@@ -28,9 +28,7 @@ discard block |
||
28 | 28 | |
29 | 29 | /** |
30 | 30 | * imports entries according to given definition object. |
31 | - * @param resource $_stream |
|
32 | - * @param string $_charset |
|
33 | - * @param definition $_definition |
|
31 | + * @param importexport_definition $_definition |
|
34 | 32 | */ |
35 | 33 | public function init(importexport_definition $_definition ) { |
36 | 34 | |
@@ -52,7 +50,7 @@ discard block |
||
52 | 50 | * |
53 | 51 | * Updates the count of actions taken |
54 | 52 | * |
55 | - * @return boolean success |
|
53 | + * @return null|boolean success |
|
56 | 54 | */ |
57 | 55 | protected function import_record(importexport_iface_egw_record &$record, &$import_csv) |
58 | 56 | { |
@@ -45,15 +45,15 @@ discard block |
||
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
48 | - * Import a single record |
|
49 | - * |
|
50 | - * You don't need to worry about mappings or translations, they've been done already. |
|
51 | - * You do need to handle the conditions and the actions taken. |
|
52 | - * |
|
53 | - * Updates the count of actions taken |
|
54 | - * |
|
55 | - * @return boolean success |
|
56 | - */ |
|
48 | + * Import a single record |
|
49 | + * |
|
50 | + * You don't need to worry about mappings or translations, they've been done already. |
|
51 | + * You do need to handle the conditions and the actions taken. |
|
52 | + * |
|
53 | + * Updates the count of actions taken |
|
54 | + * |
|
55 | + * @return boolean success |
|
56 | + */ |
|
57 | 57 | protected function import_record(importexport_iface_egw_record &$record, &$import_csv) |
58 | 58 | { |
59 | 59 | // Check for an un-matched accessory of, try again on just name |
@@ -250,14 +250,14 @@ discard block |
||
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
253 | - * Returns warnings that were encountered during importing |
|
254 | - * Maximum of one warning message per record, but you can append if you need to |
|
255 | - * |
|
256 | - * @return Array ( |
|
257 | - * record_# => warning message |
|
258 | - * ) |
|
259 | - */ |
|
260 | - public function get_warnings() { |
|
253 | + * Returns warnings that were encountered during importing |
|
254 | + * Maximum of one warning message per record, but you can append if you need to |
|
255 | + * |
|
256 | + * @return Array ( |
|
257 | + * record_# => warning message |
|
258 | + * ) |
|
259 | + */ |
|
260 | + public function get_warnings() { |
|
261 | 261 | return $this->warnings; |
262 | 262 | } |
263 | 263 | } |
@@ -16,7 +16,8 @@ discard block |
||
16 | 16 | /** |
17 | 17 | * class to import resources from CSV |
18 | 18 | */ |
19 | -class resources_import_csv extends importexport_basic_import_csv { |
|
19 | +class resources_import_csv extends importexport_basic_import_csv |
|
20 | +{ |
|
20 | 21 | |
21 | 22 | |
22 | 23 | /** |
@@ -32,7 +33,8 @@ discard block |
||
32 | 33 | * @param string $_charset |
33 | 34 | * @param definition $_definition |
34 | 35 | */ |
35 | - public function init(importexport_definition $_definition ) { |
|
36 | + public function init(importexport_definition $_definition ) |
|
37 | + { |
|
36 | 38 | |
37 | 39 | // fetch the resource bo |
38 | 40 | $this->bo = new resources_bo(); |
@@ -92,7 +94,8 @@ discard block |
||
92 | 94 | // Check for a new category, it needs permissions set |
93 | 95 | $category = $GLOBALS['egw']->categories->read($record->cat_id); |
94 | 96 | |
95 | - if($category['last_mod'] >= $this->start_time) { |
|
97 | + if($category['last_mod'] >= $this->start_time) |
|
98 | + { |
|
96 | 99 | // New category. Give read & write permissions to the current user's default group |
97 | 100 | $this->acl_bo->set_rights($record['cat_id'], |
98 | 101 | array($GLOBALS['egw_info']['user']['account_primary_group']), |
@@ -104,35 +107,53 @@ discard block |
||
104 | 107 | // Refresh ACL |
105 | 108 | //$GLOBALS['egw']->acl->read_repository(); |
106 | 109 | } |
107 | - if(!$record->accessory_of) $record->accessory_of = -1; |
|
110 | + if(!$record->accessory_of) |
|
111 | + { |
|
112 | + $record->accessory_of = -1; |
|
113 | + } |
|
108 | 114 | //error_log(__METHOD__.__LINE__.array2string($_definition->plugin_options['conditions'])); |
109 | - if ($this->definition->plugin_options['conditions']) { |
|
115 | + if ($this->definition->plugin_options['conditions']) |
|
116 | + { |
|
110 | 117 | |
111 | - foreach ( $this->definition->plugin_options['conditions'] as $condition ) { |
|
118 | + foreach ( $this->definition->plugin_options['conditions'] as $condition ) |
|
119 | + { |
|
112 | 120 | $results = array(); |
113 | - switch ( $condition['type'] ) { |
|
121 | + switch ( $condition['type'] ) |
|
122 | + { |
|
114 | 123 | // exists |
115 | 124 | case 'exists' : |
116 | - if($record->$condition['string']) { |
|
125 | + if($record->$condition['string']) |
|
126 | + { |
|
117 | 127 | $results = $this->bo->so->search( |
118 | 128 | array( $condition['string'] => $record->$condition['string']), |
119 | 129 | False |
120 | 130 | ); |
121 | 131 | } |
122 | 132 | |
123 | - if ( is_array( $results ) && count( array_keys( $results )) >= 1) { |
|
133 | + if ( is_array( $results ) && count( array_keys( $results )) >= 1) |
|
134 | + { |
|
124 | 135 | // apply action to all contacts matching this exists condition |
125 | 136 | $action = $condition['true']; |
126 | - foreach ( (array)$results as $resource ) { |
|
137 | + foreach ( (array)$results as $resource ) |
|
138 | + { |
|
127 | 139 | $record->res_id = $resource['res_id']; |
128 | - if ( $_definition->plugin_options['update_cats'] == 'add' ) { |
|
129 | - if ( !is_array( $resource['cat_id'] ) ) $resource['cat_id'] = explode( ',', $resource['cat_id'] ); |
|
130 | - if ( !is_array( $record->cat_id ) ) $record->cat_id = explode( ',', $record->cat_id ); |
|
140 | + if ( $_definition->plugin_options['update_cats'] == 'add' ) |
|
141 | + { |
|
142 | + if ( !is_array( $resource['cat_id'] ) ) |
|
143 | + { |
|
144 | + $resource['cat_id'] = explode( ',', $resource['cat_id'] ); |
|
145 | + } |
|
146 | + if ( !is_array( $record->cat_id ) ) |
|
147 | + { |
|
148 | + $record->cat_id = explode( ',', $record->cat_id ); |
|
149 | + } |
|
131 | 150 | $record->cat_id = implode( ',', array_unique( array_merge( $record->cat_id, $resource['cat_id'] ) ) ); |
132 | 151 | } |
133 | 152 | $success = $this->action( $action['action'], $record, $import_csv->get_current_position() ); |
134 | 153 | } |
135 | - } else { |
|
154 | + } |
|
155 | + else |
|
156 | + { |
|
136 | 157 | $action = $condition['false']; |
137 | 158 | $success = ($this->action( $action['action'], $record, $import_csv->get_current_position() )); |
138 | 159 | } |
@@ -143,9 +164,14 @@ discard block |
||
143 | 164 | die('condition / action not supported!!!'); |
144 | 165 | break; |
145 | 166 | } |
146 | - if ($action['last']) break; |
|
167 | + if ($action['last']) |
|
168 | + { |
|
169 | + break; |
|
170 | + } |
|
147 | 171 | } |
148 | - } else { |
|
172 | + } |
|
173 | + else |
|
174 | + { |
|
149 | 175 | // unconditional insert |
150 | 176 | $success = $this->action( 'insert', $record, $import_csv->get_current_position() ); |
151 | 177 | } |
@@ -159,9 +185,11 @@ discard block |
||
159 | 185 | * @param importexport_iface_egw_record $record Entry record |
160 | 186 | * @return bool success or not |
161 | 187 | */ |
162 | - protected function action ( $_action, importexport_iface_egw_record &$record, $record_num = 0 ) { |
|
188 | + protected function action ( $_action, importexport_iface_egw_record &$record, $record_num = 0 ) |
|
189 | + { |
|
163 | 190 | $_data = $record->get_record_array(); |
164 | - switch ($_action) { |
|
191 | + switch ($_action) |
|
192 | + { |
|
165 | 193 | case 'none' : |
166 | 194 | return true; |
167 | 195 | case 'update' : |
@@ -173,20 +201,27 @@ discard block |
||
173 | 201 | |
174 | 202 | // Fall through |
175 | 203 | case 'insert' : |
176 | - if($_action == 'insert') { |
|
204 | + if($_action == 'insert') |
|
205 | + { |
|
177 | 206 | // Backend doesn't like inserting with ID specified, it can overwrite |
178 | 207 | unset($_data['res_id']); |
179 | 208 | } |
180 | - if ( $this->dry_run ) { |
|
209 | + if ( $this->dry_run ) |
|
210 | + { |
|
181 | 211 | //print_r($_data); |
182 | 212 | $this->results[$_action]++; |
183 | 213 | return true; |
184 | - } else { |
|
214 | + } |
|
215 | + else |
|
216 | + { |
|
185 | 217 | $result = $this->bo->save( $_data ); |
186 | - if($result && !is_numeric($result)) { |
|
218 | + if($result && !is_numeric($result)) |
|
219 | + { |
|
187 | 220 | $this->errors[$record_num] = $result; |
188 | 221 | return false; |
189 | - } else { |
|
222 | + } |
|
223 | + else |
|
224 | + { |
|
190 | 225 | $this->results[$_action]++; |
191 | 226 | return true; |
192 | 227 | } |
@@ -202,7 +237,8 @@ discard block |
||
202 | 237 | * |
203 | 238 | * @return string name |
204 | 239 | */ |
205 | - public static function get_name() { |
|
240 | + public static function get_name() |
|
241 | + { |
|
206 | 242 | return lang('Resources CSV import'); |
207 | 243 | } |
208 | 244 | |
@@ -211,7 +247,8 @@ discard block |
||
211 | 247 | * |
212 | 248 | * @return string descriprion |
213 | 249 | */ |
214 | - public static function get_description() { |
|
250 | + public static function get_description() |
|
251 | + { |
|
215 | 252 | return lang("Imports a list of resources from a CSV file."); |
216 | 253 | } |
217 | 254 | |
@@ -220,7 +257,8 @@ discard block |
||
220 | 257 | * |
221 | 258 | * @return string suffix (comma seperated) |
222 | 259 | */ |
223 | - public static function get_filesuffix() { |
|
260 | + public static function get_filesuffix() |
|
261 | + { |
|
224 | 262 | return 'csv'; |
225 | 263 | } |
226 | 264 | |
@@ -236,7 +274,8 @@ discard block |
||
236 | 274 | * preserv => array, |
237 | 275 | * ) |
238 | 276 | */ |
239 | - public function get_options_etpl() { |
|
277 | + public function get_options_etpl() |
|
278 | + { |
|
240 | 279 | // lets do it! |
241 | 280 | } |
242 | 281 | |
@@ -245,7 +284,8 @@ discard block |
||
245 | 284 | * |
246 | 285 | * @return string etemplate name |
247 | 286 | */ |
248 | - public function get_selectors_etpl() { |
|
287 | + public function get_selectors_etpl() |
|
288 | + { |
|
249 | 289 | // lets do it! |
250 | 290 | } |
251 | 291 | |
@@ -257,7 +297,8 @@ discard block |
||
257 | 297 | * record_# => warning message |
258 | 298 | * ) |
259 | 299 | */ |
260 | - public function get_warnings() { |
|
300 | + public function get_warnings() |
|
301 | + { |
|
261 | 302 | return $this->warnings; |
262 | 303 | } |
263 | 304 | } |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * class to import resources from CSV |
17 | 17 | */ |
18 | -class resources_import_csv extends importexport_basic_import_csv { |
|
18 | +class resources_import_csv extends importexport_basic_import_csv { |
|
19 | 19 | |
20 | 20 | |
21 | 21 | /** |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @var array |
25 | 25 | */ |
26 | - protected static $conditions = array( 'exists' ); |
|
26 | + protected static $conditions = array('exists'); |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * imports entries according to given definition object. |
@@ -31,13 +31,13 @@ discard block |
||
31 | 31 | * @param string $_charset |
32 | 32 | * @param definition $_definition |
33 | 33 | */ |
34 | - public function init(importexport_definition $_definition ) { |
|
34 | + public function init(importexport_definition $_definition) { |
|
35 | 35 | |
36 | 36 | // fetch the resource bo |
37 | 37 | $this->bo = new resources_bo(); |
38 | 38 | |
39 | 39 | // For adding ACLs |
40 | - $this->acl_bo = CreateObject('resources.bo_acl',True); |
|
40 | + $this->acl_bo = CreateObject('resources.bo_acl', True); |
|
41 | 41 | |
42 | 42 | // For checking categories |
43 | 43 | $this->start_time = time(); |
@@ -53,33 +53,33 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @return boolean success |
55 | 55 | */ |
56 | - protected function import_record(importexport_iface_egw_record &$record, &$import_csv) |
|
56 | + protected function import_record(importexport_iface_egw_record&$record, &$import_csv) |
|
57 | 57 | { |
58 | 58 | // Check for an un-matched accessory of, try again on just name |
59 | - if(!is_numeric($record->accessory_of)) |
|
59 | + if (!is_numeric($record->accessory_of)) |
|
60 | 60 | { |
61 | 61 | $accessory_of = $record->accessory_of; |
62 | 62 | |
63 | 63 | // Look for exact match in just name |
64 | - $results = $this->bo->so->search(array('name' => $record->accessory_of),array('res_id','name')); |
|
65 | - if(count($results) >= 1) |
|
64 | + $results = $this->bo->so->search(array('name' => $record->accessory_of), array('res_id', 'name')); |
|
65 | + if (count($results) >= 1) |
|
66 | 66 | { |
67 | 67 | // More than 1 result? Bad names. Pick one. |
68 | - foreach($results as $result) |
|
68 | + foreach ($results as $result) |
|
69 | 69 | { |
70 | - if($result['name'] == $record->accessory_of) |
|
70 | + if ($result['name'] == $record->accessory_of) |
|
71 | 71 | { |
72 | 72 | $record->accessory_of = $result['res_id']; |
73 | 73 | break; |
74 | 74 | } |
75 | 75 | } |
76 | - if(is_numeric($record->accessory_of)) |
|
76 | + if (is_numeric($record->accessory_of)) |
|
77 | 77 | { |
78 | 78 | // Import/Export conversion gave a warning, so cancel it |
79 | - $pattern = lang('Unable to link to %1 "%2"',lang('resources'),$accessory_of) . ' - ('.lang('too many matches') . '|'.lang('no matches') . ')'; |
|
79 | + $pattern = lang('Unable to link to %1 "%2"', lang('resources'), $accessory_of).' - ('.lang('too many matches').'|'.lang('no matches').')'; |
|
80 | 80 | $this->warnings[$import_csv->get_current_position()] = preg_replace($pattern, '', $this->warnings[$import_csv->get_current_position()], 1); |
81 | 81 | // If that was the only warning, clear it for this row |
82 | - if(trim($this->warnings[$import_csv->get_current_position()]) == '') |
|
82 | + if (trim($this->warnings[$import_csv->get_current_position()]) == '') |
|
83 | 83 | { |
84 | 84 | unset($this->warnings[$import_csv->get_current_position()]); |
85 | 85 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | // Check for a new category, it needs permissions set |
92 | 92 | $category = $GLOBALS['egw']->categories->read($record->cat_id); |
93 | 93 | |
94 | - if($category['last_mod'] >= $this->start_time) { |
|
94 | + if ($category['last_mod'] >= $this->start_time) { |
|
95 | 95 | // New category. Give read & write permissions to the current user's default group |
96 | 96 | $this->acl_bo->set_rights($record['cat_id'], |
97 | 97 | array($GLOBALS['egw_info']['user']['account_primary_group']), |
@@ -103,37 +103,37 @@ discard block |
||
103 | 103 | // Refresh ACL |
104 | 104 | //$GLOBALS['egw']->acl->read_repository(); |
105 | 105 | } |
106 | - if(!$record->accessory_of) $record->accessory_of = -1; |
|
106 | + if (!$record->accessory_of) $record->accessory_of = -1; |
|
107 | 107 | //error_log(__METHOD__.__LINE__.array2string($_definition->plugin_options['conditions'])); |
108 | 108 | if ($this->definition->plugin_options['conditions']) { |
109 | 109 | |
110 | - foreach ( $this->definition->plugin_options['conditions'] as $condition ) { |
|
110 | + foreach ($this->definition->plugin_options['conditions'] as $condition) { |
|
111 | 111 | $results = array(); |
112 | - switch ( $condition['type'] ) { |
|
112 | + switch ($condition['type']) { |
|
113 | 113 | // exists |
114 | 114 | case 'exists' : |
115 | - if($record->$condition['string']) { |
|
115 | + if ($record->$condition['string']) { |
|
116 | 116 | $results = $this->bo->so->search( |
117 | - array( $condition['string'] => $record->$condition['string']), |
|
117 | + array($condition['string'] => $record->$condition['string']), |
|
118 | 118 | False |
119 | 119 | ); |
120 | 120 | } |
121 | 121 | |
122 | - if ( is_array( $results ) && count( array_keys( $results )) >= 1) { |
|
122 | + if (is_array($results) && count(array_keys($results)) >= 1) { |
|
123 | 123 | // apply action to all contacts matching this exists condition |
124 | 124 | $action = $condition['true']; |
125 | - foreach ( (array)$results as $resource ) { |
|
125 | + foreach ((array)$results as $resource) { |
|
126 | 126 | $record->res_id = $resource['res_id']; |
127 | - if ( $_definition->plugin_options['update_cats'] == 'add' ) { |
|
128 | - if ( !is_array( $resource['cat_id'] ) ) $resource['cat_id'] = explode( ',', $resource['cat_id'] ); |
|
129 | - if ( !is_array( $record->cat_id ) ) $record->cat_id = explode( ',', $record->cat_id ); |
|
130 | - $record->cat_id = implode( ',', array_unique( array_merge( $record->cat_id, $resource['cat_id'] ) ) ); |
|
127 | + if ($_definition->plugin_options['update_cats'] == 'add') { |
|
128 | + if (!is_array($resource['cat_id'])) $resource['cat_id'] = explode(',', $resource['cat_id']); |
|
129 | + if (!is_array($record->cat_id)) $record->cat_id = explode(',', $record->cat_id); |
|
130 | + $record->cat_id = implode(',', array_unique(array_merge($record->cat_id, $resource['cat_id']))); |
|
131 | 131 | } |
132 | - $success = $this->action( $action['action'], $record, $import_csv->get_current_position() ); |
|
132 | + $success = $this->action($action['action'], $record, $import_csv->get_current_position()); |
|
133 | 133 | } |
134 | 134 | } else { |
135 | 135 | $action = $condition['false']; |
136 | - $success = ($this->action( $action['action'], $record, $import_csv->get_current_position() )); |
|
136 | + $success = ($this->action($action['action'], $record, $import_csv->get_current_position())); |
|
137 | 137 | } |
138 | 138 | break; |
139 | 139 | |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | } |
147 | 147 | } else { |
148 | 148 | // unconditional insert |
149 | - $success = $this->action( 'insert', $record, $import_csv->get_current_position() ); |
|
149 | + $success = $this->action('insert', $record, $import_csv->get_current_position()); |
|
150 | 150 | } |
151 | 151 | return $success; |
152 | 152 | } |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @param importexport_iface_egw_record $record Entry record |
159 | 159 | * @return bool success or not |
160 | 160 | */ |
161 | - protected function action ( $_action, importexport_iface_egw_record &$record, $record_num = 0 ) { |
|
161 | + protected function action($_action, importexport_iface_egw_record&$record, $record_num = 0) { |
|
162 | 162 | $_data = $record->get_record_array(); |
163 | 163 | switch ($_action) { |
164 | 164 | case 'none' : |
@@ -172,17 +172,17 @@ discard block |
||
172 | 172 | |
173 | 173 | // Fall through |
174 | 174 | case 'insert' : |
175 | - if($_action == 'insert') { |
|
175 | + if ($_action == 'insert') { |
|
176 | 176 | // Backend doesn't like inserting with ID specified, it can overwrite |
177 | 177 | unset($_data['res_id']); |
178 | 178 | } |
179 | - if ( $this->dry_run ) { |
|
179 | + if ($this->dry_run) { |
|
180 | 180 | //print_r($_data); |
181 | 181 | $this->results[$_action]++; |
182 | 182 | return true; |
183 | 183 | } else { |
184 | - $result = $this->bo->save( $_data ); |
|
185 | - if($result && !is_numeric($result)) { |
|
184 | + $result = $this->bo->save($_data); |
|
185 | + if ($result && !is_numeric($result)) { |
|
186 | 186 | $this->errors[$record_num] = $result; |
187 | 187 | return false; |
188 | 188 | } else { |
@@ -33,7 +33,7 @@ |
||
33 | 33 | * |
34 | 34 | * @param string $key key of value to get |
35 | 35 | * @param int $res_id resource id |
36 | - * @return mixed value of key and resource, false if key or id not found. |
|
36 | + * @return integer value of key and resource, false if key or id not found. |
|
37 | 37 | */ |
38 | 38 | function get_value($key,$res_id) |
39 | 39 | { |
@@ -22,10 +22,10 @@ discard block |
||
22 | 22 | { |
23 | 23 | function __construct() |
24 | 24 | { |
25 | - parent::__construct('resources','egw_resources', 'egw_resources_extra', '', |
|
26 | - 'extra_name', 'extra_value', 'extra_id' ); |
|
25 | + parent::__construct('resources', 'egw_resources', 'egw_resources_extra', '', |
|
26 | + 'extra_name', 'extra_value', 'extra_id'); |
|
27 | 27 | |
28 | - $this->columns_to_search = array('name','short_description','inventory_number','long_description','location'); |
|
28 | + $this->columns_to_search = array('name', 'short_description', 'inventory_number', 'long_description', 'location'); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -35,10 +35,9 @@ discard block |
||
35 | 35 | * @param int $res_id resource id |
36 | 36 | * @return mixed value of key and resource, false if key or id not found. |
37 | 37 | */ |
38 | - function get_value($key,$res_id) |
|
38 | + function get_value($key, $res_id) |
|
39 | 39 | { |
40 | - return $res_id == $this->data['res_id'] ? $this->data[$key] : |
|
41 | - $this->db->select($this->table_name,$key,array('res_id' => $res_id),__LINE__,__FILE__)->fetchColumn(); |
|
40 | + return $res_id == $this->data['res_id'] ? $this->data[$key] : $this->db->select($this->table_name, $key, array('res_id' => $res_id), __LINE__, __FILE__)->fetchColumn(); |
|
42 | 41 | } |
43 | 42 | |
44 | 43 | /** |
@@ -90,7 +89,7 @@ discard block |
||
90 | 89 | function save($resource) |
91 | 90 | { |
92 | 91 | $this->data = $resource; |
93 | - if(parent::save() != 0) return false; |
|
92 | + if (parent::save() != 0) return false; |
|
94 | 93 | $res_id = $this->data['res_id']; |
95 | 94 | |
96 | 95 | return $res_id; |
@@ -51,7 +51,10 @@ discard block |
||
51 | 51 | */ |
52 | 52 | function read($res_id) |
53 | 53 | { |
54 | - if (is_array($res_id) && count($res_id) == 1 && isset($res_id['res_id'])) $res_id = $res_id['res_id']; |
|
54 | + if (is_array($res_id) && count($res_id) == 1 && isset($res_id['res_id'])) |
|
55 | + { |
|
56 | + $res_id = $res_id['res_id']; |
|
57 | + } |
|
55 | 58 | |
56 | 59 | /*if (!is_array($res_id) && $res_id == $this->data['res_id']) |
57 | 60 | { |
@@ -90,7 +93,10 @@ discard block |
||
90 | 93 | function save($resource) |
91 | 94 | { |
92 | 95 | $this->data = $resource; |
93 | - if(parent::save() != 0) return false; |
|
96 | + if(parent::save() != 0) |
|
97 | + { |
|
98 | + return false; |
|
99 | + } |
|
94 | 100 | $res_id = $this->data['res_id']; |
95 | 101 | |
96 | 102 | return $res_id; |
@@ -936,9 +936,6 @@ |
||
936 | 936 | * |
937 | 937 | * Uses $this->ldap_host, $this->ldap_admin and $this->ldap_admin_pw to connect. |
938 | 938 | * |
939 | - * @param string $this->object_class ='qmailUser' |
|
940 | - * @param string $this->mbox_attr ='mailmessagestore' lowercase!!! |
|
941 | - * @param string $this->mail_login_type ='email' 'email', 'vmailmgr', 'standard' or 'uidNumber' |
|
942 | 939 | * @return string with success message N entries modified |
943 | 940 | * @throws Api\Exception if dn not found, not listable or delete fails |
944 | 941 | */ |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | * @param string $ldap_encryption_type ='des' |
83 | 83 | * @param boolean $truncate_egw_accounts =false truncate accounts table before migration to SQL |
84 | 84 | */ |
85 | - function __construct($domain,$ldap_host=null,$ldap_suffix=null,$ldap_admin=null,$ldap_admin_pw=null, |
|
86 | - $ldap_base=null,$ldap_root_dn=null,$ldap_root_pw=null,$ldap_context=null,$ldap_search_filter=null, |
|
87 | - $ldap_group_context=null,$sub_command='create_ldap',$ldap_encryption_type='des',$truncate_egw_accounts=false) |
|
85 | + function __construct($domain, $ldap_host = null, $ldap_suffix = null, $ldap_admin = null, $ldap_admin_pw = null, |
|
86 | + $ldap_base = null, $ldap_root_dn = null, $ldap_root_pw = null, $ldap_context = null, $ldap_search_filter = null, |
|
87 | + $ldap_group_context = null, $sub_command = 'create_ldap', $ldap_encryption_type = 'des', $truncate_egw_accounts = false) |
|
88 | 88 | { |
89 | 89 | if (!is_array($domain)) |
90 | 90 | { |
@@ -117,23 +117,23 @@ discard block |
||
117 | 117 | * @throws Exception(lang('Wrong credentials to access the header.inc.php file!'),2); |
118 | 118 | * @throws Exception('header.inc.php not found!'); |
119 | 119 | */ |
120 | - protected function exec($check_only=false) |
|
120 | + protected function exec($check_only = false) |
|
121 | 121 | { |
122 | - if (!empty($this->domain) && !preg_match('/^([a-z0-9_-]+\.)*[a-z0-9]+/i',$this->domain)) |
|
122 | + if (!empty($this->domain) && !preg_match('/^([a-z0-9_-]+\.)*[a-z0-9]+/i', $this->domain)) |
|
123 | 123 | { |
124 | - throw new egw_exception_wrong_userinput(lang("'%1' is no valid domain name!",$this->domain)); |
|
124 | + throw new egw_exception_wrong_userinput(lang("'%1' is no valid domain name!", $this->domain)); |
|
125 | 125 | } |
126 | 126 | if ($this->remote_id && $check_only && !in_array($this->sub_command, array('set_mailbox', 'sid2uidnumber', 'copy2ad'))) |
127 | 127 | { |
128 | - return true; // further checks can only done locally |
|
128 | + return true; // further checks can only done locally |
|
129 | 129 | } |
130 | 130 | $this->_merge_defaults(); |
131 | 131 | //_debug_array($this->as_array()); |
132 | 132 | |
133 | - switch($this->sub_command) |
|
133 | + switch ($this->sub_command) |
|
134 | 134 | { |
135 | 135 | case 'test_ldap_root': |
136 | - $msg = $this->connect($this->ldap_admin,$this->ldap_admin_pw); |
|
136 | + $msg = $this->connect($this->ldap_admin, $this->ldap_admin_pw); |
|
137 | 137 | break; |
138 | 138 | case 'test_ldap': |
139 | 139 | $msg = $this->connect(); |
@@ -178,28 +178,28 @@ discard block |
||
178 | 178 | * |
179 | 179 | * @param boolean $check_only =false true: only connect and output necessary commands |
180 | 180 | */ |
181 | - private function sid2uidnumber($check_only=false) |
|
181 | + private function sid2uidnumber($check_only = false) |
|
182 | 182 | { |
183 | 183 | $msg = array(); |
184 | 184 | $this->connect(); |
185 | 185 | |
186 | 186 | // check if base does exist |
187 | - if (!@ldap_read($this->test_ldap->ds,$this->ldap_base,'objectClass=*')) |
|
187 | + if (!@ldap_read($this->test_ldap->ds, $this->ldap_base, 'objectClass=*')) |
|
188 | 188 | { |
189 | - throw new egw_exception_wrong_userinput(lang('Base dn "%1" NOT found!',$this->ldap_base)); |
|
189 | + throw new egw_exception_wrong_userinput(lang('Base dn "%1" NOT found!', $this->ldap_base)); |
|
190 | 190 | } |
191 | 191 | |
192 | - if (!($sr = ldap_search($this->test_ldap->ds,$this->ldap_base, |
|
193 | - $search='(&(|(objectClass=posixAccount)(objectClass=posixGroup))('.self::sambaSID.'=*)(!(uid=*$)))', |
|
194 | - array('uidNumber','gidNumber','uid','cn', 'objectClass',self::sambaSID))) || |
|
192 | + if (!($sr = ldap_search($this->test_ldap->ds, $this->ldap_base, |
|
193 | + $search = '(&(|(objectClass=posixAccount)(objectClass=posixGroup))('.self::sambaSID.'=*)(!(uid=*$)))', |
|
194 | + array('uidNumber', 'gidNumber', 'uid', 'cn', 'objectClass', self::sambaSID))) || |
|
195 | 195 | !($entries = ldap_get_entries($this->test_ldap->ds, $sr))) |
196 | 196 | { |
197 | - throw new egw_exception(lang('Error searching "dn=%1" for "%2"!',$this->ldap_base, $search)); |
|
197 | + throw new egw_exception(lang('Error searching "dn=%1" for "%2"!', $this->ldap_base, $search)); |
|
198 | 198 | } |
199 | 199 | $change = $accounts = array(); |
200 | 200 | $cmd_change_account_id = 'admin/admin-cli.php --change-account-id <admin>@<domain>,<adminpw>'; |
201 | 201 | $change_account_id = ''; |
202 | - foreach($entries as $key => $entry) |
|
202 | + foreach ($entries as $key => $entry) |
|
203 | 203 | { |
204 | 204 | if ($key === 'count') continue; |
205 | 205 | |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | |
235 | 235 | // now change them in LDAP |
236 | 236 | $changed = 0; |
237 | - foreach($accounts as $dn => $account) |
|
237 | + foreach ($accounts as $dn => $account) |
|
238 | 238 | { |
239 | 239 | $modify = array(); |
240 | 240 | if (!empty($account['uidnumber']) && isset($change[$account['uidnumber']])) |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | if (!$check_only && $modify && !ldap_modify($this->test_ldap->ds, $dn, $modify)) |
249 | 249 | { |
250 | 250 | throw new egw_exception("Failed to modify ldap: !ldap_modify({$this->test_ldap->ds}, '$dn', ".array2string($modify).") ".ldap_error($this->test_ldap->ds). |
251 | - "\n- ".implode("\n- ", $msg)); // EGroupware change already run successful |
|
251 | + "\n- ".implode("\n- ", $msg)); // EGroupware change already run successful |
|
252 | 252 | } |
253 | 253 | if ($modify) ++$changed; |
254 | 254 | } |
@@ -263,13 +263,13 @@ discard block |
||
263 | 263 | * |
264 | 264 | * @param boolean $check_only =false true: only connect and output necessary commands |
265 | 265 | */ |
266 | - private function copy2ad($check_only=false) |
|
266 | + private function copy2ad($check_only = false) |
|
267 | 267 | { |
268 | 268 | $msg = array(); |
269 | 269 | $attrs = $rename = array(); |
270 | - foreach(explode(',', $this->attributes) as $attr) |
|
270 | + foreach (explode(',', $this->attributes) as $attr) |
|
271 | 271 | { |
272 | - if ($attr[0] == '@' || // copy whole objectclass without renaming, eg. @inetOrgPerson |
|
272 | + if ($attr[0] == '@' || // copy whole objectclass without renaming, eg. @inetOrgPerson |
|
273 | 273 | strpos($attr, '=') === false) |
274 | 274 | { |
275 | 275 | $attrs[] = $attr; |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | $ignore_attr = array_flip(array('dn', 'objectclass', 'cn', 'userpassword')); |
285 | 285 | if (!in_array('uid', $attrs)) |
286 | 286 | { |
287 | - $attrs[] = 'uid'; // need to match account |
|
287 | + $attrs[] = 'uid'; // need to match account |
|
288 | 288 | $ignore_attr['uid'] = true; |
289 | 289 | } |
290 | 290 | // connect to destination ads |
@@ -293,9 +293,8 @@ discard block |
||
293 | 293 | $this->ads_context = 'CN=Users,DC='.implode(',DC=', explode('.', $this->ads_domain)); |
294 | 294 | } |
295 | 295 | if (empty($this->ads_admin_user)) $this->ads_admin_user = 'Administrator'; |
296 | - $admin_dn = strpos($this->ads_admin_user, '=') !== false ? $this->ads_admin_user : |
|
297 | - 'CN='.$this->ads_admin_user.','.$this->ads_context; |
|
298 | - switch($this->ads_connection) |
|
296 | + $admin_dn = strpos($this->ads_admin_user, '=') !== false ? $this->ads_admin_user : 'CN='.$this->ads_admin_user.','.$this->ads_context; |
|
297 | + switch ($this->ads_connection) |
|
299 | 298 | { |
300 | 299 | case 'ssl': |
301 | 300 | $url = 'ldaps://'.$this->ads_host.'/'; |
@@ -313,28 +312,27 @@ discard block |
||
313 | 312 | // check if ads base does exist |
314 | 313 | if (!@ldap_read($ads->ds, $this->ads_context, 'objectClass=*')) |
315 | 314 | { |
316 | - throw new egw_exception_wrong_userinput(lang('Ads dn "%1" NOT found!',$this->ads_context)); |
|
315 | + throw new egw_exception_wrong_userinput(lang('Ads dn "%1" NOT found!', $this->ads_context)); |
|
317 | 316 | } |
318 | 317 | |
319 | 318 | // connect to source ldap |
320 | 319 | $this->connect(); |
321 | 320 | |
322 | 321 | // check if ldap base does exist |
323 | - if (!@ldap_read($this->test_ldap->ds,$this->ldap_base,'objectClass=*')) |
|
322 | + if (!@ldap_read($this->test_ldap->ds, $this->ldap_base, 'objectClass=*')) |
|
324 | 323 | { |
325 | - throw new egw_exception_wrong_userinput(lang('Base dn "%1" NOT found!',$this->ldap_base)); |
|
324 | + throw new egw_exception_wrong_userinput(lang('Base dn "%1" NOT found!', $this->ldap_base)); |
|
326 | 325 | } |
327 | 326 | |
328 | - if (!($sr = ldap_search($this->test_ldap->ds,$this->ldap_base, |
|
329 | - $search = $this->no_sid_check ? '(objectClass=posixAccount)' : |
|
330 | - '(&(objectClass=posixAccount)('.self::sambaSID.'=*)(!(uid=*$)))', $attrs)) || |
|
327 | + if (!($sr = ldap_search($this->test_ldap->ds, $this->ldap_base, |
|
328 | + $search = $this->no_sid_check ? '(objectClass=posixAccount)' : '(&(objectClass=posixAccount)('.self::sambaSID.'=*)(!(uid=*$)))', $attrs)) || |
|
331 | 329 | !($entries = ldap_get_entries($this->test_ldap->ds, $sr))) |
332 | 330 | { |
333 | - throw new egw_exception(lang('Error searching "dn=%1" for "%2"!',$this->ldap_base, $search)); |
|
331 | + throw new egw_exception(lang('Error searching "dn=%1" for "%2"!', $this->ldap_base, $search)); |
|
334 | 332 | } |
335 | 333 | $changed = 0; |
336 | 334 | $utc_diff = null; |
337 | - foreach($entries as $key => $entry) |
|
335 | + foreach ($entries as $key => $entry) |
|
338 | 336 | { |
339 | 337 | if ($key === 'count') continue; |
340 | 338 | |
@@ -343,7 +341,7 @@ discard block |
||
343 | 341 | $entry = array_diff_key($entry_arr, $ignore_attr); |
344 | 342 | |
345 | 343 | if (!($sr = ldap_search($ads->ds, $this->ads_context, |
346 | - $search='(&(objectClass=user)(sAMAccountName='.ldap::quote($uid).'))', array('dn'))) || |
|
344 | + $search = '(&(objectClass=user)(sAMAccountName='.ldap::quote($uid).'))', array('dn'))) || |
|
347 | 345 | !($dest = ldap_get_entries($ads->ds, $sr))) |
348 | 346 | { |
349 | 347 | $msg[] = lang('User "%1" not found!', $uid); |
@@ -363,11 +361,11 @@ discard block |
||
363 | 361 | { |
364 | 362 | if (is_null($utc_diff)) $utc_diff = date('Z'); |
365 | 363 | $entry['shadowexpire'] = accounts_ads::convertUnixTimeToWindowsTime( |
366 | - $entry['shadowexpire']*24*3600+$utc_diff); // ldap time to unixTime |
|
364 | + $entry['shadowexpire'] * 24 * 3600 + $utc_diff); // ldap time to unixTime |
|
367 | 365 | } |
368 | 366 | } |
369 | 367 | $update = array(); |
370 | - foreach($entry as $attr => $value) |
|
368 | + foreach ($entry as $attr => $value) |
|
371 | 369 | { |
372 | 370 | if ($value || $attr === '') |
373 | 371 | { |
@@ -377,14 +375,14 @@ discard block |
||
377 | 375 | { |
378 | 376 | list($prefix, $to) = explode('}', substr($to, 1)); |
379 | 377 | } |
380 | - foreach((array)$value as $val) |
|
378 | + foreach ((array)$value as $val) |
|
381 | 379 | { |
382 | 380 | if (isset($update[$to])) |
383 | 381 | { |
384 | 382 | if (!is_array($update[$to])) $update[$to] = array($update[$to]); |
385 | 383 | // we need to check (caseinsensitive) if value already exists in set |
386 | 384 | // as AD chokes on doublicate values "Type or value exists" |
387 | - foreach($update[$to] as $v) |
|
385 | + foreach ($update[$to] as $v) |
|
388 | 386 | { |
389 | 387 | if (!strcasecmp($v, $prefix.$val)) continue 2; |
390 | 388 | } |
@@ -416,7 +414,7 @@ discard block |
||
416 | 414 | if ($check_only) return lang("%1 accounts to copy found.", count($entries)); |
417 | 415 | |
418 | 416 | return "Copied data of $changed accounts from LDAP to AD ". |
419 | - (count($msg) > $changed ? ' ('.(count($msg)-$changed).' errors!)' : ''); |
|
417 | + (count($msg) > $changed ? ' ('.(count($msg) - $changed).' errors!)' : ''); |
|
420 | 418 | } |
421 | 419 | |
422 | 420 | /** |
@@ -459,9 +457,9 @@ discard block |
||
459 | 457 | $accounts_created = $groups_created = $errors = $egw_info_set = 0; |
460 | 458 | $emailadmin_src = $ldap_class = null; |
461 | 459 | $target = strtoupper($to); |
462 | - foreach($accounts as $account_id => $account) |
|
460 | + foreach ($accounts as $account_id => $account) |
|
463 | 461 | { |
464 | - if (isset($this->only) && !in_array($account_id,$this->only)) |
|
462 | + if (isset($this->only) && !in_array($account_id, $this->only)) |
|
465 | 463 | { |
466 | 464 | continue; |
467 | 465 | } |
@@ -481,12 +479,12 @@ discard block |
||
481 | 479 | { |
482 | 480 | if (!($sql_account = $accounts_obj->read($account_id))) |
483 | 481 | { |
484 | - $msg[] = lang('%1 does NOT exist in %2.',$what,$target); |
|
482 | + $msg[] = lang('%1 does NOT exist in %2.', $what, $target); |
|
485 | 483 | $errors++; |
486 | 484 | } |
487 | - elseif(empty($account['account_pwd'])) |
|
485 | + elseif (empty($account['account_pwd'])) |
|
488 | 486 | { |
489 | - $msg[] = lang('%1 does NOT have a password (userPassword attribute) or we are not allowed to read it!',$what); |
|
487 | + $msg[] = lang('%1 does NOT have a password (userPassword attribute) or we are not allowed to read it!', $what); |
|
490 | 488 | $errors++; |
491 | 489 | } |
492 | 490 | else |
@@ -495,12 +493,12 @@ discard block |
||
495 | 493 | |
496 | 494 | if (!$accounts_obj->save($sql_account)) |
497 | 495 | { |
498 | - $msg[] = lang('Update of %1 in %2 failed !!!',$what,$target); |
|
496 | + $msg[] = lang('Update of %1 in %2 failed !!!', $what, $target); |
|
499 | 497 | $errors++; |
500 | 498 | } |
501 | 499 | else |
502 | 500 | { |
503 | - $msg[] = lang('%1 password set in %2.',$what,$target); |
|
501 | + $msg[] = lang('%1 password set in %2.', $what, $target); |
|
504 | 502 | $accounts_created++; |
505 | 503 | } |
506 | 504 | } |
@@ -511,7 +509,7 @@ discard block |
||
511 | 509 | { |
512 | 510 | if ($accounts_obj->exists($account_id)) |
513 | 511 | { |
514 | - $msg[] = lang('%1 already exists in %2.',$what,$target); |
|
512 | + $msg[] = lang('%1 already exists in %2.', $what, $target); |
|
515 | 513 | $errors++; |
516 | 514 | continue; |
517 | 515 | } |
@@ -519,7 +517,7 @@ discard block |
||
519 | 517 | { |
520 | 518 | if ($GLOBALS['egw_info']['server']['ldap_extra_attributes']) |
521 | 519 | { |
522 | - $account['homedirectory'] = $GLOBALS['egw_info']['server']['ldap_account_home'] . '/' . $account['account_lid']; |
|
520 | + $account['homedirectory'] = $GLOBALS['egw_info']['server']['ldap_account_home'].'/'.$account['account_lid']; |
|
523 | 521 | $account['loginshell'] = $GLOBALS['egw_info']['server']['ldap_account_shell']; |
524 | 522 | } |
525 | 523 | $account['account_passwd'] = self::hash_sql2ldap($account['account_pwd']); |
@@ -532,12 +530,12 @@ discard block |
||
532 | 530 | |
533 | 531 | if (!$accounts_obj->save($account)) |
534 | 532 | { |
535 | - $msg[] = lang('Creation of %1 in %2 failed !!!',$what,$target); |
|
533 | + $msg[] = lang('Creation of %1 in %2 failed !!!', $what, $target); |
|
536 | 534 | $errors++; |
537 | 535 | continue; |
538 | 536 | } |
539 | - $accounts_obj->set_memberships($account['memberships'],$account_id); |
|
540 | - $msg[] = lang('%1 created in %2.',$what,$target); |
|
537 | + $accounts_obj->set_memberships($account['memberships'], $account_id); |
|
538 | + $msg[] = lang('%1 created in %2.', $what, $target); |
|
541 | 539 | $accounts_created++; |
542 | 540 | |
543 | 541 | // check if we need to migrate mail-account |
@@ -546,7 +544,7 @@ discard block |
||
546 | 544 | $ldap_class = false; |
547 | 545 | $ldap = new ldap(); |
548 | 546 | $ldap->ldapConnect(); |
549 | - foreach(array( // todo: have these enumerated by emailadmin ... |
|
547 | + foreach (array( // todo: have these enumerated by emailadmin ... |
|
550 | 548 | 'qmailUser' => 'postfixldap', |
551 | 549 | 'dbMailUser' => 'postfixdbmailuser', |
552 | 550 | // nothing to migrate for inetOrgPerson ... |
@@ -594,7 +592,7 @@ discard block |
||
594 | 592 | // setting up egw_info array with new ldap information, so hook can use ldap::ldapConnect() |
595 | 593 | if (!$egw_info_set++) |
596 | 594 | { |
597 | - foreach(array('ldap_host','ldap_root_dn','ldap_root_pw','ldap_context','ldap_group_context','ldap_search_filter','ldap_encryptin_type','mail_suffix','mail_login_type') as $name) |
|
595 | + foreach (array('ldap_host', 'ldap_root_dn', 'ldap_root_pw', 'ldap_context', 'ldap_group_context', 'ldap_search_filter', 'ldap_encryptin_type', 'mail_suffix', 'mail_login_type') as $name) |
|
598 | 596 | { |
599 | 597 | if (!empty($this->$name)) $GLOBALS['egw_info']['server'][$name] = $this->$name; |
600 | 598 | } |
@@ -606,14 +604,14 @@ discard block |
||
606 | 604 | // running all addAccount hooks (currently NOT working, as not all work in setup) |
607 | 605 | if ($this->add_account_hook === true) |
608 | 606 | { |
609 | - $GLOBALS['egw']->hooks->process($account,array(),true); |
|
607 | + $GLOBALS['egw']->hooks->process($account, array(), true); |
|
610 | 608 | } |
611 | - elseif(is_callable($this->add_account_hook)) |
|
609 | + elseif (is_callable($this->add_account_hook)) |
|
612 | 610 | { |
613 | - call_user_func($this->add_account_hook,$account); |
|
611 | + call_user_func($this->add_account_hook, $account); |
|
614 | 612 | } |
615 | 613 | } |
616 | - catch(Exception $e) |
|
614 | + catch (Exception $e) |
|
617 | 615 | { |
618 | 616 | $msg[] = $e->getMessage(); |
619 | 617 | $errors++; |
@@ -627,38 +625,38 @@ discard block |
||
627 | 625 | { |
628 | 626 | if (!$accounts_obj->save($account)) |
629 | 627 | { |
630 | - $msg[] = lang('Creation of %1 in %2 failed !!!',$what,$target); |
|
628 | + $msg[] = lang('Creation of %1 in %2 failed !!!', $what, $target); |
|
631 | 629 | ++$errors; |
632 | 630 | continue; |
633 | 631 | } |
634 | - $msg[] = lang('%1 created in %2.',$what,$target); |
|
632 | + $msg[] = lang('%1 created in %2.', $what, $target); |
|
635 | 633 | $groups_created++; |
636 | 634 | } |
637 | 635 | else |
638 | 636 | { |
639 | - $msg[] = lang('%1 already exists in %2.',$what,$target); |
|
637 | + $msg[] = lang('%1 already exists in %2.', $what, $target); |
|
640 | 638 | $errors++; |
641 | 639 | |
642 | 640 | if ($accounts_obj->id2name($account_id) != $account['account_lid']) |
643 | 641 | { |
644 | - $msg[] = lang("==> different group '%1' under that gidNumber %2, NOT setting memberships!",$account['account_lid'],$account_id); |
|
642 | + $msg[] = lang("==> different group '%1' under that gidNumber %2, NOT setting memberships!", $account['account_lid'], $account_id); |
|
645 | 643 | ++$errors; |
646 | - continue; // different group under that gidnumber! |
|
644 | + continue; // different group under that gidnumber! |
|
647 | 645 | } |
648 | 646 | } |
649 | 647 | // now saving / updating the memberships |
650 | - $accounts_obj->set_members($account['members'],$account_id); |
|
648 | + $accounts_obj->set_members($account['members'], $account_id); |
|
651 | 649 | } |
652 | 650 | } |
653 | 651 | if ($passwords2sql) |
654 | 652 | { |
655 | - return lang('%1 passwords updated, %3 errors',$accounts_created,$groups_created,$errors). |
|
656 | - ($errors || $this->verbose ? "\n- ".implode("\n- ",$msg) : ''); |
|
653 | + return lang('%1 passwords updated, %3 errors', $accounts_created, $groups_created, $errors). |
|
654 | + ($errors || $this->verbose ? "\n- ".implode("\n- ", $msg) : ''); |
|
657 | 655 | } |
658 | 656 | // migrate addressbook data |
659 | - $GLOBALS['egw_info']['user']['apps']['admin'] = true; // otherwise migration will not run in setup! |
|
657 | + $GLOBALS['egw_info']['user']['apps']['admin'] = true; // otherwise migration will not run in setup! |
|
660 | 658 | $addressbook = new addressbook_so(); |
661 | - foreach($this->as_array() as $name => $value) |
|
659 | + foreach ($this->as_array() as $name => $value) |
|
662 | 660 | { |
663 | 661 | if (substr($name, 5) == 'ldap_') |
664 | 662 | { |
@@ -671,8 +669,8 @@ discard block |
||
671 | 669 | |
672 | 670 | $this->restore_db(); |
673 | 671 | |
674 | - return lang('%1 users and %2 groups created, %3 errors',$accounts_created,$groups_created,$errors). |
|
675 | - ($errors || $this->verbose ? "\n- ".implode("\n- ",$msgs) : ''); |
|
672 | + return lang('%1 users and %2 groups created, %3 errors', $accounts_created, $groups_created, $errors). |
|
673 | + ($errors || $this->verbose ? "\n- ".implode("\n- ", $msgs) : ''); |
|
676 | 674 | } |
677 | 675 | |
678 | 676 | /** |
@@ -686,22 +684,22 @@ discard block |
||
686 | 684 | if (!($type = $GLOBALS['egw_info']['server']['sql_encryption_type'])) $type = 'md5'; |
687 | 685 | |
688 | 686 | $matches = null; |
689 | - if (preg_match('/^\\{(.*)\\}(.*)$/',$hash,$matches)) |
|
687 | + if (preg_match('/^\\{(.*)\\}(.*)$/', $hash, $matches)) |
|
690 | 688 | { |
691 | - list(,$type,$hash) = $matches; |
|
689 | + list(,$type, $hash) = $matches; |
|
692 | 690 | } |
693 | - elseif (preg_match('/^[0-9a-f]{32}$/',$hash)) |
|
691 | + elseif (preg_match('/^[0-9a-f]{32}$/', $hash)) |
|
694 | 692 | { |
695 | 693 | $type = 'md5'; |
696 | 694 | } |
697 | - switch(strtolower($type)) |
|
695 | + switch (strtolower($type)) |
|
698 | 696 | { |
699 | 697 | case 'plain': |
700 | 698 | // ldap stores plaintext passwords without {plain} prefix |
701 | 699 | break; |
702 | 700 | |
703 | 701 | case 'md5': |
704 | - $hash = base64_encode(pack("H*",$hash)); |
|
702 | + $hash = base64_encode(pack("H*", $hash)); |
|
705 | 703 | // fall through |
706 | 704 | default: |
707 | 705 | $hash = '{'.strtoupper($type).'}'.$hash; |
@@ -731,14 +729,14 @@ discard block |
||
731 | 729 | * @param string $type ='both' |
732 | 730 | * @return array |
733 | 731 | */ |
734 | - public function accounts($from='ldap', $type='both') |
|
732 | + public function accounts($from = 'ldap', $type = 'both') |
|
735 | 733 | { |
736 | 734 | $accounts_obj = $this->accounts_obj($from); |
737 | 735 | //error_log(__METHOD__."(from_ldap=".array2string($from_ldap).') get_class(accounts_obj->backend)='.get_class($accounts_obj->backend)); |
738 | 736 | |
739 | 737 | $accounts = $accounts_obj->search(array('type' => $type, 'objectclass' => true, 'active' => false)); |
740 | 738 | |
741 | - foreach($accounts as $account_id => &$account) |
|
739 | + foreach ($accounts as $account_id => &$account) |
|
742 | 740 | { |
743 | 741 | if ($account_id != $account['account_id']) // not all backends have as key the account_id |
744 | 742 | { |
@@ -749,11 +747,11 @@ discard block |
||
749 | 747 | |
750 | 748 | if ($account['account_type'] == 'g') |
751 | 749 | { |
752 | - $account['members'] = $accounts_obj->members($account_id,true); |
|
750 | + $account['members'] = $accounts_obj->members($account_id, true); |
|
753 | 751 | } |
754 | 752 | else |
755 | 753 | { |
756 | - $account['memberships'] = $accounts_obj->memberships($account_id,true); |
|
754 | + $account['memberships'] = $accounts_obj->memberships($account_id, true); |
|
757 | 755 | } |
758 | 756 | } |
759 | 757 | accounts::cache_invalidate(); |
@@ -769,13 +767,13 @@ discard block |
||
769 | 767 | */ |
770 | 768 | private function accounts_obj($type) |
771 | 769 | { |
772 | - static $enviroment_setup=null; |
|
770 | + static $enviroment_setup = null; |
|
773 | 771 | if (!$enviroment_setup) |
774 | 772 | { |
775 | 773 | parent::_setup_enviroment($this->domain); |
776 | 774 | $enviroment_setup = true; |
777 | 775 | } |
778 | - if ($type != 'sql') $this->connect(); // throws exception, if it can NOT connect |
|
776 | + if ($type != 'sql') $this->connect(); // throws exception, if it can NOT connect |
|
779 | 777 | |
780 | 778 | // otherwise search does NOT work, as accounts_sql uses addressbook_bo for it |
781 | 779 | $GLOBALS['egw_info']['server']['account_repository'] = $type; |
@@ -784,8 +782,8 @@ discard block |
||
784 | 782 | array( |
785 | 783 | 'account_repository' => $GLOBALS['egw_info']['server']['account_repository'], |
786 | 784 | ) + $this->as_array()) || |
787 | - !is_a(self::$egw_setup->accounts,'accounts') || |
|
788 | - !is_a(self::$egw_setup->accounts->backend,'accounts_'.$type)) |
|
785 | + !is_a(self::$egw_setup->accounts, 'accounts') || |
|
786 | + !is_a(self::$egw_setup->accounts->backend, 'accounts_'.$type)) |
|
789 | 787 | { |
790 | 788 | throw new Exception(lang("Can NOT instancate accounts object for %1", strtoupper($type))); |
791 | 789 | } |
@@ -800,7 +798,7 @@ discard block |
||
800 | 798 | * @param string $host =null default $this->ldap_host, hostname, ip or ldap-url |
801 | 799 | * @throws egw_exception_wrong_userinput Can not connect to ldap ... |
802 | 800 | */ |
803 | - private function connect($dn=null,$pw=null,$host=null) |
|
801 | + private function connect($dn = null, $pw = null, $host = null) |
|
804 | 802 | { |
805 | 803 | if (is_null($dn)) $dn = $this->ldap_root_dn; |
806 | 804 | if (is_null($pw)) $pw = $this->ldap_root_pw; |
@@ -813,18 +811,18 @@ discard block |
||
813 | 811 | $this->test_ldap = new ldap(); |
814 | 812 | |
815 | 813 | $error_rep = error_reporting(); |
816 | - error_reporting($error_rep & ~E_WARNING); // switch warnings of, in case they are on |
|
814 | + error_reporting($error_rep&~E_WARNING); // switch warnings of, in case they are on |
|
817 | 815 | ob_start(); |
818 | - $ds = $this->test_ldap->ldapConnect($host,$dn,$pw); |
|
816 | + $ds = $this->test_ldap->ldapConnect($host, $dn, $pw); |
|
819 | 817 | ob_end_clean(); |
820 | 818 | error_reporting($error_rep); |
821 | 819 | |
822 | 820 | if (!$ds) |
823 | 821 | { |
824 | 822 | throw new egw_exception_wrong_userinput(lang('Can not connect to LDAP server on host %1 using DN %2!', |
825 | - $host,$dn).($this->test_ldap->ds ? ' ('.ldap_error($this->test_ldap->ds).')' : '')); |
|
823 | + $host, $dn).($this->test_ldap->ds ? ' ('.ldap_error($this->test_ldap->ds).')' : '')); |
|
826 | 824 | } |
827 | - return lang('Successful connected to LDAP server on %1 using DN %2.',$this->ldap_host,$dn); |
|
825 | + return lang('Successful connected to LDAP server on %1 using DN %2.', $this->ldap_host, $dn); |
|
828 | 826 | } |
829 | 827 | |
830 | 828 | /** |
@@ -837,16 +835,16 @@ discard block |
||
837 | 835 | { |
838 | 836 | $this->connect(); |
839 | 837 | |
840 | - $sr = ldap_list($this->test_ldap->ds,$this->ldap_context,'ObjectClass=posixAccount',array('dn','shadowExpire')); |
|
838 | + $sr = ldap_list($this->test_ldap->ds, $this->ldap_context, 'ObjectClass=posixAccount', array('dn', 'shadowExpire')); |
|
841 | 839 | if (!($entries = ldap_get_entries($this->test_ldap->ds, $sr))) |
842 | 840 | { |
843 | - throw new egw_exception('Error listing "dn=%1"!',$this->ldap_context); |
|
841 | + throw new egw_exception('Error listing "dn=%1"!', $this->ldap_context); |
|
844 | 842 | } |
845 | 843 | $num = 0; |
846 | - foreach($entries as $n => $entry) |
|
844 | + foreach ($entries as $n => $entry) |
|
847 | 845 | { |
848 | 846 | if ($n === 'count') continue; |
849 | - if (isset($entry['shadowexpire']) && $entry['shadowexpire'][0]*24*3600 < time()) continue; |
|
847 | + if (isset($entry['shadowexpire']) && $entry['shadowexpire'][0] * 24 * 3600 < time()) continue; |
|
850 | 848 | ++$num; |
851 | 849 | } |
852 | 850 | return $num; |
@@ -860,23 +858,23 @@ discard block |
||
860 | 858 | */ |
861 | 859 | private function create() |
862 | 860 | { |
863 | - $this->connect($this->ldap_admin,$this->ldap_admin_pw); |
|
861 | + $this->connect($this->ldap_admin, $this->ldap_admin_pw); |
|
864 | 862 | |
865 | - foreach(array( |
|
863 | + foreach (array( |
|
866 | 864 | $this->ldap_base => array(), |
867 | 865 | $this->ldap_context => array(), |
868 | 866 | $this->ldap_group_context => array(), |
869 | - $this->ldap_root_dn => array('userPassword' => auth::encrypt_ldap($this->ldap_root_pw,'ssha')), |
|
867 | + $this->ldap_root_dn => array('userPassword' => auth::encrypt_ldap($this->ldap_root_pw, 'ssha')), |
|
870 | 868 | ) as $dn => $extra) |
871 | 869 | { |
872 | - if (!$this->_create_node($dn,$extra,$this->check_only) && $dn == $this->ldap_root_dn) |
|
870 | + if (!$this->_create_node($dn, $extra, $this->check_only) && $dn == $this->ldap_root_dn) |
|
873 | 871 | { |
874 | 872 | // ldap_root already existed, lets check the pw is correct |
875 | 873 | $this->connect(); |
876 | 874 | } |
877 | 875 | } |
878 | 876 | return lang('Successful connected to LDAP server on %1 and created/checked required structur %2.', |
879 | - $this->ldap_host,$this->ldap_base); |
|
877 | + $this->ldap_host, $this->ldap_base); |
|
880 | 878 | } |
881 | 879 | |
882 | 880 | /** |
@@ -887,25 +885,25 @@ discard block |
||
887 | 885 | */ |
888 | 886 | private function delete_base() |
889 | 887 | { |
890 | - $this->connect($this->ldap_admin,$this->ldap_admin_pw); |
|
888 | + $this->connect($this->ldap_admin, $this->ldap_admin_pw); |
|
891 | 889 | |
892 | 890 | // if base not set, use context minus one hierarchy, eg. ou=accounts,(o=domain,dc=local) |
893 | 891 | if (empty($this->ldap_base) && $this->ldap_context) |
894 | 892 | { |
895 | - list(,$this->ldap_base) = explode(',',$this->ldap_context,2); |
|
893 | + list(,$this->ldap_base) = explode(',', $this->ldap_context, 2); |
|
896 | 894 | } |
897 | 895 | // some precausion to not delete whole ldap tree! |
898 | - if (count(explode(',',$this->ldap_base)) < 2) |
|
896 | + if (count(explode(',', $this->ldap_base)) < 2) |
|
899 | 897 | { |
900 | - throw new egw_exception_assertion_failed(lang('Refusing to delete dn "%1"!',$this->ldap_base)); |
|
898 | + throw new egw_exception_assertion_failed(lang('Refusing to delete dn "%1"!', $this->ldap_base)); |
|
901 | 899 | } |
902 | 900 | // check if base does exist |
903 | - if (!@ldap_read($this->test_ldap->ds,$this->ldap_base,'objectClass=*')) |
|
901 | + if (!@ldap_read($this->test_ldap->ds, $this->ldap_base, 'objectClass=*')) |
|
904 | 902 | { |
905 | - throw new egw_exception_wrong_userinput(lang('Base dn "%1" NOT found!',$this->ldap_base)); |
|
903 | + throw new egw_exception_wrong_userinput(lang('Base dn "%1" NOT found!', $this->ldap_base)); |
|
906 | 904 | } |
907 | 905 | return lang('LDAP dn="%1" with %2 entries deleted.', |
908 | - $this->ldap_base,$this->rdelete($this->ldap_base)); |
|
906 | + $this->ldap_base, $this->rdelete($this->ldap_base)); |
|
909 | 907 | } |
910 | 908 | |
911 | 909 | /** |
@@ -917,20 +915,20 @@ discard block |
||
917 | 915 | */ |
918 | 916 | private function rdelete($dn) |
919 | 917 | { |
920 | - if (!($sr = ldap_list($this->test_ldap->ds,$dn,'ObjectClass=*',array(''))) || |
|
918 | + if (!($sr = ldap_list($this->test_ldap->ds, $dn, 'ObjectClass=*', array(''))) || |
|
921 | 919 | !($entries = ldap_get_entries($this->test_ldap->ds, $sr))) |
922 | 920 | { |
923 | - throw new egw_exception(lang('Error listing "dn=%1"!',$dn)); |
|
921 | + throw new egw_exception(lang('Error listing "dn=%1"!', $dn)); |
|
924 | 922 | } |
925 | 923 | $deleted = 0; |
926 | - foreach($entries as $n => $entry) |
|
924 | + foreach ($entries as $n => $entry) |
|
927 | 925 | { |
928 | 926 | if ($n === 'count') continue; |
929 | 927 | $deleted += $this->rdelete($entry['dn']); |
930 | 928 | } |
931 | - if (!ldap_delete($this->test_ldap->ds,$dn)) |
|
929 | + if (!ldap_delete($this->test_ldap->ds, $dn)) |
|
932 | 930 | { |
933 | - throw new egw_exception(lang('Error deleting "dn=%1"!',$dn)); |
|
931 | + throw new egw_exception(lang('Error deleting "dn=%1"!', $dn)); |
|
934 | 932 | } |
935 | 933 | return ++$deleted; |
936 | 934 | } |
@@ -946,32 +944,32 @@ discard block |
||
946 | 944 | * @return string with success message N entries modified |
947 | 945 | * @throws egw_exception if dn not found, not listable or delete fails |
948 | 946 | */ |
949 | - private function set_mailbox($check_only=false) |
|
947 | + private function set_mailbox($check_only = false) |
|
950 | 948 | { |
951 | - $this->connect($this->ldap_admin,$this->ldap_admin_pw); |
|
949 | + $this->connect($this->ldap_admin, $this->ldap_admin_pw); |
|
952 | 950 | |
953 | 951 | // if base not set, use context minus one hierarchy, eg. ou=accounts,(o=domain,dc=local) |
954 | 952 | if (empty($this->ldap_base) && $this->ldap_context) |
955 | 953 | { |
956 | - list(,$this->ldap_base) = explode(',',$this->ldap_context,2); |
|
954 | + list(,$this->ldap_base) = explode(',', $this->ldap_context, 2); |
|
957 | 955 | } |
958 | 956 | // check if base does exist |
959 | - if (!@ldap_read($this->test_ldap->ds,$this->ldap_base,'objectClass=*')) |
|
957 | + if (!@ldap_read($this->test_ldap->ds, $this->ldap_base, 'objectClass=*')) |
|
960 | 958 | { |
961 | - throw new egw_exception_wrong_userinput(lang('Base dn "%1" NOT found!',$this->ldap_base)); |
|
959 | + throw new egw_exception_wrong_userinput(lang('Base dn "%1" NOT found!', $this->ldap_base)); |
|
962 | 960 | } |
963 | 961 | $object_class = $this->object_class ? $this->object_class : 'qmailUser'; |
964 | 962 | $mbox_attr = $this->mbox_attr ? $this->mbox_attr : 'mailmessagestore'; |
965 | 963 | $mail_login_type = $this->mail_login_type ? $this->mail_login_type : 'email'; |
966 | 964 | |
967 | - if (!($sr = ldap_search($this->test_ldap->ds,$this->ldap_base, |
|
968 | - 'objectClass='.$object_class,array('mail','uidNumber','uid',$mbox_attr))) || |
|
965 | + if (!($sr = ldap_search($this->test_ldap->ds, $this->ldap_base, |
|
966 | + 'objectClass='.$object_class, array('mail', 'uidNumber', 'uid', $mbox_attr))) || |
|
969 | 967 | !($entries = ldap_get_entries($this->test_ldap->ds, $sr))) |
970 | 968 | { |
971 | - throw new egw_exception(lang('Error listing "dn=%1"!',$this->ldap_base)); |
|
969 | + throw new egw_exception(lang('Error listing "dn=%1"!', $this->ldap_base)); |
|
972 | 970 | } |
973 | 971 | $modified = 0; |
974 | - foreach($entries as $n => $entry) |
|
972 | + foreach ($entries as $n => $entry) |
|
975 | 973 | { |
976 | 974 | if ($n === 'count') continue; |
977 | 975 | |
@@ -979,21 +977,20 @@ discard block |
||
979 | 977 | 'account_id' => $entry['uidnumber'][0], |
980 | 978 | 'account_lid' => $entry['uid'][0], |
981 | 979 | 'account_email' => $entry['mail'][0], |
982 | - ),$this->domain,$mail_login_type); |
|
980 | + ), $this->domain, $mail_login_type); |
|
983 | 981 | |
984 | - if ($mbox === $entry[$mbox_attr][0]) continue; // nothing to change |
|
982 | + if ($mbox === $entry[$mbox_attr][0]) continue; // nothing to change |
|
985 | 983 | |
986 | - if (!$check_only && !ldap_modify($this->test_ldap->ds,$entry['dn'],array( |
|
984 | + if (!$check_only && !ldap_modify($this->test_ldap->ds, $entry['dn'], array( |
|
987 | 985 | $mbox_attr => $mbox, |
988 | 986 | ))) |
989 | 987 | { |
990 | - throw new egw_exception(lang("Error modifying dn=%1: %2='%3'!",$entry['dn'],$mbox_attr,$mbox)); |
|
988 | + throw new egw_exception(lang("Error modifying dn=%1: %2='%3'!", $entry['dn'], $mbox_attr, $mbox)); |
|
991 | 989 | } |
992 | 990 | ++$modified; |
993 | 991 | if ($check_only) echo "$modified: $entry[dn]: $mbox_attr={$entry[$mbox_attr][0]} --> $mbox\n"; |
994 | 992 | } |
995 | - return $check_only ? lang('%1 entries would have been modified.',$modified) : |
|
996 | - lang('%1 entries modified.',$modified); |
|
993 | + return $check_only ? lang('%1 entries would have been modified.', $modified) : lang('%1 entries modified.', $modified); |
|
997 | 994 | } |
998 | 995 | |
999 | 996 | /** |
@@ -1004,9 +1001,9 @@ discard block |
||
1004 | 1001 | static $requiredObjectclasses = array( |
1005 | 1002 | 'o' => 'organization', |
1006 | 1003 | 'ou' => 'organizationalUnit', |
1007 | - 'cn' => array('organizationalRole','simpleSecurityObject'), |
|
1008 | - 'uid' => array('uidObject','organizationalRole','simpleSecurityObject'), |
|
1009 | - 'dc' => array('organization','dcObject'), |
|
1004 | + 'cn' => array('organizationalRole', 'simpleSecurityObject'), |
|
1005 | + 'uid' => array('uidObject', 'organizationalRole', 'simpleSecurityObject'), |
|
1006 | + 'dc' => array('organization', 'dcObject'), |
|
1010 | 1007 | ); |
1011 | 1008 | |
1012 | 1009 | /** |
@@ -1017,37 +1014,37 @@ discard block |
||
1017 | 1014 | * @return boolean true if the node was create, false if it was already there |
1018 | 1015 | * @throws egw_exception_wrong_userinput |
1019 | 1016 | */ |
1020 | - private function _create_node($dn,$extra=array()) |
|
1017 | + private function _create_node($dn, $extra = array()) |
|
1021 | 1018 | { |
1022 | 1019 | // check if the node already exists and return if it does |
1023 | - if (@ldap_read($this->test_ldap->ds,$dn,'objectClass=*')) |
|
1020 | + if (@ldap_read($this->test_ldap->ds, $dn, 'objectClass=*')) |
|
1024 | 1021 | { |
1025 | 1022 | return false; |
1026 | 1023 | } |
1027 | - list($node,$base) = explode(',',$dn,2); |
|
1024 | + list($node, $base) = explode(',', $dn, 2); |
|
1028 | 1025 | |
1029 | - if (!@ldap_read($this->test_ldap->ds,$base,'objectClass=*')) |
|
1026 | + if (!@ldap_read($this->test_ldap->ds, $base, 'objectClass=*')) |
|
1030 | 1027 | { |
1031 | - $this->_create_node($base); // create the base if it's not already there |
|
1028 | + $this->_create_node($base); // create the base if it's not already there |
|
1032 | 1029 | } |
1033 | 1030 | // now we need to create the node itself |
1034 | - list($name,$value) = explode('=',$node); |
|
1031 | + list($name, $value) = explode('=', $node); |
|
1035 | 1032 | |
1036 | 1033 | if (!isset(self::$requiredObjectclasses[$name])) |
1037 | 1034 | { |
1038 | - throw new egw_exception_wrong_userinput(lang('Can not create DN %1!',$dn).' '. |
|
1039 | - lang('Supported node types:').implode(', ',array_keys(self::$requiredObjectclasses))); |
|
1035 | + throw new egw_exception_wrong_userinput(lang('Can not create DN %1!', $dn).' '. |
|
1036 | + lang('Supported node types:').implode(', ', array_keys(self::$requiredObjectclasses))); |
|
1040 | 1037 | } |
1041 | - if ($name == 'dc') $extra['o'] = $value; // required by organisation |
|
1042 | - if ($name == 'uid') $extra['cn'] = $value; // required by organizationalRole |
|
1038 | + if ($name == 'dc') $extra['o'] = $value; // required by organisation |
|
1039 | + if ($name == 'uid') $extra['cn'] = $value; // required by organizationalRole |
|
1043 | 1040 | |
1044 | - if (!@ldap_add($this->test_ldap->ds,$dn,$attr = array( |
|
1041 | + if (!@ldap_add($this->test_ldap->ds, $dn, $attr = array( |
|
1045 | 1042 | $name => $value, |
1046 | 1043 | 'objectClass' => self::$requiredObjectclasses[$name], |
1047 | - )+$extra)) |
|
1044 | + ) + $extra)) |
|
1048 | 1045 | { |
1049 | - throw new egw_exception_wrong_userinput(lang('Can not create DN %1!',$dn). |
|
1050 | - ' ('.ldap_error($this->test_ldap->ds).', attributes='.print_r($attr,true).')'); |
|
1046 | + throw new egw_exception_wrong_userinput(lang('Can not create DN %1!', $dn). |
|
1047 | + ' ('.ldap_error($this->test_ldap->ds).', attributes='.print_r($attr, true).')'); |
|
1051 | 1048 | } |
1052 | 1049 | return true; |
1053 | 1050 | } |
@@ -1078,30 +1075,30 @@ discard block |
||
1078 | 1075 | */ |
1079 | 1076 | private function _merge_defaults() |
1080 | 1077 | { |
1081 | - foreach(self::defaults() as $name => $default) |
|
1078 | + foreach (self::defaults() as $name => $default) |
|
1082 | 1079 | { |
1083 | - if ($this->sub_command == 'delete_ldap' && in_array($name,array('ldap_base','ldap_context'))) |
|
1080 | + if ($this->sub_command == 'delete_ldap' && in_array($name, array('ldap_base', 'ldap_context'))) |
|
1084 | 1081 | { |
1085 | - continue; // no default on what to delete! |
|
1082 | + continue; // no default on what to delete! |
|
1086 | 1083 | } |
1087 | 1084 | if (!$this->$name) |
1088 | 1085 | { |
1089 | 1086 | //echo "<p>setting $name='{$this->$name}' to it's default='$default'</p>\n"; |
1090 | 1087 | $this->set_defaults[$name] = $this->$name = $default; |
1091 | 1088 | } |
1092 | - if (strpos($this->$name,'$') !== false) |
|
1089 | + if (strpos($this->$name, '$') !== false) |
|
1093 | 1090 | { |
1094 | 1091 | $this->set_defaults[$name] = $this->$name = str_replace(array( |
1095 | 1092 | '$domain', |
1096 | 1093 | '$suffix', |
1097 | 1094 | '$base', |
1098 | 1095 | '$admin_pw', |
1099 | - ),array( |
|
1096 | + ), array( |
|
1100 | 1097 | $this->domain, |
1101 | 1098 | $this->ldap_suffix, |
1102 | 1099 | $this->ldap_base, |
1103 | 1100 | $this->ldap_admin_pw, |
1104 | - ),$this->$name); |
|
1101 | + ), $this->$name); |
|
1105 | 1102 | } |
1106 | 1103 | } |
1107 | 1104 | } |
@@ -201,7 +201,10 @@ discard block |
||
201 | 201 | $change_account_id = ''; |
202 | 202 | foreach($entries as $key => $entry) |
203 | 203 | { |
204 | - if ($key === 'count') continue; |
|
204 | + if ($key === 'count') |
|
205 | + { |
|
206 | + continue; |
|
207 | + } |
|
205 | 208 | |
206 | 209 | $entry = ldap::result2array($entry); |
207 | 210 | $accounts[$entry['dn']] = $entry; |
@@ -228,7 +231,10 @@ discard block |
||
228 | 231 | //print_r($change); die('Stop'); |
229 | 232 | |
230 | 233 | // change account-ids inside EGroupware |
231 | - if ($check_only) $msg[] = "You need to run now:\n$cmd_change_account_id $change_account_id"; |
|
234 | + if ($check_only) |
|
235 | + { |
|
236 | + $msg[] = "You need to run now:\n$cmd_change_account_id $change_account_id"; |
|
237 | + } |
|
232 | 238 | //$cmd = new admin_cmd_change_account_id($change); |
233 | 239 | //$msg[] = $cmd->run($time=null, $set_modifier=false, $skip_checks=false, $check_only); |
234 | 240 | |
@@ -250,7 +256,10 @@ discard block |
||
250 | 256 | throw new egw_exception("Failed to modify ldap: !ldap_modify({$this->test_ldap->ds}, '$dn', ".array2string($modify).") ".ldap_error($this->test_ldap->ds). |
251 | 257 | "\n- ".implode("\n- ", $msg)); // EGroupware change already run successful |
252 | 258 | } |
253 | - if ($modify) ++$changed; |
|
259 | + if ($modify) |
|
260 | + { |
|
261 | + ++$changed; |
|
262 | + } |
|
254 | 263 | } |
255 | 264 | $msg[] = "You need to run now on your samba share(s):\nsetup/doc/chown.php -R $change_account_id <share>"; |
256 | 265 | |
@@ -277,7 +286,10 @@ discard block |
||
277 | 286 | else |
278 | 287 | { |
279 | 288 | list($to, $from) = explode('=', $attr); |
280 | - if ($from) $attrs[] = $from; |
|
289 | + if ($from) |
|
290 | + { |
|
291 | + $attrs[] = $from; |
|
292 | + } |
|
281 | 293 | $rename[strtolower($from)] = $to; |
282 | 294 | } |
283 | 295 | } |
@@ -292,7 +304,10 @@ discard block |
||
292 | 304 | { |
293 | 305 | $this->ads_context = 'CN=Users,DC='.implode(',DC=', explode('.', $this->ads_domain)); |
294 | 306 | } |
295 | - if (empty($this->ads_admin_user)) $this->ads_admin_user = 'Administrator'; |
|
307 | + if (empty($this->ads_admin_user)) |
|
308 | + { |
|
309 | + $this->ads_admin_user = 'Administrator'; |
|
310 | + } |
|
296 | 311 | $admin_dn = strpos($this->ads_admin_user, '=') !== false ? $this->ads_admin_user : |
297 | 312 | 'CN='.$this->ads_admin_user.','.$this->ads_context; |
298 | 313 | switch($this->ads_connection) |
@@ -336,7 +351,10 @@ discard block |
||
336 | 351 | $utc_diff = null; |
337 | 352 | foreach($entries as $key => $entry) |
338 | 353 | { |
339 | - if ($key === 'count') continue; |
|
354 | + if ($key === 'count') |
|
355 | + { |
|
356 | + continue; |
|
357 | + } |
|
340 | 358 | |
341 | 359 | $entry_arr = ldap::result2array($entry); |
342 | 360 | $uid = $entry_arr['uid']; |
@@ -350,7 +368,10 @@ discard block |
||
350 | 368 | continue; |
351 | 369 | } |
352 | 370 | $dn = $dest[0]['dn']; |
353 | - if (isset($rename[''])) $entry[''] = ''; |
|
371 | + if (isset($rename[''])) |
|
372 | + { |
|
373 | + $entry[''] = ''; |
|
374 | + } |
|
354 | 375 | // special handling for copying shadowExpires to accountExpires |
355 | 376 | if (strtolower($rename['shadowexpire']) === 'accountexpires') |
356 | 377 | { |
@@ -361,7 +382,10 @@ discard block |
||
361 | 382 | } |
362 | 383 | else |
363 | 384 | { |
364 | - if (is_null($utc_diff)) $utc_diff = date('Z'); |
|
385 | + if (is_null($utc_diff)) |
|
386 | + { |
|
387 | + $utc_diff = date('Z'); |
|
388 | + } |
|
365 | 389 | $entry['shadowexpire'] = accounts_ads::convertUnixTimeToWindowsTime( |
366 | 390 | $entry['shadowexpire']*24*3600+$utc_diff); // ldap time to unixTime |
367 | 391 | } |
@@ -373,20 +397,29 @@ discard block |
||
373 | 397 | { |
374 | 398 | $to = isset($rename[$attr]) ? $rename[$attr] : $attr; |
375 | 399 | $prefix = null; |
376 | - if ($to[0] == '{') // eg. {smtp:}proxyAddresses=forwardTo |
|
400 | + if ($to[0] == '{') |
|
401 | + { |
|
402 | + // eg. {smtp:}proxyAddresses=forwardTo |
|
377 | 403 | { |
378 | 404 | list($prefix, $to) = explode('}', substr($to, 1)); |
379 | 405 | } |
406 | + } |
|
380 | 407 | foreach((array)$value as $val) |
381 | 408 | { |
382 | 409 | if (isset($update[$to])) |
383 | 410 | { |
384 | - if (!is_array($update[$to])) $update[$to] = array($update[$to]); |
|
411 | + if (!is_array($update[$to])) |
|
412 | + { |
|
413 | + $update[$to] = array($update[$to]); |
|
414 | + } |
|
385 | 415 | // we need to check (caseinsensitive) if value already exists in set |
386 | 416 | // as AD chokes on doublicate values "Type or value exists" |
387 | 417 | foreach($update[$to] as $v) |
388 | 418 | { |
389 | - if (!strcasecmp($v, $prefix.$val)) continue 2; |
|
419 | + if (!strcasecmp($v, $prefix.$val)) |
|
420 | + { |
|
421 | + continue 2; |
|
422 | + } |
|
390 | 423 | } |
391 | 424 | $update[$to][] = $prefix.$val; |
392 | 425 | } |
@@ -413,7 +446,10 @@ discard block |
||
413 | 446 | $changed++; |
414 | 447 | } |
415 | 448 | } |
416 | - if ($check_only) return lang("%1 accounts to copy found.", count($entries)); |
|
449 | + if ($check_only) |
|
450 | + { |
|
451 | + return lang("%1 accounts to copy found.", count($entries)); |
|
452 | + } |
|
417 | 453 | |
418 | 454 | return "Copied data of $changed accounts from LDAP to AD ". |
419 | 455 | (count($msg) > $changed ? ' ('.(count($msg)-$changed).' errors!)' : ''); |
@@ -429,7 +465,10 @@ discard block |
||
429 | 465 | private function migrate($mode) |
430 | 466 | { |
431 | 467 | // support old boolean mode |
432 | - if (is_bool($mode)) $mode = $mode ? 'migrate_to_ldap' : 'migrate_to_sql'; |
|
468 | + if (is_bool($mode)) |
|
469 | + { |
|
470 | + $mode = $mode ? 'migrate_to_ldap' : 'migrate_to_sql'; |
|
471 | + } |
|
433 | 472 | |
434 | 473 | $passwords2sql = $mode === "passwords_to_sql"; |
435 | 474 | list(,$to) = explode('_to_', $mode); |
@@ -596,7 +635,10 @@ discard block |
||
596 | 635 | { |
597 | 636 | foreach(array('ldap_host','ldap_root_dn','ldap_root_pw','ldap_context','ldap_group_context','ldap_search_filter','ldap_encryptin_type','mail_suffix','mail_login_type') as $name) |
598 | 637 | { |
599 | - if (!empty($this->$name)) $GLOBALS['egw_info']['server'][$name] = $this->$name; |
|
638 | + if (!empty($this->$name)) |
|
639 | + { |
|
640 | + $GLOBALS['egw_info']['server'][$name] = $this->$name; |
|
641 | + } |
|
600 | 642 | } |
601 | 643 | //error_log(__METHOD__."() setup up egw_info[server]: ldap_host='{$GLOBALS['egw_info']['server']['ldap_host']}', ldap_root_dn='{$GLOBALS['egw_info']['server']['ldap_root_dn']}', ldap_root_pw='{$GLOBALS['egw_info']['server']['ldap_root_pw']}', ldap_context='{$GLOBALS['egw_info']['server']['ldap_context']}', mail_suffix='{$GLOBALS['egw_info']['server']['mail_suffix']}', mail_logig_type='{$GLOBALS['egw_info']['server']['mail_login-type']}'"); |
602 | 644 | } |
@@ -683,7 +725,10 @@ discard block |
||
683 | 725 | */ |
684 | 726 | public static function hash_sql2ldap($hash) |
685 | 727 | { |
686 | - if (!($type = $GLOBALS['egw_info']['server']['sql_encryption_type'])) $type = 'md5'; |
|
728 | + if (!($type = $GLOBALS['egw_info']['server']['sql_encryption_type'])) |
|
729 | + { |
|
730 | + $type = 'md5'; |
|
731 | + } |
|
687 | 732 | |
688 | 733 | $matches = null; |
689 | 734 | if (preg_match('/^\\{(.*)\\}(.*)$/',$hash,$matches)) |
@@ -717,10 +762,13 @@ discard block |
||
717 | 762 | */ |
718 | 763 | public static function hash_ldap2sql($hash) |
719 | 764 | { |
720 | - if ($hash[0] != '{') // plain has to be explicitly specified for sql, in ldap it's the default |
|
765 | + if ($hash[0] != '{') |
|
766 | + { |
|
767 | + // plain has to be explicitly specified for sql, in ldap it's the default |
|
721 | 768 | { |
722 | 769 | $hash = '{PLAIN}'.$hash; |
723 | 770 | } |
771 | + } |
|
724 | 772 | return $hash; |
725 | 773 | } |
726 | 774 | |
@@ -740,9 +788,12 @@ discard block |
||
740 | 788 | |
741 | 789 | foreach($accounts as $account_id => &$account) |
742 | 790 | { |
743 | - if ($account_id != $account['account_id']) // not all backends have as key the account_id |
|
791 | + if ($account_id != $account['account_id']) |
|
792 | + { |
|
793 | + // not all backends have as key the account_id |
|
744 | 794 | { |
745 | 795 | unset($account); |
796 | + } |
|
746 | 797 | $account_id = $account['account_id']; |
747 | 798 | } |
748 | 799 | $account += $accounts_obj->read($account_id); |
@@ -775,7 +826,11 @@ discard block |
||
775 | 826 | parent::_setup_enviroment($this->domain); |
776 | 827 | $enviroment_setup = true; |
777 | 828 | } |
778 | - if ($type != 'sql') $this->connect(); // throws exception, if it can NOT connect |
|
829 | + if ($type != 'sql') |
|
830 | + { |
|
831 | + $this->connect(); |
|
832 | + } |
|
833 | + // throws exception, if it can NOT connect |
|
779 | 834 | |
780 | 835 | // otherwise search does NOT work, as accounts_sql uses addressbook_bo for it |
781 | 836 | $GLOBALS['egw_info']['server']['account_repository'] = $type; |
@@ -802,14 +857,26 @@ discard block |
||
802 | 857 | */ |
803 | 858 | private function connect($dn=null,$pw=null,$host=null) |
804 | 859 | { |
805 | - if (is_null($dn)) $dn = $this->ldap_root_dn; |
|
806 | - if (is_null($pw)) $pw = $this->ldap_root_pw; |
|
807 | - if (is_null($host)) $host = $this->ldap_host; |
|
860 | + if (is_null($dn)) |
|
861 | + { |
|
862 | + $dn = $this->ldap_root_dn; |
|
863 | + } |
|
864 | + if (is_null($pw)) |
|
865 | + { |
|
866 | + $pw = $this->ldap_root_pw; |
|
867 | + } |
|
868 | + if (is_null($host)) |
|
869 | + { |
|
870 | + $host = $this->ldap_host; |
|
871 | + } |
|
808 | 872 | |
809 | - if (!$pw) // ldap::ldapConnect use the current eGW's pw otherwise |
|
873 | + if (!$pw) |
|
874 | + { |
|
875 | + // ldap::ldapConnect use the current eGW's pw otherwise |
|
810 | 876 | { |
811 | 877 | throw new egw_exception_wrong_userinput(lang('You need to specify a password!')); |
812 | 878 | } |
879 | + } |
|
813 | 880 | $this->test_ldap = new ldap(); |
814 | 881 | |
815 | 882 | $error_rep = error_reporting(); |
@@ -845,8 +912,14 @@ discard block |
||
845 | 912 | $num = 0; |
846 | 913 | foreach($entries as $n => $entry) |
847 | 914 | { |
848 | - if ($n === 'count') continue; |
|
849 | - if (isset($entry['shadowexpire']) && $entry['shadowexpire'][0]*24*3600 < time()) continue; |
|
915 | + if ($n === 'count') |
|
916 | + { |
|
917 | + continue; |
|
918 | + } |
|
919 | + if (isset($entry['shadowexpire']) && $entry['shadowexpire'][0]*24*3600 < time()) |
|
920 | + { |
|
921 | + continue; |
|
922 | + } |
|
850 | 923 | ++$num; |
851 | 924 | } |
852 | 925 | return $num; |
@@ -925,7 +998,10 @@ discard block |
||
925 | 998 | $deleted = 0; |
926 | 999 | foreach($entries as $n => $entry) |
927 | 1000 | { |
928 | - if ($n === 'count') continue; |
|
1001 | + if ($n === 'count') |
|
1002 | + { |
|
1003 | + continue; |
|
1004 | + } |
|
929 | 1005 | $deleted += $this->rdelete($entry['dn']); |
930 | 1006 | } |
931 | 1007 | if (!ldap_delete($this->test_ldap->ds,$dn)) |
@@ -973,7 +1049,10 @@ discard block |
||
973 | 1049 | $modified = 0; |
974 | 1050 | foreach($entries as $n => $entry) |
975 | 1051 | { |
976 | - if ($n === 'count') continue; |
|
1052 | + if ($n === 'count') |
|
1053 | + { |
|
1054 | + continue; |
|
1055 | + } |
|
977 | 1056 | |
978 | 1057 | $mbox = emailadmin_smtp_ldap::mailbox_addr(array( |
979 | 1058 | 'account_id' => $entry['uidnumber'][0], |
@@ -981,7 +1060,11 @@ discard block |
||
981 | 1060 | 'account_email' => $entry['mail'][0], |
982 | 1061 | ),$this->domain,$mail_login_type); |
983 | 1062 | |
984 | - if ($mbox === $entry[$mbox_attr][0]) continue; // nothing to change |
|
1063 | + if ($mbox === $entry[$mbox_attr][0]) |
|
1064 | + { |
|
1065 | + continue; |
|
1066 | + } |
|
1067 | + // nothing to change |
|
985 | 1068 | |
986 | 1069 | if (!$check_only && !ldap_modify($this->test_ldap->ds,$entry['dn'],array( |
987 | 1070 | $mbox_attr => $mbox, |
@@ -990,7 +1073,10 @@ discard block |
||
990 | 1073 | throw new egw_exception(lang("Error modifying dn=%1: %2='%3'!",$entry['dn'],$mbox_attr,$mbox)); |
991 | 1074 | } |
992 | 1075 | ++$modified; |
993 | - if ($check_only) echo "$modified: $entry[dn]: $mbox_attr={$entry[$mbox_attr][0]} --> $mbox\n"; |
|
1076 | + if ($check_only) |
|
1077 | + { |
|
1078 | + echo "$modified: $entry[dn]: $mbox_attr={$entry[$mbox_attr][0]} --> $mbox\n"; |
|
1079 | + } |
|
994 | 1080 | } |
995 | 1081 | return $check_only ? lang('%1 entries would have been modified.',$modified) : |
996 | 1082 | lang('%1 entries modified.',$modified); |
@@ -1038,8 +1124,16 @@ discard block |
||
1038 | 1124 | throw new egw_exception_wrong_userinput(lang('Can not create DN %1!',$dn).' '. |
1039 | 1125 | lang('Supported node types:').implode(', ',array_keys(self::$requiredObjectclasses))); |
1040 | 1126 | } |
1041 | - if ($name == 'dc') $extra['o'] = $value; // required by organisation |
|
1042 | - if ($name == 'uid') $extra['cn'] = $value; // required by organizationalRole |
|
1127 | + if ($name == 'dc') |
|
1128 | + { |
|
1129 | + $extra['o'] = $value; |
|
1130 | + } |
|
1131 | + // required by organisation |
|
1132 | + if ($name == 'uid') |
|
1133 | + { |
|
1134 | + $extra['cn'] = $value; |
|
1135 | + } |
|
1136 | + // required by organizationalRole |
|
1043 | 1137 | |
1044 | 1138 | if (!@ldap_add($this->test_ldap->ds,$dn,$attr = array( |
1045 | 1139 | $name => $value, |
@@ -252,7 +252,7 @@ |
||
252 | 252 | /** |
253 | 253 | * Check if header exists and is up to date |
254 | 254 | * |
255 | - * @return int 1=no header.inc.php, 2=no header admin pw, 3=no instances, 4=need upgrade, 10=ok |
|
255 | + * @return string 1=no header.inc.php, 2=no header admin pw, 3=no instances, 4=need upgrade, 10=ok |
|
256 | 256 | */ |
257 | 257 | function check_header() |
258 | 258 | { |
@@ -65,7 +65,9 @@ discard block |
||
65 | 65 | foreach($GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->applications_table,'*',false,__LINE__,__FILE__) as $row) |
66 | 66 | { |
67 | 67 | $app = $row['app_name']; |
68 | - if (!isset($setup_info[$app])) // app source no longer there |
|
68 | + if (!isset($setup_info[$app])) |
|
69 | + { |
|
70 | + // app source no longer there |
|
69 | 71 | { |
70 | 72 | $setup_info[$app] = array( |
71 | 73 | 'name' => $app, |
@@ -73,6 +75,7 @@ discard block |
||
73 | 75 | 'version' => 'deleted', |
74 | 76 | ); |
75 | 77 | } |
78 | + } |
|
76 | 79 | $setup_info[$app]['currentver'] = $row['app_version']; |
77 | 80 | $setup_info[$app]['enabled'] = $row['app_enabled']; |
78 | 81 | } |
@@ -212,7 +215,9 @@ discard block |
||
212 | 215 | if ($setup_info['depends'][$depkey]['status'] == False) |
213 | 216 | { |
214 | 217 | /* Only set this if it has not already failed to upgrade - Milosch */ |
215 | - if($setup_info[$key]['status'] != 'F')//&& $setup_info[$key]['status'] != 'C') |
|
218 | + if($setup_info[$key]['status'] != 'F') |
|
219 | + { |
|
220 | + //&& $setup_info[$key]['status'] != 'C') |
|
216 | 221 | { |
217 | 222 | /* Added check for status U - uninstalled apps carry this flag (upgrade from nothing == install). |
218 | 223 | * This should fix apps showing post-install dep failure when they are not yet installed. |
@@ -220,6 +225,7 @@ discard block |
||
220 | 225 | if($setup_info[$key]['status'] == 'C' || $setup_info[$key]['status'] == 'U') |
221 | 226 | { |
222 | 227 | $setup_info[$key]['status'] = 'D'; |
228 | + } |
|
223 | 229 | } |
224 | 230 | else |
225 | 231 | { |
@@ -292,7 +298,10 @@ discard block |
||
292 | 298 | */ |
293 | 299 | function check_db($setup_info=null) |
294 | 300 | { |
295 | - if (!$setup_info) $setup_info = $GLOBALS['setup_info']; |
|
301 | + if (!$setup_info) |
|
302 | + { |
|
303 | + $setup_info = $GLOBALS['setup_info']; |
|
304 | + } |
|
296 | 305 | |
297 | 306 | try { // catch DB errors |
298 | 307 | if (!$GLOBALS['egw_setup']->db->Link_ID) |
@@ -482,11 +491,14 @@ discard block |
||
482 | 491 | { |
483 | 492 | echo '<br>check_app_tables(): Checking: ' . $appname . ',table: ' . $val; |
484 | 493 | } |
485 | - if(!in_array($val,$tables) && !in_array(strtolower($val),$tables)) // names in tables might be lowercase |
|
494 | + if(!in_array($val,$tables) && !in_array(strtolower($val),$tables)) |
|
495 | + { |
|
496 | + // names in tables might be lowercase |
|
486 | 497 | { |
487 | 498 | if($GLOBALS['DEBUG']) |
488 | 499 | { |
489 | 500 | echo '<br>check_app_tables(): ' . $val . ' missing!'; |
501 | + } |
|
490 | 502 | } |
491 | 503 | if(!$any) |
492 | 504 | { |
@@ -543,9 +555,12 @@ discard block |
||
543 | 555 | $msg = lang('does not exist'); |
544 | 556 | return false; |
545 | 557 | } |
546 | - if (!@is_writeable($dir) && $_SERVER['HTTP_HOST']) // only do the check if we run by the webserver |
|
558 | + if (!@is_writeable($dir) && $_SERVER['HTTP_HOST']) |
|
559 | + { |
|
560 | + // only do the check if we run by the webserver |
|
547 | 561 | { |
548 | 562 | $msg = lang('is not writeable by the webserver'); |
563 | + } |
|
549 | 564 | return false; |
550 | 565 | } |
551 | 566 | if ($check_in_docroot) |
@@ -464,7 +464,7 @@ |
||
464 | 464 | { |
465 | 465 | /* Make a copy, else we send some callers into an infinite loop */ |
466 | 466 | $copy = $setup_info; |
467 | - $tables = Array(); |
|
467 | + $tables = array(); |
|
468 | 468 | try { |
469 | 469 | $table_names = $GLOBALS['egw_setup']->db->table_names(); |
470 | 470 | foreach($table_names as $key => $val) |
@@ -25,12 +25,12 @@ discard block |
||
25 | 25 | { |
26 | 26 | $setup_info = array(); |
27 | 27 | $d = dir(EGW_SERVER_ROOT); |
28 | - while($entry=$d->read()) |
|
28 | + while ($entry = $d->read()) |
|
29 | 29 | { |
30 | - if($entry != ".." && $entry != 'setup' && is_dir(EGW_SERVER_ROOT . '/' . $entry)) |
|
30 | + if ($entry != ".." && $entry != 'setup' && is_dir(EGW_SERVER_ROOT.'/'.$entry)) |
|
31 | 31 | { |
32 | - $f = EGW_SERVER_ROOT . '/' . $entry . '/setup/setup.inc.php'; |
|
33 | - if (@file_exists ($f)) |
|
32 | + $f = EGW_SERVER_ROOT.'/'.$entry.'/setup/setup.inc.php'; |
|
33 | + if (@file_exists($f)) |
|
34 | 34 | { |
35 | 35 | include($f); |
36 | 36 | $setup_info[$entry]['filename'] = $f; |
@@ -50,18 +50,18 @@ discard block |
||
50 | 50 | * @param array $setup_info |
51 | 51 | * @return array $setup_info |
52 | 52 | */ |
53 | - function get_db_versions($setup_info=null) |
|
53 | + function get_db_versions($setup_info = null) |
|
54 | 54 | { |
55 | 55 | try { // catch DB errors |
56 | 56 | $GLOBALS['egw_setup']->set_table_names(); |
57 | 57 | |
58 | - if($GLOBALS['egw_setup']->table_exist(array($GLOBALS['egw_setup']->applications_table),true)) |
|
58 | + if ($GLOBALS['egw_setup']->table_exist(array($GLOBALS['egw_setup']->applications_table), true)) |
|
59 | 59 | { |
60 | 60 | /* one of these tables exists. checking for post/pre beta version */ |
61 | - if($GLOBALS['egw_setup']->applications_table != 'applications') |
|
61 | + if ($GLOBALS['egw_setup']->applications_table != 'applications') |
|
62 | 62 | { |
63 | - $GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->applications_table,'*',false,__LINE__,__FILE__); |
|
64 | - while(@$GLOBALS['egw_setup']->db->next_record()) |
|
63 | + $GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->applications_table, '*', false, __LINE__, __FILE__); |
|
64 | + while (@$GLOBALS['egw_setup']->db->next_record()) |
|
65 | 65 | { |
66 | 66 | $app = $GLOBALS['egw_setup']->db->f('app_name'); |
67 | 67 | if (!isset($setup_info[$app])) // app source no longer there |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | } |
78 | 78 | /* This is to catch old setup installs that did not have phpgwapi listed as an app */ |
79 | 79 | $tmp = @$setup_info['phpgwapi']['version']; /* save the file version */ |
80 | - if(!@$setup_info['phpgwapi']['currentver']) |
|
80 | + if (!@$setup_info['phpgwapi']['currentver']) |
|
81 | 81 | { |
82 | 82 | $setup_info['phpgwapi']['currentver'] = $setup_info['admin']['currentver']; |
83 | 83 | $setup_info['phpgwapi']['version'] = $setup_info['admin']['currentver']; |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | else |
98 | 98 | { |
99 | 99 | $GLOBALS['egw_setup']->db->query('select * from applications'); |
100 | - while(@$GLOBALS['egw_setup']->db->next_record()) |
|
100 | + while (@$GLOBALS['egw_setup']->db->next_record()) |
|
101 | 101 | { |
102 | - if($GLOBALS['egw_setup']->db->f('app_name') == 'admin') |
|
102 | + if ($GLOBALS['egw_setup']->db->f('app_name') == 'admin') |
|
103 | 103 | { |
104 | 104 | $setup_info['phpgwapi']['currentver'] = $GLOBALS['egw_setup']->db->f('app_version'); |
105 | 105 | } |
@@ -127,25 +127,25 @@ discard block |
||
127 | 127 | * V Version mismatch at end of upgrade (Not used, proposed only) |
128 | 128 | * M Missing files at start of upgrade (Not used, proposed only) |
129 | 129 | */ |
130 | - function compare_versions($setup_info,$try_downgrade=false) |
|
130 | + function compare_versions($setup_info, $try_downgrade = false) |
|
131 | 131 | { |
132 | - foreach($setup_info as $key => $value) |
|
132 | + foreach ($setup_info as $key => $value) |
|
133 | 133 | { |
134 | 134 | //echo '<br>'.$value['name'].'STATUS: '.$value['status']; |
135 | 135 | /* Only set this if it has not already failed to upgrade - Milosch */ |
136 | - if(!( (@$value['status'] == 'F') || (@$value['status'] == 'C') )) |
|
136 | + if (!((@$value['status'] == 'F') || (@$value['status'] == 'C'))) |
|
137 | 137 | { |
138 | 138 | //if ($setup_info[$key]['currentver'] > $setup_info[$key]['version']) |
139 | - if(!$try_downgrade && $GLOBALS['egw_setup']->amorethanb($value['currentver'],@$value['version']) || |
|
139 | + if (!$try_downgrade && $GLOBALS['egw_setup']->amorethanb($value['currentver'], @$value['version']) || |
|
140 | 140 | $value['version'] == 'deleted') |
141 | 141 | { |
142 | 142 | $setup_info[$key]['status'] = 'V'; |
143 | 143 | } |
144 | - elseif(@$value['currentver'] == @$value['version']) |
|
144 | + elseif (@$value['currentver'] == @$value['version']) |
|
145 | 145 | { |
146 | 146 | $setup_info[$key]['status'] = 'C'; |
147 | 147 | } |
148 | - elseif($GLOBALS['egw_setup']->alessthanb(@$value['currentver'],@$value['version'])) |
|
148 | + elseif ($GLOBALS['egw_setup']->alessthanb(@$value['currentver'], @$value['version'])) |
|
149 | 149 | { |
150 | 150 | $setup_info[$key]['status'] = 'U'; |
151 | 151 | } |
@@ -162,35 +162,35 @@ discard block |
||
162 | 162 | function check_depends($setup_info) |
163 | 163 | { |
164 | 164 | /* Run the list of apps */ |
165 | - foreach($setup_info as $key => $value) |
|
165 | + foreach ($setup_info as $key => $value) |
|
166 | 166 | { |
167 | 167 | /* Does this app have any depends */ |
168 | - if(isset($value['depends'])) |
|
168 | + if (isset($value['depends'])) |
|
169 | 169 | { |
170 | 170 | /* If so find out which apps it depends on */ |
171 | - foreach($value['depends'] as $depkey => $depvalue) |
|
171 | + foreach ($value['depends'] as $depkey => $depvalue) |
|
172 | 172 | { |
173 | 173 | /* I set this to False until we find a compatible version of this app */ |
174 | 174 | $setup_info['depends'][$depkey]['status'] = False; |
175 | 175 | /* Now we loop thru the versions looking for a compatible version */ |
176 | 176 | |
177 | - foreach($depvalue['versions'] as $depsvalue) |
|
177 | + foreach ($depvalue['versions'] as $depsvalue) |
|
178 | 178 | { |
179 | 179 | $currentver = $setup_info[$depvalue['appname']]['currentver']; |
180 | - if ($depvalue['appname'] == 'phpgwapi' && substr($currentver,0,6) == '0.9.99') |
|
180 | + if ($depvalue['appname'] == 'phpgwapi' && substr($currentver, 0, 6) == '0.9.99') |
|
181 | 181 | { |
182 | 182 | $currentver = '0.9.14.508'; |
183 | 183 | } |
184 | 184 | $major = $GLOBALS['egw_setup']->get_major($currentver); |
185 | - if ($major >= $depsvalue || $major == $depsvalue && substr($major,0,strlen($depsvalue)+1) == $depsvalue.'.') |
|
185 | + if ($major >= $depsvalue || $major == $depsvalue && substr($major, 0, strlen($depsvalue) + 1) == $depsvalue.'.') |
|
186 | 186 | { |
187 | 187 | $setup_info['depends'][$depkey]['status'] = True; |
188 | 188 | } |
189 | 189 | else // check if majors are equal and minors greater or equal |
190 | 190 | { |
191 | 191 | $major_depsvalue = $GLOBALS['egw_setup']->get_major($depsvalue); |
192 | - $tmp = explode('.',$depsvalue); $minor_depsvalue = array_pop($tmp); |
|
193 | - $tmp2 = explode('.',$currentver); $minor = array_pop($tmp2); |
|
192 | + $tmp = explode('.', $depsvalue); $minor_depsvalue = array_pop($tmp); |
|
193 | + $tmp2 = explode('.', $currentver); $minor = array_pop($tmp2); |
|
194 | 194 | if ($major == $major_depsvalue && $minor <= $minor_depsvalue) |
195 | 195 | { |
196 | 196 | $setup_info['depends'][$depkey]['status'] = True; |
@@ -203,17 +203,17 @@ discard block |
||
203 | 203 | Finally, we loop through the dependencies again to look for apps that still have a failure status |
204 | 204 | If we find one, we set the apps overall status as a dependency failure. |
205 | 205 | */ |
206 | - foreach($value['depends'] as $depkey => $depvalue) |
|
206 | + foreach ($value['depends'] as $depkey => $depvalue) |
|
207 | 207 | { |
208 | 208 | if ($setup_info['depends'][$depkey]['status'] == False) |
209 | 209 | { |
210 | 210 | /* Only set this if it has not already failed to upgrade - Milosch */ |
211 | - if($setup_info[$key]['status'] != 'F')//&& $setup_info[$key]['status'] != 'C') |
|
211 | + if ($setup_info[$key]['status'] != 'F')//&& $setup_info[$key]['status'] != 'C') |
|
212 | 212 | { |
213 | 213 | /* Added check for status U - uninstalled apps carry this flag (upgrade from nothing == install). |
214 | 214 | * This should fix apps showing post-install dep failure when they are not yet installed. |
215 | 215 | */ |
216 | - if($setup_info[$key]['status'] == 'C' || $setup_info[$key]['status'] == 'U') |
|
216 | + if ($setup_info[$key]['status'] == 'C' || $setup_info[$key]['status'] == 'U') |
|
217 | 217 | { |
218 | 218 | $setup_info[$key]['status'] = 'D'; |
219 | 219 | } |
@@ -235,9 +235,9 @@ discard block |
||
235 | 235 | */ |
236 | 236 | function upgrade_exclude($setup_info) |
237 | 237 | { |
238 | - foreach($setup_info as $key => $value) |
|
238 | + foreach ($setup_info as $key => $value) |
|
239 | 239 | { |
240 | - if(isset($value['no_mass_update'])) |
|
240 | + if (isset($value['no_mass_update'])) |
|
241 | 241 | { |
242 | 242 | unset($setup_info[$key]); |
243 | 243 | } |
@@ -252,24 +252,24 @@ discard block |
||
252 | 252 | */ |
253 | 253 | function check_header() |
254 | 254 | { |
255 | - if(!file_exists(EGW_SERVER_ROOT.'/header.inc.php') || filesize(EGW_SERVER_ROOT.'/header.inc.php') < 200) |
|
255 | + if (!file_exists(EGW_SERVER_ROOT.'/header.inc.php') || filesize(EGW_SERVER_ROOT.'/header.inc.php') < 200) |
|
256 | 256 | { |
257 | 257 | $GLOBALS['egw_info']['setup']['header_msg'] = 'Stage One'; |
258 | 258 | return '1'; |
259 | 259 | } |
260 | 260 | else |
261 | 261 | { |
262 | - if(!@isset($GLOBALS['egw_info']['server']['header_admin_password'])) |
|
262 | + if (!@isset($GLOBALS['egw_info']['server']['header_admin_password'])) |
|
263 | 263 | { |
264 | 264 | $GLOBALS['egw_info']['setup']['header_msg'] = 'Stage One (No header admin password set)'; |
265 | 265 | return '2'; |
266 | 266 | } |
267 | - elseif(!@isset($GLOBALS['egw_domain'])) |
|
267 | + elseif (!@isset($GLOBALS['egw_domain'])) |
|
268 | 268 | { |
269 | 269 | $GLOBALS['egw_info']['setup']['header_msg'] = 'Stage One (Add domains to your header.inc.php)'; |
270 | 270 | return '3'; |
271 | 271 | } |
272 | - elseif(@$GLOBALS['egw_info']['server']['versions']['header'] != @$GLOBALS['egw_info']['server']['versions']['current_header']) |
|
272 | + elseif (@$GLOBALS['egw_info']['server']['versions']['header'] != @$GLOBALS['egw_info']['server']['versions']['current_header']) |
|
273 | 273 | { |
274 | 274 | $GLOBALS['egw_info']['setup']['header_msg'] = 'Stage One (Upgrade your header.inc.php)'; |
275 | 275 | return '4'; |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | * @param array $setup_info =null default use $GLOBALS['setup_info'] |
287 | 287 | * @return int 1=no database, 3=empty, 4=need upgrade, 10=complete |
288 | 288 | */ |
289 | - function check_db($setup_info=null) |
|
289 | + function check_db($setup_info = null) |
|
290 | 290 | { |
291 | 291 | if (!$setup_info) $setup_info = $GLOBALS['setup_info']; |
292 | 292 | |
@@ -294,14 +294,14 @@ discard block |
||
294 | 294 | if (!$GLOBALS['egw_setup']->db->Link_ID) |
295 | 295 | { |
296 | 296 | $old = error_reporting(); |
297 | - error_reporting($old & ~E_WARNING); // no warnings |
|
297 | + error_reporting($old&~E_WARNING); // no warnings |
|
298 | 298 | $GLOBALS['egw_setup']->db->connect(); |
299 | 299 | error_reporting($old); |
300 | 300 | |
301 | 301 | $GLOBALS['egw_setup']->set_table_names(); |
302 | 302 | } |
303 | 303 | } |
304 | - catch(egw_exception_db $e) { |
|
304 | + catch (egw_exception_db $e) { |
|
305 | 305 | // ignore error |
306 | 306 | } |
307 | 307 | |
@@ -310,14 +310,14 @@ discard block |
||
310 | 310 | $GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 1 (Create Database)'; |
311 | 311 | return 1; |
312 | 312 | } |
313 | - if(!isset($setup_info['phpgwapi']['currentver'])) |
|
313 | + if (!isset($setup_info['phpgwapi']['currentver'])) |
|
314 | 314 | { |
315 | 315 | $setup_info = $this->get_db_versions($setup_info); |
316 | 316 | } |
317 | 317 | //_debug_array($setup_info); |
318 | 318 | if (isset($setup_info['phpgwapi']['currentver'])) |
319 | 319 | { |
320 | - if(@$setup_info['phpgwapi']['currentver'] == @$setup_info['phpgwapi']['version']) |
|
320 | + if (@$setup_info['phpgwapi']['currentver'] == @$setup_info['phpgwapi']['version']) |
|
321 | 321 | { |
322 | 322 | $GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 1 (Tables Complete)'; |
323 | 323 | return 10; |
@@ -351,14 +351,14 @@ discard block |
||
351 | 351 | */ |
352 | 352 | function check_config() |
353 | 353 | { |
354 | - if(@$GLOBALS['egw_info']['setup']['stage']['db'] != 10) |
|
354 | + if (@$GLOBALS['egw_info']['setup']['stage']['db'] != 10) |
|
355 | 355 | { |
356 | 356 | return ''; |
357 | 357 | } |
358 | 358 | |
359 | 359 | try { // catch db errors |
360 | - $GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->config_table,'config_name,config_value',array('config_app' => 'phpgwapi'),__LINE__,__FILE__); |
|
361 | - while($GLOBALS['egw_setup']->db->next_record()) |
|
360 | + $GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->config_table, 'config_name,config_value', array('config_app' => 'phpgwapi'), __LINE__, __FILE__); |
|
361 | + while ($GLOBALS['egw_setup']->db->next_record()) |
|
362 | 362 | { |
363 | 363 | $config[$GLOBALS['egw_setup']->db->f(0)] = $GLOBALS['egw_setup']->db->f(1); |
364 | 364 | } |
@@ -368,21 +368,21 @@ discard block |
||
368 | 368 | // ignore db errors |
369 | 369 | } |
370 | 370 | $GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 2 (Needs Configuration)'; |
371 | - if(!count($config)) |
|
371 | + if (!count($config)) |
|
372 | 372 | { |
373 | 373 | return 1; |
374 | 374 | } |
375 | - $config_errors =& $GLOBALS['egw_info']['setup']['config_errors']; |
|
375 | + $config_errors = & $GLOBALS['egw_info']['setup']['config_errors']; |
|
376 | 376 | $GLOBALS['egw_info']['setup']['config_errors'] = array(); |
377 | 377 | $error_msg = null; |
378 | - if (!$this->check_dir($config['temp_dir'],$error_msg)) |
|
378 | + if (!$this->check_dir($config['temp_dir'], $error_msg)) |
|
379 | 379 | { |
380 | - $config_errors[] = lang("Your temporary directory '%1' %2",$config['temp_dir'],$error_msg); |
|
380 | + $config_errors[] = lang("Your temporary directory '%1' %2", $config['temp_dir'], $error_msg); |
|
381 | 381 | } |
382 | 382 | |
383 | - if (!$this->check_dir($config['files_dir'],$error_msg,true)) |
|
383 | + if (!$this->check_dir($config['files_dir'], $error_msg, true)) |
|
384 | 384 | { |
385 | - $config_errors[] = lang("Your files directory '%1' %2",$config['files_dir'],$error_msg); |
|
385 | + $config_errors[] = lang("Your files directory '%1' %2", $config['files_dir'], $error_msg); |
|
386 | 386 | } |
387 | 387 | // set and create the default backup_dir |
388 | 388 | if (@is_writeable($config['files_dir']) && empty($config['backup_dir'])) |
@@ -390,35 +390,35 @@ discard block |
||
390 | 390 | $config['backup_dir'] = $config['files_dir'].'/db_backup'; |
391 | 391 | if (!is_dir($config['backup_dir']) && mkdir($config['backup_dir'])) |
392 | 392 | { |
393 | - $GLOBALS['egw_setup']->db->insert($GLOBALS['egw_setup']->config_table,array( |
|
393 | + $GLOBALS['egw_setup']->db->insert($GLOBALS['egw_setup']->config_table, array( |
|
394 | 394 | 'config_value' => $config['backup_dir'], |
395 | - ),array( |
|
395 | + ), array( |
|
396 | 396 | 'config_app' => 'phpgwapi', |
397 | 397 | 'config_name' => 'backup_dir', |
398 | - ),__LINE__,__FILE__); |
|
398 | + ), __LINE__, __FILE__); |
|
399 | 399 | } |
400 | 400 | } |
401 | 401 | if (isset($config['backup_mincount'])) |
402 | 402 | { |
403 | - $GLOBALS['egw_setup']->db->insert($GLOBALS['egw_setup']->config_table,array( |
|
403 | + $GLOBALS['egw_setup']->db->insert($GLOBALS['egw_setup']->config_table, array( |
|
404 | 404 | 'config_value' => $config['backup_mincount'], |
405 | - ),array( |
|
405 | + ), array( |
|
406 | 406 | 'config_app' => 'phpgwapi', |
407 | 407 | 'config_name' => 'backup_mincount', |
408 | - ),__LINE__,__FILE__); |
|
408 | + ), __LINE__, __FILE__); |
|
409 | 409 | } |
410 | 410 | if (isset($config['backup_files'])) |
411 | 411 | { |
412 | - $GLOBALS['egw_setup']->db->insert($GLOBALS['egw_setup']->config_table,array( |
|
412 | + $GLOBALS['egw_setup']->db->insert($GLOBALS['egw_setup']->config_table, array( |
|
413 | 413 | 'config_value' => (int)$config['backup_files'], |
414 | - ),array( |
|
414 | + ), array( |
|
415 | 415 | 'config_app' => 'phpgwapi', |
416 | 416 | 'config_name' => 'backup_files', |
417 | - ),__LINE__,__FILE__); |
|
417 | + ), __LINE__, __FILE__); |
|
418 | 418 | } |
419 | - if (!$this->check_dir($config['backup_dir'],$error_msg,true)) |
|
419 | + if (!$this->check_dir($config['backup_dir'], $error_msg, true)) |
|
420 | 420 | { |
421 | - $config_errors[] = lang("Your backup directory '%1' %2",$config['backup_dir'],$error_msg); |
|
421 | + $config_errors[] = lang("Your backup directory '%1' %2", $config['backup_dir'], $error_msg); |
|
422 | 422 | } |
423 | 423 | if ($config_errors) |
424 | 424 | { |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | |
431 | 431 | function check_lang($check = True) |
432 | 432 | { |
433 | - if($check && $GLOBALS['egw_info']['setup']['stage']['db'] != 10) |
|
433 | + if ($check && $GLOBALS['egw_info']['setup']['stage']['db'] != 10) |
|
434 | 434 | { |
435 | 435 | return ''; |
436 | 436 | } |
@@ -439,21 +439,21 @@ discard block |
||
439 | 439 | $GLOBALS['setup_info'] = $GLOBALS['egw_setup']->detection->get_db_versions($GLOBALS['setup_info']); |
440 | 440 | } |
441 | 441 | try { |
442 | - $GLOBALS['egw_setup']->db->query($q = "SELECT DISTINCT lang FROM {$GLOBALS['egw_setup']->lang_table}",__LINE__,__FILE__); |
|
442 | + $GLOBALS['egw_setup']->db->query($q = "SELECT DISTINCT lang FROM {$GLOBALS['egw_setup']->lang_table}", __LINE__, __FILE__); |
|
443 | 443 | } |
444 | 444 | catch (egw_exception_db $e) { |
445 | 445 | // ignore db error |
446 | 446 | } |
447 | - if($e || $GLOBALS['egw_setup']->db->num_rows() == 0) |
|
447 | + if ($e || $GLOBALS['egw_setup']->db->num_rows() == 0) |
|
448 | 448 | { |
449 | 449 | $GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 3 (No languages installed)'; |
450 | 450 | return 1; |
451 | 451 | } |
452 | - while(@$GLOBALS['egw_setup']->db->next_record()) |
|
452 | + while (@$GLOBALS['egw_setup']->db->next_record()) |
|
453 | 453 | { |
454 | 454 | $GLOBALS['egw_info']['setup']['installed_langs'][$GLOBALS['egw_setup']->db->f('lang')] = $GLOBALS['egw_setup']->db->f('lang'); |
455 | 455 | } |
456 | - foreach($GLOBALS['egw_info']['setup']['installed_langs'] as $value) |
|
456 | + foreach ($GLOBALS['egw_info']['setup']['installed_langs'] as $value) |
|
457 | 457 | { |
458 | 458 | $sql = "SELECT lang_name FROM {$GLOBALS['egw_setup']->languages_table} WHERE lang_id = '".$value."'"; |
459 | 459 | $GLOBALS['egw_setup']->db->query($sql); |
@@ -471,19 +471,19 @@ discard block |
||
471 | 471 | * @param $appname |
472 | 472 | * @param $any optional, set to True to see if any of the apps tables are installed |
473 | 473 | */ |
474 | - function check_app_tables($appname,$any=False) |
|
474 | + function check_app_tables($appname, $any = False) |
|
475 | 475 | { |
476 | 476 | $none = 0; |
477 | 477 | $setup_info = $GLOBALS['setup_info']; |
478 | 478 | |
479 | - if(@$setup_info[$appname]['tables']) |
|
479 | + if (@$setup_info[$appname]['tables']) |
|
480 | 480 | { |
481 | 481 | /* Make a copy, else we send some callers into an infinite loop */ |
482 | 482 | $copy = $setup_info; |
483 | 483 | $tables = Array(); |
484 | 484 | try { |
485 | 485 | $table_names = $GLOBALS['egw_setup']->db->table_names(); |
486 | - foreach($table_names as $key => $val) |
|
486 | + foreach ($table_names as $key => $val) |
|
487 | 487 | { |
488 | 488 | $tables[] = $val['table_name']; |
489 | 489 | } |
@@ -492,19 +492,19 @@ discard block |
||
492 | 492 | unset($e); |
493 | 493 | // ignore db error |
494 | 494 | } |
495 | - foreach($copy[$appname]['tables'] as $key => $val) |
|
495 | + foreach ($copy[$appname]['tables'] as $key => $val) |
|
496 | 496 | { |
497 | - if($GLOBALS['DEBUG']) |
|
497 | + if ($GLOBALS['DEBUG']) |
|
498 | 498 | { |
499 | - echo '<br>check_app_tables(): Checking: ' . $appname . ',table: ' . $val; |
|
499 | + echo '<br>check_app_tables(): Checking: '.$appname.',table: '.$val; |
|
500 | 500 | } |
501 | - if(!in_array($val,$tables) && !in_array(strtolower($val),$tables)) // names in tables might be lowercase |
|
501 | + if (!in_array($val, $tables) && !in_array(strtolower($val), $tables)) // names in tables might be lowercase |
|
502 | 502 | { |
503 | - if($GLOBALS['DEBUG']) |
|
503 | + if ($GLOBALS['DEBUG']) |
|
504 | 504 | { |
505 | - echo '<br>check_app_tables(): ' . $val . ' missing!'; |
|
505 | + echo '<br>check_app_tables(): '.$val.' missing!'; |
|
506 | 506 | } |
507 | - if(!$any) |
|
507 | + if (!$any) |
|
508 | 508 | { |
509 | 509 | return False; |
510 | 510 | } |
@@ -515,9 +515,9 @@ discard block |
||
515 | 515 | } |
516 | 516 | else |
517 | 517 | { |
518 | - if($any) |
|
518 | + if ($any) |
|
519 | 519 | { |
520 | - if($GLOBALS['DEBUG']) |
|
520 | + if ($GLOBALS['DEBUG']) |
|
521 | 521 | { |
522 | 522 | echo '<br>check_app_tables(): Some tables installed'; |
523 | 523 | } |
@@ -526,9 +526,9 @@ discard block |
||
526 | 526 | } |
527 | 527 | } |
528 | 528 | } |
529 | - if($none && $any) |
|
529 | + if ($none && $any) |
|
530 | 530 | { |
531 | - if($GLOBALS['DEBUG']) |
|
531 | + if ($GLOBALS['DEBUG']) |
|
532 | 532 | { |
533 | 533 | echo '<br>check_app_tables(): No tables installed'; |
534 | 534 | } |
@@ -536,7 +536,7 @@ discard block |
||
536 | 536 | } |
537 | 537 | else |
538 | 538 | { |
539 | - if($GLOBALS['DEBUG']) |
|
539 | + if ($GLOBALS['DEBUG']) |
|
540 | 540 | { |
541 | 541 | echo '<br>check_app_tables(): All tables installed'; |
542 | 542 | } |
@@ -552,9 +552,9 @@ discard block |
||
552 | 552 | * @param boolean $check_in_docroot =false run an optional in docroot check |
553 | 553 | * @return boolean |
554 | 554 | */ |
555 | - static function check_dir($dir,&$msg,$check_in_docroot=false) |
|
555 | + static function check_dir($dir, &$msg, $check_in_docroot = false) |
|
556 | 556 | { |
557 | - if (!@is_dir($dir) && !@mkdir($dir,0700,true)) |
|
557 | + if (!@is_dir($dir) && !@mkdir($dir, 0700, true)) |
|
558 | 558 | { |
559 | 559 | $msg = lang('does not exist'); |
560 | 560 | return false; |
@@ -566,16 +566,16 @@ discard block |
||
566 | 566 | } |
567 | 567 | if ($check_in_docroot) |
568 | 568 | { |
569 | - $docroots = array(realpath(EGW_SERVER_ROOT),realpath($_SERVER['DOCUMENT_ROOT'])); |
|
569 | + $docroots = array(realpath(EGW_SERVER_ROOT), realpath($_SERVER['DOCUMENT_ROOT'])); |
|
570 | 570 | $dir = realpath($dir); |
571 | 571 | |
572 | 572 | foreach ($docroots as $docroot) |
573 | 573 | { |
574 | 574 | $len = strlen($docroot); |
575 | 575 | |
576 | - if ($docroot == substr($dir,0,$len) && $len>0) |
|
576 | + if ($docroot == substr($dir, 0, $len) && $len > 0) |
|
577 | 577 | { |
578 | - $rest = substr($dir,$len); |
|
578 | + $rest = substr($dir, $len); |
|
579 | 579 | |
580 | 580 | if (!strlen($rest) || $rest[0] == DIRECTORY_SEPARATOR) |
581 | 581 | { |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | * |
262 | 262 | * @param statuses List of statuses to process, with sub-statuses in a 'substatus' array |
263 | 263 | * @param labels Array of labels, pass array() and labels will be built in it |
264 | - * @param depth Current depth |
|
264 | + * @param depth integer depth |
|
265 | 265 | * |
266 | 266 | * @return None, labels are built in labels parameter |
267 | 267 | */ |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | * |
306 | 306 | * @param array|int $data =null use $this->data or $this->data['ts_id'] (to fetch the data) |
307 | 307 | * @param int $user =null for which user to check, default current user |
308 | - * @return boolean true if the rights are ok, false if no rights |
|
308 | + * @return null|boolean true if the rights are ok, false if no rights |
|
309 | 309 | */ |
310 | 310 | function check_statusForEditRights($data=null,$user=null) |
311 | 311 | { |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | * @param int $required Acl::READ, EGW_ACL_WRITE, Acl::ADD, Acl::DELETE, EGW_ACL_BUDGET, EGW_ACL_EDIT_BUDGET |
341 | 341 | * @param array|int $data =null project or project-id to use, default the project in $this->data |
342 | 342 | * @param int $user =null for which user to check, default current user |
343 | - * @return boolean true if the rights are ok, null if not found, false if no rights |
|
343 | + * @return null|boolean true if the rights are ok, null if not found, false if no rights |
|
344 | 344 | */ |
345 | 345 | function check_acl($required,$data=null,$user=null) |
346 | 346 | { |
@@ -397,11 +397,11 @@ discard block |
||
397 | 397 | * @param array|string $criteria array of key and data cols, OR a SQL query (content for WHERE), fully quoted (!) |
398 | 398 | * @param boolean|string $only_keys =true True returns only keys, False returns all cols. comma seperated list of keys to return |
399 | 399 | * @param string $order_by ='' fieldnames + {ASC|DESC} separated by colons ',', can also contain a GROUP BY (if it contains ORDER BY) |
400 | - * @param string|array $extra_cols ='' string or array of strings to be added to the SELECT, eg. "count(*) as num" |
|
400 | + * @param string $extra_cols ='' string or array of strings to be added to the SELECT, eg. "count(*) as num" |
|
401 | 401 | * @param string $wildcard ='' appended befor and after each criteria |
402 | 402 | * @param boolean $empty =false False=empty criteria are ignored in query, True=empty have to be empty in row |
403 | 403 | * @param string $op ='AND' defaults to 'AND', can be set to 'OR' too, then criteria's are OR'ed together |
404 | - * @param mixed $start =false if != false, return only maxmatch rows begining with start, or array($start,$num) |
|
404 | + * @param boolean $start =false if != false, return only maxmatch rows begining with start, or array($start,$num) |
|
405 | 405 | * @param array $filter =null if set (!=null) col-data pairs, to be and-ed (!) into the query without wildcards |
406 | 406 | * @param string $join ='' sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or |
407 | 407 | * "LEFT JOIN table2 ON (x=y)", Note: there's no quoting done on $join! |
@@ -658,8 +658,6 @@ discard block |
||
658 | 658 | * delete / move all timesheets of a given user |
659 | 659 | * |
660 | 660 | * @param array $data |
661 | - * @param int $data['account_id'] owner to change |
|
662 | - * @param int $data['new_owner'] new owner or 0 for delete |
|
663 | 661 | */ |
664 | 662 | function deleteaccount($data) |
665 | 663 | { |
@@ -686,7 +684,7 @@ discard block |
||
686 | 684 | * |
687 | 685 | * @param array $keys =null if given array with col => value pairs to characterise single timesheet or null for $this->data |
688 | 686 | * @param int $status =0 |
689 | - * @return int affected rows, should be 1 if ok, 0 if an error |
|
687 | + * @return boolean affected rows, should be 1 if ok, 0 if an error |
|
690 | 688 | */ |
691 | 689 | function set_status($keys=null, $status=0) |
692 | 690 | { |
@@ -816,7 +814,7 @@ discard block |
||
816 | 814 | * @param int $check Acl::READ for read and Acl::EDIT for write or delete access |
817 | 815 | * @param string $rel_path =null currently not used in InfoLog |
818 | 816 | * @param int $user =null for which user to check, default current user |
819 | - * @return boolean true if access is granted or false otherwise |
|
817 | + * @return null|boolean true if access is granted or false otherwise |
|
820 | 818 | */ |
821 | 819 | function file_access($id,$check,$rel_path=null,$user=null) |
822 | 820 | { |
@@ -152,8 +152,8 @@ |
||
152 | 152 | const EXTRA_TABLE = 'egw_timesheet_extra'; |
153 | 153 | |
154 | 154 | /** |
155 | - * Columns to search when user does a text search |
|
156 | - */ |
|
155 | + * Columns to search when user does a text search |
|
156 | + */ |
|
157 | 157 | var $columns_to_search = array('egw_timesheet.ts_id', 'ts_project', 'ts_title', 'ts_description', 'ts_duration', 'ts_quantity', 'ts_unitprice'); |
158 | 158 | |
159 | 159 | /** |
@@ -167,12 +167,18 @@ discard block |
||
167 | 167 | { |
168 | 168 | parent::__construct(TIMESHEET_APP,'egw_timesheet',self::EXTRA_TABLE,'','ts_extra_name','ts_extra_value','ts_id'); |
169 | 169 | |
170 | - if ($this->customfields) $this->columns_to_search[] = self::EXTRA_TABLE.'.ts_extra_value'; |
|
170 | + if ($this->customfields) |
|
171 | + { |
|
172 | + $this->columns_to_search[] = self::EXTRA_TABLE.'.ts_extra_value'; |
|
173 | + } |
|
171 | 174 | $this->config_data = Api\Config::read(TIMESHEET_APP); |
172 | 175 | $this->quantity_sum = $this->config_data['quantity_sum'] == 'true'; |
173 | 176 | |
174 | 177 | // Load & process statuses |
175 | - if($this->config_data['status_labels']) $this->load_statuses(); |
|
178 | + if($this->config_data['status_labels']) |
|
179 | + { |
|
180 | + $this->load_statuses(); |
|
181 | + } |
|
176 | 182 | |
177 | 183 | $this->today = mktime(0,0,0,date('m',$this->now),date('d',$this->now),date('Y',$this->now)); |
178 | 184 | |
@@ -190,12 +196,16 @@ discard block |
||
190 | 196 | protected function load_statuses() |
191 | 197 | { |
192 | 198 | $this->status_labels =& $this->config_data['status_labels']; |
193 | - if (!is_array($this->status_labels)) $this->status_labels= array($this->status_labels); |
|
199 | + if (!is_array($this->status_labels)) |
|
200 | + { |
|
201 | + $this->status_labels= array($this->status_labels); |
|
202 | + } |
|
194 | 203 | |
195 | 204 | foreach ($this->status_labels as $status_id => $label) |
196 | 205 | { |
197 | 206 | if (!is_array($label)) |
198 | - { //old values, before parent status |
|
207 | + { |
|
208 | +//old values, before parent status |
|
199 | 209 | $name = $label; |
200 | 210 | $label=array(); |
201 | 211 | $label['name'] = $name; |
@@ -243,7 +253,10 @@ discard block |
||
243 | 253 | */ |
244 | 254 | function get_sub_status($status) |
245 | 255 | { |
246 | - if (!isset($this->status_labels_config)) $this->load_statuses(); |
|
256 | + if (!isset($this->status_labels_config)) |
|
257 | + { |
|
258 | + $this->load_statuses(); |
|
259 | + } |
|
247 | 260 | $stati = array($status); |
248 | 261 | foreach($this->status_labels_config as $stat) |
249 | 262 | { |
@@ -319,9 +332,16 @@ discard block |
||
319 | 332 | $data = $this->read($data,true); |
320 | 333 | $this->data = $save_data; |
321 | 334 | |
322 | - if (!$data) return null; // entry not found |
|
335 | + if (!$data) |
|
336 | + { |
|
337 | + return null; |
|
338 | + } |
|
339 | + // entry not found |
|
340 | + } |
|
341 | + if (!$user) |
|
342 | + { |
|
343 | + $user = $this->user; |
|
323 | 344 | } |
324 | - if (!$user) $user = $this->user; |
|
325 | 345 | if (!isset($GLOBALS['egw_info']['user']['apps']['admin']) && $data['ts_status']) |
326 | 346 | { |
327 | 347 | if ($this->status_labels_config[$data['ts_status']]['admin']) |
@@ -354,9 +374,16 @@ discard block |
||
354 | 374 | $data = $this->read($data,true); |
355 | 375 | $this->data = $save_data; |
356 | 376 | |
357 | - if (!$data) return null; // entry not found |
|
377 | + if (!$data) |
|
378 | + { |
|
379 | + return null; |
|
380 | + } |
|
381 | + // entry not found |
|
382 | + } |
|
383 | + if (!$user) |
|
384 | + { |
|
385 | + $user = $this->user; |
|
358 | 386 | } |
359 | - if (!$user) $user = $this->user; |
|
360 | 387 | if ($user == $this->user) |
361 | 388 | { |
362 | 389 | $grants = $this->grants; |
@@ -430,7 +457,10 @@ discard block |
||
430 | 457 | } |
431 | 458 | else |
432 | 459 | { |
433 | - if (!is_array($filter['ts_owner'])) $filter['ts_owner'] = array($filter['ts_owner']); |
|
460 | + if (!is_array($filter['ts_owner'])) |
|
461 | + { |
|
462 | + $filter['ts_owner'] = array($filter['ts_owner']); |
|
463 | + } |
|
434 | 464 | |
435 | 465 | foreach($filter['ts_owner'] as $key => $owner) |
436 | 466 | { |
@@ -485,7 +515,10 @@ discard block |
||
485 | 515 | $this->summary = $this->summary[0]; |
486 | 516 | $this->summary['max_modified'] = Api\DateTime::server2user($this->summary['max_modified']); |
487 | 517 | |
488 | - if ($only_summary) return $this->summary; |
|
518 | + if ($only_summary) |
|
519 | + { |
|
520 | + return $this->summary; |
|
521 | + } |
|
489 | 522 | |
490 | 523 | if ($this->show_sums && strpos($order_by,'ts_start') !== false && // sums only make sense if ordered by ts_start |
491 | 524 | $this->db->capabilities['union'] && ($from_unixtime_ts_start = $this->db->from_unixtime('ts_start'))) |
@@ -561,7 +594,10 @@ discard block |
||
561 | 594 | */ |
562 | 595 | function save($keys=null,$touch_modified=true,$ignore_acl=false) |
563 | 596 | { |
564 | - if ($keys) $this->data_merge($keys); |
|
597 | + if ($keys) |
|
598 | + { |
|
599 | + $this->data_merge($keys); |
|
600 | + } |
|
565 | 601 | |
566 | 602 | if (!$ignore_acl && $this->data['ts_id'] && !$this->check_acl(Acl::EDIT)) |
567 | 603 | { |
@@ -583,10 +619,13 @@ discard block |
||
583 | 619 | $old =& $this->data; |
584 | 620 | $this->data =& $new; |
585 | 621 | $changed = array(); |
586 | - if (isset($old)) foreach($old as $name => $value) |
|
622 | + if (isset($old)) |
|
623 | + { |
|
624 | + foreach($old as $name => $value) |
|
587 | 625 | { |
588 | 626 | if (isset($new[$name]) && $new[$name] != $value) $changed[] = $name; |
589 | 627 | } |
628 | + } |
|
590 | 629 | } |
591 | 630 | if (isset($old) && !$changed) |
592 | 631 | { |
@@ -703,7 +742,10 @@ discard block |
||
703 | 742 | } |
704 | 743 | |
705 | 744 | $this->data['ts_status'] = $status; |
706 | - if ($this->save($ts_id)!=0) $ret = false; |
|
745 | + if ($this->save($ts_id)!=0) |
|
746 | + { |
|
747 | + $ret = false; |
|
748 | + } |
|
707 | 749 | |
708 | 750 | return $ret; |
709 | 751 | } |
@@ -747,10 +789,13 @@ discard block |
||
747 | 789 | return $entry; |
748 | 790 | } |
749 | 791 | $format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat']; |
750 | - if (date('H:i',$entry['ts_start']) != '00:00') // dont show 00:00 time, as it means date only |
|
792 | + if (date('H:i',$entry['ts_start']) != '00:00') |
|
793 | + { |
|
794 | + // dont show 00:00 time, as it means date only |
|
751 | 795 | { |
752 | 796 | $format .= ' '.($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == 12 ? 'h:i a' : 'H:i'); |
753 | 797 | } |
798 | + } |
|
754 | 799 | return date($format,$entry['ts_start']).': '.$entry['ts_title']; |
755 | 800 | } |
756 | 801 | |
@@ -796,14 +841,18 @@ discard block |
||
796 | 841 | { |
797 | 842 | $limit = false; |
798 | 843 | $need_count = false; |
799 | - if($options['start'] || $options['num_rows']) { |
|
844 | + if($options['start'] || $options['num_rows']) |
|
845 | + { |
|
800 | 846 | $limit = array($options['start'], $options['num_rows']); |
801 | 847 | $need_count = true; |
802 | 848 | } |
803 | 849 | $result = array(); |
804 | 850 | foreach((array) $this->search($pattern,false,'','','%',false,'OR', $limit, null, '', $need_count) as $ts ) |
805 | 851 | { |
806 | - if ($ts) $result[$ts['ts_id']] = $this->link_title($ts); |
|
852 | + if ($ts) |
|
853 | + { |
|
854 | + $result[$ts['ts_id']] = $this->link_title($ts); |
|
855 | + } |
|
807 | 856 | } |
808 | 857 | $options['total'] = $need_count ? $this->total : count($result); |
809 | 858 | return $result; |
@@ -922,7 +971,10 @@ discard block |
||
922 | 971 | //error_log(__METHOD__."() setting pm_id=$pm_id --> ".array2string($update)); |
923 | 972 | } |
924 | 973 | } |
925 | - if ($backup) $this->data = $backup; |
|
974 | + if ($backup) |
|
975 | + { |
|
976 | + $this->data = $backup; |
|
977 | + } |
|
926 | 978 | } |
927 | 979 | |
928 | 980 | |
@@ -947,7 +999,10 @@ discard block |
||
947 | 999 | $first_pm_id = null; |
948 | 1000 | foreach(Link::get_links('timesheet', $data['ts_id'], 'projectmanager') as $pm_id) |
949 | 1001 | { |
950 | - if (!isset($first_pm_id)) $first_pm_id = $pm_id; |
|
1002 | + if (!isset($first_pm_id)) |
|
1003 | + { |
|
1004 | + $first_pm_id = $pm_id; |
|
1005 | + } |
|
951 | 1006 | if ($data['ts_project'] == Link::title('projectmanager', $pm_id)) |
952 | 1007 | { |
953 | 1008 | $data['pm_id'] = $pm_id; |
@@ -956,7 +1011,10 @@ discard block |
||
956 | 1011 | break; |
957 | 1012 | } |
958 | 1013 | } |
959 | - if (!isset($data['pm_id']) && isset($first_pm_id)) $data['pm_id'] = $first_pm_id; |
|
1014 | + if (!isset($data['pm_id']) && isset($first_pm_id)) |
|
1015 | + { |
|
1016 | + $data['pm_id'] = $first_pm_id; |
|
1017 | + } |
|
960 | 1018 | } |
961 | 1019 | elseif ($data['ts_id'] && $data['pm_id'] && Link::title('projectmanager', $data['pm_id']) == $data['ts_project']) |
962 | 1020 | { |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | if (!defined('TIMESHEET_APP')) |
14 | 14 | { |
15 | - define('TIMESHEET_APP','timesheet'); |
|
15 | + define('TIMESHEET_APP', 'timesheet'); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * |
40 | 40 | * @var boolean |
41 | 41 | */ |
42 | - var $quantity_sum=false; |
|
42 | + var $quantity_sum = false; |
|
43 | 43 | /** |
44 | 44 | * current user |
45 | 45 | * |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * @var array |
53 | 53 | */ |
54 | 54 | var $timestamps = array( |
55 | - 'ts_start','ts_modified' |
|
55 | + 'ts_start', 'ts_modified' |
|
56 | 56 | ); |
57 | 57 | /** |
58 | 58 | * Start of today in user-time |
@@ -66,17 +66,17 @@ discard block |
||
66 | 66 | * @var array |
67 | 67 | */ |
68 | 68 | var $date_filters = array( // Start: year,month,day,week, End: year,month,day,week |
69 | - 'Today' => array(0,0,0,0, 0,0,1,0), |
|
70 | - 'Yesterday' => array(0,0,-1,0, 0,0,0,0), |
|
71 | - 'This week' => array(0,0,0,0, 0,0,0,1), |
|
72 | - 'Last week' => array(0,0,0,-1, 0,0,0,0), |
|
73 | - 'This month' => array(0,0,0,0, 0,1,0,0), |
|
74 | - 'Last month' => array(0,-1,0,0, 0,0,0,0), |
|
75 | - '2 month ago' => array(0,-2,0,0, 0,-1,0,0), |
|
76 | - 'This year' => array(0,0,0,0, 1,0,0,0), |
|
77 | - 'Last year' => array(-1,0,0,0, 0,0,0,0), |
|
78 | - '2 years ago' => array(-2,0,0,0, -1,0,0,0), |
|
79 | - '3 years ago' => array(-3,0,0,0, -2,0,0,0), |
|
69 | + 'Today' => array(0, 0, 0, 0, 0, 0, 1, 0), |
|
70 | + 'Yesterday' => array(0, 0, -1, 0, 0, 0, 0, 0), |
|
71 | + 'This week' => array(0, 0, 0, 0, 0, 0, 0, 1), |
|
72 | + 'Last week' => array(0, 0, 0, -1, 0, 0, 0, 0), |
|
73 | + 'This month' => array(0, 0, 0, 0, 0, 1, 0, 0), |
|
74 | + 'Last month' => array(0, -1, 0, 0, 0, 0, 0, 0), |
|
75 | + '2 month ago' => array(0, -2, 0, 0, 0, -1, 0, 0), |
|
76 | + 'This year' => array(0, 0, 0, 0, 1, 0, 0, 0), |
|
77 | + 'Last year' => array(-1, 0, 0, 0, 0, 0, 0, 0), |
|
78 | + '2 years ago' => array(-2, 0, 0, 0, -1, 0, 0, 0), |
|
79 | + '3 years ago' => array(-3, 0, 0, 0, -2, 0, 0, 0), |
|
80 | 80 | ); |
81 | 81 | /** |
82 | 82 | * Grants: $GLOBALS['egw']->acl->get_grants(TIMESHEET_APP); |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * |
102 | 102 | * @var array |
103 | 103 | */ |
104 | - var $customfields=array(); |
|
104 | + var $customfields = array(); |
|
105 | 105 | /** |
106 | 106 | * Array with status label |
107 | 107 | * |
@@ -161,21 +161,21 @@ discard block |
||
161 | 161 | |
162 | 162 | function __construct() |
163 | 163 | { |
164 | - parent::__construct(TIMESHEET_APP,'egw_timesheet',self::EXTRA_TABLE,'','ts_extra_name','ts_extra_value','ts_id'); |
|
164 | + parent::__construct(TIMESHEET_APP, 'egw_timesheet', self::EXTRA_TABLE, '', 'ts_extra_name', 'ts_extra_value', 'ts_id'); |
|
165 | 165 | |
166 | 166 | if ($this->customfields) $this->columns_to_search[] = self::EXTRA_TABLE.'.ts_extra_value'; |
167 | 167 | $this->config_data = config::read(TIMESHEET_APP); |
168 | 168 | $this->quantity_sum = $this->config_data['quantity_sum'] == 'true'; |
169 | 169 | |
170 | 170 | // Load & process statuses |
171 | - if($this->config_data['status_labels']) $this->load_statuses(); |
|
171 | + if ($this->config_data['status_labels']) $this->load_statuses(); |
|
172 | 172 | |
173 | - $this->today = mktime(0,0,0,date('m',$this->now),date('d',$this->now),date('Y',$this->now)); |
|
173 | + $this->today = mktime(0, 0, 0, date('m', $this->now), date('d', $this->now), date('Y', $this->now)); |
|
174 | 174 | |
175 | 175 | // save us in $GLOBALS['timesheet_bo'] for ExecMethod used in hooks |
176 | 176 | if (!is_object($GLOBALS['timesheet_bo'])) |
177 | 177 | { |
178 | - $GLOBALS['timesheet_bo'] =& $this; |
|
178 | + $GLOBALS['timesheet_bo'] = & $this; |
|
179 | 179 | } |
180 | 180 | $this->grants = $GLOBALS['egw']->acl->get_grants(TIMESHEET_APP); |
181 | 181 | } |
@@ -185,15 +185,15 @@ discard block |
||
185 | 185 | */ |
186 | 186 | protected function load_statuses() |
187 | 187 | { |
188 | - $this->status_labels =& $this->config_data['status_labels']; |
|
189 | - if (!is_array($this->status_labels)) $this->status_labels= array($this->status_labels); |
|
188 | + $this->status_labels = & $this->config_data['status_labels']; |
|
189 | + if (!is_array($this->status_labels)) $this->status_labels = array($this->status_labels); |
|
190 | 190 | |
191 | 191 | foreach ($this->status_labels as $status_id => $label) |
192 | 192 | { |
193 | 193 | if (!is_array($label)) |
194 | 194 | { //old values, before parent status |
195 | 195 | $name = $label; |
196 | - $label=array(); |
|
196 | + $label = array(); |
|
197 | 197 | $label['name'] = $name; |
198 | 198 | $label['parent'] = ''; |
199 | 199 | } |
@@ -205,12 +205,12 @@ discard block |
||
205 | 205 | $map = array( |
206 | 206 | '' => array('substatus' => array()) |
207 | 207 | ); |
208 | - foreach($this->status_labels_config as $id => &$status) |
|
208 | + foreach ($this->status_labels_config as $id => &$status) |
|
209 | 209 | { |
210 | 210 | $status['substatus'] = array(); |
211 | 211 | $map[$id] = &$status; |
212 | 212 | } |
213 | - foreach($this->status_labels_config as &$status) |
|
213 | + foreach ($this->status_labels_config as &$status) |
|
214 | 214 | { |
215 | 215 | $map[$status['parent']]['substatus'][] = &$status; |
216 | 216 | } |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | |
223 | 223 | // Sort config based on tree |
224 | 224 | $sorted = array(); |
225 | - foreach($this->status_labels as $status_id => $label) |
|
225 | + foreach ($this->status_labels as $status_id => $label) |
|
226 | 226 | { |
227 | 227 | $sorted[$status_id] = $this->status_labels_config[$status_id]; |
228 | 228 | //$sorted[$status_id]['name'] = $label; |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | { |
242 | 242 | if (!isset($this->status_labels_config)) $this->load_statuses(); |
243 | 243 | $stati = array($status); |
244 | - foreach($this->status_labels_config as $stat) |
|
244 | + foreach ($this->status_labels_config as $stat) |
|
245 | 245 | { |
246 | 246 | if ($stat['parent'] && in_array($stat['parent'], $stati)) |
247 | 247 | { |
@@ -261,14 +261,14 @@ discard block |
||
261 | 261 | * |
262 | 262 | * @return None, labels are built in labels parameter |
263 | 263 | */ |
264 | - protected function make_status_labels($statuses, &$labels, $depth=0) |
|
264 | + protected function make_status_labels($statuses, &$labels, $depth = 0) |
|
265 | 265 | { |
266 | - foreach($statuses as $status) |
|
266 | + foreach ($statuses as $status) |
|
267 | 267 | { |
268 | - $labels[$status['id']] = str_pad('',$depth*12, " ",STR_PAD_LEFT).trim(str_replace(' ','',$status['name'])); |
|
269 | - if(count($status['substatus']) > 0) |
|
268 | + $labels[$status['id']] = str_pad('', $depth * 12, " ", STR_PAD_LEFT).trim(str_replace(' ', '', $status['name'])); |
|
269 | + if (count($status['substatus']) > 0) |
|
270 | 270 | { |
271 | - $this->make_status_labels($status['substatus'], $labels, $depth+1); |
|
271 | + $this->make_status_labels($status['substatus'], $labels, $depth + 1); |
|
272 | 272 | } |
273 | 273 | } |
274 | 274 | } |
@@ -279,12 +279,12 @@ discard block |
||
279 | 279 | * @param int $required =EGW_ACL_READ |
280 | 280 | * @return array with uid => Username pairs |
281 | 281 | */ |
282 | - function grant_list($required=EGW_ACL_READ) |
|
282 | + function grant_list($required = EGW_ACL_READ) |
|
283 | 283 | { |
284 | 284 | $result = array(); |
285 | - foreach($this->grants as $uid => $grant) |
|
285 | + foreach ($this->grants as $uid => $grant) |
|
286 | 286 | { |
287 | - if ($grant & $required) |
|
287 | + if ($grant&$required) |
|
288 | 288 | { |
289 | 289 | $result[$uid] = common::grab_owner_name($uid); |
290 | 290 | } |
@@ -303,19 +303,19 @@ discard block |
||
303 | 303 | * @param int $user =null for which user to check, default current user |
304 | 304 | * @return boolean true if the rights are ok, false if no rights |
305 | 305 | */ |
306 | - function check_statusForEditRights($data=null,$user=null) |
|
306 | + function check_statusForEditRights($data = null, $user = null) |
|
307 | 307 | { |
308 | 308 | if (is_null($data) || (int)$data == $this->data['ts_id']) |
309 | 309 | { |
310 | - $data =& $this->data; |
|
310 | + $data = & $this->data; |
|
311 | 311 | } |
312 | 312 | if (!is_array($data)) |
313 | 313 | { |
314 | 314 | $save_data = $this->data; |
315 | - $data = $this->read($data,true); |
|
315 | + $data = $this->read($data, true); |
|
316 | 316 | $this->data = $save_data; |
317 | 317 | |
318 | - if (!$data) return null; // entry not found |
|
318 | + if (!$data) return null; // entry not found |
|
319 | 319 | } |
320 | 320 | if (!$user) $user = $this->user; |
321 | 321 | if (!isset($GLOBALS['egw_info']['user']['apps']['admin']) && $data['ts_status']) |
@@ -338,19 +338,19 @@ discard block |
||
338 | 338 | * @param int $user =null for which user to check, default current user |
339 | 339 | * @return boolean true if the rights are ok, null if not found, false if no rights |
340 | 340 | */ |
341 | - function check_acl($required,$data=null,$user=null) |
|
341 | + function check_acl($required, $data = null, $user = null) |
|
342 | 342 | { |
343 | 343 | if (is_null($data) || (int)$data == $this->data['ts_id']) |
344 | 344 | { |
345 | - $data =& $this->data; |
|
345 | + $data = & $this->data; |
|
346 | 346 | } |
347 | 347 | if (!is_array($data)) |
348 | 348 | { |
349 | 349 | $save_data = $this->data; |
350 | - $data = $this->read($data,true); |
|
350 | + $data = $this->read($data, true); |
|
351 | 351 | $this->data = $save_data; |
352 | 352 | |
353 | - if (!$data) return null; // entry not found |
|
353 | + if (!$data) return null; // entry not found |
|
354 | 354 | } |
355 | 355 | if (!$user) $user = $this->user; |
356 | 356 | if ($user == $this->user) |
@@ -359,11 +359,11 @@ discard block |
||
359 | 359 | } |
360 | 360 | else |
361 | 361 | { |
362 | - $grants = $GLOBALS['egw']->acl->get_grants(TIMESHEET_APP,true,$user); |
|
362 | + $grants = $GLOBALS['egw']->acl->get_grants(TIMESHEET_APP, true, $user); |
|
363 | 363 | } |
364 | - $ret = $data && !!($grants[$data['ts_owner']] & $required); |
|
364 | + $ret = $data && !!($grants[$data['ts_owner']]&$required); |
|
365 | 365 | |
366 | - if(($required & EGW_ACL_DELETE) && $this->config_data['history'] == 'history' && |
|
366 | + if (($required&EGW_ACL_DELETE) && $this->config_data['history'] == 'history' && |
|
367 | 367 | $data['ts_status'] == self::DELETED_STATUS) |
368 | 368 | { |
369 | 369 | $ret = !!($GLOBALS['egw_info']['user']['apps']['admin']); |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | * @param int &$end |
381 | 381 | * @return string |
382 | 382 | */ |
383 | - function date_filter($name,&$start,&$end) |
|
383 | + function date_filter($name, &$start, &$end) |
|
384 | 384 | { |
385 | 385 | return egw_time::sql_filter($name, $start, $end, 'ts_start', $this->date_filters); |
386 | 386 | } |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | * @param boolean $only_summary =false If true only return the sums as array with keys duration and price, default false |
406 | 406 | * @return array of matching rows (the row is an array of the cols) or False |
407 | 407 | */ |
408 | - 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,$only_summary=false) |
|
408 | + 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, $only_summary = false) |
|
409 | 409 | { |
410 | 410 | //error_log(__METHOD__."(".print_r($criteria,true).",'$only_keys','$order_by',".print_r($extra_cols,true).",'$wildcard','$empty','$op','$start',".print_r($filter,true).",'$join')"); |
411 | 411 | //echo "<p>".__METHOD__."(".print_r($criteria,true).",'$only_keys','$order_by',".print_r($extra_cols,true).",'$wildcard','$empty','$op','$start',".print_r($filter,true).",'$join')</p>\n"; |
@@ -414,9 +414,9 @@ discard block |
||
414 | 414 | |
415 | 415 | if (!is_array($extra_cols)) |
416 | 416 | { |
417 | - $extra_cols = $extra_cols ? explode(',',$extra_cols) : array(); |
|
417 | + $extra_cols = $extra_cols ? explode(',', $extra_cols) : array(); |
|
418 | 418 | } |
419 | - if ($only_keys === false || $this->show_sums && strpos($order_by,'ts_start') !== false) |
|
419 | + if ($only_keys === false || $this->show_sums && strpos($order_by, 'ts_start') !== false) |
|
420 | 420 | { |
421 | 421 | $extra_cols[] = $total_sql.' AS ts_total'; |
422 | 422 | } |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | { |
429 | 429 | if (!is_array($filter['ts_owner'])) $filter['ts_owner'] = array($filter['ts_owner']); |
430 | 430 | |
431 | - foreach($filter['ts_owner'] as $key => $owner) |
|
431 | + foreach ($filter['ts_owner'] as $key => $owner) |
|
432 | 432 | { |
433 | 433 | if (!isset($this->grants[$owner])) |
434 | 434 | { |
@@ -442,8 +442,8 @@ discard block |
||
442 | 442 | } |
443 | 443 | else |
444 | 444 | { |
445 | - $filter[] = '(ts_status ' . ($filter['ts_status'] == self::DELETED_STATUS ? '=':'!= ') . self::DELETED_STATUS . |
|
446 | - ($filter['ts_status'] == self::DELETED_STATUS ? '':' OR ts_status IS NULL') . ')'; |
|
445 | + $filter[] = '(ts_status '.($filter['ts_status'] == self::DELETED_STATUS ? '=' : '!= ').self::DELETED_STATUS. |
|
446 | + ($filter['ts_status'] == self::DELETED_STATUS ? '' : ' OR ts_status IS NULL').')'; |
|
447 | 447 | } |
448 | 448 | if (!count($filter['ts_owner'])) |
449 | 449 | { |
@@ -451,15 +451,15 @@ discard block |
||
451 | 451 | $this->summary = array(); |
452 | 452 | return array(); |
453 | 453 | } |
454 | - if ($only_summary==false && $criteria && $this->show_sums) |
|
454 | + if ($only_summary == false && $criteria && $this->show_sums) |
|
455 | 455 | { |
456 | 456 | // if we have a criteria AND intend to show the sums we first query the affected ids, |
457 | 457 | // then we throw away criteria and filter, and replace the filter with the list of ids |
458 | - $ids = parent::search($criteria,'egw_timesheet.ts_id as id','','',$wildcard,$empty,$op,false,$filter,$join); |
|
458 | + $ids = parent::search($criteria, 'egw_timesheet.ts_id as id', '', '', $wildcard, $empty, $op, false, $filter, $join); |
|
459 | 459 | //_debug_array($ids); |
460 | 460 | if (empty($ids)) |
461 | 461 | { |
462 | - $this->summary = array('duration'=>0,'price'=>null,'quantity'=>0); |
|
462 | + $this->summary = array('duration'=>0, 'price'=>null, 'quantity'=>0); |
|
463 | 463 | return array(); |
464 | 464 | } |
465 | 465 | unset($criteria); |
@@ -483,45 +483,45 @@ discard block |
||
483 | 483 | |
484 | 484 | if ($only_summary) return $this->summary; |
485 | 485 | |
486 | - if ($this->show_sums && strpos($order_by,'ts_start') !== false && // sums only make sense if ordered by ts_start |
|
486 | + if ($this->show_sums && strpos($order_by, 'ts_start') !== false && // sums only make sense if ordered by ts_start |
|
487 | 487 | $this->db->capabilities['union'] && ($from_unixtime_ts_start = $this->db->from_unixtime('ts_start'))) |
488 | 488 | { |
489 | 489 | $sum_sql = array( |
490 | - 'year' => $this->db->date_format($from_unixtime_ts_start,'%Y'), |
|
491 | - 'month' => $this->db->date_format($from_unixtime_ts_start,'%Y%m'), |
|
492 | - 'week' => $this->db->date_format($from_unixtime_ts_start,$GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts'] == 'Sunday' ? '%X%V' : '%x%v'), |
|
493 | - 'day' => $this->db->date_format($from_unixtime_ts_start,'%Y-%m-%d'), |
|
490 | + 'year' => $this->db->date_format($from_unixtime_ts_start, '%Y'), |
|
491 | + 'month' => $this->db->date_format($from_unixtime_ts_start, '%Y%m'), |
|
492 | + 'week' => $this->db->date_format($from_unixtime_ts_start, $GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts'] == 'Sunday' ? '%X%V' : '%x%v'), |
|
493 | + 'day' => $this->db->date_format($from_unixtime_ts_start, '%Y-%m-%d'), |
|
494 | 494 | ); |
495 | - foreach($this->show_sums as $type) |
|
495 | + foreach ($this->show_sums as $type) |
|
496 | 496 | { |
497 | 497 | $extra_cols[] = $sum_sql[$type].' AS ts_'.$type; |
498 | 498 | $extra_cols[] = '0 AS is_sum_'.$type; |
499 | - $sum_extra_cols[] = str_replace('ts_start','MIN(ts_start)',$sum_sql[$type]); // as we dont group by ts_start |
|
499 | + $sum_extra_cols[] = str_replace('ts_start', 'MIN(ts_start)', $sum_sql[$type]); // as we dont group by ts_start |
|
500 | 500 | $sum_extra_cols[$type] = '0 AS is_sum_'.$type; |
501 | 501 | } |
502 | 502 | // regular entries |
503 | - parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,'UNION',$filter,$join,$need_full_no_count); |
|
503 | + parent::search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, 'UNION', $filter, $join, $need_full_no_count); |
|
504 | 504 | |
505 | - $sort = substr($order_by,8); |
|
505 | + $sort = substr($order_by, 8); |
|
506 | 506 | $union_order = array(); |
507 | - $sum_ts_id = array('year' => -3,'month' => -2,'week' => -1,'day' => 0); |
|
508 | - foreach($this->show_sums as $type) |
|
507 | + $sum_ts_id = array('year' => -3, 'month' => -2, 'week' => -1, 'day' => 0); |
|
508 | + foreach ($this->show_sums as $type) |
|
509 | 509 | { |
510 | - $union_order[] = 'ts_'.$type . ' ' . $sort; |
|
510 | + $union_order[] = 'ts_'.$type.' '.$sort; |
|
511 | 511 | $union_order[] = 'is_sum_'.$type; |
512 | 512 | $sum_extra_cols[$type]{0} = '1'; |
513 | 513 | // the $type sum |
514 | - parent::search($criteria,array( |
|
515 | - (string)$sum_ts_id[$type],"''","''","''",'MIN(ts_start)','SUM(ts_duration) AS ts_duration', |
|
514 | + parent::search($criteria, array( |
|
515 | + (string)$sum_ts_id[$type], "''", "''", "''", 'MIN(ts_start)', 'SUM(ts_duration) AS ts_duration', |
|
516 | 516 | ($this->quantity_sum ? "SUM(ts_quantity) AS ts_quantity" : '0'), |
517 | - '0','NULL','0','0','0','0','0',"SUM($total_sql) AS ts_total" |
|
518 | - ),'GROUP BY '.$sum_sql[$type],$sum_extra_cols,$wildcard,$empty,$op,'UNION',$filter,$join,$need_full_no_count); |
|
517 | + '0', 'NULL', '0', '0', '0', '0', '0', "SUM($total_sql) AS ts_total" |
|
518 | + ), 'GROUP BY '.$sum_sql[$type], $sum_extra_cols, $wildcard, $empty, $op, 'UNION', $filter, $join, $need_full_no_count); |
|
519 | 519 | $sum_extra_cols[$type]{0} = '0'; |
520 | 520 | } |
521 | 521 | $union_order[] = 'ts_start '.$sort; |
522 | - return parent::search('','',implode(',',$union_order),'','',false,'',$start); |
|
522 | + return parent::search('', '', implode(',', $union_order), '', '', false, '', $start); |
|
523 | 523 | } |
524 | - return parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count); |
|
524 | + return parent::search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, $start, $filter, $join, $need_full_no_count); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | /** |
@@ -531,16 +531,16 @@ discard block |
||
531 | 531 | * @param boolean $ignore_acl =false should the acl be checked |
532 | 532 | * @return array|boolean array with timesheet entry, null if timesheet not found or false if no rights |
533 | 533 | */ |
534 | - function read($ts_id,$ignore_acl=false) |
|
534 | + function read($ts_id, $ignore_acl = false) |
|
535 | 535 | { |
536 | 536 | //error_log(__METHOD__."($ts_id,$ignore_acl) ".function_backtrace()); |
537 | 537 | if (!(int)$ts_id || (int)$ts_id != $this->data['ts_id'] && !parent::read($ts_id)) |
538 | 538 | { |
539 | - return null; // entry not found |
|
539 | + return null; // entry not found |
|
540 | 540 | } |
541 | 541 | if (!$ignore_acl && !($ret = $this->check_acl(EGW_ACL_READ))) |
542 | 542 | { |
543 | - return false; // no read rights |
|
543 | + return false; // no read rights |
|
544 | 544 | } |
545 | 545 | return $this->data; |
546 | 546 | } |
@@ -555,7 +555,7 @@ discard block |
||
555 | 555 | * @param boolean $ignore_acl =false should the acl be checked, returns true if no edit-rigts |
556 | 556 | * @return int 0 on success and errno != 0 else |
557 | 557 | */ |
558 | - function save($keys=null,$touch_modified=true,$ignore_acl=false) |
|
558 | + function save($keys = null, $touch_modified = true, $ignore_acl = false) |
|
559 | 559 | { |
560 | 560 | if ($keys) $this->data_merge($keys); |
561 | 561 | |
@@ -573,13 +573,13 @@ discard block |
||
573 | 573 | // check if we have a real modification of an existing record |
574 | 574 | if ($this->data['ts_id']) |
575 | 575 | { |
576 | - $new =& $this->data; |
|
576 | + $new = & $this->data; |
|
577 | 577 | unset($this->data); |
578 | 578 | $this->read($new['ts_id']); |
579 | - $old =& $this->data; |
|
580 | - $this->data =& $new; |
|
579 | + $old = & $this->data; |
|
580 | + $this->data = & $new; |
|
581 | 581 | $changed = array(); |
582 | - if (isset($old)) foreach($old as $name => $value) |
|
582 | + if (isset($old)) foreach ($old as $name => $value) |
|
583 | 583 | { |
584 | 584 | if (isset($new[$name]) && $new[$name] != $value) $changed[] = $name; |
585 | 585 | } |
@@ -590,7 +590,7 @@ discard block |
||
590 | 590 | } |
591 | 591 | |
592 | 592 | // Check for restore of deleted contact, restore held links |
593 | - if($old && $old['ts_status'] == self::DELETED_STATUS && $new['ts_status'] != self::DELETED_STATUS) |
|
593 | + if ($old && $old['ts_status'] == self::DELETED_STATUS && $new['ts_status'] != self::DELETED_STATUS) |
|
594 | 594 | { |
595 | 595 | egw_link::restore(TIMESHEET_APP, $new['ts_id']); |
596 | 596 | } |
@@ -601,14 +601,14 @@ discard block |
||
601 | 601 | |
602 | 602 | $this->tracking->html_content_allow = true; |
603 | 603 | } |
604 | - if ($this->tracking->track($this->data,$old,$this->user) === false) |
|
604 | + if ($this->tracking->track($this->data, $old, $this->user) === false) |
|
605 | 605 | { |
606 | - return implode(', ',$this->tracking->errors); |
|
606 | + return implode(', ', $this->tracking->errors); |
|
607 | 607 | } |
608 | 608 | if (!($err = parent::save())) |
609 | 609 | { |
610 | 610 | // notify the link-class about the update, as other apps may be subscribt to it |
611 | - egw_link::notify_update(TIMESHEET_APP,$this->data['ts_id'],$this->data); |
|
611 | + egw_link::notify_update(TIMESHEET_APP, $this->data['ts_id'], $this->data); |
|
612 | 612 | } |
613 | 613 | |
614 | 614 | return $err; |
@@ -621,15 +621,15 @@ discard block |
||
621 | 621 | * @param boolean $ignore_acl =false should the acl be checked, returns false if no delete-rigts |
622 | 622 | * @return int affected rows, should be 1 if ok, 0 if an error |
623 | 623 | */ |
624 | - function delete($keys=null,$ignore_acl=false) |
|
624 | + function delete($keys = null, $ignore_acl = false) |
|
625 | 625 | { |
626 | - if (!is_array($keys) && (int) $keys) |
|
626 | + if (!is_array($keys) && (int)$keys) |
|
627 | 627 | { |
628 | - $keys = array('ts_id' => (int) $keys); |
|
628 | + $keys = array('ts_id' => (int)$keys); |
|
629 | 629 | } |
630 | 630 | $ts_id = is_null($keys) ? $this->data['ts_id'] : $keys['ts_id']; |
631 | 631 | |
632 | - if (!$ignore_acl && !$this->check_acl(EGW_ACL_DELETE,$ts_id) || !($old = $this->read($ts_id))) |
|
632 | + if (!$ignore_acl && !$this->check_acl(EGW_ACL_DELETE, $ts_id) || !($old = $this->read($ts_id))) |
|
633 | 633 | { |
634 | 634 | return false; |
635 | 635 | } |
@@ -640,12 +640,12 @@ discard block |
||
640 | 640 | $delete = $old; |
641 | 641 | $delete['ts_status'] = self::DELETED_STATUS; |
642 | 642 | $ret = !($this->save($delete)); |
643 | - egw_link::unlink(0,TIMESHEET_APP,$ts_id,'','','',true); |
|
643 | + egw_link::unlink(0, TIMESHEET_APP, $ts_id, '', '', '', true); |
|
644 | 644 | } |
645 | 645 | elseif (($ret = parent::delete($keys)) && $ts_id) |
646 | 646 | { |
647 | 647 | // delete all links to timesheet entry $ts_id |
648 | - egw_link::unlink(0,TIMESHEET_APP,$ts_id); |
|
648 | + egw_link::unlink(0, TIMESHEET_APP, $ts_id); |
|
649 | 649 | } |
650 | 650 | return $ret; |
651 | 651 | } |
@@ -660,7 +660,7 @@ discard block |
||
660 | 660 | function deleteaccount($data) |
661 | 661 | { |
662 | 662 | $account_id = $data['account_id']; |
663 | - $new_owner = $data['new_owner']; |
|
663 | + $new_owner = $data['new_owner']; |
|
664 | 664 | |
665 | 665 | if (!$new_owner) |
666 | 666 | { |
@@ -684,22 +684,22 @@ discard block |
||
684 | 684 | * @param int $status =0 |
685 | 685 | * @return int affected rows, should be 1 if ok, 0 if an error |
686 | 686 | */ |
687 | - function set_status($keys=null, $status=0) |
|
687 | + function set_status($keys = null, $status = 0) |
|
688 | 688 | { |
689 | 689 | $ret = true; |
690 | - if (!is_array($keys) && (int) $keys) |
|
690 | + if (!is_array($keys) && (int)$keys) |
|
691 | 691 | { |
692 | - $keys = array('ts_id' => (int) $keys); |
|
692 | + $keys = array('ts_id' => (int)$keys); |
|
693 | 693 | } |
694 | 694 | $ts_id = is_null($keys) ? $this->data['ts_id'] : $keys['ts_id']; |
695 | 695 | |
696 | - if (!$this->check_acl(EGW_ACL_EDIT,$ts_id) || !$this->read($ts_id,true)) |
|
696 | + if (!$this->check_acl(EGW_ACL_EDIT, $ts_id) || !$this->read($ts_id, true)) |
|
697 | 697 | { |
698 | 698 | return false; |
699 | 699 | } |
700 | 700 | |
701 | 701 | $this->data['ts_status'] = $status; |
702 | - if ($this->save($ts_id)!=0) $ret = false; |
|
702 | + if ($this->save($ts_id) != 0) $ret = false; |
|
703 | 703 | |
704 | 704 | return $ret; |
705 | 705 | } |
@@ -716,7 +716,7 @@ discard block |
||
716 | 716 | { |
717 | 717 | return array('duration' => 0, 'quantity' => 0, 'price' => 0, 'max_modified' => null); |
718 | 718 | } |
719 | - return $this->search(array('ts_id'=>$ids),true,'','','',false,'AND',false,null,'',false,true); |
|
719 | + return $this->search(array('ts_id'=>$ids), true, '', '', '', false, 'AND', false, null, '', false, true); |
|
720 | 720 | } |
721 | 721 | |
722 | 722 | /** |
@@ -727,27 +727,27 @@ discard block |
||
727 | 727 | * @param int|array $entry int ts_id or array with timesheet entry |
728 | 728 | * @return string/boolean string with title, null if timesheet not found, false if no perms to view it |
729 | 729 | */ |
730 | - function link_title( $entry ) |
|
730 | + function link_title($entry) |
|
731 | 731 | { |
732 | 732 | if (!is_array($entry)) |
733 | 733 | { |
734 | 734 | // need to preserve the $this->data |
735 | - $backup =& $this->data; |
|
735 | + $backup = & $this->data; |
|
736 | 736 | unset($this->data); |
737 | - $entry = $this->read( $entry,false,false); |
|
737 | + $entry = $this->read($entry, false, false); |
|
738 | 738 | // restore the data again |
739 | - $this->data =& $backup; |
|
739 | + $this->data = & $backup; |
|
740 | 740 | } |
741 | 741 | if (!$entry) |
742 | 742 | { |
743 | 743 | return $entry; |
744 | 744 | } |
745 | 745 | $format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat']; |
746 | - if (date('H:i',$entry['ts_start']) != '00:00') // dont show 00:00 time, as it means date only |
|
746 | + if (date('H:i', $entry['ts_start']) != '00:00') // dont show 00:00 time, as it means date only |
|
747 | 747 | { |
748 | 748 | $format .= ' '.($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == 12 ? 'h:i a' : 'H:i'); |
749 | 749 | } |
750 | - return date($format,$entry['ts_start']).': '.$entry['ts_title']; |
|
750 | + return date($format, $entry['ts_start']).': '.$entry['ts_title']; |
|
751 | 751 | } |
752 | 752 | |
753 | 753 | /** |
@@ -758,18 +758,18 @@ discard block |
||
758 | 758 | * @param array $ids array with ts_id's |
759 | 759 | * @return array with titles, see link_title |
760 | 760 | */ |
761 | - function link_titles( array $ids ) |
|
761 | + function link_titles(array $ids) |
|
762 | 762 | { |
763 | 763 | $titles = array(); |
764 | - if (($entries = $this->search(array('ts_id' => $ids),'ts_id,ts_title,ts_start'))) |
|
764 | + if (($entries = $this->search(array('ts_id' => $ids), 'ts_id,ts_title,ts_start'))) |
|
765 | 765 | { |
766 | - foreach($entries as $entry) |
|
766 | + foreach ($entries as $entry) |
|
767 | 767 | { |
768 | 768 | $titles[$entry['ts_id']] = $this->link_title($entry); |
769 | 769 | } |
770 | 770 | } |
771 | 771 | // we assume all not returned entries are not readable by the user, as we notify egw_link about all deletes |
772 | - foreach($ids as $id) |
|
772 | + foreach ($ids as $id) |
|
773 | 773 | { |
774 | 774 | if (!isset($titles[$id])) |
775 | 775 | { |
@@ -788,16 +788,16 @@ discard block |
||
788 | 788 | * @param array $options Array of options for the search |
789 | 789 | * @return array with ts_id - title pairs of the matching entries |
790 | 790 | */ |
791 | - function link_query( $pattern, Array &$options = array() ) |
|
791 | + function link_query($pattern, Array &$options = array()) |
|
792 | 792 | { |
793 | 793 | $limit = false; |
794 | 794 | $need_count = false; |
795 | - if($options['start'] || $options['num_rows']) { |
|
795 | + if ($options['start'] || $options['num_rows']) { |
|
796 | 796 | $limit = array($options['start'], $options['num_rows']); |
797 | 797 | $need_count = true; |
798 | 798 | } |
799 | 799 | $result = array(); |
800 | - foreach((array) $this->search($pattern,false,'','','%',false,'OR', $limit, null, '', $need_count) as $ts ) |
|
800 | + foreach ((array)$this->search($pattern, false, '', '', '%', false, 'OR', $limit, null, '', $need_count) as $ts) |
|
801 | 801 | { |
802 | 802 | if ($ts) $result[$ts['ts_id']] = $this->link_title($ts); |
803 | 803 | } |
@@ -814,11 +814,11 @@ discard block |
||
814 | 814 | * @param int $user =null for which user to check, default current user |
815 | 815 | * @return boolean true if access is granted or false otherwise |
816 | 816 | */ |
817 | - function file_access($id,$check,$rel_path=null,$user=null) |
|
817 | + function file_access($id, $check, $rel_path = null, $user = null) |
|
818 | 818 | { |
819 | - unset($rel_path); // not used, but required by function signature |
|
819 | + unset($rel_path); // not used, but required by function signature |
|
820 | 820 | |
821 | - return $this->check_acl($check,$id,$user); |
|
821 | + return $this->check_acl($check, $id, $user); |
|
822 | 822 | } |
823 | 823 | |
824 | 824 | /** |
@@ -830,16 +830,16 @@ discard block |
||
830 | 830 | * @param string $newtitle => the new title of the project |
831 | 831 | * @return boolean true for success, false for invalid parameters |
832 | 832 | */ |
833 | - function update_ts_project($oldtitle='', $newtitle='') |
|
833 | + function update_ts_project($oldtitle = '', $newtitle = '') |
|
834 | 834 | { |
835 | - if(strlen($oldtitle) > 0 && strlen($newtitle) > 0) |
|
835 | + if (strlen($oldtitle) > 0 && strlen($newtitle) > 0) |
|
836 | 836 | { |
837 | - $this->db->update('egw_timesheet',array( |
|
837 | + $this->db->update('egw_timesheet', array( |
|
838 | 838 | 'ts_project' => $newtitle, |
839 | 839 | 'ts_title' => $newtitle, |
840 | - ),array( |
|
840 | + ), array( |
|
841 | 841 | 'ts_project' => $oldtitle, |
842 | - ),__LINE__,__FILE__,TIMESHEET_APP); |
|
842 | + ), __LINE__, __FILE__, TIMESHEET_APP); |
|
843 | 843 | |
844 | 844 | return true; |
845 | 845 | } |
@@ -852,16 +852,16 @@ discard block |
||
852 | 852 | * @param int $pm_id ID of selected project |
853 | 853 | * @return array containing link_id and ts_id |
854 | 854 | */ |
855 | - function get_ts_links($pm_id=0) |
|
855 | + function get_ts_links($pm_id = 0) |
|
856 | 856 | { |
857 | - if($pm_id && isset($GLOBALS['egw_info']['user']['apps']['projectmanager'])) |
|
857 | + if ($pm_id && isset($GLOBALS['egw_info']['user']['apps']['projectmanager'])) |
|
858 | 858 | { |
859 | - $pm_ids = ExecMethod('projectmanager.projectmanager_bo.children',$pm_id); |
|
859 | + $pm_ids = ExecMethod('projectmanager.projectmanager_bo.children', $pm_id); |
|
860 | 860 | $pm_ids[] = $pm_id; |
861 | - $links = solink::get_links('projectmanager',$pm_ids,'timesheet'); // solink::get_links not egw_links::get_links! |
|
861 | + $links = solink::get_links('projectmanager', $pm_ids, 'timesheet'); // solink::get_links not egw_links::get_links! |
|
862 | 862 | if ($links) |
863 | 863 | { |
864 | - $links = array_unique(call_user_func_array('array_merge',$links)); |
|
864 | + $links = array_unique(call_user_func_array('array_merge', $links)); |
|
865 | 865 | } |
866 | 866 | return $links; |
867 | 867 | } |
@@ -879,17 +879,17 @@ discard block |
||
879 | 879 | function notify($data) |
880 | 880 | { |
881 | 881 | //error_log(__METHOD__.'('.array2string($data).')'); |
882 | - $backup =& $this->data; // backup internal data in case class got re-used by ExecMethod |
|
882 | + $backup = & $this->data; // backup internal data in case class got re-used by ExecMethod |
|
883 | 883 | unset($this->data); |
884 | 884 | |
885 | 885 | if ($data['target_app'] == 'projectmanager' && $this->read($data['id'])) |
886 | 886 | { |
887 | 887 | $old_title = isset($data['data']) ? $data['data'][egw_link::OLD_LINK_TITLE] : null; |
888 | - switch($data['type']) |
|
888 | + switch ($data['type']) |
|
889 | 889 | { |
890 | 890 | case 'link': |
891 | 891 | case 'update': |
892 | - if (empty($this->data['ts_project']) || // timesheet has not yet project set --> set just linked one |
|
892 | + if (empty($this->data['ts_project']) || // timesheet has not yet project set --> set just linked one |
|
893 | 893 | isset($old_title) && $this->data['ts_project'] === $old_title) |
894 | 894 | { |
895 | 895 | $pm_id = $data['target_id']; |
@@ -931,17 +931,17 @@ discard block |
||
931 | 931 | * @param array $data =null if given works on that array and returns result, else works on internal data-array |
932 | 932 | * @return array |
933 | 933 | */ |
934 | - function db2data($data=null) |
|
934 | + function db2data($data = null) |
|
935 | 935 | { |
936 | 936 | if (($intern = !is_array($data))) |
937 | 937 | { |
938 | - $data =& $this->data; |
|
938 | + $data = & $this->data; |
|
939 | 939 | } |
940 | 940 | // get pm_id from links and ts_project: either project matching ts_project or first found project |
941 | 941 | if (!isset($data['pm_id']) && $data['ts_id']) |
942 | 942 | { |
943 | 943 | $first_pm_id = null; |
944 | - foreach(egw_link::get_links('timesheet', $data['ts_id'], 'projectmanager') as $pm_id) |
|
944 | + foreach (egw_link::get_links('timesheet', $data['ts_id'], 'projectmanager') as $pm_id) |
|
945 | 945 | { |
946 | 946 | if (!isset($first_pm_id)) $first_pm_id = $pm_id; |
947 | 947 | if ($data['ts_project'] == egw_link::title('projectmanager', $pm_id)) |
@@ -959,7 +959,7 @@ discard block |
||
959 | 959 | $data['ts_project_blur'] = $data['ts_project']; |
960 | 960 | $data['ts_project'] = ''; |
961 | 961 | } |
962 | - return parent::db2data($intern ? null : $data); // important to use null, if $intern! |
|
962 | + return parent::db2data($intern ? null : $data); // important to use null, if $intern! |
|
963 | 963 | } |
964 | 964 | |
965 | 965 | /** |
@@ -971,17 +971,17 @@ discard block |
||
971 | 971 | * @param array $data =null if given works on that array and returns result, else works on internal data-array |
972 | 972 | * @return array |
973 | 973 | */ |
974 | - function data2db($data=null) |
|
974 | + function data2db($data = null) |
|
975 | 975 | { |
976 | 976 | if (($intern = !is_array($data))) |
977 | 977 | { |
978 | - $data =& $this->data; |
|
978 | + $data = & $this->data; |
|
979 | 979 | } |
980 | 980 | // allways store ts_project to be able to search for it, even if no custom project is set |
981 | 981 | if (empty($data['ts_project']) && !is_null($data['ts_project'])) |
982 | 982 | { |
983 | 983 | $data['ts_project'] = $data['pm_id'] ? egw_link::title('projectmanager', $data['pm_id']) : ''; |
984 | 984 | } |
985 | - return parent::data2db($intern ? null : $data); // important to use null, if $intern! |
|
985 | + return parent::data2db($intern ? null : $data); // important to use null, if $intern! |
|
986 | 986 | } |
987 | 987 | } |
@@ -572,7 +572,7 @@ |
||
572 | 572 | * @param array $options Array of options for the search |
573 | 573 | * |
574 | 574 | */ |
575 | - function link_query( $pattern, Array &$options = array() ) |
|
575 | + function link_query( $pattern, array &$options = array() ) |
|
576 | 576 | { |
577 | 577 | if (is_array($pattern)) |
578 | 578 | { |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | /** |
26 | 26 | * Exports records as defined in $_definition |
27 | 27 | * |
28 | - * @param egw_record $_definition |
|
28 | + * @param importexport_definition $_definition |
|
29 | 29 | */ |
30 | 30 | public function export( $_stream, importexport_definition $_definition) { |
31 | 31 | $options = $_definition->plugin_options; |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | * return html for options. |
133 | 133 | * this way the plugin has all opportunities for options tab |
134 | 134 | * |
135 | - * @return string html |
|
135 | + * @return boolean html |
|
136 | 136 | */ |
137 | 137 | public function get_options_etpl() { |
138 | 138 | return false; |
@@ -125,8 +125,8 @@ |
||
125 | 125 | } |
126 | 126 | |
127 | 127 | public static function get_mimetype() { |
128 | - return 'text/csv'; |
|
129 | - } |
|
128 | + return 'text/csv'; |
|
129 | + } |
|
130 | 130 | |
131 | 131 | /** |
132 | 132 | * return html for options. |
@@ -27,51 +27,51 @@ discard block |
||
27 | 27 | * |
28 | 28 | * @param egw_record $_definition |
29 | 29 | */ |
30 | - public function export( $_stream, importexport_definition $_definition) { |
|
30 | + public function export($_stream, importexport_definition $_definition) { |
|
31 | 31 | $options = $_definition->plugin_options; |
32 | 32 | |
33 | 33 | $this->ui = new timesheet_ui(); |
34 | 34 | $selection = array(); |
35 | 35 | |
36 | - if($options['selection'] == 'search') { |
|
37 | - $query = $GLOBALS['egw']->session->appsession('index',TIMESHEET_APP); |
|
38 | - $query['num_rows'] = -1; // all records |
|
39 | - $query['csv_export'] = true; // so get_rows method _can_ produce different content or not store state in the session |
|
40 | - $this->ui->get_rows($query,$selection,$readonlys,true); // true = only return the id's |
|
41 | - } elseif($options['selection'] == 'all') { |
|
36 | + if ($options['selection'] == 'search') { |
|
37 | + $query = $GLOBALS['egw']->session->appsession('index', TIMESHEET_APP); |
|
38 | + $query['num_rows'] = -1; // all records |
|
39 | + $query['csv_export'] = true; // so get_rows method _can_ produce different content or not store state in the session |
|
40 | + $this->ui->get_rows($query, $selection, $readonlys, true); // true = only return the id's |
|
41 | + } elseif ($options['selection'] == 'all') { |
|
42 | 42 | $query = array( |
43 | 43 | 'num_rows' => -1, |
44 | - 'csv_export' => true, // so get_rows method _can_ produce different content or not store state in the session |
|
44 | + 'csv_export' => true, // so get_rows method _can_ produce different content or not store state in the session |
|
45 | 45 | ); |
46 | - $this->ui->get_rows($query,$selection,$readonlys,true); // true = only return the id's |
|
46 | + $this->ui->get_rows($query, $selection, $readonlys, true); // true = only return the id's |
|
47 | 47 | } |
48 | - else if($options['selection'] == 'filter') |
|
48 | + else if ($options['selection'] == 'filter') |
|
49 | 49 | { |
50 | 50 | $fields = importexport_helper_functions::get_filter_fields($_definition->application, $this); |
51 | 51 | $filter = $_definition->filter; |
52 | 52 | $query = array( |
53 | 53 | 'num_rows' => -1, |
54 | - 'csv_export' => true, // so get_rows method _can_ produce different content or not store state in the session |
|
54 | + 'csv_export' => true, // so get_rows method _can_ produce different content or not store state in the session |
|
55 | 55 | 'col_filter' => array() |
56 | 56 | ); |
57 | 57 | |
58 | 58 | // Handle ranges |
59 | - foreach($filter as $field => $value) |
|
59 | + foreach ($filter as $field => $value) |
|
60 | 60 | { |
61 | - if($field == 'cat_id') |
|
61 | + if ($field == 'cat_id') |
|
62 | 62 | { |
63 | 63 | $query['cat_id'] = $value; |
64 | 64 | continue; |
65 | 65 | } |
66 | 66 | $query['col_filter'][$field] = $value; |
67 | - if(!is_array($value) || (!$value['from'] && !$value['to'])) continue; |
|
67 | + if (!is_array($value) || (!$value['from'] && !$value['to'])) continue; |
|
68 | 68 | |
69 | 69 | // Ranges are inclusive, so should be provided that way (from 2 to 10 includes 2 and 10) |
70 | - if($value['from']) $query['col_filter'][] = "$field >= " . (int)$value['from']; |
|
71 | - if($value['to']) $query['col_filter'][] = "$field <= " . (int)$value['to']; |
|
70 | + if ($value['from']) $query['col_filter'][] = "$field >= ".(int)$value['from']; |
|
71 | + if ($value['to']) $query['col_filter'][] = "$field <= ".(int)$value['to']; |
|
72 | 72 | unset($query['col_filter'][$field]); |
73 | 73 | } |
74 | - $this->ui->get_rows($query,$selection,$readonlys,true); // true = only return the id's |
|
74 | + $this->ui->get_rows($query, $selection, $readonlys, true); // true = only return the id's |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | |
@@ -83,12 +83,12 @@ discard block |
||
83 | 83 | // support other selectors atm. |
84 | 84 | foreach ($selection as $identifier) { |
85 | 85 | $record = new timesheet_egw_record($identifier); |
86 | - if($options['convert']) { |
|
86 | + if ($options['convert']) { |
|
87 | 87 | importexport_export_csv::convert($record, timesheet_egw_record::$types, 'timesheet', $this->selects); |
88 | 88 | } else { |
89 | 89 | // Implode arrays, so they don't say 'Array' |
90 | - foreach($record->get_record_array() as $key => $value) { |
|
91 | - if(is_array($value)) $record->$key = implode(',', $value); |
|
90 | + foreach ($record->get_record_array() as $key => $value) { |
|
91 | + if (is_array($value)) $record->$key = implode(',', $value); |
|
92 | 92 | } |
93 | 93 | } |
94 | 94 | $export_object->export_record($record); |
@@ -151,10 +151,10 @@ discard block |
||
151 | 151 | public function get_selects() |
152 | 152 | { |
153 | 153 | $this->selects = array( |
154 | - 'ts_status' => $this->ui->status_labels+array(lang('No status')) |
|
154 | + 'ts_status' => $this->ui->status_labels + array(lang('No status')) |
|
155 | 155 | ); |
156 | - foreach($this->selects['ts_status'] as &$status) { |
|
157 | - $status = str_replace(' ','',$status); // Remove |
|
156 | + foreach ($this->selects['ts_status'] as &$status) { |
|
157 | + $status = str_replace(' ', '', $status); // Remove |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | } |
@@ -163,9 +163,9 @@ discard block |
||
163 | 163 | */ |
164 | 164 | public function get_filter_fields(Array &$filters) |
165 | 165 | { |
166 | - foreach($filters as $field_name => &$settings) |
|
166 | + foreach ($filters as $field_name => &$settings) |
|
167 | 167 | { |
168 | - if($this->selects[$field_name]) $settings['values'] = $this->selects[$field_name]; |
|
168 | + if ($this->selects[$field_name]) $settings['values'] = $this->selects[$field_name]; |
|
169 | 169 | } |
170 | 170 | } |
171 | 171 |
@@ -14,7 +14,8 @@ discard block |
||
14 | 14 | /** |
15 | 15 | * export plugin of addressbook |
16 | 16 | */ |
17 | -class timesheet_export_csv implements importexport_iface_export_plugin { |
|
17 | +class timesheet_export_csv implements importexport_iface_export_plugin |
|
18 | +{ |
|
18 | 19 | |
19 | 20 | public function __construct() |
20 | 21 | { |
@@ -27,18 +28,22 @@ discard block |
||
27 | 28 | * |
28 | 29 | * @param egw_record $_definition |
29 | 30 | */ |
30 | - public function export( $_stream, importexport_definition $_definition) { |
|
31 | + public function export( $_stream, importexport_definition $_definition) |
|
32 | + { |
|
31 | 33 | $options = $_definition->plugin_options; |
32 | 34 | |
33 | 35 | $this->ui = new timesheet_ui(); |
34 | 36 | $selection = array(); |
35 | 37 | |
36 | - if($options['selection'] == 'search') { |
|
38 | + if($options['selection'] == 'search') |
|
39 | + { |
|
37 | 40 | $query = $GLOBALS['egw']->session->appsession('index',TIMESHEET_APP); |
38 | 41 | $query['num_rows'] = -1; // all records |
39 | 42 | $query['csv_export'] = true; // so get_rows method _can_ produce different content or not store state in the session |
40 | 43 | $this->ui->get_rows($query,$selection,$readonlys,true); // true = only return the id's |
41 | - } elseif($options['selection'] == 'all') { |
|
44 | + } |
|
45 | + elseif($options['selection'] == 'all') |
|
46 | + { |
|
42 | 47 | $query = array( |
43 | 48 | 'num_rows' => -1, |
44 | 49 | 'csv_export' => true, // so get_rows method _can_ produce different content or not store state in the session |
@@ -64,11 +69,20 @@ discard block |
||
64 | 69 | continue; |
65 | 70 | } |
66 | 71 | $query['col_filter'][$field] = $value; |
67 | - if(!is_array($value) || (!$value['from'] && !$value['to'])) continue; |
|
72 | + if(!is_array($value) || (!$value['from'] && !$value['to'])) |
|
73 | + { |
|
74 | + continue; |
|
75 | + } |
|
68 | 76 | |
69 | 77 | // Ranges are inclusive, so should be provided that way (from 2 to 10 includes 2 and 10) |
70 | - if($value['from']) $query['col_filter'][] = "$field >= " . (int)$value['from']; |
|
71 | - if($value['to']) $query['col_filter'][] = "$field <= " . (int)$value['to']; |
|
78 | + if($value['from']) |
|
79 | + { |
|
80 | + $query['col_filter'][] = "$field >= " . (int)$value['from']; |
|
81 | + } |
|
82 | + if($value['to']) |
|
83 | + { |
|
84 | + $query['col_filter'][] = "$field <= " . (int)$value['to']; |
|
85 | + } |
|
72 | 86 | unset($query['col_filter'][$field]); |
73 | 87 | } |
74 | 88 | $this->ui->get_rows($query,$selection,$readonlys,true); // true = only return the id's |
@@ -81,14 +95,22 @@ discard block |
||
81 | 95 | |
82 | 96 | // $options['selection'] is array of identifiers as this plugin doesn't |
83 | 97 | // support other selectors atm. |
84 | - foreach ($selection as $identifier) { |
|
98 | + foreach ($selection as $identifier) |
|
99 | + { |
|
85 | 100 | $record = new timesheet_egw_record($identifier); |
86 | - if($options['convert']) { |
|
101 | + if($options['convert']) |
|
102 | + { |
|
87 | 103 | importexport_export_csv::convert($record, timesheet_egw_record::$types, 'timesheet', $this->selects); |
88 | - } else { |
|
104 | + } |
|
105 | + else |
|
106 | + { |
|
89 | 107 | // Implode arrays, so they don't say 'Array' |
90 | - foreach($record->get_record_array() as $key => $value) { |
|
91 | - if(is_array($value)) $record->$key = implode(',', $value); |
|
108 | + foreach($record->get_record_array() as $key => $value) |
|
109 | + { |
|
110 | + if(is_array($value)) |
|
111 | + { |
|
112 | + $record->$key = implode(',', $value); |
|
113 | + } |
|
92 | 114 | } |
93 | 115 | } |
94 | 116 | $export_object->export_record($record); |
@@ -102,7 +124,8 @@ discard block |
||
102 | 124 | * |
103 | 125 | * @return string name |
104 | 126 | */ |
105 | - public static function get_name() { |
|
127 | + public static function get_name() |
|
128 | + { |
|
106 | 129 | return lang('Timesheet CSV export'); |
107 | 130 | } |
108 | 131 | |
@@ -111,7 +134,8 @@ discard block |
||
111 | 134 | * |
112 | 135 | * @return string descriprion |
113 | 136 | */ |
114 | - public static function get_description() { |
|
137 | + public static function get_description() |
|
138 | + { |
|
115 | 139 | return lang("Exports entries from your Timesheet into a CSV File. "); |
116 | 140 | } |
117 | 141 | |
@@ -120,11 +144,13 @@ discard block |
||
120 | 144 | * |
121 | 145 | * @return string suffix |
122 | 146 | */ |
123 | - public static function get_filesuffix() { |
|
147 | + public static function get_filesuffix() |
|
148 | + { |
|
124 | 149 | return 'csv'; |
125 | 150 | } |
126 | 151 | |
127 | - public static function get_mimetype() { |
|
152 | + public static function get_mimetype() |
|
153 | + { |
|
128 | 154 | return 'text/csv'; |
129 | 155 | } |
130 | 156 | |
@@ -134,7 +160,8 @@ discard block |
||
134 | 160 | * |
135 | 161 | * @return string html |
136 | 162 | */ |
137 | - public function get_options_etpl() { |
|
163 | + public function get_options_etpl() |
|
164 | + { |
|
138 | 165 | return false; |
139 | 166 | } |
140 | 167 | |
@@ -142,7 +169,8 @@ discard block |
||
142 | 169 | * returns slectors of this plugin via xajax |
143 | 170 | * |
144 | 171 | */ |
145 | - public function get_selectors_etpl() { |
|
172 | + public function get_selectors_etpl() |
|
173 | + { |
|
146 | 174 | return array( |
147 | 175 | 'name' => 'importexport.export_csv_selectors', |
148 | 176 | ); |
@@ -153,7 +181,8 @@ discard block |
||
153 | 181 | $this->selects = array( |
154 | 182 | 'ts_status' => $this->ui->status_labels+array(lang('No status')) |
155 | 183 | ); |
156 | - foreach($this->selects['ts_status'] as &$status) { |
|
184 | + foreach($this->selects['ts_status'] as &$status) |
|
185 | + { |
|
157 | 186 | $status = str_replace(' ','',$status); // Remove |
158 | 187 | } |
159 | 188 | |
@@ -165,7 +194,10 @@ discard block |
||
165 | 194 | { |
166 | 195 | foreach($filters as $field_name => &$settings) |
167 | 196 | { |
168 | - if($this->selects[$field_name]) $settings['values'] = $this->selects[$field_name]; |
|
197 | + if($this->selects[$field_name]) |
|
198 | + { |
|
199 | + $settings['values'] = $this->selects[$field_name]; |
|
200 | + } |
|
169 | 201 | } |
170 | 202 | } |
171 | 203 |
@@ -247,7 +247,7 @@ |
||
247 | 247 | $this->selects['info_status'] = $this->bo->get_status(); |
248 | 248 | } |
249 | 249 | |
250 | - public function get_filter_fields(Array &$filters) |
|
250 | + public function get_filter_fields(array &$filters) |
|
251 | 251 | { |
252 | 252 | foreach($filters as $field_name => &$settings) |
253 | 253 | { |
@@ -104,8 +104,7 @@ |
||
104 | 104 | /** |
105 | 105 | * imports entries according to given definition object. |
106 | 106 | * @param resource $_stream |
107 | - * @param string $_charset |
|
108 | - * @param definition $_definition |
|
107 | + * @param importexport_definition $_definition |
|
109 | 108 | */ |
110 | 109 | public function import( $_stream, importexport_definition $_definition ) { |
111 | 110 | $import_csv = new importexport_import_csv( $_stream, array( |
@@ -72,8 +72,8 @@ discard block |
||
72 | 72 | private $bo; |
73 | 73 | |
74 | 74 | /** |
75 | - * For figuring out if a record has changed |
|
76 | - */ |
|
75 | + * For figuring out if a record has changed |
|
76 | + */ |
|
77 | 77 | protected $tracking; |
78 | 78 | |
79 | 79 | /** |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | protected $errors = array(); |
98 | 98 | |
99 | 99 | /** |
100 | - * List of actions, and how many times that action was taken |
|
101 | - */ |
|
102 | - protected $results = array(); |
|
100 | + * List of actions, and how many times that action was taken |
|
101 | + */ |
|
102 | + protected $results = array(); |
|
103 | 103 | |
104 | 104 | /** |
105 | 105 | * imports entries according to given definition object. |
@@ -458,40 +458,40 @@ discard block |
||
458 | 458 | } |
459 | 459 | |
460 | 460 | /** |
461 | - * Returns warnings that were encountered during importing |
|
462 | - * Maximum of one warning message per record, but you can append if you need to |
|
463 | - * |
|
464 | - * @return Array ( |
|
465 | - * record_# => warning message |
|
466 | - * ) |
|
467 | - */ |
|
468 | - public function get_warnings() { |
|
461 | + * Returns warnings that were encountered during importing |
|
462 | + * Maximum of one warning message per record, but you can append if you need to |
|
463 | + * |
|
464 | + * @return Array ( |
|
465 | + * record_# => warning message |
|
466 | + * ) |
|
467 | + */ |
|
468 | + public function get_warnings() { |
|
469 | 469 | return $this->warnings; |
470 | 470 | } |
471 | 471 | |
472 | 472 | /** |
473 | - * Returns errors that were encountered during importing |
|
474 | - * Maximum of one error message per record, but you can append if you need to |
|
475 | - * |
|
476 | - * @return Array ( |
|
477 | - * record_# => error message |
|
478 | - * ) |
|
479 | - */ |
|
480 | - public function get_errors() { |
|
473 | + * Returns errors that were encountered during importing |
|
474 | + * Maximum of one error message per record, but you can append if you need to |
|
475 | + * |
|
476 | + * @return Array ( |
|
477 | + * record_# => error message |
|
478 | + * ) |
|
479 | + */ |
|
480 | + public function get_errors() { |
|
481 | 481 | return $this->errors; |
482 | 482 | } |
483 | 483 | |
484 | 484 | /** |
485 | - * Returns a list of actions taken, and the number of records for that action. |
|
486 | - * Actions are things like 'insert', 'update', 'delete', and may be different for each plugin. |
|
487 | - * |
|
488 | - * @return Array ( |
|
489 | - * action => record count |
|
490 | - * ) |
|
491 | - */ |
|
492 | - public function get_results() { |
|
493 | - return $this->results; |
|
494 | - } |
|
485 | + * Returns a list of actions taken, and the number of records for that action. |
|
486 | + * Actions are things like 'insert', 'update', 'delete', and may be different for each plugin. |
|
487 | + * |
|
488 | + * @return Array ( |
|
489 | + * action => record count |
|
490 | + * ) |
|
491 | + */ |
|
492 | + public function get_results() { |
|
493 | + return $this->results; |
|
494 | + } |
|
495 | 495 | // end of iface_export_plugin |
496 | 496 | |
497 | 497 | // Extra conversion functions - must be static |
@@ -15,18 +15,18 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * class import_csv for timesheet |
17 | 17 | */ |
18 | -class timesheet_import_csv implements importexport_iface_import_plugin { |
|
18 | +class timesheet_import_csv implements importexport_iface_import_plugin { |
|
19 | 19 | |
20 | 20 | private static $plugin_options = array( |
21 | - 'fieldsep', // char |
|
22 | - 'charset', // string |
|
23 | - 'update_cats', // string {override|add} overides record |
|
21 | + 'fieldsep', // char |
|
22 | + 'charset', // string |
|
23 | + 'update_cats', // string {override|add} overides record |
|
24 | 24 | // with cat(s) from csv OR add the cat from |
25 | 25 | // csv file to exeisting cat(s) of record |
26 | 26 | 'num_header_lines', // int number of header lines |
27 | 27 | 'field_conversion', // array( $csv_col_num => conversion) |
28 | - 'field_mapping', // array( $csv_col_num => adb_filed) |
|
29 | - 'conditions', /* => array containing condition arrays: |
|
28 | + 'field_mapping', // array( $csv_col_num => adb_filed) |
|
29 | + 'conditions', /* => array containing condition arrays: |
|
30 | 30 | 'type' => exists, // exists |
31 | 31 | 'string' => '#kundennummer', |
32 | 32 | 'true' => array( |
@@ -50,14 +50,14 @@ discard block |
||
50 | 50 | /** |
51 | 51 | * actions wich could be done to data entries |
52 | 52 | */ |
53 | - protected static $actions = array( 'none', 'update', 'insert', 'delete', ); |
|
53 | + protected static $actions = array('none', 'update', 'insert', 'delete',); |
|
54 | 54 | |
55 | 55 | /** |
56 | 56 | * conditions for actions |
57 | 57 | * |
58 | 58 | * @var array |
59 | 59 | */ |
60 | - protected static $conditions = array( 'exists' ); |
|
60 | + protected static $conditions = array('exists'); |
|
61 | 61 | |
62 | 62 | /** |
63 | 63 | * @var definition |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | * @param string $_charset |
106 | 106 | * @param definition $_definition |
107 | 107 | */ |
108 | - public function import( $_stream, importexport_definition $_definition ) { |
|
109 | - $import_csv = new importexport_import_csv( $_stream, array( |
|
108 | + public function import($_stream, importexport_definition $_definition) { |
|
109 | + $import_csv = new importexport_import_csv($_stream, array( |
|
110 | 110 | 'fieldsep' => $_definition->plugin_options['fieldsep'], |
111 | 111 | 'charset' => $_definition->plugin_options['charset'], |
112 | 112 | )); |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | $this->user = $GLOBALS['egw_info']['user']['account_id']; |
117 | 117 | |
118 | 118 | // dry run? |
119 | - $this->dry_run = isset( $_definition->plugin_options['dry_run'] ) ? $_definition->plugin_options['dry_run'] : false; |
|
119 | + $this->dry_run = isset($_definition->plugin_options['dry_run']) ? $_definition->plugin_options['dry_run'] : false; |
|
120 | 120 | |
121 | 121 | // fetch the bo |
122 | 122 | $this->bo = new timesheet_bo(); |
@@ -134,15 +134,15 @@ discard block |
||
134 | 134 | $import_csv->conversion_class = $this; |
135 | 135 | |
136 | 136 | //check if file has a header lines |
137 | - if ( isset( $_definition->plugin_options['num_header_lines'] ) && $_definition->plugin_options['num_header_lines'] > 0) { |
|
137 | + if (isset($_definition->plugin_options['num_header_lines']) && $_definition->plugin_options['num_header_lines'] > 0) { |
|
138 | 138 | $import_csv->skip_records($_definition->plugin_options['num_header_lines']); |
139 | - } elseif(isset($_definition->plugin_options['has_header_line']) && $_definition->plugin_options['has_header_line']) { |
|
139 | + } elseif (isset($_definition->plugin_options['has_header_line']) && $_definition->plugin_options['has_header_line']) { |
|
140 | 140 | // First method is preferred |
141 | 141 | $import_csv->skip_records(1); |
142 | 142 | } |
143 | 143 | |
144 | 144 | // set Owner |
145 | - $_definition->plugin_options['record_owner'] = isset( $_definition->plugin_options['record_owner'] ) ? |
|
145 | + $_definition->plugin_options['record_owner'] = isset($_definition->plugin_options['record_owner']) ? |
|
146 | 146 | $_definition->plugin_options['record_owner'] : $this->user; |
147 | 147 | |
148 | 148 | // Used to try to automatically match names to account IDs |
@@ -156,9 +156,9 @@ discard block |
||
156 | 156 | ); |
157 | 157 | |
158 | 158 | // Status need leading spaces removed |
159 | - foreach($lookups['ts_status'] as $id => &$label) { |
|
160 | - $label = str_replace(' ', '',trim($label)); |
|
161 | - if($label == '') unset($lookups['ts_status'][$id]); |
|
159 | + foreach ($lookups['ts_status'] as $id => &$label) { |
|
160 | + $label = str_replace(' ', '', trim($label)); |
|
161 | + if ($label == '') unset($lookups['ts_status'][$id]); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | // Start counting successes |
@@ -168,22 +168,22 @@ discard block |
||
168 | 168 | // Failures |
169 | 169 | $this->errors = array(); |
170 | 170 | |
171 | - while ( $record = $import_csv->get_record() ) { |
|
171 | + while ($record = $import_csv->get_record()) { |
|
172 | 172 | $success = false; |
173 | 173 | |
174 | 174 | // don't import empty records |
175 | - if( count( array_unique( $record ) ) < 2 ) continue; |
|
175 | + if (count(array_unique($record)) < 2) continue; |
|
176 | 176 | |
177 | 177 | $result = importexport_import_csv::convert($record, timesheet_egw_record::$types, 'timesheet', $lookups, $_definition->plugin_options['convert']); |
178 | - if($result) $this->warnings[$import_csv->get_current_position()] = $result; |
|
178 | + if ($result) $this->warnings[$import_csv->get_current_position()] = $result; |
|
179 | 179 | |
180 | 180 | // Automatically handle text categories without explicit translation |
181 | - foreach(array('ts_status','cat_id') as $field) { |
|
182 | - if(!is_numeric($record[$field])) { |
|
183 | - $translate_key = 'translate'.(substr($field,0,2) == 'ts' ? substr($field,2) : '_cat_id'); |
|
184 | - if($key = array_search($record[$field], $lookups[$field])) { |
|
181 | + foreach (array('ts_status', 'cat_id') as $field) { |
|
182 | + if (!is_numeric($record[$field])) { |
|
183 | + $translate_key = 'translate'.(substr($field, 0, 2) == 'ts' ? substr($field, 2) : '_cat_id'); |
|
184 | + if ($key = array_search($record[$field], $lookups[$field])) { |
|
185 | 185 | $record[$field] = $key; |
186 | - } elseif(array_key_exists($translate_key, $_definition->plugin_options)) { |
|
186 | + } elseif (array_key_exists($translate_key, $_definition->plugin_options)) { |
|
187 | 187 | $t_field = $_definition->plugin_options[$translate_key]; |
188 | 188 | switch ($t_field) { |
189 | 189 | case '': |
@@ -194,29 +194,29 @@ discard block |
||
194 | 194 | case '~skip~': |
195 | 195 | continue 2; |
196 | 196 | default: |
197 | - if(strpos($t_field, 'add') === 0) { |
|
197 | + if (strpos($t_field, 'add') === 0) { |
|
198 | 198 | // Check for a parent |
199 | - list($name, $parent_name) = explode('~',$t_field); |
|
200 | - if($parent_name) { |
|
199 | + list($name, $parent_name) = explode('~', $t_field); |
|
200 | + if ($parent_name) { |
|
201 | 201 | $parent = importexport_helper_functions::cat_name2id($parent_name); |
202 | 202 | } |
203 | 203 | |
204 | - if($field == 'cat_id') { |
|
204 | + if ($field == 'cat_id') { |
|
205 | 205 | $record[$field] = importexport_helper_functions::cat_name2id($record[$field], $parent); |
206 | 206 | } elseif ($field == 'ts_status') { |
207 | 207 | end($this->bo->status_labels); |
208 | - $id = key($this->bo->status_labels)+1; |
|
208 | + $id = key($this->bo->status_labels) + 1; |
|
209 | 209 | $this->bo->status_labels[$id] = $record[$field]; |
210 | 210 | $this->bo->status_labels_config[$id] = array( |
211 | 211 | 'name' => $record[$field], |
212 | 212 | 'parent' => $parent, |
213 | 213 | 'admin' => false |
214 | 214 | ); |
215 | - config::save_value('status_labels',$this->bo->status_labels_config,TIMESHEET_APP); |
|
215 | + config::save_value('status_labels', $this->bo->status_labels_config, TIMESHEET_APP); |
|
216 | 216 | $lookups[$field][$id] = $name; |
217 | 217 | $record[$field] = $id; |
218 | 218 | } |
219 | - } elseif($key = array_search($t_field, $lookups[$field])) { |
|
219 | + } elseif ($key = array_search($t_field, $lookups[$field])) { |
|
220 | 220 | $record[$field] = $key; |
221 | 221 | } else { |
222 | 222 | $record[$field] = $t_field; |
@@ -228,11 +228,11 @@ discard block |
||
228 | 228 | } |
229 | 229 | |
230 | 230 | // Set creator, unless it's supposed to come from CSV file |
231 | - if($_definition->plugin_options['owner_from_csv'] && $record['ts_owner']) { |
|
232 | - if(!is_numeric($record['ts_owner'])) { |
|
231 | + if ($_definition->plugin_options['owner_from_csv'] && $record['ts_owner']) { |
|
232 | + if (!is_numeric($record['ts_owner'])) { |
|
233 | 233 | // Automatically handle text owner without explicit translation |
234 | 234 | $new_owner = importexport_helper_functions::account_name2id($record['ts_owner']); |
235 | - if($new_owner == '') { |
|
235 | + if ($new_owner == '') { |
|
236 | 236 | $this->errors[$import_csv->get_current_position()] = lang( |
237 | 237 | 'Unable to convert "%1" to account ID. Using plugin setting (%2) for %3.', |
238 | 238 | $record['ts_owner'], |
@@ -249,11 +249,11 @@ discard block |
||
249 | 249 | } |
250 | 250 | |
251 | 251 | // Check account IDs |
252 | - foreach(array('ts_modifier') as $field) { |
|
253 | - if($record[$field] && !is_numeric($record[$field])) { |
|
252 | + foreach (array('ts_modifier') as $field) { |
|
253 | + if ($record[$field] && !is_numeric($record[$field])) { |
|
254 | 254 | // Try an automatic conversion |
255 | 255 | $account_id = importexport_helper_functions::account_name2id($record[$field]); |
256 | - if($account_id && strtoupper(common::grab_owner_name($account_id)) == strtoupper($record[$field])) { |
|
256 | + if ($account_id && strtoupper(common::grab_owner_name($account_id)) == strtoupper($record[$field])) { |
|
257 | 257 | $record[$field] = $account_id; |
258 | 258 | } else { |
259 | 259 | $this->errors[$import_csv->get_current_position()] = lang( |
@@ -269,35 +269,35 @@ discard block |
||
269 | 269 | // Special values |
270 | 270 | if ($record['addressbook'] && !is_numeric($record['addressbook'])) |
271 | 271 | { |
272 | - list($lastname,$firstname,$org_name) = explode(',',$record['addressbook']); |
|
273 | - $record['addressbook'] = self::addr_id($lastname,$firstname,$org_name); |
|
272 | + list($lastname, $firstname, $org_name) = explode(',', $record['addressbook']); |
|
273 | + $record['addressbook'] = self::addr_id($lastname, $firstname, $org_name); |
|
274 | 274 | } |
275 | 275 | |
276 | - if ( $_definition->plugin_options['conditions'] ) { |
|
277 | - foreach ( $_definition->plugin_options['conditions'] as $condition ) { |
|
276 | + if ($_definition->plugin_options['conditions']) { |
|
277 | + foreach ($_definition->plugin_options['conditions'] as $condition) { |
|
278 | 278 | $results = array(); |
279 | - switch ( $condition['type'] ) { |
|
279 | + switch ($condition['type']) { |
|
280 | 280 | // exists |
281 | 281 | case 'exists' : |
282 | - if($record[$condition['string']]) { |
|
282 | + if ($record[$condition['string']]) { |
|
283 | 283 | $results = $this->bo->search(array($condition['string'] => $record[$condition['string']])); |
284 | 284 | } |
285 | 285 | |
286 | - if ( is_array( $results ) && count( array_keys( $results )) >= 1 ) { |
|
286 | + if (is_array($results) && count(array_keys($results)) >= 1) { |
|
287 | 287 | // apply action to all records matching this exists condition |
288 | 288 | $action = $condition['true']; |
289 | - foreach ( (array)$results as $result ) { |
|
289 | + foreach ((array)$results as $result) { |
|
290 | 290 | $record['ts_id'] = $result['ts_id']; |
291 | - if ( $_definition->plugin_options['update_cats'] == 'add' ) { |
|
292 | - if ( !is_array( $result['cat_id'] ) ) $result['cat_id'] = explode( ',', $result['cat_id'] ); |
|
293 | - if ( !is_array( $record['cat_id'] ) ) $record['cat_id'] = explode( ',', $record['cat_id'] ); |
|
294 | - $record['cat_id'] = implode( ',', array_unique( array_merge( $record['cat_id'], $result['cat_id'] ) ) ); |
|
291 | + if ($_definition->plugin_options['update_cats'] == 'add') { |
|
292 | + if (!is_array($result['cat_id'])) $result['cat_id'] = explode(',', $result['cat_id']); |
|
293 | + if (!is_array($record['cat_id'])) $record['cat_id'] = explode(',', $record['cat_id']); |
|
294 | + $record['cat_id'] = implode(',', array_unique(array_merge($record['cat_id'], $result['cat_id']))); |
|
295 | 295 | } |
296 | - $success = $this->action( $action['action'], $record, $import_csv->get_current_position() ); |
|
296 | + $success = $this->action($action['action'], $record, $import_csv->get_current_position()); |
|
297 | 297 | } |
298 | 298 | } else { |
299 | 299 | $action = $condition['false']; |
300 | - $success = ($this->action( $action['action'], $record, $import_csv->get_current_position() )); |
|
300 | + $success = ($this->action($action['action'], $record, $import_csv->get_current_position())); |
|
301 | 301 | } |
302 | 302 | break; |
303 | 303 | |
@@ -310,9 +310,9 @@ discard block |
||
310 | 310 | } |
311 | 311 | } else { |
312 | 312 | // unconditional insert |
313 | - $success = $this->action( 'insert', $record, $import_csv->get_current_position() ); |
|
313 | + $success = $this->action('insert', $record, $import_csv->get_current_position()); |
|
314 | 314 | } |
315 | - if($success) $count++; |
|
315 | + if ($success) $count++; |
|
316 | 316 | } |
317 | 317 | return $count; |
318 | 318 | } |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | * @param array $_data tracker data for the action |
325 | 325 | * @return bool success or not |
326 | 326 | */ |
327 | - private function action ( $_action, $_data, $record_num = 0 ) { |
|
327 | + private function action($_action, $_data, $record_num = 0) { |
|
328 | 328 | $result = true; |
329 | 329 | switch ($_action) { |
330 | 330 | case 'none' : |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | $old_record = new timesheet_egw_record($_data['ts_id']); |
335 | 335 | $old = $old_record->get_record_array(); |
336 | 336 | |
337 | - if(!$this->definition->plugin_options['change_owner']) { |
|
337 | + if (!$this->definition->plugin_options['change_owner']) { |
|
338 | 338 | // Don't change creator of an existing ticket |
339 | 339 | unset($_data['ts_owner']); |
340 | 340 | } |
@@ -342,35 +342,35 @@ discard block |
||
342 | 342 | // Merge to deal with fields not in import record |
343 | 343 | $_data = array_merge($old, $_data); |
344 | 344 | $changed = $this->tracking->changed_fields($_data, $old); |
345 | - if(count($changed) == 0 && !$this->definition->plugin_options['update_timestamp']) { |
|
345 | + if (count($changed) == 0 && !$this->definition->plugin_options['update_timestamp']) { |
|
346 | 346 | break; |
347 | 347 | } |
348 | 348 | |
349 | 349 | // Clear old link, if different |
350 | 350 | if ($_data['ts_id'] && array_key_exists('pm_id', $_data) && $_data['pm_id'] != $old['pm_id']) { |
351 | - egw_link::unlink2(0,TIMESHEET_APP,$_data['ts_id'],0,'projectmanager',$old['pm_id']); |
|
351 | + egw_link::unlink2(0, TIMESHEET_APP, $_data['ts_id'], 0, 'projectmanager', $old['pm_id']); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | // Fall through |
355 | 355 | case 'insert' : |
356 | - if ( $this->dry_run ) { |
|
356 | + if ($this->dry_run) { |
|
357 | 357 | //print_r($_data); |
358 | 358 | $this->results[$_action]++; |
359 | 359 | break; |
360 | 360 | } else { |
361 | - $result = $this->bo->save( $_data); |
|
361 | + $result = $this->bo->save($_data); |
|
362 | 362 | $_data['ts_id'] = $this->bo->data['ts_id']; |
363 | 363 | |
364 | 364 | // Set projectmanager link |
365 | 365 | if ($_data['pm_id']) { |
366 | - egw_link::link(TIMESHEET_APP,$_data['ts_id'],'projectmanager',$_data['pm_id']); |
|
366 | + egw_link::link(TIMESHEET_APP, $_data['ts_id'], 'projectmanager', $_data['pm_id']); |
|
367 | 367 | } |
368 | 368 | |
369 | - if($result) { |
|
369 | + if ($result) { |
|
370 | 370 | $this->errors[$record_num] = lang('Permissions error - %1 could not %2', |
371 | 371 | $GLOBALS['egw']->accounts->id2name($_data['owner']), |
372 | 372 | lang($_action) |
373 | - ) . ' ' . $result; |
|
373 | + ).' '.$result; |
|
374 | 374 | } else { |
375 | 375 | $this->results[$_action]++; |
376 | 376 | $result = $this->bo->data['ts_id']; |
@@ -382,22 +382,22 @@ discard block |
||
382 | 382 | } |
383 | 383 | |
384 | 384 | // Process some additional fields |
385 | - if(!is_numeric($result)) { |
|
385 | + if (!is_numeric($result)) { |
|
386 | 386 | return $result; |
387 | 387 | } |
388 | 388 | $_link_id = false; |
389 | - foreach(self::$special_fields as $field => $desc) { |
|
390 | - if(!$_data[$field]) continue; |
|
389 | + foreach (self::$special_fields as $field => $desc) { |
|
390 | + if (!$_data[$field]) continue; |
|
391 | 391 | |
392 | 392 | // Links |
393 | - if(strpos('link', $field) === 0) { |
|
393 | + if (strpos('link', $field) === 0) { |
|
394 | 394 | list($app, $id) = explode(':', $_data[$field]); |
395 | 395 | } else { |
396 | 396 | $app = $field; |
397 | 397 | $id = $_data[$field]; |
398 | 398 | } |
399 | 399 | if ($app && $app_id) { |
400 | - $link_id = egw_link::link('timesheet',$id,$app,$app_id); |
|
400 | + $link_id = egw_link::link('timesheet', $id, $app, $app_id); |
|
401 | 401 | } |
402 | 402 | } |
403 | 403 | return $result; |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | // end of iface_export_plugin |
494 | 494 | |
495 | 495 | // Extra conversion functions - must be static |
496 | - public static function addr_id( $n_family,$n_given=null,$org_name=null ) { |
|
496 | + public static function addr_id($n_family, $n_given = null, $org_name = null) { |
|
497 | 497 | |
498 | 498 | // find in Addressbook, at least n_family AND (n_given OR org_name) have to match |
499 | 499 | static $contacts; |
@@ -503,18 +503,18 @@ discard block |
||
503 | 503 | list($n_family, $n_given, $org_name) = explode(',', $n_family); |
504 | 504 | } |
505 | 505 | $n_family = trim($n_family); |
506 | - if(!is_null($n_given)) $n_given = trim($n_given); |
|
506 | + if (!is_null($n_given)) $n_given = trim($n_given); |
|
507 | 507 | if (!is_object($contacts)) |
508 | 508 | { |
509 | - $contacts =& CreateObject('phpgwapi.contacts'); |
|
509 | + $contacts = & CreateObject('phpgwapi.contacts'); |
|
510 | 510 | } |
511 | 511 | if (!is_null($org_name)) // org_name given? |
512 | 512 | { |
513 | 513 | $org_name = trim($org_name); |
514 | - $addrs = $contacts->read( 0,0,array('id'),'',"n_family=$n_family,n_given=$n_given,org_name=$org_name" ); |
|
514 | + $addrs = $contacts->read(0, 0, array('id'), '', "n_family=$n_family,n_given=$n_given,org_name=$org_name"); |
|
515 | 515 | if (!count($addrs)) |
516 | 516 | { |
517 | - $addrs = $contacts->read( 0,0,array('id'),'',"n_family=$n_family,org_name=$org_name",'','n_family,org_name'); |
|
517 | + $addrs = $contacts->read(0, 0, array('id'), '', "n_family=$n_family,org_name=$org_name", '', 'n_family,org_name'); |
|
518 | 518 | } |
519 | 519 | } |
520 | 520 | if (!is_null($n_given) && (is_null($org_name) || !count($addrs))) // first name given and no result so far |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | } |
524 | 524 | if (is_null($n_given) && is_null($org_name)) // just one name given, check against fn (= full name) |
525 | 525 | { |
526 | - $addrs = $contacts->read( 0,0,array('id'),'',"n_fn=$n_family",'','n_fn' ); |
|
526 | + $addrs = $contacts->read(0, 0, array('id'), '', "n_fn=$n_family", '', 'n_fn'); |
|
527 | 527 | } |
528 | 528 | if (count($addrs)) |
529 | 529 | { |
@@ -15,7 +15,8 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * class import_csv for timesheet |
17 | 17 | */ |
18 | -class timesheet_import_csv implements importexport_iface_import_plugin { |
|
18 | +class timesheet_import_csv implements importexport_iface_import_plugin |
|
19 | +{ |
|
19 | 20 | |
20 | 21 | private static $plugin_options = array( |
21 | 22 | 'fieldsep', // char |
@@ -105,7 +106,8 @@ discard block |
||
105 | 106 | * @param string $_charset |
106 | 107 | * @param definition $_definition |
107 | 108 | */ |
108 | - public function import( $_stream, importexport_definition $_definition ) { |
|
109 | + public function import( $_stream, importexport_definition $_definition ) |
|
110 | + { |
|
109 | 111 | $import_csv = new importexport_import_csv( $_stream, array( |
110 | 112 | 'fieldsep' => $_definition->plugin_options['fieldsep'], |
111 | 113 | 'charset' => $_definition->plugin_options['charset'], |
@@ -134,9 +136,12 @@ discard block |
||
134 | 136 | $import_csv->conversion_class = $this; |
135 | 137 | |
136 | 138 | //check if file has a header lines |
137 | - if ( isset( $_definition->plugin_options['num_header_lines'] ) && $_definition->plugin_options['num_header_lines'] > 0) { |
|
139 | + if ( isset( $_definition->plugin_options['num_header_lines'] ) && $_definition->plugin_options['num_header_lines'] > 0) |
|
140 | + { |
|
138 | 141 | $import_csv->skip_records($_definition->plugin_options['num_header_lines']); |
139 | - } elseif(isset($_definition->plugin_options['has_header_line']) && $_definition->plugin_options['has_header_line']) { |
|
142 | + } |
|
143 | + elseif(isset($_definition->plugin_options['has_header_line']) && $_definition->plugin_options['has_header_line']) |
|
144 | + { |
|
140 | 145 | // First method is preferred |
141 | 146 | $import_csv->skip_records(1); |
142 | 147 | } |
@@ -156,9 +161,13 @@ discard block |
||
156 | 161 | ); |
157 | 162 | |
158 | 163 | // Status need leading spaces removed |
159 | - foreach($lookups['ts_status'] as $id => &$label) { |
|
164 | + foreach($lookups['ts_status'] as $id => &$label) |
|
165 | + { |
|
160 | 166 | $label = str_replace(' ', '',trim($label)); |
161 | - if($label == '') unset($lookups['ts_status'][$id]); |
|
167 | + if($label == '') |
|
168 | + { |
|
169 | + unset($lookups['ts_status'][$id]); |
|
170 | + } |
|
162 | 171 | } |
163 | 172 | |
164 | 173 | // Start counting successes |
@@ -168,24 +177,37 @@ discard block |
||
168 | 177 | // Failures |
169 | 178 | $this->errors = array(); |
170 | 179 | |
171 | - while ( $record = $import_csv->get_record() ) { |
|
180 | + while ( $record = $import_csv->get_record() ) |
|
181 | + { |
|
172 | 182 | $success = false; |
173 | 183 | |
174 | 184 | // don't import empty records |
175 | - if( count( array_unique( $record ) ) < 2 ) continue; |
|
185 | + if( count( array_unique( $record ) ) < 2 ) |
|
186 | + { |
|
187 | + continue; |
|
188 | + } |
|
176 | 189 | |
177 | 190 | $result = importexport_import_csv::convert($record, timesheet_egw_record::$types, 'timesheet', $lookups, $_definition->plugin_options['convert']); |
178 | - if($result) $this->warnings[$import_csv->get_current_position()] = $result; |
|
191 | + if($result) |
|
192 | + { |
|
193 | + $this->warnings[$import_csv->get_current_position()] = $result; |
|
194 | + } |
|
179 | 195 | |
180 | 196 | // Automatically handle text categories without explicit translation |
181 | - foreach(array('ts_status','cat_id') as $field) { |
|
182 | - if(!is_numeric($record[$field])) { |
|
197 | + foreach(array('ts_status','cat_id') as $field) |
|
198 | + { |
|
199 | + if(!is_numeric($record[$field])) |
|
200 | + { |
|
183 | 201 | $translate_key = 'translate'.(substr($field,0,2) == 'ts' ? substr($field,2) : '_cat_id'); |
184 | - if($key = array_search($record[$field], $lookups[$field])) { |
|
202 | + if($key = array_search($record[$field], $lookups[$field])) |
|
203 | + { |
|
185 | 204 | $record[$field] = $key; |
186 | - } elseif(array_key_exists($translate_key, $_definition->plugin_options)) { |
|
205 | + } |
|
206 | + elseif(array_key_exists($translate_key, $_definition->plugin_options)) |
|
207 | + { |
|
187 | 208 | $t_field = $_definition->plugin_options[$translate_key]; |
188 | - switch ($t_field) { |
|
209 | + switch ($t_field) |
|
210 | + { |
|
189 | 211 | case '': |
190 | 212 | case '0': |
191 | 213 | // Skip that field |
@@ -194,16 +216,21 @@ discard block |
||
194 | 216 | case '~skip~': |
195 | 217 | continue 2; |
196 | 218 | default: |
197 | - if(strpos($t_field, 'add') === 0) { |
|
219 | + if(strpos($t_field, 'add') === 0) |
|
220 | + { |
|
198 | 221 | // Check for a parent |
199 | 222 | list($name, $parent_name) = explode('~',$t_field); |
200 | - if($parent_name) { |
|
223 | + if($parent_name) |
|
224 | + { |
|
201 | 225 | $parent = importexport_helper_functions::cat_name2id($parent_name); |
202 | 226 | } |
203 | 227 | |
204 | - if($field == 'cat_id') { |
|
228 | + if($field == 'cat_id') |
|
229 | + { |
|
205 | 230 | $record[$field] = importexport_helper_functions::cat_name2id($record[$field], $parent); |
206 | - } elseif ($field == 'ts_status') { |
|
231 | + } |
|
232 | + elseif ($field == 'ts_status') |
|
233 | + { |
|
207 | 234 | end($this->bo->status_labels); |
208 | 235 | $id = key($this->bo->status_labels)+1; |
209 | 236 | $this->bo->status_labels[$id] = $record[$field]; |
@@ -216,9 +243,13 @@ discard block |
||
216 | 243 | $lookups[$field][$id] = $name; |
217 | 244 | $record[$field] = $id; |
218 | 245 | } |
219 | - } elseif($key = array_search($t_field, $lookups[$field])) { |
|
246 | + } |
|
247 | + elseif($key = array_search($t_field, $lookups[$field])) |
|
248 | + { |
|
220 | 249 | $record[$field] = $key; |
221 | - } else { |
|
250 | + } |
|
251 | + else |
|
252 | + { |
|
222 | 253 | $record[$field] = $t_field; |
223 | 254 | } |
224 | 255 | break; |
@@ -228,11 +259,14 @@ discard block |
||
228 | 259 | } |
229 | 260 | |
230 | 261 | // Set creator, unless it's supposed to come from CSV file |
231 | - if($_definition->plugin_options['owner_from_csv'] && $record['ts_owner']) { |
|
232 | - if(!is_numeric($record['ts_owner'])) { |
|
262 | + if($_definition->plugin_options['owner_from_csv'] && $record['ts_owner']) |
|
263 | + { |
|
264 | + if(!is_numeric($record['ts_owner'])) |
|
265 | + { |
|
233 | 266 | // Automatically handle text owner without explicit translation |
234 | 267 | $new_owner = importexport_helper_functions::account_name2id($record['ts_owner']); |
235 | - if($new_owner == '') { |
|
268 | + if($new_owner == '') |
|
269 | + { |
|
236 | 270 | $this->errors[$import_csv->get_current_position()] = lang( |
237 | 271 | 'Unable to convert "%1" to account ID. Using plugin setting (%2) for %3.', |
238 | 272 | $record['ts_owner'], |
@@ -240,22 +274,31 @@ discard block |
||
240 | 274 | lang($this->bo->field2label['ts_owner']) |
241 | 275 | ); |
242 | 276 | $record['ts_owner'] = $_definition->plugin_options['record_owner']; |
243 | - } else { |
|
277 | + } |
|
278 | + else |
|
279 | + { |
|
244 | 280 | $record['ts_owner'] = $new_owner; |
245 | 281 | } |
246 | 282 | } |
247 | - } elseif ($_definition->plugin_options['record_owner']) { |
|
283 | + } |
|
284 | + elseif ($_definition->plugin_options['record_owner']) |
|
285 | + { |
|
248 | 286 | $record['ts_owner'] = $_definition->plugin_options['record_owner']; |
249 | 287 | } |
250 | 288 | |
251 | 289 | // Check account IDs |
252 | - foreach(array('ts_modifier') as $field) { |
|
253 | - if($record[$field] && !is_numeric($record[$field])) { |
|
290 | + foreach(array('ts_modifier') as $field) |
|
291 | + { |
|
292 | + if($record[$field] && !is_numeric($record[$field])) |
|
293 | + { |
|
254 | 294 | // Try an automatic conversion |
255 | 295 | $account_id = importexport_helper_functions::account_name2id($record[$field]); |
256 | - if($account_id && strtoupper(common::grab_owner_name($account_id)) == strtoupper($record[$field])) { |
|
296 | + if($account_id && strtoupper(common::grab_owner_name($account_id)) == strtoupper($record[$field])) |
|
297 | + { |
|
257 | 298 | $record[$field] = $account_id; |
258 | - } else { |
|
299 | + } |
|
300 | + else |
|
301 | + { |
|
259 | 302 | $this->errors[$import_csv->get_current_position()] = lang( |
260 | 303 | 'Unable to convert "%1" to account ID. Using plugin setting (%2) for %3.', |
261 | 304 | $record[$field], |
@@ -273,29 +316,44 @@ discard block |
||
273 | 316 | $record['addressbook'] = self::addr_id($lastname,$firstname,$org_name); |
274 | 317 | } |
275 | 318 | |
276 | - if ( $_definition->plugin_options['conditions'] ) { |
|
277 | - foreach ( $_definition->plugin_options['conditions'] as $condition ) { |
|
319 | + if ( $_definition->plugin_options['conditions'] ) |
|
320 | + { |
|
321 | + foreach ( $_definition->plugin_options['conditions'] as $condition ) |
|
322 | + { |
|
278 | 323 | $results = array(); |
279 | - switch ( $condition['type'] ) { |
|
324 | + switch ( $condition['type'] ) |
|
325 | + { |
|
280 | 326 | // exists |
281 | 327 | case 'exists' : |
282 | - if($record[$condition['string']]) { |
|
328 | + if($record[$condition['string']]) |
|
329 | + { |
|
283 | 330 | $results = $this->bo->search(array($condition['string'] => $record[$condition['string']])); |
284 | 331 | } |
285 | 332 | |
286 | - if ( is_array( $results ) && count( array_keys( $results )) >= 1 ) { |
|
333 | + if ( is_array( $results ) && count( array_keys( $results )) >= 1 ) |
|
334 | + { |
|
287 | 335 | // apply action to all records matching this exists condition |
288 | 336 | $action = $condition['true']; |
289 | - foreach ( (array)$results as $result ) { |
|
337 | + foreach ( (array)$results as $result ) |
|
338 | + { |
|
290 | 339 | $record['ts_id'] = $result['ts_id']; |
291 | - if ( $_definition->plugin_options['update_cats'] == 'add' ) { |
|
292 | - if ( !is_array( $result['cat_id'] ) ) $result['cat_id'] = explode( ',', $result['cat_id'] ); |
|
293 | - if ( !is_array( $record['cat_id'] ) ) $record['cat_id'] = explode( ',', $record['cat_id'] ); |
|
340 | + if ( $_definition->plugin_options['update_cats'] == 'add' ) |
|
341 | + { |
|
342 | + if ( !is_array( $result['cat_id'] ) ) |
|
343 | + { |
|
344 | + $result['cat_id'] = explode( ',', $result['cat_id'] ); |
|
345 | + } |
|
346 | + if ( !is_array( $record['cat_id'] ) ) |
|
347 | + { |
|
348 | + $record['cat_id'] = explode( ',', $record['cat_id'] ); |
|
349 | + } |
|
294 | 350 | $record['cat_id'] = implode( ',', array_unique( array_merge( $record['cat_id'], $result['cat_id'] ) ) ); |
295 | 351 | } |
296 | 352 | $success = $this->action( $action['action'], $record, $import_csv->get_current_position() ); |
297 | 353 | } |
298 | - } else { |
|
354 | + } |
|
355 | + else |
|
356 | + { |
|
299 | 357 | $action = $condition['false']; |
300 | 358 | $success = ($this->action( $action['action'], $record, $import_csv->get_current_position() )); |
301 | 359 | } |
@@ -306,13 +364,21 @@ discard block |
||
306 | 364 | die('condition / action not supported!!!'); |
307 | 365 | break; |
308 | 366 | } |
309 | - if ($action['last']) break; |
|
367 | + if ($action['last']) |
|
368 | + { |
|
369 | + break; |
|
370 | + } |
|
310 | 371 | } |
311 | - } else { |
|
372 | + } |
|
373 | + else |
|
374 | + { |
|
312 | 375 | // unconditional insert |
313 | 376 | $success = $this->action( 'insert', $record, $import_csv->get_current_position() ); |
314 | 377 | } |
315 | - if($success) $count++; |
|
378 | + if($success) |
|
379 | + { |
|
380 | + $count++; |
|
381 | + } |
|
316 | 382 | } |
317 | 383 | return $count; |
318 | 384 | } |
@@ -324,9 +390,11 @@ discard block |
||
324 | 390 | * @param array $_data tracker data for the action |
325 | 391 | * @return bool success or not |
326 | 392 | */ |
327 | - private function action ( $_action, $_data, $record_num = 0 ) { |
|
393 | + private function action ( $_action, $_data, $record_num = 0 ) |
|
394 | + { |
|
328 | 395 | $result = true; |
329 | - switch ($_action) { |
|
396 | + switch ($_action) |
|
397 | + { |
|
330 | 398 | case 'none' : |
331 | 399 | return true; |
332 | 400 | case 'update' : |
@@ -334,7 +402,8 @@ discard block |
||
334 | 402 | $old_record = new timesheet_egw_record($_data['ts_id']); |
335 | 403 | $old = $old_record->get_record_array(); |
336 | 404 | |
337 | - if(!$this->definition->plugin_options['change_owner']) { |
|
405 | + if(!$this->definition->plugin_options['change_owner']) |
|
406 | + { |
|
338 | 407 | // Don't change creator of an existing ticket |
339 | 408 | unset($_data['ts_owner']); |
340 | 409 | } |
@@ -342,36 +411,45 @@ discard block |
||
342 | 411 | // Merge to deal with fields not in import record |
343 | 412 | $_data = array_merge($old, $_data); |
344 | 413 | $changed = $this->tracking->changed_fields($_data, $old); |
345 | - if(count($changed) == 0 && !$this->definition->plugin_options['update_timestamp']) { |
|
414 | + if(count($changed) == 0 && !$this->definition->plugin_options['update_timestamp']) |
|
415 | + { |
|
346 | 416 | break; |
347 | 417 | } |
348 | 418 | |
349 | 419 | // Clear old link, if different |
350 | - if ($_data['ts_id'] && array_key_exists('pm_id', $_data) && $_data['pm_id'] != $old['pm_id']) { |
|
420 | + if ($_data['ts_id'] && array_key_exists('pm_id', $_data) && $_data['pm_id'] != $old['pm_id']) |
|
421 | + { |
|
351 | 422 | egw_link::unlink2(0,TIMESHEET_APP,$_data['ts_id'],0,'projectmanager',$old['pm_id']); |
352 | 423 | } |
353 | 424 | |
354 | 425 | // Fall through |
355 | 426 | case 'insert' : |
356 | - if ( $this->dry_run ) { |
|
427 | + if ( $this->dry_run ) |
|
428 | + { |
|
357 | 429 | //print_r($_data); |
358 | 430 | $this->results[$_action]++; |
359 | 431 | break; |
360 | - } else { |
|
432 | + } |
|
433 | + else |
|
434 | + { |
|
361 | 435 | $result = $this->bo->save( $_data); |
362 | 436 | $_data['ts_id'] = $this->bo->data['ts_id']; |
363 | 437 | |
364 | 438 | // Set projectmanager link |
365 | - if ($_data['pm_id']) { |
|
439 | + if ($_data['pm_id']) |
|
440 | + { |
|
366 | 441 | egw_link::link(TIMESHEET_APP,$_data['ts_id'],'projectmanager',$_data['pm_id']); |
367 | 442 | } |
368 | 443 | |
369 | - if($result) { |
|
444 | + if($result) |
|
445 | + { |
|
370 | 446 | $this->errors[$record_num] = lang('Permissions error - %1 could not %2', |
371 | 447 | $GLOBALS['egw']->accounts->id2name($_data['owner']), |
372 | 448 | lang($_action) |
373 | 449 | ) . ' ' . $result; |
374 | - } else { |
|
450 | + } |
|
451 | + else |
|
452 | + { |
|
375 | 453 | $this->results[$_action]++; |
376 | 454 | $result = $this->bo->data['ts_id']; |
377 | 455 | } |
@@ -382,21 +460,30 @@ discard block |
||
382 | 460 | } |
383 | 461 | |
384 | 462 | // Process some additional fields |
385 | - if(!is_numeric($result)) { |
|
463 | + if(!is_numeric($result)) |
|
464 | + { |
|
386 | 465 | return $result; |
387 | 466 | } |
388 | 467 | $_link_id = false; |
389 | - foreach(self::$special_fields as $field => $desc) { |
|
390 | - if(!$_data[$field]) continue; |
|
468 | + foreach(self::$special_fields as $field => $desc) |
|
469 | + { |
|
470 | + if(!$_data[$field]) |
|
471 | + { |
|
472 | + continue; |
|
473 | + } |
|
391 | 474 | |
392 | 475 | // Links |
393 | - if(strpos('link', $field) === 0) { |
|
476 | + if(strpos('link', $field) === 0) |
|
477 | + { |
|
394 | 478 | list($app, $id) = explode(':', $_data[$field]); |
395 | - } else { |
|
479 | + } |
|
480 | + else |
|
481 | + { |
|
396 | 482 | $app = $field; |
397 | 483 | $id = $_data[$field]; |
398 | 484 | } |
399 | - if ($app && $app_id) { |
|
485 | + if ($app && $app_id) |
|
486 | + { |
|
400 | 487 | $link_id = egw_link::link('timesheet',$id,$app,$app_id); |
401 | 488 | } |
402 | 489 | } |
@@ -408,7 +495,8 @@ discard block |
||
408 | 495 | * |
409 | 496 | * @return string name |
410 | 497 | */ |
411 | - public static function get_name() { |
|
498 | + public static function get_name() |
|
499 | + { |
|
412 | 500 | return lang('Timesheet CSV import'); |
413 | 501 | } |
414 | 502 | |
@@ -417,7 +505,8 @@ discard block |
||
417 | 505 | * |
418 | 506 | * @return string descriprion |
419 | 507 | */ |
420 | - public static function get_description() { |
|
508 | + public static function get_description() |
|
509 | + { |
|
421 | 510 | return lang("Imports entries into the timesheet from a CSV File. "); |
422 | 511 | } |
423 | 512 | |
@@ -426,7 +515,8 @@ discard block |
||
426 | 515 | * |
427 | 516 | * @return string suffix (comma seperated) |
428 | 517 | */ |
429 | - public static function get_filesuffix() { |
|
518 | + public static function get_filesuffix() |
|
519 | + { |
|
430 | 520 | return 'csv'; |
431 | 521 | } |
432 | 522 | |
@@ -442,7 +532,8 @@ discard block |
||
442 | 532 | * preserv => array, |
443 | 533 | * ) |
444 | 534 | */ |
445 | - public function get_options_etpl() { |
|
535 | + public function get_options_etpl() |
|
536 | + { |
|
446 | 537 | // lets do it! |
447 | 538 | } |
448 | 539 | |
@@ -451,7 +542,8 @@ discard block |
||
451 | 542 | * |
452 | 543 | * @return string etemplate name |
453 | 544 | */ |
454 | - public function get_selectors_etpl() { |
|
545 | + public function get_selectors_etpl() |
|
546 | + { |
|
455 | 547 | // lets do it! |
456 | 548 | } |
457 | 549 | |
@@ -463,7 +555,8 @@ discard block |
||
463 | 555 | * record_# => warning message |
464 | 556 | * ) |
465 | 557 | */ |
466 | - public function get_warnings() { |
|
558 | + public function get_warnings() |
|
559 | + { |
|
467 | 560 | return $this->warnings; |
468 | 561 | } |
469 | 562 | |
@@ -475,7 +568,8 @@ discard block |
||
475 | 568 | * record_# => error message |
476 | 569 | * ) |
477 | 570 | */ |
478 | - public function get_errors() { |
|
571 | + public function get_errors() |
|
572 | + { |
|
479 | 573 | return $this->errors; |
480 | 574 | } |
481 | 575 | |
@@ -487,13 +581,15 @@ discard block |
||
487 | 581 | * action => record count |
488 | 582 | * ) |
489 | 583 | */ |
490 | - public function get_results() { |
|
584 | + public function get_results() |
|
585 | + { |
|
491 | 586 | return $this->results; |
492 | 587 | } |
493 | 588 | // end of iface_export_plugin |
494 | 589 | |
495 | 590 | // Extra conversion functions - must be static |
496 | - public static function addr_id( $n_family,$n_given=null,$org_name=null ) { |
|
591 | + public static function addr_id( $n_family,$n_given=null,$org_name=null ) |
|
592 | + { |
|
497 | 593 | |
498 | 594 | // find in Addressbook, at least n_family AND (n_given OR org_name) have to match |
499 | 595 | static $contacts; |
@@ -503,28 +599,40 @@ discard block |
||
503 | 599 | list($n_family, $n_given, $org_name) = explode(',', $n_family); |
504 | 600 | } |
505 | 601 | $n_family = trim($n_family); |
506 | - if(!is_null($n_given)) $n_given = trim($n_given); |
|
602 | + if(!is_null($n_given)) |
|
603 | + { |
|
604 | + $n_given = trim($n_given); |
|
605 | + } |
|
507 | 606 | if (!is_object($contacts)) |
508 | 607 | { |
509 | 608 | $contacts =& CreateObject('phpgwapi.contacts'); |
510 | 609 | } |
511 | - if (!is_null($org_name)) // org_name given? |
|
610 | + if (!is_null($org_name)) |
|
611 | + { |
|
612 | + // org_name given? |
|
512 | 613 | { |
513 | 614 | $org_name = trim($org_name); |
615 | + } |
|
514 | 616 | $addrs = $contacts->read( 0,0,array('id'),'',"n_family=$n_family,n_given=$n_given,org_name=$org_name" ); |
515 | 617 | if (!count($addrs)) |
516 | 618 | { |
517 | 619 | $addrs = $contacts->read( 0,0,array('id'),'',"n_family=$n_family,org_name=$org_name",'','n_family,org_name'); |
518 | 620 | } |
519 | 621 | } |
520 | - if (!is_null($n_given) && (is_null($org_name) || !count($addrs))) // first name given and no result so far |
|
622 | + if (!is_null($n_given) && (is_null($org_name) || !count($addrs))) |
|
623 | + { |
|
624 | + // first name given and no result so far |
|
521 | 625 | { |
522 | 626 | $addrs = $contacts->search(array('n_family' => $n_family, 'n_given' => $n_given)); |
523 | 627 | } |
524 | - if (is_null($n_given) && is_null($org_name)) // just one name given, check against fn (= full name) |
|
628 | + } |
|
629 | + if (is_null($n_given) && is_null($org_name)) |
|
630 | + { |
|
631 | + // just one name given, check against fn (= full name) |
|
525 | 632 | { |
526 | 633 | $addrs = $contacts->read( 0,0,array('id'),'',"n_fn=$n_family",'','n_fn' ); |
527 | 634 | } |
635 | + } |
|
528 | 636 | if (count($addrs)) |
529 | 637 | { |
530 | 638 | return $addrs[0]['id']; |
@@ -1053,7 +1053,7 @@ |
||
1053 | 1053 | * @param int &$success number of succeded actions |
1054 | 1054 | * @param int &$failed number of failed actions (not enought permissions) |
1055 | 1055 | * @param string &$action_msg translated verb for the actions, to be used in a message like %1 timesheets 'deleted' |
1056 | - * @param string/array $session_name 'index' or 'email', or array with session-data depending if we are in the main list or the popup |
|
1056 | + * @param string $session_name 'index' or 'email', or array with session-data depending if we are in the main list or the popup |
|
1057 | 1057 | * @return boolean true if all actions succeded, false otherwise |
1058 | 1058 | */ |
1059 | 1059 | function action($action,$checked,$use_all,&$success,&$failed,&$action_msg,$session_name,&$msg) |
@@ -942,7 +942,7 @@ |
||
942 | 942 | * |
943 | 943 | * @return array see nextmatch_widget::egw_actions() |
944 | 944 | */ |
945 | - public function get_actions(Array $query) |
|
945 | + public function get_actions(array $query) |
|
946 | 946 | { |
947 | 947 | $actions = array( |
948 | 948 | 'open' => array( // does edit if allowed, otherwise view |
@@ -49,10 +49,10 @@ discard block |
||
49 | 49 | |
50 | 50 | function view() |
51 | 51 | { |
52 | - $this->edit(null,true); |
|
52 | + $this->edit(null, true); |
|
53 | 53 | } |
54 | 54 | |
55 | - function edit($content = null,$view = false) |
|
55 | + function edit($content = null, $view = false) |
|
56 | 56 | { |
57 | 57 | $etpl = new etemplate_new('timesheet.edit'); |
58 | 58 | if (!is_array($content)) |
@@ -74,20 +74,19 @@ discard block |
||
74 | 74 | { |
75 | 75 | $this->data = array( |
76 | 76 | 'ts_start' => $this->today, |
77 | - 'start_time' => '', // force empty start-time |
|
78 | - 'end_time' => egw_time::to($this->now,'H:i'), |
|
77 | + 'start_time' => '', // force empty start-time |
|
78 | + 'end_time' => egw_time::to($this->now, 'H:i'), |
|
79 | 79 | 'ts_owner' => $GLOBALS['egw_info']['user']['account_id'], |
80 | - 'cat_id' => (int) $_REQUEST['cat_id'], |
|
80 | + 'cat_id' => (int)$_REQUEST['cat_id'], |
|
81 | 81 | 'ts_status'=> $GLOBALS['egw_info']['user']['preferences']['timesheet']['predefined_status'], |
82 | 82 | ); |
83 | 83 | } |
84 | 84 | $matches = null; |
85 | - $referer = preg_match('/menuaction=([^&]+)/',$_SERVER['HTTP_REFERER'],$matches) ? $matches[1] : |
|
86 | - (strpos($_SERVER['HTTP_REFERER'],'/infolog/index.php') !== false ? 'infolog.infolog_ui.index' : TIMESHEET_APP.'.timesheet_ui.index'); |
|
85 | + $referer = preg_match('/menuaction=([^&]+)/', $_SERVER['HTTP_REFERER'], $matches) ? $matches[1] : (strpos($_SERVER['HTTP_REFERER'], '/infolog/index.php') !== false ? 'infolog.infolog_ui.index' : TIMESHEET_APP.'.timesheet_ui.index'); |
|
87 | 86 | |
88 | 87 | if (!$this->check_statusForEditRights($this->data)) |
89 | 88 | { |
90 | - $view = true; //only admin can edit with this status |
|
89 | + $view = true; //only admin can edit with this status |
|
91 | 90 | $only_admin_edit = true; |
92 | 91 | $msg = lang('only Admin can edit this status'); |
93 | 92 | } |
@@ -100,7 +99,7 @@ discard block |
||
100 | 99 | { |
101 | 100 | if ($this->status_labels_config[$content['ts_status']]['admin']) |
102 | 101 | { |
103 | - $view = true; //only admin can edit with this status |
|
102 | + $view = true; //only admin can edit with this status |
|
104 | 103 | $only_admin_edit = true; |
105 | 104 | $msg = lang('only Admin can edit this status'); |
106 | 105 | } |
@@ -114,29 +113,29 @@ discard block |
||
114 | 113 | { |
115 | 114 | //$content['ts_start'] += $content['start_time']; |
116 | 115 | $start = new egw_time($content['ts_start']); |
117 | - $start_time = explode(':',$content['start_time']); |
|
118 | - $start->setTime($start_time[0],$start_time[1]); |
|
116 | + $start_time = explode(':', $content['start_time']); |
|
117 | + $start->setTime($start_time[0], $start_time[1]); |
|
119 | 118 | $content['ts_start'] = $start->format('ts'); |
120 | 119 | } |
121 | 120 | if (isset($content['end_time'])) // end-time specified |
122 | 121 | { |
123 | 122 | $end = new egw_time($content['ts_start']); |
124 | - $end_time = explode(':',$content['end_time']); |
|
125 | - $end->setTime($end_time[0],$end_time[1]); |
|
123 | + $end_time = explode(':', $content['end_time']); |
|
124 | + $end->setTime($end_time[0], $end_time[1]); |
|
126 | 125 | } |
127 | 126 | if ($end && $start) // start- & end-time --> calculate the duration |
128 | 127 | { |
129 | 128 | $content['ts_duration'] = ($end->format('ts') - $start->format('ts')) / 60; |
130 | 129 | // check if negative duration is caused by wrap over midnight |
131 | - if ($content['ts_duration'] < 0 && $content['ts_duration'] > -24*60) |
|
130 | + if ($content['ts_duration'] < 0 && $content['ts_duration'] > -24 * 60) |
|
132 | 131 | { |
133 | - $content['ts_duration'] += 24*60; |
|
132 | + $content['ts_duration'] += 24 * 60; |
|
134 | 133 | } |
135 | 134 | //echo "<p>end_time=$content[end_time], start_time=$content[start_time] --> duration=$content[ts_duration]</p>\n"; |
136 | 135 | } |
137 | 136 | elseif ($content['ts_duration'] && $end) // no start, calculate from end and duration |
138 | 137 | { |
139 | - $content['ts_start'] = $end->format('ts') - 60*$content['ts_duration']; |
|
138 | + $content['ts_start'] = $end->format('ts') - 60 * $content['ts_duration']; |
|
140 | 139 | //echo "<p>end_time=$content[end_time], duration=$content[ts_duration] --> ts_start=$content[ts_start]=".egw_time::to($content['ts_start'])."</p>\n"; |
141 | 140 | } |
142 | 141 | if ($content['ts_duration'] > 0) unset($content['end_time']); |
@@ -146,18 +145,18 @@ discard block |
||
146 | 145 | $referer = $content['referer']; |
147 | 146 | $content['ts_project_blur'] = $content['pm_id'] ? egw_link::title('projectmanager', $content['pm_id']) : ''; |
148 | 147 | $this->data = $content; |
149 | - foreach(array('button','view','referer','tabs','start_time') as $key) |
|
148 | + foreach (array('button', 'view', 'referer', 'tabs', 'start_time') as $key) |
|
150 | 149 | { |
151 | 150 | unset($this->data[$key]); |
152 | 151 | } |
153 | - switch($button) |
|
152 | + switch ($button) |
|
154 | 153 | { |
155 | 154 | case 'edit': |
156 | 155 | if ($this->check_acl(EGW_ACL_EDIT) && !$only_admin_edit) $view = false; |
157 | 156 | break; |
158 | 157 | |
159 | 158 | case 'undelete': |
160 | - if($content['ts_status'] == self::DELETED_STATUS) |
|
159 | + if ($content['ts_status'] == self::DELETED_STATUS) |
|
161 | 160 | { |
162 | 161 | unset($content['ts_status']); |
163 | 162 | $this->data['ts_status'] = ''; |
@@ -175,14 +174,14 @@ discard block |
||
175 | 174 | } |
176 | 175 | if (!$this->data['ts_quantity']) |
177 | 176 | { |
178 | - $etpl->set_validation_error('ts_quantity',lang('Field must not be empty !!!')); |
|
177 | + $etpl->set_validation_error('ts_quantity', lang('Field must not be empty !!!')); |
|
179 | 178 | } |
180 | 179 | if ($this->data['ts_duration'] < 0) |
181 | 180 | { |
182 | - $etpl->set_validation_error('start_time',lang('Starttime has to be before endtime !!!')); |
|
181 | + $etpl->set_validation_error('start_time', lang('Starttime has to be before endtime !!!')); |
|
183 | 182 | } |
184 | 183 | // set ts_title to ts_project if short viewtype (title is not editable) |
185 | - if($this->ts_viewtype == 'short') |
|
184 | + if ($this->ts_viewtype == 'short') |
|
186 | 185 | { |
187 | 186 | $this->data['ts_title'] = $this->data['ts_project']; |
188 | 187 | } |
@@ -193,9 +192,9 @@ discard block |
||
193 | 192 | |
194 | 193 | if (!$this->data['ts_title']) |
195 | 194 | { |
196 | - $etpl->set_validation_error('ts_title',lang('Field must not be empty !!!')); |
|
195 | + $etpl->set_validation_error('ts_title', lang('Field must not be empty !!!')); |
|
197 | 196 | } |
198 | - elseif($button != 'save_new') |
|
197 | + elseif ($button != 'save_new') |
|
199 | 198 | { |
200 | 199 | // remove title-blur for same behavior after apply, as for opening the saved entry again |
201 | 200 | unset($this->data['ts_title_blur']); |
@@ -204,26 +203,26 @@ discard block |
||
204 | 203 | unset($content['ts_project_blur']); |
205 | 204 | } |
206 | 205 | } |
207 | - if ($etpl->validation_errors()) break; // the user need to fix the error, before we can save the entry |
|
206 | + if ($etpl->validation_errors()) break; // the user need to fix the error, before we can save the entry |
|
208 | 207 | |
209 | 208 | // account for changed project --> remove old one from links and add new one |
210 | - if ((int) $this->data['pm_id'] != (int) $this->data['old_pm_id']) |
|
209 | + if ((int)$this->data['pm_id'] != (int)$this->data['old_pm_id']) |
|
211 | 210 | { |
212 | 211 | // update links accordingly |
213 | 212 | if ($this->data['pm_id']) |
214 | 213 | { |
215 | - egw_link::link(TIMESHEET_APP,$content['link_to']['to_id'],'projectmanager',$this->data['pm_id']); |
|
214 | + egw_link::link(TIMESHEET_APP, $content['link_to']['to_id'], 'projectmanager', $this->data['pm_id']); |
|
216 | 215 | } |
217 | 216 | if ($this->data['old_pm_id']) |
218 | 217 | { |
219 | - egw_link::unlink2(0,TIMESHEET_APP,$content['link_to']['to_id'],0,'projectmanager',$this->data['old_pm_id']); |
|
218 | + egw_link::unlink2(0, TIMESHEET_APP, $content['link_to']['to_id'], 0, 'projectmanager', $this->data['old_pm_id']); |
|
220 | 219 | unset($this->data['old_pm_id']); |
221 | 220 | } |
222 | 221 | } |
223 | 222 | // check if we are linked to a project, but that is NOT set as project |
224 | 223 | if (!$this->data['pm_id'] && is_array($content['link_to']['to_id'])) |
225 | 224 | { |
226 | - foreach($content['link_to']['to_id'] as $data) |
|
225 | + foreach ($content['link_to']['to_id'] as $data) |
|
227 | 226 | { |
228 | 227 | if ($data['app'] == 'projectmanager') |
229 | 228 | { |
@@ -244,26 +243,26 @@ discard block |
||
244 | 243 | $msg = lang('Entry saved'); |
245 | 244 | if (is_array($content['link_to']['to_id']) && count($content['link_to']['to_id'])) |
246 | 245 | { |
247 | - egw_link::link(TIMESHEET_APP,$this->data['ts_id'],$content['link_to']['to_id']); |
|
246 | + egw_link::link(TIMESHEET_APP, $this->data['ts_id'], $content['link_to']['to_id']); |
|
248 | 247 | } |
249 | 248 | } |
250 | 249 | egw_framework::refresh_opener($msg, 'timesheet', $this->data['ts_id'], $content['ts_id'] ? 'edit' : 'add'); |
251 | 250 | if ($button == 'apply') break; |
252 | 251 | if ($button == 'save_new') |
253 | 252 | { |
254 | - $msg .= ', '.lang('creating new entry'); // giving some feedback to the user |
|
253 | + $msg .= ', '.lang('creating new entry'); // giving some feedback to the user |
|
255 | 254 | |
256 | 255 | if (!is_array($content['link_to']['to_id'])) // set links again, so new entry gets the same links as the existing one |
257 | 256 | { |
258 | 257 | $content['link_to']['to_id'] = 0; |
259 | - foreach(egw_link::get_links(TIMESHEET_APP,$this->data['ts_id'],'!'.egw_link::VFS_APPNAME) as $link) |
|
258 | + foreach (egw_link::get_links(TIMESHEET_APP, $this->data['ts_id'], '!'.egw_link::VFS_APPNAME) as $link) |
|
260 | 259 | { |
261 | - egw_link::link(TIMESHEET_APP,$content['link_to']['to_id'],$link['app'],$link['id'],$link['remark']); |
|
260 | + egw_link::link(TIMESHEET_APP, $content['link_to']['to_id'], $link['app'], $link['id'], $link['remark']); |
|
262 | 261 | } |
263 | 262 | } |
264 | 263 | // create a new entry |
265 | 264 | $this->data['ts_start'] += 60 * $this->data['ts_duration']; |
266 | - foreach(array('ts_id','ts_title','ts_description','ts_duration','ts_quantity','ts_modified','ts_modifier') as $name) |
|
265 | + foreach (array('ts_id', 'ts_title', 'ts_description', 'ts_duration', 'ts_quantity', 'ts_modified', 'ts_modifier') as $name) |
|
267 | 266 | { |
268 | 267 | unset($this->data[$name]); |
269 | 268 | } |
@@ -283,7 +282,7 @@ discard block |
||
283 | 282 | else |
284 | 283 | { |
285 | 284 | $msg = lang('Error deleting the entry!!!'); |
286 | - break; // dont close window |
|
285 | + break; // dont close window |
|
287 | 286 | } |
288 | 287 | } |
289 | 288 | // fall-through for save |
@@ -296,7 +295,7 @@ discard block |
||
296 | 295 | 'referer' => $referer, |
297 | 296 | 'ts_title_blur' => $content['ts_title_blur'], |
298 | 297 | ); |
299 | - $content = array_merge($this->data,array( |
|
298 | + $content = array_merge($this->data, array( |
|
300 | 299 | 'msg' => $msg, |
301 | 300 | 'view' => $view, |
302 | 301 | 'tabs' => $content['tabs'], |
@@ -304,8 +303,8 @@ discard block |
||
304 | 303 | 'to_id' => $this->data['ts_id'] ? $this->data['ts_id'] : $content['link_to']['to_id'], |
305 | 304 | 'to_app' => TIMESHEET_APP, |
306 | 305 | ), |
307 | - 'ts_quantity_blur' => $this->data['ts_duration'] ? round($this->data['ts_duration'] / 60.0,3) : '', |
|
308 | - 'ts_quantity' => $this->data['ts_duration']/60.0 == $this->data['ts_quantity'] ? null : $this->data['ts_quantity'], |
|
306 | + 'ts_quantity_blur' => $this->data['ts_duration'] ? round($this->data['ts_duration'] / 60.0, 3) : '', |
|
307 | + 'ts_quantity' => $this->data['ts_duration'] / 60.0 == $this->data['ts_quantity'] ? null : $this->data['ts_quantity'], |
|
309 | 308 | 'start_time' => isset($this->data['start_time']) ? $this->data['start_time'] : $this->data['ts_start'], |
310 | 309 | 'pm_integration' => $this->pm_integration, |
311 | 310 | 'no_ts_status' => !$this->status_labels && ($this->data['ts_status'] != self::DELETED_STATUS), |
@@ -315,10 +314,10 @@ discard block |
||
315 | 314 | if (!$this->data['ts_id'] && isset($_REQUEST['link_app']) && isset($_REQUEST['link_id']) && !is_array($content['link_to']['to_id'])) |
316 | 315 | { |
317 | 316 | $link_ids = is_array($_REQUEST['link_id']) ? $_REQUEST['link_id'] : array($_REQUEST['link_id']); |
318 | - foreach(is_array($_REQUEST['link_app']) ? $_REQUEST['link_app'] : array($_REQUEST['link_app']) as $n => $link_app) |
|
317 | + foreach (is_array($_REQUEST['link_app']) ? $_REQUEST['link_app'] : array($_REQUEST['link_app']) as $n => $link_app) |
|
319 | 318 | { |
320 | 319 | $link_id = $link_ids[$n]; |
321 | - if (preg_match('/^[a-z_0-9-]+:[:a-z_0-9-]+$/i',$link_app.':'.$link_id)) // gard against XSS |
|
320 | + if (preg_match('/^[a-z_0-9-]+:[:a-z_0-9-]+$/i', $link_app.':'.$link_id)) // gard against XSS |
|
322 | 321 | { |
323 | 322 | switch ($link_app) |
324 | 323 | { |
@@ -326,33 +325,33 @@ discard block |
||
326 | 325 | $links[] = $link_id; |
327 | 326 | // fall-through; |
328 | 327 | default: |
329 | - if(!$n) |
|
328 | + if (!$n) |
|
330 | 329 | { |
331 | 330 | // get title from first linked app |
332 | - $preserv['ts_title_blur'] = egw_link::title($link_app,$link_id); |
|
331 | + $preserv['ts_title_blur'] = egw_link::title($link_app, $link_id); |
|
333 | 332 | // ask first linked app via "timesheet_set" hook, for further data to set, incl. links |
334 | - if (($set = $GLOBALS['egw']->hooks->single(array('location'=>'timesheet_set','id'=>$link_id),$link_app))) |
|
333 | + if (($set = $GLOBALS['egw']->hooks->single(array('location'=>'timesheet_set', 'id'=>$link_id), $link_app))) |
|
335 | 334 | { |
336 | - foreach((array)$set['link_app'] as $i => $l_app) |
|
335 | + foreach ((array)$set['link_app'] as $i => $l_app) |
|
337 | 336 | { |
338 | - if (($l_id=$set['link_id'][$i])) egw_link::link(TIMESHEET_APP,$content['link_to']['to_id'],$l_app,$l_id); |
|
337 | + if (($l_id = $set['link_id'][$i])) egw_link::link(TIMESHEET_APP, $content['link_to']['to_id'], $l_app, $l_id); |
|
339 | 338 | if ($l_app == 'projectmanager') $links[] = $l_id; |
340 | 339 | } |
341 | 340 | unset($set['link_app']); |
342 | 341 | unset($set['link_id']); |
343 | 342 | |
344 | - $content = array_merge($content,$set); |
|
343 | + $content = array_merge($content, $set); |
|
345 | 344 | } |
346 | 345 | } |
347 | 346 | break; |
348 | 347 | } |
349 | - egw_link::link(TIMESHEET_APP,$content['link_to']['to_id'],$link_app,$link_id); |
|
348 | + egw_link::link(TIMESHEET_APP, $content['link_to']['to_id'], $link_app, $link_id); |
|
350 | 349 | } |
351 | 350 | } |
352 | 351 | } |
353 | 352 | elseif ($this->data['ts_id']) |
354 | 353 | { |
355 | - $links = egw_link::get_links(TIMESHEET_APP,$this->data['ts_id'],'projectmanager'); |
|
354 | + $links = egw_link::get_links(TIMESHEET_APP, $this->data['ts_id'], 'projectmanager'); |
|
356 | 355 | } |
357 | 356 | // make all linked projects availible for the pm-pricelist widget, to be able to choose prices from all |
358 | 357 | $content['all_pm_ids'] = array_values($links); |
@@ -395,7 +394,7 @@ discard block |
||
395 | 394 | |
396 | 395 | if ($view) |
397 | 396 | { |
398 | - foreach(array_merge(array_keys($this->data),array('pm_id','pl_id','link_to')) as $key) |
|
397 | + foreach (array_merge(array_keys($this->data), array('pm_id', 'pl_id', 'link_to')) as $key) |
|
399 | 398 | { |
400 | 399 | $readonlys[$key] = true; |
401 | 400 | } |
@@ -411,9 +410,9 @@ discard block |
||
411 | 410 | { |
412 | 411 | $edit_grants[$content['ts_owner']] = common::grab_owner_name($content['ts_owner']); |
413 | 412 | } |
414 | - $sel_options['ts_owner'] = $edit_grants; |
|
415 | - $sel_options['ts_status'] = $this->status_labels; |
|
416 | - if($this->config_data['history'] && $content['ts_status'] == self::DELETED_STATUS) |
|
413 | + $sel_options['ts_owner'] = $edit_grants; |
|
414 | + $sel_options['ts_status'] = $this->status_labels; |
|
415 | + if ($this->config_data['history'] && $content['ts_status'] == self::DELETED_STATUS) |
|
417 | 416 | { |
418 | 417 | $sel_options['ts_status'][self::DELETED_STATUS] = 'Deleted'; |
419 | 418 | } |
@@ -423,19 +422,19 @@ discard block |
||
423 | 422 | // supress unknow widget 'projectmanager-*', if projectmanager is not installed or old |
424 | 423 | if (!@file_exists(EGW_INCLUDE_ROOT.'/projectmanager/inc/class.projectmanager_widget.inc.php')) |
425 | 424 | { |
426 | - $etpl->set_cell_attribute('pm_id','disabled',true); |
|
427 | - $etpl->set_cell_attribute('pl_id','disabled',true); |
|
425 | + $etpl->set_cell_attribute('pm_id', 'disabled', true); |
|
426 | + $etpl->set_cell_attribute('pl_id', 'disabled', true); |
|
428 | 427 | } |
429 | 428 | |
430 | - if($this->ts_viewtype == 'short') |
|
429 | + if ($this->ts_viewtype == 'short') |
|
431 | 430 | { |
432 | 431 | $content['ts_viewtype'] = $readonlys['tabs']['notes'] = true; |
433 | 432 | $content['ts_description_short'] = $content['ts_description']; |
434 | 433 | } |
435 | - if (!$this->customfields) $readonlys['tabs']['customfields'] = true; // suppress tab if there are not customfields |
|
436 | - if (!$this->data['ts_id']) $readonlys['tabs']['history'] = true; //suppress history for the first loading without ID |
|
434 | + if (!$this->customfields) $readonlys['tabs']['customfields'] = true; // suppress tab if there are not customfields |
|
435 | + if (!$this->data['ts_id']) $readonlys['tabs']['history'] = true; //suppress history for the first loading without ID |
|
437 | 436 | |
438 | - return $etpl->exec(TIMESHEET_APP.'.timesheet_ui.edit',$content,$sel_options,$readonlys,$preserv,2); |
|
437 | + return $etpl->exec(TIMESHEET_APP.'.timesheet_ui.edit', $content, $sel_options, $readonlys, $preserv, 2); |
|
439 | 438 | } |
440 | 439 | |
441 | 440 | /** |
@@ -448,7 +447,7 @@ discard block |
||
448 | 447 | { |
449 | 448 | if (!$datetime) return 0; |
450 | 449 | |
451 | - return $datetime - mktime(0,0,0,date('m',$datetime),date('d',$datetime),date('Y',$datetime)); |
|
450 | + return $datetime - mktime(0, 0, 0, date('m', $datetime), date('d', $datetime), date('Y', $datetime)); |
|
452 | 451 | } |
453 | 452 | |
454 | 453 | /** |
@@ -462,17 +461,17 @@ discard block |
||
462 | 461 | * @param boolean $id_only if true only return (via $rows) an array of contact-ids, dont save state to session |
463 | 462 | * @return int total number of contacts matching the selection |
464 | 463 | */ |
465 | - function get_rows(&$query_in,&$rows,&$readonlys,$id_only=false) |
|
464 | + function get_rows(&$query_in, &$rows, &$readonlys, $id_only = false) |
|
466 | 465 | { |
467 | 466 | $this->show_sums = false; |
468 | 467 | if ($query_in['filter']) |
469 | 468 | { |
470 | - $date_filter = $this->date_filter($query_in['filter'],$query_in['startdate'],$query_in['enddate']); |
|
469 | + $date_filter = $this->date_filter($query_in['filter'], $query_in['startdate'], $query_in['enddate']); |
|
471 | 470 | |
472 | 471 | if ($query_in['startdate']) |
473 | 472 | { |
474 | - $start = explode('-',date('Y-m-d',$query_in['startdate']+12*60*60)); |
|
475 | - $end = explode('-',date('Y-m-d',$query_in['enddate'] ? $query_in['enddate'] : $query_in['startdate']+7.5*24*60*60)); |
|
473 | + $start = explode('-', date('Y-m-d', $query_in['startdate'] + 12 * 60 * 60)); |
|
474 | + $end = explode('-', date('Y-m-d', $query_in['enddate'] ? $query_in['enddate'] : $query_in['startdate'] + 7.5 * 24 * 60 * 60)); |
|
476 | 475 | |
477 | 476 | // show year-sums, if we are year-aligned (show full years)? |
478 | 477 | if ((int)$start[2] == 1 && (int)$start[1] == 1 && (int)$end[2] == 31 && (int)$end[1] == 12) |
@@ -480,42 +479,42 @@ discard block |
||
480 | 479 | $this->show_sums[] = 'year'; |
481 | 480 | } |
482 | 481 | // show month-sums, if we are month-aligned (show full monthes)? |
483 | - if ((int)$start[2] == 1 && (int)$end[2] == (int)date('d',mktime(12,0,0,$end[1]+1,0,$end[0]))) |
|
482 | + if ((int)$start[2] == 1 && (int)$end[2] == (int)date('d', mktime(12, 0, 0, $end[1] + 1, 0, $end[0]))) |
|
484 | 483 | { |
485 | 484 | $this->show_sums[] = 'month'; |
486 | 485 | } |
487 | 486 | // show week-sums, if we are week-aligned (show full weeks)? |
488 | 487 | $week_start_day = $GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts']; |
489 | 488 | if (!$week_start_day) $week_start_day = 'Sunday'; |
490 | - switch($week_start_day) |
|
489 | + switch ($week_start_day) |
|
491 | 490 | { |
492 | 491 | case 'Sunday': $week_end_day = 'Saturday'; break; |
493 | 492 | case 'Monday': $week_end_day = 'Sunday'; break; |
494 | 493 | case 'Saturday': $week_end_day = 'Friday'; break; |
495 | 494 | } |
496 | - $filter_start_day = date('l',$query_in['startdate']+12*60*60); |
|
497 | - $filter_end_day = $query_in['enddate'] ? date('l',$query_in['enddate']+12*60*60) : false; |
|
495 | + $filter_start_day = date('l', $query_in['startdate'] + 12 * 60 * 60); |
|
496 | + $filter_end_day = $query_in['enddate'] ? date('l', $query_in['enddate'] + 12 * 60 * 60) : false; |
|
498 | 497 | //echo "<p align=right>prefs: $week_start_day - $week_end_day, filter: $filter_start_day - $filter_end_day</p>\n"; |
499 | 498 | if ($filter_start_day == $week_start_day && (!$filter_end_day || $filter_end_day == $week_end_day)) |
500 | 499 | { |
501 | 500 | $this->show_sums[] = 'week'; |
502 | 501 | } |
503 | 502 | // show day-sums, if range <= 5 weeks |
504 | - if (!$query_in['enddate'] || $query_in['enddate'] - $query_in['startdate'] < 36*24*60*60) |
|
503 | + if (!$query_in['enddate'] || $query_in['enddate'] - $query_in['startdate'] < 36 * 24 * 60 * 60) |
|
505 | 504 | { |
506 | 505 | $this->show_sums[] = 'day'; |
507 | 506 | } |
508 | 507 | } |
509 | 508 | } |
510 | 509 | //echo "<p align=right>show_sums=".print_r($this->show_sums,true)."</p>\n"; |
511 | - if (!$id_only && !$query_in['csv_export']) $GLOBALS['egw']->session->appsession('index',TIMESHEET_APP,$query_in); |
|
510 | + if (!$id_only && !$query_in['csv_export']) $GLOBALS['egw']->session->appsession('index', TIMESHEET_APP, $query_in); |
|
512 | 511 | |
513 | 512 | // Refresh actions (undelete needs this) |
514 | 513 | $query_in['actions'] = $this->get_actions($query_in); |
515 | 514 | |
516 | - $query = $query_in; // keep the original query |
|
515 | + $query = $query_in; // keep the original query |
|
517 | 516 | |
518 | - if($this->ts_viewtype == 'short') $query_in['options-selectcols'] = array('ts_quantity'=>false,'ts_unitprice'=>false,'ts_total'=>false); |
|
517 | + if ($this->ts_viewtype == 'short') $query_in['options-selectcols'] = array('ts_quantity'=>false, 'ts_unitprice'=>false, 'ts_total'=>false); |
|
519 | 518 | if ($query['no_status']) $query_in['options-selectcols']['ts_status'] = false; |
520 | 519 | |
521 | 520 | //_debug_array($query['col_filter']); |
@@ -542,10 +541,10 @@ discard block |
||
542 | 541 | // handle linked filter (show only entries linked to a certain other entry) |
543 | 542 | if ($query['col_filter']['linked']) |
544 | 543 | { |
545 | - list($app,$id) = explode(':',$query['col_filter']['linked']); |
|
546 | - if (!($links = egw_link::get_links($app,$id,'timesheet'))) |
|
544 | + list($app, $id) = explode(':', $query['col_filter']['linked']); |
|
545 | + if (!($links = egw_link::get_links($app, $id, 'timesheet'))) |
|
547 | 546 | { |
548 | - $rows = array(); // no infologs linked to project --> no rows to return |
|
547 | + $rows = array(); // no infologs linked to project --> no rows to return |
|
549 | 548 | return 0; |
550 | 549 | } |
551 | 550 | if (!$query['col_filter']['ts_id']) |
@@ -553,9 +552,9 @@ discard block |
||
553 | 552 | $query['col_filter']['ts_id'] = array_values(array_unique($links)); |
554 | 553 | } |
555 | 554 | // allow to combine with other filters using ts_id --> intersect ids |
556 | - elseif (!($query['col_filter']['ts_id'] = array_intersect((array)$query['col_filter']['ts_id'],array_values(array_unique($links))))) |
|
555 | + elseif (!($query['col_filter']['ts_id'] = array_intersect((array)$query['col_filter']['ts_id'], array_values(array_unique($links))))) |
|
557 | 556 | { |
558 | - $rows = array(); // no infologs linked to project --> no rows to return |
|
557 | + $rows = array(); // no infologs linked to project --> no rows to return |
|
559 | 558 | return 0; |
560 | 559 | } |
561 | 560 | } |
@@ -579,13 +578,13 @@ discard block |
||
579 | 578 | { |
580 | 579 | if (isset($this->status_labels_substatus['2level'][$status_id])) |
581 | 580 | { |
582 | - $query['col_filter']['ts_status'] = array_merge($query['col_filter']['ts_status'],$this->status_labels_substatus[$status_id]); |
|
581 | + $query['col_filter']['ts_status'] = array_merge($query['col_filter']['ts_status'], $this->status_labels_substatus[$status_id]); |
|
583 | 582 | } |
584 | 583 | } |
585 | 584 | } |
586 | 585 | if ((int)$query['filter2'] != (int)$GLOBALS['egw_info']['user']['preferences'][TIMESHEET_APP]['show_details']) |
587 | 586 | { |
588 | - $GLOBALS['egw']->preferences->add(TIMESHEET_APP,'show_details',(int)$query['filter2']); |
|
587 | + $GLOBALS['egw']->preferences->add(TIMESHEET_APP, 'show_details', (int)$query['filter2']); |
|
589 | 588 | $GLOBALS['egw']->preferences->save_repository(true); |
590 | 589 | } |
591 | 590 | // category filter: cat_id or ''=All cats or 0=No cat |
@@ -608,7 +607,7 @@ discard block |
||
608 | 607 | $GLOBALS['egw_info']['flags']['app_header'] .= ': '.common::grab_owner_name($query['col_filter']['ts_owner']); |
609 | 608 | #if ($GLOBALS['egw']->accounts->get_type($query['col_filter']['ts_owner']) == 'g') $GLOBALS['egw_info']['flags']['app_header'] .= ' '. lang("and its members"); |
610 | 609 | #_debug_array($GLOBALS['egw']->accounts->members($query['col_filter']['ts_owner'],true)); |
611 | - if ($query['col_filter']['ts_owner']<0) $query['col_filter']['ts_owner'] = array_merge(array($query['col_filter']['ts_owner']),$GLOBALS['egw']->accounts->members($query['col_filter']['ts_owner'],true)); |
|
610 | + if ($query['col_filter']['ts_owner'] < 0) $query['col_filter']['ts_owner'] = array_merge(array($query['col_filter']['ts_owner']), $GLOBALS['egw']->accounts->members($query['col_filter']['ts_owner'], true)); |
|
612 | 611 | } |
613 | 612 | else |
614 | 613 | { |
@@ -621,51 +620,51 @@ discard block |
||
621 | 620 | // generate a meaningful app-header / report title |
622 | 621 | if ($this->show_sums['month']) |
623 | 622 | { |
624 | - if ((int)$start[1] == 1 && (int) $end[1] == 12) // whole year(s) |
|
623 | + if ((int)$start[1] == 1 && (int)$end[1] == 12) // whole year(s) |
|
625 | 624 | { |
626 | - $GLOBALS['egw_info']['flags']['app_header'] .= ': ' . $start[0] . ($start[0] != $end[0] ? ' - '.$end[0] : ''); |
|
625 | + $GLOBALS['egw_info']['flags']['app_header'] .= ': '.$start[0].($start[0] != $end[0] ? ' - '.$end[0] : ''); |
|
627 | 626 | } |
628 | 627 | else |
629 | 628 | { |
630 | - $GLOBALS['egw_info']['flags']['app_header'] .= ': ' . lang(date('F',$query['startdate']+12*60*60)) . ' ' . $start[0]; |
|
629 | + $GLOBALS['egw_info']['flags']['app_header'] .= ': '.lang(date('F', $query['startdate'] + 12 * 60 * 60)).' '.$start[0]; |
|
631 | 630 | if ($start[0] != $end[0] || $start[1] != $end[1]) |
632 | 631 | { |
633 | - $GLOBALS['egw_info']['flags']['app_header'] .= ' - ' . lang(date('F',$query['enddate']+12*60*60)) . ' ' . $end[0]; |
|
632 | + $GLOBALS['egw_info']['flags']['app_header'] .= ' - '.lang(date('F', $query['enddate'] + 12 * 60 * 60)).' '.$end[0]; |
|
634 | 633 | } |
635 | 634 | } |
636 | 635 | } |
637 | 636 | elseif ($this->show_sums['week']) |
638 | 637 | { |
639 | - $GLOBALS['egw_info']['flags']['app_header'] .= ': ' . lang('week') . ' ' . date('W',$query['startdate']+36*60*60) . '/' . $start[0]; |
|
640 | - if ($query['enddate'] && $query['enddate'] - $query['startdate'] > 10*24*60*60) |
|
638 | + $GLOBALS['egw_info']['flags']['app_header'] .= ': '.lang('week').' '.date('W', $query['startdate'] + 36 * 60 * 60).'/'.$start[0]; |
|
639 | + if ($query['enddate'] && $query['enddate'] - $query['startdate'] > 10 * 24 * 60 * 60) |
|
641 | 640 | { |
642 | - $GLOBALS['egw_info']['flags']['app_header'] .= ' - ' . date('W',$query['enddate']-36*60*60) . '/' . $end[0]; |
|
641 | + $GLOBALS['egw_info']['flags']['app_header'] .= ' - '.date('W', $query['enddate'] - 36 * 60 * 60).'/'.$end[0]; |
|
643 | 642 | } |
644 | 643 | } |
645 | 644 | elseif ($query['startdate']) |
646 | 645 | { |
647 | 646 | $df = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat']; |
648 | - $GLOBALS['egw_info']['flags']['app_header'] .= ': ' . common::show_date($query['startdate']+12*60*60,$df,false); |
|
647 | + $GLOBALS['egw_info']['flags']['app_header'] .= ': '.common::show_date($query['startdate'] + 12 * 60 * 60, $df, false); |
|
649 | 648 | if ($start != $end) |
650 | 649 | { |
651 | - $GLOBALS['egw_info']['flags']['app_header'] .= ' - '.common::show_date($query['enddate']+12*60*60,$df,false); |
|
650 | + $GLOBALS['egw_info']['flags']['app_header'] .= ' - '.common::show_date($query['enddate'] + 12 * 60 * 60, $df, false); |
|
652 | 651 | } |
653 | 652 | } |
654 | 653 | } |
655 | - $total = parent::get_rows($query,$rows,$readonlys); |
|
654 | + $total = parent::get_rows($query, $rows, $readonlys); |
|
656 | 655 | |
657 | 656 | $ids = array(); |
658 | - foreach($rows as &$row) |
|
657 | + foreach ($rows as &$row) |
|
659 | 658 | { |
660 | 659 | if ($row['ts_id'] > 0) $ids[] = $row['ts_id']; |
661 | 660 | } |
662 | 661 | if ($id_only) |
663 | 662 | { |
664 | 663 | $rows = $ids; |
665 | - return $this->total; // no need to set other fields or $readonlys |
|
664 | + return $this->total; // no need to set other fields or $readonlys |
|
666 | 665 | } |
667 | 666 | $links = array(); |
668 | - $links3 = egw_link::get_links_multiple(TIMESHEET_APP,$ids,true,'projectmanager'); // only check for pm links! |
|
667 | + $links3 = egw_link::get_links_multiple(TIMESHEET_APP, $ids, true, 'projectmanager'); // only check for pm links! |
|
669 | 668 | //as the full array is expected, we must supply the missing but needed (since expected further down) information |
670 | 669 | if (is_array($links3)) |
671 | 670 | { |
@@ -685,14 +684,14 @@ discard block |
||
685 | 684 | |
686 | 685 | $readonlys = array(); |
687 | 686 | $have_cats = false; |
688 | - foreach($rows as &$row) |
|
687 | + foreach ($rows as &$row) |
|
689 | 688 | { |
690 | 689 | if ($row['cat_id']) $have_cats = true; |
691 | 690 | |
692 | 691 | $row['class'] = 'row'; |
693 | 692 | if ($row['ts_id'] <= 0) // sums |
694 | 693 | { |
695 | - if ($query['sort'] == 'ASC') $row['ts_start'] -= 7200; // fix for DSL change |
|
694 | + if ($query['sort'] == 'ASC') $row['ts_start'] -= 7200; // fix for DSL change |
|
696 | 695 | |
697 | 696 | // Remove fake modified date, it breaks nextmatch checks |
698 | 697 | unset($row['ts_modified']); |
@@ -700,23 +699,23 @@ discard block |
||
700 | 699 | // Set flag to avoid actions on these rows |
701 | 700 | $row['no_actions'] = true; |
702 | 701 | |
703 | - switch($row['ts_id']) |
|
702 | + switch ($row['ts_id']) |
|
704 | 703 | { |
705 | 704 | case 0: // day-sum |
706 | - $row['ts_title'] = lang('Sum %1:',lang(date('l',$row['ts_start'])).' '.common::show_date($row['ts_start'], |
|
707 | - $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'],false)); |
|
705 | + $row['ts_title'] = lang('Sum %1:', lang(date('l', $row['ts_start'])).' '.common::show_date($row['ts_start'], |
|
706 | + $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], false)); |
|
708 | 707 | $row['ts_id'] = 'sum-day-'.$row['ts_start']; |
709 | 708 | break; |
710 | 709 | case -1: // week-sum |
711 | - $row['ts_title'] = lang('Sum %1:',lang('week').' '.substr($row['ts_week'],4).'/'.substr($row['ts_week'],0,4)); |
|
710 | + $row['ts_title'] = lang('Sum %1:', lang('week').' '.substr($row['ts_week'], 4).'/'.substr($row['ts_week'], 0, 4)); |
|
712 | 711 | $row['ts_id'] = 'sum-week-'.$row['ts_week']; |
713 | 712 | break; |
714 | 713 | case -2: // month-sum |
715 | - $row['ts_title'] = lang('Sum %1:',lang(date('F',$row['ts_start'])).' '.substr($row['ts_month'],0,4)); |
|
714 | + $row['ts_title'] = lang('Sum %1:', lang(date('F', $row['ts_start'])).' '.substr($row['ts_month'], 0, 4)); |
|
716 | 715 | $row['ts_id'] = 'sum-month-'.$row['ts_month']; |
717 | 716 | break; |
718 | 717 | case -3: // year-sum |
719 | - $row['ts_title'] = lang('Sum %1:',$row['ts_year']); |
|
718 | + $row['ts_title'] = lang('Sum %1:', $row['ts_year']); |
|
720 | 719 | $row['ts_id'] = 'sum-year-'.$row['ts_year']; |
721 | 720 | break; |
722 | 721 | } |
@@ -726,11 +725,11 @@ discard block |
||
726 | 725 | $row['titleClass'] = 'timesheet_titleSum'; |
727 | 726 | continue; |
728 | 727 | } |
729 | - if($row['ts_quantity']) |
|
728 | + if ($row['ts_quantity']) |
|
730 | 729 | { |
731 | 730 | $row['ts_quantity'] = round($row['ts_quantity'], 2); |
732 | 731 | } |
733 | - if (!$this->check_acl(EGW_ACL_EDIT,$row)) |
|
732 | + if (!$this->check_acl(EGW_ACL_EDIT, $row)) |
|
734 | 733 | { |
735 | 734 | $row['class'] .= ' rowNoEdit '; |
736 | 735 | } |
@@ -738,21 +737,21 @@ discard block |
||
738 | 737 | { |
739 | 738 | $row['class'] .= ' rowNoEdit '; |
740 | 739 | } |
741 | - if (!$this->check_acl(EGW_ACL_DELETE,$row)) |
|
740 | + if (!$this->check_acl(EGW_ACL_DELETE, $row)) |
|
742 | 741 | { |
743 | 742 | $row['class'] .= ' rowNoDelete '; |
744 | 743 | } |
745 | - if($row['ts_status'] != self::DELETED_STATUS) |
|
744 | + if ($row['ts_status'] != self::DELETED_STATUS) |
|
746 | 745 | { |
747 | 746 | $row['class'] .= ' rowNoUndelete '; |
748 | 747 | } |
749 | 748 | if ($query['col_filter']['ts_project']) |
750 | 749 | { |
751 | - unset($row['ts_project']); // dont need or want to show it |
|
750 | + unset($row['ts_project']); // dont need or want to show it |
|
752 | 751 | } |
753 | 752 | elseif ($links[$row['ts_id']]) |
754 | 753 | { |
755 | - foreach($links[$row['ts_id']] as $link) |
|
754 | + foreach ($links[$row['ts_id']] as $link) |
|
756 | 755 | { |
757 | 756 | if ($link['app'] == 'projectmanager') |
758 | 757 | { |
@@ -763,26 +762,26 @@ discard block |
||
763 | 762 | } |
764 | 763 | } |
765 | 764 | |
766 | - if(!$row['titleClass']) $row['titleClass'] = 'timesheet_titleDetails'; |
|
765 | + if (!$row['titleClass']) $row['titleClass'] = 'timesheet_titleDetails'; |
|
767 | 766 | |
768 | 767 | } |
769 | 768 | if (!$have_cats || $query['cat_id']) $rows['no_cat_id'] = true; |
770 | 769 | if ($query['col_filter']['ts_owner']) $rows['ownerClass'] = 'noPrint'; |
771 | 770 | $rows['no_owner_col'] = $query['no_owner_col']; |
772 | - if (!$rows['no_owner_col'] && $query['selectcols'] && !strpos($query['selectcols'],'ts_owner')) $rows['no_owner_col'] = 1; |
|
771 | + if (!$rows['no_owner_col'] && $query['selectcols'] && !strpos($query['selectcols'], 'ts_owner')) $rows['no_owner_col'] = 1; |
|
773 | 772 | if ($query['filter']) |
774 | 773 | { |
775 | 774 | $rows += $this->summary; |
776 | 775 | } |
777 | 776 | $rows['pm_integration'] = $this->pm_integration; |
778 | - $rows['ts_viewtype'] = $rows['no_ts_quantity'] = $rows['no_ts_unitprice'] = $rows['no_ts_total'] = $this->ts_viewtype == 'short'; |
|
777 | + $rows['ts_viewtype'] = $rows['no_ts_quantity'] = $rows['no_ts_unitprice'] = $rows['no_ts_total'] = $this->ts_viewtype == 'short'; |
|
779 | 778 | if (!$rows['ts_viewtype']) |
780 | 779 | { |
781 | 780 | #_debug_array($query['selectcols']); |
782 | 781 | #ts_quantity,ts_unitprice,ts_total |
783 | - if ($query['selectcols'] && strpos($query['selectcols'],'ts_quantity')===false) $rows['no_ts_quantity'] = 1; |
|
784 | - if ($query['selectcols'] && strpos($query['selectcols'],'ts_unitprice')===false) $rows['no_ts_unitprice'] = 1; |
|
785 | - if ($query['selectcols'] && strpos($query['selectcols'],'ts_total')===false) $rows['no_ts_total'] = 1; |
|
782 | + if ($query['selectcols'] && strpos($query['selectcols'], 'ts_quantity') === false) $rows['no_ts_quantity'] = 1; |
|
783 | + if ($query['selectcols'] && strpos($query['selectcols'], 'ts_unitprice') === false) $rows['no_ts_unitprice'] = 1; |
|
784 | + if ($query['selectcols'] && strpos($query['selectcols'], 'ts_total') === false) $rows['no_ts_total'] = 1; |
|
786 | 785 | } |
787 | 786 | $rows['no_ts_status'] = strpos($query['selectcols'], 'ts_status') === false && !$this->config_data['history'] || |
788 | 787 | $query['no_status']; |
@@ -796,7 +795,7 @@ discard block |
||
796 | 795 | * @param array $content |
797 | 796 | * @param string $msg |
798 | 797 | */ |
799 | - function index($content = null,$msg='') |
|
798 | + function index($content = null, $msg = '') |
|
800 | 799 | { |
801 | 800 | $etpl = new etemplate_new('timesheet.index'); |
802 | 801 | |
@@ -833,26 +832,26 @@ discard block |
||
833 | 832 | else |
834 | 833 | { |
835 | 834 | $success = $failed = $action_msg = null; |
836 | - if ($this->action($content['nm']['action'],$content['nm']['selected'],$content['nm']['select_all'], |
|
837 | - $success,$failed,$action_msg,'index',$msg)) |
|
835 | + if ($this->action($content['nm']['action'], $content['nm']['selected'], $content['nm']['select_all'], |
|
836 | + $success, $failed, $action_msg, 'index', $msg)) |
|
838 | 837 | { |
839 | - $msg .= lang('%1 timesheets(s) %2',$success,$action_msg); |
|
838 | + $msg .= lang('%1 timesheets(s) %2', $success, $action_msg); |
|
840 | 839 | } |
841 | - elseif(empty($msg)) |
|
840 | + elseif (empty($msg)) |
|
842 | 841 | { |
843 | - $msg .= lang('%1 timesheets(s) %2, %3 failed because of insufficent rights !!!',$success,$action_msg,$failed); |
|
842 | + $msg .= lang('%1 timesheets(s) %2, %3 failed because of insufficent rights !!!', $success, $action_msg, $failed); |
|
844 | 843 | } |
845 | 844 | } |
846 | 845 | } |
847 | 846 | |
848 | 847 | $content = array( |
849 | - 'nm' => $GLOBALS['egw']->session->appsession('index',TIMESHEET_APP), |
|
848 | + 'nm' => $GLOBALS['egw']->session->appsession('index', TIMESHEET_APP), |
|
850 | 849 | 'msg' => $msg, |
851 | 850 | ); |
852 | 851 | if (!is_array($content['nm'])) |
853 | 852 | { |
854 | 853 | $date_filters = array('All'); |
855 | - foreach(array_keys($this->date_filters) as $name) |
|
854 | + foreach (array_keys($this->date_filters) as $name) |
|
856 | 855 | { |
857 | 856 | $date_filters[$name] = $name; |
858 | 857 | } |
@@ -861,9 +860,9 @@ discard block |
||
861 | 860 | $content['nm'] = array( |
862 | 861 | 'get_rows' => TIMESHEET_APP.'.timesheet_ui.get_rows', |
863 | 862 | 'options-filter' => $date_filters, |
864 | - 'options-filter2' => array('No details','Details'), |
|
865 | - 'order' => 'ts_start',// IO name of the column to sort after (optional for the sortheaders) |
|
866 | - 'sort' => 'DESC',// IO direction of the sort: 'ASC' or 'DESC' |
|
863 | + 'options-filter2' => array('No details', 'Details'), |
|
864 | + 'order' => 'ts_start', // IO name of the column to sort after (optional for the sortheaders) |
|
865 | + 'sort' => 'DESC', // IO direction of the sort: 'ASC' or 'DESC' |
|
867 | 866 | 'header_left' => 'timesheet.index.dates', |
868 | 867 | 'header_row' => 'timesheet.index.add', |
869 | 868 | 'filter_onchange' => "app.timesheet.filter_change();", |
@@ -872,13 +871,13 @@ discard block |
||
872 | 871 | 'row_id' => 'ts_id', |
873 | 872 | 'row_modified' => 'ts_modified', |
874 | 873 | //'actions' => $this->get_actions(), |
875 | - 'default_cols' => '!legacy_actions', // switch legacy actions column and row off by default |
|
874 | + 'default_cols' => '!legacy_actions', // switch legacy actions column and row off by default |
|
876 | 875 | 'pm_integration' => $this->pm_integration, |
877 | 876 | ); |
878 | 877 | } |
879 | 878 | $content['nm']['actions'] = $this->get_actions($content['nm']); |
880 | 879 | |
881 | - if($_GET['search']) |
|
880 | + if ($_GET['search']) |
|
882 | 881 | { |
883 | 882 | $content['nm']['search'] = $_GET['search']; |
884 | 883 | } |
@@ -889,25 +888,25 @@ discard block |
||
889 | 888 | 'ts_owner' => $read_grants, |
890 | 889 | 'pm_id' => array(lang('No project')), |
891 | 890 | 'cat_id' => array(array('value' => '', 'label' => lang('all')), array('value' => 0, 'label'=>lang('None'))), |
892 | - 'ts_status' => $this->status_labels+array(lang('No status')), |
|
891 | + 'ts_status' => $this->status_labels + array(lang('No status')), |
|
893 | 892 | ); |
894 | - if($this->config_data['history']) |
|
893 | + if ($this->config_data['history']) |
|
895 | 894 | { |
896 | 895 | $sel_options['ts_status'][self::DELETED_STATUS] = 'Deleted'; |
897 | 896 | } |
898 | - $content['nm']['no_status'] = count($sel_options['ts_status']) <= 1; // 1 because of 'No status' |
|
899 | - $content['nm']['favorites'] = true; //Enable favorite |
|
897 | + $content['nm']['no_status'] = count($sel_options['ts_status']) <= 1; // 1 because of 'No status' |
|
898 | + $content['nm']['favorites'] = true; //Enable favorite |
|
900 | 899 | |
901 | 900 | if ($this->pm_integration != 'full') |
902 | 901 | { |
903 | - $projects =& $this->query_list('ts_project'); |
|
902 | + $projects = & $this->query_list('ts_project'); |
|
904 | 903 | if (!is_array($projects)) $projects = array(); |
905 | 904 | $sel_options['ts_project'] = $projects + array(lang('No project')); |
906 | 905 | } |
907 | 906 | |
908 | 907 | // dont show [Export] button if app is not availible to the user or we are on php4 |
909 | - $readonlys['export'] = !$GLOBALS['egw_info']['user']['apps']['importexport'] || (int) phpversion() < 5; |
|
910 | - return $etpl->exec(TIMESHEET_APP.'.timesheet_ui.index',$content,$sel_options,$readonlys); |
|
908 | + $readonlys['export'] = !$GLOBALS['egw_info']['user']['apps']['importexport'] || (int)phpversion() < 5; |
|
909 | + return $etpl->exec(TIMESHEET_APP.'.timesheet_ui.index', $content, $sel_options, $readonlys); |
|
911 | 910 | } |
912 | 911 | |
913 | 912 | /** |
@@ -926,7 +925,7 @@ discard block |
||
926 | 925 | 'allowOnMultiple' => false, |
927 | 926 | 'url' => 'menuaction=timesheet.timesheet_ui.edit&ts_id=$id', |
928 | 927 | 'popup' => egw_link::get_registry('timesheet', 'add_popup'), |
929 | - 'group' => $group=1, |
|
928 | + 'group' => $group = 1, |
|
930 | 929 | 'disableClass' => 'th', |
931 | 930 | ), |
932 | 931 | /* |
@@ -954,7 +953,7 @@ discard block |
||
954 | 953 | 'group' => $group, |
955 | 954 | ), |
956 | 955 | 'cat' => etemplate_widget_nextmatch::category_action( |
957 | - 'timesheet',++$group,'Change category','cat_' |
|
956 | + 'timesheet', ++$group, 'Change category', 'cat_' |
|
958 | 957 | ), |
959 | 958 | 'status' => array( |
960 | 959 | 'icon' => 'apply', |
@@ -1006,7 +1005,7 @@ discard block |
||
1006 | 1005 | ); |
1007 | 1006 | } |
1008 | 1007 | // enable additonal edit check for following actions, if they are generally available |
1009 | - foreach(array('cat','status') as $action) |
|
1008 | + foreach (array('cat', 'status') as $action) |
|
1010 | 1009 | { |
1011 | 1010 | if ($actions[$action]['enabled']) |
1012 | 1011 | { |
@@ -1029,27 +1028,27 @@ discard block |
||
1029 | 1028 | * @param string/array $session_name 'index' or 'email', or array with session-data depending if we are in the main list or the popup |
1030 | 1029 | * @return boolean true if all actions succeded, false otherwise |
1031 | 1030 | */ |
1032 | - function action($action,$checked,$use_all,&$success,&$failed,&$action_msg,$session_name,&$msg) |
|
1031 | + function action($action, $checked, $use_all, &$success, &$failed, &$action_msg, $session_name, &$msg) |
|
1033 | 1032 | { |
1034 | 1033 | $success = $failed = 0; |
1035 | 1034 | if ($use_all) |
1036 | 1035 | { |
1037 | 1036 | // get the whole selection |
1038 | - $query = is_array($session_name) ? $session_name : $GLOBALS['egw']->session->appsession($session_name,'timesheet'); |
|
1037 | + $query = is_array($session_name) ? $session_name : $GLOBALS['egw']->session->appsession($session_name, 'timesheet'); |
|
1039 | 1038 | |
1040 | 1039 | if ($use_all) |
1041 | 1040 | { |
1042 | - @set_time_limit(0); // switch off the execution time limit, as it's for big selections to small |
|
1043 | - $query['num_rows'] = -1; // all |
|
1041 | + @set_time_limit(0); // switch off the execution time limit, as it's for big selections to small |
|
1042 | + $query['num_rows'] = -1; // all |
|
1044 | 1043 | $readonlys = null; |
1045 | - $this->get_rows($query,$checked,$readonlys,true); // true = only return the id's |
|
1044 | + $this->get_rows($query, $checked, $readonlys, true); // true = only return the id's |
|
1046 | 1045 | } |
1047 | 1046 | } |
1048 | 1047 | //error_log(__METHOD__."('$action', ".array2string($checked).', '.array2string($use_all).",,, '$session_name')"); |
1049 | 1048 | |
1050 | - if (substr($action,0,9) == 'to_status') |
|
1049 | + if (substr($action, 0, 9) == 'to_status') |
|
1051 | 1050 | { |
1052 | - $to_status = (int)substr($action,10); |
|
1051 | + $to_status = (int)substr($action, 10); |
|
1053 | 1052 | $action = 'to_status'; |
1054 | 1053 | } |
1055 | 1054 | else |
@@ -1058,11 +1057,11 @@ discard block |
||
1058 | 1057 | list($action, $settings) = explode('_', $action, 2); |
1059 | 1058 | } |
1060 | 1059 | |
1061 | - switch($action) |
|
1060 | + switch ($action) |
|
1062 | 1061 | { |
1063 | 1062 | case 'delete': |
1064 | 1063 | $action_msg = lang('deleted'); |
1065 | - foreach((array)$checked as $n => $id) |
|
1064 | + foreach ((array)$checked as $n => $id) |
|
1066 | 1065 | { |
1067 | 1066 | if ($this->delete($id)) |
1068 | 1067 | { |
@@ -1075,10 +1074,10 @@ discard block |
||
1075 | 1074 | } |
1076 | 1075 | break; |
1077 | 1076 | case 'undelete': |
1078 | - $action_msg =lang('recovered'); |
|
1079 | - foreach((array)$checked as $n => $id) |
|
1077 | + $action_msg = lang('recovered'); |
|
1078 | + foreach ((array)$checked as $n => $id) |
|
1080 | 1079 | { |
1081 | - if ($this->set_status($id,'')) |
|
1080 | + if ($this->set_status($id, '')) |
|
1082 | 1081 | { |
1083 | 1082 | $success++; |
1084 | 1083 | } |
@@ -1089,10 +1088,10 @@ discard block |
||
1089 | 1088 | } |
1090 | 1089 | break; |
1091 | 1090 | case 'to_status': |
1092 | - $action_msg =lang('changed status'); |
|
1093 | - foreach((array)$checked as $n => $id) |
|
1091 | + $action_msg = lang('changed status'); |
|
1092 | + foreach ((array)$checked as $n => $id) |
|
1094 | 1093 | { |
1095 | - if ($this->set_status($id,$to_status)) |
|
1094 | + if ($this->set_status($id, $to_status)) |
|
1096 | 1095 | { |
1097 | 1096 | $success++; |
1098 | 1097 | } |
@@ -1105,10 +1104,10 @@ discard block |
||
1105 | 1104 | case 'cat': |
1106 | 1105 | $cat_name = categories::id2name($settings); |
1107 | 1106 | $action_msg = lang('changed category to %1', $cat_name); |
1108 | - foreach((array)$checked as $n => $id) { |
|
1107 | + foreach ((array)$checked as $n => $id) { |
|
1109 | 1108 | $entry = $this->read($id); |
1110 | 1109 | $entry['cat_id'] = $settings; |
1111 | - if($this->save($entry) == 0) |
|
1110 | + if ($this->save($entry) == 0) |
|
1112 | 1111 | { |
1113 | 1112 | $success++; |
1114 | 1113 | } |
@@ -1136,7 +1135,7 @@ discard block |
||
1136 | 1135 | * @param conetnt |
1137 | 1136 | * @param view |
1138 | 1137 | */ |
1139 | - function editstatus($content = null,$msg='') |
|
1138 | + function editstatus($content = null, $msg = '') |
|
1140 | 1139 | { |
1141 | 1140 | // this function requires admin rights |
1142 | 1141 | $GLOBALS['egw_info']['flags']['admin_only'] = true; |
@@ -1147,13 +1146,13 @@ discard block |
||
1147 | 1146 | list($button) = @each($content['button']); |
1148 | 1147 | unset ($content['button']); |
1149 | 1148 | |
1150 | - switch($button) |
|
1149 | + switch ($button) |
|
1151 | 1150 | { |
1152 | 1151 | case 'delete': |
1153 | 1152 | break; |
1154 | 1153 | case 'apply': |
1155 | 1154 | case 'save': |
1156 | - foreach($content['statis'] as &$cat) |
|
1155 | + foreach ($content['statis'] as &$cat) |
|
1157 | 1156 | { |
1158 | 1157 | $id = $cat['id']; |
1159 | 1158 | if (($cat ['name'] !== $this->status_labels_config[$id]) && ($cat ['name'] !== '') || ($cat ['parent'] !== $this->status_labels_config[$id]['parent']) && ($cat ['parent'] !== '')) |
@@ -1167,7 +1166,7 @@ discard block |
||
1167 | 1166 | } |
1168 | 1167 | if ($need_update) |
1169 | 1168 | { |
1170 | - config::save_value('status_labels',$this->status_labels_config,TIMESHEET_APP); |
|
1169 | + config::save_value('status_labels', $this->status_labels_config, TIMESHEET_APP); |
|
1171 | 1170 | $this->config_data = config::read(TIMESHEET_APP); |
1172 | 1171 | $this->load_statuses(); |
1173 | 1172 | $msg .= lang('Status updated.'); |
@@ -1184,7 +1183,7 @@ discard block |
||
1184 | 1183 | if (isset($this->status_labels_config[$id])) |
1185 | 1184 | { |
1186 | 1185 | unset($this->status_labels_config[$id]); |
1187 | - config::save_value('status_labels',$this->status_labels_config,TIMESHEET_APP); |
|
1186 | + config::save_value('status_labels', $this->status_labels_config, TIMESHEET_APP); |
|
1188 | 1187 | unset($this->status_labels[$id]); |
1189 | 1188 | $msg .= lang('Status deleted.'); |
1190 | 1189 | } |
@@ -1193,12 +1192,12 @@ discard block |
||
1193 | 1192 | $i = 1; |
1194 | 1193 | $max_id = 0; |
1195 | 1194 | unset($content['statis']); |
1196 | - foreach($this->status_labels_config as $id => $label) |
|
1195 | + foreach ($this->status_labels_config as $id => $label) |
|
1197 | 1196 | { |
1198 | - $content['statis'][$i]['name']= $label['name']; |
|
1199 | - $content['statis'][$i]['id']= $id; |
|
1200 | - $content['statis'][$i]['parent']= $label['parent']; |
|
1201 | - $content['statis'][$i]['admin']= $label['admin']; |
|
1197 | + $content['statis'][$i]['name'] = $label['name']; |
|
1198 | + $content['statis'][$i]['id'] = $id; |
|
1199 | + $content['statis'][$i]['parent'] = $label['parent']; |
|
1200 | + $content['statis'][$i]['admin'] = $label['admin']; |
|
1202 | 1201 | $i++; |
1203 | 1202 | $max_id = max($id, $max_id); |
1204 | 1203 | } |
@@ -1210,6 +1209,6 @@ discard block |
||
1210 | 1209 | $preserv = $content; |
1211 | 1210 | $sel_options['parent'] = $this->status_labels; |
1212 | 1211 | $etpl = new etemplate_new('timesheet.editstatus'); |
1213 | - $etpl->exec('timesheet.timesheet_ui.editstatus',$content,$sel_options,array(),$preserv); |
|
1212 | + $etpl->exec('timesheet.timesheet_ui.editstatus', $content, $sel_options, array(), $preserv); |
|
1214 | 1213 | } |
1215 | 1214 | } |
@@ -57,7 +57,10 @@ discard block |
||
57 | 57 | $etpl = new etemplate_new('timesheet.edit'); |
58 | 58 | if (!is_array($content)) |
59 | 59 | { |
60 | - if ($_GET['msg']) $msg = strip_tags($_GET['msg']); |
|
60 | + if ($_GET['msg']) |
|
61 | + { |
|
62 | + $msg = strip_tags($_GET['msg']); |
|
63 | + } |
|
61 | 64 | |
62 | 65 | if ($view || (int)$_GET['ts_id']) |
63 | 66 | { |
@@ -110,23 +113,32 @@ discard block |
||
110 | 113 | $content['ts_description'] = $content['ts_description_short']; |
111 | 114 | } |
112 | 115 | // we only need 2 out of 3 values from start-, end-time or duration (the date in ts_start is always required!) |
113 | - if (isset($content['start_time'])) // start-time specified |
|
116 | + if (isset($content['start_time'])) |
|
117 | + { |
|
118 | + // start-time specified |
|
114 | 119 | { |
115 | 120 | //$content['ts_start'] += $content['start_time']; |
116 | 121 | $start = new egw_time($content['ts_start']); |
122 | + } |
|
117 | 123 | $start_time = explode(':',$content['start_time']); |
118 | 124 | $start->setTime($start_time[0],$start_time[1]); |
119 | 125 | $content['ts_start'] = $start->format('ts'); |
120 | 126 | } |
121 | - if (isset($content['end_time'])) // end-time specified |
|
127 | + if (isset($content['end_time'])) |
|
128 | + { |
|
129 | + // end-time specified |
|
122 | 130 | { |
123 | 131 | $end = new egw_time($content['ts_start']); |
132 | + } |
|
124 | 133 | $end_time = explode(':',$content['end_time']); |
125 | 134 | $end->setTime($end_time[0],$end_time[1]); |
126 | 135 | } |
127 | - if ($end && $start) // start- & end-time --> calculate the duration |
|
136 | + if ($end && $start) |
|
137 | + { |
|
138 | + // start- & end-time --> calculate the duration |
|
128 | 139 | { |
129 | 140 | $content['ts_duration'] = ($end->format('ts') - $start->format('ts')) / 60; |
141 | + } |
|
130 | 142 | // check if negative duration is caused by wrap over midnight |
131 | 143 | if ($content['ts_duration'] < 0 && $content['ts_duration'] > -24*60) |
132 | 144 | { |
@@ -134,12 +146,18 @@ discard block |
||
134 | 146 | } |
135 | 147 | //echo "<p>end_time=$content[end_time], start_time=$content[start_time] --> duration=$content[ts_duration]</p>\n"; |
136 | 148 | } |
137 | - elseif ($content['ts_duration'] && $end) // no start, calculate from end and duration |
|
149 | + elseif ($content['ts_duration'] && $end) |
|
150 | + { |
|
151 | + // no start, calculate from end and duration |
|
138 | 152 | { |
139 | 153 | $content['ts_start'] = $end->format('ts') - 60*$content['ts_duration']; |
154 | + } |
|
140 | 155 | //echo "<p>end_time=$content[end_time], duration=$content[ts_duration] --> ts_start=$content[ts_start]=".egw_time::to($content['ts_start'])."</p>\n"; |
141 | 156 | } |
142 | - if ($content['ts_duration'] > 0) unset($content['end_time']); |
|
157 | + if ($content['ts_duration'] > 0) |
|
158 | + { |
|
159 | + unset($content['end_time']); |
|
160 | + } |
|
143 | 161 | // now we only deal with start (date+time) and duration |
144 | 162 | list($button) = @each($content['button']); |
145 | 163 | $view = $content['view']; |
@@ -153,7 +171,10 @@ discard block |
||
153 | 171 | switch($button) |
154 | 172 | { |
155 | 173 | case 'edit': |
156 | - if ($this->check_acl(EGW_ACL_EDIT) && !$only_admin_edit) $view = false; |
|
174 | + if ($this->check_acl(EGW_ACL_EDIT) && !$only_admin_edit) |
|
175 | + { |
|
176 | + $view = false; |
|
177 | + } |
|
157 | 178 | break; |
158 | 179 | |
159 | 180 | case 'undelete': |
@@ -167,12 +188,15 @@ discard block |
||
167 | 188 | case 'save': |
168 | 189 | case 'save_new': |
169 | 190 | case 'apply': |
170 | - if ((!$this->data['ts_quantity'] || $this->ts_viewtype == 'short') && $this->data['ts_duration']) // set the quantity (in h) from the duration (in min) |
|
191 | + if ((!$this->data['ts_quantity'] || $this->ts_viewtype == 'short') && $this->data['ts_duration']) |
|
192 | + { |
|
193 | + // set the quantity (in h) from the duration (in min) |
|
171 | 194 | { |
172 | 195 | // We need to keep the actual value of ts_quantity when we are storing it, as it is used in price calculation |
173 | 196 | // and rounding it causes miscalculation on prices |
174 | 197 | $this->data['ts_quantity'] = $this->data['ts_duration'] / 60.0; |
175 | 198 | } |
199 | + } |
|
176 | 200 | if (!$this->data['ts_quantity']) |
177 | 201 | { |
178 | 202 | $etpl->set_validation_error('ts_quantity',lang('Field must not be empty !!!')); |
@@ -204,7 +228,11 @@ discard block |
||
204 | 228 | unset($content['ts_project_blur']); |
205 | 229 | } |
206 | 230 | } |
207 | - if ($etpl->validation_errors()) break; // the user need to fix the error, before we can save the entry |
|
231 | + if ($etpl->validation_errors()) |
|
232 | + { |
|
233 | + break; |
|
234 | + } |
|
235 | + // the user need to fix the error, before we can save the entry |
|
208 | 236 | |
209 | 237 | // account for changed project --> remove old one from links and add new one |
210 | 238 | if ((int) $this->data['pm_id'] != (int) $this->data['old_pm_id']) |
@@ -248,14 +276,20 @@ discard block |
||
248 | 276 | } |
249 | 277 | } |
250 | 278 | egw_framework::refresh_opener($msg, 'timesheet', $this->data['ts_id'], $content['ts_id'] ? 'edit' : 'add'); |
251 | - if ($button == 'apply') break; |
|
279 | + if ($button == 'apply') |
|
280 | + { |
|
281 | + break; |
|
282 | + } |
|
252 | 283 | if ($button == 'save_new') |
253 | 284 | { |
254 | 285 | $msg .= ', '.lang('creating new entry'); // giving some feedback to the user |
255 | 286 | |
256 | - if (!is_array($content['link_to']['to_id'])) // set links again, so new entry gets the same links as the existing one |
|
287 | + if (!is_array($content['link_to']['to_id'])) |
|
288 | + { |
|
289 | + // set links again, so new entry gets the same links as the existing one |
|
257 | 290 | { |
258 | 291 | $content['link_to']['to_id'] = 0; |
292 | + } |
|
259 | 293 | foreach(egw_link::get_links(TIMESHEET_APP,$this->data['ts_id'],'!'.egw_link::VFS_APPNAME) as $link) |
260 | 294 | { |
261 | 295 | egw_link::link(TIMESHEET_APP,$content['link_to']['to_id'],$link['app'],$link['id'],$link['remark']); |
@@ -318,12 +352,15 @@ discard block |
||
318 | 352 | foreach(is_array($_REQUEST['link_app']) ? $_REQUEST['link_app'] : array($_REQUEST['link_app']) as $n => $link_app) |
319 | 353 | { |
320 | 354 | $link_id = $link_ids[$n]; |
321 | - if (preg_match('/^[a-z_0-9-]+:[:a-z_0-9-]+$/i',$link_app.':'.$link_id)) // gard against XSS |
|
355 | + if (preg_match('/^[a-z_0-9-]+:[:a-z_0-9-]+$/i',$link_app.':'.$link_id)) |
|
356 | + { |
|
357 | + // gard against XSS |
|
322 | 358 | { |
323 | 359 | switch ($link_app) |
324 | 360 | { |
325 | 361 | case 'projectmanager': |
326 | 362 | $links[] = $link_id; |
363 | + } |
|
327 | 364 | // fall-through; |
328 | 365 | default: |
329 | 366 | if(!$n) |
@@ -335,8 +372,14 @@ discard block |
||
335 | 372 | { |
336 | 373 | foreach((array)$set['link_app'] as $i => $l_app) |
337 | 374 | { |
338 | - if (($l_id=$set['link_id'][$i])) egw_link::link(TIMESHEET_APP,$content['link_to']['to_id'],$l_app,$l_id); |
|
339 | - if ($l_app == 'projectmanager') $links[] = $l_id; |
|
375 | + if (($l_id=$set['link_id'][$i])) |
|
376 | + { |
|
377 | + egw_link::link(TIMESHEET_APP,$content['link_to']['to_id'],$l_app,$l_id); |
|
378 | + } |
|
379 | + if ($l_app == 'projectmanager') |
|
380 | + { |
|
381 | + $links[] = $l_id; |
|
382 | + } |
|
340 | 383 | } |
341 | 384 | unset($set['link_app']); |
342 | 385 | unset($set['link_id']); |
@@ -432,8 +475,16 @@ discard block |
||
432 | 475 | $content['ts_viewtype'] = $readonlys['tabs']['notes'] = true; |
433 | 476 | $content['ts_description_short'] = $content['ts_description']; |
434 | 477 | } |
435 | - if (!$this->customfields) $readonlys['tabs']['customfields'] = true; // suppress tab if there are not customfields |
|
436 | - if (!$this->data['ts_id']) $readonlys['tabs']['history'] = true; //suppress history for the first loading without ID |
|
478 | + if (!$this->customfields) |
|
479 | + { |
|
480 | + $readonlys['tabs']['customfields'] = true; |
|
481 | + } |
|
482 | + // suppress tab if there are not customfields |
|
483 | + if (!$this->data['ts_id']) |
|
484 | + { |
|
485 | + $readonlys['tabs']['history'] = true; |
|
486 | + } |
|
487 | + //suppress history for the first loading without ID |
|
437 | 488 | |
438 | 489 | return $etpl->exec(TIMESHEET_APP.'.timesheet_ui.edit',$content,$sel_options,$readonlys,$preserv,2); |
439 | 490 | } |
@@ -446,7 +497,10 @@ discard block |
||
446 | 497 | */ |
447 | 498 | function datetime2time($datetime) |
448 | 499 | { |
449 | - if (!$datetime) return 0; |
|
500 | + if (!$datetime) |
|
501 | + { |
|
502 | + return 0; |
|
503 | + } |
|
450 | 504 | |
451 | 505 | return $datetime - mktime(0,0,0,date('m',$datetime),date('d',$datetime),date('Y',$datetime)); |
452 | 506 | } |
@@ -486,7 +540,10 @@ discard block |
||
486 | 540 | } |
487 | 541 | // show week-sums, if we are week-aligned (show full weeks)? |
488 | 542 | $week_start_day = $GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts']; |
489 | - if (!$week_start_day) $week_start_day = 'Sunday'; |
|
543 | + if (!$week_start_day) |
|
544 | + { |
|
545 | + $week_start_day = 'Sunday'; |
|
546 | + } |
|
490 | 547 | switch($week_start_day) |
491 | 548 | { |
492 | 549 | case 'Sunday': $week_end_day = 'Saturday'; break; |
@@ -508,15 +565,24 @@ discard block |
||
508 | 565 | } |
509 | 566 | } |
510 | 567 | //echo "<p align=right>show_sums=".print_r($this->show_sums,true)."</p>\n"; |
511 | - if (!$id_only && !$query_in['csv_export']) $GLOBALS['egw']->session->appsession('index',TIMESHEET_APP,$query_in); |
|
568 | + if (!$id_only && !$query_in['csv_export']) |
|
569 | + { |
|
570 | + $GLOBALS['egw']->session->appsession('index',TIMESHEET_APP,$query_in); |
|
571 | + } |
|
512 | 572 | |
513 | 573 | // Refresh actions (undelete needs this) |
514 | 574 | $query_in['actions'] = $this->get_actions($query_in); |
515 | 575 | |
516 | 576 | $query = $query_in; // keep the original query |
517 | 577 | |
518 | - if($this->ts_viewtype == 'short') $query_in['options-selectcols'] = array('ts_quantity'=>false,'ts_unitprice'=>false,'ts_total'=>false); |
|
519 | - if ($query['no_status']) $query_in['options-selectcols']['ts_status'] = false; |
|
578 | + if($this->ts_viewtype == 'short') |
|
579 | + { |
|
580 | + $query_in['options-selectcols'] = array('ts_quantity'=>false,'ts_unitprice'=>false,'ts_total'=>false); |
|
581 | + } |
|
582 | + if ($query['no_status']) |
|
583 | + { |
|
584 | + $query_in['options-selectcols']['ts_status'] = false; |
|
585 | + } |
|
520 | 586 | |
521 | 587 | //_debug_array($query['col_filter']); |
522 | 588 | //echo "PM Integration:".$this->pm_integration.'<br>'; |
@@ -529,8 +595,14 @@ discard block |
||
529 | 595 | { |
530 | 596 | //$query['col_filter']['ts_id'] = egw_link::get_links('projectmanager',$query['col_filter']['pm_id'],'timesheet'); |
531 | 597 | $query['col_filter']['ts_id'] = $this->get_ts_links($query['col_filter']['pm_id']); |
532 | - if (empty($query['col_filter']['ts_id'])) $query['col_filter']['ts_id'] = -1; |
|
533 | - if (!$query['col_filter']['ts_id']) $query['col_filter']['ts_id'] = 0; |
|
598 | + if (empty($query['col_filter']['ts_id'])) |
|
599 | + { |
|
600 | + $query['col_filter']['ts_id'] = -1; |
|
601 | + } |
|
602 | + if (!$query['col_filter']['ts_id']) |
|
603 | + { |
|
604 | + $query['col_filter']['ts_id'] = 0; |
|
605 | + } |
|
534 | 606 | } |
535 | 607 | if ((string)$query['col_filter']['pm_id'] != '' && (string)$query['col_filter']['pm_id'] == '0') |
536 | 608 | { |
@@ -594,10 +666,13 @@ discard block |
||
594 | 666 | $cats = $GLOBALS['egw']->categories->return_all_children((int)$query['cat_id']); |
595 | 667 | $query['col_filter']['cat_id'] = count($cats) > 1 ? $cats : $query['cat_id']; |
596 | 668 | } |
597 | - elseif ((string)$query['cat_id'] == '0') // no category |
|
669 | + elseif ((string)$query['cat_id'] == '0') |
|
670 | + { |
|
671 | + // no category |
|
598 | 672 | { |
599 | 673 | $query['col_filter']['cat_id'] = null; |
600 | 674 | } |
675 | + } |
|
601 | 676 | else // all cats --> no filter |
602 | 677 | { |
603 | 678 | unset($query['col_filter']['cat_id']); |
@@ -608,7 +683,10 @@ discard block |
||
608 | 683 | $GLOBALS['egw_info']['flags']['app_header'] .= ': '.common::grab_owner_name($query['col_filter']['ts_owner']); |
609 | 684 | #if ($GLOBALS['egw']->accounts->get_type($query['col_filter']['ts_owner']) == 'g') $GLOBALS['egw_info']['flags']['app_header'] .= ' '. lang("and its members"); |
610 | 685 | #_debug_array($GLOBALS['egw']->accounts->members($query['col_filter']['ts_owner'],true)); |
611 | - if ($query['col_filter']['ts_owner']<0) $query['col_filter']['ts_owner'] = array_merge(array($query['col_filter']['ts_owner']),$GLOBALS['egw']->accounts->members($query['col_filter']['ts_owner'],true)); |
|
686 | + if ($query['col_filter']['ts_owner']<0) |
|
687 | + { |
|
688 | + $query['col_filter']['ts_owner'] = array_merge(array($query['col_filter']['ts_owner']),$GLOBALS['egw']->accounts->members($query['col_filter']['ts_owner'],true)); |
|
689 | + } |
|
612 | 690 | } |
613 | 691 | else |
614 | 692 | { |
@@ -621,10 +699,13 @@ discard block |
||
621 | 699 | // generate a meaningful app-header / report title |
622 | 700 | if ($this->show_sums['month']) |
623 | 701 | { |
624 | - if ((int)$start[1] == 1 && (int) $end[1] == 12) // whole year(s) |
|
702 | + if ((int)$start[1] == 1 && (int) $end[1] == 12) |
|
703 | + { |
|
704 | + // whole year(s) |
|
625 | 705 | { |
626 | 706 | $GLOBALS['egw_info']['flags']['app_header'] .= ': ' . $start[0] . ($start[0] != $end[0] ? ' - '.$end[0] : ''); |
627 | 707 | } |
708 | + } |
|
628 | 709 | else |
629 | 710 | { |
630 | 711 | $GLOBALS['egw_info']['flags']['app_header'] .= ': ' . lang(date('F',$query['startdate']+12*60*60)) . ' ' . $start[0]; |
@@ -657,7 +738,10 @@ discard block |
||
657 | 738 | $ids = array(); |
658 | 739 | foreach($rows as &$row) |
659 | 740 | { |
660 | - if ($row['ts_id'] > 0) $ids[] = $row['ts_id']; |
|
741 | + if ($row['ts_id'] > 0) |
|
742 | + { |
|
743 | + $ids[] = $row['ts_id']; |
|
744 | + } |
|
661 | 745 | } |
662 | 746 | if ($id_only) |
663 | 747 | { |
@@ -687,12 +771,19 @@ discard block |
||
687 | 771 | $have_cats = false; |
688 | 772 | foreach($rows as &$row) |
689 | 773 | { |
690 | - if ($row['cat_id']) $have_cats = true; |
|
774 | + if ($row['cat_id']) |
|
775 | + { |
|
776 | + $have_cats = true; |
|
777 | + } |
|
691 | 778 | |
692 | 779 | $row['class'] = 'row'; |
693 | - if ($row['ts_id'] <= 0) // sums |
|
780 | + if ($row['ts_id'] <= 0) |
|
781 | + { |
|
782 | + // sums |
|
694 | 783 | { |
695 | - if ($query['sort'] == 'ASC') $row['ts_start'] -= 7200; // fix for DSL change |
|
784 | + if ($query['sort'] == 'ASC') $row['ts_start'] -= 7200; |
|
785 | + } |
|
786 | + // fix for DSL change |
|
696 | 787 | |
697 | 788 | // Remove fake modified date, it breaks nextmatch checks |
698 | 789 | unset($row['ts_modified']); |
@@ -721,7 +812,10 @@ discard block |
||
721 | 812 | break; |
722 | 813 | } |
723 | 814 | $row['ts_start'] = $row['ts_unitprice'] = ''; |
724 | - if (!$this->quantity_sum) $row['ts_quantity'] = ''; |
|
815 | + if (!$this->quantity_sum) |
|
816 | + { |
|
817 | + $row['ts_quantity'] = ''; |
|
818 | + } |
|
725 | 819 | $row['class'] = 'th rowNoEdit rowNoDelete rowNoUndelete'; |
726 | 820 | $row['titleClass'] = 'timesheet_titleSum'; |
727 | 821 | continue; |
@@ -763,13 +857,25 @@ discard block |
||
763 | 857 | } |
764 | 858 | } |
765 | 859 | |
766 | - if(!$row['titleClass']) $row['titleClass'] = 'timesheet_titleDetails'; |
|
860 | + if(!$row['titleClass']) |
|
861 | + { |
|
862 | + $row['titleClass'] = 'timesheet_titleDetails'; |
|
863 | + } |
|
767 | 864 | |
768 | 865 | } |
769 | - if (!$have_cats || $query['cat_id']) $rows['no_cat_id'] = true; |
|
770 | - if ($query['col_filter']['ts_owner']) $rows['ownerClass'] = 'noPrint'; |
|
866 | + if (!$have_cats || $query['cat_id']) |
|
867 | + { |
|
868 | + $rows['no_cat_id'] = true; |
|
869 | + } |
|
870 | + if ($query['col_filter']['ts_owner']) |
|
871 | + { |
|
872 | + $rows['ownerClass'] = 'noPrint'; |
|
873 | + } |
|
771 | 874 | $rows['no_owner_col'] = $query['no_owner_col']; |
772 | - if (!$rows['no_owner_col'] && $query['selectcols'] && !strpos($query['selectcols'],'ts_owner')) $rows['no_owner_col'] = 1; |
|
875 | + if (!$rows['no_owner_col'] && $query['selectcols'] && !strpos($query['selectcols'],'ts_owner')) |
|
876 | + { |
|
877 | + $rows['no_owner_col'] = 1; |
|
878 | + } |
|
773 | 879 | if ($query['filter']) |
774 | 880 | { |
775 | 881 | $rows += $this->summary; |
@@ -780,9 +886,18 @@ discard block |
||
780 | 886 | { |
781 | 887 | #_debug_array($query['selectcols']); |
782 | 888 | #ts_quantity,ts_unitprice,ts_total |
783 | - if ($query['selectcols'] && strpos($query['selectcols'],'ts_quantity')===false) $rows['no_ts_quantity'] = 1; |
|
784 | - if ($query['selectcols'] && strpos($query['selectcols'],'ts_unitprice')===false) $rows['no_ts_unitprice'] = 1; |
|
785 | - if ($query['selectcols'] && strpos($query['selectcols'],'ts_total')===false) $rows['no_ts_total'] = 1; |
|
889 | + if ($query['selectcols'] && strpos($query['selectcols'],'ts_quantity')===false) |
|
890 | + { |
|
891 | + $rows['no_ts_quantity'] = 1; |
|
892 | + } |
|
893 | + if ($query['selectcols'] && strpos($query['selectcols'],'ts_unitprice')===false) |
|
894 | + { |
|
895 | + $rows['no_ts_unitprice'] = 1; |
|
896 | + } |
|
897 | + if ($query['selectcols'] && strpos($query['selectcols'],'ts_total')===false) |
|
898 | + { |
|
899 | + $rows['no_ts_total'] = 1; |
|
900 | + } |
|
786 | 901 | } |
787 | 902 | $rows['no_ts_status'] = strpos($query['selectcols'], 'ts_status') === false && !$this->config_data['history'] || |
788 | 903 | $query['no_status']; |
@@ -800,7 +915,10 @@ discard block |
||
800 | 915 | { |
801 | 916 | $etpl = new etemplate_new('timesheet.index'); |
802 | 917 | |
803 | - if ($_GET['msg']) $msg = $_GET['msg']; |
|
918 | + if ($_GET['msg']) |
|
919 | + { |
|
920 | + $msg = $_GET['msg']; |
|
921 | + } |
|
804 | 922 | if ($content['nm']['rows']['delete']) |
805 | 923 | { |
806 | 924 | list($ts_id) = each($content['nm']['rows']['delete']); |
@@ -813,9 +931,12 @@ discard block |
||
813 | 931 | $msg = lang('Error deleting the entry!!!'); |
814 | 932 | } |
815 | 933 | } |
816 | - if (is_array($content) && isset($content['nm']['rows']['document'])) // handle insert in default document button like an action |
|
934 | + if (is_array($content) && isset($content['nm']['rows']['document'])) |
|
935 | + { |
|
936 | + // handle insert in default document button like an action |
|
817 | 937 | { |
818 | 938 | list($id) = @each($content['nm']['rows']['document']); |
939 | + } |
|
819 | 940 | $content['nm']['action'] = 'document'; |
820 | 941 | $content['nm']['selected'] = array($id); |
821 | 942 | } |
@@ -884,7 +1005,10 @@ discard block |
||
884 | 1005 | } |
885 | 1006 | $read_grants = $this->grant_list(EGW_ACL_READ); |
886 | 1007 | $content['nm']['no_owner_col'] = count($read_grants) == 1; |
887 | - if ($GLOBALS['egw_info']['user']['preferences']['timesheet']['nextmatch-timesheet.index.rows']) $content['nm']['selectcols'] = $GLOBALS['egw_info']['user']['preferences']['timesheet']['nextmatch-timesheet.index.rows']; |
|
1008 | + if ($GLOBALS['egw_info']['user']['preferences']['timesheet']['nextmatch-timesheet.index.rows']) |
|
1009 | + { |
|
1010 | + $content['nm']['selectcols'] = $GLOBALS['egw_info']['user']['preferences']['timesheet']['nextmatch-timesheet.index.rows']; |
|
1011 | + } |
|
888 | 1012 | $sel_options = array( |
889 | 1013 | 'ts_owner' => $read_grants, |
890 | 1014 | 'pm_id' => array(lang('No project')), |
@@ -901,7 +1025,10 @@ discard block |
||
901 | 1025 | if ($this->pm_integration != 'full') |
902 | 1026 | { |
903 | 1027 | $projects =& $this->query_list('ts_project'); |
904 | - if (!is_array($projects)) $projects = array(); |
|
1028 | + if (!is_array($projects)) |
|
1029 | + { |
|
1030 | + $projects = array(); |
|
1031 | + } |
|
905 | 1032 | $sel_options['ts_project'] = $projects + array(lang('No project')); |
906 | 1033 | } |
907 | 1034 | |
@@ -1105,7 +1232,8 @@ discard block |
||
1105 | 1232 | case 'cat': |
1106 | 1233 | $cat_name = categories::id2name($settings); |
1107 | 1234 | $action_msg = lang('changed category to %1', $cat_name); |
1108 | - foreach((array)$checked as $n => $id) { |
|
1235 | + foreach((array)$checked as $n => $id) |
|
1236 | + { |
|
1109 | 1237 | $entry = $this->read($id); |
1110 | 1238 | $entry['cat_id'] = $settings; |
1111 | 1239 | if($this->save($entry) == 0) |
@@ -1120,7 +1248,10 @@ discard block |
||
1120 | 1248 | break; |
1121 | 1249 | |
1122 | 1250 | case 'document': |
1123 | - if (!$settings) $settings = $GLOBALS['egw_info']['user']['preferences']['timesheet']['default_document']; |
|
1251 | + if (!$settings) |
|
1252 | + { |
|
1253 | + $settings = $GLOBALS['egw_info']['user']['preferences']['timesheet']['default_document']; |
|
1254 | + } |
|
1124 | 1255 | $document_merge = new timesheet_merge(); |
1125 | 1256 | $msg = $document_merge->download($settings, $checked, '', $GLOBALS['egw_info']['user']['preferences']['timesheet']['document_dir']); |
1126 | 1257 | $failed = count($checked); |
@@ -1172,7 +1303,10 @@ discard block |
||
1172 | 1303 | $this->load_statuses(); |
1173 | 1304 | $msg .= lang('Status updated.'); |
1174 | 1305 | } |
1175 | - if ($button == 'apply') break; |
|
1306 | + if ($button == 'apply') |
|
1307 | + { |
|
1308 | + break; |
|
1309 | + } |
|
1176 | 1310 | // fall-through |
1177 | 1311 | case 'cancel': |
1178 | 1312 | $GLOBALS['egw']->redirect_link('/admin/index.php', null, 'admin'); |
@@ -31,7 +31,7 @@ |
||
31 | 31 | * Create a session or if the user has no account return authenticate header and 401 Unauthorized |
32 | 32 | * |
33 | 33 | * @param array &$account |
34 | - * @return int session-id |
|
34 | + * @return string session-id |
|
35 | 35 | */ |
36 | 36 | function check_access(&$account) |
37 | 37 | { |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | { |
35 | 35 | if (isset($_GET['auth'])) |
36 | 36 | { |
37 | - list($_SERVER['PHP_AUTH_USER'],$_SERVER['PHP_AUTH_PW']) = explode(':',base64_decode($_GET['auth']),2); |
|
37 | + list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':', base64_decode($_GET['auth']), 2); |
|
38 | 38 | } |
39 | 39 | return egw_digest_auth::autocreate_session_callback($account); |
40 | 40 | } |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | 'noheader' => True, |
46 | 46 | 'currentapp' => preg_match('|/webdav.php/apps/([A-Za-z0-9_-]+)/|', $_SERVER['REQUEST_URI'], $matches) ? $matches[1] : 'filemanager', |
47 | 47 | 'autocreate_session_callback' => 'check_access', |
48 | - 'no_exception_handler' => 'basic_auth', // we use a basic auth exception handler (sends exception message as basic auth realm) |
|
49 | - 'auth_realm' => 'EGroupware WebDAV server', // cant use vfs_webdav_server::REALM as autoloading and include path not yet setup! |
|
48 | + 'no_exception_handler' => 'basic_auth', // we use a basic auth exception handler (sends exception message as basic auth realm) |
|
49 | + 'auth_realm' => 'EGroupware WebDAV server', // cant use vfs_webdav_server::REALM as autoloading and include path not yet setup! |
|
50 | 50 | ) |
51 | 51 | ); |
52 | 52 | require_once('phpgwapi/inc/class.egw_digest_auth.inc.php'); |