Location: PHPKode > projects > Vehicle Service Tracker > VST/add.php
// add.php
// Form to add,error check and edit New vehicle repair orders
// Copyright (c) 2006 Kenneth J. Snyder
// Licensed under the GNU GPL. For full terms see the file LICENSE
// -------------------------------------------------------------------------
// Created: 10Mar2006 Snyder, Kenneth J. hide@address.com 
// Revised: 

<link rel='stylesheet' type='text/css' href='vst.css'>

if (isset($_REQUEST['SID'])) { $SID=$_REQUEST['SID']; } else { $SID=""; }
if (isset($_REQUEST['USERNAME'])) { $USERNAME=$_REQUEST['USERNAME'];} else { $USERNAME=""; }
$dbconn = odbc_connect("$dbname","$dbuid","$dbpasswd");
if ($dbconn==0) {
   $a = odbc_errormsg("DB2 Connect Failed. DB2 might not be running");
 } else {

                    $GASMILE,$IMAGE,$GORD,$MORK,$ODO,$DESC) {
     echo "<form method=post action=add.php>";
     echo "<table cellpadding='5'>";
     echo "<tr><td rowspan='8'><img src='$IMAGE'></td></tr>";
     echo "<tr><td align='right'><B>";
     echo "Odometer Reading</b></td><td>";
     echo "<input name=ODO type=text size=7 maxlength=7 value=$ODO>";
     echo "</td></tr><tr><td align='right'><B>";
     echo "General Short Decription of Service";
     echo "</b></td><td>";
     echo "<input name=DESC type=text size=60 maxlength=75 value=\"$DESC\">";
     echo "</td></tr>";
     echo "<input name=VIN type=hidden value=$VIN>";
     echo "<input name=YEAR type=hidden value=$YEAR>";
     echo "<input name=MAKE type=hidden value=\"$MAKE\">";
     echo "<input name=MODEL type=hidden value=\"$MODEL\">";
     echo "<input name=COLOR type=hidden value=$COLOR>";
     echo "<input name=SID type=hidden value=$SID>";
     echo "<input name=USERNAME type=hidden value=$USERNAME>";
     echo "<input name=IMAGE type=hidden value=$IMAGE>";
     echo "<input name=GASMILE type=hidden value=$GASMILE>";
     echo "<input name=GORD type=hidden value=$GORD>";
     echo "<input name=MORK type=hidden value=$MORK>";
     echo "</table>";
     echo "<p>";
     echo "<center><B>";
     echo "<input type='submit' name='addnewro' ";
     echo "value='Create New Service Record & Continue to Enter Line Items' ";
     echo "id='butt'></B></center>";
     echo "</form>";
   } // function show new ro form

   echo "<center><p class='Header1'>";
   echo "<title>Vehicle Service Tracker - Add A New Repair Order</title>";
   echo "<B>Vehicle Service Tracker - Add A New Repair Order</B></p></center>";

   if (isset($add)) {
    } else {
      // Ok the user is trying to create a brand new RO..lets check his input
      $LastODOSelect="select MILEAGE from VST.SERVICEHIST where VEHICLE='$VIN' ";
      $LastODOSelect.="order by MILEAGE DESC fetch first row only";
      if (! $LastODOResult ) die("Something went wrong with select last mileage");
      if ( $LastODO=="" ) $LastODO=0;

      if ( $ODO=="" ) {
         if (!isset($UIErrors)) $UIErrors="";
         $UIErrors.="<b><ul><li><font color=#ff0000>";
         $UIErrors.="You didn't enter the Vehicle's Odometer reading</font></li></ul></b>";
       } elseif (! is_numeric($ODO)) {
         if (!isset($UIErrors)) $UIErrors="";
         $UIErrors.="<b><ul><li><font color=#ff0000>";
         $UIErrors.="The odometer reading you entered [$ODO] is not a number";
       } elseif ($LastODO>$ODO) {
         if (!isset($UIErrors)) $UIErrors="";
         $UIErrors.="<b><ul><li><font color=#ff0000>";
         $UIErrors.="The odometer reading you entered [";
         $UIErrors.=number_format($ODO)."] is smaller than the ";
         $UIErrors.="last known odometer reading of [".number_format($LastODO)."]";
      if ( $DESC=="" ) {
         if (!isset($UIErrors)) $UIErrors="";
         $UIErrors.="<b><ul><li><font color=#ff0000>";
         $UIErrors.="You didn't enter a general Service Description</font></li></ul></b>";
      if (isset($UIErrors)) {
        echo "<b><center><font size=+1>";
        echo "There was trouble with proccessing your information.</font>";
        echo "</b></center>";
        echo $UIErrors;
       } else {
        // OK. Insert this new vehicle!

        // Generate a Uniq RO number
        // Strip off any tenths of odometer reading entered
        //Build the insert
        $MyInsert="insert into VST.SERVICEHIST ";
        $MyInsert.="(repair_order,vehicle,service_date,mileage,service_short) values ('";
        echo $MyInsert;
        // Perform the insert and redirect or die
        if (odbc_exec($dbconn,$MyInsert)) {
           $LIHeader="Location: addli.php?SID=$SID&USERNAME=$USERNAME&RO=$NRONum&FromNewRO=0";
         } else {
           die ("Something went wrong with repair order insert.");

      } // if ui errors or not

   } // if it's add or check add

} // if authorized to view this page

Return current item: Vehicle Service Tracker