Source for file project.class.php

Documentation is available at project.class.php


1 <?php
2 /**
3 * @category phpTimeSheet
4 * @package phpTimeSheet
5 * @version $Id: project.class.php,v 1.21 2003/09/25 16:07:26 cybot_tm Exp $
6 */
7
8 /**
9 * Class Project reflects access to tables project*
10 *
11 * @package phpTimeSheet
12 */
13 class Project
14 {
15 /**
16 * @var int Project ID, equal to unique DB-Index
17 * @access protected
18 * @since 2003-08-31
19 */
20 var $id = 0;
21
22 /**
23 * @var string Project Name
24 * @access protected
25 * @since 2003-08-31
26 */
27 var $name = '';
28
29 /**
30 * @var string Parent Project Name
31 * @access protected
32 * @since v1.19
33 */
34 var $parent_name = '';
35
36 /**
37 * @var int Project Status (open, closed, active, ..))
38 * @access protected
39 * @since 2003-08-31
40 */
41 var $status = 0;
42
43 /**
44 * @var int Project Hours taken so far
45 * @access protected
46 * @since 2003-08-31
47 */
48 var $aggregate_period = 0;
49
50 /**
51 * @var array Array of Workers with Hours in this Project (worker_id => worker_name)
52 * @access protected
53 * @since 2003-08-31
54 * @deprecated
55 */
56 var $workers;
57
58 /**
59 * @access protected
60 * @var int number of Workers in array $workers
61 * @since 2003-08-31
62 * @deprecated
63 */
64 var $numworkers = 0;
65
66 /**
67 * @var array Array of Workerhours in this Project (worker_id => worker_hours)
68 * @access protected
69 * @since 2003-08-31
70 * @deprecated
71 */
72 var $workerhours;
73
74 /**
75 * @var array Array of Sub-Projects
76 * @access protected
77 * @since 2003-08-31
78 */
79 var $sub_project = array();
80
81 /**
82 * @var int ID from Parent-Project
83 * @access protected
84 * @since 2003-08-31
85 */
86 var $parent_project_id = 0;
87
88 /**
89 * @var int ID of main worker for this project
90 * @access protected
91 * @since 2003-08-31
92 */
93 var $worker_id = 0;
94
95 /**
96 * @var object Worker
97 * @access public
98 * @since 2003-08-31
99 */
100 var $worker = null;
101
102 /**
103 * @var string project-type
104 * @access protected
105 * @since 2003-08-31
106 */
107 var $type = 'P';
108
109 /**
110 * @var string Project description
111 * @access protected
112 * @since 2003-08-31
113 */
114 var $description = '';
115
116 /**
117 * @param int project_id
118 */
119 function Project($project_id = 0)
120 {
121 $this->SetId($project_id);
122 if ( $this->GetId() == 0 )
123 {
124 return true;
125 }
126
127 $sql = '
128 SELECT `' . PTS_TBL_PROJECT . '`.*,
129 CONCAT_WS("-",`parent`.`name`,`' . PTS_TBL_PROJECT . '`.`name`) AS `fullname`,
130 `parent`.`name` AS `parent_name`,
131 `parent`.`type` AS `parent_projektart`
132 FROM `' . PTS_TBL_PROJECT . '`
133 LEFT JOIN `' . PTS_TBL_PROJECT . '` AS `parent`
134 ON `' . PTS_TBL_PROJECT . '`.`parent` = `parent`.`id`
135 WHERE `' . PTS_TBL_PROJECT . '`.`id` = ' . $this->GetId();
136
137 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
138
139 $row = mysql_fetch_assoc($result);
140
141 $this->SetName($row['name']);
142 $this->SetStatus($row['status']);
143 $this->ptyp = $row['ptyp'];
144 if ( $row['parent'] == 0 )
145 {
146 $this->SetParentProjectId($this->GetId());
147 }
148 else
149 {
150 $this->SetParentProjectId($row['parent']);
151 }
152 $this->SetDescription($row['description']);
153 $this->SetWorkerId($row['worker']);
154 $this->SetDate($row['date']);
155 $this->SetPriority($row['priority']);
156 $this->SetParentName($row['parent_name']);
157
158 $this->SetType($row['type']);
159 if ( $this->GetType() == 0 )
160 {
161 $this->SetType($row['type']);
162 }
163 }
164
165 function LoadWorker()
166 {
167 $this->worker = new Worker($this->GetWorkerId());
168 return $this->GetWorker();
169 }
170
171 function SetStatus($project_status)
172 {
173 $this->status = $project_status;
174 return true;
175 }
176
177 function SetWorkerId($worker_id)
178 {
179 $this->worker_id = (int) $worker_id;
180 return true;
181 }
182
183 function SetDescription($description)
184 {
185 $this->description = $description;
186 return true;
187 }
188
189 function SetDate($date)
190 {
191 $this->date = $date;
192 return true;
193 }
194
195 function SetPriority($priority)
196 {
197 $this->priority = (int) $priority;
198 return true;
199 }
200
201 function SetParentProjectId($parent_project_id)
202 {
203 $this->parent_project_id = (int) $parent_project_id;
204 return true;
205 }
206
207 function SetType($project_type)
208 {
209 $this->type = $project_type;
210 return true;
211 }
212
213 function SetName($project_name)
214 {
215 $this->name = $project_name;
216 return true;
217 }
218
219 function SetParentName($parent_name)
220 {
221 $this->parent_name = $parent_name;
222 return true;
223 }
224
225 function SetId($project_id)
226 {
227 $this->id = (int) $project_id;
228 return true;
229 }
230
231 function GetDate() { return $this->date; }
232 function GetDescription() { return $this->description; }
233 function GetFullName() { return $this->GetParentName() . ' - ' . $this->GetName(); }
234 function GetId() { return $this->id; }
235 function GetName() { return $this->name; }
236 function GetParentName() { return $this->parent_name; }
237 function GetParentProjectId() { return $this->parent_project_id; }
238 function GetPriority() { return $this->priority; }
239 function GetStatus() { return $this->status; }
240 function GetType() { return $this->type; }
241 function GetWorker() { return $this->worker; }
242 function GetWorkerId() { return $this->worker_id; }
243
244 function IsChildPid() { return ('P' == $this->type) ? (FALSE) : (TRUE); }
245
246 function UpdateStatus($status)
247 {
248 $this->SetStatus($status);
249
250 $sql = '
251 UPDATE `' . PTS_TBL_PROJECT . '`
252 SET `status` = "' . $this->GetStatus() . '"
253 WHERE `id` = ' . $this->GetId();
254 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
255
256 return true;
257 }
258
259 /* deprecated */
260 function get_dbindex() { return $this->GetId(); }
261 function get_name(){ return $this->GetName(); }
262 function get_status() { return $this->GetStatus(); }
263 function GetParentPidId() { return $this->GetParentProjectId(); }
264
265 function set_name($newname) { $this->SetName($newname); }
266 function set_status($newstatus) { $this->SetStatus($newstatus); }
267
268
269
270
271 /*Creates a detailed repprt form for the job and this worker.
272 * If worker_id == -1 all workers are shown. */
273 function detail_report($template, $worker_id){
274
275 if($worker_id == -1){
276 $sql = '
277 SELECT `' . PTS_TBL_PROJECT_TIME . '`.`day`,
278 `' . PTS_TBL_PROJECT_TIME . '`.`hours`,
279 `' . PTS_TBL_WORKER . '`.`name`,
280 `' . PTS_TBL_WORKER . '`.`id`,
281 `' . PTS_TBL_PROJECT . '`.`name`
282 FROM `' . PTS_TBL_PROJECT_TIME . '`
283 LEFT JOIN `' . PTS_TBL_WORKER . '`
284 ON `' . PTS_TBL_PROJECT_TIME . '`.`worker` = `' . PTS_TBL_WORKER . '`.`id`
285 LEFT JOIN `' . PTS_TBL_PROJECT . '`
286 ON `' . PTS_TBL_PROJECT_TIME . '`.`subpid` = `' . PTS_TBL_PROJECT . '`.`id`
287 WHERE `' . PTS_TBL_PROJECT_TIME . '`.`pid` = ' . $this->id . '
288 ORDER BY `' . PTS_TBL_PROJECT_TIME . '`.`day`';
289
290 $mode = "allworkers";
291 }else{
292 $sql = '
293 SELECT `' . PTS_TBL_PROJECT_TIME . '`.`day`,
294 `' . PTS_TBL_PROJECT_TIME . '`.`hours`,
295 `' . PTS_TBL_WORKER . '`.`name`,
296 `' . PTS_TBL_WORKER . '`.`id`,
297 `' . PTS_TBL_PROJECT . '`.`name`
298 FROM `' . PTS_TBL_PROJECT_TIME . '`
299 LEFT JOIN `' . PTS_TBL_WORKER . '`
300 ON `' . PTS_TBL_PROJECT_TIME . '`.`worker` = `' . PTS_TBL_WORKER . '`.`id`
301 LEFT JOIN `' . PTS_TBL_PROJECT . '`
302 ON `' . PTS_TBL_PROJECT_TIME . '`.`subpid` = `' . PTS_TBL_PROJECT . '`.`id`
303 WHERE `' . PTS_TBL_PROJECT_TIME . '`.`pid` = ' . $this->id . '
304 AND `' . PTS_TBL_PROJECT_TIME . '`.`worker` = "' . $worker_id . '"
305 ORDER BY `' . PTS_TBL_PROJECT_TIME . '`.`day`';
306 }
307
308 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
309
310 $aggregate_period = 0;
311
312 while($row = mysql_fetch_array($result)){
313 $mydayarray[] = $row;
314 $aggregate_period += $row["hours"];
315 }
316
317 $pid_name = $this->name;
318 $pid_target = $this->id;
319 $pid_status = $this->status;
320
321 if($mode == "allworkers"){
322 $jstring = sprintf("Alle Projektbeteiligte");
323 }else{
324 $jstring = sprintf("Bearbeiter: %s <a href=\"report.php?pid_target=%d&report_pid=1&report_type=detail&worker_target=-1\">Alle Projektbeteiligte anzeigen</a>",
325 $myworker, $this->id);
326 }
327
328 include($template);
329 }
330
331 /*Creates the basic report form */
332 function report_form($template, $type){
333 global $password
334 $pid_target = $this->id;
335 $pid_name = $this->name;
336 $pid_status = $this->status;
337
338 $aggregate_period = $this->get_aggregate_period();
339 $pid_workers = $this->get_workers();
340 $numworkers = $this->numworkers;
341
342 if($numworkers > 0){
343 while(list($key, $val) = each($pid_workers)){
344 $thisworkerhours = $this->get_hours_for_worker($key);
345 $this->workerhours[$key] = $thisworkerhours;
346 }
347 }
348 $workerhours = $this->workerhours;
349
350 include($template);
351 }
352
353 /* gibt alle noch nicht gewählten noch verfügbaren teilleistungen für diese projekt */
354 function getAdditionalTeilleistungen() {
355
356 $sql = sprintf("
357 SELECT `" . PTS_TBL_TASK . "`.*
358 FROM `" . PTS_TBL_TASK . "`
359 LEFT JOIN `" . PTS_TBL_PROJECT . "`
360 ON `" . PTS_TBL_TASK . "`.`tname` = `" . PTS_TBL_PROJECT . "`.`pname`
361 AND `" . PTS_TBL_PROJECT . "`.`pparent` = " . $this->parent_project_id . "
362 WHERE IF ( `" . PTS_TBL_PROJECT . "`.`pindex`, 0, 1 )
363 AND FIND_IN_SET('" . $this->projektart . "', `" . PTS_TBL_TASK . "`.`projektart`) > 0
364 ORDER BY `" . PTS_TBL_TASK . "`.`tname` ASC ");
365
366 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
367 while($row = mysql_fetch_array($result))
368 $AdditionalTeilleistungen[$row['tid']] = $row['tname'];
369
370 return($AdditionalTeilleistungen);
371 }/*function list_teilleistungen()*/
372
373 /* Returns the details of hours on this job for each worker as array workerid,hours,day*/
374 function get_detail_hours_for_workers(){
375 if ( $this->type == 'P' ) {
376 $sql = sprintf("SELECT SUBSTRING_INDEX(SEC_TO_TIME(SUM(TIME_TO_SEC(`time`))), ':', 2) `hours`,`worker`,`day` FROM %s WHERE pid = %d ORDER BY `worker`, `day`",
377 PTS_TBL_PROJECT_TIME, $this->id);
378 }
379 elseif ( $this->type == 'C' ) {
380 $sql = sprintf("SELECT SUBSTRING_INDEX(SEC_TO_TIME(SUM(TIME_TO_SEC(`time`))), ':', 2) `hours`,`worker`,`day` FROM %s WHERE subpid = %d ORDER BY `worker`, `day`",
381 PTS_TBL_PROJECT_TIME, $this->id);
382 }
383 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
384
385 while ( $row = mysql_fetch_assoc($result) )
386 $hours[] = $row;
387
388 return $hours;
389 }
390
391 /* Returns the sum of hours on this job for each worker as array workerid,hours*/
392 function get_hours_for_workers(){
393 if ( $this->type == 'P' ) {
394 $sql = sprintf("SELECT SUBSTRING_INDEX(SEC_TO_TIME(SUM(TIME_TO_SEC(`time`))), ':', 2) AS `hours`,`worker` FROM `%s` WHERE `pid` = '%d' GROUP BY `worker`",
395 PTS_TBL_PROJECT_TIME, $this->id);
396 }
397 elseif ( $this->type == 'C' ) {
398 $sql = sprintf("SELECT SUBSTRING_INDEX(SEC_TO_TIME(SUM(TIME_TO_SEC(`time`))), ':', 2) AS `hours`,`worker` FROM `%s` WHERE `subpid` = '%d' GROUP BY `worker`",
399 PTS_TBL_PROJECT_TIME, $this->id);
400 }
401
402 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
403
404 while ( $row = mysql_fetch_assoc($result) )
405 $hours[] = $row;
406
407 return($hours);
408 }
409
410 /* Returns the sum of hours on this job for worker workerid*/
411 function get_hours_for_worker($workerid){
412 if ( $this->type == 'P' ) {
413 $sql = sprintf("SELECT SUBSTRING_INDEX(SEC_TO_TIME(SUM(TIME_TO_SEC(`time`))), ':', 2) FROM %s WHERE worker = %d AND pid = %d",
414 PTS_TBL_PROJECT_TIME, $workerid, $this->id);
415 }
416 elseif ( $this->type == 'C' ) {
417 $sql = sprintf("SELECT SUBSTRING_INDEX(SEC_TO_TIME(SUM(TIME_TO_SEC(`time`))), ':', 2) FROM %s WHERE worker = %d AND subpid = %d",
418 PTS_TBL_PROJECT_TIME, $workerid, $this->id);
419 }
420
421 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
422 $myhours = mysql_result($result, 0, 0);
423 return($myhours);
424 }
425
426 /* Returns the sum of hours on this job for subpid pindex*/
427 function GetHours()
428 {
429 $sql = '
430 SELECT SUBSTRING_INDEX(SEC_TO_TIME(SUM(TIME_TO_SEC(`time`))), ":", 2)
431 FROM `' . PTS_TBL_PROJECT_TIME . '`
432 WHERE `pid` = ' . $this->GetId();
433 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
434
435 $hours = mysql_result($result, 0, 0);
436 return $hours;
437 }
438
439 // Sebastian Mendel 2002-02-07 gibt ein array von arrays mit 'worker' für alle subpids zurück
440 function get_subpidworkers() {
441 $sql = '
442 SELECT `' . PTS_TBL_PROJECT . '`.`pindex`,
443 `' . PTS_TBL_WORKER . '`.`wname`,
444 `' . PTS_TBL_WORKER . '`.`windex`
445 FROM `' . PTS_TBL_PROJECT . '`
446 LEFT JOIN `' . PTS_TBL_WORKER . '`
447 USING(`windex`)
448 WHERE `' . PTS_TBL_PROJECT . '`.`pparent` = ' . $this->parent_project_id;
449 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
450 while ( $row = mysql_fetch_assoc($result) ) {
451 $pid[$row['pindex']]['wname'] = $row['wname'];
452 $pid[$row['pindex']]['worker_id'] = $row['windex'];
453 }
454 return $pid;
455 }
456
457 /* gibt Array mit allen Angestellten zur&uuml;ck, die an diesem Projekt arbeiten */
458 function get_workers(){
459 if ( $this->type == 'P' ) {
460 $sql = sprintf("SELECT DISTINCT worker, wname FROM %s, %s WHERE %s.worker = %s.windex AND %s.pid = %d ORDER BY wname",
461 PTS_TBL_PROJECT_TIME, PTS_TBL_WORKER, PTS_TBL_PROJECT_TIME, PTS_TBL_WORKER, PTS_TBL_PROJECT_TIME, $this->id);
462 }
463 elseif ( $this->type == 'C' ) {
464 $sql = sprintf("SELECT DISTINCT worker, wname FROM %s, %s WHERE %s.worker = %s.windex AND %s.subpid = %d ORDER BY wname",
465 PTS_TBL_PROJECT_TIME, PTS_TBL_WORKER, PTS_TBL_PROJECT_TIME, PTS_TBL_WORKER, PTS_TBL_PROJECT_TIME, $this->id);
466 } else return FALSE;
467
468 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
469
470 $this->numworkers = 0;
471 while($row = mysql_fetch_array($result)){
472 $myworkerid = $row["worker"];
473 $this->workers[$myworkerid] = $row["name"];
474 $this->numworkers++;
475 }
476 return($this->workers);
477 }
478
479 function GetCountWorker()
480 {
481 $this->get_workers;
482 return $this->numworkers;
483 }
484
485 /**
486 * loads all sub-projects and stores them in array $this->sub_project
487 *
488 * @return array
489 */
490 function LoadSubProject()
491 {
492 $sql = '
493 SELECT `id`
494 FROM `' . PTS_TBL_PROJECT . '`
495 WHERE `parent` = ' . $this->GetParentProjectId();
496 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
497
498 $this->sub_project = array();
499 while ( $row = mysql_fetch_array($result) )
500 {
501 $this->sub_project[$row['id']] = new Project($row['id']);
502 }
503 return $this->sub_project;
504 }
505
506 /* holt Gesamtstunden f&uuml;r dieses Projekt aus der DB */
507 function get_aggregate_period(){
508 $sql = sprintf("SELECT SUBSTRING_INDEX(SEC_TO_TIME(SUM(TIME_TO_SEC(`time`))), ':', 2) FROM %s WHERE subpid = %d",
509 PTS_TBL_PROJECT_TIME, $this->id);
510 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
511 $mytotal = mysql_result($result, 0, 0);
512 $this->aggregate_period = $mytotal;
513 return($mytotal);
514 }
515
516 /**
517 * Saves Object in Database
518 *
519 * @return bool success
520 */
521 function Save()
522 {
523 if ( $this->GetId() > 0 )
524 {
525 $sql = '
526 UPDATE `' . PTS_TBL_PROJECT . '`
527 SET `name` = "' . $this->GetName() . '",
528 `status` = "' . $this->GetStatus() . '",
529 `worker` = "' . $this->GetWorkerId() . '",
530 `date` = "' . $this->GetDate() . '",
531 `description` = "' . $this->GetDescription() . '",
532 `parent` = "' . $this->GetParentProjectId() . '",
533 `priority` = "' . $this->GetPriority() . '",
534 `type` = "' . $this->GetType() . '"
535 WHERE `id` = ' . $this->GetId();
536 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
537 }
538 else
539 {
540 $sql = '
541 INSERT INTO `' . PTS_TBL_PROJECT . '`
542 SET `name` = "' . $this->GetName() . '",
543 `status` = "' . $this->GetStatus() . '",
544 `worker` = "' . $this->GetWorkerId() . '",
545 `date` = "' . $this->GetDate() . '",
546 `description` = "' . $this->GetDescription() . '",
547 `parent` = "' . $this->GetParentProjectId() . '",
548 `priority` = "' . $this->GetPriority() . '",
549 `type` = "' . $this->GetType() . '"';
550 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
551 $this->SetId(mysql_insert_id());
552 }
553
554 return true;
555 }
556
557 function Delete()
558 {
559 if ( count($this->subpids) )
560 foreach ( $this->subpids as $subpid )
561 $subpid->delete();
562
563 $sql = sprintf("DELETE FROM %s WHERE pindex = %d",PTS_TBL_PROJECT, $this->id);
564 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
565
566 $sql = sprintf("DELETE FROM %s WHERE pid = %d",PTS_TBL_PROJECT_TIME, $this->id);
567 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
568 }
569
570 /*Creates a simple HTML form to edit the pid record in the
571 * database. The $template is an HTML template to control the overall
572 look of the form*/
573 function modify_form($template){
574 // global $password;
575 // global $pstatus_list;
576 // global $windex_list;// 2002-02-04 Sebastian Mendel
577 // global $teilleistungen_list;// 2002-02-04 Sebastian Mendel
578
579 $pstatus_list = list_pstatus();// 2002-02-04 Sebastian Mendel
580 $windex_list = list_workers();// 2002-02-04 Sebastian Mendel
581 $teilleistungen_list = $this->getAdditionalTeilleistungen();// 2002-02-04 Sebastian Mendel
582
583
584 $pid_target = $this->GetId();
585 $pid_name = $this->GetName();
586 $pstatus = $this->GetStatus();// 2002-02-04 Sebastian Mendel
587 $ptyp = $this->type;// 2002-02-04 Sebastian Mendel
588 $parent_project_id = $this->parent_project_id;
589 $pbeschreibung = $this->description;
590 $worker_id = $this->worker_id;
591 $pdate = $this->pdate;
592 $ppriority = $this->priority;
593
594 $aggregate_period = $this->get_aggregate_period();
595 $pid_workers = $this->get_workers();
596 $numworkers = $this->numworkers;
597
598 $subpids = $this->get_subpids();// 2002-02-04 Sebastian Mendel
599 $numsubpids = $this->numsubpids;// 2002-02-04 Sebastian Mendel
600 $subpid_workers = $this->get_subpidworkers();// 2002-02-04 Sebastian Mendel
601
602 $total_hours = '00:00';
603 if ( isset($_REQUEST['detailstundenansicht']) )
604 $workerhours = $this->get_detail_hours_for_workers();
605 else
606 $workerhours = $this->get_hours_for_workers();
607
608 // 2002-02-04 Sebastian Mendel stunden für teilleistungen
609 if($numsubpids > 0) {
610 while(list($key, $val) = each($subpids))
611 $this->subpidhours[$key] = $this->get_hours_for_pid($key);
612 }
613 $subpidhours = $this->subpidhours;
614
615 include($template);
616 }
617
618 /**
619 * Creates an array project-id => project-name from all Projects in Database and returns it
620 *
621 * @param bool $only_active Return only active Projects
622 * @return array project_id => project_name
623 * @static
624 * @todo name is confusing, there should be a better one
625 */
626 function GetProjectArray($only_active = true)
627 {
628 $sql = 'SELECT `id`, `name` FROM `' . PTS_TBL_PROJECT . '` WHERE `ptyp` = "P" ORDER BY `name` ASC';
629 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
630
631 $project_array = array();
632
633 while ( $row = mysql_fetch_assoc($result) )
634 {
635 $project_array[$row['id']] = $row['name'];
636 }
637
638 return $project_array;
639 }
640
641 /**
642 * Creates a Selectbox from all Projects in Database and returns the HTML-Code
643 *
644 * if $selected_project_id > (int) 0 then the Project with this ID is preselcted
645 * if $selected_project_id === (bool) true then the Project with ID == $this->id is selected
646 * else no pre-selected Project
647 *
648 * @param bool $only_active Return only active Projects
649 * @param mixed $selected_project_id preselected Project
650 * @return string HTML-Code for Selectbox with Projects
651 * @static
652 * @todo name is confusing, there should be a better one
653 */
654 function GetSelectBox($only_active = true, $selected_project_id = false)
655 {
656 $project_array = Project::GetProjectArray($only_active);
657
658 $selectbox = '<select name="project_id">';
659 foreach ( $project_array as $project_id => $project_name )
660 {
661 if ( $selected_project_id == $project_id )
662 {
663 $selected = ' selected="selected"';
664 }
665 else
666 {
667 $selected = '';
668 }
669 $selectbox .= '<option value="' . $project_id . '"' . $selected . '>' . $project_name . '</option>';
670 }
671 $selectbox .= '</select>';
672
673 return $selectbox;
674 }
675
676 /**
677 * Creates an array priority-id => priority-name from all priority in Database and returns it
678 *
679 * @return array priority_id => priority_name
680 * @static
681 */
682 function GetPriorityArray()
683 {
684 $sql = 'SELECT * FROM `' . PTS_TBL_PROJECT_PRIORITY . '` ORDER BY `name` ASC';
685 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
686
687 $priority_array = array();
688
689 while ( $row = mysql_fetch_assoc($result) )
690 {
691 $priority_array[$row['id']] = $row['name'];
692 }
693
694 return $priority_array;
695 }
696
697 /**
698 * Creates a Selectbox from all Prioritys in Database and returns the HTML-Code
699 *
700 * if $selected_priority_id > (int) 0 then the priority with this ID is preselcted
701 * if $selected_priority_id === (bool) true then the priority with ID == $this->id is selected
702 * else no pre-selected priority
703 *
704 * @param mixed $selected_priority_id preselected priority
705 * @return string HTML-Code for Selectbox with prioritys
706 * @static
707 */
708 function GetPrioritySelectBox($selected_priority_id = false)
709 {
710 $priority_array = Project::GetPriorityArray();
711
712 $selectbox = '<select name="priority_id">';
713 foreach ( $priority_array as $priority_id => $priority_name )
714 {
715 if ( $selected_priority_id == $priority_id )
716 {
717 $selected = ' selected="selected"';
718 }
719 else
720 {
721 $selected = '';
722 }
723 $selectbox .= '<option value="' . $priority_id . '"' . $selected . '>' . $priority_name . '</option>';
724 }
725 $selectbox .= '</select>';
726
727 return $selectbox;
728 }
729
730 /**
731 * Creates an array status-id => status-name from all status in Database and returns it
732 *
733 * @return array status_id => status_name
734 * @static
735 */
736 function GetStatusArray()
737 {
738 $sql = 'SELECT * FROM `' . PTS_TBL_PROJECT_STATUS . '` ORDER BY `name` ASC';
739 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
740
741 $status_array = array();
742
743 while ( $row = mysql_fetch_assoc($result) )
744 {
745 $status_array[$row['id']] = $row['name'];
746 }
747
748 return $status_array;
749 }
750
751 /**
752 * Creates a Selectbox from all status in Database and returns the HTML-Code
753 *
754 * if $selected_status_id > (int) 0 then the status with this ID is preselcted
755 * if $selected_status_id === (bool) true then the status with ID == $this->status is selected
756 * else no pre-selected status
757 *
758 * @param mixed $selected_status_id preselected status
759 * @return string HTML-Code for Selectbox with status
760 * @static
761 */
762 function GetStatusSelectBox($selected_status_id = false)
763 {
764 $status_array = Project::GetStatusArray();
765
766 $selectbox = '<select name="status_id">';
767 foreach ( $status_array as $status_id => $status_name )
768 {
769 if ( $selected_status_id == $status_id )
770 {
771 $selected = ' selected="selected"';
772 }
773 else
774 {
775 $selected = '';
776 }
777 $selectbox .= '<option value="' . $status_id . '"' . $selected . '>' . $status_name . '</option>';
778 }
779 $selectbox .= '</select>';
780
781 return $selectbox;
782 }
783
784 /**
785 * Creates an array status-id => status-name from all status in Database and returns it
786 *
787 * @return array status_id => status_name
788 * @static
789 */
790 function GetTypeArray()
791 {
792 $sql = 'SELECT * FROM `' . PTS_TBL_PROJECT_TYPE . '` ORDER BY `name` ASC';
793 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
794
795 $type_array = array();
796
797 while ( $row = mysql_fetch_assoc($result) )
798 {
799 $type_array[$row['id']] = $row['name'];
800 }
801
802 return $type_array;
803 }
804
805 /**
806 * Creates a Selectbox from all types in Database and returns the HTML-Code
807 *
808 * if $selected_type_id > (int) 0 then the type with this ID is preselcted
809 * if $selected_type_id === (bool) true then the type with ID == $this->type is selected
810 * else no pre-selected status
811 *
812 * @param mixed $selected_type_id preselected type
813 * @return string HTML-Code for Selectbox with types
814 * @static
815 */
816 function GetTypeSelectBox($selected_type_id = false)
817 {
818 $type_array = Project::GetTypeArray();
819
820 $selectbox = '<select name="type_id">';
821 foreach ( $type_array as $type_id => $type_name )
822 {
823 if ( $selected_type_id == $type_id )
824 {
825 $selected = ' selected="selected"';
826 }
827 else
828 {
829 $selected = '';
830 }
831 $selectbox .= '<option value="' . $type_id . '"' . $selected . '>' . $type_name . '</option>';
832 }
833 $selectbox .= '</select>';
834
835 return $selectbox;
836 }
837
838 /**
839 * Creates an array status-id => status-name from all status in Database and returns it
840 *
841 * @return array status_id => status_name
842 * @static
843 */
844 function GetTaskArray()
845 {
846 $sql = 'SELECT * FROM `' . PTS_TBL_TASK . '` ORDER BY `tname` ASC';
847 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
848
849 $task_array = array();
850
851 while ( $row = mysql_fetch_assoc($result) )
852 {
853 $task_array[$row['tid']] = $row['tname'];
854 }
855
856 return $task_array;
857 }
858
859 /**
860 * Creates a Selectbox from all task in Database and returns the HTML-Code
861 *
862 * if $selected_type_id > (int) 0 then the type with this ID is preselcted
863 * if $selected_type_id === (bool) true then the type with ID == $this->type is selected
864 * else no pre-selected status
865 *
866 * @param mixed $selected_type_id preselected type
867 * @return string HTML-Code for Selectbox with types
868 * @static
869 */
870 function GetTaskSelectBox($selected_task_id = false)
871 {
872 $task_array = Project::GetTaskArray();
873
874 $selectbox = '<select name="task_name">';
875 foreach ( $task_array as $task_id => $task_name )
876 {
877 if ( $selected_task_id == $task_id )
878 {
879 $selected = ' selected="selected"';
880 }
881 else
882 {
883 $selected = '';
884 }
885 $selectbox .= '<option value="' . $task_name . '"' . $selected . '>' . $task_name . '</option>';
886 }
887 $selectbox .= '</select>';
888
889 return $selectbox;
890 }
891
892 /**
893 * @todo viel!
894 */
895 function check_for_subpid_id ($subpid,$pid)
896 {
897 // falls es die teilleistung noch nicht gibt dann müssen wir sie erst anlegen
898 if ( intval($subpid) === 0 )
899 {
900 $sql = '
901 INSERT
902 INTO `pids`
903 SET `name` = "' . $subpid . '",
904 `status` = 1,
905 `ptyp` = "C",
906 `parent` = ' . $pid;
907 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
908
909 return mysql_insert_id();
910 }
911 else
912 {
913 return $subpid;
914 }
915 }
916
917 }
918 ?>

Documentation generated on Fri, 26 Sep 2003 15:39:53 +0200 by phpDocumentor 1.2.2