<?php
/**************************************************************************\
* phpgwtimetrack - phpGroupWare addon application *
* http://phpgwtimetrack.sourceforge.net *
* Written by Robert Schader <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: editjob.php,v 1.7 2001/01/12 22:14:35 rschader Exp $ */
if($submit) {
$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) {
//if($quoteYear && $quoteMonth && $quoteDay)
//$quote_date_sql = $quoteYear . "-" . $quoteMonth . "-" . $quoteDay;
//if($openedYear && $openedMonth && $openedDay)
//$opened_date_sql = $openedYear . "-" . $openedMonth . "-" . $openedDay;
//if($deadlineYear && $deadlineMonth && $deadlineDay)
//$deadline_date_sql = $deadlineYear . "-" . $deadlineMonth . "-" . $deadlineDay;
//if($completedYear && $completedMonth && $completedDay)
//$completed_date_sql = $completedYear . "-" . $completedMonth . "-" . $completedDay;
//if($paidinfullYear && $paidinfullMonth && $paidinfullDay)
//$paidinfull_date_sql = $paidinfullYear . "-" . $paidinfullMonth . "-" . $paidinfullDay;
//if($cancelledYear && $cancelledMonth && $cancelledDay)
//$cancelled_date_sql = $cancelledYear . "-" . $cancelledMonth . "-" . $cancelledDay;
$quote_date_sql = $quotedate;
$opened_date_sql = $opendate;
$deadline_date_sql = $deadlinedate;
$completed_date_sql = $completedate;
$paidinfull_date_sql = $paidinfulldate;
$cancelled_date_sql = $cancelleddate;
if ($n_billable == "True") { //null value passed
$billit = "Y";
} else {
$billit = "N";
}
$editjob_sqlmain = "UPDATE jobs SET contact_id='$n_contact',account_id='$n_employee',"
. "summary='" . addslashes($n_summary) . "',description='" . addslashes($n_detail)
. "',quoted_hours='$n_quoted_hours',"
. "approved_by='$n_approvedby',status_id='$n_status',billable='$billit',"
. "quote_date='$quote_date_sql',opened_date='$opened_date_sql',deadline='$deadline_date_sql',"
. "completed_date='$completed_date_sql',paid_date='$paidinfull_date_sql',"
. "cancelled_date='$cancelled_date_sql'"
. " WHERE job_id='$n_jobid'";
$phpgw->db->query($editjob_sqlmain);
echo '<script LANGUAGE="JavaScript">';
echo 'window.location="' . $phpgw->link("jobslist.php", "start=$start&order=$order&filter=$filter"
. "&query=$query&sort=$sort&qfield=$qfield") . '"';
echo '</script>';
} // end submit
else
{
inc_cal(); // Init js calendar datepicker
inc_myutil(); // validation routines, etc for form inputs
?>
<center><h3>Edit Job Entry</h3></center>
<form method="POST" name="jobform" action="<?php echo $phpgw->link();?>">
<input type="hidden" name="sort" value="<?php echo $sort; ?>">
<input type="hidden" name="order" value="<?php echo $order; ?>">
<input type="hidden" name="query" value="<?php echo $query; ?>">
<input type="hidden" name="start" value="<?php echo $start; ?>">
<input type="hidden" name="filter" value="<?php echo $filter; ?>">
<input type="hidden" name="qfield" value="<?php echo $qfield; ?>">
<?php
if ($error) {
echo "<center>" . lang("Error") . ":$error</center>";
}
// Notes for editing jobs:
// 1. The company name (id) or job_id are not allowed to change.
//
// Might as well get all the query info here
echo "<center>Internal Job ID is: " . $jobid . "</center><br>";
echo '<input type=hidden name=n_jobid value="' . $jobid . '">';
$phpgw->db->query("select * from jobs where job_id=" . $jobid);
$phpgw->db->next_record();
$n_company_id = $phpgw->db->f("company_id");
$n_contact_id = $phpgw->db->f("contact_id");
$n_account_id = $phpgw->db->f("account_id");
$n_job_number = $phpgw->db->f("job_number");
$n_job_revision = $phpgw->db->f("job_revision");
$n_description = $phpgw->db->f("description");
$n_quote_date = $phpgw->db->f("quote_date");
$n_quoted_hours = $phpgw->db->f("quoted_hours");
$n_opened_date = $phpgw->db->f("opened_date");
$n_deadline = $phpgw->db->f("deadline");
$n_approved_by = $phpgw->db->f("approved_by");
$n_status_id = $phpgw->db->f("status_id");
$n_billable = $phpgw->db->f("billable");
$n_summary = $phpgw->db->f("summary");
$n_completed_date = $phpgw->db->f("completed_date");
$n_paid_date = $phpgw->db->f("paid_date");
$n_cancelled_date = $phpgw->db->f("cancelled_date");
// 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");
?>
<center>
<table border=0 width=65%>
<tr>
<td><?php echo "Company"; ?></td>
<td><?php echo $n_customer; ?></td>
</tr>
<tr>
<td><?php echo "Contact"; ?></td>
<td><select name="n_contact">
<?php
$contact_sql = "select ab_id,ab_firstname,ab_lastname from addressbook "
. "where ab_company_id=" . $n_company_id
. " order by ab_lastname,ab_firstname";
$phpgw->db->query($contact_sql);
$test_result = $phpgw->db->num_rows();
if ($test_result == 0) {
echo'<option value="">No Match</option>';
}
while ($phpgw->db->next_record()) {
$ncontact = $phpgw->db->f("ab_id");
$contact_name = $phpgw->db->f("ab_firstname") . " " . $phpgw->db->f("ab_lastname");
echo '<option value="' . $ncontact . '"';
if ($ncontact == $n_contact_id) echo " selected";
echo '>' . $contact_name . '</option>';
}
?>
</select></td>
</tr>
<tr>
<td><?php echo "Assigned To"; ?></td>
<td><select name="n_employee">
<option value="">Select Employee...</option>
<?php
// I suppose I could add a preselected option here to pick the user entering the job (maybe)
$phpgw->db->query("select account_id,account_firstname,account_lastname from accounts "
. "order by account_lastname,account_firstname");
while ($phpgw->db->next_record()) {
$n_employee_id = $phpgw->db->f("account_id");
$n_empname = $phpgw->db->f("account_lastname") . ", " . $phpgw->db->f("account_firstname");
echo '<option value="' . $n_employee_id . '"';
if ($n_account_id == $n_employee_id) echo " selected";
echo '>' . $n_empname . '</option>';
}
?>
</select></td>
</tr>
<tr>
<!-- This item is not to be changed on this form. -->
<td><?php echo "Job Number"; ?></td>
<td><?php echo $n_job_number; ?></td>
</tr>
<tr><!-- Neither is this for now -->
<td><?php echo "Revision"; ?></td>
<td><?php echo $n_job_revision; ?></td>
</tr>
<tr>
<td><?php echo "Summary Description"; ?></td>
<td><input name="n_summary" value="<?php echo $n_summary; ?>" size="40" maxlength="40"></td>
</tr>
<tr>
<td><?php echo "Detailed Description"; ?></td>
<td><textarea name="n_detail" cols="40" rows="4"
wrap="virtual"><?php echo $n_description ?></textarea></td>
</tr>
<tr>
<td><?php echo "Quote Date"; ?></td><td>
<?php
if(($n_quote_date == "") || ($n_quote_date =="0000-00-00"))
{
CalDateSelector("jobform","quotedate",1,"");
} else {
$yr=strval(substr($n_quote_date,0,4));
$mo=strval(substr($n_quote_date,5,2));
$da=strval(substr($n_quote_date,8,2));
CalDateSelector("jobform","quotedate",0,"",$mo,$da,$yr);
}
?></td>
</tr>
<tr>
<td><?php echo "Quoted Hours"; ?></td>
<td><input name="n_quoted_hours"
onBlur="CheckNum(this,0,99999);"
value="<?php echo $n_quoted_hours; ?>"></td>
</tr>
<tr>
<td><?php echo "Opened Date"; ?></td><td>
<?php
if(($n_opened_date == "") || ($n_opened_date == "0000-00-00"))
{
CalDateSelector("jobform","opendate",1,"");
} else {
$yr=strval(substr($n_opened_date,0,4));
$mo=strval(substr($n_opened_date,5,2));
$da=strval(substr($n_opened_date,8,2));
CalDateSelector("jobform","opendate",0,"",$mo,$da,$yr);
}
?></td>
</tr>
<tr>
<td><?php echo "Deadline"; ?></td><td>
<?php
if(($n_deadline == "") || ($n_deadline == "0000-00-00"))
{
CalDateSelector("jobform","deadlinedate",1,"");
} else {
$yr=strval(substr($n_deadline,0,4));
$mo=strval(substr($n_deadline,5,2));
$da=strval(substr($n_deadline,8,2));
CalDateSelector("jobform","deadlinedate",0,"",$mo,$da,$yr);
}
?></td>
</tr>
<tr>
<td><?php echo "Date Completed"; ?></td><td>
<?php
if(($n_completed_date == "") || ($n_completed_date == "0000-00-00"))
{
CalDateSelector("jobform","completedate",1,"");
} else {
$yr=strval(substr($n_completed_date,0,4));
$mo=strval(substr($n_completed_date,5,2));
$da=strval(substr($n_completed_date,8,2));
CalDateSelector("jobform","completedate",0,"",$mo,$da,$yr);
}
?></td>
</tr>
<tr>
<td><?php echo "Paid in Full"; ?></td><td>
<?php
if(($n_paid_date == "") || ($n_paid_date == "0000-00-00"))
{
CalDateSelector("jobform","paidinfulldate",1,"");
} else {
$yr=strval(substr($n_paid_date,0,4));
$mo=strval(substr($n_paid_date,5,2));
$da=strval(substr($n_paid_date,8,2));
CalDateSelector("jobform","paidinfulldate",0,"",$mo,$da,$yr);
}
?></td>
</tr>
<tr>
<td><?php echo "Date Cancelled"; ?></td><td>
<?php
if(($n_cancelled_date == "") || ($n_cancelled_date == "0000-00-00"))
{
CalDateSelector("jobform","cancelleddate",1,"");
} else {
$yr=strval(substr($n_cancelled_date,0,4));
$mo=strval(substr($n_cancelled_date,5,2));
$da=strval(substr($n_cancelled_date,8,2));
CalDateSelector("jobform","cancelleddate",0,"",$mo,$da,$yr);
}
?></td>
</tr>
<tr>
<td><?php echo "Assigned By"; ?></td>
<td><select name="n_approvedby">
<option value="">Select...</option>
<?php
// Will need to work on a better way to dynamically update and access the "Manager's Group
// as it won't always be "4". Leave it for now though. Should be avle to do by query to
// groups table to find id of "Managers" group easy enough.
$phpgw->db->query("select account_id,account_lastname,account_firstname from accounts "
. "where account_groups like \"%," . $phpgw_info["apps"]["timetrack"]["manager_gid"]
. ":%\" order by account_lastname,account_firstname");
while ($phpgw->db->next_record()) {
$con = $phpgw->db->f("account_id");
echo '<option value="' . $con . '"';
if($n_approved_by == $con) echo " selected";
echo '>'
. $phpgw->db->f("account_lastname") . ', '
. $phpgw->db->f("account_firstname") . '</option>';
}
?>
</select></td>
</tr>
<tr>
<!-- Will be a dropdown list -->
<!-- I almost wonder if I should change this ENUM to be it's own table? (YES) -->
<td><?php echo "Status"; ?></td>
<td><select name="n_status">
<option value="">Select Status...</option>
<?php
// Note on status and var names used for status change dates: these should
// be changed to better reflect the configurable status id's, 1: by
// somehow basing the form elements title on the status_name and 2: by renaming
// some of the var's referenced for status changes on forms to be a generic
// name (or array) called something like status_change[status_id] or
// status_stage_1. This would also neccesitate somehow changing the jobs
// table either dynamically or whatever in order to allow it to have a
// status change date for every status_id. Once that code change is implemented,
// it should be wholly possible to build the dateselector form elements
// in a for loop.
$phpgw->db->query("select * from job_status order by status_id");
while ($phpgw->db->next_record()) {
$status_id = $phpgw->db->f("status_id");
echo '<option value="' . $phpgw->db->f("status_id") . '"';
if($status_id == $n_status_id) echo " selected";
echo '>' . $phpgw->db->f("status_name") . '</option>';
}
?>
</select></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_billable" value="True"
<?php
if($n_billable == "Y") echo " CHECKED";
echo "></td>";
?>
</tr>
<tr>
<td colspan=2>
<input type="submit" name="submit" value="<?php echo lang("submit"); ?>">
</td>
</tr>
</table>
</center>
</form>
<?php
$phpgw->common->phpgw_footer();
}
?>