<?php
include "config.php";

//checks cookies to make sure they are logged in
if(isset($_COOKIE['ID_my_site']))
{
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{

//if the cookie has the wrong password, they are taken to the login page
if ($pass != $info['password'])
{ header("Location: login.php");
}

//otherwise they are shown the admin area
else
{
include "header.php";
$class_t_ad=$_GET['class_t_ad'];
$section=$_GET['section'];
$day=$_GET['day'];
$month=$_GET['month'];
$year=$_GET['year'];
?>
<style type="text/css">
<!--
.style1 {color: #FFFFFF; font-size:12px;}
-->
</style>

<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td bgcolor="#990000" style="border:none;background:url(images/title2.jpg); padding:2px; height:20; color:#990000; background-repeat:repeat-x;"><div align="left"><font face=Verdana, Geneva, sans-serif>Attendance - Student</font></div></td>
      </tr>
      <tr>
        <td align="center" valign="top"> <?php 
  $date_c=$day."-".$month."-".$year;
 $query_c = "SELECT * FROM att where classt='$class_t_ad' and section='$section' and date='$date_c' and session='$session' and code='$code'";
$numresults_c=mysql_query($query_c);
$result_c = mysql_query($query_c) or die("Couldn't execute query");
$a_rowc = mysql_fetch_row( $result_c );
  ?>
  
 <form action="att.php" method="post"  name="class_d_m_y" >
        <table width="800"  border="1" <?php if($a_rowc!=""){ ?> style="background-color:#FFFF99" <?php }else{ ?>style="background-color:#99FF99" <?php } ?>>
   <tr>
    
     <td  colspan="3" ><div align="right">Class</div></td>
     <td colspan="2"><select name="class_t_ad" required="required" style="background-color:#66FFFF" tabindex="7">
           <option ><?php echo $_GET['class_t_ad'];?></option>
                 
        </select></td>
   </tr>
   <tr>
     
     <td  colspan="3" ><div align="right">Section</div></td>
     <td colspan="2"   ><select name="section"  required="required" style="width:50; background-color:#66FFFF" tabindex="8">
      <option value="<?php echo $_GET['section'];?>"><?php echo $_GET['section'];?></option>
     
    </select></td>
   </tr>
   <tr>
    <td   colspan="3"><div align="right">Date</div></td>
    <td  colspan="2" ><select name="day" style="width:50; background-color:#66FFFF" required="required">
            <option><?php echo $_GET['day'];?></option>
           
          </select>
          <select name="month" style="width:50; background-color:#66FFFF" required="required">
            <option><?php echo $_GET['month'];?></option>
          </select>
          <select name="year" style="width:50; background-color:#66FFFF" required="required">
          <option value="<?php echo $_GET['year']; ?>"><?php echo $_GET['year']; ?></option>
          </select> </td>
  </tr>
  <tr>
    <td bgcolor="#0000FF"  ><span class="style1">Student Name</span></td>
    <td bgcolor="#0000FF" colspan="3"><div align="center"><span class="style1">Present</span></div></td>
    <?php /*?><td bgcolor="#0000FF"  ><div align="center"><span class="style1">Absent</span></div></td>
    <td bgcolor="#0000FF"  ><div align="center"><span class="style1">Holiday</span></div></td>
    <td bgcolor="#0000FF"  ><div align="center"><span class="style1">Leave</span></div></td><?php */?>
  </tr>
 
  <?php
  $query = "SELECT * FROM add_new_admision where class_t_ad='$class_t_ad' and section='$section' and session='$session' and code='$code' order by en";
$numresults=mysql_query($query);
$result = mysql_query($query) or die("Couldn't execute query");

?>
    <?php while ( $a_row = mysql_fetch_row( $result ) )
 { 
 $pid=$a_row[2];
$date_u=$day."-".$month."-".$year;
 $query_update = "SELECT * FROM att where classt='$class_t_ad' and section='$section' and sid='$pid' and date='$date_u' and session='$session' and code='$code'";
$numresults_update=mysql_query($query_update);
$result_u = mysql_query($query_update) or die("Couldn't execute query");
$a_rowu = mysql_fetch_row( $result_u );
$id=$a_rowu[0];
$statuss=$a_rowu[2];

 ?> <tr>
  <td><?php 
 echo $a_row[12];
?>   
<style>
.greenText{ background-color:green; color:#FFFFFF; }

.blueText{ background-color:blue;   color:#FFFFFF;}

.redText{ background-color:red;  color:#FFFFFF;}
.yText{ background-color:#FFCC00;  color:#FFFFFF;}
</style>
<input type="hidden" name="id[]" value="<?php echo $id; ?>">
<input type="hidden" name="sid[]" value="<?php echo $pid; ?>">
<input type="hidden" name="date[]" value="<?php echo $_GET['day'];?>-<?php echo $_GET['month'];?>-<?php echo $_GET['year']; ?>">
<input type="hidden" name="classt[]" value="<?php echo $class_t_ad; ?>">
<input type="hidden" name="section[]" value="<?php echo $section; ?>">
</td>
  <td colspan="3" ><div align="center">
  <select name="status[]" onchange="this.className=this.options[this.selectedIndex].className"
    <?php $cdate=date('D'); if($cdate=='Sun'){?>class="blueText"<?php }elseif($statuss=='P'){ ?> class="greenText" <?php }elseif($statuss=='A'){ ?> class="redText" <?php }elseif($statuss=='H'){ ?> class="blueText" <?php }elseif($statuss=='L'){ ?> class="yText" <?php }elseif($statuss==""){ ?> class="greenText" <?php }?>>
  <option value="P" class="greenText" <?php if($statuss=='P'){ ?> selected="selected" <?php }?> >Present</option>
  <option value="A" class="redText" <?php if($statuss=='A'){ ?> selected="selected" <?php }?>>Absent</option>
  <option value="H" class="blueText"<?php $cdate=date('D'); if($cdate=='Sun'){?>selected="selected" <?php }elseif($statuss=='H'){ ?> selected="selected" <?php }?>>Holiday</option>
  <option value="L" class="yText" <?php if($statuss=='L'){ ?> selected="selected" <?php }?>>Leave</option>
  </select>
<?php /*?>    <input  type="radio" value="P" required="required"  />
<?php */?>  </div></td>
 <?php /*?> <td bgcolor="#FF0000"><div align="center">
    <input name="status[]" type="radio" value="A" required="required" />
  </div></td>
  <td bgcolor="#FF00FF"><div align="center">
    <input name="status[]" type="radio" value="H" required="required"/>
  </div></td>
  <td bgcolor="#FFFF00"><div align="center">
    <input name="status[]" type="radio" value="L" required="required"/>
  </div></td><?php */?>
    </tr>
    <?php }?>
  
   
    
 
  <tr>
   
    <td  >&nbsp;</td>
    <td colspan="5"  ><?php if($a_rowc==""){ ?><input type="submit" name="Feed" value="Feed"  style="width:80"/>
            &nbsp;
            <input type="reset" name="Submit" value="Clear"  style="width:80"/><?php } elseif($a_rowc!=""){ ?><input type="submit" name="Update" value="Update"  style="width:80"/>
            &nbsp;
            <input type="reset" name="Submit" value="Clear"  style="width:80"/><?php } ?></td>
    </tr>
 
  </form></table>
       </td>
      </tr>
       <tr>
        <td>&nbsp;</td>
      </tr>

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

//if the cookie does not exist, they are taken to the login screen
{
header("Location: login.php");
}
?> 