<?PHP
ob_start();
session_start();
include 'connect.php';
if(isset($_SESSION['adminemail']))
{
$user=$_SESSION['adminemail'];

$gtp=mysql_query("select * from admin where username='$user'");
$gtp1=mysql_fetch_array($gtp);

include 'top.php';
?>



			<div class="main-content">
				<div class="main-content-inner">
					<div class="breadcrumbs ace-save-state" id="breadcrumbs">
						<ul class="breadcrumb">
							<li>
								<i class="ace-icon fa fa-home home-icon"></i>
								<a href="#">Home</a>
							</li>
							<li class="active">Expense Category</li>
						</ul><!-- /.breadcrumb -->
					</div>

					<div class="page-content">
			

						<div class="page-header">
                        
<?php

$aca=mysql_query("select * from financial where user='$user' order by ID desc");
$aca1=mysql_fetch_array($aca);

$financial=$aca1['financial'];

?>                        
                        
							<table style="width:100%;">
                        
                        <tr><td style="width:50%;">
                        
							<h1>
								Expense Category
							</h1>
                            
                            </td>
                            
                            <td style="width:50%; text-align:right; padding-right:15px; font-size:15px;">
                            
                            <i class="fa fa-calendar"></i>&nbsp; <?php echo $financial; ?>
                            
                            </td></tr></table>
                            
						</div><!-- /.page-header -->

						<div class="row">
							<div class="col-xs-12">
                            
								<!-- PAGE CONTENT BEGINS -->

<script src="assets/js/jquery-2.1.4.min.js"></script>
<script>
	
jQuery(function($){
		   
	// simple jQuery validation script
	$('#course').submit(function(){
		
		var valid = true;
		var errormsg = 'This field is required!';
		var errorcn = 'error';
		
		$('.' + errorcn, this).remove();			
		
		$('#required', this).each(function(){
			var parent = $(this).parent();
			if( $(this).val() == '' ){
				var msg = $(this).attr('title');
				msg = (msg != '') ? msg : errormsg;
				$('<span style="font-size:13px;color:#FF0000; padding-left:3px;" class="'+ errorcn +'">'+ msg +'</span>')
					.appendTo(parent)
					.fadeIn('fast')
					.click(function(){ $(this).remove(); });
				valid = false;
			};
		});
		
		return valid;
		
		$('button:submit').prop('disabled', true);
		
	});
	
});	

</script>					
										
                                        
<?php  



if(isset($_POST['submit']))

{

$id=$_POST['id'];

$category=$_POST['category'];



$up=mysql_query("update exp_category set category='$category' where ID='$id'");



if($up)

{

header("location:viewexpense_category.php?s=1");

}



}      



elseif($_GET['id'])

{

$id=$_GET['id'];



$c=mysql_query("select * from exp_category where ID='$id'");

$c1=mysql_fetch_array($c);



echo"<center><form action='viewexpense_category.php' method='post' id='course'>

<input type='hidden' name='id' value='".$id."'>

Category <span class='red'>*</span> : <input type='text' name='category' value='".$c1['category']."' style='width:250px;' id='required' title='*' autocomplete='off' /><br /><br />

<button type='submit' class='btn btn-sm btn-primary' name='submit' value='submit'>Edit</button>

</form></center>";

}

else

	{
	
if (isset($_GET['s'])) 	
	{
	 $status=$_GET['s'];
		
		 if($status=='1')
		 {
			 echo'<div class="alert alert-block alert-success">
									<button type="button" class="close" data-dismiss="alert">
										<i class="ace-icon fa fa-times"></i>
									</button>
						Values Edited Successfully.
				  </div>';				  
		 }
		 if($status=='2')
		 {
			 echo'<div class="alert alert-block alert-success">
									<button type="button" class="close" data-dismiss="alert">
										<i class="ace-icon fa fa-times"></i>
									</button>
						Category Created Successfully.
				  </div>';				  
		 }
		 if($status=='5')
		 {
			 echo'<div class="alert alert-block alert-success">
									<button type="button" class="close" data-dismiss="alert">
										<i class="ace-icon fa fa-times"></i>
									</button>
						Category Deleted Successfully.
				  </div>';				  
		 }
	}
	
	echo'<table style="width:99%; margin:11px auto 10px auto;">
                                        
                                        <tr><td style="width:20%;">
                                        <a href="exp_category.php"><button class="btn btn-minier btn-info">+ Add Category</button></a>
                                        </td>
                                        
                                        <td style="width:50%;"></td>
                                        
                                        <td style="width:30%;">
                                        
                                        </td>
                                        
                                        </tr>
                                        
                                        </table>';
									
echo'<table id="dynamic-table" class="table table-striped table-bordered table-hover">';

echo"<thead><th height='25' width='5%'>S.No</th><th width='35%'>Category</th><th width='10%' style='text-align:center;'>Actions</th></thead>
<tbody>";

$select="select * from exp_category order by ID ASC";
$select1=mysql_query($select);
$sno=0;
while($value=mysql_fetch_array($select1))
{
$sno=$sno+1;
echo'<tr><td>'.$sno.'</td><td>'.$value['category'].'</td><td>

													   <div class="hidden-sm hidden-xs btn-group">
													   
															<a href="viewexpense_category.php?id='.$value['ID'].'" title="Edit">
																<i class="ace-icon fa fa-pencil bigger-100 green"></i></a> &nbsp; 
															
														</div>

</td></tr>';
}

echo"</tbody></table>";

}

?>
                                        
                                            
                                            							

										<!-- PAGE CONTENT ENDS -->
									</div><!-- /.col -->
								</div><!-- /.row -->
							</div><!-- /.page-content -->
						</div>
					</div><!-- /.main-content -->


<?php
include 'bottom.php';
}
else
{

 header("location:login.php");
}
ob_flush();
?>
