<html>
<! BasicForms.inc                                             >
<! Chapter 11, Oracle Database XE PHP Web Programming         >
<! by Michael McLaughlin                                      >
<!                                                            >
<! This script defines library for user account management.   >
<head>
<title>
  Chapter 11 : BasicForms.inc
</title>
</head>
<body>
<?php

  /* Library functions.
  || ----------------------------------------------------------------
  ||  Function Name               Return Type  Parameters
  || ---------------------------  -----------  ----------------------
  ||  addUserForm()               string       array    $args
  */

  // Build dynamic data entry form.
  function addUserForm($args)
  {
    // Define local variables.
    $code;
    $form;
    $userid;

    // Parse form parameters.
    foreach ($args as $name => $value)
    {
      switch (true)
      {
        case ($name == "form"):
          $form = $value;
          break;
        case ($name == "code"):
          $code = $value;
          break;
        case ($name == "userid"):
          $userid = $value;
          break;
      }
    }

    // Initialize return variable.
    $out  = '<div id=centered>';
  
    // Set and append next form target file.
    $out .= '<form method="post" action="'.$form.'">';
  
    // Append balance of form header.
    $out .= '<table border="4"
                    bgcolor="beige"
                    bordercolor="silver"
                    cellspacing="0">';
    $out .= '<tr><td align="center" width="400">';
    $out .= '<font size=+3>New User</font>';
    $out .= '</td></tr>';

    // Verify if optional message.
    if ((isset($code)) && (is_int($code)))
    {
      $out .= '<tr><td align="center" bgcolor="white" width="400">';
      $out .= '<font color=blue>'.get_message($code,$userid).'</font>';
      $out .= '</td></tr>';
    }
  
    // Append standard data entry components.
    $out .= '<tr><td>';
    $out .= '<table border="0" cellpadding="5" cellspacing="0">';
    $out .= '<tr>';
    $out .= '<td align="right" width="200">User ID:</td>';
    $out .= '<td width="200"><input name="userid" type="text"></td>';
    $out .= '</tr>';
    $out .= '<tr>';
    $out .= '<td align="right">User Password:</td>';
    $out .= '<td><input name="passwd" type="password"></td>';
    $out .= '</tr>';
    $out .= '<tr>';
    $out .= '</table>';
    $out .= '</td></tr>';
    $out .= '<tr><td align="center" colspan="2">';
    $out .= '<table border="0" cellpadding="5" cellspacing="0">';
    $out .= '<tr>';
    $out .= '<td align="center" valign="center">';
    $out .= '<input name="submit" type="submit" value="Add User">';
    $out .= '</td>';
    $out .= '</tr>';
    $out .= '</table>';
    $out .= '</td></tr>';
    $out .= '</table>';
    $out .= '</form>';
    $out .= '</div>';

    // Return the form for rendering in a web page.    
    print $out;
  }
?>
</body>
</html>
