<?php
include 'connection.php';
session_start();
if (!isset($_SESSION['is_logged_in'])) {
    header("Location:login.php");
    die();
    }

date_default_timezone_set('Asia/Calcutta');
$today = date("Y-m-d");
$time = date("h:i A"); 
$currentyear = date("Y");

?>
<?php 
$querylogin = "select * from staff_login where username = '". $_SESSION["LOGIN_NAME"]."' AND password = '".$_SESSION["EMPLOYEE_PASSWORD"]."'";
$resultlogin = mysql_query($querylogin,$conn);
while($row=mysql_fetch_array($resultlogin))
{
$Designation = $row['designation'];
$staff_name = $row['staff_name'];

}
?>
<?php
function randomPassword() {
    $alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $pass = array(); //remember to declare $pass as an array
    $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
    for ($i = 0; $i < 5; $i++) {
        $n = rand(0, $alphaLength);
        $pass[] = $alphabet[$n];
    }
    return implode($pass); //turn the array into a string
}
$unique_id = randomPassword();
?>
<?php



//echo $qry2;
$customer_id = $_REQUEST['customer_id'];
$saul = $_POST['saul'];
$name = $_POST['name'];
$gender = $_POST['gender'];
$bday = $_POST['bday'];
$department = $_POST['department'];
$designation = $_POST['designation'];
$contact_types = $_POST['contact_types'];
$email = $_POST['email'];
$office_phone = $_POST['office_phone'];
$mobile_no = $_POST['mobile_no'];
$linkedinid = $_POST['linkedinid'];
$twitterid = $_POST['twitterid'];
$remark = $_POST['remark'];
if($_REQUEST['contact_id']=='' AND $_REQUEST['newcontact']!='')
{
$query3 = "insert into contact_person(customer_id,saul,name,gender,bday,department,designation,contact_types,email,office_phone,mobile_no,linkedinid,twitterid,remark,customer_name) values ('$customer_id','$saul','$name','$gender','$bday','$department','$designation','$contact_types','$email','$office_phone','$mobile_no','$linkedinid','$twitterid','$remark','$customer_name')";
//echo $query3;
$r3=mysql_query($query3,$conn);

}else {
$query3 = "update contact_person set saul = '$saul', name= '$name', gender = '$gender', bday = '$bday',department='$department',designation='$designation',contact_types='$contact_types',email='$email',office_phone='$office_phone',mobile_no='$mobile_no',linkedinid='$linkedinid',twitterid='$twitterid',remark='$remark',customer_name='$customer_name' where customer_id = '".$_REQUEST['customer_id']."' AND contact_id='".$_REQUEST['contact_id']."'";
//echo $query3;
$r3=mysql_query($query3,$conn);

}
//exit();
//echo $qry3;
?> 

<script>
javascript:window.location.href="edit_accounts.php?customer_id=<?php echo $_REQUEST['customer_id'] ?>&&id=<?php echo $_REQUEST['id'];?>";
</script>
