<?php
include('../config.php');
include('inc.session-create.php');
$PageTitle="Update Profile";
$FileName = 'login_profile.php';
$validate=new Validation();
if($_SESSION['success']!="")
{
   $stat['success']=$_SESSION['success'];
   unset($_SESSION['success']);
}
if(isset($_POST['updatebank']))
{
 		$aryData=array(
						'bankname'          => 	$_POST['bankname'],
						'bankname'          => 	$_POST['bankname'],
						'accountno'         => 	$_POST['accountno'],
						'ifsccode'          => 	$_POST['ifsccode'],
						'swiftcode'         => 	$_POST['swiftcode'],
						'numberemailwire'   => 	$_POST['numberemailwire'],
						'transferibmnumber' => 	$_POST['transferibmnumber'],
						'benefitnumber' 	=> 	$_POST['benefitnumber'],
						);
		$flgIn = $db->updateAry("setting_bankdetail", $aryData , "where id='1'");
		// echo $db->getLastQuery();	exit;
		$stat	 =	'Record Updated successfully';
		$result = 	array("error"=>	0, "msg"=> $stat,);
		$iJsonResult = json_encode($result);
		echo $iJsonResult;
		exit;
 }
elseif(isset($_POST['updaterecord']))
	{
$validate->addRule($_POST['fullname'],'','Full name',true);
$validate->addRule($_POST['emailid'],'email','Emali id',true);
$validate->addRule($_POST['mobileno'],'num','Mobile No.',true,10,10);
if($validate->validate() && count($stat)==0)
  {
		if(isset($_FILES["profilepic"]["name"]) && !empty($_FILES["profilepic"]["name"]))
			{
				$filename = basename($_FILES['profilepic']['name']);
				$ext1 = strtolower(substr($filename, strrpos($filename, '.')+1));
				if(in_array($ext1,array('jpg','png', 'gif')))
				{
					$newfile=md5(time())."_".$filename;
					move_uploaded_file($_FILES['profilepic']['tmp_name'],"../uploads/".$newfile);
				 }
			 }
		else { $newfile =$_POST['image_old']; }

$iEMailId	=$db->getVal("select id from  admin_login where emailid='".$_POST['emailid']."' and id!='".$_SESSION['SUPER_ADMIN']['id']."'");
$iMobileNo	=$db->getVal("select   mobileno from  admin_login where mobileno='".$_POST['mobileno']."' and id!='".$_SESSION['SUPER_ADMIN']['id']."'");
		   if($iEMailId!='')
			{
				$stat['error'] = "This email id is already register";
			}
			elseif($iMobileNo!='')
			{
				$stat['error'] = "This mobile no is already register";
			}
			else{
					$aryData=array(
										'fullname'     	 	     			=>	$_POST['fullname'],
										'profilepic'     	 	     		=>	$newfile,
										'mobileno'     	 	    			=>	$_POST['mobileno'],
										'emailid'     	 	     			=>	$_POST['emailid'],
										'company'     	 	     			=>	$_POST['company'],
									 );
					$flgIn = $db->updateAry("admin_login", $aryData , "where id='".$_SESSION['SUPER_ADMIN']['id']."'");
					$_SESSION['success']="Record Updated Successfully";
					unset($_POST);
					redirect($FileName);
			}
	} else {
			$stat['error'] = $validate->errors();
 	}
}
?>
<!DOCTYPE html>
<html>
<head>
<?php include('inc.meta.php'); ?>
</head>
<body class="fixed-left">
<div id="wrapper">
<?php include('inc.header.php'); ?>
  <?php include('inc.sideleft.php'); ?>
  <div class="content-page">
    <div class="content">
      <div class="container">
        <div class="row">
          <div class="col-sm-12">
            <h4 class="page-title"><?php echo $PageTitle; ?></h4>
          </div>
        </div>
        <div class="row">
          <div class="col-md-12">
            <div class="card-box aplhanewclass">
              <div class="row">
                <div class="col-md-9"> <?php echo msg($stat); ?> </div>
                <div class="col-md-3"> </div>
              </div>
            </div>
            <?php   $iLoginUserDetails=$db->getRow("select * from admin_login where id='".$_SESSION['SUPER_ADMIN']['id']."'");  ?>
            <div class="card-box">
              <form role="form" action="" method="post" enctype="multipart/form-data">
                <div class="row">
                  <div class="col-lg-6 col-md-6">
                    <div class="form-group clearfix">
                      <label class="col-lg-12 control-label">Ful Name</label>
                      <div class="col-lg-12">
                        <input type="text" name="fullname" class="form-control" value="<?php echo $iLoginUserDetails['fullname']; ?>" >
                      </div>
                    </div>
                  </div>
                  <div class="col-lg-6 col-md-6">
                    <div class="form-group clearfix">
                      <label class="col-lg-12 control-label">Email Id</label>
                      <div class="col-lg-12">
                        <input type="emailid" name="emailid" class="form-control" value="<?php echo $iLoginUserDetails['emailid']; ?>" >
                      </div>
                    </div>
                  </div>
                  <div class="col-lg-6 col-md-6">
                    <div class="form-group clearfix">
                      <label class="col-lg-12 control-label">Contact No.*</label>
                      <div class="col-lg-12">
                        <input type="text" name="mobileno" class="form-control" value="<?php echo $iLoginUserDetails['mobileno']; ?>" >
                      </div>
                    </div>
                  </div>
                  <div class="col-lg-6 col-md-6">
                    <div class="form-group clearfix">
                      <label class="col-lg-12 control-label">Company</label>
                      <div class="col-lg-12">
                        <input type="text" name="company" class="form-control" value="<?php echo $iLoginUserDetails['company']; ?>" >
                      </div>
                    </div>
                  </div>


                </div>
                <div class="row footsect">
                  <div class="col-lg-12 col-md-12">
                    <div class="form-group clearfix">
                      <button type="submit" name="updaterecord" class="btn btn-default"><i class="fa fa-paper-plane-o"></i> Update</button>
                    </div>
                  </div>
                </div>
              </form>
            </div>
            <?php  $iBankDetail=$db->getRow("select * from   setting_bankdetail where id='1'");?>
	 		<div class="card-box">
		<h3 class="prohead"><?php echo BANK_DETAILS; ?></h3>
		<form role="form" action="" method="post"  id="bank"   enctype="multipart/form-data">
		  <div class="row">
			<div class="col-md-6">
			  <div class="form-group clearfix">
				<label class="col-md-12 control-label"><?php echo BANK_NAME; ?></label>
				<div class="col-md-12">
				  <input type="text" class="form-control" name="bankname"  value="<?php echo $iBankDetail['bankname']; ?>">
				</div>
			  </div>
			</div>
			<div class="col-md-6">
			  <div class="form-group clearfix">
				<label class="col-md-12 control-label"><?php echo ACCOUNT_NUMBER; ?></label>
				<div class="col-md-12">
				  <input type="text" class="form-control" name="accountno"  value="<?php echo $iBankDetail['accountno']; ?>">
				</div>
			  </div>
			</div>
			<div class="col-md-6">
			  <div class="form-group clearfix">
				<label class="col-md-12 control-label"><?php echo IFSC_CODE; ?></label>
				<div class="col-md-12">
				  <input type="text" class="form-control" name="ifsccode"  value="<?php echo $iBankDetail['ifsccode']; ?>">
				</div>
			  </div>
			</div>
			<div class="col-md-6">
			  <div class="form-group clearfix">
				<label class="col-md-12 control-label"><?php echo SWIFT_CODE; ?></label>
				<div class="col-md-12">
				  <input type="text" class="form-control" name="swiftcode"   value="<?php echo $iBankDetail['swiftcode']; ?>">
				</div>
			  </div>
			</div>
			<div class="col-md-6">
			  <div class="form-group clearfix">
				<label class="col-md-12 control-label"><?php echo NUMBER_EMAIL_WIRE; ?></label>
				<div class="col-md-12">
				  <input type="text" class="form-control" name="numberemailwire"   value="<?php echo $iBankDetail['numberemailwire']; ?>">
				</div>
			  </div>
			</div>
			<div class="col-md-6">
			  <div class="form-group clearfix">
				<label class="col-md-12 control-label"><?php echo TRANSFER_IBAN_NUMBER; ?></label>
				<div class="col-md-12">
				  <input type="text" class="form-control" name="transferibmnumber"   value="<?php echo $iBankDetail['transferibmnumber']; ?>">
				</div>
			  </div>
			</div>
			<div class="col-md-6">
			  <div class="form-group clearfix">
				<label class="col-md-12 control-label"><?php echo BENEFIT_NUMBER; ?></label>
				<div class="col-md-12">
				  <input type="text" class="form-control" name="benefitnumber"   value="<?php echo $iBankDetail['benefitnumber']; ?>">
				</div>
			  </div>
			</div>
		  </div>
		  <div class="row footsect">
			<div class="col-xs-12" id="showerror5"></div>
			<div class="col-md-12 mt-10">
			  <input type="hidden" name="updatebank" value="updatebank">
			  <button type="button"  onclick="upbank()" class="btn btn-default" id="updaterecord"><i class="fa fa-paper-plane-o"></i> <?php echo SUBMIT; ?></button>
			</div>
		  </div>
		</form>
	  </div>
          </div>
        </div>
      </div>
    </div>
    <?php include('inc.footer.php'); ?>
  </div>
</div>
<?php include('inc.js.php'); ?>
<script>
function upbank()
{
	var form = document.getElementById("bank");
	var XHR = new XMLHttpRequest();
	var FD = new FormData( form );
		XHR.addEventListener( "load", function(event) {
		//	alert(this.response);
		var ResData 	= 	this.response;
		var JsonData 	= 	JSON.parse(ResData);
		//	alert(JsonData.error);
		if(JsonData.error==1)
			{
				 document.getElementById("showerror5").innerHTML= '<div class="alert-error">'+JsonData.msg+'</div>';
			} else {
				document.getElementById("showerror5").innerHTML= '<div class="alert-success">'+JsonData.msg+'</div>';
			}
		});
		XHR.open("POST","<?php echo $FileName; ?>");
		XHR.send(FD);
}
</script>
</body>
</html>