Location: PHPKode > projects > T-77.com Operational Management System > omis/contact_add.php
<?php require_once('Connections/t77_connect.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
  $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO t77_bill_contacts (contact_name, contact_company_name, contact_person, contact_title, contact_company_address, contact_company_zip, contact_company_city, contact_telephone, contact_fax, mobile, contact_email, contact_country) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($HTTP_POST_VARS['contact_name'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['contact_company_name'], "int"),
                       GetSQLValueString($HTTP_POST_VARS['contact_person'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['contact_title'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['contact_company_address'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['contact_company_zip'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['contact_company_city'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['contact_telephone'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['contact_fax'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['mobile'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['contact_email'], "text"),
					   GetSQLValueString($HTTP_POST_VARS['contact_country'], "text"));

  mysql_select_db($database_t77_connect, $t77_connect);
  $Result1 = mysql_query($insertSQL, $t77_connect) or die(mysql_error());

  $insertGoTo = "close.php?ref=" . $_GET['ref'] . "quer=" . $_GET['quer'];
  if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_t77_connect, $t77_connect);
$query_companies = "SELECT * FROM t77_bill_companies";
$companies = mysql_query($query_companies, $t77_connect) or die(mysql_error());
$row_companies = mysql_fetch_assoc($companies);
$totalRows_companies = mysql_num_rows($companies);
?>
<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="styles.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->
</script>
</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="20"><img src="images/tabletopstart.gif" width="20" height="31" /></td>
          <td><table width="100%" height="30" border="0" cellpadding="5" cellspacing="0">
              <tr>
                <td><p><strong>Add contact </strong></p>
                </td>
                <td>&nbsp;</td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td>
      <form method="post" name="form1" action="<?php echo $editFormAction; ?>">
        <table width="100%" border="0" cellspacing="0" cellpadding="20">
          <tr>
            <td align="left" valign="top"><table width="100%" align="center" cellpadding="5" cellspacing="0" class="tableBorder">
              <tr valign="baseline">
                <td nowrap="nowrap" align="right"><h1>Contact name :</h1></td>
                <td><input type="text" name="contact_name" value="" size="32" />
                </td>
              </tr>
              <tr valign="baseline">
                <td align="right" nowrap="nowrap" bgcolor="#eeeeee"><h1>Company:</h1></td>
                <td bgcolor="#eeeeee">
                  <p>
  <select name="contact_company_name">
                        <?php 
do {  
?>
                        <option value="<?php echo $row_companies['company_id']?>" ><?php echo $row_companies['company_name']?></option>
                        <?php
} while ($row_companies = mysql_fetch_assoc($companies));
?>
                    </select>
                      &nbsp;&nbsp; <a href="javascript:;" onClick="MM_openBrWindow('company_add.php?ref=<? echo $_SERVER['PHP_SELF']; ?>&amp;quer=<? echo $_SERVER['QUERY_STRING']; ?>','companyAdd','scrollbars=yes,width=500,height=150')">[
                       click here to add a company]</a></p></td>
              </tr>
              <tr> </tr>
              <tr valign="baseline">
                <td nowrap="nowrap" align="right"><h1>Contact person:</h1></td>
                <td><input type="text" name="contact_person" value="" size="32" />
                </td>
              </tr>
              <tr valign="baseline">
                <td align="right" nowrap="nowrap" bgcolor="#eeeeee"><h1>Title:</h1>
                  </td>
                <td bgcolor="#eeeeee"><input type="text" name="contact_title" value="" size="32" />
                </td>
              </tr>
              <tr valign="baseline">
                <td nowrap="nowrap" align="right"><h1> Number + street:</h1></td>
                <td><input type="text" name="contact_company_address" value="" size="32" />
                </td>
              </tr>
              <tr valign="baseline">
                <td align="right" nowrap="nowrap" bgcolor="#eeeeee"><h1>Postal
                    code :</h1></td>
                <td bgcolor="#eeeeee"><input type="text" name="contact_company_zip" value="" size="32" />
                </td>
              </tr>
              <tr valign="baseline">
                <td nowrap="nowrap" align="right"><h1>City:</h1></td>
                <td><input type="text" name="contact_company_city" value="" size="32" />
                </td>
              </tr>
              <tr valign="baseline">
                <td align="right" nowrap="nowrap" bgcolor="#eeeeee"><h1>Country:</h1></td>
                <td bgcolor="#eeeeee"><input name="contact_country" type="text" id="contact_country" value="" size="32" /></td>
              </tr>
              <tr valign="baseline">
                <td align="right" nowrap="nowrap" bgcolor="#eeeeee"><h1>Telephone
                    number :</h1></td>
                <td bgcolor="#eeeeee"><input name="contact_telephone" type="text" value="" size="32" />
                </td>
              </tr>
              <tr valign="baseline">
                <td nowrap="nowrap" align="right"><h1>Fax number :</h1></td>
                <td><input name="contact_fax" type="text" value="" size="32" />
                </td>
              </tr>
              <tr valign="baseline">
                <td align="right" nowrap="nowrap" bgcolor="#eeeeee"><h1>Cell
                    phone :</h1></td>
                <td bgcolor="#eeeeee"><input name="mobile" type="text" id="mobile" value="" size="32" /></td>
              </tr>
              <tr valign="baseline">
                <td align="right" nowrap="nowrap"><h1>Email address:</h1></td>
                <td><input type="text" name="contact_email" value="" size="32" />
                </td>
              </tr>
              <tr valign="baseline" bgcolor="#eeeeee">
                <td align="right" nowrap="nowrap">&nbsp;</td>
                <td><input type="submit" value="Add contact" />
                </td>
              </tr>
            </table>
              <input type="hidden" name="MM_insert" value="form1" />
            </td>
          </tr>
        </table>
      </form>
    </td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result($companies);
?>
Return current item: T-77.com Operational Management System