<?php
require_once('../config/config.php');
require_once(CLASS_DIR.'dbClass.php');
$obj = new DBClass();
$dat = date('Y-m-d');
$headin = 'Add New Liasoning';
$buton = 'Add Submit';
$cupage = 'liasoning';
$sql1 = "SELECT * FROM liasoning";
$rs1 = $obj->executeQry($sql1,$link);
$row1 = $obj->fetchrow();	 

if(isset($_GET['action']) && $_GET['action'] == 'edit'){
	$headin = 'Edit Liasoning';
	$buton = 'Edit Submit';
	$obj2 = new DBClass();
	$sql = "SELECT * FROM liasoning WHERE id = '".$_GET['id']."' ";
	$rs = $obj2->executeQry($sql,$link);
	$row = $obj2->fetchrow();
}

if(isset($_POST['submit'])){
	if($error == ''){
		if($_POST['submit'] == 'Add Submit'){
			$sqll = "INSERT INTO liasoning (person_name,organisation_name,address,district,state,pincode,phone,fax,mobile1,email1,commodity,origin,area,sub_area,mines,added_on,website) VALUES ('".trim($_POST['person_name'])."','".trim($_POST['organisation_name'])."','".trim($_POST['address'])."','".trim($_POST['district'])."','".trim($_POST['state'])."','".trim($_POST['pincode'])."','".trim($_POST['phone'])."','".trim($_POST['fax'])."','".trim($_POST['mobile1'])."','".trim($_POST['email1'])."','".trim($_POST['commodity'])."','".trim($_POST['origin'])."','".$_POST['area']."','".$_POST['sub_area']."','".$_POST['mines']."','".date("Y-m-d")."','".$_POST['website']."') ";
			$rs2 = $obj->executeQry($sqll,$link);
				if($rs2){
					@header('Location: liasoning.php?msg=add');
					exit;
				}
		}
	
		if($_POST['submit'] == 'Edit Submit'){
			$sqll = "UPDATE liasoning SET person_name = '".trim($_POST['person_name'])."', organisation_name = '".trim($_POST['organisation_name'])."', address = '".$_POST['address']."', district = '".$_POST['district']."', state = '".$_POST['state']."', pincode = '".$_POST['pincode']."', phone = '".$_POST['phone']."', fax = '".$_POST['fax']."', mobile1 = '".$_POST['mobile1']."', email1 = '".$_POST['email1']."', commodity = '".$_POST['commodity']."', origin = '".$_POST['origin']."', area = '".$_POST['area']."', sub_area = '".$_POST['sub_area']."', mines = '".$_POST['mines']."', website = '".$_POST['website']."' WHERE id = '".$_GET['id']."'";
			$rs2 = $obj->executeQry($sqll,$link);
			if($rs2){
				@header('Location: liasoning.php?msg=edit');
				exit;
			}
		}
	}	
}

require_once(INCLUDES_DIR.ADMHEADER); 
?>
<script>
function change_origin1(val) {
	if(val=='Indian') {
		document.getElementById('area').style.display='';
		document.getElementById('subarea').style.display='';
		document.getElementById('mines').style.display='none';
	}
	else {
		document.getElementById('area').style.display='none';
		document.getElementById('subarea').style.display='none';
		document.getElementById('mines').style.display='';	
	}
}
</script>

<table border="0" cellspacing="0" cellpadding="0">
  <tr>
      <td height="29" align="center" class="submenu"><a href="liasoning.php">Liasoning & Lifting Services</a></td>
	<td height="29" align="center" class="submenu"><a href="transporter.php">Transportation & logistics</a></td>
	<td height="29" align="center" class="submenu"><a href="steave.php">Stevedores & Shiping agents</a></td>
  </tr>
</table>
<table width="1000" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="17"></td>
  </tr>
  <tr>
    <td><table width="910" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td class="pagehead"><table width="900" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="315" height="35"><?php echo $headin;?></td>
            </tr>
        </table></td>
      </tr>
      <tr>
        <td valign="top" bgcolor="#FFFFFF" class="innermain"><table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td height="25"><?php ShowError($error); ShowInfo($info);?></td>
          </tr>
	<form name="pageform" id="pageform" method="post" action="">
          <tr>
            <td valign="top" class="bdr4"><table width="800" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td bgcolor="#990066" class="form_head">Name & Address</td>
                </tr>
              <tr>
                <td valign="top" class="form_bg"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="form_txt1">
                  <tr>
                    <td align="right" width="30%">Name of the contact person : </td>
                    <td align="left" width="70%"><input type="text" name="person_name" id="person_name" value="<?php echo ($_POST['person_name'] == '') ? $row['person_name'] : $_POST['person_name']; ?>" /></td>
                    </tr>
                  
                  <tr>
                    <td align="right" width="30%">Company Name : </td>
                    <td align="left" width="70%"><input type="text" name="organisation_name" id="organisation_name" value="<?php echo ($_POST['organisation_name'] == '') ? $row['organisation_name'] : $_POST['organisation_name']; ?>" /></td>
                    </tr>
                  
                  <tr>
                    <td align="right">Address:</td>
                    <td><input type="text" name="address" id="address" value="<?php echo ($_POST['address'] == '') ? $row['address'] : $_POST['address']; ?>" /></td>
                    </tr>
                  
                  <tr>
                    <td align="right">City:</td>
                    <td><input type="text" name="district" id="district" value="<?php echo ($_POST['district'] == '') ? $row['district'] : $_POST['district']; ?>" /></td>
                    </tr>
                  <tr>
                    <td align="right">State:</td>
                    <td><input type="text" name="state" id="state" value="<?php echo ($_POST['state'] == '') ? $row['state'] : $_POST['state']; ?>" />
			</td>
                    </tr>
                  <tr>
                    <td align="right">Zip:</td>
                    <td><input type="text" name="pincode" id="pincode" value="<?php echo ($_POST['pincode'] == '') ? $row['pincode'] : $_POST['pincode']; ?>" /></td>
                    </tr>
                    <tr>
                    <td align="right" width="30%">Website: </td>
                    <td width="70%"><input type="text" name="website" id="website" value="<?php echo ($_POST['website'] == '') ? $row['website'] : $_POST['website']; ?>" /></td>
                  </tr>
                    
                  </table></td>
              </tr>
              <tr>
                <td bgcolor="#990066" class="form_head">Contact Details</td>
              </tr>
              <tr>
                <td valign="top" class="form_bg"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="form_txt1">
                  <tr>
                    <td align="right" width="30%">Phone: </td>
                    <td width="70%"><input type="text" name="phone" id="phone" value="<?php echo ($_POST['phone'] == '') ? $row['phone'] : $_POST['phone']; ?>" /></td>
                  </tr>
                  <tr>
                    <td valign="top" align="right">Fax: </td>
                    <td><input type="text" name="fax" id="fax" value="<?php echo ($_POST['fax'] == '') ? $row['fax'] : $_POST['fax']; ?>" /></td>
                  </tr>
                  <tr>
                    <td valign="top" align="right">Mobile No.: </td>
                    <td><input type="text" name="mobile1" id="mobile1" value="<?php echo ($_POST['mobile1'] == '') ? $row['mobile1'] : $_POST['mobile1']; ?>" /></td>
                  </tr>
                  <tr>
                    <td align="right" width="30%">Email:</td>
                    <td width="70%"><input type="text" name="email1" id="email1" value="<?php echo ($_POST['email1'] == '') ? $row['email1'] : $_POST['email1']; ?>" /></td>
                  </tr>
                </table></td>
              </tr>
              
              <tr>
                <td bgcolor="#990066" class="form_head">Working Details</td>
              </tr>
              <tr>
                <td valign="top" class="form_bg"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="form_txt1">
                  <tr>
                    <td align="right" width="30%">Commodity: </td>
                    <td width="70%"><select name="commodity" style="width:150px !important">

					<option value="">Select</option>

<?php 

$obj1 = new DBClass();

$sql2 = "SELECT * FROM ".TBL_OPTIONS." where `option`='Commodity' and `value`!='' and `status`=0";

$rs2 = $obj1->executeQry($sql2,$link);

while($row2 = $obj1->fetchrow()){ 

?>          

					<option value="<?php echo $row2['value'];?>" <?php if($_POST['commodity'] == $row2['value'] || $row['commodity'] == $row2['value']) echo 'selected'; ?>><?php echo $row2['value'];?></option>

<?php } ?>

				</select></td>
                  </tr>
                  <tr>
                    <td valign="top" align="right">Origin: </td>
                    <td><select name="origin" class="txt_box2" onchange="change_origin1(this.value)"  style="width:150px !important">

					<option value="">Select</option>

<?php 

$sql2 = "SELECT * FROM ".TBL_OPTIONS." where `option`='origin' and `value`!='' and `status`=0";

$rs2 = $obj1->executeQry($sql2,$link);

while($row2 = $obj1->fetchrow()){ 

?>          

					<option value="<?php echo $row2['value'];?>" <?php if($_POST['origin'] == $row2['value'] || $row['origin'] == $row2['value']) echo 'selected'; ?>><?php echo $row2['value'];?></option>

<?php } ?>

				</select></td>
                  </tr>
                  <tr id="area" <?php if($_POST['origin']=='Imported' || $row['origin']=='Imported') { ?> style="display:none"<?php } ?>>
                    <td valign="top" align="right">Area/Mines: </td>
                    <td><select name="area" class="txt_box2"  style="width:150px !important">

					<option value="">Select</option>

<?php 

$sql2 = "SELECT * FROM ".TBL_OPTIONS." where `option`='area' and `value`!='' and `status`=0";

$rs2 = $obj1->executeQry($sql2,$link);

while($row2 = $obj1->fetchrow()){ 

?>          

					<option value="<?php echo $row2['value'];?>" <?php if($_POST['area'] == $row2['value'] || $row['area'] == $row2['value']) echo 'selected'; ?>><?php echo $row2['value'];?></option>

<?php } ?>

				</select></td>
                  </tr>
                  <tr id="mines" <?php if($_POST['origin']!='Imported' && $row['origin']!='Imported') { ?> style="display:none"<?php } ?>>
                    <td align="right" width="30%">Port:</td>
                    <td width="70%"><select name="mines" class="txt_box2"  style="width:150px !important">

					<option value="">Select</option>

<?php 

$sql2 = "SELECT * FROM ".TBL_OPTIONS." where `option`='Port' and `value`!='' and `status`=0";

$rs2 = $obj1->executeQry($sql2,$link);

while($row2 = $obj1->fetchrow()){ 

?>          

					<option value="<?php echo $row2['value'];?>" <?php if($_POST['mines'] == $row2['value'] || $row['mines'] == $row2['value']) echo 'selected'; ?>><?php echo $row2['value'];?></option>

<?php } ?>

				</select></td>
                  </tr>
				  <tr id="subarea" <?php if($_POST['origin']!='Imported' && $row['origin']!='Imported') { ?> style="display:none"<?php } ?>>
				  	<td align="right" width="30%">Sub Area</td>
					<td><input type="text" name="sub_area" /></td>
				  </tr>
                </table></td>
              </tr>
              
              
              <tr>
                <td align="right" valign="top" class="form_bg"><table width="500" border="0" cellpadding="0" cellspacing="0">
                  <tr>
                    <td align="center"><input name="submit" type="submit" class="bg_bt" id="button" value="<?php echo $buton;?>" /></td>
                  </tr>
                  </table></td>
              </tr>

              </table></td>
          </tr>
    </form>s      
          </table></td>
      </tr>
      </table></td>
  </tr>
  <tr>
    <td height="40">&nbsp;</td>
  </tr>
</table>

<?php require_once(INCLUDES_DIR.ADMFOOTER); ?>