Location: PHPKode > projects > Phpgw Time Tracking Add On App > timetrack/addjobdetail.php
<?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: addjobdetail.php,v 1.14 2001/01/12 22:14:21 rschader Exp $ */
  // This file is being updated to use the new "TimeSelect2()" function instead
  // of TimeSelector(). Also change from the current DateSelector() to the new one.

 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) {
   //$worked_date_sql = $workedYear . "-" . $workedMonth . "-" . $workedDay;
   $worked_date_sql = $workdate;

   //$starttimestamp = date("Ymd", mktime(0,0,0,$workedMonth,$workedDay,$workedYear)) . $n_start_time . "00";
   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";

   //Billable enum is : 1 = Y, 2 = N, so
   if ($n_billable == "True") { //null value passed
    $billit = "Y";
   } else {
     $billit = "N";
   }
   // Test block to printout values for testing purposes:
   //echo "job_id = $n_jobnum <br>";
   //echo "account_id = $n_employee <br>";
   //echo "work_catagory_id = $n_catagory <br>";
   //echo "work_date = $worked_date_sql <br>";
   //echo "start_time = $starttime <br>";
   //echo "end_time = $endtime <br>";
   //echo "num_hours = $n_whours <br>";
   //echo "detail_billable = $billit <br>";
   //echo "comments = $n_comments <br>";
   //exit;
   // End test block
   // For now, let's just build the sql statement:
   if($n_jobnum && $n_employee && $n_catagory && $worked_date_sql && $n_whours) {
     $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_jobnum','$n_employee','$n_catagory','$worked_date_sql','$starttime',"
	. "'$endtime','$n_whours','$billit','" . addslashes($n_comments) . "')";
    $phpgw->db->query($newjobdetail_sql);
    echo '<script LANGUAGE="JavaScript">';
    echo 'window.location="' . $phpgw->link("index.php") . '"';
    echo '</script>';
  } else {
    // Error:
    inc_myutil();
    echo "You forgot something that was needed! Use your back button to correct.";
    // added a little something to wake-up the user regarding his mistakes.
    echo "<script LANGUAGE=\"JavaScript1.2\">shake(2);</script>";
  }

  } // end submit
else
  {
   inc_cal(); // Init js calendar datepicker
   inc_myutil(); // validation routines, etc for form inputs
     ?>
	 <center><h3>Job Detail Entry</h3></center>
       <?php
         // Get the userid so we can put it in a hidden form element
        $phpgw->db->query("select account_id,account_firstname,account_lastname from accounts where account_lid='"
		. $phpgw_info["user"]["userid"] . "'");
	$phpgw->db->next_record();
	$n_employee = $phpgw->db->f("account_id");
	$employee_name = $phpgw->db->f("account_firstname") . " " . $phpgw->db->f("account_lastname");
        echo '<center><h4>for ' . $employee_name . '</h4></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>
	 <input type=hidden name=n_employee value="<?php echo $n_employee; ?>">
         <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 "Job Number"; ?></td>
             <td><select name="n_jobnum">
                
		<?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 {
		  $jobnum_sql = "select job_id,job_number,job_revision,summary from jobs where company_id = '$cust'"
                    . " order by job_number desc,job_revision desc";
		   $phpgw->db->query($jobnum_sql);
		   $test_result = $phpgw->db->num_rows();
		   if ($test_result == 0) {
		     echo'<option value="">No Match</option>';
		   }
		  while ($phpgw->db->next_record()) {
		   $njobid = $phpgw->db->f("job_id");
		   $job_name = $phpgw->db->f("job_number") . $phpgw->db->f("job_revision")
			. " - " . $phpgw->db->f("summary");
		    echo '<option value="' . $njobid . '">' . $job_name . '</option>';
		  }
		}
                ?>
             </select></td>
           </tr>
           <tr>
             <td><?php echo "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 . '">' . $n_catname . '</option>';
		   }
		?>
	     </select></td>
           </tr>
           <tr>
             <td><?php echo "Date Worked"; ?></td>
             <td>
		<?php 
		  //DateSelector("worked",time());
		  //CalDateSelector("jobform","workdate",0,"INLINE");
                  CalDateSelector("jobform","workdate",0,"");
		  //echo '</td><td>';
		  //cal_layer(600,120);
		?>
	     </td>
           </tr>
           <tr>
             <td><?php echo "Start Time"; ?></td>
             <td>
		<?php 
		  //TimeSelector("n_start_time");
		  TimeSelect3("jobform","n_start_time",0);
		?>
	     </td>
           </tr>
           <tr>
             <td><?php echo "End Time"; ?></td>
             <td>
                <?php
                   TimeSelect3("jobform","n_end_time",0);
                ?>
             </td>
           </tr>
           <tr>
             <td><?php echo "Hours Worked"; ?></td>
             <td><input name="n_whours" size="8" maxlength="6"
			onFocus="this.blur();"
		         onBlur="CheckNum(this,0,24);"
		  value="<?php echo $n_whours; ?>">
                 <input type=button name="calctime" value="Update"
                   onclick="gethours('jobform','n_whours','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_billable" value="True" CHECKED></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 colspan=2>
              <input type="submit" name="submit" value="<?php echo lang("submit"); ?>"
               onclick="gethours('jobform','n_whours','n_start_time','n_end_time')";>
             </td>
           </tr>
         </table>
        </center>
       </form>
     <?php
     $phpgw->common->phpgw_footer();
  }
?>
Return current item: Phpgw Time Tracking Add On App