<?php include("homeheader.php"); 
?>
<script type="text/javascript" >
function validate(){
	var pwrd = form.pword.value();
	var pwrd2 = form.pasword.value();
	
	if(document.form.pwrd.value !=""  && document.form.pwrd2.value != ""){
		if( pwrd != pwrd2){
			alert("Passwords didn't match! please try again");
			document.form.pword.focus();
			return false;
		}
		return true;
		
	}else{
		alert("Fill all required fields!");
		return false;
	}
}
</script>

  <body class="nav-md">
    <div class="container body">
      <div class="main_container">
        <div class="col-md-3 left_col">
          <div class="left_col scroll-view">
            <!--div class="navbar nav_title" style="border: 0;">
              <a href="index.html" class="site_title">
			   <div class="profile_pic" style="margin-top:-10px;">
			  <img src="images/mlogo.png" alt="" class="img-circle profile_img" />
			    </div>
			  <!--i class="fa fa-paw"></i--> <!--span>Instant Airtime </span></a>
            </div-->

            <div class="clearfix"></div>

            <!-- menu profile quick info -->
            <div class="profile">
              <div class="profile_pic">
			  <?php 
			  if($img == ""){
				  ?>
				   <img src="profileimages/noimage.gif" alt="..." class="img-circle profile_img">
				  <?php
			  }else{
				?>
				 <img src="<?php echo $photo ?>" alt="..." class="img-circle profile_img" width="40px;" height="60px;">
            <?php				
			  }
			  ?>
               
              </div>
             <div class="profile_info">

                <span>Welcome,</span>
			<h2> <?php $fname = $dat['fname']; $lname = $dat['lname']; $comp = $dat['company'];  if(empty($comp)){ echo ucwords($fname." ".$lname); }else{ echo ucwords($comp); }  ?> </h2>
             <!--   <h2>John Doe</h2> -->
              </div>
            </div>
            <!-- /menu profile quick info -->

            <br />

            <!-- sidebar menu -->
            <div id="sidebar-menu" class="main_menu_side hidden-print main_menu">
              <div class="menu_section">
			  <br/>
                <h3>General</h3>
                <ul class="nav side-menu">
                  <li ><a  href="homepage.php" ><i class="fa fa-home"></i>  Home <span class="fa fa-chevron-right"></span></a> </li>
                  <li ><a><i class="fa fa-building"></i> My Contacts <span class="fa fa-chevron-down"></span></a> 
				  <ul class="nav child_menu">
				         <li class="active"><a href="addcontact.php"  ><i class="fa fa-user-plus"></i>Add New Contact<span class="fa fa-chevron-right"></span></a> </li>
						<li><a  href="addnewcontact.php" ><i class="fa fa-eye"></i>View Contacts<span class="fa fa-chevron-down"></span></a>	</li>
					   </ul>
				  </li>
                  <li><a><i class="fa fa-users"></i> Groups <span class="fa fa-chevron-down"></span></a> 
				        <ul class="nav child_menu">
					   <li><a  href="creategroup.php" ><i class="fa fa-paw"></i>Create Group<span class="fa fa-chevron-right"></span></a> </li>
						<li><a    href="viewgroups.php" ><i class="fa fa-eye"></i>View Groups<span class="fa fa-chevron-right"></span></a> </li>
					   </ul>
				  </li>
                  <li><a href="#"><i class="fa fa-table"></i> Topup <span class="fa fa-chevron-down"></span></a>  
				   <ul class="nav child_menu">
				       	<li><a  href="sendtogroup.php" ><i class="fa fa-cloud-download"></i>Top-up Group Contacts <span class="fa fa-chevron-right"></span></a> </li>
						<li><a  href="selectcontacttosend.php" ><i class="fa fa-building"></i>Select Contact(s)<span class="fa fa-chevron-right"></span></a> </li>
                         <li><a  href="sendtome.php" ><i class="fa fa-mobile"></i>Top-up My Line<span class="fa fa-chevron-right"></span></a> </li>
						 <li><a href="autosend-airtime.php" ><i class="fa fa-recycle"></i>Auto-Send Airtime <span class="fa fa-chevron-right"></span></a> </li>
					   </ul>
					  				  
				  </li>
                <li><a><i class="fa fa-gg"></i> Billing <span class="fa fa-chevron-down"></span></a> 
				   <ul class="nav child_menu">
                     <li><a  href="purchasetome.php" ><i class="fa fa-server"></i> Top-up My Account<span class="fa fa-chevron-right"></span></a> </li>
					   </ul>
				  </li>
				   <li><a><i class="fa fa-bar-chart-o"></i> History <span class="fa fa-chevron-down"></span></a>  
				      <!--  <ul class="nav side-menu"> -->
					   <ul class="nav child_menu">
					    <li><a  href="creditassignment.php" ><i class="fa fa-bars"></i>Credit Assignment<span class="fa fa-chevron-right"></span></a> </li>
						
					   </ul>
				   </li>
                </ul>
              </div>

            </div>
			 </div>
        </div>
		
		<?php
        include("topmenubar.php");

         ?>
		 
		 
		 <!-- page content -->
        <div class="right_col" role="main">
		  <!-- /top navigation -->
		    <div class="row">
              <!-- top tiles -->
			<div class="row tile_count">
				<div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count">
					<p>  </p>
				</div>
            
			</div>
			</div>
          <!-- /top tiles -->
		 
			<div class="row">
					<div class="x_title">
						<div style="margin-left:80px;" > <h2>Reset Password </h2> </div>
							<div class="clearfix"></div>
					</div>
					
					 <form name="contacts" data-parsley-validate class="form-horizontal form-label-left" method="post" action="">
						<div class="form-group">
							<label class="control-label col-md-3 col-sm-3 col-xs-3" for="first-name">Old Password: <span class="required"> </span> </label>
								<div class="col-md-3 col-sm-3 col-xs-3" style="padding:10px;">
								    <input type="password" id="name" name="pwordold" required="required" class="form-control col-md-3 col-xs-3" placeholder="Current Password" /> 
								</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-3 col-sm-3 col-xs-3" for="first-name">New Password: <span class="required"> </span> </label>
								<div class="col-md-3 col-sm-3 col-xs-3">
									<input type="password" id="amount" name="pword"  required="required" placeholder="New Password" class="form-control col-md-3 col-xs-3">
								</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-3 col-sm-3 col-xs-3" for="first-name">Re-Enter Password: <span class="required"> </span> </label>
								<div class="col-md-3 col-sm-3 col-xs-3">
									<input type="password" id="amount" name="pasword"  required="required" placeholder="Confirm Password" class="form-control col-md-3 col-xs-3">
								</div>
						</div>
						<br/>
						
						<div class="form-group">
								<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
									<input type="reset"  class="btn btn-primary" name="cancel" value="Cancel" />
										<input type="submit"  class="btn btn-success" name="changepword" value="Save Changes"/>
								</div>
						</div>
			  </form>
					 
				<?php
					if(isset($_POST['changepword'])){
						
						$oldpw = $_POST['pwordold'];
						$pw = $_POST['pword'];
						$pw2 = $_POST['pasword'];
						
						 $usr = $_POST['usernm'];   
		 $password = $_POST['pword']; 
		 
		$host = 'localhost';
        $db   = 'ki223469_temp';
        $user = 'ki223469_temp';
        $pass = 'm0bi.2018$';
        $charset = 'utf8mb4';
        
        $dsn = "mysql:host=$host;dbname=$db;charset=$charset";
        $options = [
            PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
            PDO::ATTR_EMULATE_PREPARES   => false,
        ];
        $pdo = new PDO($dsn, $user, $pass, $options);
		
		//create a select query
		$stmt = $pdo->prepare('SELECT * FROM airtime_customer WHERE customer_id = :cust');
		try{
		    
		    $stmt->execute(['cust' => $session_id]);
		    //get the selected array
		    $user=$stmt->fetch();
		    if(count($user)>0){
		        
		        //verify the password
		        	if(password_verify($oldpw, $user['password'])){
		        	   
		        	   	if($pw == $pw2){
		        	   	    $phashed = password_hash($pw2, PASSWORD_BCRYPT);
								$sql = mysql_query("update airtime_customer set password = '$phashed' where customer_id = '$session_id' ") or die (mysql_error());	
								
								if($sql){
								    
								   $qry = mysql_query("select * from airtime_logs where id = '$session_lid' ");
							        $sdata = mysql_fetch_array($qry);
							        $actions = $sdata['user_actions'];
						        	mysql_query("update airtime_logs set user_actions = '$actions Updated Account Password.' where id = '$session_lid'  "); 
								
								    	?>
									        <script>
									        	alert("Success. Your Password updated successfully.");
									        	window.location="profile.php";
									        </script>
								        <?php
								}
							
							}else{
								?>
									<script>
										alert("Passwords didn't match! Please try again");
										window.location="newpword.php";
									</script>
								<?php
								//echo "Passwords didn't match! Please try again!";
							}
		        	   
		        	}
		        	else{
		        	    	?>
								<script>
									alert("Wrong Password! Please try again");
									window.location="newpword.php";
								</script>
							<?php
		        	}
		    }
		    else
		    {
		       ?>
								<script>
									alert("Account not found");
									window.location="newpword.php";
								</script>
							<?php 
		    }
		    
		}catch(PDOException $ex){
		    	?>
		   <script>
									alert("Error! Kindly contact the Admin");
									window.location="newpword.php";
								</script> 
								<?php
		}
		
						
	}
					
	?>
		 
			</div>
		  
		 </div>
		  
		  
		          <!-- /page content. End of main -->

     <?php include("footerlinks.php"); ?>
 <!-- jQuery -->
    <script src="vendors/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap -->
    <script src="vendors/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- FastClick -->
    <script src="vendors/fastclick/lib/fastclick.js"></script>
    <!-- NProgress -->
    <script src="vendors/nprogress/nprogress.js"></script>
    <!-- Datatables -->
    <script src="vendors/datatables.net/js/jquery.dataTables.min.js"></script>
    <script src="vendors/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
    <script src="vendors/datatables.net-buttons/js/dataTables.buttons.min.js"></script>
    <script src="vendors/datatables.net-buttons-bs/js/buttons.bootstrap.min.js"></script>
    <script src="vendors/datatables.net-buttons/js/buttons.flash.min.js"></script>
    <script src="vendors/datatables.net-buttons/js/buttons.html5.min.js"></script>
    <script src="vendors/datatables.net-buttons/js/buttons.print.min.js"></script>
    <script src="vendors/datatables.net-fixedheader/js/dataTables.fixedHeader.min.js"></script>
    <script src="vendors/datatables.net-keytable/js/dataTables.keyTable.min.js"></script>
    <script src="vendors/datatables.net-responsive/js/dataTables.responsive.min.js"></script>
    <script src="vendors/datatables.net-responsive-bs/js/responsive.bootstrap.js"></script>
    <script src="vendors/datatables.net-scroller/js/datatables.scroller.min.js"></script>
    <script src="vendors/jszip/dist/jszip.min.js"></script>
    <script src="vendors/pdfmake/build/pdfmake.min.js"></script>
    <script src="vendors/pdfmake/build/vfs_fonts.js"></script>