<?php 
include 'dheader.php';
if (isset($_POST['submitf'])) {
 	# code...
 	extract($_POST, EXTR_OVERWRITE);
	if (isset($_GET['edit'])) {
		$id = $_GET['edit'];
		$sql = $db->query("UPDATE careof SET name = '$cname' WHERE id = '$id'");
		header("LOCATION: careof.php");
	}else{ 	
 		$sql = $db->query("INSERT INTO careof (name) VALUES ('$cname')");
 	}
 } 
if (isset($_GET['edit'])) {
 	# code...
 	$id = $_GET['edit'];
 	$edit = $db->query("SELECT * FROM careof WHERE id = '$id'");
	$editrow = $edit->fetchArray();
 } 
if (isset($_GET['delete'])) {
 	# code...
 	$id = $_GET['delete'];
 	$delete = $db->query("DELETE FROM careof WHERE id = '$id'");
 }  
?>
	<div class="modal fade hidden-print" id="myModal" tabindex="-1" role="dialog" aria-hidden="true"></div>
	<div class="wrapper ">
		<?php include 'leftbar.php'; ?>
		<!-- left-bar -->
		<?php include 'topbar.php'; ?>
			<!-- top-bar -->
			<div class="main-content">

<div class="row" id="form">
	<div class="spinner" id="grid-loader" style="display:none">
	  <div class="rect1"></div>
	  <div class="rect2"></div>
	  <div class="rect3"></div>
	</div>
	
	<div class="col-md-12">
		<form action="" id="customer_form" class="form-horizontal" enctype="multipart/form-data" method="post" accept-charset="utf-8" novalidate="novalidate">
			<div class="col-md-12">
	<div class="panel panel-piluku">
		<div class="panel-heading">
                <h3 class="panel-title">
                    <i class="ion-edit"></i> 
                    	Sale Person Information						<small>(Fields in red are required)</small>
                </h3>
        </div>
        	<?php if (isset($_GET['edit'])) { ?>
			<div class="panel-body">
				<div class="item_navigation clearfix text-center">
					<ul class="list-inline">
						<li>
													</li>
						<li>
													</li>
					</ul>
				</div>

				<div class="form-group">
					<label for="name" class="col-sm-3 col-md-3 col-lg-2 control-label required wide">Sale Person Name :</label>					<div class="col-sm-9 col-md-9 col-lg-10">
						<input type="text" name="cname" autofocus="on" value="<?php echo @$editrow['name'];  ?>" list="listcat" id="cname" class="form-control form-inps">
						<datalist id="listcat">
						<?php
							$listCat = $db->query("SELECT * FROM careof");
							while($listrow = $listCat->fetchArray()){
						?>
							<option value="<?php echo $listrow['name']; ?>"><?php echo $listrow['name']; ?></option>
						<?php } ?>	
						</datalist>
					</div>
				</div>
				<!-- <a href="careof.php" class="submit_button btn btn-success">New Careof</a> -->
 		<div class="form-actions pull-right">
										&nbsp;

					<input type="submit" name="submitf" value="Update" id="submitf" class="submit_button btn btn-primary">

				</div>

							</div><!--/panel-body -->
			<?php }else{ ?>
				<div class="panel-body">
				<div class="item_navigation clearfix text-center">
					<ul class="list-inline">
						<li>
													</li>
						<li>
													</li>
					</ul>
				</div>

				<div class="form-group">
					<label for="name" class="col-sm-3 col-md-3 col-lg-2 control-label required wide">Sale Person Name :</label>					<div class="col-sm-9 col-md-9 col-lg-10">
						<input type="text" name="cname" autofocus="on" value="" list="listcat" id="cname" class="form-control form-inps">
					</div>
				</div>
				<!-- <a href="careof.php" class="submit_button btn btn-success">New Careof</a> -->
 		<div class="form-actions pull-right">
										&nbsp;

					<input type="submit" name="submitf" value="Add" id="submitf" class="submit_button btn btn-primary">

				</div>

							</div><!--/panel-body -->
			<?php } ?>				
		</div><!-- /panel-piluku -->

	</div>
			
		</form>
			</div>
		</div><!-- /row -->


			<div class="container-fluid">
		<div class="row manage-table">
			<div class="panel panel-piluku">
				<div class="panel-heading">
				<h3 class="panel-title">
				<?php
					$countcareof = $db->query("SELECT count(*) AS totalCat FROM careof");
					$count = $countcareof->fetchArray();
				?>
					List of Sale Person					<span title="2 total careof" class="badge bg-primary tip-left"><?php echo $count['totalCat']; ?></span>
					<span class="panel-options custom">
											</span>
				</h3>
			</div>
				<div class="panel-body nopadding table_holder table-responsive" >
					<table class="tablesorter table  table-hover" id="sortable_table">
						<thead>
							<tr>
								<th>Sale Person Id</th>
								<th>Name</th>
								<th>Edit</th>
								<!-- <th>Delete</th> -->
								<th>Report</th>
							</tr>
						</thead>
						<tbody>
							<?php
								$today = date('m/d/Y');
							?>
						<?php
							$careof = $db->query("SELECT * FROM careof");
							while($row = $careof->fetchArray()){
						?>
							<tr>
								<td><?php echo $row['id']; ?></td>
								<td><a href="#" class="underline"><?php echo $row['name']; ?></a></td>
								<td><a href="careof.php?edit=<?php echo $row['id']; ?>" class="update-category" title="Update">Edit</a></td>
								<!-- <td><a href="careof.php?delete=<?php echo $row['id']; ?>" class="delete_category" title="Delete">Delete</a></td> -->
								<td><a href="careofReport.php?report=<?php echo $row['name']; ?>&date=<?php echo $today ?>" class="update-category" title="Update" style="color: green;">Print Report</a></td>

							</tr>
						<?php } ?>		
							</tbody>
						</table>			
				</div>	
		</div>	
				</div>

	

			
<?php include 'dfooter.php'; ?>