<?php include "header.php";
 echo '<h1>'.$login_type.'</h1>';
if($login_type=='admin'){ 
$submit=$_POST['submit'];
if($submit=='Add Record'){
$lid=$_POST['lid'];
$user=$_POST['user'];
$code=$_POST['code'];
$query = "INSERT INTO `dl_user` (`id`, `lid`, `user`,`code`,`session`) VALUES ('$id', '$lid', '$user','$code','$session')";

  mysql_query( $query )

 or die ( "Couldn't add data to \"application\" table: " 

 .mysql_error() );

print "<div>Data Save [ ". mysql_affected_rows() .

" row(s) ] Successfully </div>";

}





if($submit=='Update'){

$id=$_POST['id'];

$lid=$_POST['lid'];

$user=$_POST['user'];

$code=$_POST['code'];

$query = "UPDATE dl_user SET lid='$lid',user='$user',code='$code' WHERE id='$id' and session='$session' and code='$code'";

 $result = mysql_query( $query );

 if ( ! $result )

die ("Couldn't update: ".mysql_error());

print "<h1>Table Updated ". mysql_affected_rows() .

" row(s) updated</h1>";

}







$submit=$_GET['submit'];

if($submit=='Delete'){

$id=$_GET['id'];

$query = "DELETE FROM dl_user WHERE id='$id' and session='$session' and code='$code'";

$result = mysql_query( $query );

if ( ! $result )

die ("Couldn't deleted: ".mysql_error());

print "<h1>Table deleted ". mysql_affected_rows() .

" row(s) deleted</h1><p>";

}

?>

  <div id="page-wrapper">



            <div class="row">

                <!-- Page Header -->

                <div class="col-lg-12">

                    <h1 class="page-header">User Access</h1>  

    <br>

    <br>

    <style type="text/css">

<!--

.style1 {color: }

-->

</style>

<script language='JavaScript'>



function validate()

{

	conf = confirm("Are you sure you want to delete?");

	if (conf)

		return true

	else

		return false;

}



</script>

<table width="100%" border="0" cellspacing="2" cellpadding="2" background="images/co-surgeons.jpg">

  <tr>

    <td><div align="center"><a href="welcome-home.php?title=Dashboard"><img src="images/back.gif" alt="" boarder="0" /> Back</a></div></td>

  </tr>

  

  <tr>

    <td>&nbsp;</td>

  </tr>

  <tr>

    <td><table width="100%" border="0" cellspacing="2" cellpadding="2">

  <tr>

    <td valign="top"><table width="100%" border="0" cellspacing="2" cellpadding="2">

  <tr>

    

    <td width="50%" valign="top" align="center"><div align="center">

      <form name="myform" id="myform" method="post" action="user_access.php">

	  <table cellpadding=2 cellspacing=0 border=1 bordercolor=#FFFFCC bgcolor="" align=center class="table table-bordered table-striped">

				

		<tr>

		  <td colspan="2"  class=color3 style="color:">Add Rights</td>
		  </tr>

		<tr>
          <td class="color3">Select College</td>
		  <td class="color2"><?php

							

$queryy = "SELECT * FROM college_name where code='$code'";

$numresultsy=mysql_query($queryy);

$resulty= mysql_query($queryy) or die("Couldn't execute query");

?>
              <select name="code" id="code" required="required" tabindex="3" style="width:150px;">
                <option value="">Select</option>
                <?php

while ( $a_roww = mysql_fetch_row( $resulty ) )

 {?>
                <option

                 <?php 

				 $cn_id=$a_roww[2];

				 if($cn_id==$college){

				  ?>selected<?php } ?>

                  

                   value="<?php echo $a_roww[2];?>" >( <?php echo $a_roww[2];?> ) <?php echo $a_roww[1];?></option>
                <?php } ?>
            </select></td>
		  </tr>

		<tr>

		  <td width="116" class=color3> Links</td>

		  <td width="190" class=color2><select name="lid" required="required" tabindex="2">
<?php
$query = "SELECT * FROM dashboard_links ORDER BY id";
$numresults=mysql_query($query);
 $numrows=mysql_num_rows($numresults);
$result = mysql_query($query) or die("Couldn't execute query");
while ( $a_row = mysql_fetch_row( $result ) )

 {?>
          <option value="<?php echo $a_row[1]; ?>"><?php echo $a_row[1]; ?></option>
<?php } ?>
          </select> </td>
		  </tr>

        <tr>
          <td class=color3>User</td>
          <td class=color2><select name="user" required="required" tabindex="3">
            <?php
$query = "SELECT * FROM user where code='$code' ORDER BY id";
$numresults=mysql_query($query);
 $numrows=mysql_num_rows($numresults);
$result = mysql_query($query) or die("Couldn't execute query");
while ( $a_row = mysql_fetch_row( $result ) )

 {?>
            <option value="<?php echo $a_row[1]; ?>"><?php echo $a_row[1]; ?></option>
            <?php } ?>
          </select></td>
        </tr>
        <tr> 

			<td class=color3></td>

			<td class=color2><input name="submit" type="submit" value="Add Record" tabindex="3"/></td>
		</tr>
	</table>

</form></div></td>

  </tr>

</table></td>

    <td valign="top"><?php

	 

$query = "SELECT * FROM dl_user where session='$session' and code='$code' ORDER BY user";

$numresults=mysql_query($query);

 $numrows=mysql_num_rows($numresults);

$result = mysql_query($query) or die("Couldn't execute query");





?>

<div style="overflow:auto; text-align:center">



<?php if($numrows!=""){?>

   <table  cellpadding="1" border="1" cellspacing="1" bgcolor="" align="center" class="table table-bordered table-striped">

 <tr>

	

 <td align="center" valign="top" bgcolor="#0000FF" class="border"><div align="center" style="font-size:12px; color:"  ><em><strong>S.</strong></em></div></td>

  <td align="center" valign="top" bgcolor="#0000FF" class="style1" style="font-size:12px; color:">Links</td>

  <td align="center" valign="top" bgcolor="#0000FF" class="style1" style="font-size:12px; color:">&nbsp;</td>
  <td align="center" valign="top" bgcolor="#0000FF" class="style1" style="font-size:12px; color:">College Code</td>

  <td align="center" valign="top" bgcolor="#0000FF" class="border"><div align="center" style="font-size:12px; color:"   ><em><strong>Update</strong></em></div></td>

 <td align="center" valign="top" bgcolor="#0000FF" class="border"><div align="center" style="font-size:12px; color:"   ><em><strong>Delete</strong></em></div></td>
 </tr>

<?php 

$counter = 1;?>

 <?php

while ( $a_row = mysql_fetch_row( $result ) )

 {?>

 

 

<form action="user_access.php" enctype="multipart/form-data" method="post">

<input  name="id" type="hidden" value="<?php echo $a_row[0];?>" />

 <tr>

 <td height="20" align="center" valign="top" ><div align="center" style="font-size:12px;"><?php echo $counter;?></div></td>

 <td align="center" valign="top" ><span class="color2">
   <select name="lid" required="required" tabindex="2">
     <?php
	 $lidc=$a_row[1];
$query = "SELECT * FROM dashboard_links ORDER BY id";
$numresults=mysql_query($query);
 $numrows=mysql_num_rows($numresults);
$result = mysql_query($query) or die("Couldn't execute query");
while ( $a_rowx = mysql_fetch_row( $result ) )

 {?>
     <option value="<?php echo $lpp=$a_rowx[0]; ?>" <?php if($lidc==$lpp){ ?>selected="selected"><?php } ?><?php echo $a_rowx[1]; ?></option>
     <?php } ?>
   </select>
 </span></td>
 <td align="center" valign="top" ><select name="user" required="required" tabindex="3">
            <?php
$query = "SELECT * FROM user where code='$code' ORDER BY id";
$numresults=mysql_query($query);
 $numrows=mysql_num_rows($numresults);
$result = mysql_query($query) or die("Couldn't execute query");
while ( $a_rowy = mysql_fetch_row( $result ) )

 {?>
            <option value="<?php echo $a_rowy[1]; ?>"><?php echo $a_rowy[1]; ?></option>
            <?php } ?>
          </select></td>
 <td align="center" valign="top" >

 

 <?php

							

$queryy = "SELECT * FROM college_name where code='$code'";

$numresultsy=mysql_query($queryy);

$resulty= mysql_query($queryy) or die("Couldn't execute query");

?>

<select name="code" id="code" required style="width:150px;"> 

      

                                  <?php

while ( $a_roww = mysql_fetch_row( $resulty ) )

 {?>

                  <option

                 <?php 

				 $college=$a_row[3];

				 $cn_id=$a_roww[2];

				 if($cn_id==$college){

				  ?>selected<?php } ?>

                  

                   value="<?php echo $a_roww[2];?>" >( <?php echo $a_roww[2];?> ) <?php echo $a_roww[1];?></option>

                  <?php } ?>
                </select> </td>

 <td align="center" valign="top" >



 <input type="submit"  name="submit" value="Update"  ></td>

 <td align="center" valign="top" >



 

<a href="feed_course.php?id=<?php echo $a_row[0];?>&&submit=Delete" onclick='return validate();'><img src="images/out.gif" height="25" width="25" /></a></td>
 </tr>
 </form>



   

  <?php $counter++;}?>
  </table>

</div>

   <?php }?>



<?php if($numrows==""){

  echo "<div  style='border:none; text-align:center'><h3 class='logo2'>No Record Found</h3></div>";

}?></td>

  </tr>

</table>

</td>

  </tr>

  <tr>

    <td align="center">

</td>

  </tr>

  <tr>

    <td></td>

  </tr>

</table></div>

                <!--End Page Header -->

            </div>



            



        </div>



<?php } include "footer.php"; ?>