<?php if(isset($_SESSION['msg']) ){?>
<div class="alert alert-info">                
<h4>Info!</h4>
<?php echo $_SESSION['msg']; unset($_SESSION['msg']); ?>
</div> <?php }  ?> 
 <?php
 if(isset($_REQUEST['submit']))
 {
	$symbol	 	           = strtoupper(mysql_real_escape_string($_POST['symbol']));
	$details               = ucwords(strtolower(mysql_real_escape_string($_POST['details'])));
	$sql				   = mysql_query("select * from `tbl_attend_type` where `symbol`='$symbol' ")or die(mysql_error());
	if(mysql_num_rows($sql)>0)
	{
		$_SESSION['msg']   = 'Attendence Type Already Exists!!!!!! ';
	}
	else
	{
		$_SESSION['msg']   = 'Attendence Type Added Sucessfully!!';
		mysql_query("insert into `tbl_attend_type` set `symbol`='$symbol', `details`='$details' ")or die(mysql_error());
	}
	header("location:home.php?page=add_atten_st");	 
 }
 if(isset($_REQUEST['update']))
 {
	$id                    = $_POST['id'];
	$symbol	 	           = strtoupper(mysql_real_escape_string($_POST['symbol']));
	$details               = ucwords(strtolower(mysql_real_escape_string($_POST['details'])));
	$sql				   = mysql_query("select * from `tbl_attend_type` where `id`!='$id' and `symbol`='$symbol' ")or die(mysql_error());
	if(mysql_num_rows($sql)>0)
	{
		$_SESSION['msg']   = 'Attendence Type Already Exists!!!!!! ';
	}
	else
	{
		$_SESSION['msg']   = 'Attendence Type Update Sucessfully!!';
		mysql_query("update `tbl_attend_type` set `symbol`='$symbol', `details`='$details' where `id`='$id' ")or die(mysql_error());
	}
	header("location:home.php?page=add_atten_st");	  
 }
 ?>           
<div class="row-fluid" >
    <div class="span12">
        <div class="head clearfix">
            <div class="isw-ok"></div>
            <h1>Attendence Type</h1>
        </div>
        <div class="block-fluid">
            <form class="form-horizontal" action="" method="post" enctype="multipart/form-data">
              <fieldset>
              <?php
			   if(isset($_REQUEST['page_id']))
			   {
				   $id            =       $_REQUEST['page_id'];
				   $modify_menu   =       mysql_query("SELECT * FROM `tbl_attend_type` WHERE `id` = '$id'");
				   $show_modify   =       mysql_fetch_array($modify_menu);
			   }
			  ?>
              <input type="hidden" name="id" placeholder="Page Name" <?php if(isset($_REQUEST['page_id'])){?> required value="<?php echo $show_modify['id'];  ?>"<?php } ?> id="txt_name" autocomplete="off" />
                     <div class="row-form clearfix">
                        <div class="span3">
                        	<label>Attendence Symbol</label>
                        	<input type="text" name="symbol" placeholder="Attendence Symbol" <?php if(isset($_REQUEST['page_id'])){?>value="<?php echo $show_modify['symbol'];?>"<?php } ?> autocomplete="off" id="symbol" onkeyup="capital_letter('symbol');" maxlength="4" tabindex="1" required/>
                        </div>
                        <div class="span3">
                        	<label>Details</label>
                        	<input type="text" tabindex="2" name="details" placeholder="Details" <?php if(isset($_REQUEST['page_id'])){?>value="<?php echo $show_modify['details'];  ?>"<?php } ?> autocomplete="off" id="details" onkeyup="capital_letter('details');" required/>
                        </div>
                    <div class="span3">
                    	<label>&nbsp;</label>
                        <input type="submit" tabindex="3" name="<?php if(isset($_REQUEST['page_id'])){echo "update"; }else{ echo "submit";}?>" class="btn btn-block" value="<?php if(isset($_REQUEST['page_id'])){ echo "Update"; }else{ echo "Save";}?>"/>
                        </div>
                        </div>
              </fieldset>
            </form>  
        </div> 
    </div>
</div> 
<div class="row-fluid" >
    <div class="span12">    
    	<div class="head clearfix">
        <div class="isw-ok"></div>
        <h1>View Attendence Type List</h1>
     </div>   
   		<div class="block-fluid">
        	<table cellpadding="0" cellspacing="0" width="100%" class="table" id="example">
                <thead>
                    <tr>
                        <th>S.No.</th>
                        <th>Symbol</th>
                       	<th>Details</th>
                        <th>Status</th>
                        <th>Modify</th>
                    </tr>
                </thead>                 
                <tbody>
					<?php
					$i=1;
					$menu		= mysql_query( "SELECT * FROM `tbl_attend_type`  ")or die(mysql_error());
                    while($show_menu = mysql_fetch_array($menu)) 
                    {
						$a			 = "<img height='20' width='20' src='images/right.png'/>";
						$b			 = "<img height='20' width='20' src='images/wrong.png'/>";
						$status		 = $a;
						if($show_menu['status']==0)
						{
							$status		 = $b;
						}
                    ?>	
                    	<tr id="tr_num_<?php echo $i;?>">
                        <td><?php echo $i++; ?></td>
                        <td ><?php echo $show_menu['symbol']; ?></td>
                        <td><?php echo $show_menu['details']; ?></td>
                        <td style="text-align:center !important;"><?php echo $status; ?></td>
                        <td class="center" style="text-align:center">
                        	<a href="home.php?page=add_atten_st&page_id=<?php echo $show_menu['id']; ?>"><img src="images/edit_new.png"  border="0" style="width: 20px;"/></a>
                        </td>      
                    </tr>
               	   <?php } ?>                
                </tbody>            
            </table> 
        </div>    
   </div>
   </div> 
<script>
function capital_letter(id)
{
    var arr 		  = $('#'+id).val().split(' ');
    var result 		  = "";
    for (var x=0; x<arr.length; x++)
        result+=arr[x].substring(0,1).toUpperCase()+arr[x].substring(1)+' ';
    $('#'+id).val(result.substring(0, result.length-1));
}
$(document).ready(function() {
    var table = $('#example').DataTable( {
		"order": [[ 2, "asc" ]],
		"pageLength": 50,stateSave: true,
        fixedHeader: {
            header: true,
            footer: true
        }
    } );
	 table.on( 'order.dt search.dt', function () {
        table.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
            cell.innerHTML = i+1;
        } );
    } ).draw(); } );
	</script>   
