<?php
/**************************************************************************\
* phpgwtimetrack - phpGroupWare addon application *
* http://phpgwtimetrack.sourceforge.net *
* Written by Robert Schader <hide@address.com> *
* Written by Joseph Engo <hide@address.com> *
* -------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 2 of the License, or (at your *
* option) any later version. *
\**************************************************************************/
/* $Id: editdetail.php,v 1.10 2001/01/12 22:14:35 rschader Exp $ */
// This file is being updated to use the new "TimeSelect2()" function instead
// of TimeSelector(). Also change to new DateSelector() function.
if($submit || $submit_new) {
$phpgw_info["flags"] = array("noheader" => True, "nonavbar" => True);
}
$phpgw_info["flags"]["enable_nextmatchs_class"] = "True";
$phpgw_info["flags"]["currentapp"] = "timetrack";
include("../header.inc.php");
?>
<?php
if ($submit || $submit_new) {
//if($workedYear && $workedMonth && $workedDay)
//$worked_date_sql = $workedYear . "-" . $workedMonth . "-" . $workedDay;
$worked_date_sql = $workdate;
//$starttimestamp = date("Ymd", mktime(0,0,0,$workedMonth,$workedDay,$workedYear)) . $n_start_time . "00";
//echo "n_start_time_ampm = [$n_start_time_ampm]";
//exit;
if($n_start_time_ampm == "pm" && $n_start_time_h < 12) {
$n_start_time_h += 12;
}
if($n_start_time_ampm == "am" && $n_start_time_h == 12) {
$n_start_time_h = 0;
}
$starttime = $n_start_time_h . ":" . $n_start_time_m . ":00";
if($n_end_time_ampm == "pm" && $n_end_time_h < 12) {
$n_end_time_h += 12;
}
if($n_end_time_ampm == "am" && $n_end_time_h == 12) {
$n_end_time_h = 0;
}
$endtime = $n_end_time_h . ":" . $n_end_time_m . ":00";
if ($n_detail_billable == "True") { //null value passed
$billit = "Y";
} else {
$billit = "N";
}
// Simple error checking
if($n_catagory && $worked_date_sql && $starttime && $n_num_hours) {
if($submit) {
$editjdet_sql = "UPDATE job_details SET work_catagory_id=$n_catagory,"
. "work_date='$worked_date_sql',start_time='$starttime',"
. "end_time='$endtime',num_hours='$n_num_hours',detail_billable='$billit',"
. "comments='" . addslashes($n_comments) . "'"
. " WHERE detail_id=$n_detail_id";
$phpgw->db->query($editjdet_sql);
} else { // Only alternative is $submit_new
$newjobdetail_sql = "insert into job_details (job_id, account_id, work_catagory_id, work_date, start_time, "
. "end_time, num_hours, detail_billable, comments) "
. "VALUES ('$n_job_id','$n_employee','$n_catagory','$worked_date_sql','$starttime',"
. "'$endtime','$n_num_hours','$billit','" . addslashes($n_comments) . "')";
$phpgw->db->query($newjobdetail_sql);
}
$yr=strval(substr($workdate,0,4));
$mo=strval(substr($workdate,5,2));
$da=strval(substr($workdate,8,2));
$ytext = "year=$yr&month=$mo&day=$da";
echo '<script LANGUAGE="JavaScript">';
echo 'window.location="' . $phpgw->link("timesheets.php","$ytext&n_employee=$n_employee") . '"';
echo '</script>';
} else { // Error, go back
echo "You made a mistake, please use your back button to correct it";
}
} // end submit
else
{
inc_cal(); // Init js calendar datepicker
inc_myutil(); // validation routines, etc for form inputs
?>
<center><h3>Edit Time Entry</h3></center>
<form method="POST" name="jobform" action="<?php echo $phpgw->link();?>">
<?php
if ($error) {
echo "<center>" . lang("Error") . ":$error</center>";
}
echo "<center>Detail ID is: " . $detailid
. "</center><br>";
echo '<input type=hidden name=n_detail_id value="' . $detailid . '">';
$phpgw->db->query("select * from job_details where detail_id=" . $detailid);
$phpgw->db->next_record();
$n_job_id = $phpgw->db->f("job_id");
$n_account_id = $phpgw->db->f("account_id");
$n_work_catagory_id = $phpgw->db->f("work_catagory_id");
$n_work_date = $phpgw->db->f("work_date");
$n_start_time = $phpgw->db->f("start_time");
$n_end_time = $phpgw->db->f("end_time");
$n_num_hours = $phpgw->db->f("num_hours");
$n_detail_billable = $phpgw->db->f("detail_billable");
$n_comments = $phpgw->db->f("comments");
// Need to now get customer_id and job_number,revision from jobs table, then
// get customers.company_name.
$phpgw->db->query("select company_id,job_number,job_revision,summary from jobs where job_id=" . $n_job_id);
$phpgw->db->next_record();
$n_company_id = $phpgw->db->f("company_id");
$n_job_number = $phpgw->db->f("job_number");
$n_job_revision = $phpgw->db->f("job_revision");
$n_summary = $phpgw->db->f("summary");
// Info to get from other tables: customers.company_name
// other table info should be able to get when doing the SELECT dropdowns:
// contact_id(name), account_id(employee), status_name, approved_by.
$phpgw->db->query("select company_name from customers where company_id=" . $n_company_id);
$phpgw->db->next_record();
$n_customer = $phpgw->db->f("company_name");
// For passing account_id back to timesheets.php
echo '<input type=hidden name=n_employee value="' . $n_account_id . '">';
// For passing other, non editable items back when submitting using the "Add As New" button
echo '<input type=hidden name=n_job_id value="' . $n_job_id . '">';
//echo '<input type=hidden name=n_ value="' . $n_ . '">';
//echo '<input type=hidden name=n_ value="' . $n_ . '">';
//echo '<input type=hidden name=n_ value="' . $n_ . '">';
?>
<center>
<table border=0 width=65%>
<tr>
<td><?php echo "Company"; ?></td>
<td><?php echo $n_customer; ?></td>
</tr>
<tr>
<td><?php echo "Job Number"; ?></td>
<td><?php echo $n_job_number; ?></td>
</tr>
<tr>
<td><?php echo "Revision"; ?></td>
<td><?php echo $n_job_revision; ?></td>
</tr>
<tr>
<td><?php echo "Summary"; ?></td>
<td><?php echo $n_summary; ?></td>
</tr>
<tr>
<td><?php echo "Work Catagory"; ?></td>
<td><select name="n_catagory">
<option value="">Select Work Type...</option>
<?php
$phpgw->db->query("select * from work_catagories order by work_catagory_id");
while ($phpgw->db->next_record()) {
$n_catagory_id = $phpgw->db->f("work_catagory_id");
$n_catname = $phpgw->db->f("catagory_desc");
echo '<option value="' . $n_catagory_id . '"';
if($n_catagory_id == $n_work_catagory_id) echo "selected";
echo '>' . $n_catname . '</option>';
}
?>
</select></td>
</tr>
<tr>
<td><?php echo "Work Date"; ?></td>
<?php // Need to turn quote date into a unix timestamp here:
if(($n_work_date != "") && ($n_work_date !="0000-00-00"))
{
$work_date = mysql_datetime_to_timestamp($n_work_date);
} else {
$work_date = 0;
}
?>
<td>
<?php
$yr=strval(substr($n_work_date,0,4));
$mo=strval(substr($n_work_date,5,2));
$da=strval(substr($n_work_date,8,2));
CalDateSelector("jobform","workdate",0,"",$mo,$da,$yr);
//DateSelector("worked",$work_date);
//echo '</td><td>';
//cal_layer(500,150);
?></td>
</tr>
<tr>
<td><?php echo "Start Time"; ?></td>
<td><?php
//$stime = mysql_timestamp_to_timestamp($n_start_time);
TimeSelect3("jobform","n_start_time",0,strval(substr($n_start_time,0,2)),
strval(substr($n_start_time,3,2)));
?></td>
</tr>
<tr>
<td><?php echo "End Time"; ?></td>
<td><?php
if($n_end_time) {
// Once the database has been updates, we really won't need to test this
TimeSelect3("jobform","n_end_time",0,strval(substr($n_end_time,0,2)),
strval(substr($n_end_time,3,2)));
} else {
TimeSelect3("jobform","n_end_time",0);
}
?></td>
</tr>
<tr>
<td><?php echo "Number of Hours"; ?></td>
<td><input name="n_num_hours" size="8" maxlength="6"
onFocus="this.blur();"
onBlur="CheckNum(this,0,24);"
value="<?php echo $n_num_hours; ?>">
<input type=button name="calctime" value="Update"
onclick="gethours('jobform','n_num_hours','n_start_time','n_end_time')";>
</td>
</tr>
<tr>
<td><?php echo "Billable"; ?></td>
<!-- This could just be a checkbox, default to True for billable -->
<td><input type="checkbox" name="n_detail_billable" value="True"
<?php
if($n_detail_billable == "Y") echo " CHECKED";
echo "></td>";
?>
</tr>
<tr>
<td><?php echo "Work Comments"; ?></td>
<td><textarea name="n_comments" cols="40" rows="4"
onBlur="this.value = capitalizeFirstWord(this.value);"
wrap="virtual"><?php echo $n_comments; ?></textarea></td>
</tr>
<tr>
<td width="10%">
<input type="submit" name="submit" value="<?php echo lang("Update"); ?>">
</td>
<td width="10%">
<input type="submit" name="submit_new" value="<?php echo lang("Add As New"); ?>">
</td>
<td width="10%">
<?php
$myyear = date("Y", $work_date);
$mymonth = date("m", $work_date);
$myday = date("d", $work_date);
echo '<A HREF="' . $phpgw->link("timesheets.php")
. "?year=$myyear&month=$mymonth&day=$myday&n_employee=$n_account_id\">" . lang("Cancel"); ?></a>
</td>
<td align=right>
<a href="<?php
echo $phpgw->link("deletedetail.php",
"jd_id=$detailid&year=$myyear&month=$mymonth&day=$myday&n_employee=$n_account_id")
. "\">" . lang("Delete"); ?></a>
</td>
</tr>
</table>
</center>
</form>
<?php
$phpgw->common->phpgw_footer();
}
?>