<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../css/main.css" rel="stylesheet" type="text/css" />
<?php
include('../include/session.php');

$cust_id = $_GET['cust_id'];

if ($cust_id=='') {

$string = $_GET['customer_name_text'];
	
	function extract_numbers($string)
	{
	preg_match_all('/([\d]+)/', $string, $match);
 
	return $match[0];
	}

	$numbers_array = extract_numbers($string);
	
	$cust_id=$numbers_array[0];	
}

$table_name = $_SESSION['db_prefix']."_list_places";
    $position_query = "SELECT item_name FROM $table_name ORDER BY item_name ASC";
	$arrId3 = array ();
	$arrName3 = array ();
	$position_result = execsql($position_query);
	if ($position_result!="") {
	$position_num = mysql_num_rows($position_result);
	$b = 0;
	while ($b < $position_num) {
		$arrId3[$b] = mysql_result($position_result, $b, "item_name");
		$arrName3[$b] = mysql_result($position_result, $b, "item_name");
		$b++;
	}
	}

$table_name = $_SESSION['db_prefix']."_list_country";
    $position_query = "SELECT item_name FROM $table_name ORDER BY item_name ASC";
	$arrId4 = array ();
	$arrName4 = array ();
	$position_result = execsql($position_query);
	if ($position_result!="") {
	$position_num = mysql_num_rows($position_result);
	$b = 0;
	while ($b < $position_num) {
		$arrId4[$b] = mysql_result($position_result, $b, "item_name");
		$arrName4[$b] = mysql_result($position_result, $b, "item_name");
		$b++;
	}
	}	

	
$table_name2 = $_SESSION['db_prefix']."_customer";
$customer_query = "SELECT * FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
$customer_result = mySQL_query($customer_query);
$customer_num = mysql_num_rows($customer_result);

$account_type = mysql_result($customer_result, 0, "account_type");
$a0 = mysql_result($customer_result, 0, "comp_name");
$a1 = mysql_result($customer_result, 0, "contact_1");
$a2 = mysql_result($customer_result, 0, "status");
$a3 = mysql_result($customer_result, 0, "bag_box");
$a4 = mysql_result($customer_result, 0, "box_no");
$a5 = mysql_result($customer_result, 0, "postal_place");
$a6 = mysql_result($customer_result, 0, "phys_address");
$a7 = mysql_result($customer_result, 0, "phys_place");
$a8 = mysql_result($customer_result, 0, "web_site");
$a9 = mysql_result($customer_result, 0, "vat_no");
$a10 = mysql_result($customer_result, 0, "email_2");
$a11 = mysql_result($customer_result, 0, "fax");
$a12 = mysql_result($customer_result, 0, "phone");
$a13 = mysql_result($customer_result, 0, "country");
$a14 = mysql_result($customer_result, 0, "email_1");
$a15 = mysql_result($customer_result, 0, "cell_1");
$a16 = mysql_result($customer_result, 0, "cell_2");
$a17 = mysql_result($customer_result, 0, "contact_2");
$a18 = mysql_result($customer_result, 0, "notes");
$a19 = mysql_result($customer_result, 0, "account_type");
$a20 = mysql_result($customer_result, 0, "name_2");
$a21 = mysql_result($customer_result, 0, "title");

?>
<!--jscript-->
<script language="JavaScript" src="../jscript/gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script>
<script language="JavaScript" src="../jscript/capitalize_textbox.js"  type="text/javascript"></script>  
<script language="JavaScript" src="../jscript/lower_case.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/upper_case.js"  type="text/javascript"></script>  
<script language="JavaScript" src="../jscript/numbers_only.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/cancel_confirmation.js"  type="text/javascript"></script>  


</head>
<body>
<?php
include ("../navigation/header.php");
$page_name = "Customer-edit";
include ("../navigation/access.php");
if ($permission_num==1) {
	include ("../navigation/sales_sidebar.php");
?>
<div class="main_frame">
  <label class="label_page_head">Edit Customer </label><label class="label_page_head_2"> <?php echo $a0 ?></label></td>
            <td width="248" align="right">

     
<form action="customer_details_edit_save.php" method="post">

<div class="page_middle_frame">
<div class="page_inside_frame">
<div align="left">Company details</div>
  <table width="640" id="table_details_display">
    <tr>
      <td width="126" height="25">Account:</td>
      <td width="230"><select name="account_type_select" class="select120" id="account_select">
        <option value="corporate">corporate</option>
        <option value="private">private</option>
        <option value="<?php echo $a19 ?>" selected="selected"><?php echo $a19 ?></option>
      </select></td>
      <td colspan="2">Customer number:&nbsp;&nbsp;&nbsp;<?php echo $cust_id ?></td>
      </tr>
    <tr>
      <td height="25">Company/surname:</td>
      <td colspan="3">
          <input name="comp_name_text" type="text" class="text300" id="comp_name_text" value="<?php echo $a0?>" onBlur="capitalize(this)"/>
        </a></b></td>
      </tr>
    <tr>
      <td height="25">First name:</td>
      <td><input name="name_2_text" type="text" class="text150" value="<?php echo $a20?>" onblur="capitalize(this)"/></td>
      <td width="85">Title:</td>
      <td width="179"><select name="title_select" class="select80" id="title_select">
        <option value="Mr">Mr</option>
        <option value="Mrs">Mrs</option>
        <option value="Ms">Ms</option>
        <option value="Miss">Miss</option>
        <option value="Dr">Dr</option>
        <option value="<?php echo $a21 ?>" selected="selected"><?php echo $a21 ?></option>
        <option> </option>
      </select></td>
    </tr>
  </table>
</div>

<div class="page_inside_frame">
<div align="left">Contact details</div>
  <table width="670" id="table_details_display">
    <tr>
      <td width="126" height="25">Postal address:</td>
      <td width="101"><b>
        <select name="bag_box_select" class="select80" id="bag_box_select">
          <option value="PO Box">PO Box</option>
          <option value="P Bag">P Bag</option>
          <option value="<?php echo $a3?>" selected="selected"><?php echo $a3?></option>
      </select>
      </b></a></td>
      <td width="86"><b>
        <input name="box_no_text" type="text" class="text60" id="box_no_text" value="<?php echo $a4?>" onkeyup="ToUpper(this)"/>
      </a></b></td>
      <td width="86">Postal place:</td>
      <td width="247">
        <select name="postal_place_select" class="select120" id="postal_place_select">
          <option value="<?php echo $a5?>" selected="selected"><?php echo $a5?></option>
          <?php
        	for ($j = 0; $j < count($arrId3); $j++) {
    		echo "<option value=" . "\"" . $arrId3[$j] . "\"" . ">" . $arrName3[$j] . "</option>";
	}
?>
          </select>
      </td>
      </tr>
    <tr>
      <td height="25">Physical address:</td>
      <td colspan="2"><input name="phys_address_text" type="text" class="text150" value="<?php echo $a6?>" onBlur="capitalize(this)"/></td>
      <td>Place:</td>
      <td><select name="phys_place_select" class="select120">
        <option value="<?php echo $a7?>" selected="selected"><?php echo $a7?></option>
        <?php
        	for ($j = 0; $j < count($arrId3); $j++) {
    		echo "<option value=" . "\"" . $arrId3[$j] . "\"" . ">" . $arrName3[$j] . "</option>";
	}
?>
      </select></td>
      </tr>
    <tr>
      <td height="25">Country:</td>
      <td colspan="4"><select name="country_select" class="select120" id="country_select">
        <option value="<?php echo $a13?>" selected="selected"><?php echo $a13?></option>
        <?php
        	for ($j = 0; $j < count($arrId4); $j++) {
    		echo "<option value=" . "\"" . $arrId4[$j] . "\"" . ">" . $arrName4[$j] . "</option>";
	}
?>
      </select></td>
      </tr>
    <tr>
      <td height="25">Phone:</td>
      <td colspan="2"><input name="phone_text"  type="text" class="text150" id="phone_text" value="<?php echo $a12?>" onkeypress="return numbersonly(this, event)"/></td>
      <td>Fax:</td>
      <td><input name="fax_text" type="text" class="text150" id="fax_text" value="<?php echo $a11?>" onkeypress="return numbersonly(this, event)"/></td>
      </tr>
    <tr>
      <td height="25">web site:</td>
      <td colspan="4"><input name="web_site_text" type="text" class="text300" value="<?php echo $a8?>" onkeyup="ToLower(this)"/></td>
      </tr>
    <tr>
      <td height="25">VAT registration no:</td>
      <td colspan="4"><input name="vat_no_text" type="text" class="text150" id="vat_no_text" value="<?php echo $a9?>" onkeyup="ToUpper(this)"/></td>
      </tr>
  </table>
</div>
<div class="page_inside_frame">
<div align="left">Company contacts</div>
  <table width="640" id="table_details_display">
    <tr>
      <td width="114" height="25">Contact 1:</td>
      <td width="107"><input name="contact_1_text" type="text" class="text150" id="contact_1_text" value="<?php echo $a1?>" onBlur="capitalize(this)"/></td>
      <td width="101">Cell:</td>
      <td width="115"><input name="cell_1_text" type="text" class="text150" id="cell_1_text" value="<?php echo $a15?>" onkeypress="return numbersonly(this, event)"/></td>
      <td width="76">&nbsp;</td>
      <td width="128">&nbsp;</td>
    </tr>
    <tr>
      <td height="25">e-mail:</td>
      <td colspan="5"><input name="email_1_text" type="text" class="text400" id="email_1_text" value="<?php echo $a14?>" onkeyup="ToLower(this)"/></td>
      </tr>
    <tr>
      <td height="25">Contact 2:</td>
      <td><b><input name="contact_2_text" type="text" class="text150" id="contact_2_text" value="<?php echo $a17?>" onBlur="capitalize(this)"/></td>
      <td>Cell:</td>
      <td><b><input name="cell_2_text" type="text" class="text150" id="cell_2_text" value="<?php echo $a16?>" onkeypress="return numbersonly(this, event)"/></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td height="25">e-mail:</td>
      <td colspan="5"><input name="email_2_text" id="email_2_text" type="text" class="text400" value="<?php echo $a10?>" onkeyup="ToLower(this)"/></td>
      </tr>
  </table>
</div>
<div class="page_inside_frame">
<div align="left">Miscellaneous</div>
  <table width="640" id="table_details_display">
    <tr>
      <td width="120" height="25" valign="top">Notes:</td>
      <td width="473"><textarea name="notes_text" cols="60" rows="3" class="text_box"><?php echo $a18?></textarea></td>
    </tr>
  </table>
</div>
<div class="page_inside_frame">
  <table width="645" border="0">
    <tr>
      <td width="20"></td>
      <td width="615" align="right"><input type="hidden" name="cust_id_text" id="cust_id_text" value="<?php echo $cust_id ?>" />
        <input name="button2" type="button" class="imagebutton" id="button2" onclick="cancel_confirmation(3, '../sales/sales_main.php?date=0');" value="Close"/>
        <input name="save_button"  id="save_button" type="submit" class="imagebutton" value="Save" onclick="needToConfirm = false; confirmRefresh();" />
        <input name="save_close_button"  id="save_close_button" type="submit" class="imagebutton" value="Save &amp; Close" onclick="needToConfirm = false; confirmRefresh();" /></td>
    </tr>
  </table>
</div>
</div>
</form>

  
</div>

<?php include ('../navigation/side_bar.php'); ?>  
</body>
<?php 

} else {
$_SESSION['denied_return'] = "sales/sales_main.php?date=";	
include ("../navigation/sales_sidebar.php");?>
	<body onload="accessdenied(); return false">
    <?php
    include ("../navigation/side_bar.php");
	?>
	</body>
<?php }
?>
</html>