Source for file worker.class.php

Documentation is available at worker.class.php


1 <?php
2 /**
3 * @category phpTimeSheet
4 * @package phpTimeSheet
5 * @version $Id: worker.class.php,v 1.34 2003/09/25 16:07:26 cybot_tm Exp $
6 */
7
8 /**
9 *
10 */
11 require_once 'config.inc.php';
12 require_once 'function.inc.php';
13 require_once 'db.inc.php';
14
15 require_once 'company.class.php';
16 require_once 'date.class.php';
17 require_once 'time.class.php';
18
19 /**
20 * reflects acces to tables worker*
21 *
22 * @category phpTimeSheet
23 * @package phpTimeSheet
24 * @version $Id: worker.class.php,v 1.34 2003/09/25 16:07:26 cybot_tm Exp $
25 * @since 2003-08-31
26 */
27 class Worker
28 {
29 /**#@+
30 * @access protected
31 */
32
33 /**
34 * @var object freebie overtime per week
35 * @since 1.9
36 */
37 var $freebie_overtime = null;
38
39 /**
40 * @var string Login-Name
41 * @since 1.9
42 */
43 var $login_name;
44
45 /**
46 * @var string Surename
47 * @since 1.9
48 */
49 var $surename;
50
51 /**
52 * @var string Lastname
53 * @since 1.9
54 */
55 var $lastname;
56
57 /**
58 * @var string Login-Password
59 * @since 1.9
60 */
61 var $login_password;
62
63 /**
64 * @var int ID
65 * @since 1.9
66 */
67 var $id;
68
69 /**
70 * @var object Company
71 * @since 1.9
72 */
73 var $company;
74
75 /**
76 * @var string Encrypted Password
77 * @since 1.9
78 */
79 var $login_password_encrypted;
80
81 /**
82 * @var bool Admin
83 * @since 1.9
84 */
85 var $admin = false;
86
87 /**
88 * @var object time
89 * @since 1.9
90 */
91 var $wzeit;
92
93 /**
94 * @var object time workspace per day
95 * @since 1.9
96 */
97 var $workspace;
98
99 /**
100 * @var int Annual-Holidays
101 * @since 1.9
102 */
103 var $annual_holiday = 0;
104
105 /**
106 * @var object date Last update
107 * @since 1.9
108 */
109 var $updated = null;
110
111 /**
112 * @var int current project_id
113 * @since 1.9
114 */
115 var $current_project_id;
116
117 /**
118 * @var int current sub-project_id
119 * @since 1.9
120 */
121 var $current_subproject_id;
122
123 /**
124 * @var object Project current project
125 * @since 1.9
126 */
127 var $current_project = null;
128
129 /**
130 * @var object Project current sub_project
131 * @since 1.9
132 */
133 var $current_subproject = null;
134
135 /**
136 * @var array day => hours
137 * @since 1.9
138 */
139 var $DayHours = null;
140
141 /**
142 * @var bool Logedin
143 * @since 1.9
144 */
145 var $LogedIn = false;
146
147 /**
148 * @var int current Year for Year-View
149 * @since 1.9
150 */
151 var $current_year = null;
152
153 /**
154 * @var date current week for week-view
155 * @since 1.9
156 */
157 var $current_week = null;
158
159 /**
160 * @var date current Date for day-view
161 * @since 1.9
162 */
163 var $current_day = null;
164
165 /**
166 * @var date start of contract
167 * @since 1.9
168 */
169 var $contract_start = null;
170
171 /**
172 * @var date end of contract
173 * @since 1.9
174 */
175 var $contract_end = null;
176
177 /**
178 * @var array
179 * @since 1.9
180 */
181 var $lastworktime = null;
182
183 /**#@-*/
184
185 /**
186 * Constructor
187 * @param int worker_id
188 */
189 function Worker($worker_id = 0)
190 {
191 $this->SetCurrentYear();
192 $this->SetCurrentWeek();
193 $this->SetCurrentDay();
194
195 $this->SetId($worker_id);
196
197 if ( $this->GetId() === 0 )
198 {
199 return TRUE;
200 }
201
202 $where = 'WHERE `id` = ' . $this->GetId();
203 return $this->load_worker_by_query($where);
204 }
205
206 /**
207 * Sets the current week-date for the week-view, day must be object of type Date or a string
208 *
209 * @uses Date
210 * @param mixed date
211 * @return bool success
212 */
213 function SetCurrentWeek($date = null)
214 {
215 if ( is_object($date) && get_class($date) == 'date' )
216 {
217 $this->current_week = $date;
218 }
219 else
220 {
221 if ( $date === null )
222 {
223 $this->current_week = new date(time());
224 }
225 else
226 {
227 $this->current_week = new date($date);
228 }
229 }
230
231 $this->current_week->SetToStartOfWeek(PTS_WEEK_START);
232 return true;
233 }
234
235 /**
236 * Sets the current Day for the day-view, day must be object of type Date or a string
237 *
238 * @uses Date
239 * @param mixed date
240 * @return bool success
241 */
242 function SetCurrentDay($date = null)
243 {
244 if ( is_object($date) && get_class($date) == 'date' )
245 {
246 $this->current_day = $date;
247 }
248 else
249 {
250 if ( $date === null )
251 {
252 $this->current_day = new date(time());
253 }
254 else
255 {
256 $this->current_day = new date($date);
257 }
258 }
259
260 return true;
261 }
262
263 /**
264 * Sets the current year for the year-view, year must be an integer
265 *
266 * @param int year
267 * @return bool success
268 */
269 function SetCurrentYear($year = null)
270 {
271 if ( 1000 > $year || 3000 < $year )
272 {
273 $year = date('Y');
274 }
275
276 $this->current_year = $year;
277
278 if ( $this->GetCurrentYear() == $year )
279 {
280 return true;
281 }
282
283 return false;
284 }
285
286 function GetPidSelectBox($selected = null)
287 {
288 // get all pids/subpids
289 $sql = '
290 SELECT `subpids`.*,
291 `' . PTS_TBL_PROJECT . '`.`name` AS `parent_name`
292 FROM `' . PTS_TBL_PROJECT . '`
293 LEFT JOIN `' . PTS_TBL_PROJECT . '` AS `subpids`
294 ON `' . PTS_TBL_PROJECT . '`.`id` = `subpids`.`parent`
295 WHERE `' . PTS_TBL_PROJECT . '`.`ptyp` = "P"
296 ORDER BY `' . PTS_TBL_PROJECT . '`.`name` ASC,
297 `subpids`.`name` ASC';
298
299 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
300
301 while ( $row = mysql_fetch_assoc($result) )
302 {
303 $pids[$row['parent']]['subpid'][$row['id']] = $row['name'];
304 $pids[$row['parent']]['name'] = $row['parent_name'];
305 }
306
307 $script = '
308 <script language="javascript">
309 <!--
310 function chooseMake()
311 {
312 var arrProList;
313 var objProjects;
314 var objSubProjects;
315 var i;
316
317 objProjects = document.getElementById(\'selectbox_pid\');
318 objSubProjects = document.getElementById(\'selectbox_subpid\');
319 objSubProjects.selectedIndex = 0;
320 objSubProjects.options.length = 1;
321
322 arrProList = (arrProjects[objProjects.selectedIndex]).split(\';\');
323 for (i = 0; i < arrModelList.length; i++)
324 {
325 objSubProjects.options.length = i+2;
326 objSubProjects.options[i+1].value = (arrProList[i]).split(\',\')[0];
327 objSubProjects.options[i+1].text = (arrProList[i]).split(\',\')[1];
328 }
329 }
330
331 var arrProjects = new Array();
332 arrProjects[0] = \'0, bitte wählen sei erst ein Projekt\';
333 ';
334
335 $info = "<select id=\"selectbox_pid\" name=\"pid\" onChange=\"chooseMake();\">\n";
336 $info .= "<option value=\"0\">Bitte w&auml;hlen...</option>\n";
337
338 $array_pointer = 1;
339 $script_array = '';
340 foreach ( $pids as $pid => $pdata )
341 {
342 if ( count($pdata['subpid']) > 0 )
343 {
344 $script_array_ = '';
345 foreach ( $pdata['subpid'] as $pindex => $pname )
346 {
347 $script_array_ .= "$pindex,$pname;";
348 }
349 $script_array .= "arrModels[$array_pointer] = '" . substr($script_array_, 0, -1) . "';\n";
350 $array_pointer++;
351
352 if ($pid == $selected)
353 {
354 $info .= '<option value="' . $pid . '" selected="selected">' . $pdata['name'] . '</option>' . "\n";
355 }
356 else
357 {
358 $info .= '<option value="' . $pid . '">' . $pdata['name'] . '</option>' . "\n";
359 }
360 }
361 }
362
363 $script .= $script_array . "//--></script>";
364 $info .= "</select>\n";
365 $info .= "<select id=\"selectbox_subpid\" name=\"subpid\">\n";
366 $info .= "<option value=\"0\">Bitte w&auml;hlen...</option>\n";
367 $info .= "</select>\n";
368
369 $info .= $script;
370
371 return $info;
372 }
373
374 function SetPidTimeForDay($project_id, $time, $day)
375 {
376 if ( time_to_seconds($time) > 0 )
377 {
378 $sql = '
379 REPLACE `' . PTS_TBL_PROJECT_TIME . '`
380 SET `day` = "' . $day . '",
381 `worker` = ' . $this->GetID() . ',
382 `time` = "' . $time . '",
383 `company` = ' . $this->GetCompanyId() . ',
384 `subpid` = ' . $project_id;
385 }
386 else
387 {
388 $sql = '
389 DELETE
390 FROM `' . PTS_TBL_PROJECT_TIME . '`
391 WHERE `day` = "' . $day . '"
392 AND `worker` = ' . $this->GetID() . '
393 AND `subpid` = ' . $project_id . '
394 LIMIT 1';
395 }
396 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
397 return true;
398 }
399
400 function CanCome()
401 {
402 if ( $this->lastworktime['day'] < date('Y-m-d') )
403 {
404 return true;
405 }
406 else
407 {
408 return false;
409 }
410 }
411
412 function GetComeLink()
413 {
414 if ( $this->CanCome() )
415 {
416 return '<a href="' . $_SERVER['PHP_SELF'] . '?action=come">Kommen</a>';
417 }
418 else
419 {
420 return '';
421 }
422 }
423
424 function GetGoLink()
425 {
426 if ( $this->CanGo() )
427 {
428 return '<a href="' . $_SERVER['PHP_SELF'] . '?action=go">Gehen</a>';
429 }
430 else
431 {
432 return '';
433 }
434 }
435
436 function CanGo()
437 {
438 if ( $this->lastworktime['day'] == date('Y-m-d') && $this->lastworktime['go'] == '00:00:00' )
439 {
440 return true;
441 }
442 else
443 {
444 return false;
445 }
446 }
447
448 /**
449 *
450 * @uses Date
451 * @param object Date
452 * @param int worktype
453 * @return bool success
454 * @since v1.0
455 */
456 function UpdateWorkDayTypeForDay($day, $worktype)
457 {
458 if ( ! is_object($day) || ! get_class($day) == 'date' )
459 {
460 die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\nwrong Paramter 1, expected object of type Date");
461 }
462
463 $daytype = $this->GetDayTypeForDay($day);
464
465 $sql = '
466 REPLACE `' . PTS_TBL_WORKTIME . '`
467 SET `day` = "' . $day->Get() . '",
468 `worker` = ' . $this->GetId() . ',
469 `worktype` = ' . $worktype . ',
470 `daytype` = ' . $daytype . ',
471 `allowed` = "NO"';
472 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
473
474 $this->CalculateDataForDay($day);
475
476 return true;
477 }
478
479 /**
480 *
481 * @uses Date
482 * @uses Worker::UpdateWorkDayTypeForDay()
483 * @param object Date
484 * @param int worktype
485 * @return bool success
486 * @since v1.0
487 */
488 function UpdateWorkDayType($_days, $worktype)
489 {
490 $worktype = (int) $worktype;
491
492 if ( $worktype === PTS_WT_WORK )
493 {
494 $days_string = '';
495 foreach ($_days as $day)
496 {
497 $days_string .= '"' . $day->Get() . '",';
498 }
499 $days_string = substr($days_string, 0, -1);
500
501 $sql = '
502 DELETE FROM `' . PTS_TBL_WORKTIME . '` WHERE `worker` = ' . $this->GetId() . ' AND`day` IN (' . $days_string . ')';
503 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
504 }
505 else
506 {
507 foreach ($_days as $day)
508 {
509 $this->UpdateWorkDayTypeForDay($day, $worktype);
510 }
511 }
512
513
514 return true;
515 }
516
517 function GetAnnualHolidays($year = null)
518 {
519 if ( null == $year )
520 {
521 $year = date('Y');
522 }
523 else
524 {
525 $year = (int) $year;
526 }
527
528 $sql = '
529 SELECT `holidays`
530 FROM `' . PTS_TBL_CORRECTION . '`
531 WHERE YEAR(`day`) = ' . $year . '
532 AND `worker` = ' . $this->GetId() . '
533 LIMIT 1';
534 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
535
536 if ( mysql_num_rows($result) == 1 )
537 {
538 $holidays = mysql_result($result, 0, 0);
539 }
540 else
541 {
542 $holidays = $this->GetContractedAnnualHolidays();
543 }
544
545 return $holidays;
546 }
547
548 function LogIn($Username, $Password)
549 {
550 $where = 'WHERE `login_name` = "' . $Username . '" AND (`login_password` = SHA1("' . $Password . '") OR `login_password` = "")';
551
552 if ( true === $this->load_worker_by_query($where) )
553 {
554 $this->SetLogedIn(true);
555 return true;
556 }
557 else
558 {
559 $this->SetLogedIn(false);
560 return false;
561 }
562 }
563
564 function LogOut()
565 {
566 $this = new Worker();
567 return true;
568 }
569
570 /*Creates the basic report form*/
571 function report_form($template, $type, $job_id)
572 {
573
574 /*Collect statistics for this worker
575 * Jobs with hours, Total hours per job, Total Overall
576 * Total and per week*/
577
578
579 $myname = $this->name;
580 $id = $this->dbindex;
581 $total_hours = $this->get_total_hours();
582 $worker_pids = $this->get_pids();
583 $numpids = $this->numpids;
584
585 $employer = $this->empname;
586
587 if($numpids > 0){
588 while(list($key, $val) = each($worker_pids)){
589 $thispidhours = $this->get_hours_for_pid($key);
590 $this->pidhours[$key] = $thispidhours;
591 }
592 }
593
594 $pidhours = $this->pidhours;
595 include($template);
596
597 }
598
599 /*Creates the detailed report form for job job_id. If job_id == -1 all jobs are displayed */
600 function job_report($template, $job_id)
601 {
602
603 if($job_id == -1)
604 {
605 $sql = '
606 SELECT `' . PTS_TBL_PROJECT_TIME . '`.`day`,
607 `' . PTS_TBL_PROJECT_TIME . '`.`hours`,
608 `' . PTS_TBL_PROJECT . '`.`pname`,
609 `parent`.`pindex`,
610 `parent`.`pname` AS `parname`
611 FROM `' . PTS_TBL_PROJECT_TIME . '`
612 LEFT JOIN `' . PTS_TBL_PROJECT . '`
613 ON `' . PTS_TBL_PROJECT_TIME . '`.`subpid` = `' . PTS_TBL_PROJECT . '`.`pindex`
614 LEFT JOIN `' . PTS_TBL_PROJECT . '` AS `parent`
615 ON `' . PTS_TBL_PROJECT . '`.`pparent` = `parent`.`pindex`
616 WHERE `' . PTS_TBL_PROJECT_TIME . '`.`worker` = "' . $this->dbindex . '"
617 AND `' . PTS_TBL_PROJECT_TIME . '`.`worktype` = "0"
618 ORDER BY `' . PTS_TBL_PROJECT_TIME . '`.`day`';
619 $mode = "alljobs";
620 }
621 else
622 {
623 $sql = '
624 SELECT `' . PTS_TBL_PROJECT_TIME . '`.`day`,
625 `' . PTS_TBL_PROJECT_TIME . '`.`hours`,
626 `' . PTS_TBL_PROJECT . '`.`pname`,
627 `parent`.`pindex`,
628 `parent`.`pname` AS `parname`
629 FROM `' . PTS_TBL_PROJECT_TIME . '`
630 LEFT JOIN `' . PTS_TBL_PROJECT . '`
631 ON `' . PTS_TBL_PROJECT_TIME . '`.`subpid` = `' . PTS_TBL_PROJECT . '`.`pindex`
632 LEFT JOIN `' . PTS_TBL_PROJECT . '` AS `parent`
633 ON `' . PTS_TBL_PROJECT . '`.`pparent` = `parent`.`pindex`
634 WHERE `' . PTS_TBL_PROJECT_TIME . '`.`worker` = "' . $this->dbindex . '"
635 AND `' . PTS_TBL_PROJECT_TIME . '`.`pid` = ' . $job_id . '
636 AND `' . PTS_TBL_PROJECT_TIME . '`.`worktype` = "0"
637 ORDER BY `' . PTS_TBL_PROJECT_TIME . '`.`day`';
638 $mode = "onejobs";
639 }
640
641 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
642
643 $total_hours = 0;
644 while ($row = mysql_fetch_array($result))
645 {
646 $mydayarray[] = $row;
647 $total_hours += $row['hours'];
648 }
649 $name = $this->name;
650
651 if($mode == "alljobs")
652 {
653 $jstring = sprintf("Projektübersicht");
654 }
655 else
656 {
657 $jstring = sprintf("Projekt: %s <a href=\"report.php?worker_target=%d&report_worker=1&report_type=job&job_id=-1\">Alle Projekte anzeigen</a>",
658 $myjob, $this->dbindex);
659 }
660
661 $worker_target = $this->dbindex;
662 include($template);
663 }
664
665 /* Monatsübersicht wie bisher in EXCEL*/
666 function month_report($template, $month, $year)
667 {
668
669 //Daten holen
670
671 //Um wen geht's?
672 $name = $this->name;
673
674 //Wieviele Tage hat der anzuzeigende Monat?
675 $days_in_month = date("t", mktime(1,1,1,$month,1,$year));
676
677 //Daten aus der timetable holen für diesen Monat
678
679 //Projekte diesen Monat
680 $sqlp = sprintf("SELECT DISTINCT t.pid as id, p.pname as name, SUM(t.hours) as std FROM timetable as t, pids as p
681 WHERE t.pid = p.pindex
682 AND t.worker=%d AND t.day >= '%s' AND t.day <= '%s' GROUP BY p.pname ORDER BY p.pname",
683 $this->dbindex, $year."-".$month."-01", $year."-".$month."-".$days_in_month);
684 $presult = mysql_query($sqlp) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sqlp . "\n" . mysql_error());
685
686 while ($zeile = mysql_fetch_array($presult))
687 {
688 //entspricht den Zeilen bzw. der ersten Spalte
689 if ($zeile["id"] != 0)
690 {
691 $projekt[$zeile["id"]] = array("id"=>$zeile["id"], "Name"=>$zeile["name"], "Gesamt"=>$zeile["std"]);
692 }
693 else
694 {
695 $projekt["Tag"] = array("id"=>0, "Name"=>"Tag", "Gesamt"=>" ");
696 }
697 }
698
699 //Projektstunden zu den Projekten
700 $sqlh = sprintf("SELECT pid, dayofmonth(day) as tag, hours, worktype FROM timetable
701 WHERE (worker=%d OR (worker=0 AND pid=0)) AND day >= '%s' AND day <= '%s' ORDER BY day",
702 $this->dbindex, $year."-".$month."-01", $year."-".$month."-".$days_in_month);
703 $hresult = mysql_query($sqlh) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sqlh . "\n" . mysql_error());
704
705 while ($zeile = mysql_fetch_array($hresult))
706 {
707 //Stunden pro Projekt und Tag
708 if ($zeile["pid"] !=0)
709 {
710 $projekt[$zeile["pid"]][$zeile["tag"]] = $zeile["hours"];
711 }
712 else
713 {
714 switch ($zeile["worktype"])
715 {
716 case 1: $art = "UB "; break;
717 case 2: $art = "U "; break;
718 case 3: $art = "F "; break;
719 case 4: $art = "K "; break;
720 case 5: $art = "hU "; break;
721 case 6: $art = "hF "; break;
722 }
723 $projekt["Tag"][$zeile["tag"]] .= $art;
724 }
725 }
726
727 //Stunden pro Tag AND worktype = 0
728 $sqls = sprintf("SELECT dayofmonth(day) as tag, dayofweek(day) as wochentag, SUM(hours) as gesamt FROM timetable
729 WHERE worker=%d AND worktype = 0 AND day >= '%s' AND day <= '%s' GROUP BY day ORDER BY day",
730 $this->dbindex, $year."-".$month."-01", $year."-".$month."-".$days_in_month);
731 $sresult = mysql_query($sqls) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sqls . "\n" . mysql_error());
732
733 while ($zeile = mysql_fetch_array($sresult))
734 {
735 //Stunden pro Tag
736 $projekt["Gesamt"][$zeile["tag"]] = $zeile["gesamt"];
737
738 $soll += $this->sollzeit[$zeile['wochentag']-1]; //Sollstunden für diese Tage?
739 }
740
741
742 $letzterMonat = "<a href=\"report.php?report_worker=1&report_type=month&worker_target=".$this->
743 dbindex ."&month=".date("m",mktime(1,1,1,$month-1,1,$year))
744 ."&year=".date("Y",mktime(1,1,1,$month-1,1,$year))."\">letzter Monat</a>";
745
746 $naechsterMonat = "<a href=\"report.php?report_worker=1&report_type=month&worker_target=".$this->
747 dbindex ."&month=".date("m",mktime(1,1,1,$month+1,1,$year))
748 ."&year=".date("Y",mktime(1,1,1,$month+1,1,$year))."\">nächster Monat</a>";
749
750 include($template);
751 }
752
753 function CheckTimes()
754 {
755 $sql = '
756 SELECT *
757 FROM `' . PTS_TBL_WORKTIME . '`
758 WHERE `come` <> "00:00:00"
759 AND `go` = "00:00:00"
760 AND `day` < "' . date('Y-m-d') . '"
761 AND `worker` = ' . $this->GetId() . '
762 LIMIT 1';
763 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
764
765 if ( mysql_num_rows($result) > 0 )
766 {
767 $row = mysql_fetch_assoc($result);
768 $this->GetCorrectForm($row['day']);
769 }
770 }
771
772 /* sieht nach, ob der Angestellte heute schon im System angemeldet ist */
773 function schon_da()
774 {
775 if ( $this->lastworktime == null )
776 // arbeiter war noch NIE da
777 return array(1 => FALSE, 'Nachricht' => '');
778
779 if ( $this->lastworktime['day'] == date('Y-m-d') )
780 // worker war/ist heute schon da
781 return array(1 => TRUE, 'Nachricht' => '');
782
783 // Worker ist heute schon da
784 // return TRUE;
785
786 // überprüfen ob sich benutzer abgemeldet hatte
787 if ( $this->lastworktime['go'] == NULL || $this->lastworktime['go'] == '00:00:00' )
788 {
789 // worker hatte sich das letzte mal nicht abgemeldet
790 $error = "
791 Sie haben sich das letzte Mal nicht abgemeldet!<br />
792 Es wird zunächst 12:00 Uhr gespeichert.<br />
793 Bitte wenden Sie sich an Ihren Administrator.";
794
795 $sql = sprintf("UPDATE times SET go = '12:00:11' WHERE day = '%s' AND worker = %d",
796 $this->lastworktime['day'], $this->dbindex);
797 $update = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
798 return array(1 => FALSE, 'Nachricht' => $error);
799 }
800
801 // überprüfen ob die zeit korrekt ist
802 if ( $this->lastworktime['go'] == '12:00:11' )
803 {
804 // Zeit wurde auf 12:00:11 gesetzt, aber noch nicht geändert
805 $error = "Ihre Arbeitszeit am ".db_to_date($this->lastworktime['day'])." muss noch vom Administrator geändert werden!";
806 return array(1 => FALSE, 'Nachricht' => $error);
807 }
808
809 $timetest = time_test($this->dbindex,$this->lastworktime['day'],$this->pzeit);
810
811 if ( empty($timetest) )
812 {
813 // Zeiten sind ok
814 return array(1 => FALSE, 'Nachricht' => '');
815 }
816 else
817 {
818 // Zeiten sind nicht ok, Benutzer muß Tag korrigieren dürfen
819 $date = db_to_date($this->lastworktime['day']);
820 $error = "
821 DieanIhremletztenArbeitstag ($date) eingegebenenProjektstunden
822 (= Arbeitszeit - Pausenzeit".$this->pzeit." Min.) stimmennicht
823 mitIhrerArbeitszeitüberein ($timetest). BittekorrigierenSiedies";
824
825 $WEEK = get_week_start_day($this->lastworktime['day']);
826
827 $error .= sprintf("<a href=\"timesheet.php?worker_name=%s&WEEK=%s&edit_day=%s&mod_day=1\">HIER</a>!",
828 rawurlencode($worker_name), $WEEK, $this->lastworktime['day']);
829
830 return array(1 => FALSE, 'Nachricht' => $error);
831 }
832 }
833
834 /* Mitarbeiter schon abgemeldet */
835 function schon_weg()
836 {
837 if ( ! isset($this->lastworktime) )
838 // worker war noch NIE da
839 return FALSE;
840
841 if ( $this->lastworktime['day'] != date('Y-m-d') )
842 // worker ist heute noch nicht da
843 return FALSE;
844
845 if ( $this->lastworktime['go'] == '00:00:00' || $this->lastworktime['go'] == NULL )
846 // worker ist noch da
847 return FALSE;
848
849 // worker ist heute schon weg
850 return TRUE;
851 }
852
853 /**
854 * @return bool success
855 * @param string[optional] time
856 * @param string[optional] date
857 * @desc setzt die Kommen-Zeit für die angegebene Zeit und den angegebenen Tag,
858 * wird time und date nicht angegeben wir die akteulle Zeit und der Aktuelle Tag angenommen,
859 * Returns true on success, false otherwise
860 */
861 function come($time = null, $date = null)
862 {
863 if ( null === $time )
864 {
865 $time = date('H:i');
866 }
867 $time = new Time($time);
868
869 if ( null === $date )
870 {
871 $date = date('Y-m-d');
872 }
873 $date = new Date($date);
874
875 // update/insert come time
876 $sql = '
877 REPLACE `' . PTS_TBL_WORKTIME . '`
878 SET `day` = "' . $date->Get() . '",
879 `worker` = ' . $this->GetId() . ',
880 `come` = "' . $time->Get() . '"';
881
882 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
883
884 $this->load_last_work_day();
885
886 return true;
887 }
888
889 /**
890 *
891 * @uses Date
892 * @param object Date
893 * @return int worktype
894 */
895 function GetDayTypeForDay($day)
896 {
897 $day = new Date($day);
898 if ( ! is_object($day) || ! get_class($day) == 'date' || $day->IsNull() )
899 {
900 die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\nwrong Paramter 1, expected object of type Date");
901 }
902
903 // first check times table if there is already an entry for this day
904 $sql = '
905 SELECT `daytype`
906 FROM `' . PTS_TBL_WORKTIME . '`
907 WHERE `day` = "' . $day->Get() . '"
908 AND `worker` = ' . $this->GetId() . '
909 LIMIT 1';
910 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
911
912 if ( mysql_num_rows($result) == 1 )
913 {
914 // there is already an entry for this day
915 // so we have to check some things
916 $row = mysql_fetch_assoc($result);
917
918 if ( $row['daytype'] != 0 )
919 {
920 // daytype is set
921 return $row['daytype'];
922 }
923 }
924
925
926 // second check for public holidays und plant holidays
927 $sql = '
928 SELECT `daytype`
929 FROM `' . PTS_TBL_WORKTIME . '`
930 WHERE `worker` = 0
931 AND `day` = "' . $day->Get() . '"
932 LIMIT 1';
933 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
934
935 if ( mysql_num_rows($result) == 1 )
936 {
937 $row = mysql_fetch_assoc($result);
938 if ( $row['daytype'] == PTS_WT_PUBLIC_HOLIDAY )
939 {
940 return PTS_WT_PUBLIC_HOLIDAY;
941 }
942 else
943 {
944 $day_type = $row['daytype'];
945 }
946 }
947 else
948 {
949 $day_type = PTS_WT_WORK;
950 }
951
952 if ( $this->DayHours[$day->GetWeekDay()] == '00:00' )
953 {
954 // day is not a workday for this worker
955 $day_type = PTS_WT_FREE;
956 }
957 return $day_type;
958 }
959
960 /**
961 * @return bool success
962 * @param string[optional] day
963 * @desc aktualisert Datenabnk für angegeben tag,
964 * wird day nicht angegeben wird der aktuelle tag angenommen
965 */
966 function CalculateDataForDay($day = null)
967 {
968 if ( null === $day )
969 {
970 $day = date('Y-m-d');
971 }
972
973 $date = new Date($day);
974
975 // get data for day
976 $day_type = $this->GetDayTypeForDay($date->Get());
977 $work_type = $this->GetWorkTypeForDay($date->Get());
978 $workspace = $this->GetWorkspaceForDay($date->Get()) * 60;
979 $contracted_hours = $this->GetContractedHoursForDay($date->Get());
980
981 // lade eventuell schon vorhandene daten für mitarbeiter aus der times-tabelle
982 $sql = 'SELECT * FROM `' . PTS_TBL_WORKTIME . '` WHERE `worker` = ' . $this->GetID() . ' AND `day` = "' . $date->Get() . '" LIMIT 1';
983 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
984 $row = mysql_fetch_assoc($result);
985
986 /*
987 // if worker not at work but workday than day = flexday
988 if ( $row['come'] == '00:00:00' && $work_type == PTS_WT_WORK)
989 {
990 $work_type = PTS_WT_FLEXTIME;
991 }
992 */
993
994 // update day in time_table
995 $sql = '
996 REPLACE `' . PTS_TBL_WORKTIME . '`
997 SET `worker` = ' . $this->GetID() . ',
998 `day` = "' . $date->Get() . '",
999 `come` = "' . $row['come'] . '",
1000 `go` = "' . $row['go'] . '",
1001 `workspace` = SEC_TO_TIME(' . $workspace . '),
1002 `worktype` = ' . $work_type . ',
1003 `daytype` = ' . $day_type . ',
1004 `allowed` = "YES",
1005 `contracted_hours` = "' . $contracted_hours . '"';
1006 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1007
1008 // check for weekchange
1009 if ( $date->IsSunday() && $this->GetFreebieOvertime() > 0 )
1010 {
1011 // woche ist zu ende und der worker hat gratisüberstunden
1012 // wir rechnen die gratisüberstunden raus
1013 $over_time = $this->GetOverTimeForWeek($day);
1014 if ( $over_time > 0 )
1015 {
1016 if ( $over_time > $this->GetFreebieOvertime() )
1017 {
1018 $correct_over_time = $this->GetFreebieOvertime();
1019 }
1020 else
1021 {
1022 $correct_over_time = $over_time;
1023 }
1024
1025 $sql = '
1026 replace into `' . PTS_TBL_CORRECTION . '`
1027 set `worker` = ' . $this->GetId() . ',
1028 `day` = "' . $date->Get() . '",
1029 `overtime` = "-' . $correct_over_time . '",
1030 `reason` = "TURN_OF_THE_WEEK"';
1031 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1032
1033 }
1034 }
1035
1036 // check for yearchange
1037 if ( $date->IsNewYear() )
1038 {
1039 // neues jahr
1040 // jahresurlaub hinzufügen
1041 $sql = '
1042 replace into `' . PTS_TBL_CORRECTION . '`
1043 set `worker` = ' . $this->GetId() . ',
1044 `day` = "' . $date->Get() . '",
1045 `holidays` = ' . $this->GetAnnualHolidays($day) . ',
1046 `reason` = "TURN_OF_THE_YEAR"';
1047 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1048 }
1049 $this->UpdateUpdated($date->Get());
1050 }
1051
1052 function GetContractedAnnualHolidays()
1053 {
1054 return $this->annual_holiday;
1055 }
1056
1057 /**
1058 *
1059 * @uses Date
1060 * @param object date
1061 * @return bool success
1062 */
1063 function UpdateUpdated($day)
1064 {
1065 if ( null == $day )
1066 {
1067 // es wurde kein Datum angegeben, also nehmen wir das aktuelle
1068 $day = date('Y-m-d');
1069 }
1070 $day = new Date($day);
1071 if ( ! is_object($day) || ! get_class($day) == 'date' || $day->IsNull() )
1072 {
1073 die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\nwrong Paramter 1, expected object of type Date");
1074 }
1075
1076 // update day in time_table
1077 $sql = '
1078 UPDATE `' . PTS_TBL_WORKER . '`
1079 SET `updated` = "' . $day->Get() . '"
1080 WHERE `id` = "' . $this->GetId() . '"';
1081 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1082
1083 $this->SetUpdated($day);
1084 }
1085
1086 function GetOverTimeForWeek($day = null)
1087 {
1088 if ( null == $day )
1089 {
1090 // es wurde kein Datum angegeben, also nehmen wir das aktuelle
1091 $day = date('Y-m-d');
1092 }
1093
1094 if ( ! is_date($day) )
1095 {
1096 // Datums-Format ist ungültig
1097 die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . 'wrong Date-Format: "' . $day . '"');
1098 return false;
1099 }
1100
1101 // berechnung Überstunden:
1102 // Gehen-Zeit - Kommen-Zeit - Pausen-Zeit - SOLL-Stunden = Überstunden
1103 // Beispiel:
1104 // 17:15 - 7:55 - 0:15 - 8:30 = 0:35
1105 // 12:30 - 9:15 - 0:00 - 6:00 = -2:45
1106 $sql = '
1107 SELECT SEC_TO_TIME(SUM((TIME_TO_SEC(`go`) - TIME_TO_SEC(`come`) - TIME_TO_SEC(`workspace`)) - TIME_TO_SEC(`contracted_hours`))) AS `overtime`
1108 FROM `' . PTS_TBL_WORKTIME .'`
1109 WHERE YEARWEEK(`day`, 1) = YEARWEEK("' . $day . '", 1)
1110 AND `worker` = ' . $this->GetId() . '
1111 AND ( `come` = "00:00:00" OR `go` <> "00:00:00" )
1112 GROUP BY `worker`';
1113 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1114
1115 $overtime = mysql_result($result, 0, 0);
1116 return $overtime;
1117 }
1118
1119 function SetUpdated($day = null)
1120 {
1121 if ( null === $day )
1122 {
1123 // es wurde kein Datum angegeben, also nehmen wir das aktuelle
1124 $day = date('Y-m-d');
1125 }
1126 $day = new Date($day);
1127 if ( ! is_object($day) || ! get_class($day) == 'date' || $day->IsNull() )
1128 {
1129 die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\nwrong Paramter 1, expected object of type Date");
1130 }
1131
1132 $this->updated = $day;
1133 }
1134
1135 /**
1136 * returns time as string that is not projected for given day, if day is empty current date is taken
1137 *
1138 * @uses Date
1139 * @param object date
1140 * @return string time
1141 */
1142 function GetUnProjectedWorkTimeForDay($day = null)
1143 {
1144 if ( null === $day )
1145 {
1146 // es wurde kein Datum angegeben, also nehmen wir das aktuelle
1147 $day = date('Y-m-d');
1148 }
1149 $day = new Date($day);
1150 if ( ! is_object($day) || ! get_class($day) == 'date' || $day->IsNull() )
1151 {
1152 die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\nwrong Paramter 1, expected object of type Date");
1153 }
1154
1155 if ( $day->IsToday() && $this->CanGo() )
1156 {
1157 // its today
1158 // worker is at work and not gone
1159 // we need not projected time till now
1160 $sql = '
1161 SELECT SUBSTRING_INDEX(
1162 SEC_TO_TIME( TIME_TO_SEC("' . date('H:i') . '")
1163 - TIME_TO_SEC(`come`)
1164 - TIME_TO_SEC(`workspace`)
1165 - IFNULL( SUM(TIME_TO_SEC(`' . PTS_TBL_PROJECT_TIME . '`.`time`)), 0 )
1166 ), ":", 2) AS `worktime`
1167 FROM `' . PTS_TBL_WORKTIME . '`
1168 LEFT JOIN `' . PTS_TBL_PROJECT_TIME . '`
1169 ON `' . PTS_TBL_WORKTIME . '`.`worker` = `' . PTS_TBL_PROJECT_TIME . '`.`worker`
1170 AND `' . PTS_TBL_WORKTIME . '`.`day` = `' . PTS_TBL_PROJECT_TIME . '`.`day`
1171 WHERE `' . PTS_TBL_WORKTIME . '`.`worker` = ' . $this->GetId() . '
1172 AND `' . PTS_TBL_WORKTIME . '`.`day` = "' . $day->Get() . '"
1173 GROUP BY `' . PTS_TBL_WORKTIME . '`.`go`,
1174 `' . PTS_TBL_WORKTIME . '`.`come`,
1175 `' . PTS_TBL_WORKTIME . '`.`workspace`';
1176 }
1177 else
1178 {
1179 // normal day
1180 $sql = '
1181 SELECT SUBSTRING_INDEX(
1182 SEC_TO_TIME( TIME_TO_SEC(`go`)
1183 - TIME_TO_SEC(`come`)
1184 - TIME_TO_SEC(`workspace`)
1185 - IFNULL( SUM(TIME_TO_SEC(`' . PTS_TBL_PROJECT_TIME . '`.`time`)), 0 )
1186 ), ":", 2) AS `worktime`
1187 FROM `' . PTS_TBL_WORKTIME . '`
1188 LEFT JOIN `' . PTS_TBL_PROJECT_TIME . '`
1189 ON `' . PTS_TBL_WORKTIME . '`.`worker` = `' . PTS_TBL_PROJECT_TIME . '`.`worker`
1190 AND `' . PTS_TBL_WORKTIME . '`.`day` = `' . PTS_TBL_PROJECT_TIME . '`.`day`
1191 WHERE `' . PTS_TBL_WORKTIME . '`.`worker` = ' . $this->GetId() . '
1192 AND `' . PTS_TBL_WORKTIME . '`.`day` = "' . $day->Get() . '"
1193 GROUP BY `' . PTS_TBL_WORKTIME . '`.`go`,
1194 `' . PTS_TBL_WORKTIME . '`.`come`,
1195 `' . PTS_TBL_WORKTIME . '`.`workspace`';
1196 }
1197 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1198
1199 if ( mysql_num_rows($result) < 1 )
1200 {
1201 return '00:00';
1202 }
1203
1204 return mysql_result($result, 0, 0);
1205 }
1206
1207 /**
1208 *
1209 * @uses Time
1210 * @uses Date
1211 */
1212 function GetWorkTimeForDay($day = null)
1213 {
1214 if ( null === $day )
1215 {
1216 $day = date('Y-m-d');
1217 }
1218
1219 $date = new Date($day);
1220
1221 if ( $date->IsToday() && $this->CanGo() )
1222 {
1223 $time = new Time(date('H:i'));
1224 $sql = '
1225 SELECT SEC_TO_TIME(' . $time->GetAsSeconds() . ' - TIME_TO_SEC(`come`) - TIME_TO_SEC(`workspace`)) AS `worktime`
1226 FROM `' . PTS_TBL_WORKTIME .'`
1227 WHERE `worker` = ' . $this->GetId() . '
1228 AND `day` = "' . $date->Get() . '"';
1229 }
1230 else
1231 {
1232 $sql = '
1233 SELECT SEC_TO_TIME(TIME_TO_SEC(`go`) - TIME_TO_SEC(`come`) - TIME_TO_SEC(`workspace`)) AS `worktime`
1234 FROM `' . PTS_TBL_WORKTIME .'`
1235 WHERE `worker` = ' . $this->GetId() . '
1236 AND `day` = "' . $date->Get() . '"';
1237 }
1238 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1239
1240 $time = new Time();
1241
1242 if ( mysql_num_rows($result) < 1 )
1243 {
1244 return $time;
1245 }
1246
1247 $time->Set(mysql_result($result, 0, 0));
1248 return $time;
1249 }
1250
1251 /**
1252 *
1253 * @uses Time
1254 * @uses Date
1255 */
1256 function GetWorkspaceForDay($day = null)
1257 {
1258 if ( null === $day )
1259 {
1260 $day = date('Y-m-d');
1261 }
1262
1263 $date = new Date($day);
1264
1265 if ( $date->IsFriday() )
1266 {
1267 // no workspace on fridays
1268 return 0;
1269 }
1270
1271 $worktime = $this->GetWorkTimeForDay($date);
1272
1273 if ( $worktime->GetAsSeconds() <= 15 * 60 )
1274 {
1275 return 0;
1276 }
1277
1278 return $this->GetWorkspace();
1279 }
1280
1281 /**
1282 * returns type of owkr for given day
1283 *
1284 * @param string[optional] day
1285 * @return int worktype
1286 */
1287 function GetWorkTypeForDay($day = null)
1288 {
1289 if ( null === $day )
1290 {
1291 $day = date('Y-m-d');
1292 }
1293 $day = new Date($day);
1294 if ( ! is_object($day) || ! get_class($day) == 'date' || $day->IsNull() )
1295 {
1296 die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\nwrong Paramter 1, expected object of type Date");
1297 }
1298
1299
1300 // first check times table if there is already an entry for this day
1301 $sql = '
1302 SELECT `worktype`,
1303 CASE WHEN `come` <> "00:00:00" THEN 1 ELSE 0 END AS `is_come`
1304 FROM `' . PTS_TBL_WORKTIME . '`
1305 WHERE `day` = "' . $day->Get() . '"
1306 AND `worker` = ' . $this->GetId() . '
1307 LIMIT 1';
1308 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1309
1310 if ( mysql_num_rows($result) == 1 )
1311 {
1312 // there is already an entry for this day
1313 // so we have to check some things
1314 $row = mysql_fetch_assoc($result);
1315
1316 // determine correct worktype independent from set wrktype
1317 if ( $row['worktype'] != 0 )
1318 {
1319 // worktype is set
1320 return $row['worktype'];
1321 }
1322 }
1323
1324
1325 // second check if this day is a workday for this worker
1326 if ( $this->DayHours[$day->GetWeekDay()] == '00:00' )
1327 {
1328 // day is not a workday for this worker
1329 return PTS_WT_FREE;
1330 }
1331
1332
1333 // third check for public holidays und plant holidays
1334 $sql = '
1335 SELECT `worktype`
1336 FROM `' . PTS_TBL_WORKTIME . '`
1337 WHERE `worker` = 0
1338 AND `day` = "' . $day->Get() . '"
1339 LIMIT 1';
1340 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1341
1342 if ( mysql_num_rows($result) == 1 )
1343 {
1344 $row = mysql_fetch_assoc($result);
1345 if ( $row['worktype'] == PTS_WT_PUBLIC_HOLIDAY )
1346 {
1347 // there is no worktype PTS_WT_PUBLIC_HOLIDAY, so we change it to FREDAY
1348 $row['worktype'] == PTS_WT_FREE;
1349 }
1350 return $row['worktype'];
1351 }
1352
1353
1354 // at least it must be a normal workday but the worker was not at work, so it is a flexday
1355 return PTS_WT_FLEXTIME;
1356 }
1357
1358 function GetContractedHoursForDay($day = null)
1359 {
1360 if ( null === $day )
1361 {
1362 $day = date('Y-m-d');
1363 }
1364 $day = new Date($day);
1365 if ( ! is_object($day) || ! get_class($day) == 'date' || $day->IsNull() )
1366 {
1367 die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\nwrong Paramter 1, expected object of type Date");
1368 }
1369
1370 if ( $day->IsGT($this->GetContractStart()) && ($day->IsLT($this->GetContractEnd()) || $this->GetContractEnd() == '0000-00-00' ))
1371 {
1372 return '00:00';
1373 }
1374
1375 $work_type = $this->GetWorkTypeForDay($day);
1376
1377 if ( $work_type == PTS_WT_HOLIDAY || $work_type == PTS_WT_PUBLIC_HOLIDAY || $work_type == PTS_WT_SICK || $work_type == PTS_WT_FREE || $work_type == PTS_WT_HOLIDAY_HALF )
1378 {
1379 // day is public holiday or plant holiday or sickday
1380 return '00:00';
1381 }
1382 elseif ( $work_type == PTS_WT_HOLIDAY_HALF )
1383 {
1384 // day is half public holiday or half plant holiday
1385 return seconds_to_time(time_to_seconds($this->DayHours[$day->GetWeekDay()]) * 0.5);
1386 }
1387
1388 // at least its a normal workday
1389 // calculate weekday from $day
1390 return $this->DayHours[$day->GetWeekDay()];
1391 }
1392
1393 /**
1394 * @return bool success
1395 * @desc Checks and calculates data for given date with current data from worker
1396 * f.e. sets contracted hours for this day from cuurent settings in worker or workspace
1397 */
1398 function CalculateData()
1399 {
1400 if ( date('Y-m-d') <= $this->GetUpdated() )
1401 {
1402 // Datenstand bereits aktuell
1403 return true;
1404 }
1405
1406 // wir gehen jetzt _jeden_ tag seit dem letzten update einzeln durch
1407 // bis wir bei heute sind
1408 while ( $this->GetUpdated() < date('Y-m-d', time() - ONE_DAY) )
1409 {
1410 // wir addieren etwas mehr ( eine stunde ) als nur einen tag nach oben, weil ansonsten manchmal es nicht ausreicht um ein tag weiter zu gehen
1411 // 2002-10-27 = date('Y-m-d', strtotime('2002-10-27') + ONE_DAY ) // ONE_DAY = 24 * 60 * 60 * 1(sekunde) BUG??!!
1412 $day = date('Y-m-d', strtotime($this->GetUpdated()) + ONE_DAY + ONE_HOUR);
1413 $this->CalculateDataForDay($day);
1414 }
1415 }
1416
1417 function UpdateCurrentSubProjectId($subproject_id)
1418 {
1419 $this->SetCurrentSubProjectId($subproject_id);
1420
1421 $sql = '
1422 UPDATE `' . PTS_TBL_WORKER . '`
1423 SET `current_subpid` = "' . $this->GetCurrentSubProjectId() . '"
1424 WHERE `id` = "' . $this->GetId() . '"';
1425 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1426
1427 return true;
1428 }
1429
1430 function UpdateCurrentProjectId($project_id)
1431 {
1432 $this->SetCurrentProjectId($project_id);
1433
1434 $sql = '
1435 UPDATE `' . PTS_TBL_WORKER . '`
1436 SET `current_pid` = "' . $this->GetCurrentProjectId() . '"
1437 WHERE `id` = "' . $this->GetId() . '"';
1438 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1439
1440 return true;
1441 }
1442
1443 /**
1444 * @return bool success
1445 * @param string[optional] time
1446 * @param string[optional] day
1447 * @desc Arbeitszeit beenden
1448 */
1449 function go($time = null, $day = null)
1450 {
1451 // überprüfe zeit und datum
1452 if ( null === $time )
1453 {
1454 $time = date('H:i');
1455 }
1456
1457 if ( null == $day )
1458 {
1459 $day = date('Y-m-d');
1460 }
1461
1462 if ( ! is_date($day) )
1463 {
1464 die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . 'wrong Date-Format: "' . $day . '"');
1465 return false;
1466 }
1467
1468 $time = date('H:i', strtotime($time));
1469
1470 if ( ! preg_match("/^[0-9]{1,2}:[0-9]{1,2}$/", $time) )
1471 {
1472 die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . 'wrong Time-Format: "' . $time . '"');
1473 return false;
1474 }
1475
1476 // save go-time
1477 $sql = '
1478 UPDATE `' . PTS_TBL_WORKTIME .'` SET `go` = "'. $time .'"
1479 WHERE `day` = "' . $day . '"
1480 AND `worker` = ' . $this->GetId();
1481 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1482 //echo $sql;
1483
1484 $this->CalculateDataForDay($day);
1485
1486 // setzt gesamte zeit automatisch auf voreingestelltes projekt
1487 $this->set_freetime_to_current_pid();
1488
1489 // 2003-02-21 Sebastian Mendel, aktulisiere letzten arbeitstag
1490 $this->load_last_work_day();
1491
1492 return true;
1493 }
1494
1495 // Sebastian Mendel 2002-02-06
1496 // setze gesamte zeit automatisch auf voreingestelltes projekt
1497 /*
1498 function set_freetime_to_current_pid()
1499 {
1500 if ( $this->GetCurrentSubPid() < 1 )
1501 {
1502 // no subpid selected, do nothing
1503 return true;
1504 }
1505
1506 $day = date('Y-m-d');
1507
1508 $sql = '
1509 SELECT COUNT(*)
1510 FROM `' . PTS_TBL_PROJECT_TIME . '`
1511 WHERE `day` = "' . $day . '"
1512 AND `worker` = ' . $this->GetId() . '
1513 AND `subpid` = ' . $this->GetCurrentSubPid() . '
1514 AND `company` = ' . $this->company->GetID();
1515 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1516
1517
1518 $worktime = $this->GetUnProjectedWorkTimeForDay();
1519
1520 echo $worktime;
1521 if ( $worktime !== '00:00' )
1522 {
1523 // mach ein update oder insert der stunden
1524 if ( mysql_result($result, 0, 0) == 1 )
1525 {
1526 $sql = '
1527 UPDATE `' . PTS_TBL_PROJECT_TIME . '`
1528 SET `time` = SEC_TO_TIME( TIME_TO_SEC(`time`) + TIME_TO_SEC("' . $worktime . '"))
1529 WHERE `day` = "' . $day . '"
1530 AND `worker` = ' . $this->GetId() . '
1531 AND `subpid` = ' . $this->GetCurrentSubPid() . '
1532 AND `company` = ' . $this->company->GetID();
1533 }
1534 else
1535 {
1536 $sql = '
1537 INSERT `' . PTS_TBL_PROJECT_TIME . '`
1538 SET `time` = "' . $worktime . '",
1539 `day` = "' . $day . '",
1540 `worker` = ' . $this->GetId() . ',
1541 `company` = ' . $this->company->GetID() . ',
1542 `subpid` = ' . $this->GetCurrentSubPid();
1543 }
1544 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1545 }
1546
1547 return TRUE;
1548 }
1549 */
1550
1551 /**
1552 * returns object Time with overtime till given date or now
1553 *
1554 * @param mixed day
1555 * @return object Time
1556 * @since v1.0
1557 */
1558 function GetOverTime($day = null)
1559 {
1560 if ( null === $day )
1561 {
1562 // es wurde kein Datum angegeben, also nehmen wir das aktuelle
1563 $day = new Date(time());
1564 }
1565 else
1566 {
1567 $new_day = $day;
1568 $day = new Date($new_day);
1569 }
1570
1571 // berechnung Überstunden:
1572 // Gehen-Zeit - Kommen-Zeit - Pausen-Zeit - SOLL-Stunden = Überstunden
1573 // Beispiel:
1574 // 17:15 - 7:55 - 0:15 - 8:30 = 0:35
1575 // 12:30 - 9:15 - 0:00 - 6:00 = -2:45
1576 $sql = '
1577 SELECT SUM((TIME_TO_SEC(`go`) - TIME_TO_SEC(`come`) - TIME_TO_SEC(`workspace`)) - TIME_TO_SEC(`contracted_hours`)) AS `overtime`
1578 FROM `' . PTS_TBL_WORKTIME . '`
1579 WHERE `day` <= "' . $day->Get() . '"
1580 AND `worker` = ' . $this->GetId();
1581 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1582
1583 $current_overtime = null;
1584 if ( mysql_num_rows($result) > 0 )
1585 {
1586 $current_overtime = mysql_result($result, 0, 0);
1587 }
1588
1589 if ( $current_overtime === null )
1590 {
1591 $current_overtime = 0;
1592 }
1593
1594 // get overtime from correction-table
1595 $sql = '
1596 SELECT SUBSTRING_INDEX(SEC_TO_TIME(' . $current_overtime . ' + sum(TIME_TO_SEC(`overtime`))), ":", 2)
1597 FROM `' . PTS_TBL_CORRECTION . '`
1598 WHERE `worker` = ' . $this->GetId() . '
1599 AND `day` <= "' . $day->Get() . '"';
1600 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1601
1602 if ( mysql_num_rows($result) > 0 )
1603 {
1604 $time = mysql_result($result, 0, 0);
1605 $corrected_overtime = new Time($time);
1606 }
1607 else
1608 {
1609 $corrected_overtime = new Time('00:00');
1610 }
1611
1612 return $corrected_overtime;
1613 }
1614
1615 /**
1616 * returns count of holidays for given or actual year
1617 *
1618 * @param int year
1619 * @return double holidays
1620 * @since v1.0
1621 */
1622 function GetTakenHolidays($year = null)
1623 {
1624 if ( null == $year )
1625 {
1626 // es wurde kein Datum angegeben, also nehmen wir das aktuelle
1627 $year = date('Y');
1628 }
1629 else
1630 {
1631 $year = (int) $year;
1632 }
1633
1634 $sql = '
1635 SELECT SUM(`' . PTS_TBL_DAYTYPE . '`.`x_soll`)
1636 FROM `' . PTS_TBL_WORKTIME . '`
1637 LEFT JOIN `' . PTS_TBL_DAYTYPE . '`
1638 ON `' . PTS_TBL_WORKTIME . '`.`daytype` = `' . PTS_TBL_DAYTYPE . '`.`id`
1639 WHERE `' . PTS_TBL_WORKTIME . '`.`worker` = ' . $this->GetId() . '
1640 AND `' . PTS_TBL_WORKTIME . '`.`worktype` = ' . PTS_WT_HOLIDAY . '
1641 AND YEAR(`day`) = "' . $year . '"';
1642 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1643
1644 $taken_holidays = (double) mysql_result($result, 0, 0);
1645
1646 return $taken_holidays;
1647 }
1648
1649 /**
1650 * returns remaining holidays till given date or now
1651 *
1652 * @param mixed date date-object, date-string or null for current
1653 * @return double holidays
1654 * @since v1.0
1655 */
1656 function GetRemainingHolidays($day = null)
1657 {
1658 if ( null === $day )
1659 {
1660 // es wurde kein Datum angegeben, also nehmen wir das aktuelle
1661 $day = new Date(time());
1662 }
1663 $day = new Date($day);
1664
1665 $taken_holidays = $this->GetTakenHolidays($day->GetYear());
1666
1667 // get data from correction-table
1668 $sql = '
1669 SELECT SUM(`holidays`)
1670 FROM `' . PTS_TBL_CORRECTION . '`
1671 WHERE `worker` = ' . $this->GetId() . '
1672 AND `day` <= "' . $day->Get() . '"';
1673 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1674
1675 $remaining_holidays = (double) mysql_result($result, 0, 0) - $taken_holidays;
1676 return $remaining_holidays;
1677 }
1678
1679 /**
1680 * returns sickdays for given or current year
1681 *
1682 * @param int year
1683 * @return double sickdays
1684 * @since v1.0
1685 */
1686 function GetSickDays($year = null)
1687 {
1688 if ( null == $year )
1689 {
1690 // es wurde kein Datum angegeben, also nehmen wir das aktuelle
1691 $year = date('Y');
1692 }
1693 else
1694 {
1695 $year = (int) $year;
1696 }
1697
1698 $sql = '
1699 SELECT COUNT(*)
1700 FROM `' . PTS_TBL_WORKTIME . '`
1701 WHERE `worker` = ' . $this->GetId() . '
1702 AND YEAR(`day`) = "' . $year . '"
1703 AND `worktype` = ' . PTS_WT_SICK;
1704 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1705
1706 $sick_days = (int) mysql_result($result, 0, 0);
1707
1708 return $sick_days;
1709 }
1710
1711 /*Returns total hours for this worker for a given job id*/
1712 function get_hours_for_pid($pidid){
1713 $sql = sprintf("SELECT SUM(TIME_TO_SEC(`time`) / 60 / 60) FROM %s WHERE worker = %d AND pid = %d",
1714 PTS_TBL_PROJECT_TIME, $this->dbindex, $pidid);
1715 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1716 $myhours = mysql_result($result, 0, 0);
1717 return($myhours);
1718 }
1719
1720
1721 /*Returns the total number of hours for this worker for all job ids*/
1722 function get_total_hours(){
1723
1724 $sql = sprintf("SELECT SUM(TIME_TO_SEC(`time`) / 60 / 60) FROM %s WHERE worker = %d",
1725 PTS_TBL_PROJECT_TIME, $this->dbindex);
1726 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1727
1728 $mytotal = mysql_result($result, 0, 0);
1729 $this->total = $mytotal;
1730 return($mytotal);
1731 }
1732
1733 /*Returns an array of Job names indexed by job id that this worker has hours for*/
1734 function get_pids(){
1735
1736 $sql = sprintf("SELECT DISTINCT pid, pname FROM %s, %s WHERE %s.pid = %s.pindex AND %s.worker = %d",
1737 PTS_TBL_PROJECT_TIME, PTS_TBL_PROJECT, PTS_TBL_PROJECT_TIME, PTS_TBL_PROJECT, PTS_TBL_PROJECT_TIME, $this->dbindex);
1738 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1739
1740 $this->numpids = 0;
1741 while($row = mysql_fetch_array($result)){
1742 $mypidid = $row["pid"];
1743 $this->pids[$mypidid] = $row["pname"];
1744 $this->numpids++;
1745 }
1746
1747 return($this->pids);
1748 }
1749
1750 /**
1751 * removes all DB-entrys for this Object
1752 *
1753 * @return bool success
1754 */
1755 function Delete()
1756 {
1757 $sql = 'DELETE FROM `' . PTS_TBL_WORKER . '` WHERE `id` = ' . $this->GetId();
1758 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1759
1760 $sql = 'DELETE FROM `' . PTS_TBL_PROJECT_TIME . '` WHERE `worker` = ' . $this->GetId();
1761 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1762
1763 return true;
1764 }
1765
1766 /**
1767 * Saves Object in DB
1768 * returns true on succes, otherwise false
1769 *
1770 * @return bool succes
1771 */
1772 function Update()
1773 {
1774 if ( $this->GetId() === 0 )
1775 {
1776 $sql = '
1777 INSERT
1778 INTO `' . PTS_TBL_WORKER . '`
1779 SET `login_name` = "' . $this->GetLoginName() . '",
1780 `login_password` = "' . $this->GetPasswordEncrypted() . '",
1781 `company` = ' . $this->Company->GetId() . ',
1782 `admin` = ' . $this->IsAdmin() . ',
1783 `contracted_hours` = ' . $this->GetWorkertype() . ',
1784 `workspace` = "' . $this->GetWorkSpace() . '",
1785 `annual_holiday` = ' . $this->GetContractedAnnualHolidays() . ',
1786 `freebie_overtime` = "' . $this->GetFreebieOverTime() . '",
1787 `updated` = "' . $this->GetUpdated() . '",
1788 `contract_start` = "' . $this->GetContractStart() . '",
1789 `contract_end` = "' . $this->GetContractEnd() . '",
1790 `surename` = "' . $this->GetSureName() . '",
1791 `lastname` = "' . $this->GetLastName() . '",
1792 `current_pid` = ' . $this->GetCurrentProjectId() . ',
1793 `current_subpid` = ' . $this->GetCurrentSubProjectId() . ',
1794 `description` = "' . $this->GetDescription() . '",
1795 `need_project` = ' . $this->GetNeedProject();
1796 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1797
1798 $this->SetId(mysql_insert_id());
1799 return $this->GetId();
1800 }
1801 else
1802 {
1803 $sql = '
1804 UPDATE `' . PTS_TBL_WORKER . '`
1805 SET `login_name` = "' . $this->GetLoginName() . '",
1806 `login_password` = "' . $this->GetPasswordEncrypted() . '",
1807 `company` = ' . $this->Company->GetId() . ',
1808 `admin` = ' . $this->IsAdmin() . ',
1809 `contracted_hours` = ' . $this->GetWorkertype() . ',
1810 `workspace` = "' . $this->GetWorkSpace() . '",
1811 `annual_holiday` = ' . $this->GetContractedAnnualHolidays() . ',
1812 `freebie_overtime` = "' . $this->GetFreebieOverTime() . '",
1813 `updated` = "' . $this->GetUpdated() . '",
1814 `contract_start` = "' . $this->GetContractStart() . '",
1815 `contract_end` = "' . $this->GetContractEnd() . '",
1816 `surename` = "' . $this->GetSureName() . '",
1817 `lastname` = "' . $this->GetLastName() . '",
1818 `current_pid` = ' . $this->GetCurrentProjectId() . ',
1819 `current_subpid` = ' . $this->GetCurrentSubProjectId() . ',
1820 `description` = "' . $this->GetDescription() . '",
1821 `need_project` = ' . $this->GetNeedProject() . '
1822 WHERE `id` = ' . $this->GetId();
1823 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1824 return true;
1825 }
1826 }
1827
1828 function modify_form($template)
1829 {
1830 global $password
1831 global $error
1832 global $message
1833
1834 $myname = $this->name;
1835 $id = $this->dbindex;
1836 $total_hours = $this->get_total_hours();
1837 $worker_pids = $this->get_pids();
1838 $numpids = $this->numpids;
1839
1840 $wzeit = $this->wzeit;
1841 $pzeit = $this->pzeit;
1842 $jurlaub= $this->jurlaub;
1843 $rurlaub = $this->rurlaub;
1844 $geschenk = $this->geschenk;
1845 $workertype = $this->workertype;
1846 $ueberstd = $this->ueberstd;
1847
1848 $sollzeittabelle = sollzeittabelle($workertype);
1849
1850 $employer = $this->empname;
1851 $adminflag = $this->can_admin;
1852
1853 if($numpids > 0){
1854 while(list($key, $val) = each($worker_pids)){
1855 $thispidhours = $this->get_hours_for_pid($key);
1856 $this->pidhours[$key] = $thispidhours;
1857 }
1858 }
1859
1860 $pidhours = $this->pidhours;
1861 $worker_list = list_workers(FALSE);
1862
1863 include($template);
1864 }/*function modify_form*/
1865
1866 function load_worker_by_query($where)
1867 {
1868 if ( ! stristr($where, 'where') )
1869 {
1870 return false;
1871 }
1872
1873 $sql = '
1874 SELECT `' . PTS_TBL_CONTRACTED_HOURS . '`.*,
1875 `' . PTS_TBL_WORKER . '`.*,
1876 SUBSTRING_INDEX(`' . PTS_TBL_WORKER . '`.`workspace`, ":", 2 ) AS `workspace`
1877 FROM `' . PTS_TBL_WORKER . '`
1878 LEFT JOIN `' . PTS_TBL_CONTRACTED_HOURS . '`
1879 ON `' . PTS_TBL_WORKER . '`.`contracted_hours` = `' . PTS_TBL_CONTRACTED_HOURS . '`.`id`
1880 ' . $where . '
1881 GROUP BY `' . PTS_TBL_WORKER . '`.`id`
1882 LIMIT 1';
1883
1884 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1885
1886 if ( mysql_num_rows($result) != 1 )
1887 {
1888 return false;
1889 }
1890
1891 $row = mysql_fetch_assoc($result);
1892
1893 $this->SetLoginName($row['login_name']);
1894 $this->SetId($row['id']);
1895 $this->SetCompany($row['company']);
1896 $this->SetPasswordEncrypted($row['login_password']);
1897 $this->SetWorkSpace($row['workspace']);
1898 $this->SetAnnualHoliday($row['annual_holidays']);
1899 $this->SetFreebieOvertime($row['freebie_overtime']);
1900 $this->SetWorkerType($row['contracted_hours']);
1901 $this->SetUpdated($row['updated']);
1902 $this->SetCurrentProjectId($row['current_pid']);
1903 $this->SetCurrentSubProjectId($row['current_subpid']);
1904 $this->SetSurename($row['surename']);
1905 $this->SetLastName($row['lastname']);
1906 $this->SetContractStart($row['contract_start']);
1907 $this->SetContractEnd($row['contract_end']);
1908 $this->SetDescription($row['description']);
1909 $this->SetAdmin($row['admin']);
1910
1911 // arbeitszeiten
1912 $this->DayHours[1] = substr($row['1'], 0, 5); // Monday
1913 $this->DayHours[2] = substr($row['2'], 0, 5); // Tuesday
1914 $this->DayHours[3] = substr($row['3'], 0, 5); // Wednsday
1915 $this->DayHours[4] = substr($row['4'], 0, 5); // Thursday
1916 $this->DayHours[5] = substr($row['5'], 0, 5); // Friday
1917 $this->DayHours[6] = substr($row['6'], 0, 5); // Saturday
1918 $this->DayHours[0] = substr($row['7'], 0, 5); // Sunday
1919
1920 $this->load_last_work_day();
1921
1922 return TRUE;
1923 }
1924
1925 function lookup_worker_by_name($user_name)
1926 {
1927 $where = 'WHERE `wname` = "' . $user_name . '"';
1928 return $this->load_worker_by_query($where);
1929 }
1930
1931 function GetContractEnd() { return $this->contract_end; }
1932 function GetContractStart() { return $this->contract_start; }
1933 function GetCurrentDay() { return $this->current_day; }
1934 function GetCurrentProjectId() { return $this->current_project_id; }
1935 function GetCurrentSubProjectId() { return $this->current_subproject_id; }
1936 function GetCurrentWeek() { return $this->current_week; }
1937 function GetCurrentYear() { return $this->current_year; }
1938 function GetFreebieOverTime() { return $this->freebie_overtime; }
1939 function GetFullName() { return $this->surename . ' ' . $this->lastname; }
1940 function GetId() { return $this->id; }
1941 function GetLoginName() { return $this->login_name; }
1942 function GetPasswordEncrypted() { return $this->password_encrypted; }
1943 function GetUpdated() { return $this->updated; }
1944 function GetWorkertype() { return $this->workertype; }
1945 function GetWorkSpace() { return $this->workspace; }
1946
1947 function SetAdmin($admin) { $this->admin = $admin; return true; }
1948 function SetAnnualHoliday($annual_holiday) { $this->annual_holiday = (int) $annual_holiday; return true; }
1949 function SetCompany($company_id) { $this->company = new Company($company_id); return true; }
1950 function SetContractEnd($contract_end) { $this->contract_end = $contract_end; return true; }
1951 function SetContractStart($contract_start) { $this->contract_start = $contract_start; return true; }
1952 function SetCurrentProjectId($project_id) { $this->current_project_id = $project_id; return true; }
1953 function SetCurrentSubProjectId($subproject_id) { $this->current_subproject_id = $subproject_id; return true; }
1954 function SetDescription($description) { $this->description = $description; return true; }
1955 function SetFreebieOvertime($freebie_overtime) { $this->freebie_overtime = $freebie_overtime; return true; }
1956 function SetId($worker_id) { $this->id = (int) $worker_id; return true; }
1957 function SetLastName($last_name) { $this->lastname = $last_name; return true; }
1958 function SetLogedIn($LogedIn) { $this->LogedIn = $LogedIn; return true; }
1959 function SetLoginName($login_name) { $this->login_name = $login_name; return true; }
1960 function SetPassword($password) { $this->SetPasswordEncrypted($this->EncryptPassword($password)); return true; }
1961 function SetPasswordEncrypted($password_encrypted) { $this->login_password_encrypted = $password_encrypted; return true; }
1962 function SetSureName($sure_name) { $this->surename = $sure_name; return true; }
1963 function SetWorkerType($worker_type) { $this->worker_type = $worker_type; return true; }
1964 function SetWorkSpace($work_space) { $this->workspace = $work_space; return true; }
1965
1966 function EncryptPassword($password) { return sha1($password); }
1967
1968 function IsAdmin() { return $this->admin; }
1969 function IsLogedIn() { return $this->LogedIn; }
1970
1971 /**
1972 * Updates the user pasword in the database
1973 *
1974 * @parameter string password
1975 * @return bool success
1976 */
1977 function UpdatePassword($plain_pass = null)
1978 {
1979 if ( empty($plain_pass) )
1980 {
1981 $sql = '
1982 UPDATE `' . PTS_TBL_WORKER . '`
1983 SET `password` = NULL
1984 WHERE `id` = ' . $this->GetId();
1985 }
1986 else
1987 {
1988 $sql = '
1989 UPDATE `' . PTS_TBL_WORKER . '`
1990 SET `password` = SHA1("' . $plain_pass . '")
1991 WHERE `id` = ' . $this->GetId();
1992 }
1993 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
1994 $this->SetPassword($plain_pass);
1995 return true;
1996 }
1997
1998 /**
1999 * Looks up and compares user password
2000 *
2001 * @parameter string plain password
2002 * @return bool true if password is correct, otherwise false
2003 */
2004 function authenticate($plain_pass)
2005 {
2006 if ( $this->GetPasswordEncrypted() == "" || $this->GetPasswordEncrypted() == sha1($plain_pass) )
2007 {
2008 return true;
2009 }
2010
2011 return false;
2012 }
2013
2014 // 2003-02-21 Sebastian Mendel, lädt letzte arbeitstezit
2015 function load_last_work_day()
2016 {
2017 $sql = '
2018 SELECT *
2019 FROM `' . PTS_TBL_WORKTIME . '`
2020 WHERE `' . PTS_TBL_WORKTIME . '`.`worker` = "' . $this->GetId() . '"
2021 AND `' . PTS_TBL_WORKTIME . '`.`day` <= "' . date('Y-m-d') . '"
2022 AND `' . PTS_TBL_WORKTIME . '`.`come` <> "00:00:00"
2023 ORDER BY `' . PTS_TBL_WORKTIME . '`.`day` DESC
2024 LIMIT 1';
2025
2026 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
2027
2028 if ( mysql_num_rows($result) > 0 )
2029 {
2030 $this->lastworktime = mysql_fetch_assoc($result);
2031 }
2032 else
2033 {
2034 $this->lastworktime = null;
2035 }
2036
2037 return TRUE;
2038 }
2039
2040 function DumpTimeData()
2041 {
2042 // hole tagesdaten
2043 $sql = '
2044 SELECT *,
2045 SEC_TO_TIME(TIME_TO_SEC(`go`) - TIME_TO_SEC(`come`)) AS `anwesend`,
2046 TIME_TO_SEC(`go`) - TIME_TO_SEC(`come`) - TIME_TO_SEC(`workspace`) - TIME_TO_SEC(`contracted_hours`) AS `overtime_sec`,
2047 SEC_TO_TIME(TIME_TO_SEC(`go`) - TIME_TO_SEC(`come`) - TIME_TO_SEC(`workspace`) - TIME_TO_SEC(`contracted_hours`)) AS `overtime`,
2048 CASE `worktype`
2049 WHEN ' . PTS_WT_HOLIDAY . ' THEN -1
2050 WHEN ' . PTS_WT_HOLIDAY_HALF . ' THEN -0.5
2051 ELSE 0
2052 END AS `holidays`
2053 FROM `' . PTS_TBL_WORKTIME . '`
2054 WHERE `worker` = ' . $this->GetId() . '
2055 ORDER BY `day` ASC';
2056 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
2057
2058 while ( $row = mysql_fetch_assoc($result) )
2059 $rows[$row['day']] = $row;
2060
2061
2062 // hole korrektur-zeiten
2063 $sql = '
2064 SELECT *, TIME_TO_SEC(`overtime`) AS `overtime_sec`, CONCAT(`day`, "-", `' . PTS_TBL_CORRECTION . '`.`id`) AS `day`
2065 FROM `' . PTS_TBL_CORRECTION . '`
2066 LEFt JOIN `correction_reason` ON `' . PTS_TBL_CORRECTION . '`.`reason` = `correction_reason`.`id`
2067 WHERE `worker` = "' . $this->GetId() . '"';
2068 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
2069
2070 while ( $row = mysql_fetch_assoc($result) )
2071 $rows[$row['day'].'-c'] = $row;
2072
2073 // sort days in array
2074 ksort($rows);
2075
2076 $content = '<table border="1" cellpadding="0" cellspacing="0">';
2077 $content .= '
2078 <tr><th colspan="8"></th>
2079 <th colspan="2">Gesamt</th></tr>
2080 <tr><th>Datum</th>
2081 <th>Kommen</th>
2082 <th>Gehen</th>
2083 <th>Anwesend</th>
2084 <th>Pause</th>
2085 <th>SOLL</th>
2086 <th>ÜS</th>
2087 <th>Urlaub</th>
2088 <th>ÜS</th>
2089 <th>URLAUB</th></tr>';
2090
2091 global $WORK_TYPE
2092
2093 foreach ( $rows as $date => $row )
2094 {
2095 $all_overtime += $row['overtime_sec'];
2096 $disp_all_overtime = $all_overtime / 60 /60;
2097
2098 $all_holidays += $row['holidays'];
2099
2100 if ( $row['overtime_sec'] <> 0 || $row['holidays'] <> 0 )
2101 {
2102 $style = 'style="font-weight: bold;"';
2103 }
2104 else
2105 {
2106 $style = 'style="font-weight: normal;"';
2107 }
2108
2109 if ( date('w', strtotime($date)) == 0 )
2110 {
2111 // sonntag
2112 $datestyle = 'style="background-color: #ffffff;"';
2113 }
2114 else
2115 {
2116 $datestyle = '';
2117 }
2118
2119 $content .= '
2120 <tr ' . $style . '><td>' . $date . '</td>';
2121
2122 global $WORK_TYPE
2123
2124 if ( ! empty($row['reason']) )
2125 {
2126 $content .= '
2127 <td colspan="4">' . $row['name'] . '</td>';
2128 }
2129 elseif ( $row['anwesend'] == '00:00:00' )
2130 {
2131 $content .= '<td colspan="4">' . $WORK_TYPE[$row['worktype']]['short'] . '</td>';
2132 }
2133 else
2134 {
2135 $content .= '
2136 <td align="right">' . $row['come'] . '</td>
2137 <td align="right">' . $row['go'] . '</td>
2138 <td align="right">' . $row['anwesend'] . '</td>
2139 <td align="right">' . $row['workspace'] . '</td>';
2140 }
2141 $content .= '
2142 <td align="right">' . $row['contracted_hours'] . '</td>
2143 <td align="right">' . $row['overtime'] . '</td>
2144 <td align="right">' . $row['holidays'] . '</td>
2145 <td align="right">' . dbhm($disp_all_overtime) . '</td>
2146 <td align="right">' . $all_holidays . '</td>
2147 </tr>';
2148 }
2149
2150 $content .= "</table>";
2151 return $content;
2152 }
2153
2154 /**
2155 * returns a HTML-Selectbox as string
2156 *
2157 * @static
2158 * @return string HTML-Code for selectbox with Workers
2159 */
2160 function GetSelectBox($only_active = true, $selected_worker_id = 0)
2161 {
2162 if ( $only_active )
2163 {
2164 $sql = "
2165 SELECT `id`, `surename`, `lastname`
2166 FROM `" . PTS_TBL_WORKER . "`
2167 WHERE UNIX_TIMESTAMP(`austritt`) >= UNIX_TIMESTAMP(CURDATE())
2168 OR UNIX_TIMESTAMP(`austritt`) = 0
2169 ORDER BY `lastname`";
2170 }
2171 else
2172 {
2173 $sql = "
2174 SELECT `id`, `surename`, `lastname`
2175 FROM `" . PTS_TBL_WORKER . "`
2176 ORDER BY `lastname`";
2177 }
2178
2179 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
2180
2181 $worker_selectbox = '<select name="worker_id">';
2182 while ( $row = mysql_fetch_assoc($result) )
2183 {
2184 if ( $selected_worker_id == $row['id'] )
2185 {
2186 $selected = ' selected="selected"';
2187 }
2188 else
2189 {
2190 $selected = '';
2191 }
2192 $worker_selectbox .= '<option value="' . $row['id'] . '"' . $selected . '>' . $row['lastname'] . ', ' . $row['surename'] . '</option>';
2193 }
2194 $worker_selectbox .= '</select>';
2195
2196 return $worker_selectbox;
2197 }
2198
2199 function GetViewSelectbox($current_view = null)
2200 {
2201 global $str
2202 $views['project'] = 'projectview';
2203 $views['day'] = 'dayview';
2204 $views['week'] = 'weekview';
2205 $views['year'] = 'yearview';
2206 $views['settings'] = 'settings';
2207
2208 $sb = '<select name="view" onchange="this.form.submit()">';
2209 foreach ( $views as $view => $viewname )
2210 {
2211 if ( $view === $current_view )
2212 {
2213 $selected = ' selected="selected"';
2214 }
2215 else
2216 {
2217 $selected = '';
2218 }
2219 $sb .= '<option value="' . $view . '"' . $selected . '>' . $str[$viewname] . '</option>';
2220 }
2221 $sb .= '</select>';
2222
2223 return $sb;
2224 }
2225 }
2226 ?>

Documentation generated on Fri, 26 Sep 2003 15:40:16 +0200 by phpDocumentor 1.2.2