1 | <?php |
---|
2 | /** |
---|
3 | * ProjectManager - UI to list and edit project-elments |
---|
4 | * |
---|
5 | * @link http://www.egroupware.org |
---|
6 | * @author Ralf Becker <RalfBecker-AT-outdoor-training.de> |
---|
7 | * @package projectmanager |
---|
8 | * @copyright (c) 2005/6 by Ralf Becker <RalfBecker-AT-outdoor-training.de> |
---|
9 | * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License |
---|
10 | * @version $Id: class.uiprojectelements.inc.php 23913 2007-05-22 04:04:13Z lkneschke $ |
---|
11 | */ |
---|
12 | |
---|
13 | include_once(PHPGW_INCLUDE_ROOT.'/projectmanager/inc/class.boprojectelements.inc.php'); |
---|
14 | |
---|
15 | /** |
---|
16 | * ProjectManage UI: list and edit projects-elements |
---|
17 | */ |
---|
18 | class uiprojectelements extends boprojectelements |
---|
19 | { |
---|
20 | /** |
---|
21 | * Functions to call via menuaction |
---|
22 | * |
---|
23 | * @var array |
---|
24 | */ |
---|
25 | var $public_functions = array( |
---|
26 | 'index' => true, |
---|
27 | 'edit' => true, |
---|
28 | 'view' => true, |
---|
29 | ); |
---|
30 | /** |
---|
31 | * Instance of the etemplate class |
---|
32 | * |
---|
33 | * @var etemplate |
---|
34 | */ |
---|
35 | var $tpl; |
---|
36 | /** |
---|
37 | * Labels for status-filter |
---|
38 | * |
---|
39 | * @var array |
---|
40 | */ |
---|
41 | var $status_labels; |
---|
42 | /** |
---|
43 | * Config-settings for projectmanager |
---|
44 | * |
---|
45 | * @var array |
---|
46 | */ |
---|
47 | var $config; |
---|
48 | |
---|
49 | /** |
---|
50 | * Constructor, calls the constructor of the extended class |
---|
51 | * |
---|
52 | * @return uiprojectelements |
---|
53 | */ |
---|
54 | function uiprojectelements() |
---|
55 | { |
---|
56 | $this->tpl =& CreateObject('etemplate.etemplate'); |
---|
57 | |
---|
58 | if ((int) $_REQUEST['pm_id']) |
---|
59 | { |
---|
60 | $pm_id = (int) $_REQUEST['pm_id']; |
---|
61 | // store the current project (only for index, as popups may be called by other parent-projects) |
---|
62 | } |
---|
63 | else |
---|
64 | { |
---|
65 | $pm_id = $GLOBALS['phpgw']->session->appsession('pm_id','projectmanager'); |
---|
66 | } |
---|
67 | if (!$pm_id) |
---|
68 | { |
---|
69 | $this->tpl->location(array( |
---|
70 | 'menuaction' => 'projectmanager.uiprojectmanager.index', |
---|
71 | 'msg' => lang('You need to select a project first'), |
---|
72 | )); |
---|
73 | } |
---|
74 | $this->boprojectelements($pm_id); |
---|
75 | |
---|
76 | // check if we have at least read-access to this project |
---|
77 | if (!$this->project->check_acl(PHPGW_ACL_READ)) |
---|
78 | { |
---|
79 | $this->tpl->location(array( |
---|
80 | 'menuaction' => 'projectmanager.uiprojectmanager.index', |
---|
81 | 'msg' => lang('Permission denied !!!'), |
---|
82 | )); |
---|
83 | } |
---|
84 | |
---|
85 | $this->status_labels = array( |
---|
86 | 'all' => lang('all'), |
---|
87 | 'used' => lang('used'), |
---|
88 | 'new' => lang('new'), |
---|
89 | 'ignored' => lang('ignored'), |
---|
90 | ); |
---|
91 | } |
---|
92 | |
---|
93 | |
---|
94 | /** |
---|
95 | * View a project-element, just calls edit with view-param set |
---|
96 | */ |
---|
97 | function view() |
---|
98 | { |
---|
99 | $this->edit(null,true); |
---|
100 | } |
---|
101 | |
---|
102 | /** |
---|
103 | * Edit or view a project-element |
---|
104 | * |
---|
105 | * @var array $content content-array if called by process-exec |
---|
106 | * @var boolean $view only view project, default false, only used on first call !is_array($content) |
---|
107 | */ |
---|
108 | function edit($content=null,$view=false) |
---|
109 | { |
---|
110 | if ((int) $this->debug >= 1 || $this->debug == 'edit') $this->debug_message("uiprojectelements::edit(".print_r($content,true).",$view)"); |
---|
111 | |
---|
112 | if (is_array($content)) |
---|
113 | { |
---|
114 | $this->data = $content['data']; |
---|
115 | $update_necessary = $save_necessary = 0; |
---|
116 | $datasource = $this->datasource($this->data['pe_app']); |
---|
117 | if (($ds_read_from_element = !($ds = $datasource->read($this->data['pe_app_id'],$this->data)))) |
---|
118 | { |
---|
119 | $ds = $datasource->element_values($this->data); |
---|
120 | } |
---|
121 | if (!$content['view']) |
---|
122 | { |
---|
123 | if ($content['pe_completion'] !== '') $content['pe_completion'] .= '%'; |
---|
124 | |
---|
125 | foreach($datasource->name2id as $name => $id) |
---|
126 | { |
---|
127 | //echo "checking $name=$id (overwrite={$this->data['pe_overwrite']}&$id == ".($this->data['pe_overwrite']&$id?'true':'false')."), content='{$content[$name]}'<br>\n"; |
---|
128 | // check if update is necessary, because a field has be set or changed |
---|
129 | if ($content[$name] && ($content[$name] != $this->data[$name] || !($this->data['pe_overwrite'] & $id))) |
---|
130 | { |
---|
131 | //echo "need to update $name as content[$name] changed to '".$content[$name]."' != '".$this->data[$name]."'<br>\n"; |
---|
132 | $this->data[$name] = $content[$name]; |
---|
133 | $this->data['pe_overwrite'] |= $id; |
---|
134 | $update_necessary |= $id; |
---|
135 | } |
---|
136 | // check if a field is no longer set, or it's not set and datasource changed |
---|
137 | // => set it from the datasource |
---|
138 | elseif (($this->data['pe_overwrite'] & $id) && !$content[$name] || |
---|
139 | !($this->data['pe_overwrite'] & $id) && (int)$this->data[$name] != (int)$ds[$name]) |
---|
140 | { |
---|
141 | //echo "need to update $name as content[$name] is unset or datasource changed cont='".$content[$name]."', data='".$this->data[$name]."', ds='".$ds[$name]."'<br>\n"; |
---|
142 | // if we have a change in the datasource, set pe_synced |
---|
143 | if ($this->data[$name] != $ds[$name]) |
---|
144 | { |
---|
145 | $this->data['pe_synced'] = $this->now_su; |
---|
146 | } |
---|
147 | $this->data[$name] = $ds[$name]; |
---|
148 | $this->data['pe_overwrite'] &= ~$id; |
---|
149 | $update_necessary |= $id; |
---|
150 | } |
---|
151 | } |
---|
152 | $content['cat_id'] = (int) $content['cat_id']; // as All='' and cat_id column is int |
---|
153 | |
---|
154 | // calculate the new summary and if a percentage give the share in hours |
---|
155 | //echo "<p>project_summary[pe_total_shares]={$this->project_summary['pe_total_shares']}, old_pe_share={$content['old_pe_share']}, old_default_share=$content[old_default_share], content[pe_share]={$content['pe_share']}</p>\n"; |
---|
156 | $planned_time = $content['pe_planned_time'] ? $content['pe_planned_time'] : $ds['pe_planned_time']; |
---|
157 | $default_share = $planned_time && $this->project->data['pm_accounting_type'] != 'status' ? $planned_time : $this->default_share; |
---|
158 | |
---|
159 | $this->project_summary['pe_total_shares'] -= round((string) $content['old_pe_share'] !== '' ? $content['old_pe_share'] : $content['old_default_share']); |
---|
160 | if (substr($content['pe_share'],-1) == '%' || $this->project->data['pm_accounting_type'] == 'status') |
---|
161 | { |
---|
162 | //echo "<p>project_summary[pe_total_shares]={$this->project_summary['pe_total_shares']}</p>\n"; |
---|
163 | if ((float) $content['pe_share'] == 100 || !$this->project_summary['pe_total_shares']) |
---|
164 | { |
---|
165 | $content['pe_share'] = $this->default_share; |
---|
166 | } |
---|
167 | else |
---|
168 | { |
---|
169 | $content['pe_share'] = round($this->project_summary['pe_total_shares'] * (float) $content['pe_share'] / |
---|
170 | (100 - (float) $content['pe_share']),1); |
---|
171 | } |
---|
172 | //echo "<p>pe_share={$content['pe_share']}</p>\n"; |
---|
173 | } |
---|
174 | $this->project_summary['pe_total_shares'] += round((string) $content['pe_share'] !== '' ? $content['pe_share'] : $default_share); |
---|
175 | //echo "<p>project_summary[pe_total_shares]={$this->project_summary['pe_total_shares']}, default_share=$default_share, content[pe_share]={$content['pe_share']}</p>\n"; |
---|
176 | |
---|
177 | foreach(array('pe_status','cat_id','pe_remark','pe_constraints','pe_share') as $name) |
---|
178 | { |
---|
179 | if ($name == 'pe_constraints') |
---|
180 | { |
---|
181 | foreach($content['pe_constraints'] as $type => $data) |
---|
182 | { |
---|
183 | if (!$data) |
---|
184 | { |
---|
185 | unset($content['pe_constraints'][$type]); // ignore not set constraints |
---|
186 | } |
---|
187 | elseif (!is_array($data)) |
---|
188 | { |
---|
189 | $content['pe_constraints'][$type] = explode(',',$data); // otherwise it's detected as change |
---|
190 | } |
---|
191 | } |
---|
192 | } |
---|
193 | if ($content[$name] != $this->data[$name] || |
---|
194 | $name == 'pe_share' && $content[$name] !== $this->data[$name]) // for pe_share we differ between 0 and empty! |
---|
195 | { |
---|
196 | //echo "need to update $name as content[$name] changed to '".print_r($content[$name],true)."' != '".print_r($this->data[$name],true)."'<br>\n"; |
---|
197 | $this->data[$name] = $content[$name]; |
---|
198 | $save_necessary = true; |
---|
199 | |
---|
200 | if ($name == 'pe_remark') $this->data['update_remark'] = true; |
---|
201 | } |
---|
202 | } |
---|
203 | } |
---|
204 | //echo "uiprojectelements::edit(): save_necessary=".(int)$save_necessary.", update_necessary=$update_necessary, data="; _debug_array($this->data); |
---|
205 | |
---|
206 | $view = $content['view'] && !($content['edit'] && $this->check_acl(PHPGW_ACL_EDIT)); |
---|
207 | |
---|
208 | if (($content['save'] || $content['apply']) && $this->check_acl(PHPGW_ACL_EDIT)) |
---|
209 | { |
---|
210 | if ($update_necessary || $save_necessary) |
---|
211 | { |
---|
212 | if ($this->save(null,true,$update_necessary) != 0) |
---|
213 | { |
---|
214 | $msg = lang('Error: saving the project-element (%1) !!!',$this->db->Error); |
---|
215 | unset($content['save']); // dont exit |
---|
216 | } |
---|
217 | else |
---|
218 | { |
---|
219 | $msg = lang('Project-Element saved'); |
---|
220 | $js = "opener.location.href='".$GLOBALS['phpgw']->link('/index.php',array( |
---|
221 | 'menuaction' => $content['caller'] ? $content['caller'] : 'projectmanager.uiprojectelements.index', |
---|
222 | 'msg' => $msg, |
---|
223 | ))."';"; |
---|
224 | } |
---|
225 | } |
---|
226 | else |
---|
227 | { |
---|
228 | $msg = lang('no save necessary'); |
---|
229 | } |
---|
230 | } |
---|
231 | if ($content['delete'] && $this->check_acl(PHPGW_ACL_DELETE)) |
---|
232 | { |
---|
233 | // all delete are done by index |
---|
234 | $js = "opener.location.href='".$GLOBALS['phpgw']->link('/index.php',array( |
---|
235 | 'menuaction' => $content['caller'] ? $content['caller'] : 'projectmanager.uiprojectelements.index', |
---|
236 | 'delete' => $this->data['pe_id'], |
---|
237 | ))."';"; |
---|
238 | /* |
---|
239 | return $this->index(array('nm'=>array('rows'=>array( |
---|
240 | 'delete' => array($this->data['pe_id']=>true) |
---|
241 | )))); |
---|
242 | */ |
---|
243 | } |
---|
244 | if ($content['save'] || $content['cancel'] || $content['delete']) |
---|
245 | { |
---|
246 | $js .= 'window.close();'; |
---|
247 | echo '<html><body onload="'.$js.'"></body></html>'; |
---|
248 | $GLOBALS['phpgw']->common->phpgw_exit(); |
---|
249 | /* |
---|
250 | $this->tpl->location(array( |
---|
251 | 'menuaction' => 'projectmanager.uiprojectelements.index', |
---|
252 | 'msg' => $msg, |
---|
253 | )); |
---|
254 | */ |
---|
255 | } |
---|
256 | } |
---|
257 | else |
---|
258 | { |
---|
259 | if ((int) $_GET['pe_id']) |
---|
260 | { |
---|
261 | $this->read((int) $_GET['pe_id']); |
---|
262 | } |
---|
263 | if ($this->data['pe_id']) |
---|
264 | { |
---|
265 | if (!$this->check_acl(PHPGW_ACL_READ)) |
---|
266 | { |
---|
267 | $this->tpl->location(array( |
---|
268 | 'menuaction' => 'projectmanager.uiprojectelements.index', |
---|
269 | 'msg' => lang('Permission denied !!!'), |
---|
270 | )); |
---|
271 | } |
---|
272 | if (!$this->check_acl(PHPGW_ACL_EDIT)) $view = true; |
---|
273 | } |
---|
274 | $js = 'window.focus();'; |
---|
275 | |
---|
276 | $datasource = $this->datasource($this->data['pe_app']); |
---|
277 | if (($ds_read_from_element = !($ds = $datasource->read($this->data['pe_app_id'],$this->data)))) |
---|
278 | { |
---|
279 | $ds = $datasource->element_values($this->data); |
---|
280 | } |
---|
281 | else |
---|
282 | { |
---|
283 | $this->data['pe_title'] = $ds['pe_title']; // updating the title, not all datasources do it automatic |
---|
284 | } |
---|
285 | } |
---|
286 | $planned_time = $this->data['pe_planned_time'] ? $this->data['pe_planned_time'] : $ds['pe_planned_time']; |
---|
287 | $default_share = $planned_time && $this->project->data['pm_accounting_type'] != 'status' ? $planned_time : $this->default_share; |
---|
288 | |
---|
289 | if ($ds_read_from_element && !$view) |
---|
290 | { |
---|
291 | $msg .= lang('No READ access to the datasource: removing overwritten values will just empty them !!!'); |
---|
292 | } |
---|
293 | $preserv = $this->data + array( |
---|
294 | 'view' => $view, |
---|
295 | 'data' => $this->data, |
---|
296 | 'caller' => !$content['caller'] && preg_match('/menuaction=([^&]+)/',$_SERVER['HTTP_REFERER'],$matches) ? |
---|
297 | $matches[1] : $content['caller'], |
---|
298 | 'old_pe_share' => $this->data['pe_share'], |
---|
299 | 'old_default_share' => $default_share, |
---|
300 | ); |
---|
301 | unset($preserv['pe_resources']); // otherwise we cant detect no more resources set |
---|
302 | |
---|
303 | foreach($datasource->name2id as $name => $id) |
---|
304 | { |
---|
305 | if ($id != PM_TITLE && !($this->data['pe_overwrite'] & $id)) // empty not explicitly set values |
---|
306 | { |
---|
307 | $this->data[$name] = ''; |
---|
308 | } |
---|
309 | } |
---|
310 | $js .= "\nfunction calc_budget(form) { |
---|
311 | form['exec[pe_used_budget]'].value = form['exec[pe_used_quantity]'].value.replace(/,/,'.') * form['exec[pe_unitprice]'].value.replace(/,/,'.'); |
---|
312 | if (form['exec[pe_used_budget]'].value == '0') form['exec[pe_used_budget]'].value = ''; |
---|
313 | form['exec[pe_planned_budget]'].value = form['exec[pe_planned_quantity]'].value.replace(/,/,'.') * form['exec[pe_unitprice]'].value.replace(/,/,'.'); |
---|
314 | if (form['exec[pe_planned_budget]'].value == '0') form['exec[pe_planned_budget]'].value = ''; |
---|
315 | }"; |
---|
316 | $tabs = 'dates|times|budget|constraints|resources|details'; |
---|
317 | $content = $this->data + array( |
---|
318 | 'ds' => $ds, |
---|
319 | 'msg' => $msg, |
---|
320 | 'js' => '<script>'.$js.'</script>', |
---|
321 | 'default_share' => $default_share, |
---|
322 | 'duration_format' => $this->config['duration_format'], |
---|
323 | 'no_times' => $this->project->data['pm_accounting_type'] == 'status', |
---|
324 | $tabs => $content[$tabs], |
---|
325 | 'no_pricelist' => $this->project->data['pm_accounting_type'] != 'pricelist', |
---|
326 | 'planned_quantity_blur' => $this->data['pe_planned_time'] ? $this->data['pe_planned_time'] / 60 : $ds['pe_planned_quantity'], |
---|
327 | 'used_quantity_blur' => $this->data['pe_used_time'] ? $this->data['pe_used_time'] / 60 : $ds['pe_used_quantity'], |
---|
328 | ); |
---|
329 | // calculate percentual shares |
---|
330 | $content['default_total'] = $content['share_total'] = $this->project_summary['pe_total_shares']; |
---|
331 | if ((string) $this->data['pe_share'] !== '') |
---|
332 | { |
---|
333 | if ($this->project_summary['pe_total_shares']) |
---|
334 | { |
---|
335 | $content['share_percentage'] = round(100.0 * $this->data['pe_share'] / $this->project_summary['pe_total_shares'],1) . '%'; |
---|
336 | } |
---|
337 | $content['default_total'] += $default_share - $this->data['pe_share']; |
---|
338 | } |
---|
339 | if ($content['default_total']) |
---|
340 | { |
---|
341 | $content['default_percentage'] = round(100.0 * $default_share / $content['default_total'],1) . '%'; |
---|
342 | } |
---|
343 | if ($this->project->data['pm_accounting_type'] == 'status') |
---|
344 | { |
---|
345 | $content['pe_share'] = $content['share_percentage']; |
---|
346 | } |
---|
347 | //_debug_array($content); |
---|
348 | $sel_options = array( |
---|
349 | 'pe_constraints' => $this->titles(array( // only titles of elements displayed in a gantchart |
---|
350 | "pe_status != 'ignore'", |
---|
351 | // '(pe_planned_start IS NOT NULL OR pe_real_start IS NOT NULL)', |
---|
352 | // '(pe_planned_end IS NOT NULL OR pe_real_end IS NOT NULL)', |
---|
353 | 'pe_id != '.(int)$this->data['pe_id'], // dont show own title |
---|
354 | )), |
---|
355 | 'milestone' => $this->milestones->titles(array('pm_id' => $this->data['pm_id'])), |
---|
356 | ); |
---|
357 | $readonlys = array( |
---|
358 | 'delete' => !$this->data['pe_id'] || !$this->check_acl(PHPGW_ACL_DELETE), |
---|
359 | 'edit' => !$view || !$this->check_acl(PHPGW_ACL_EDIT), |
---|
360 | ); |
---|
361 | // disable the times tab, if accounting-type status |
---|
362 | $readonlys[$tabs]['times'] = $this->project->data['pm_accounting_type'] == 'status'; |
---|
363 | // check if user has the necessary rights to view or edit the budget |
---|
364 | $readonlys[$tabs]['budget'] = !$this->check_acl(PHPGW_ACL_BUDGET); |
---|
365 | if (!$this->check_acl(PHPGW_ACL_EDIT_BUDGET)) |
---|
366 | { |
---|
367 | foreach(array('pe_planned_budget','pe_used_budget','pl_id','pe_unitprice','pe_planned_quantity','pe_used_quantity') as $key) |
---|
368 | { |
---|
369 | $readonlys[$key] = true; |
---|
370 | } |
---|
371 | } |
---|
372 | if ($view) |
---|
373 | { |
---|
374 | foreach($this->db_cols as $name) |
---|
375 | { |
---|
376 | $readonlys[$name] = true; |
---|
377 | } |
---|
378 | $readonlys['pe_remark'] = true; |
---|
379 | $readonlys['save'] = $readonlys['apply'] = true; |
---|
380 | $readonlys['pe_constraints[start]'] = $readonlys['pe_constraints[end]'] = $readonlys['pe_constraints[milestone]'] = true; |
---|
381 | } |
---|
382 | $GLOBALS['phpgw_info']['flags']['app_header'] = lang('projectmanager') . ' - ' . |
---|
383 | ($this->data['pm_id'] ? ($view ? lang('View project-elements') : lang('Edit project-elements')) : lang('Add project-elements')); |
---|
384 | $this->tpl->read('projectmanager.elements.edit'); |
---|
385 | $this->tpl->exec('projectmanager.uiprojectelements.edit',$content,$sel_options,$readonlys,$preserv,2); |
---|
386 | } |
---|
387 | |
---|
388 | /** |
---|
389 | * query projects for nextmatch in the projects-list |
---|
390 | * |
---|
391 | * reimplemented from so_sql to disable action-buttons based on the acl and make some modification on the data |
---|
392 | * |
---|
393 | * @param array &$query_in |
---|
394 | * @param array &$rows returned rows/cups |
---|
395 | * @param array &$readonlys eg. to disable buttons based on acl |
---|
396 | */ |
---|
397 | function get_rows(&$query_in,&$rows,&$readonlys) |
---|
398 | { |
---|
399 | $GLOBALS['phpgw']->session->appsession('projectelements_list','projectmanager',$query=$query_in); |
---|
400 | |
---|
401 | if ($this->status_filter[$query['filter']]) |
---|
402 | { |
---|
403 | $query['col_filter']['pe_status'] = $this->status_filter[$query['filter']]; |
---|
404 | } |
---|
405 | else |
---|
406 | { |
---|
407 | unset($query['col_filter']['pe_status']); |
---|
408 | } |
---|
409 | if ($query['cat_id']) |
---|
410 | { |
---|
411 | $query['col_filter']['cat_id'] = $query['cat_id']; |
---|
412 | $query_in['link_add']['extra'] = array('cat_id' => $query['cat_id']); |
---|
413 | } |
---|
414 | else |
---|
415 | { |
---|
416 | unset($query['col_filter']['cat_id']); |
---|
417 | unset($query_in['link_add']['extra']); |
---|
418 | } |
---|
419 | if (!$query['col_filter']['pe_resources']) |
---|
420 | { |
---|
421 | unset($query['col_filter']['pe_resources']); |
---|
422 | } |
---|
423 | if ($query['filter2'] & 2) // show sub-elements (elements of sub-projects) |
---|
424 | { |
---|
425 | $query['col_filter']['pm_id'] = $this->project->children($this->pm_id,array($this->pm_id)); |
---|
426 | if (count($query['col_filter']['pm_id']) <= 1) $query['col_filter']['pm_id'] = $this->pm_id; |
---|
427 | // dont show the sub-projects |
---|
428 | $query['col_filter'][] = "link_app1!='projectmanager'"; |
---|
429 | } |
---|
430 | // cumulate eg. timesheets in also included infologs |
---|
431 | $query['col_filter']['cumulate'] = !($query['filter2'] & 4); |
---|
432 | $total = parent::get_rows($query,$rows,$readonlys,true); |
---|
433 | unset($query['col_filter']['cumulate']); |
---|
434 | |
---|
435 | // adding the project itself always as first line |
---|
436 | $self = $this->update('projectmanager',$this->pm_id); |
---|
437 | $self['pe_app'] = 'projectmanager'; |
---|
438 | $self['pe_app_id'] = $this->pm_id; |
---|
439 | $self['pe_icon'] = 'projectmanager/navbar'; |
---|
440 | $self['pe_modified'] = $this->project->data['pm_modified']; |
---|
441 | $self['pe_modifier'] = $this->project->data['pm_modifier']; |
---|
442 | $rows = array_merge(array($self),$rows); |
---|
443 | |
---|
444 | $readonlys = array(); |
---|
445 | foreach($rows as $n => $val) |
---|
446 | { |
---|
447 | $row =& $rows[$n]; |
---|
448 | if ($n && !$this->check_acl(PHPGW_ACL_EDIT,$row)) |
---|
449 | { |
---|
450 | $readonlys["edit[$row[pe_id]]"] = true; |
---|
451 | } |
---|
452 | if ($n && !$this->check_acl(PHPGW_ACL_DELETE,$row)) |
---|
453 | { |
---|
454 | $readonlys["delete[$row[pe_id]]"] = true; |
---|
455 | } |
---|
456 | if (!$n) |
---|
457 | { |
---|
458 | // no link for own project |
---|
459 | if (!$this->project->check_acl(PHPGW_ACL_EDIT,$this->project->data)) |
---|
460 | { |
---|
461 | $readonlys['edit'] = true; |
---|
462 | } |
---|
463 | } |
---|
464 | else |
---|
465 | { |
---|
466 | $row['link'] = array( |
---|
467 | 'app' => $row['pe_app'], |
---|
468 | 'id' => $row['pe_app_id'], |
---|
469 | 'title'=> $row['pe_title'], |
---|
470 | 'help' => $row['pe_app'] == 'projectmanager' ? lang("Select this project and show it's elements") : |
---|
471 | lang('View this element in %1',lang($row['pe_app'])), |
---|
472 | ); |
---|
473 | } |
---|
474 | if (!($query['filter2']&1)) unset($row['pe_details']); |
---|
475 | |
---|
476 | // add project-title for elements from sub-projects |
---|
477 | if (($query['filter2']&2) && $row['pm_id'] != $this->pm_id) |
---|
478 | { |
---|
479 | $row['pm_title'] = $this->project->link_title($row['pm_id']); |
---|
480 | $row['pm_link'] = array( |
---|
481 | 'app' => 'projectmanager', |
---|
482 | 'id' => $row['pm_id'], |
---|
483 | 'title'=> $this->project->link_title($row['pm_id']), |
---|
484 | 'help' => lang("Select this project and show it's elements"), |
---|
485 | ); |
---|
486 | } |
---|
487 | $row['pe_completion_icon'] = $row['pe_completion'] == 100 ? 'done' : $row['pe_completion']; |
---|
488 | |
---|
489 | $custom_app_icons[$row['pe_app']][] = $row['pe_app_id']; |
---|
490 | } |
---|
491 | if ($GLOBALS['phpgw_info']['user']['preferences']['projectmanager']['show_custom_app_icons']) |
---|
492 | { |
---|
493 | $custom_app_icons['location'] = 'pm_custom_app_icons'; |
---|
494 | $custom_app_icons = $GLOBALS['phpgw']->hooks->process($custom_app_icons); |
---|
495 | unset($row); // it's used as reference before !!! |
---|
496 | foreach($rows as $n => $row) |
---|
497 | { |
---|
498 | if (isset($custom_app_icons[$row['pe_app']][$row['pe_app_id']])) |
---|
499 | { |
---|
500 | $rows[$n]['pe_completion_icon'] = $custom_app_icons[$row['pe_app']][$row['pe_app_id']]; |
---|
501 | } |
---|
502 | } |
---|
503 | } |
---|
504 | if (!$this->project->check_acl(PHPGW_ACL_BUDGET)) |
---|
505 | { |
---|
506 | $rows['no_pe_used_budget_pe_planned_budget'] = true; |
---|
507 | } |
---|
508 | if ($this->project->data['pm_accounting_type'] == 'status') |
---|
509 | { |
---|
510 | $rows['no_pe_used_time_pe_planned_time'] = true; |
---|
511 | } |
---|
512 | // disable time & budget columns if pm is configures for status or status and time only |
---|
513 | if ($this->config['accounting_types'] == 'status') |
---|
514 | { |
---|
515 | $rows['no_pm_used_time_pm_planned_time'] = true; |
---|
516 | $rows['no_pm_used_budget_pm_planned_budget'] = true; |
---|
517 | $query_in['options-selectcols']['pm_used_time'] = $query_in['options-selectcols']['pm_planned_time'] = false; |
---|
518 | $query_in['options-selectcols']['pm_used_budget'] = $query_in['options-selectcols']['pm_planned_budget'] = false; |
---|
519 | } |
---|
520 | if ($this->config['accounting_types'] == 'status,times') |
---|
521 | { |
---|
522 | $rows['no_pm_used_budget_pm_planned_budget'] = true; |
---|
523 | $query_in['options-selectcols']['pm_used_budget'] = $query_in['options-selectcols']['pm_planned_budget'] = false; |
---|
524 | } |
---|
525 | $rows['duration_format'] = ','.$this->config['duration_format'].',,1'; |
---|
526 | if ($query['cat_id']) $rows['no_cat_id'] = true; |
---|
527 | // calculate the filter-specific summary if we have a filter, beside the default pe_status=used=array(new,regular) |
---|
528 | if (array_diff(array_keys($query['col_filter']),array(0,'pe_status','pm_id')) || !is_array($query['col_filter']['pe_status'])) |
---|
529 | { |
---|
530 | $rows += $this->summary(null,$query['col_filter']); |
---|
531 | } |
---|
532 | if ((int)$this->debug >= 2 || $this->debug == 'get_rows') |
---|
533 | { |
---|
534 | $this->debug_message("uiprojectelements::get_rows(".print_r($query,true).") total=$total, rows =".print_r($rows,true)."readonlys=".print_r($readonlys,true)); |
---|
535 | } |
---|
536 | return $total; |
---|
537 | } |
---|
538 | |
---|
539 | /** |
---|
540 | * List existing projects-elements |
---|
541 | * |
---|
542 | * @param array $content=null |
---|
543 | * @param string $msg='' |
---|
544 | */ |
---|
545 | function index($content=null,$msg='') |
---|
546 | { |
---|
547 | if ((int) $this->debug >= 1 || $this->debug == 'index') $this->debug_message("uiprojectelements::index(".print_r($content,true).",$msg)"); |
---|
548 | |
---|
549 | // store the current project (only for index, as popups may be called by other parent-projects) |
---|
550 | $GLOBALS['phpgw']->session->appsession('pm_id','projectmanager',$this->project->data['pm_id']); |
---|
551 | |
---|
552 | if ($_GET['msg']) $msg = $_GET['msg']; |
---|
553 | |
---|
554 | if ($content['nm']['rows']['edit']) |
---|
555 | { |
---|
556 | $this->tpl->location(array( |
---|
557 | 'menuaction' => 'projectmanager.uiprojectmanager.edit', |
---|
558 | 'pm_id' => $this->pm_id, |
---|
559 | )); |
---|
560 | } |
---|
561 | elseif ($content['sync_all'] && $this->project->check_acl(PHPGW_ACL_ADD)) |
---|
562 | { |
---|
563 | $msg = lang('%1 element(s) updated',$this->sync_all()); |
---|
564 | } |
---|
565 | elseif((int) $_GET['delete'] || $content['nm']['rows']['delete']) |
---|
566 | { |
---|
567 | if ($content['nm']['rows']['delete']) |
---|
568 | { |
---|
569 | list($pe_id) = each($content['nm']['rows']['delete']); |
---|
570 | } |
---|
571 | else |
---|
572 | { |
---|
573 | $pe_id = (int) $_GET['delete']; |
---|
574 | } |
---|
575 | if ($this->read($pe_id) && !$this->check_acl(PHPGW_ACL_DELETE)) |
---|
576 | { |
---|
577 | $msg = lang('Permission denied !!!'); |
---|
578 | } |
---|
579 | else |
---|
580 | { |
---|
581 | $msg = $this->delete($pe_id) ? lang('Project-Element deleted') : |
---|
582 | lang('Error: deleting project-element !!!'); |
---|
583 | } |
---|
584 | } |
---|
585 | $content = array( |
---|
586 | 'nm' => $GLOBALS['phpgw']->session->appsession('projectelements_list','projectmanager'), |
---|
587 | 'msg' => $msg, |
---|
588 | ); |
---|
589 | if (!is_array($content['nm'])) |
---|
590 | { |
---|
591 | $content['nm'] = array( |
---|
592 | 'get_rows' => 'projectmanager.uiprojectelements.get_rows', |
---|
593 | 'filter' => 'used',// I initial value for the filter |
---|
594 | 'filter_label' => lang('Filter'),// I label for filter (optional) |
---|
595 | 'options-filter' => $this->status_labels, |
---|
596 | 'filter_no_lang' => True,// I set no_lang for filter (=dont translate the options) |
---|
597 | 'options-filter2' => array( |
---|
598 | 0 => 'No details', |
---|
599 | 1 => 'Details', |
---|
600 | 2 => 'Subelements', |
---|
601 | 3 => 'Details of subelements', |
---|
602 | 4 => 'Cumulated elements too', |
---|
603 | 5 => 'Details of cumulated', |
---|
604 | ), |
---|
605 | 'col_filter' => array('pe_resources' => 0), // default value, to suppress loop |
---|
606 | 'order' => 'pe_modified',// IO name of the column to sort after (optional for the sortheaders) |
---|
607 | 'sort' => 'DESC',// IO direction of the sort: 'ASC' or 'DESC' |
---|
608 | 'default_cols' => '!cat_id', |
---|
609 | ); |
---|
610 | } |
---|
611 | // add "buttons" only with add-rights |
---|
612 | if ($this->project->check_acl(PHPGW_ACL_ADD)) |
---|
613 | { |
---|
614 | $content['nm']['header_right'] = 'projectmanager.elements.list.add'; |
---|
615 | $content['nm']['header_left'] = 'projectmanager.elements.list.add-new'; |
---|
616 | } |
---|
617 | else |
---|
618 | { |
---|
619 | unset($content['nm']['header_right']); |
---|
620 | unset($content['nm']['header_left']); |
---|
621 | $readonlys['sync_all'] = true; |
---|
622 | } |
---|
623 | $content['nm']['link_to'] = array( |
---|
624 | 'to_id' => $this->pm_id, |
---|
625 | 'to_app' => 'projectmanager', |
---|
626 | 'no_files' => true, |
---|
627 | 'search_label' => 'Add existing', |
---|
628 | 'link_label' => 'Add', |
---|
629 | ); |
---|
630 | $content['nm']['link_add'] = array( |
---|
631 | 'to_id' => $this->pm_id, |
---|
632 | 'to_app' => 'projectmanager', |
---|
633 | 'add_app' => 'infolog', |
---|
634 | ); |
---|
635 | // set id for automatic linking via quick add |
---|
636 | $GLOBALS['phpgw_info']['flags']['currentid'] = $this->pm_id; |
---|
637 | |
---|
638 | $GLOBALS['phpgw_info']['flags']['app_header'] = lang('projectmanager').' - '.lang('Elementlist') . |
---|
639 | ': ' . $this->project->data['pm_number'] . ': ' .$this->project->data['pm_title'] ; |
---|
640 | $this->tpl->read('projectmanager.elements.list'); |
---|
641 | $this->tpl->exec('projectmanager.uiprojectelements.index',$content,'',$readonlys); |
---|
642 | } |
---|
643 | } |
---|