<?php
session_start();
include ("includes/security.php");
include ("includes/database.php");
include ("includes/setting.php");

//retrieved logged's user data
$username=$_SESSION["username"];
$dataUser=mysqli_query($newcon,"SELECT * from user where username='$username'");
$bil_rekod=mysqli_num_rows($dataUser);
$showData=mysqli_fetch_array($dataUser);



//retrieved tbl_data2

$parliment=mysqli_query($newcon,"SELECT * from parliment");

$stata=mysqli_query($newcon,"SELECT * from stata");

$ybstate=mysqli_query($newcon,"SELECT * from ybstate");




?>

<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title><?php echo $tajuk; ?></title>

    <!-- Bootstrap Core CSS -->
    <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

    <!-- MetisMenu CSS -->
    <link href="vendor/metisMenu/metisMenu.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="dist/css/sb-admin-2.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body>

    <div id="wrapper">

        <!-- Navigation -->
        <nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="index.html"><?php echo $tajuk; ?></a>
            </div>
            <!-- /.navbar-header -->

            <ul class="nav navbar-top-links navbar-right">

               
                
                <li class="dropdown">
                    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                        <i class="fa fa-user fa-fw"></i> <i class="fa fa-caret-down"></i>
                    </a>
                    <ul class="dropdown-menu dropdown-user">
<?php include ("includes/menu_atas.php"); ?>
                    </ul>
                    <!-- /.dropdown-user -->
                </li>
                <!-- /.dropdown -->
            </ul>
            <!-- /.navbar-top-links -->

            <div class="navbar-default sidebar" role="navigation">
                <div class="sidebar-nav navbar-collapse">
                    <ul class="nav" id="side-menu">
                        
                        <?php include "includes/menu_tepi.php";?>
                    </ul>
                </div>
                <!-- /.sidebar-collapse -->
            </div>
            <!-- /.navbar-static-side -->
        </nav>

        <!-- Page Content -->
        <div id="page-wrapper">
            <div class="container-fluid">
                <div class="row">
                  <div class="col-lg-12">
                    <table width="751" border="1">
                    </table>
                    <div class="col-lg-12">
                      <h1 class="page-header"><font face="Times new roman" size="12" color="#000099">Hello ! ! Welcome to YB Profile...</font></h1>
                      
                       <?php
						
						if (!isset($_POST ["name"]))
						{
							?>
                            
                        <form role="form" method="post" enctype="multipart/form-data">
                        
                            <fieldset>
                            
                           
                            <div class="form-group">
                            <label>YB Name</label>
                                    <input class="form-control" placeholder="Name" name="name" type="text" required autocomplete"off">
                                </div>
                            <label>YB Password</label>
                                    <input class="form-control" placeholder="Password" name="password" type="password" required autocomplete"off">
                                </div> 
                                
                            <div class="form-group">
                            <label>YB IC</label>
                                    <input class="form-control" placeholder="Enter your IC number." name="ic" type="text" required autocomplete"off">
                                
                                
                                
                              <div class="form-group">
                            <label>YB State</label>
                            <select name="state" class="form-control">
                                  <?php
								  while($show123=mysqli_fetch_array($ybstate))
                                   {
                                   ?>
                                   
                                   <option><?php echo $show123['statename']; ?></option>
                                   <?php
								   }
								   ?>
                                   </select>
                                  </div>      
                                
                                   
                                  
                              <div class="form-group">
                            <label>P code</label>
                                  
                                  <select name="code1" class="form-control">
                                  <option>-</option>
                                  <?php
								  while($show123=mysqli_fetch_array($parliment))
                                   {
                                   ?>
                                   
                                   <option><?php echo $show123['parliment_code']; ?> -<?php echo $show123['parliment_name']; ?></option>
                                   <?php
								   }
								   ?>
                                   </select>
                                  </div>      
                                
                                  
                              <div class="form-group">
                            <label>S Code</label>
                             <select name="code2" class="form-control">
                             <option>-</option>
                                  <?php
								  while($show123=mysqli_fetch_array($stata))
                                   {
                                   ?>
                                   
                                   <option><?php echo $show123['state_code']; ?> -<?php echo $show123['state_name']; ?></option>
                                   <?php
								   }
								   ?>
                                   </select>
                                        </div>      
                                
                             <div class="form-group">
                            <label>YB Phone</label>
                                    
                                    <input class="form-control" placeholder="Phone" name="phone" type="tel" required autocomplete"off">
                                </div>       
                                
                          <div class="form-group">
                            <label>YB Email</label>
                            <input class="form-control" placeholder="Email" name="email" type="type" required autocomplete"off">
                          </div>  
                                
                           <div class="form-group has-feedback">
                           <label>Picture</label>
        <input type="file" class="form-control" name="pic" placeholder="YB Picture" required>
        <span class="glyphicon glyphicon-user form-control-feedback"></span>
      </div>           
                                
                            
                                
                                <!-- Change this to a button or input when using this as a form -->
                                <input type="submit" class="btn btn-lg btn-success btn-block" value="Register">
                                <a href="addyb.php" class="btn btn-lg btn-danger btn-block">Cancel</a>
                                
                            </fieldset>
                        </form>
                        
                       <?php
						}
						else
						{
							
							//get data from input
							
$pwd=md5($_POST["password"]);
							$name=$_POST["name"];
							$ic=$_POST["ic"];
							$statename=$_POST["state"];
							$phone=$_POST["phone"];
							$email=$_POST["email"];
							$Pcode=$_POST["code1"];
							$Scode=$_POST["code2"];
							
							
							//check duplicate
							
							$data=mysqli_query($newcon, "SELECT * FROM yb where YB_ic='$ic'");
							$bil_rekod=mysqli_num_rows($data);
							$show=mysqli_fetch_array($data);
							
							if ($bil_rekod!=0)
							{
							
							
							?>
                            
                            <div class="alert alert-success">
                               Account already existed in the system. <a href="addyb.php" class="alert-link">click here to cancel</a>.
                            </div>
                            
                         <?php
							}
							else
							{
			
//upload picture
$masa=date("ymdhis");$namaFile=$username.$masa.$_FILES["pic"]["name"];
move_uploaded_file($_FILES["pic"]["tmp_name"],"yb/".$namaFile);
					
//insert data into database		
mysqli_query($newcon,"INSERT INTO yb (YB_pwd,YB_name,YB_ic,YB_code1,YB_code2,YB_state,YB_phoneNO,YB_email,YB_pic) values ('$pwd','$name','$ic','$Pcode','$Scode','$statename','$phone','$email','$namaFile')")or die (mysqli_error($newcon));								
								
								
								
								?>
								
								<div class="alert alert-success">
                              New Account Successfully registered. <a href="Userview.php" class="alert-link"></a>.
                            </div>
						<?php
							}}
							?>
                      
                     <!-- Load icon library -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">


                      
                      
                        
                      
  
  
                    </div>
                    <!-- /.col-lg-12 -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.container-fluid -->
        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->
    <!-- Footer -->
    <footer class="py-4 bg-dark">
      <div class="container">
        <p class="m-0 text-center text-white">Copyright &copy; AskYB 2018</p>
      </div>
      <!-- /.container -->
    </footer>

    <!-- jQuery -->
    <script src="vendor/jquery/jquery.min.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="vendor/bootstrap/js/bootstrap.min.js"></script>

    <!-- Metis Menu Plugin JavaScript -->
    <script src="vendor/metisMenu/metisMenu.min.js"></script>

    <!-- Custom Theme JavaScript -->
    <script src="dist/js/sb-admin-2.js"></script>

</body>

</html>
