<?php include("homeheader.php");?>
<script type="text/javascript">
 function validate() {
var str=document.form1.phone.value;
       var valid="1234567890";
	   
	   for(i=0;i<str.length;i++){
	   if(valid.indexOf(str.charAt(i))==-1) {
	   alert("Phone Number can only be Numeric!");
	   document.form1.phone.value=="";
	   document.form1.phone.focus();
	   return false;
	   }
	   }
	   if(document.form1.phone.value=="") {
		   alert("enter your phone number");
		   document.form1.phone.value=="";
	       document.form1.phone.focus();
		   return false;
		   
	   }
  
	   if(document.form1.phone.value==""){
	 alert("Enter Phone No");
	document.form1.phone.focus();
	return false;
   }
   var phne = form1.phone.value;
  if(phne.length < 10){
	  alert("Enter A valid Phone Nember!");
	document.form1.phone.focus();
	return false;
	  
   }
   var pwrd = form1.password.value;
   var pwrd2 = form1.confpassword.value;
   if(pwrd != pwrd2 ){
	   
	   alert("Passwords didn't match! Please Try Again!");
	   document.form1.pwrd.value="";
	   document.form1.pwrd2.value="";
	   document.form1.pwrd.focus();
	return false;
   }
	  var user = form1.username.value; 
	  if(user.length < 6){
		  
		     alert("Username should be Atleast 6 Characers!");
			   document.form1.username.focus();
	   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>
			    <span>Instant Airtime </span>
            </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']; echo $fname." ".$lname ?> </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">
			  
                <h3>General</h3>
                <ul class="nav side-menu">
                  <li class="active"><a  href="adminpage.php" ><i class="fa fa-home"></i>  Home <span class="fa fa-chevron-right"></span></a> </li>
                   <li><a href="#">  Users <span class="fa fa-chevron-down"></span></a> 
				  <ul class="nav child_menu">
					    <li ><a  href="adduser.php" ><i class="fa fa-bug"></i>Create User<span class="fa fa-chevron-right"></span></a> </li>
						<li><a  href="viewuser.php" ><i class="fa fa-edit"></i>View Users<span class="fa fa-chevron-down"></span></a> </li>
					   </ul>
				  </li>
                  <li><a href="contacts.php">  View Contacts <span class="fa fa-chevron-right"></span> </a> </li>
                  <li><a href="groups.php"> View Groups  <span class="fa fa-chevron-right"></span> </a>   </li>
                 
				   <!--li><a> Reports <span class="fa fa-chevron-down"></span></a>  
					   <ul class="nav child_menu">
					    <li><a  href="buyinghistory.php" > Purchase History <span class="fa fa-chevron-right"></span> </a> </li>
						<li><a  href="sendinghistory.php" > Sending History <span class="fa fa-chevron-right"></span> </a></li>
					   </ul>
				   </li-->
                </ul>
              </div>

            </div>  <!-- side menu -->
			 </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>Airtime Portal </p>
						</div>
            
					</div>
				</div>
                 <!-- /top tiles -->
		 
				<div class="row">
		 
					<div style="margin-left:20px;"><a href="viewadmins.php">  <button class="btn btn-primary " > View Admins </button> </a> </div>
					<hr>
		  
						<form name="form1" data-parsley-validate class="form-horizontal form-label-left" method="post" action="" onsubmit="return validate()" >
								<div class="form-group">
									<label class="control-label col-md-3 col-sm-3 col-xs-3" for="first-name">First Name <span class="required"> </span>
										</label>
									<div class="col-md-4 col-sm-4 col-xs-5">
										<input type="text" id="fname" name="fname" required="required" 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="last-name">Last Name <span class="required"></span>
									</label>
										<div class="col-md-4 col-sm-4 col-xs-5">
											<input type="text" id="lname" name="lname" required="required" 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="last-name">Company <span class="required"></span>
									</label>
										<div class="col-md-4 col-sm-4 col-xs-5">
											<input type="text" id="compny" name="compny" value="<?php echo $dat['company']; ?>" required="required" class="form-control col-md-3 col-xs-3" readonly />
										</div>
								</div>
								<div class="form-group">
									<label class="control-label col-md-3 col-sm-3 col-xs-3" for="last-name">Username <span class="required"></span>
									</label>
										<div class="col-md-4 col-sm-4 col-xs-5">
											<input type="text" id="username" name="username" required="required" 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="last-name">Password <span class="required"></span>
									</label>
										<div class="col-md-4 col-sm-4 col-xs-5">
											<input type="password" id="password" name="password" required="required" 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="last-name">Re-Enter Password <span class="required"></span>
									</label>
										<div class="col-md-4 col-sm-4 col-xs-5">
											<input type="password" id="confpassword" name="confpassword" required="required" 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="last-name">Mobile Number <span class="required"></span>
										</label>
											<div class="col-md-4 col-sm-4 col-xs-5">
												<input type="text" id="phone" name="phone" required="required" 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="last-name">Email <span class="required"></span>
										</label>
											<div class="col-md-4 col-sm-4 col-xs-5">
												<input type="email" id="email" name="email" required="required" class="form-control col-md-3 col-xs-3">
											</div>
								</div>
					  
					  
							<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="send" value="Register Admin"/>
								</div>
							</div>
						</form>
		                         <?php
	
	if(isset($_POST['send'])){
		include("dbconnection.php");
		
		 $email = $_POST['email'];
		 $fname = $_POST['fname']; 
		 $lname = $_POST['lname']; 
		 $frm = $_POST['compny']; 
		 $username = $_POST['username'];   
		 $password = $_POST['password'];  
		 $phone = $_POST['phone'];  
		 $confpwrd = $_POST['confpassword'];  
		// echo $phone;
		
	  if($email !=null &&  $fname != null && $lname != null && $username != null && $password  != null && $confpwrd  != null ){
		  
		  if( $password !=  $confpwrd ){
			    echo ' <div class="col-md-offset-3 col-md-9">
                              <button id="btn-signup" type="button" class="btn btn-error"><i class="icon-hand-right"></i> Passwords didnot Match! Please try again!</button>
                                         
                                    </div>';
			  
		  }
		  else{
			  $sql = "select * from airtime_customer where email='$email' ";
		  $result = mysql_query($sql);
		  $nomrows = mysql_num_rows($result);
		  if($nomrows > 0){
			  //error message
			  echo ' <div class="col-md-offset-3 col-md-9">
                                        <button id="btn-signup" type="button" class="btn btn-error"><i class="icon-hand-right"></i>That email is Already Registered! Please try again!</button>
                                         
                                    </div>';
			  
		  }
		  else{
			  // register thiu user
			  $salt1 = "qm&h*";
              $salt2 = "pg!@";
			//  $token = md5("$salt1$password$salt2");
			  $name=$fname." ".$lname;
			  $query ="insert into airtime_customer values('', '$fname', '$lname','$username','$password', '$phone', '$email', 'Admin', now(),'Active','$frm', '')";
			  $rslt = mysql_query($query);
			  if(!$rslt){
				   echo ' <div class="col-md-offset-3 col-md-9">
                                        <button id="btn-signup" type="button" class="btn btn-error"><i class="icon-hand-right"></i>Error Registering! Username Already in use! </button>
                                         
                                    </div>';
				  
			  }
			  else{
				   $qry2 = mysql_query("select * from airtime_logs where id='$session_lid' ");
						$sdata=mysql_fetch_array($qry2);
												
						$actions = $sdata['user_actions'];
						mysql_query("update airtime_logs set user_actions='$actions Added a new Admin - $name.' where id='$session_lid'  ");
				  echo ' <div class="col-md-offset-3 col-md-9">
                                        <button id="btn-signup" type="button" class="btn btn-success"><i class="icon-hand-right"></i>Registered Successfully! </button>
										
                                       
                                    </div>';
			  }
			  }
		  }
		  
		  
		  
	  }else{
		   				  echo ' <div class="col-md-offset-3 col-md-9">
                                        <button id="btn-signup" type="button" class="btn btn-success"><i class="icon-hand-right"></i>Fill All Required Fields! </button>
                                         
                                    </div>';
		
	 }
	}
	
	
	
	?>
		 
				</div>
		  
			</div>
		  
		  
		          <!-- /page content. End of main -->

     <?php include("footerlinks.php"); ?>
	 <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>
    <!-- Chart.js -->
    <script src="../vendors/Chart.js/dist/Chart.min.js"></script>
    <!-- gauge.js -->
    <script src="../vendors/bernii/gauge.js/dist/gauge.min.js"></script>
    <!-- bootstrap-progressbar -->
    <script src="../vendors/bootstrap-progressbar/bootstrap-progressbar.min.js"></script>
    <!-- iCheck -->
    <script src="../vendors/iCheck/icheck.min.js"></script>
    <!-- Skycons -->
    <script src="../vendors/skycons/skycons.js"></script>
    <!-- Flot -->
    <script src="../vendors/Flot/jquery.flot.js"></script>
    <script src="../vendors/Flot/jquery.flot.pie.js"></script>
    <script src="../vendors/Flot/jquery.flot.time.js"></script>
    <script src="../vendors/Flot/jquery.flot.stack.js"></script>
    <script src="../vendors/Flot/jquery.flot.resize.js"></script>
    <!-- Flot plugins -->
    <script src="../js/flot/jquery.flot.orderBars.js"></script>
    <script src="../js/flot/date.js"></script>
    <script src="../js/flot/jquery.flot.spline.js"></script>
    <script src="../js/flot/curvedLines.js"></script>
    <!-- jVectorMap -->
    <script src="../js/maps/jquery-jvectormap-2.0.3.min.js"></script>
    <!-- bootstrap-daterangepicker -->
    <script src="../js/moment/moment.min.js"></script>
    <script src="../js/datepicker/daterangepicker.js"></script>
	

		  
		  