<?php
session_start();
require_once("header.php");

 
if(isset($_POST['post']))
{

$post=$_POST['post'];

if($post=="Sajili"){
	
 $fname=$_POST['fname'];

 $lname =$_POST['lname'];

 $phoneno =$_POST['phoneno'];

 $email=$_POST['email']; 

 $pwd =md5($_POST['pwd']);

 $date=md5(Date("Ymdhis"));

 if( $email !="" && $pwd!="" && $fname!="" && $phoneno!="" && $lname!=""){
  
$rQ=$dBcon->addClient($fname,$lname,$phoneno,$email,$pwd,$date);
//print_r($rQ);
if ($rQ->rowCount()>0) {
	
	$ownID=$date;	
	 echo "<script> window.location.href='lostPhoneInfoss.php?id=$ownID' </script>";
}
else{

	$r="Taarifa sio sahihi!.";
	
	echo "<script> window.location.href='indexs.php?id=$r' </script>";
}

}
else{
	$r="Taarifa zote zinahitajika!.";
	
	echo "<script> window.location.href='indexs.php?id=$r'</script>";
}
}
}

?>

 <fieldset style="padding-top:5%; padding-right:20%; border-radius:12px; border:0;">
		 <center>
			<form id="usr" method="POST" action="indexs.php">
				<table width="50%" border="0">
					<tr><td><b>Jisajili hapa:</b></td></tr>
					<tr><td><b><font color="red">
						<?php
						if(isset($_GET['id']))
						{
	                     echo $_GET['id'];
                         }
                     ?>

					</font></b></td></tr>
					<tr>
						<td>Jina la kwanza:<sup>*</sup>

						 <br> <sup id="nf"></sup> </br>  

						</td>
					</tr>
					<tr>
						<td>
							<input  id="fname" class="inp" type="text"  placeholder="Jina la kwanza" name="fname"/>
						</td>
					</tr>
					<tr>
						<td>Jina la mwisho:<sup>*</sup>

						 <br> <sup id="ln"></sup> </br>  
</td>
					</tr>
					<tr>
						<td>
							<input type="text" id="lname" class="inp" placeholder="Jina la mwisho" name="lname"/>
						</td>
					</tr>
					<tr>
						<td>Nambari ya simu:<sup>*</sup>

						 <br> <sup id="p"></sup> </br>  
</td>
					</tr>
					<tr>
						<td>
							<input type="text" id="phoneno" class="inp" placeholder="Namba yako simu" name="phoneno"/>
						</td>
					</tr>

					<tr>
						<td>Barua pepe:<sup>*</sup>

						 <br> <sup id="em"></sup> </br>  
</td>
					</tr>
					<tr>
						<td>
							<input type="text" id="email" class="inp"  placeholder="Barua pepe" name="email"/>
						</td>
					</tr>
					<tr>
						<td>Neno la siri:<sup>*</sup>

						 <br> <sup id="pw"></sup> </br>  
                      </td>
					</tr>
					<tr>
						<td>
							<input type="password" id="pwd" class="inp" placeholder="Neno la siri" name="pwd"/>
						</td>
					</tr>
          <tr>
            <td>Thibitisha neno la siri:<sup>*</sup>

             <br> <sup id="cpw"></sup> </br>  
                      </td>
          </tr>
          <tr>
            <td>
              <input type="password" id="cpwd" class="inp" placeholder="Thibitisha neno la siri" name="cpwd"/>
            </td>
          </tr>
					<tr>
						<td>
							<input type="submit"  value="Sajili"  name="post"/>
						</td>
					</tr>
					<tr>
						<td>
							<a href="loginforms.php">Nimeshajisajili</a>
						</td>
					</tr>
					
				</table>
			</form>
		</center>
		</fieldset>
	
	
<?php
require_once("footer.php");
?>
<script type="text/javascript">
$(document).ready(function(){
	
$("#usr").on('submit',function(e){
///////?????????????????///////
e.preventDefault();
 var fname =document.getElementById('fname').value;
$.trim(fname);
var lname =document.getElementById('lname').value;
$.trim(lname);
var email =document.getElementById('email').value;
$.trim(email);
var phoneno =document.getElementById('phoneno').value;
$.trim(phoneno);
var password =document.getElementById('pwd').value;
$.trim(password);

var cpassword =document.getElementById('cpwd').value;
$.trim(cpassword);


var vN =/[\(A-Za-z)]/g;
var nV =/[a-z\s]/i;
  var j=0,k=0, g=0,i=0;

////////////

  var pd =/[\(A-Za-z)]/;
  var  pw =/[\(0-9)]/;

var j=0,k=0, g=0,i=0; 
//password=document.getElementById('password').value;
if(password==""){
 e.preventDefault();
 document.getElementById('pw').innerHTML="Neno la siri inahitajika !..";
 


      }

 else{ 
       for (var i =0; i < password.length ; i++)
        {

             if(password[i].match(pd) )
             {
             j++;
             }
        }
         
        for (var i =0; i < password.length ; i++)
        {

             if(!password[i].match(pd) && !password[i].match(pw) )
             {
             k++;
             }
        }
         
          for (var i =0; i < password.length ; i++)
        {

             if( password[i].match(pw) )
             {
             g++;
             }
        }
         

        if(j<=0)
        {
        e.preventDefault();
         document.getElementById('pw').innerHTML="Neno la siri linahitajika kuwa imara, mchanganyiko wa herufi na namba!.."; 

              
         }
         
         else if(k>0)
         {
        e.preventDefault();
         document.getElementById('pw').innerHTML="Umeweka alama zisizohitajika katika neno la siri"; 

         }
         else if(g<=0)
         {
            e.preventDefault();
            document.getElementById('pw').innerHTML="Neno la siri lazima iwe angalia na ";

         }
         
         else
          {




                     if(password.length<8)
                        {
                     e.preventDefault();
                     document.getElementById('pw').innerHTML="Neno la siri lazima liwe angalau na herufi/alama 8.."; 
              

                        }

                        else
                        { 
                        document.getElementById('pw').innerHTML="";

                         }
            }
          }
        
         
     
 
    j=0, i=0;k=0;g=0; 


                                                   ///CONFIRM PASSWORD VALIDATION


 



if(cpassword=="")
{
e.preventDefault();
document.getElementById('cpw').innerHTML="Thibitisha neno la siri!..";
 
}
 else if(cpassword!=password)
{
e.preventDefault();
document.getElementById('cpw').innerHTML="Neno la siri haliowani!..";
 

 }

 else
 {

document.getElementById('cpw').innerHTML="";
 }


////////////
                                                         //FIRST NAME VALIDATION
if(fname=="")
{
e.preventDefault();

document.getElementById('nf').innerHTML="Jina la kwanza linahitajika!..";
 } 
 else
 {

      for(i=0;i<fname.length;i++)
       {
         if(!fname[i].match(vN))
          {
             j++;

           }
        }
      
       if(j>0){
        e.preventDefault();

       
        document.getElementById('nf').innerHTML="Jina sio sahihi"; 


              }
         else{

        document.getElementById('nf').innerHTML="";

              }
   }
 
    j=0, i=0;

                                                        ///LAST NAME VALIDATION



if(lname==""){
 e.preventDefault();

document.getElementById('ln').innerHTML="Jina la mwisho linahitajika!..";
 
 
              }
 else{

     for(i=0;i<lname.length;i++)
       {
         if(!lname[i].match(vN))
          {
             j++;

           }
        }
      
       if(j>0){
        e.preventDefault();

        document.getElementById('ln').innerHTML="Jina sio sahihi"; 
              }
         else{

        document.getElementById('ln').innerHTML="";

              }
   }
 
    j=0, i=0;
               


                                                    //EMAIL VALIDATION


 
var mail=/[\(A-Za-z)][\w.]\w+@\w+\.(net|com|edu)/;
if(email==""){
 e.preventDefault();
document.getElementById('em').innerHTML="Barua pape inahitajika!..";
 

             }
 else{
  
         if(!email.match(mail))
          {
          
        e.preventDefault();
        document.getElementById('em').innerHTML="Barua pepe sio sahihi.."; 
              }
         else{ 
        document.getElementById('em').innerHTML="";

              }
   }
 
   
///PHONE NUMBER VALIDATION

 var phn =/[\(0-9)]{10,12}/;
   
if(phoneno==""){
e.preventDefault();
document.getElementById('p').innerHTML="Namba ya simu inahitajika!..";
 

              }
 else{ 
       
         if(!phoneno.match(phn))
          {
             
        e.preventDefault();
        document.getElementById('p').innerHTML="Namba ya simu sio sahihi"; 
              
          }
        
        // else if(phoneno.length>12)
         //{
       // e.preventDefault();
        //document.getElementById('p').innerHTML="Valid phone number must contain 12 digits.."; 
              

        // }

         else
         {

        document.getElementById('p').innerHTML="";

        }
   }
 
    j=0, i=0; 

//////////?????//////////////////
}
);
}
);
 						
</script> 
	 <script type="text/javascript">
$(document).ready(function(){
	
$("#usr").on('submit',function(e){
///////?????????????????///////
e.preventDefault();
 var fname =document.getElementById('fname').value;
$.trim(fname);
var lname =document.getElementById('lname').value;
$.trim(lname);
var email =document.getElementById('email').value;
$.trim(email);
var phoneno =document.getElementById('phoneno').value;
$.trim(phoneno);
var password =document.getElementById('pwd').value;
$.trim(password);

var cpassword =document.getElementById('cpwd').value;
$.trim(cpassword);


var vN =/[\(A-Za-z)]/g;
var nV =/[a-z\s]/i;
  var j=0,k=0, g=0,i=0;

////////////

  var pd =/[\(A-Za-z)]/;
  var  pw =/[\(0-9)]/;

var j=0,k=0, g=0,i=0; 
//password=document.getElementById('password').value;
if(password==""){
 e.preventDefault();
 document.getElementById('pw').innerHTML="Neno la siri inahitajika !..";
 


      }

 else{ 
       for (var i =0; i < password.length ; i++)
        {

             if(password[i].match(pd) )
             {
             j++;
             }
        }
         
        for (var i =0; i < password.length ; i++)
        {

             if(!password[i].match(pd) && !password[i].match(pw) )
             {
             k++;
             }
        }
         
          for (var i =0; i < password.length ; i++)
        {

             if( password[i].match(pw) )
             {
             g++;
             }
        }
         

        if(j<=0)
        {
        e.preventDefault();
         document.getElementById('pw').innerHTML="Neno la siri linahitajika kuwa imara, mchanganyiko wa herufi na namba!.."; 

              
         }
         
         else if(k>0)
         {
        e.preventDefault();
         document.getElementById('pw').innerHTML="Umeweka alama zisizohitajika katika neno la siri"; 

         }
         else if(g<=0)
         {
            e.preventDefault();
            document.getElementById('pw').innerHTML="Neno la siri lazima iwe angalia na ";

         }
         
         else
          {




                     if(password.length<8)
                        {
                     e.preventDefault();
                     document.getElementById('pw').innerHTML="Neno la siri lazima liwe angalau na herufi/alama 8.."; 
              

                        }

                        else
                        { 
                        document.getElementById('pw').innerHTML="";

                         }
            }
          }
        
         
     
 
    j=0, i=0;k=0;g=0; 


                                                   ///CONFIRM PASSWORD VALIDATION


 



if(cpassword=="")
{
e.preventDefault();
document.getElementById('cpw').innerHTML="Thibitisha neno la siri!..";
 
}
 else if(cpassword!=password)
{
e.preventDefault();
document.getElementById('cpw').innerHTML="Neno la siri haliowani!..";
 

 }

 else
 {

document.getElementById('cpw').innerHTML="";
 }


////////////
                                                         //FIRST NAME VALIDATION
if(fname=="")
{
e.preventDefault();

document.getElementById('nf').innerHTML="Jina la kwanza linahitajika!..";
 } 
 else
 {

      for(i=0;i<fname.length;i++)
       {
         if(!fname[i].match(vN))
          {
             j++;

           }
        }
      
       if(j>0){
        e.preventDefault();

       
        document.getElementById('nf').innerHTML="Jina sio sahihi"; 


              }
         else{

        document.getElementById('nf').innerHTML="";

              }
   }
 
    j=0, i=0;

                                                        ///LAST NAME VALIDATION



if(lname==""){
 e.preventDefault();

document.getElementById('ln').innerHTML="Jina la mwisho linahitajika!..";
 
 
              }
 else{

     for(i=0;i<lname.length;i++)
       {
         if(!lname[i].match(vN))
          {
             j++;

           }
        }
      
       if(j>0){
        e.preventDefault();

        document.getElementById('ln').innerHTML="Jina sio sahihi"; 
              }
         else{

        document.getElementById('ln').innerHTML="";

              }
   }
 
    j=0, i=0;
               


                                                    //EMAIL VALIDATION


 
var mail=/[\(A-Za-z)][\w.]\w+@\w+\.(net|com|edu)/;
if(email==""){
 e.preventDefault();
document.getElementById('em').innerHTML="Barua pape inahitajika!..";
 

             }
 else{
  
         if(!email.match(mail))
          {
          
        e.preventDefault();
        document.getElementById('em').innerHTML="Barua pepe sio sahihi.."; 
              }
         else{ 
        document.getElementById('em').innerHTML="";

              }
   }
 
   
///PHONE NUMBER VALIDATION

 var phn =/[\(0-9)]{10,12}/;
   
if(phoneno==""){
e.preventDefault();
document.getElementById('p').innerHTML="Namba ya simu inahitajika!..";
 

              }
 else{ 
       
         if(!phoneno.match(phn))
          {
             
        e.preventDefault();
        document.getElementById('p').innerHTML="Namba ya simu sio sahihi"; 
              
          }
        
        // else if(phoneno.length>12)
         //{
       // e.preventDefault();
        //document.getElementById('p').innerHTML="Valid phone number must contain 12 digits.."; 
              

        // }

         else
         {

        document.getElementById('p').innerHTML="";

        }
   }
 
    j=0, i=0; 

//////////?????//////////////////
}
);
}
);
 						
</script> 
	 