<?php include("homeheader.php");?>
<script type="text/javascript">
 function validate() {
var str=document.form1.contact.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.myForm.phone.value=="";
	   document.myForm.phone.focus();
	   return false;
	   }}
	   if(document.myForm.phone.value=="") {
		   alert("enter your phone number");
		   document.form1.contact.value=="";
	       document.form1.contact.focus();
		   return false;
		   
	   }
  
	   if(document.form1.contact.value==""){
	 alert("Enter Phone No");
	document.form1.contact.focus();
	return false;
   }
  var phne = form1.contact.value;
  if(phne.length < 10){
	  alert("Enter A valid Phone Nember!");
	document.form1.contact.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>
			  <!--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> 
						<!--ul class="nav child_menu">
						 <li><a  href=" ><i class="fa fa-bug"></i>List<span class="fa fa-chevron-right"></span></a> </li>
						<li><a  href="viewcontacts.php" ><i class="fa fa-bug"></i>Grid<span class="fa fa-chevron-right"></span></a> </li>
						</ul-->
						</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><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>  <!-- 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="addnewcontact.php">  <button class="btn btn-primary " > View Contacts </button> </a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="uploadcontacts.php">  <button class="btn btn-primary " > Upload Contacts </button> </a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="example.csv" download >  <button class="btn btn-warning " > Download Sample template </button> </a></div>
						
						<form name="form1" 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">Contact Name <span class="required"> </span>
										</label>
									<div class="col-md-4 col-sm-4 col-xs-5">
										<input type="text"  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="first-name">Mobile Number <span class="required"></span>
										</label>
											<div class="col-md-4 col-sm-4 col-xs-5">
												<input type="text" id="cont" name="mobile" required="required" class="form-control col-md-3 col-xs-3"  > <b style="color:green;"> 07XXXXXXXX</b>
											</div>
								</div>
					  
								<div class="form-group">
										<label class="control-label col-md-3 col-sm-3 col-xs-3" for="first-name"> Select Group <span class="required"></span>
										</label>
											<div class="col-md-4 col-sm-4 col-xs-5">
												<select class="form-control" name="grup" reguired>
													<option>--Assign Group--</option>
													<?php 
														$grps = mysql_query("select * from airtime_groups where customer_id='$session_id' order by group_id");
															$numrows = mysql_num_rows($grps);
																if($numrows == 0){
														         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>Invalid! You Have Not Created Any Group Yet! </button>
                                         
																	</div>';
																}
																else{
																	while($record = mysql_fetch_array($grps)){
																		
																			echo ' <option value="'.$record['group_id'].'">'.$record['name'].'</option>';
																	}
																}
														
						 
													?>    
												</select>
											</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_data" value="Save Contact"/>
								</div>
							</div>
						</form>
		 
				</div>
				
				    <?php
       
	                            if(isset($_POST['send_data'])){
					
									$fname = $_POST['fname'];
									$phone = $_POST['mobile'];
									$grp = $_POST['grup'];
					
									if($grp != "--Assign Group--"){
										
										$cn = mysql_query("select * from airtime_contacts where customer_id = '$session_id' and contact = '$phone' and group_id = '$grp' ");
										$numrows = mysql_num_rows($cn);
						
										if($numrows > 0){
											echo ' <div class="col-md-offset-3 col-md-9">
											<button id="btn-signup" type="button" class="btn btn-danger"><i class="icon-hand-right"></i> This contact has already been added! Add a different contact. </button>
										 </div>';
											
										}
										else{
											
											$query = mysql_query("insert into airtime_contacts values('', '$session_id', '$fname', '$phone', '$grp', '') ");
											
											if($query){
												// contact id for log data
												$contact_id = mysql_insert_id();
												$name = $fname;
												// get group name
												$qry1 = mysql_query("select * from airtime_groups where group_id = '$grp' ");
												$gdt=mysql_fetch_array($qry1);
												$gname = $gdt['name'];
												// collect current user actions  for this session
												$qry = mysql_query("select * from airtime_logs where id = '$session_lid' ");
												$sdata=mysql_fetch_array($qry);
												
												if($sdata['user_actions'] == ""){
													mysql_query("update airtime_logs set user_actions = 'Added a new contact - $name to $gname.' where id = '$session_lid'  ");
													?>
														<script>
															alert("Contact Saved Successfully.");
														</script>
													<?php
													
												}else{
													$actions = $sdata['user_actions'];
													mysql_query("update airtime_logs set user_actions = '$actions Added a new contact - $name to Group - $gname.' where id = '$session_lid'  ");
													?>
														<script>
															alert("Contact Saved Successfully.");
														</script>
													<?php
												}
													
											}
											}
										
									}
										else {
											echo ' <div class="col-md-offset-3 col-md-9">
											<button id="btn-signup" type="button" class="btn btn-danger"><i class="icon-hand-right"></i> Choose Group before you save contact! </button>
                                         
										 </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>
	

		  
		  