Location: PHPKode > projects > T-77.com Operational Management System > omis/contact_edit.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_update"])) && ($HTTP_POST_VARS["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE t77_bill_contacts SET contact_name=%s, contact_company_name=%s, contact_person=%s, contact_title=%s, contact_company_address=%s, contact_company_zip=%s, contact_company_city=%s, contact_telephone=%s, contact_fax=%s, mobile=%s, contact_email=%s, contact_country=%s WHERE contact_id=%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"),
                       GetSQLValueString($HTTP_POST_VARS['contact_id'], "int"));

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

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

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);

$colname_contact = "0";
if (isset($_GET['conID'])) {
  $colname_contact = (get_magic_quotes_gpc()) ? $_GET['conID'] : addslashes($_GET['conID']);
}
mysql_select_db($database_t77_connect, $t77_connect);
$query_contact = sprintf("SELECT * FROM t77_bill_contacts WHERE t77_bill_contacts.contact_id = %s", $colname_contact);
$contact = mysql_query($query_contact, $t77_connect) or die(mysql_error());
$row_contact = mysql_fetch_assoc($contact);
$totalRows_contact = mysql_num_rows($contact);
?>
<?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%" height="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td height="31"><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>Edit contact </strong></p>
                </td>
                <td>&nbsp;</td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="20">
      <tr>
        <td>
          <form method="post" name="form1" action="<?php echo $editFormAction; ?>">
            <table width="100%" border="0" align="center" cellpadding="5" cellspacing="0" class="tableBorder">
              <tr valign="baseline">
                <td align="right" nowrap="nowrap"><h1>Contact name :</h1></td>
                <td><input type="text" name="contact_name" value="<?php echo $row_contact['contact_name']; ?>" 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 if (!(strcmp($row_companies['company_id'], $row_contact['contact_company_name']))) {echo "SELECTED";} ?>><?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']; ?>&quer=<? echo $_SERVER['QUERY_STRING']; ?>','companyAdd','scrollbars=yes,width=500,height=200')">[
                  </a><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><a href="javascript:;" onClick="MM_openBrWindow('company_add.php?ref=<? echo $_SERVER['PHP_SELF']; ?>&quer=<? echo $_SERVER['QUERY_STRING']; ?>','companyAdd','scrollbars=yes,width=500,height=200')"> ]</a> </p></td>
              <tr>
              <tr valign="baseline">
                <td align="right" nowrap="nowrap"><h1>Contact person:</h1>
                </td>
                <td><input type="text" name="contact_person" value="<?php echo $row_contact['contact_person']; ?>" 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="<?php echo $row_contact['contact_title']; ?>" size="32">
                </td>
              </tr>
              <tr valign="baseline">
                <td align="right" nowrap="nowrap"><h1> Number + street:</h1></td>
                <td><input type="text" name="contact_company_address" value="<?php echo $row_contact['contact_company_address']; ?>" size="32">
                </td>
              </tr>
              <tr valign="baseline" bgcolor="#eeeeee">
                <td align="right" nowrap="nowrap"><h1>Postal code :</h1></td>
                <td><input type="text" name="contact_company_zip" value="<?php echo $row_contact['contact_company_zip']; ?>" size="32">
                </td>
              </tr>
              <tr valign="baseline">
                <td align="right" nowrap="nowrap"><h1>City:</h1></td>
                <td><input type="text" name="contact_company_city" value="<?php echo $row_contact['contact_company_city']; ?>" 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" bgcolor="#eeeeee">
                <td align="right" nowrap="nowrap"><h1>Telephone number :</h1></td>
                <td><input type="text" name="contact_telephone" value="<?php echo $row_contact['contact_telephone']; ?>" size="32">
                </td>
              </tr>
              <tr valign="baseline">
                <td align="right" nowrap="nowrap"><h1>Fax number :</h1></td>
                <td><input type="text" name="contact_fax" value="<?php echo $row_contact['contact_fax']; ?>" size="32">
                </td>
              </tr>
              <tr valign="baseline" bgcolor="#eeeeee">
                <td align="right" nowrap="nowrap"><h1>Cell phone :</h1></td>
                <td><input type="text" name="mobile" value="<?php echo $row_contact['mobile']; ?>" 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="<?php echo $row_contact['contact_email']; ?>" size="32">
                </td>
              </tr>
              <tr valign="baseline" bgcolor="#eeeeee">
                <td align="right" nowrap>&nbsp;</td>
                <td><input type="submit" value="Update contact">
                </td>
              </tr>
            </table>
            <input type="hidden" name="contact_id" value="<?php echo $row_contact['contact_id']; ?>">
            <input type="hidden" name="MM_update" value="form1">
            <input type="hidden" name="contact_id" value="<?php echo $row_contact['contact_id']; ?>">
          </form>
        </td>
      </tr>
    </table>
</td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result($companies);

mysql_free_result($contact);
?>
Return current item: T-77.com Operational Management System