<?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: newjob.php,v 1.12 2001/01/12 22:14:47 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;
$quote_date_sql = $quotedate;
$opened_date_sql = $opendate;
$deadline_date_sql = $deadlinedate;
// What so we need to validate before inserting this job into the db?
// 1. Double check (re-query) db to make sure jobnum/rev isn't already taken.
// 2. Quoted Hours should be allowed to have a T&M flag somehow?
// 3. Opened date will not be set if staus is only "Quoted".
// 4. Deadline date MUST be later than Quoted or Opened Date.
// Main integrity check:
if($n_customer && $n_jobnum) {
// First, lets make sure the job doesn't already exist:
$phpgw->db->query("SELECT * from jobs where company_id='$n_customer' AND "
. "job_number='$n_jobnum' AND job_revision='$n_rev'");
if($phpgw->db->num_rows() > 0){ // The job already exists
echo lang("Error: The specified job already exists") . "<br>"
. lang("Please use the back button to re-examine entry");
exit;
}
if ($n_billable == "True") { //null value passed
$billit = "Y";
} else {
$billit = "N";
}
$newjob_sql = "insert into jobs (company_id, contact_id, account_id, job_number, job_revision, summary, "
. "description, quote_date, quoted_hours, opened_date, deadline, approved_by, status_id, billable) "
. "VALUES ('$n_customer','$n_contact','$n_employee','$n_jobnum','$n_rev','"
. addslashes($n_summary) . "','" . addslashes($n_detail) . "',"
. "'$quote_date_sql','$n_quoted_hours','$opened_date_sql','$deadline_date_sql','$n_approvedby',"
. "'$n_status','$billit')";
$phpgw->db->query($newjob_sql);
echo '<script LANGUAGE="JavaScript">';
echo 'window.location="' . $phpgw->link("index.php") . '"';
echo '</script>';
} else { // report error
echo lang("The Company Name and Job Number fields are required!") . "<br>";
echo lang("Please use the back button to correct these entries and re-submit");
} // end main integrity check
} // end submit
else
{
inc_cal();
inc_myutil();
?>
<center><h3>New Job Entry</h3></center>
<form method="POST" name="jobform" action="<?php echo $phpgw->link();?>">
<?php
$cnamesize = 'SIZE="' . $phpgw_info["user"]["preferences"]["timetrack"]["cnamesize"] . '"';
if ($error) {
echo "<center>" . lang("Error") . ":$error</center>";
}
?>
<center>
<table border=0 width=65%>
<tr>
<td><?php echo "Company";
if ($phpgw_info["user"]["preferences"]["timetrack"]["cnamesize"] > 1 && $cust)
{
echo '<br><i>Selected:</i><br>';
$phpgw->db->query("select company_name from customers where "
. "company_id = $cust");
$phpgw->db->next_record();
echo "<b>" . $phpgw->db->f(0) . "</b>";
}
?></td>
<?php // need to populate a drop down list here
// May want to add a where clause later to only present customers whose
// who are current to keep list short (use some kind of active flag in table)
?>
<td><select name="n_customer" <?php echo $cnamesize; ?> onChange="if (this.selectedIndex !=0)
window.location.href =
'<?php echo $phpgw->link("", "cust=");?>' + this.options[this.selectedIndex].value">
<!-- Let's do our empty option first -->
<option value="">Select Customer...</option>
<?php
$phpgw->db->query("select company_id,company_name from customers where active='Y' "
. "order by company_name");
while ($phpgw->db->next_record()) {
$ncust = $phpgw->db->f("company_id");
echo '<option value="' . $ncust . '"';
if ( $cust == $ncust ) {
echo " selected";
}
echo ">" . $phpgw->db->f("company_name") . "</option>";
}
?>
</select></td>
</tr>
<tr>
<td><?php echo "Contact"; ?></td>
<td><select name="n_contact">
<?php // Check value of $cust, if it is empty, just put a null option telling user to
// pick the customer first.
if (! $cust) {
echo '<option value="">^-Pick Customer First-^</option>';
} else {
$contact_sql = "select ab_id,ab_firstname,ab_lastname from addressbook "
. "where ab_company_id = '$cust'"
. " 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 . '">' . $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 . '">' . $n_empname . '</option>';
}
?>
</select></td>
</tr>
<tr>
<!-- This should query the jobs db for the highest job number and increment it 1 -->
<td><?php echo "Job Number"; ?></td>
<?php
if ($cust) {
$jobnum_sql = "select MAX(job_number) from jobs where company_id='" . $cust . "'";
$phpgw->db->query($jobnum_sql);
$phpgw->db->next_record();
$n_jobnum = $phpgw->db->f(0) + 1;
//$n_jobnum = 100;
}
?>
<td><input name="n_jobnum" size="5" maxlength="5"
onBlur="CheckNum(this,0,99999);"
value="<?php echo $n_jobnum; ?>">
<?php echo "Revision"; ?>
<input name="n_rev" size="2" maxlength="2"
onBlur="this.value = capitalizeAll(this.value);"
value="<?php echo $n_rev; ?>"></td>
</tr>
<tr>
<td><?php echo "Summary Description"; ?></td>
<td><input name="n_summary" value="<?php echo $n_summary; ?>" size="40" maxlength="40"
onBlur="this.value = capitalizeFirstWord(this.value);"></td>
</tr>
<tr>
<td><?php echo "Detailed Description"; ?></td>
<td><textarea name="n_detail" cols="40" rows="4"
onBlur="this.value = capitalizeFirstWord(this.value);"
wrap="virtual"><?php echo $n_detail; ?></textarea></td>
</tr>
<tr>
<td><?php echo "Quote Date"; ?></td>
<td><?php
//DateSelector("quote",time());
CalDateSelector("jobform","quotedate",0,"");
?></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
//DateSelector("opened");
CalDateSelector("jobform","opendate",1,"");
?></td>
</tr>
<tr>
<td><?php echo "Deadline"; ?></td>
<td><?php
//DateSelector("deadline");
CalDateSelector("jobform","deadlinedate",1,"");
?></td>
</tr>
<tr>
<!-- Could be a dropdown list -->
<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()) {
echo '<option value="' . $phpgw->db->f("account_id") . '">' .
$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
$phpgw->db->query("select * from job_status order by status_id");
while ($phpgw->db->next_record()) {
echo '<option value="' . $phpgw->db->f("status_id") . '">' .
$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" CHECKED></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();
}
?>