dudegio 0 Junior Poster in Training

Greetings to everyone!!!

I am editing a program in Php 4 generated in a CodeCharge 2.0.5. The last and only task i found trouble with is saving information of a billing statement to the database. I can display the information to the textboxes but i dont know how to create a function in saving it to the database by creating an event for a command button due to the fact that i find it hard in tracing the code generated from the third party. Some of the data to be saved in database are in bold format. Below is the code generated in HTML and Php file. Please help me.... Thanks......

<html>
<head>
<title>PJS Billing System</title>
<meta name="GENERATOR" content="YesSoftware CodeCharge v.2.0.5 / Templates.ccp build 11/01/2001">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script language="Javascript">
<!--
// ***********************************************
// AUTHOR: [URL="http://www.CGISCRIPT.NET"]WWW.CGISCRIPT.NET[/URL], LLC
// URL: [URL]http://www.cgiscript.net[/URL]
// Use the script, just leave this message intact.
// Download your FREE CGI/Perl Scripts today!
// ( [URL]http://www.cgiscript.net/scripts.htm[/URL] )
// ***********************************************
//window.moveTo(0,0)
//window.resizeTo(screen.width,screen.height)
//newWindow = window.open("", "printWind", "resizable")
//newWindow.print();
//-->
</script>
<style type="text/css">
<!--
.style6 {font-family: Arial, Helvetica, sans-serif; font-size: 12px; }
-->
</style>
</head>
<body style="background-color: #FFFFFF; color: #000000">
{Header}<center>
<table>
      <td><img src="pjs1.bmp"> 
      <td>
        <h1> <font size="4" face="Courier New, Courier, mono">Puyat Jacinto &amp; 
          Santos Law Office</font></h1>
        <h1 align="center"><font face="Courier New, Courier, mono" size="3">12th 
          Floor, Manila Bank Building</font><font face="Courier New, Courier, mono"><br>
          <font size="3">Ayala Avenue, Makati City<br>
          Tel. No 840-5025/ Fax 810-0890<br>
          TIN 005299549</font></font></h1>
        <h1 align="center"><font face="Courier New, Courier, mono" size="4"><b><font size="5">BILLING 
          STATEMENT</font></b></font></h1>
  </table>
</center>

<table width="100%">
  <tr>
    <td valign="top"> 
      <!--BeginFormHeadingHeader-->
      <!--EndFormHeadingHeader-->
      <!--BeginFormHeading-->
      <table style="border: 0px solid lightgray; width=100%" width="100%">
        <tr> 
          <td colspan="3" style="background-color: white"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">{sdate}</font></td>
          <td style="background-color: white" align="right"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">BS# 
            {bsnum}<input type="text" name="bsnumber" value="[B]{bsnum}[/B]" size="10"> 
   </font></td>
        </tr>
        <tr> 
          <td style="background-color: white" colspan="4"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica"><br>
            [B]{client_name}[/B]</font></td>
        </tr>
        <tr> 
          <td style="background-color: white" colspan="3"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">{address1}</font></td>
          <td width="40%" style="background-color: white"><span class="style6"> 
            <input type="checkbox" name="checkbox" value="checkbox">
            By hand</span></td>
        </tr>
        <tr> 
          <td style="background-color: white" colspan="3"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">{address2}</font></td>
          <td style="background-color: white"><span class="style6"> 
            <input type="checkbox" name="checkbox2" value="checkbox">
            By mail</span></td>
        </tr>
        <tr> 
          <td style="background-color: white" colspan="3"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">{address3}</font></td>
          <td style="background-color: white"><span class="style6"> 
            <input type="checkbox" name="checkbox3" value="checkbox">
            By email </span></td>
        </tr>
        <tr> 
          <td style="background-color: white" colspan="4"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica"><br>
            Attention: {contact} - {designation}</font></td>
        </tr>
        <tr> 
          <td style="background-color: white" colspan="4"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">{statement}</font></td>
        </tr>
        <tr> 
          <td style="background-color: white" colspan="4"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica"><br>
            <b>Re: Legal Services([B]{matter_nick}[/B]) 
            <p> </b></font></td>
        </tr>
        <tr> 
          <td style="background-color: white" colspan="4"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">{legalservices}</font></td>
        </tr>
        <tr> 
          <td style="background-color: white" colspan="4"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">{from_date} 
            to {to_date}</font></td>
        </tr>
        <tr> 
          <td colspan="3" style="background-color: white"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">as 
            per attached description. </font></td>
          <td style="background-color: white" align="right"><span style="font-weight: bold"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica"> 
            {currency} {total_amount1}</font></span></td>
        </tr>
        <tr> 
          <td style="background-color: white" colspan="4">&nbsp;</td>
        </tr>
        <tr> 
          <td colspan="3" style="background-color: white"><span style="font-weight: bold"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">DISBURSEMENTS</font></span></td>
          <td style="background-color: white">&nbsp;</td>
        </tr>
        <tr> 
          <td width="40" style="background-color: white"><div align="left"></div></td>
          <td style="background-color: white"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">{exp_print1}</font></td>
          <td style="background-color: white"><div align="right"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">PHP 
              {exp_print2}</font></div></td>
          <td style="background-color: white"><div align="right"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica"> 
              </font></div></td>
        </tr>
        <tr> 
          <td style="background-color: white"><div align="right"></div></td>
          <td colspan="2" style="background-color: white"> <div align="left"><span style=""><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">TOTAL 
              DISBURSEMENTS</font></span></div></td>
          <td style="background-color: white"><div align="right"><span style="font-weight: bold"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica"> 
              <strong>{currency}</strong> {total_expenses}</font></span></div></td>
        </tr>
        <tr> 
          <td colspan="3" style="background-color: white"><span style=""><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">VALUE 
            ADDED TAX</font></span></td>
          <td style="background-color: white"><div align="right"><strong><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">{exp_vat}</font></strong></div></td>
        </tr>
        <tr> 
          <td colspan="3" style="background-color: white"><p><span style=""><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">Available 
              Deposit on Expenses as of {previous_date}<br>
              </font><span style=""><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">Available 
              Deposit on Expenses as of {to_date}</font></span></span></p></td>
          <td style="background-color: white"><div align="right"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">{availdep1}<br>
              </font><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica"><strong>{currency} 
              {availdep2}</strong></font></div></td>
        </tr>
        <tr> 
          <td colspan="3" style="background-color: white">&nbsp;</td>
          <td style="background-color: white">&nbsp;</td>
        </tr>
        <tr> 
          <td colspan="3" style="background-color: white"><span style=""><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica"> 
            VALUE ADDED TAX</font></span></td>
          <td style="background-color: white"><div align="right"><strong><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">{vat}</font></strong></div></td>
        </tr>
        <tr> 
          <td colspan="3" style="background-color: white"><span style=""><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">TOTAL 
            LEGAL FEES &amp; DISBURSEMENTS</font></span></td>
          <td style="background-color: white"><div align="right"><strong><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica"><span style="font-weight: bold"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">{currency} 
              </font></span>{total_fees}</font></strong></div></td>
        </tr>
        <tr> 
          <td colspan="3" style="background-color: white"><span style=""><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">Outstanding 
            Legal fees and disbursements as of {previous_date} </font></span></td>
          <td style="background-color: white"><div align="right"><strong><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica"><span style="font-weight: bold"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">{currency} 
              </font></span>{outstanding_fees}<br>
              <span style="font-weight: bold"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica"><span style="font-weight: bold"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica"><span style="font-weight: bold"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">----------------------</font></font></font></font></font></font></span></font></span></font></span> 
              </font></strong></div></td>
        </tr>
        <tr> 
          <td colspan="3" style="background-color: white">&nbsp;</td>
          <td style="background-color: white">&nbsp;</td>
        </tr>
        <tr> 
          <td colspan="3" style="background-color: white"><span style=""><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">TOTAL 
            LEGAL FEES &amp; DISBURSEMENTS as of {to_date} </font></span></td>
          <td style="background-color: white"><div align="right"><strong><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">{currency} 
              {total_fees1}<br>
              <strong>======================</strong> </font></strong></div></td>
        </tr>
        <tr> 
          <td style="background-color: white" colspan="4">&nbsp;</td>
        </tr>
        <tr> 
          <td colspan="3" style="background-color: white"><span style=""><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">Prepared 
            by: </font></span></td>
          <td style="background-color: white"><span style=""><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">Noted 
            by:</font></span></td>
        </tr>
        <tr> 
          <td colspan="3" style="background-color: white">&nbsp;</td>
          <td style="background-color: white">&nbsp;</td>
        </tr>
        <tr> 
          <td colspan="3" style="background-color: white">&nbsp;</td>
          <td style="background-color: white">&nbsp;</td>
        </tr>
        <tr> 
          <td colspan="3" style="background-color: white"><span style=""><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">Emie 
            C. Romero</font></span></td>
          <td style="background-color: white"><span style=""><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">Regina 
            Jacinto-Barrientos </font></span></td>
        </tr>
        <tr> 
          <td colspan="3" style="background-color: white">&nbsp;</td>
          <td style="background-color: white"><span style=""><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">Managing 
            Partner </font></span></td>
        </tr>
        <tr> 
          <td style="background-color: white" colspan="4">&nbsp;</td>
        </tr>
        <tr> 
          <td style="background-color: white" colspan="4"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">{pagebreak}</font></td>
        </tr>
      </table>
<!--EndFormHeading-->
      <!--BeginFormHeadingFooter-->
      <!--EndFormHeadingFooter-->
    </td>
  </tr>
</table>
</form>

<table width="100%">
  <tr>
   <td valign="top">
   <!--BeginFormserviceHeader-->

   <!--EndFormserviceHeader-->
   <!--BeginFormservice-->
      <table style="border: 0px solid lightgray; width=100%" width="100%">
        <tr> 
          <td style="border-left: 1px gray solid;border-top: 1px gray solid;border-bottom: 1px gray solid; border-right: 1px gray solid; background-color: #EEEEEE; text-align: center" colspan="5"><a name="service"><font style="font-size: 12pt; color: black; font-weight: bold; font-family: Courier New, Arial, Tahoma, Verdana, Helvetica">{FormTitle}</font></a></td>
        </tr>
        <tr> 
          <td style="border-left: 1px gray solid;border-top: 1px gray solid;border-right: 1px solid gray; border-bottom: 1px solid gray; background-color: #EEEEEE" align="center"><font style="font-size: 10pt; color: black; font-weight: bold; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">Date</font></td>
          <td style="border-left: 1px gray solid;border-top: 1px gray solid;border-right: 1px solid gray; border-bottom: 1px solid gray; background-color: #EEEEEE" align="center"><font style="font-size: 10pt; color: black; font-weight: bold; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">Description</font></td>
          <td style="border-left: 1px gray solid;border-top: 1px gray solid;border-right: 1px solid gray; border-bottom: 1px solid gray; background-color: #EEEEEE" align="center"><font style="font-size: 10pt; color: black; font-weight: bold; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">Time</font></td>
          <td style="border-left: 1px gray solid;border-top: 1px gray solid;border-right: 1px solid gray; border-bottom: 1px solid gray; background-color: #EEEEEE" align="center"><font style="font-size: 10pt; color: black; font-weight: bold; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">Rate</font></td>
          <td style="border-left: 1px gray solid;border-top: 1px gray solid;border-right: 1px solid gray; border-bottom: 1px solid gray; background-color: #EEEEEE" align="center"><font style="font-size: 10pt; color: black; font-weight: bold; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">Amount</font></td>
        </tr>
        <!--BeginDListservice-->
        <tr> 
          <td colspan="5" style="background-color: white"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">{label1}</font></td>
        </tr>
        <tr> 
          <td style="background-color: white" rowspan="2" valign="top"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">{date}&nbsp;</font></td>
          <td style="background-color: white"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">[B]{service_description}[/B]&nbsp;<br>
              <font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">
              <textarea rows="3" name="description" cols="90">{service_description}</textarea>
          </font></font></td>
          <td style="background-color: white" rowspan="2" align="center" valign="top"> 
            <div align="center"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">{time}&nbsp;</font></div>          </td>
          <td style="background-color: white" rowspan="2" align="center" valign="top"> 
            <div align="center"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">{rate}&nbsp;</font></div>          </td>
          <td style="background-color: white" rowspan="2" align="right" valign="top"> 
            <div align="center">
              <p><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">{amount}</font></p>
            </div>          </td>
        </tr>
        <tr> 
          <td style="background-color: white" align="center"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">{attorney_id}</font></td>
        </tr>
        <tr> 
          <td colspan="5" style="background-color: white">&nbsp;</td>
        </tr>
        <!--EndDListservice-->
        <!--BeginserviceNoRecords-->
        <tr> 
          <td colspan="5" style="background-color: white"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">No 
            records</font></td>
        </tr>
        <!--EndserviceNoRecords-->
      </table>
   <!--EndFormservice-->
   <!--BeginFormserviceFooter-->

   <!--EndFormserviceFooter-->
   </td>
  </tr>
</table>

<table align="right">
  <tr> 
    <td valign="top"> 
      <!--BeginFormForm1Header-->
      <!--EndFormForm1Header-->
      <!--BeginFormForm1-->
      <table cellpadding="6" style="border: 0px solid lightgray; width=100%">
        <tr> 
          <td style="background-color: white" align="right"> 
            <div align="right"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica"><b>T</b></font><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica"><b>otal 
              Hours:<br>
            </b></font><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica"><b>Total 
              Amount: </b></font></div>
          </td>
          <td style="background-color: white" align="right"> 
            <p align="right"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica"><b>{total_hours}<br>
            </b></font><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica"><b>{currency} 
              {total_amount}</b></font><br> 
            </p>
          </td>
        </tr>
        <tr>
          <td colspan="2" align="right" style="background-color: white"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica">{package_note}</font></td>
        </tr>
        <tr>
          <td style="background-color: white" align="right"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica"><b>{cap_amount_label}</b></font><br>
            <font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica"><b>{cap_balance_label}</b></font></td>
          <td style="background-color: white" align="right"><font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica"><b>{cap_amount}</b></font><br>
          <font style="font-size: 10pt; color: #000000; font-family: Courier, Arial, Tahoma, Verdana, Helvetica"><b>{cap_balance}</b></font></td>
        </tr>
      </table>
      <!--EndFormForm1-->
      <!--BeginFormForm1Footer-->
      <!--EndFormForm1Footer-->
    </td>
  </tr>
</table>
<br>
<p>&nbsp;</p>
<p><br>
  <br>
</p>
<p>{Footer1} </p>
</body>
</html>





<?php
/*********************************************************************************
 *       Filename: BillingRegularDetailed.php
 *       Generated with CodeCharge 2.0.5
 *       PHP 4.0 & Templates build 11/30/2001
 *********************************************************************************/
//-------------------------------
// BillingRegularDetailed CustomIncludes begin
include ("./common.php");
include ("./header.php");
include ("./footer.php");
// BillingRegularDetailed CustomIncludes end
//-------------------------------
session_start();
//===============================
// Save Page and File Name available into variables
//-------------------------------
$filename = "BillingRegularDetailedSave.php";
$template_filename = "BillingRegularDetailedSave.html";
//===============================

//===============================
// BillingRegularDetailed PageSecurity begin
// BillingRegularDetailed PageSecurity end
//===============================
//===============================
// BillingRegularDetailed Open Event begin
$total_amount=0;
// BillingRegularDetailed Open Event end
//===============================

//===============================
//Save the name of the form and type of action into the variables
//-------------------------------
$sAction = get_param("FormAction");
$sForm = get_param("FormName");
//===============================
$sHeadingErr = "";

switch ($sForm) {
  case "Heading":
    Heading_action($sAction);
  break;
}
//-------------------------------
// BillingRegularDetailed CustomShowPage Event begin
//===============================
// Display page
//-------------------------------
// Load HTML template for this page
//-------------------------------
$tpl = new Template($app_path);
$tpl->load_file($template_filename, "main");
//-------------------------------
// Load HTML template of Header and Footer
//-------------------------------
$tpl->load_file($header_filename, "blank");
if (get_param("print")<>1)
$tpl->load_file($footer_filename, "Footer");
//-------------------------------
$tpl->set_var("FileName", $filename);

//-------------------------------
// Step through each form
//-------------------------------
if (get_param("print")<>1)  footer1_show();
service_show();Heading_show();Form1_show();
//-------------------------------
// Process page templates
//-------------------------------
$tpl->parse("blank", false);
$tpl->parse("Footer", false);
//-------------------------------
// Output the page to the browser
//-------------------------------
$tpl->pparse("main", false);
// BillingRegularDetailed CustomShowPage Event end
//-------------------------------
//===============================
// BillingRegularDetailed Close Event begin
// BillingRegularDetailed Close Event end
//===============================
//********************************************************************************

//===============================
// Display Grid Form
//-------------------------------
$SQL = "";
function service_show()
{
//-------------------------------
// Initialize variables  
//-------------------------------

  global $tpl;
  global $db;
  global $sserviceErr;
  $sWhere = "";
  $sOrder = "";
  $sSQL = "";
  $sFormTitle = "Services";
  $HasParam = false;
  $bReq = true;
  $iTmpI = 0;
  $iTmpJ = 0;
  $sCountSQL = "";
  $master_id = get_param("master_id");
  $tpl->set_var("TransitParams", "master_id=" . tourl(get_param("master_id")) . "&");
  $tpl->set_var("FormParams", "master_id=" . tourl(get_param("master_id")) . "&");

//-------------------------------
// Build WHERE statement
//-------------------------------
  $pBillDateFrom = get_session("BillDateFrom");
  if(strlen($pBillDateFrom))
  {
    $HasParam = true;
    $sWhere = $sWhere . "s.date>=" . tosql($pBillDateFrom, "Text") . "";
  }
  else
  {
    $bReq = false;
  }
  $pBillDateTo = get_session("BillDateTo");
  if(strlen($pBillDateTo))
  {
    if($sWhere != "") 
      $sWhere .= " and ";
    $HasParam = true;
    $sWhere = $sWhere . "s.date<=" . tosql($pBillDateTo, "Text") . "";
  }
  else
  {
    $bReq = false;
  }
  $pmaster_id = get_param("master_id");
  if(strlen($pmaster_id))
  {
    if($sWhere != "") 
      $sWhere .= " and ";
    $HasParam = true;
    $sWhere = $sWhere . "s.matter_id=" . tosql($pmaster_id, "Text") . "";
  }
  else
  {
    $bReq = false;
  }

  if($HasParam)
    $sWhere = " AND (per_appearance=0) AND (" . $sWhere . ")";
  else
    $sWhere = " AND per_appearance=0";
//-------------------------------
// Build ORDER BY statement
//-------------------------------
  $sOrder = " order by s.date Asc, s.attorney_id Desc";
//-------------------------------
// Build base SQL statement
//-------------------------------
  $sSQL = "select s.attorney_id as s_attorney_id, " . 
    "s.client_id as s_client_id, " . 
    "s.date as s_date, " . 
    "s.matter_id as s_matter_id, " . 
    "s.service_description as s_service_description, " . 
    "s.time as s_time, " . 
    "a.attorney_id as a_attorney_id, " . 
    "a.attorney_nick as a_attorney_nick " . 
    " from service s, attorney a" . 
    " where a.attorney_id=s.attorney_id  ";
//-------------------------------
//-------------------------------
// service Open Event begin
global $total;
global $SQL;
$exceeded=0;
$item=1;
$atty_rate2=0;
$amount=0;
global $total_hours;
$numrecs=dlookup("service", "count(*)", "matter_id=" . "'" . get_param("master_id") . "' and per_appearance=0 and date>=" . tosql($pBillDateFrom, "Text") . " and date<=" . tosql($pBillDateTo, "Text") ); 
//$tpl->set_var ("total_count", $numrecs);
// service Open Event end
//-------------------------------
//-------------------------------
// Assemble full SQL statement
//-------------------------------
  $sSQL .= $sWhere . $sOrder;
  if($sCountSQL == "")
  {
    $iTmpI = strpos(strtolower($sSQL), "select");
    $iTmpJ = strpos(strtolower($sSQL), "from") - 1;
    $sCountSQL = str_replace(substr($sSQL, $iTmpI + 6, $iTmpJ - $iTmpI - 6), " count(*) ", $sSQL);
    $iTmpI = strpos(strtolower($sCountSQL), "order by");
    if($iTmpI > 1) 
      $sCountSQL = substr($sCountSQL, 0, $iTmpI - 1);
  }
//-------------------------------
  $tpl->set_var("FormTitle", $sFormTitle);
//-------------------------------
// Process if form has all required parameter
//-------------------------------
  if(!$bReq)
  {
    $tpl->set_var("DListservice", "");
    $tpl->parse("serviceNoRecords", false);
    $tpl->parse("Formservice", false);
    return;
  }
//-------------------------------
//-------------------------------
// Execute SQL statement
//-------------------------------
  $SQL = $sSQL; 
  $db->query($sSQL);
  $next_record = $db->next_record();
//-------------------------------
// Process empty recordset
//-------------------------------
  if(!$next_record)
  {  
  $tpl->set_var ("total_hours", number_format($total_hours,2));
  $tpl->set_var("total_amount", tohtml(number_format($total_amount,2)));
  $tpl->parse("DListservice", true);
  $tpl->set_var( "serviceNoRecords", "");
  $tpl->parse( "Formservice", false);
  return;
  }
//-------------------------------

//-------------------------------
// Display grid based on recordset
//-------------------------------
  while($next_record )
  {
//-------------------------------
// Create field variables based on database fields
//-------------------------------
    $fldattorney_id = $db->f("a_attorney_nick");
    $fldclient_id = $db->f("s_client_id");
    $flddate = $db->f("s_date");
    $fldmatter_id = $db->f("s_matter_id");
    $fldservice_description = $db->f("s_service_description");
    $fldtime = $db->f("s_time");
    $next_record = $db->next_record();
    $curr_date = $flddate;
//-------------------------------
// service CustomShow Event begin
//-------------------------------
//-------------------------------
// Replace Template fields with database values
//-------------------------------

      $tpl->set_var("item", tohtml($flditem));
      $tpl->set_var("matter_id", tohtml($fldmatter_id));
      $tpl->set_var("client_id", tohtml($fldclient_id));
      $tpl->set_var("date", tohtml(date1($flddate)));
      $tpl->set_var("service_description", tohtml($fldservice_description));
      $tpl->set_var("attorney_id", tohtml(get_atty_fullname($fldattorney_id)));
      $tpl->set_var("time", tohtml(number_format($fldtime,2)));

      $total_hours=$total_hours+$fldtime;
      $atty_id = dlookup("attorney", "attorney_id", "attorney_nick='$fldattorney_id'");  
      $level = get_attylevel($atty_id,$flddate);
      $package = get_billingmode($fldmatter_id,$flddate);
      $pa_package = get_pa_billingmode($fldmatter_id,$flddate);

      if ($package=="moving monthly retainer") {
        $retainer_amount = dlookup("billing","package_amount","master_id='$fldmatter_id' AND from_date<='$flddate' AND to_date>='$flddate'");
        $amount = compute_retainer($fldmatter_id, $atty_id, $level, $flddate, $fldtime, $fldclient_id, $package, $pa_package, $fldper_appearance);
        $atty_rate = compute_retainer($fldmatter_id, $atty_id, $level, $flddate, 1.0, $fldclient_id, $package, $pa_package, $fldper_appearance);
        $trial_amount = $total + $amount;
        if ($trial_amount > $retainer_amount) {
          if ($exceeded==0) {
            $exceeded=1;
            $retainer_bal = round($retainer_amount - $total,2);
            $retainer_rate = compute_retainer($fldmatter_id, $atty_id, $level, $flddate, 1.0, $fldclient_id, $package, $pa_package, $fldper_appearance);
            $retainer_time = round($retainer_bal/$atty_rate,2);
            $retainer_amount = round(compute_retainer($fldmatter_id, $atty_id, $level, $flddate, $retainer_time, $fldclient_id, $package, $pa_package, $fldper_appearance),2);
            $regular_time = round($fldtime-$retainer_time,2);
            $regular_amount = compute_regular($fldmatter_id, $atty_id, $level, $flddate, $regular_time, $fldclient_id, $package, $pa_package, $fldper_appearance);
            $regular_rate = compute_regular($fldmatter_id, $atty_id, $level, $flddate, 1.0, $fldclient_id, $package, $pa_package, $fldper_appearance);

            //$atty_rate = number_format($retainer_rate,2) . "<br>" . number_format($regular_rate,2);
            $amount = round($retainer_amount+$regular_amount,2);
            $tpl->set_var("time", number_format($retainer_time,2) . "<br>" . number_format($regular_time,2) . "<br>");
            $tpl->set_var("rate", number_format($retainer_rate,2) . "<br>" . number_format($regular_rate,2) . "<br>");
            } 
          else { 
            $amount = round(compute_regular($fldmatter_id, $atty_id, $level, $flddate, $fldtime, $fldclient_id, $package, $pa_package, $fldper_appearance),2);
            $atty_rate = compute_regular($fldmatter_id, $atty_id, $level, $flddate, 1.0, $fldclient_id, $package, $pa_package, $fldper_appearance);
            $tpl->set_var("rate", tohtml(number_format($atty_rate,2)));
            }
          }
        else { 
          $tpl->set_var("rate", tohtml(number_format($atty_rate,2)));
          }  
        }
      else {
        $amount = round(compute_regular($fldmatter_id, $atty_id, $level, $flddate, $fldtime, $fldclient_id, $package, $pa_package, $fldper_appearance),2);
        $atty_rate = compute_regular($fldmatter_id, $atty_id, $level, $flddate, 1.0, $fldclient_id, $package, $pa_package, $fldper_appearance);   
        $tpl->set_var("rate", tohtml(number_format($atty_rate,2)));
        }
      $fldamount = $amount;
      $total = round($total + $amount,2);
      $total_amount = $total;     
      //check cap
      if ($package=="one-time package" OR $package=="fixed monthly retainer") {
        if ($package=="one-time package") $tpl->set_var("package_note", "One time package");
        $total = dlookup("billing","package_amount","master_id='$master_id' AND to_days('" . get_session("BillDateFrom") . "') >= to_days(from_date) AND to_days('" . get_session("BillDateTo") . "') <= to_days(to_date)");
        $total_amount = $total;
        }
      else {
        $package_amount = dlookup("billing","package_amount","master_id='$master_id' AND to_days('" . get_session("BillDateFrom") . "') >= to_days(from_date) AND to_days('" . get_session("BillDateTo") . "') <= to_days(to_date)");
        $cap_amount = dlookup("billing","cap_amount","master_id='$master_id' AND to_days('" . get_session("BillDateFrom") . "') >= to_days(from_date) AND to_days('" . get_session("BillDateTo") . "') <= to_days(to_date)");
        if ($total<$package_amount) $total_amount = $package_amount;
        if (dlookup("billing","cap","master_id='$master_id' AND to_days('" . get_session("BillDateFrom") . "') >= to_days(from_date) AND to_days('" . get_session("BillDateTo") . "') <= to_days(to_date)")){
          $capped=1;
          $total_raw = $total;
          if ($total > $cap_amount) {
            $total = $cap_amount;
            $total_amount = $total;
            }
          }
         else $capped=0; 
        }
      $tpl->set_var("amount", tohtml(number_format($fldamount,2)));
      $tpl->set_var("total", tohtml(number_format($total,2)));
      $tpl->set_var("total_amount", tohtml(number_format($total_amount,2)));
      $tpl->parse("DListservice", true);
//-------------------------------
// service CustomShow Event end
//-------------------------------
//-------------------------------
// Move to the next record 
//-------------------------------

  }
//-------------------------------
// Finish form processing
//-------------------------------
  $tpl->set_var( "serviceNoRecords", "");
  $tpl->parse( "Formservice", false);
//-------------------------------
// service Close Event begin
$tpl->set_var ("total_amount", number_format($total_amount,2));
$tpl->set_var ("total_hours", number_format($total_hours,2));
if ($capped) {
  $tpl->set_var ("cap_amount_label", "Cap Amount:");
  $tpl->set_var ("cap_balance_label", "Cap Balance:");
  $tpl->set_var ("cap_amount", get_curr(get_param("master_id")) . " " . number_format($cap_amount,2));
  $tpl->set_var ("cap_balance", get_curr(get_param("master_id")) . " " . number_format($cap_amount-$total_raw,2));
  }
// service Close Event end
//-------------------------------
}
//===============================

//===============================
// Display Menu Form
//-------------------------------
function Heading_show()
{
  global $tpl;
  global $db;
  $sFormTitle = "";
  $total_expenses = 0.0;
  $total_amount = 0.0;
//-------------------------------
// Heading Open Event begin
$bsnum=get_param("bsnum");
$tpl->set_var("bsnum",$bsnum);
$currency = get_curr(get_param("master_id"));
$tpl->set_var("currency", $currency);
$ConvertFlag = get_param(tohtml("ConvertFlag"));
$ConvertRate = get_param(tohtml("ConvertRate"));
set_session("ConvertRate", "$ConvertRate");
$AvailableDeposit = get_param(tohtml("AvailableDeposit"));
$PreviousDate = get_param(tohtml("PreviousDate"));
$OutstandingLegal = get_param(tohtml("OutstandingLegal"));
//$db->query("insert into test values(".$db->f("bsnum").")");
$today = getdate(); 
$month = $today['month']; 
$mday = $today['mday']; 
$year = $today['year']; 
$tpl->set_var("sdate",$month ." " . $mday . ", " . $year);
$client_id=dlookup("matter", "client_id", "master_id=" . "'" . get_param("master_id") . "'" );
$client_name=dlookup("client", "client_name", "client_id='$client_id'");
$tpl->set_var("client_name",$client_name); 
$address1=dlookup("client", "street_address1", "client_id='$client_id'");
$address2=dlookup("client", "street_address2", "client_id='$client_id'");
$city=dlookup("client", "city", "client_id='$client_id'");
$zip=dlookup("client", "zipcode", "client_id='$client_id'");
$country=dlookup("client", "country", "client_id='$client_id'");
$address3=$city . " " . $country . " " . $zipcode;
$tpl->set_var("address1",$address1);
$tpl->set_var("address2",$address2);
$tpl->set_var("address3",$address3);
$contact=dlookup("matter", "contact_person1", "master_id=" . "'" . get_param("master_id") . "'" );
$designation=dlookup("matter", "designation1", "master_id=" . "'" . get_param("master_id") . "'" );
$tpl->set_var("contact",$contact);
$tpl->set_var("designation",$designation);
$total_pa = compute_patotal();
$total_legal = compute_detailedtotal();
$exp_print1 = "";
$exp_print2 = "";
$exp=compute_total_expenses("Miscellaneous", "total_misc");
//if ($exp>0) {
  $exp_print1 .= "Miscellaneous <br>";
  $exp_print2 .= number_format($exp,2) . "<br>";
  $total_expenses += $exp;
//  }
$exp=compute_total_expenses("Miscellaneous1", "total_misc");
//if ($exp>0) {
  $exp_print1 .= "Miscellaneous1 <br>";
  $exp_print2 .= number_format($exp,2) . "<br>";
  $total_expenses += $exp;
//  }
$exp=compute_total_expenses("Miscellaneous2", "total_misc");
//if ($exp>0) {
  $exp_print1 .= "Miscellaneous2 <br>";
  $exp_print2 .= number_format($exp,2) . "<br>";
  $total_expenses += $exp;
//  }
$exp=compute_total_expenses("Miscellaneous3", "total_misc");
//if ($exp>0) {
  $exp_print1 .= "Miscellaneous3 <br>";
  $exp_print2 .= number_format($exp,2) . "<br>";
  $total_expenses += $exp;
//  }
$exp=compute_total_expenses("Miscellaneous4", "total_misc");
//if ($exp>0) {
  $exp_print1 .= "Miscellaneous4 <br>";
  $exp_print2 .= number_format($exp,2) . "<br>";
  $total_expenses += $exp;
//  }
$exp=compute_total_expenses("Processing", "total_proc");
//if ($exp>0) {
  $exp_print1 .= "Processing <br>";
  $exp_print2 .= number_format($exp,2) . "<br>";
  $total_expenses += $exp;
//  }
$exp=compute_total_expenses("Photocopying", "total_proc");
//if ($exp>0) {
  $exp_print1 .= "Photocopying <br>";
  $exp_print2 .= number_format($exp,2) . "<br>";
  $total_expenses += $exp;
// }
$exp=compute_total_expenses("Printing", "total_proc");
//if ($exp>0) {
  $exp_print1 .= "Printing <br>";
  $exp_print2 .= number_format($exp,2) . "<br>";
  $total_expenses += $exp;
//  }
$exp=compute_total_expenses("Fax", "total_proc");
//if ($exp>0) {
  $exp_print1 .= "Fax <br>";
  $exp_print2 .= number_format($exp,2) . "<br>";
  $total_expenses += $exp;
//  }
$exp=compute_total_expenses("Telephone", "total_proc");
//if ($exp>0) {
  $exp_print1 .= "Telephone <br>";
  $exp_print2 .= number_format($exp,2) . "<br>";
  $total_expenses += $exp;
//  }  
$exp=compute_total_expenses("Postage", "total_proc");
//if ($exp>0) {
  $exp_print1 .= "Postage <br>";
  $exp_print2 .= number_format($exp,2) . "<br>";
  $total_expenses += $exp;
//  }
$exp=compute_total_expenses("Transportation", "total_proc");
//if ($exp>0) {
  $exp_print1 .= "Transportation <br>";
  $exp_print2 .= number_format($exp,2) . "<br>";
  $total_expenses += $exp;
//  }  
$tpl->set_var("total_amount1", number_format($total_legal+$total_pa,2));
$tpl->set_var("exp_print1", $exp_print1);
$tpl->set_var("exp_print2", $exp_print2);
if ($ConvertFlag == "on")
        $total_expenses = $total_expenses/$ConvertRate;
$tpl->set_var("total_expenses", number_format($total_expenses,2));
$exp_vat_amount = ($total_expenses)*(get_vat(get_session("BillDateFrom"))/100);
$tpl->set_var("exp_vat",number_format($exp_vat_amount,2));

$tpl->set_var("availdep1", "(" . number_format($AvailableDeposit,2) . ")");
$dep_balance = $AvailableDeposit - $total_expenses - $exp_vat_amount;
if ( $dep_balance < 0) {
  $dep_balance = 0;
  $total_expenses = $total_expenses+$exp_vat_amount- $AvailableDeposit;
  }
else 
  $total_expenses = 0;
$tpl->set_var("availdep2", "(" . number_format($dep_balance,2) . ")");
$vat_amount = ($total_legal+$total_pa)*(get_vat(get_session("BillDateFrom"))/100);
$tpl->set_var("vat",number_format($vat_amount,2));
$total_fees = $total_legal+$total_pa+$total_expenses+$vat_amount;
$tpl->set_var("total_fees",number_format($total_fees,2));
$tpl->set_var("from_date",date1(get_session("BillDateFrom")));
$tpl->set_var("to_date",date1(get_session("BillDateTo")));
$tpl->set_var("previous_date",$PreviousDate);
$tpl->set_var("outstanding_fees",number_format($OutstandingLegal, 2));
$tpl->set_var("total_fees1",number_format($OutstandingLegal + $total_fees,2));
$matter_nick=dlookup("matter", "matter_nick", "master_id=" . "'" . get_param("master_id") . "'" );
$tpl->set_var("matter_nick",$matter_nick);
// Heading Open Event end
//-------------------------------
//-------------------------------
// Set URLs
//-------------------------------
  $fldline1 = "{sdate}{bsnum}";
  $fldField1 = "<br>{client_name}";
  $fldField2 = "{address1}";
  $fldField3 = "{address2}";
  $fldField4 = "{address3}";
  $fldattention = "<br>Attention: {contact} - {designation}";
  $fldstatement = "<hr><b><center>S T A T E M E N T</b></center>";
  $fldreline = "<br><b>Re:   Legal Services({matter_nick})<p>";
  $fldlegalservices = "For LEGAL SERVICES rendered for";
  $flddaterange = "{from_date} to {to_date}";
  $fldamt = "as per attached description. PHP{total_amount}";
  $fldpagebreak = "<p style=\"page-break-after: always\">";
//-------------------------------
// Heading Show begin
//-------------------------------
$tpl->set_var("FormTitle", $sFormTitle);
//-------------------------------
// Heading BeforeShow Event begin
$tpl->set_var("FormHeading","");
// Heading BeforeShow Event end
//-------------------------------
//-------------------------------
// Show fields
//-------------------------------
  $tpl->set_var("line1", $fldline1);
  $tpl->set_var("Field1", $fldField1);
  $tpl->set_var("Field2", $fldField2);
  $tpl->set_var("Field3", $fldField3);
  $tpl->set_var("Field4", $fldField4);
  $tpl->set_var("attention", $fldattention);
  $tpl->set_var("statement", $fldstatement);
  $tpl->set_var("reline", $fldreline);
  $tpl->set_var("legalservices", $fldlegalservices);
  $tpl->set_var("daterange", $flddaterange);
  $tpl->set_var("amt", $fldamt);
  $tpl->set_var("pagebreak", $fldpagebreak);
  $tpl->parse("FormHeading", false);
//-------------------------------
// Heading Show end
//-------------------------------
}
//===============================
//===============================
// Display Menu Form
//-------------------------------
function Form1_show()
{
  global $tpl;
  global $db;
  $sFormTitle = "";
//-------------------------------
// Form1 Open Event begin
// Form1 Open Event end
//-------------------------------
//-------------------------------
// Set URLs
//-------------------------------
  $fldField1 = "<p><b>Total Amount: {total_amount}</b></p>";
//-------------------------------
// Form1 Show begin
//-------------------------------
  $tpl->set_var("FormTitle", $sFormTitle);
//-------------------------------
// Form1 BeforeShow Event begin
// Form1 BeforeShow Event end
//-------------------------------
//-------------------------------
// Show fields
//-------------------------------
  $tpl->set_var("Field1", $fldField1);
  $tpl->parse("FormForm1", false);
//-------------------------------
// Form1 Show end
//-------------------------------
}
//===============================
function Heading_action($sAction)
{
  global $db;
  global $tpl;
  global $sHeadingErr;
  global $filename;
  switch(strtolower($sAction))
  {
    case "save":
//-------------------------------
// Form1 Login begin
//-------------------------------
        $bsnum=get_param("bsnum");
  $tpl->set_var("bsnum",$bsnum);  
   set_session("UserID", $db->f("bs_number"));      


        $sPage = get_param("ret_page");
  $db->query("insert into test values(".$db->f("bs_number").")");
        if (strlen($sPage))
        {
          header("Location: " . $sPage . "?" . get_param("querystring"));
          exit;
        }
        else
        {
          header("Location: default.php");
          exit;
        }


//-------------------------------
// Form1 Login end
//-------------------------------
    break;
    case "logout": 

    break;
  }
}
//===============================
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.