<?php 
//$Header: /usr/local/cvs/twig/config/timesheet_common.inc,v 1.1.1.1 1999/03/31 20:55:44 chris Exp $
if ($GLOBALS[TIMESHEET_COMMON_INC] != 1) {
  $GLOBALS[TIMESHEET_COMMON_INC] = 1;

  $LANGUAGE = 1; // 1 for English, 2 for German.

  $TIMESHEET_BREAK_RATIO = (0);
  // For an hour break every 8 hours this would be: (1/8)

  function get_time_date($day, $year, $month, $id, $proj_id) {
    static $my_qh;
    global $PHP_AUTH_USER, $dbconfig;

    $query = "select start_time, end_time, sec_to_time(unix_timestamp(end_time) - unix_timestamp(start_time)) ".
      "as difference, end_time+0 as num_end, trans_num from $dbconfig[timesheet_table] where uid='$PHP_AUTH_USER' AND proj_id=$proj_id ".
      "AND start_time >= '$year-$month-$day 00:00:00' AND start_time < '$year-$month-$day 23:59:59' order by start_time";
    $my_qh = dbQuery($query);
    $num = dbNumRows($my_qh);
    return array($num, $my_qh);
  }
  
  function print_weekly_totals() {
    GLOBAL $tot_sec,$tot_min,$tot_hor;
    GLOBAL $pp_h, $pp_m, $pp_s, $week_tot_h, $week_tot_m, $week_tot_s, $BREAK_RATIO;
    print "</TR><TR>\n";
    print "<TD ALIGN=RIGHT COLSPAN=7>";
    if ($BREAK_RATIO > 0) {
       $break_h = floor($BREAK_RATIO*$week_tot_h);
       $break_m = floor($BREAK_RATIO*$week_tot_m);
       $break_s = floor($BREAK_RATIO*$week_tot_s);

       $week_tot_s -= $break_s;
       if ($week_tot_s < 0) {
	 $week_tot_s += 60;
	 $week_tot_m--;
       }
       $week_tot_m -= $break_m;
       if ($week_tot_m < 0) {
	 $week_tot_m += 60;
	 $week_tot_h--;
       }	 
       $week_tot_h -= $break_h;

       print "Break time: ${break_h}h ${break_m}m ${break_s}s || ";
    }
    print "Weekly total: ${week_tot_h}h ${week_tot_m}m ${week_tot_s}s</TD>\n";
    $pp_h += $week_tot_h;
    $pp_m += $week_tot_m;
    $pp_s += $week_tot_s;
    if ($pp_s >= 60) {
      $pp_m++;
      $pp_s -= 60;
    }
    if ($pp_m >= 60) {
      $pp_h++;
      $pp_m -= 60;
    }
    $week_tot_h = 0; $week_tot_s = 0; $week_tot_m = 0;
  }

  function user_select_list() {
    // Need a "users" table before we use this...
    $qh = dbQuery("select username from users");
    print "<SELECT NAME=\"assigned[]\" MULTIPLE SIZE=4>\n";
    while (list($username) = mysql_fetch_row($qh)) {
      if ($username != 'admin')
	print "<OPTION NAME=\"$username\">$username</OPTION>\n";
    }
    print "</SELECT>";
  }


} // end if
?>
