Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 20th, 2005, 03:34 AM
Registered User
 
Join Date: Nov 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Non-Corresponding Array Indexes

Hello to everyone.

I’m reading the book: “Beginning PHP 4” by ****yu Choi, Allan Kent, Chris Lea, Ganesh Prasad, Chris Ullman, Jon Blank and Sean Cazzell first published in 2000 by Wrox. Although it might sound odd, reading a five years old book for PHP 4, when PHP 5 is already ageing, I’ll just answer that I had no time to read the book when I wanted to. Anyway, I’m traversing its contents and so far all go well and have reached chapter 7, at the regular expressions but, my problem has nothing to do with them.

I like to expand and try what I’ve learned in every chapter by making programs of my own. So far I’ve managed to create dynamic forms, and then showing their contents. This time I tried to do the following:

Take a number of employees and options as: "current tax rate", "welfare insurance rate" and if the company applies benefits for employees, like: if they are "$underage" or have "$underage kids", or are "$married" and if it is a "holiday" like Christmas etc.. If the company allows those benefits and the user checks the check box then he must also provide the present added on the primary salary value. When the user has added this data which on most cases are taken by droplists to minimize potential wrong data entries, we move to the second page.

Here we create a dynamic form for the number of employees supplied by the user on the previous page. Each line contains the following:
  • Increasing number (just a visual key/index)
  • A text filed to enter the employee’s name
  • A drop list to select the employee’s age.
  • Two radio buttons to select the employee’s gender
  • A check box to check if $Married = True (shown only if selected so in the first page)
  • A check box to check if $Parent = True (shown only if selected so in the first page)
  • A check box to which is selected and disabled (shown only if selected so in the first page)

Suppose we have entered the data for 10 employees and only 5 of them [u]are married</u> and those are selected in random order. When me click to go on the third and final page we pass the optional variables selected on the first page via hidden form elements, the rest of the data though is being tranfered via arrays like:
Code:
$EmployeesNames[], $EmployeesSex[] $EmployeesMarried[]
etc.

The big problem now is that as most of you have already assumed... That [u]the index keys of those arrays do NOT correspond which each others</u>. If, lets say, only the last 5 of the 10 employees were married and then we try to show the out coming data on a form (and of course, make the appropriate calculations for the salary depended on the $Married, $Parent etc. options) we’ll see that the first 5 employee’s will be shown as married and NOT the last 5 which would be the correct, altering also the out coming calculations.

So what I like to know is if you people know anyway to solve this problem, and if this can’t be done, what solutions you have come with to surpass this obstacle? I’ve been thiking of this problem the last few days but didn’t came up with any solution for it, probably cause of lack of experience and lack of further, advanced php use.

Any help would be welcomed. :)

The code so far of the three pages is listed below (and if copy-pasted on your notepad and saved as my_Employees(1 or 2 or 3).php they will be fully functional to help you understand what I'm trying to do (sorry if it looks too amateur and crappy).

- Pericles


FILE 01:
Quote:
quote:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1253">
<title>Monthly Employees’ Salary Calculation Form
(step 1 of 3)</title>

<style type="text/css">
<!--
BODY {
    PADDING-RIGHT: 10px;
    PADDING-LEFT: 10px;
    FONT-SIZE: 12px;
    PADDING-BOTTOM: 20px;
    MARGIN: 0px;
    COLOR: #000000;
    PADDING-TOP: 20px;
    FONT-FAMILY: Verdana, Tahoma, Arial, sans-serif;
    BACKGROUND-COLOR: #ffffff;
    TEXT-ALIGN: center
}
P{
  font-size : 9pt;
  font-family : Verdana,Arial;
  font-weight : normal;
  text-decoration : none;
}
TABLE{
  font-size : 9pt;
  font-family : Verdana,Arial;
  font-weight : normal;
  text-decoration : none;
}
.blue {
    BORDER-RIGHT: #000099 1px solid;
    \\PADDING-RIGHT: 5px;
    BORDER-TOP: #000099 1px solid;
    \\PADDING-LEFT: 5px;
    FONT-SIZE: 13px;
    \\PADDING-BOTTOM: 5px;
    BORDER-LEFT: #000099 1px solid;
    \\COLOR: #465584;
    COLOR: #000099;
    \\PADDING-TOP: 5px;
    BORDER-BOTTOM: #000099 1px solid;
    WHITE-SPACE: normal;
    BACKGROUND-COLOR: #e6f2ff;
    PADDING: 5px;
}
.red {
    BORDER-RIGHT: #ca0000 1px solid;
    BORDER-TOP: #ca0000 1px solid;
    FONT-SIZE: 13px;
    BORDER-LEFT: #ca0000 1px solid;
    COLOR: #ca0000;
    BORDER-BOTTOM: #ca0000 1px solid;
    WHITE-SPACE: normal;
    BACKGROUND-COLOR: #ffe1e1;
    PADDING: 5px;
}
-->
</style>

</head>
<body>
<h2>Monthly Employees’ Salary Calculation Form
(step 1 of 3)</h2>

<?php

################################################## ##########
# FUNCTION: f_CreateDropList #
# $ListName = The name for the List box (string) #
# $MinValue = Minimum value of the list (int) #
# $MaxValue = Maximum value of the list (int) #
# $$Step = Step of the increment numbers (int) #
################################################## ##########
function f_CreateDropList($ListName, $MinValue=1, $MaxValue=100, $Step=1)
{
  if ($MinValue >= $MaxValue) // If $MinValue > $MaxValue { Show error message }
  {
    echo ("<p><b>ERROR!<br>AT:</b> FUNCTION <code>f_CreateDropList(\$Name, \$MinValue, \$MaxValue, \$Step)</code><br><b>Type of error:</b> You have entered to <code>\"\$MinValue\"</code> a value [u]HIGHER</u> than <code>\"\$MaxValue\"</code>!</p>");
  }
  else
  {
    echo ("\n<select name=\"$ListName\">");
    for ($i=$MinValue; $i<=$MaxValue; $i+=$Step)
    {
      echo ("\n\t<option value=\"$i\">$i</option>");
    }
    echo ("\n</select>\n");
  }
  return;
}


?>
<form method="POST" action="my_employees_2.php">
<table border="0" width="400" cellpadding="0" cellspacing="1">
  <tbody>
    <tr>
      <td class="red" align="center"><b>INSTRUCTIONS</b></td>
    </tr>
    <tr>
      <td class="blue">
      <p align="justify">This program will help you calculate the
      monthly salaries of your employees.
      It takes
      in count several facts like:</p>
      <ol>
        <li>The total number of your employees
        <li>General options as:
        <ol>
          <li>Tax rate
          <li>Welfare insureance rate
          <li>Holiday benefits
        </ol>
        <li>Individual employee's options as:
        <ol>
          <li>Benefits for parents with underaged kids
          <li>Underageded employees
          <li>Benefits for married employees
        </ol>
        <li>Visual options which alter the final appearance
        of the outcoming forms.
      </ol>
      <p align="justify">In order to do all this, just fill the data
      carefully in the following forms and when
      you're ready click on the &quot;next&quot;
      button on the bottom of the page.</p>
      </td>
    </tr>
  </tbody>
</table><br>
<table border="0" cellpadding="0" cellspacing="1" width="400">
  <tbody>
    <tr>
      <td class="red" width="20" align="center"><b>1.</b></td>
      <td class="red" colspan="2" width="380"><b>Number Of Employees</b></td>
    </tr>
    <tr>
      <td class="blue" colspan="3" align="right">Insert the total number of your employees: <?php f_CreateDropList("TotalEmployees", 1, 100, 1); ?>&nbsp;&nbsp;&nbsp;</td>
    </tr>
  </tbody>
</table>
<br>
<table border="0" cellpadding="0" cellspacing="1" width="400">
  <tbody>
    <tr>
      <td class="red" align="center" width="20"><b>2.</b></td>
      <td class="red" colspan="2" width="380"><b>Options For Extra Benefit Calculations</b></td>
    </tr>
    <tr>
      <td class="blue">&nbsp;</td>
      <td class="blue" colspan="2"><b>Global options</b> (<i>Effect ALL Employees</i>)</td>
    </tr>
    <tr>
      <td class="blue"><input type="checkbox" name="Salary" checked disabled></td>
      <td class="blue" style="font-weight : bold;color : red;">SALARY</td>
      <td class="blue" align="right"><input size="6" name="Salary" type="text" maxlength="6">&nbsp; #8364;</td>
    </tr>
    <tr>
      <td class="blue"><input type="checkbox" name="TaxRate" checked disabled></td>
      <td class="blue">Current TAX rate</td>
      <td class="blue" align="right">Salary - <?php f_CreateDropList("TaxRate", 1, 100, 1); ?> %</td>
    </tr>
    <tr>
      <td class="blue"><input type="checkbox" name="WelfareInsurance" checked disabled></td>
      <td class="blue">Welfare Insurance rate</td>
      <td class="blue" align="right">Salary - <?php f_CreateDropList("WelfareInsurance", 1, 100, 1); ?> %</td>
    </tr>
    <tr>
      <td class="blue"><input type="checkbox" name="IsHoliday"></td>
      <td class="blue">Is Holiday (Christmas or easter)</td>
      <td class="blue" align="right">Salary + <?php f_CreateDropList("IsHolidayPercentage", 1, 100, 1); ?> %</td>
    </tr>
    <tr>
      <td class="blue">&nbsp;</td>
      <td class="blue" colspan="2"><b>Individual’s Options </b>(<i>effect workers individually</i>)</td>
    </tr>
    <tr>
      <td width="20" class="blue"><input type="checkbox" name="IsParent"></td>
      <td class="blue">Parent with underaged kids</td>
      <td class="blue" align="right">Salary + <?php f_CreateDropList("IsParentPercentage", 1, 100, 1); ?> %</td>
    </tr>
    <tr>
      <td class="blue"><input type="checkbox" name="IsUnderaged"></td>
      <td class="blue">Underaged worker under 21 y.o.</td>
      <td class="blue" align="right">Salary + <?php f_CreateDropList("IsUnderagedPercentage", 1, 100, 1); ?> %</td>
    </tr>
    <tr>
      <td class="blue"><input type="checkbox" name="IsMarried"></td>
      <td class="blue">Married</td>
      <td class="blue" align="right">Salary + <?php f_CreateDropList("IsMarriedPercentage", 1, 100, 1); ?> %</td>
    </tr>
  </tbody>
</table><br>
<table border="0" width="400" cellpadding="0" cellspacing="1">
  <tbody>
    <tr>
      <td width="20" align="center" class="red"><b>3.</b></td>
      <td class="red"><b>Visual Options</b> (<i>alters forms' apperance</i>)</td>
    </tr>
    <tr>
      <td class="blue">&nbsp;</td>
      <td class="blue">
      <table border="0" height="120" cellpadding="2" cellspacing="0">
        <tbody>
          <tr>
            <td rowspan="4"><img src="img/small_table.gif" width="130" height="120" border="0"></td>
            <td># <select name="ColorDark">
              <option value="003060" style="background-color : #003060; color: #ffffff;">003060</option>
              <option value="ff6600" style="background-color : #ff6600; color: #ffffff;">ff6600</option>
              <option value="000000" style="background-color : #000000; color: #ffffff;">000000</option>
              <option value="006600" style="background-color : #006600; color: #ffffff;">006600</option>
            </select></td>
          </tr>
          <tr>
            <td># <select name="ColorMedium">
              <option value="0057ae" style="background-color : #0057ae; color: #ffffff;">0057ae</option>
              <option value="ff954f" style="background-color : #ff954f; color: #ffffff;">ff954f</option>
              <option value="666666" style="background-color : #666666; color: #ffffff;">666666</option>
              <option value="00a800" style="background-color : #00a800; color: #00a800;">003060</option>
            </select></td>
          </tr>
          <tr>
            <td># <select name="ColorLight">
              <option value="d5eaff" style="background-color : #d5eaff; color: #ffffff;">d5eaff</option>
              <option value="ffd9bf" style="background-color : #ffd9bf; color: #ffffff;">ffd9bf</option>
              <option value="e4e4e4" style="background-color : #e4e4e4; color: #ffffff;">e4e4e4</option>
              <option value="caffca" style="background-color : #caffca; color: #ffffff;">caffca</option>
            </select></td>
          </tr>
          <tr>
            <td># <select name="ColorDarkColumn">
              <option value="aad5ff" style="background-color : #aad5ff; color: #ffffff;">aad5ff</option>
              <option value="ffc49b" style="background-color : #ffc49b; color: #ffffff;">ffc49b</option>
              <option value="cccccc" style="background-color : #cccccc; color: #ffffff;">cccccc</option>
              <option value="95ff95" style="background-color : #95ff95; color: #ffffff;">95ff95</option>
            </select></td>
          </tr>
        </tbody>
      </table>
      </td>
    </tr>
  </tbody>
</table><br>
<table border="0" width="400" cellpadding="0" cellspacing="1">
  <tbody>
    <tr>
      <td class="red" width="20" align="center"><b>4.</b></td>
      <td class="red"><b>Proceed to step 2</b></td>
    </tr>
    <tr>
      <td class="blue">&nbsp;</td>
      <td class="blue" align="center"><input type="reset" value="Clear All Data"> <input type="submit" value="Next &raquo;"></td>
    </tr>
  </tbody>
</table>
</form>
</body>
</html>
FILE 02:
 
Quote:
quote:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
Quote:
<html>
  <head>
   <meta http-equiv="Content-Type" content="text/html; charset=windows-1253">
    <title>Monthly Employees’ Salary Calculation Form (step 2 of 3)</title>
    <?php

    // Filtering all the potential HTML tags from the HTTP_POST_VARS Array.
    foreach ($HTTP_POST_VARS as $Index => $Value)
    {
      $Value = HTMLSpecialChars($Value);
      //echo ("$Index - $Value<br>");
    }

    // Setting Values to the Variables taken from the HTTP_POST_VARS Array.
    if (isset($HTTP_POST_VARS["TotalEmployees"])) $TotalEmployees = $HTTP_POST_VARS["TotalEmployees"];
    if (empty($HTTP_POST_VARS["Salary"])) //Checking IF the user entered a value on the Salary field.
    {
      echo ("\n<p>You have not entered the <b>Salary</b> amount for the calcuations<br>Please go back and fill in the monthly salary amount</p>");
      echo ("\n</body>\n</html>");
      exit;
    }
    elseif ($HTTP_POST_VARS["Salary"] <= 0) //Cheking if the number is positive and higher than 0.
    {
      echo ("\n<p>You have entered a non acceptable value in the <b>Salary field</b>.<br>Please go back and enter a valid, positive number</p>");
      echo ("\n</body></html>");
      exit;
    }
    else // If the number is valid -higher than 0- we proceed asighning the value to the variable.
    {
      $Salary = $HTTP_POST_VARS["Salary"];
    }
    if (isset($HTTP_POST_VARS["TaxRate"])) $TaxRate = $HTTP_POST_VARS["TaxRate"];
    if (isset($HTTP_POST_VARS["WelfareInsurance"])) $WelfareInsurance = $HTTP_POST_VARS["WelfareInsurance"];
    if (isset($HTTP_POST_VARS["IsHoliday"])) $IsHoliday = $HTTP_POST_VARS["IsHoliday"];
    if (isset($HTTP_POST_VARS["IsHolidayPercentage"])) $IsHolidayPercentage = $HTTP_POST_VARS["IsHolidayPercentage"];
    if (isset($HTTP_POST_VARS["IsParent"])) $IsParent = $HTTP_POST_VARS["IsParent"];
    if (isset($HTTP_POST_VARS["IsParentPercentage"])) $IsParentPercentage = $HTTP_POST_VARS["IsParentPercentage"];
    if (isset($HTTP_POST_VARS["IsUnderaged"])) $IsUnderaged = $HTTP_POST_VARS["IsUnderaged"];
    if (isset($HTTP_POST_VARS["IsUnderagedPercentage"])) $IsUnderagedPercentage = $HTTP_POST_VARS["IsUnderagedPercentage"];
    if (isset($HTTP_POST_VARS["IsMarried"])) $IsMarried = $HTTP_POST_VARS["IsMarried"];
    if (isset($HTTP_POST_VARS["IsMarriedPercentage"])) $IsMarriedPercentage = $HTTP_POST_VARS["IsMarriedPercentage"];
    if (isset($HTTP_POST_VARS["ColorDark"])) $ColorDark = $HTTP_POST_VARS["ColorDark"];
    if (isset($HTTP_POST_VARS["ColorMedium"])) $ColorMedium = $HTTP_POST_VARS["ColorMedium"];
    if (isset($HTTP_POST_VARS["ColorLight"])) $ColorLight = $HTTP_POST_VARS["ColorLight"];
    if (isset($HTTP_POST_VARS["ColorDarkColumn"])) $ColorDarkColumn = $HTTP_POST_VARS["ColorDarkColumn"];
    ?>
    <style type="text/css">
    <!--
    BODY
    {
      PADDING-RIGHT: 10px;
      PADDING-LEFT: 10px;
      FONT-SIZE: 12px;
      PADDING-BOTTOM: 20px;
      MARGIN: 0px;
      COLOR: #000000;
      PADDING-TOP: 20px;
      FONT-FAMILY: Verdana, Tahoma, Arial, sans-serif;
      BACKGROUND-COLOR: #ffffff;
      TEXT-ALIGN: center
    }
    P
    {
      font-size : 9pt;
      font-family : Verdana,Arial;
      font-weight : normal;
      text-decoration : none;
    }
    TABLE
    {
      font-size : 9pt;
      font-family : Verdana,Arial;
      font-weight : normal;
      text-decoration : none;
    }
    .tbl_title
    {
      font-weight : bold;
      border : #<?php echo ("$ColorDark"); ?> 1px solid;
      FONT-SIZE: 18px;
      COLOR: #<?php echo ("$ColorLight"); ?>;
      WHITE-SPACE: normal;
      BACKGROUND-COLOR: #<?php echo ("$ColorDark"); ?>;
      PADDING: 10px;
    }
    .tbl_captions
    {
      font-weight : bold;
      border : #<?php echo ("$ColorDark"); ?> 1px solid;
      FONT-SIZE: 12px;
      COLOR: #<?php echo ("$ColorLight"); ?>;
      WHITE-SPACE: normal;
      BACKGROUND-COLOR: #<?php echo ("$ColorMedium"); ?>;
      PADDING: 5px;
    }
    .tbl_row_light
    {
      font-weight : normal;
      border : #<?php echo ("$ColorDark"); ?> 1px solid;
      FONT-SIZE: 12px;
      COLOR: #<?php echo ("$ColorDark"); ?>;
      WHITE-SPACE: normal;
      BACKGROUND-COLOR: #<?php echo ("$ColorLight"); ?>;
      PADDING: 5px;
    }
    .tbl_row_dark
    {
      font-weight : normal;
      border : #<?php echo ("$ColorDark"); ?> 1px solid;
      FONT-SIZE: 12px;
      COLOR: #<?php echo ("$ColorDark"); ?>;
      WHITE-SPACE: normal;
      BACKGROUND-COLOR: #<?php echo ("$ColorDarkColumn"); ?>;
      PADDING: 5px;
    }
    -->
    </style>

</head>
<body>
<h2>Monthly Employees’ Salary Calculation Form
(step 2 of 3)</h2>


<body>
<?php

################################################## ##########
# FUNCTION: f_CreateDropList #
# $ListName = The name for the List box (string) #
# $MinValue = Minimum value of the list (int) #
# $MaxValue = Maximum value of the list (int) #
# $$Step = Step of the increment numbers (int) #
################################################## ##########
function f_CreateDropList($ListName, $MinValue=1, $MaxValue=100, $Step=1)
{
  if ($MinValue >= $MaxValue) // If $MinValue > $MaxValue { Show error message }
  {
    echo ("<p><b>ERROR!<br>AT:</b> FUNCTION <code>f_CreateDropList(\$Name, \$MinValue, \$MaxValue, \$Step)</code><br><b>Type of error:</b> You have entered to <code>\"\$MinValue\"</code> a value [u]HIGHER</u> than <code>\"\$MaxValue\"</code>!</p>");
  }
  else
  {
    echo ("\n<select name=\"$ListName\">");
    for ($i=$MinValue; $i<=$MaxValue; $i+=$Step)
    {
      echo ("\n\t<option value=\"$i\">$i</option>");
    }
    echo ("\n</select>\n");
  }
  return;
}

// Defining Table HTML potentian structure.
$TableOpen = "\n<table border=\"0\" cellpadding=\"1\" cellspacing=\"1\">\n<tbody>";
// $TableCaptionLine is defined after the Table's contruction part.
$TableTitleMain = "\n<tr>\n\t<td align=\"right\" class=\"tbl_captions\">#</td>\n\t<td class=\"tbl_captions\">Full Name</td>\n\t<td class=\"tbl_captions\">Age</td>\n\t<td class=\"tbl_captions\">Gender</td>";
$TableTitleParent = "\n\t<td class=\"tbl_captions\">Parent</td>";
//$TableTitleUnderaged = "\n\t<td class=\" tbl_row_light\">Underaged</td>";
$TableTitleMarried = "\n\t<td class=\"tbl_captions\">Married</td>";
$TableTitleHoliday = "\n\t<td class=\"tbl_captions\">Holiday</td>";
$TableClose = "\n</tr>\n</tbody>\n</table>";
$TableTotalColumns = 4;

// Constructiong Final Table.
$TableTotal = $TableTitleMain;
/*if (isset($IsUnderaged))
{
  $TableTotal .= $TableTitleUnderaged;
  $TableTotalColumns++;
}*/
if (isset($IsMarried))
{
  $TableTotal .= $TableTitleMarried;
  $TableTotalColumns++;
}
if (isset($IsParent))
{
  $TableTotal .= $TableTitleParent;
  $TableTotalColumns++;
}
if (isset($IsHoliday))
{
  $TableTotal .= $TableTitleHoliday;
  $TableTotalColumns++;
}

// Assembling them all together.
$TableCaptionLine = $TableOpen .= "\n<tr>\n\t<td class=\"tbl_title\" align=\"center\" colspan=\"" . $TableTotalColumns . "\">Employees Data [$TotalEmployees]</td>\n</tr>";
$TableTotal = $TableCaptionLine . $TableTotal;
$TableTotal .= "\n</tr>";

echo ("\n<form action=\"my_employees_3.php\" method=\"post\">");

// Show the Table on screen.
echo "$TableTotal";

$RowsColorSwitch=0;
$RowColorLight = "tbl_row_light";
$RowColorDark = "tbl_row_dark";
$CurrentRowColor = $RowColorLight;

for ($i=1; $i<=$TotalEmployees; $i++)
{
  if ($RowsColorSwitch == 0)
  {
    $CurrentRowColor = $RowColorLight;
    $RowsColorSwitch = 1;
  }
  else
  {
    $CurrentRowColor = $RowColorDark;
    $RowsColorSwitch = 0;
  }


  echo ("\n<tr>\n\t<td class=\"$CurrentRowColor\" align=\"right\"><b>$i</b></td>");
  echo ("\n\t<td class=\"$CurrentRowColor\"><input type=\"text\" name=\"EmployeeName[$i]\" size=\"42\" maxlength=\"42\"></td>");

  echo ("\n\t<td class=\"$CurrentRowColor\">");
  f_CreateDropList("EmployeeAge[$i]", 16, 72, 1);
  echo ("</td>");

  echo ("\n\t<td class=\"$CurrentRowColor\"><input type=\"radio\" name=\"EmployeeSex[$i]\" value=\"m\" checked> Male <input type=\"radio\" name=\"EmployeeSex[$i]\" value=\"f\"> Female</td>");
  //if (isset($IsUnderaged)) echo ("\n\t<td class=\" tbl_row_light\"\ align=\"center\"><input type=\"checkbox\" name=\"IsUnderaged[$i]\"></td>");
  if (isset($IsMarried)) echo ("\n\t<td class=\"$CurrentRowColor\" align=\"center\"><input type=\"checkbox\" name=\"Married[$i]\"></td>");
  if (isset($IsParent)) echo ("\n\t<td class=\"$CurrentRowColor\" align=\"center\"><input type=\"checkbox\" name=\"Parent[$i]\"></td>");
  if (isset($IsHoliday)) echo ("\n\t<td class=\"$CurrentRowColor\" align=\"center\"><input type=\"checkbox\" name=\"Holiday[$i]\" checked disabled></td>");
}

echo("\n<tr>\n\t<td class=\"tbl_captions\" align=\"center\" colspan=\"" . $TableTotalColumns . "\"><input type=\"button\" value=\"&laquo; Back\" onClick=\"history.back();\"> <input type=\"reset\" value=\"Clear All Data\"> <input type=\"submit\" value=\"Next &raquo;\"></td>\n</tr>");
echo ("$TableClose");

// Adding hidden fields
if (isset($TotalEmployees)) echo ("\n<input type=\"hidden\" name=\"TotalEmployees\" value=\"$TotalEmployees\">");
if (isset($Salary)) echo ("\n<input type=\"hidden\" name=\"Salary\" value=\"$Salary\">");
if (isset($TaxRate)) echo ("\n<input type=\"hidden\" name=\"TaxRate\" value=\"$TaxRate\">");
if (isset($WelfareInsurance)) echo ("\n<input type=\"hidden\" name=\"WelfareInsurance\" value=\"$WelfareInsurance\">");
if (isset($IsHoliday)) echo ("\n<input type=\"hidden\" name=\"IsHoliday\" value=\"$IsHoliday\">");
if (isset($IsHolidayPercentage)) echo ("\n<input type=\"hidden\" name=\"IsHolidayPercentage\" value=\"$IsHolidayPercentage\">");
if (isset($IsParent)) echo ("\n<input type=\"hidden\" name=\"IsParent\" value=\"$IsParent\">");
if (isset($IsParentPercentage)) echo ("\n<input type=\"hidden\" name=\"IsParentPercentage\" value=\"$IsParentPercentage\">");
if (isset($IsUnderaged)) echo ("\n<input type=\"hidden\" name=\"IsUnderaged\" value=\"$IsUnderaged\">");
if (isset($IsUnderagedPercentage)) echo ("\n<input type=\"hidden\" name=\"IsUnderagedPercentage\" value=\"$IsUnderagedPercentage\">");
if (isset($IsMarried)) echo ("\n<input type=\"hidden\" name=\"IsMarried\" value=\"$IsMarried\">");
if (isset($IsMarriedPercentage)) echo ("\n<input type=\"hidden\" name=\"IsMarriedPercentage\" value=\"$IsMarriedPercentage\">");
if (isset($ColorDark)) echo ("\n<input type=\"hidden\" name=\"ColorDark\" value=\"$ColorDark\">");
if (isset($ColorMedium)) echo ("\n<input type=\"hidden\" name=\"ColorMedium\" value=\"$ColorMedium\">");
if (isset($ColorLight)) echo ("\n<input type=\"hidden\" name=\"ColorLight\" value=\"$ColorLight\">");
if (isset($TotalEmployees)) echo ("\n<input type=\"hidden\" name=\"ColorDarkColumn\" value=\"$ColorDarkColumn\">");

echo ("</form>");

?>
</body>
</html>
FILE 03:
 
Quote:
quote:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
Quote:
<html>
  <head>
   <meta http-equiv="Content-Type" content="text/html; charset=windows-1253">
    <title>Monthly Employees’ Salary Calculation Form (step 3 of 3)</title>
    <?php

    // Setting Values to the Variables taken from the HTTP_POST_VARS Array.
    if (isset($HTTP_POST_VARS["TotalEmployees"])) $TotalEmployees = $HTTP_POST_VARS["TotalEmployees"];
    if (empty($HTTP_POST_VARS["Salary"])) //Checking IF the user entered a value on the Salary field.
    {
      echo ("\n<p>You have not entered the <b>Salary</b> amount for the calcuations<br>Please go back and fill in the monthly salary amount</p>");
      echo ("\n</body>\n</html>");
      exit;
    }
    elseif ($HTTP_POST_VARS["Salary"] <= 0) //Cheking if the number is positive and higher than 0.
    {
      echo ("\n<p>You have entered a non acceptable value in the <b>Salary field</b>.<br>Please go back and enter a valid, positive number</p>");
      echo ("\n</body></html>");
      exit;
    }
    else // If the number is valid -higher than 0- we proceed asighning the value to the variable.
    {
      $Salary = $HTTP_POST_VARS["Salary"];
    }
    if (isset($HTTP_POST_VARS["TaxRate"])) $TaxRate = $HTTP_POST_VARS["TaxRate"];
    if (isset($HTTP_POST_VARS["WelfareInsurance"])) $WelfareInsurance = $HTTP_POST_VARS["WelfareInsurance"];
    if (isset($HTTP_POST_VARS["IsHoliday"])) $IsHoliday = $HTTP_POST_VARS["IsHoliday"];
    if (isset($HTTP_POST_VARS["IsHolidayPercentage"])) $IsHolidayPercentage = $HTTP_POST_VARS["IsHolidayPercentage"];
    if (isset($HTTP_POST_VARS["IsParent"])) $IsParent = $HTTP_POST_VARS["IsParent"];
    if (isset($HTTP_POST_VARS["IsParentPercentage"])) $IsParentPercentage = $HTTP_POST_VARS["IsParentPercentage"];
    if (isset($HTTP_POST_VARS["IsUnderaged"])) $IsUnderaged = $HTTP_POST_VARS["IsUnderaged"];
    if (isset($HTTP_POST_VARS["IsUnderagedPercentage"])) $IsUnderagedPercentage = $HTTP_POST_VARS["IsUnderagedPercentage"];
    if (isset($HTTP_POST_VARS["IsMarried"])) $IsMarried = $HTTP_POST_VARS["IsMarried"];
    if (isset($HTTP_POST_VARS["IsMarriedPercentage"])) $IsMarriedPercentage = $HTTP_POST_VARS["IsMarriedPercentage"];
    if (isset($HTTP_POST_VARS["ColorDark"])) $ColorDark = $HTTP_POST_VARS["ColorDark"];
    if (isset($HTTP_POST_VARS["ColorMedium"])) $ColorMedium = $HTTP_POST_VARS["ColorMedium"];
    if (isset($HTTP_POST_VARS["ColorLight"])) $ColorLight = $HTTP_POST_VARS["ColorLight"];
    if (isset($HTTP_POST_VARS["ColorDarkColumn"])) $ColorDarkColumn = $HTTP_POST_VARS["ColorDarkColumn"];
    // New Variables from step 2.
    if (isset($HTTP_POST_VARS["EmployeeName"])) $EmployeeName = $HTTP_POST_VARS["EmployeeName"];
    if (isset($HTTP_POST_VARS["EmployeeSex"])) $EmployeeSex = $HTTP_POST_VARS["EmployeeSex"];
    if (isset($HTTP_POST_VARS["EmployeeAge"])) $EmployeeAge = $HTTP_POST_VARS["EmployeeAge"];
    echo count($IsMarried);
    ?>
    <style type="text/css">
    <!--
    BODY
    {
      PADDING-RIGHT: 10px;
      PADDING-LEFT: 10px;
      FONT-SIZE: 12px;
      PADDING-BOTTOM: 20px;
      MARGIN: 0px;
      COLOR: #000000;
      PADDING-TOP: 20px;
      FONT-FAMILY: Verdana, Tahoma, Arial, sans-serif;
      BACKGROUND-COLOR: #ffffff;
      TEXT-ALIGN: center
    }
    P
    {
      font-size : 9pt;
      font-family : Verdana,Arial;
      font-weight : normal;
      text-decoration : none;
    }
    TABLE
    {
      font-size : 9pt;
      font-family : Verdana,Arial;
      font-weight : normal;
      text-decoration : none;
      border: #<?php echo ("$ColorDark"); ?> 1px solid
    }
    .tbl_title
    {
      font-weight : bold;
      border : #<?php echo ("$ColorDark"); ?> 1px solid;
      FONT-SIZE: 18px;
      COLOR: #<?php echo ("$ColorLight"); ?>;
      WHITE-SPACE: normal;
      BACKGROUND-COLOR: #<?php echo ("$ColorDark"); ?>;
      PADDING: 10px;
    }
    .tbl_captions
    {
      font-weight : bold;
      border : #<?php echo ("$ColorDark"); ?> 1px solid;
      FONT-SIZE: 12px;
      COLOR: #<?php echo ("$ColorLight"); ?>;
      WHITE-SPACE: normal;
      BACKGROUND-COLOR: #<?php echo ("$ColorMedium"); ?>;
      PADDING: 5px;
    }
    .tbl_row_light
    {
      font-weight : normal;
      border : #<?php echo ("$ColorDark"); ?> 1px solid;
      FONT-SIZE: 12px;
      COLOR: #<?php echo ("$ColorDark"); ?>;
      WHITE-SPACE: normal;
      BACKGROUND-COLOR: #<?php echo ("$ColorLight"); ?>;
      PADDING: 5px;
    }
    .tbl_row_dark
    {
      font-weight : normal;
      border : #<?php echo ("$ColorDark"); ?> 1px solid;
      FONT-SIZE: 12px;
      COLOR: #<?php echo ("$ColorDark"); ?>;
      WHITE-SPACE: normal;
      BACKGROUND-COLOR: #<?php echo ("$ColorDarkColumn"); ?>;
      PADDING: 5px;
    }
    -->
    </style>

</head>
<body>
<h2>Monthly Employees’ Salary Calculation Form (step 3 of 3)</h2>
<br>
   <?php
    // Filtering all the potential HTML tags from the HTTP_POST_VARS Array.
    foreach ($HTTP_POST_VARS as $Index => $Value)
    {
      if (is_array($Value))
      {
        foreach ($Value as $IIndex =>$VValue)
        {
          $VValue = HTMLSpecialChars($VValue);
        }
      }
      else
      {
      $Value = HTMLSpecialChars($Value);
      //echo ("$Index - $Value<br>");
      }
    }

    // Defining Table HTML potentian structure.
    $TableOpen = "\n<table border=\"0\" cellpadding=\"1\" cellspacing=\"1\">\n<tbody>";
    // $TableCaptionLine is defined after the Table's contruction part.
    $TableTitleMain = "\n<tr>\n\t<td align=\"right\" class=\"tbl_captions\">#</td>\n\t<td class=\"tbl_captions\">Full Name</td>\n\t<td class=\"tbl_captions\">Age</td>\n\t<td class=\"tbl_captions\">Gender</td>";
    $TableTitleParent = "\n\t<td class=\"tbl_captions\">Parent</td>";
    $TableTitleUnderaged = "\n\t<td class=\" tbl_captions\">Underaged</td>";
    $TableTitleMarried = "\n\t<td class=\"tbl_captions\">Married</td>";
    $TableTitleHoliday = "\n\t<td class=\"tbl_captions\">Holiday</td>";
    $TableClose = "\n</tr>\n</tbody>\n</table>";
    $TableTotalColumns = 4;

    // Constructiong Final Table.
    $TableTotal = $TableTitleMain;
    if (isset($IsUnderaged))
    {
      $TableTotal .= $TableTitleUnderaged;
      $TableTotalColumns++;
    }
    if (isset($IsMarried))
    {
      $TableTotal .= $TableTitleMarried;
      $TableTotalColumns++;
    }
    if (isset($IsParent))
    {
      $TableTotal .= $TableTitleParent;
      $TableTotalColumns++;
    }
    if (isset($IsHoliday))
    {
      $TableTotal .= $TableTitleHoliday;
      $TableTotalColumns++;
    }

    // Assembling them all together.
    $TableCaptionLine = $TableOpen .= "\n<tr>\n\t<td class=\"tbl_title\" align=\"center\" colspan=\"" . $TableTotalColumns . "\">Employees Data [$TotalEmployees]</td>\n</tr>";
    $TableTotal = $TableCaptionLine . $TableTotal;
    $TableTotal .= "\n</tr>";

    // Show the Table on screen.
    echo "$TableTotal";

    $RowsColorSwitch=0;
    $RowColorLight = "tbl_row_light";
    $RowColorDark = "tbl_row_dark";
    $CurrentRowColor = $RowColorLight;

    for ($i=1; $i<=$TotalEmployees; $i++)
    {
      if ($RowsColorSwitch == 0)
      {
        $CurrentRowColor = $RowColorLight;
        $RowsColorSwitch = 1;
      }
      else
      {
        $CurrentRowColor = $RowColorDark;
        $RowsColorSwitch = 0;
      }
      echo ("\n<tr>\n\t<td class=\"$CurrentRowColor\" align=\"right\"><b>$i</b></td>");
      echo ("\n\t<td class=\"$CurrentRowColor\">$EmployeeName[$i]</td>");
      echo ("\n\t<td class=\"$CurrentRowColor\" align=\"center\">$EmployeeAge[$i]</td>");
      echo ("\n\t<td class=\"$CurrentRowColor\" align=\"center\">");

      if ($EmployeeSex[$i] == "m")
          {
              echo ("<img src=\"img/male.gif\" width=\"21\" height=\"21\" border=\"0\"");
              //$Total_Boys++;
          }
          else
          {
              echo ("<img src=\"img/female.gif\" width=\"21\" height=\"21\" border=\"0\"");
              //$Total_Girls++;
          }
      echo ("</td>");

      if (isset($IsUnderaged)) echo ("\n\t<td class=\" $CurrentRowColor\"\ align=\"center\">-</td>");
      if (isset($IsMarried)) echo ("\n\t<td class=\"$CurrentRowColor\" align=\"center\">$IsMarried[$i]</td>");
      if (isset($IsParent)) echo ("\n\t<td class=\"$CurrentRowColor\" align=\"center\">-</td>");
      if (isset($IsHoliday)) echo ("\n\t<td class=\"$CurrentRowColor\" align=\"center\">-</td>");
      }

    echo("\n<tr>\n\t<td class=\"tbl_captions\" align=\"center\" colspan=\"" . $TableTotalColumns . "\"><input type=\"button\" value=\"&laquo; Back\" onClick=\"history.back();\"></td>\n</tr>");
    echo ("$TableClose");



    ?>
  </body>
</html>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Indexes luisjeronimo BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 June 27th, 2008 09:34 AM
strings as array indexes cwalton Excel VBA 3 July 30th, 2007 02:50 AM
Indexes for searching fizzerchris SQL Server 2005 0 May 22nd, 2007 07:08 PM
Grouping Indexes ShaileshShinde XSLT 3 November 30th, 2005 05:46 AM
Indexes SQ SQL Language 1 October 5th, 2004 10:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.