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

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

if(isset($_POST['submit'])){
	if($error == ''){
		if($_POST['submit'] == 'Add Directory'){
			$sqll = "INSERT INTO directory (person_name,organisation_name,address,district,state,pincode,phone,fax,mobile1,mobile2,email1,email2,memberID,added_on,company_details,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['mobile2'])."','".trim($_POST['email1'])."','".trim($_POST['email2'])."','".$_SESSION['memberID']."','".date("Y-m-d")."','".$_POST['company_details']."','".$_POST['website']."') ";
			$rs2 = $obj->executeQry($sqll,$link);
				if($rs2){
					@header('Location: directory.php?msg=add');
					exit;
				}
		}
	
		if($_POST['submit'] == 'Edit Directory'){
			$sqll = "UPDATE directory 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']."', mobile2 = '".$_POST['mobile2']."', email1 = '".$_POST['email1']."', email2 = '".$_POST['email2']."', company_details = '".$_POST['company_details']."', website = '".$_POST['website']."' WHERE id = '".$_GET['id']."'";
			$rs2 = $obj->executeQry($sqll,$link);
			if($rs2){
				@header('Location: directory.php?msg=edit');
				exit;
			}
		}
	}	
}

require_once(INCLUDES_DIR.ADMHEADER); 
?>
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="29" align="center" class="submenu"><a href="directory.php">Manage Directory</a></td>
    <td align="center" class="submenu">Add New</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>
                  <tr>
                    <td align="right" width="30%">Company Details: </td>
                    <td width="70%"><textarea name="company_details" id="company_details" cols="45" rows="5"><?php echo ($_POST['company_details'] == '') ? $row['company_details'] : $_POST['company_details']; ?></textarea></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 valign="top" align="right">Alternate Mobile No.: </td>
                    <td><input type="text" name="mobile2" id="mobile2" value="<?php echo ($_POST['mobile2'] == '') ? $row['mobile2'] : $_POST['mobile2']; ?>" /></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>
                  <tr>
                    <td align="right" width="30%">Alternate Email:</td>
                    <td width="70%"><input type="text" name="email2" id="email2" value="<?php echo ($_POST['email2'] == '') ? $row['email2'] : $_POST['email2']; ?>" /></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>
</form>
              </table></td>
          </tr>
          </table></td>
      </tr>
      </table></td>
  </tr>
  <tr>
    <td height="40">&nbsp;</td>
  </tr>
</table>

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