<?php include('inc/header.php');
$clientObj->select($org_id); 
if(isset($_POST['batch_submit']))
{
	$cid=sanitize($_POST['course']);
	$batchname=sanitize($_POST['batch']);
	$check_batch=$batchObj->checkbatchname($batchname,$cid);
	if($check_batch==-1){
	$startdate=sanitize($_POST['start_date']);
	$end_date=sanitize($_POST['end_date']);
	if($startdate<$end_date)
	{
	$batchObj->course_id=sanitize($_POST['course']);
	$batchObj->batch=sanitize($_POST['batch']);
	$batchObj->start_date=sanitize($_POST['start_date']);
	$batchObj->end_date=sanitize($_POST['end_date']);
	$batchObj->org_id=$org_id;
	$batchObj->insert();
	$msg=1;
	}
	else
	{
		$dateerror=1;
	}
	}
	else { $batcherror=1;}
}
/* Delete  */ 
if(isset($_POST['delsubmit']))
{
	$id=sanitize($_POST['del_id']);
	$batchObj->select($id);
	
		$emp_subjectObj->deletebatch($batchObj->id);
		$addeventObj->deletebatch($batchObj->id);
		$hostelregistrationObj->deletebatch($batchObj->id);
		$libissueObj->deletebatch($batchObj->id);
		$manageexamObj->deletebatch($batchObj->id);
		$marklistObj->deletebatch($batchObj->id);
		$std_regObj->deletebatch($batchObj->id);
		$subjectObj->deletebatch($batchObj->id);
		$transportallocationObj->deletebatch($batchObj->id);
		$transportpaymentObj->deletebatch($batchObj->id);
		$timetableObj->deletebatch($batchObj->id);
		$particularObj->deletebatch($batchObj->id);
	    $batchObj->delete($id);
}
/* Delete  */

?>
<!--Delete Form-->               
<form action="#" name="delete_batchform" id="delete_batchform" method="POST">
<input type="hidden" name="del_id" id="del_id" value="" />
<input type="hidden" name="delsubmit" value="<?php echo time(); ?>" />
</form>
<!--Delete Form-->
<!-- mobile navigation -->
			<nav id="mobile_navigation"></nav>
			
			<section id="breadcrumbs">
				<div class="container">
					<ul>
						<li><a href="#">Web school </a></li>
                        <li><a href="#">General Settings </a></li>
						<li><span>Batch</span></li>						
					</ul>
				</div>
			</section>
			<section class="container clearfix main_section">
				<div id="main_content_outer" class="clearfix">
					<div id="main_content">
						<div class="alert alert-info"><strong>Batch</strong></div>
                         <?php 
						if($setting_error==1)
						{
						?>
                        <div class="warning">Hello ! Please <a href="general_setting.php" />Click Here</a> Complete your settings page. It is very important to fill up your general settings before you start.</div>
                        <?php
						}?>
						<?php 
						if($dateerror==1)
						{
						?>
                        <div class="error">Batch End date should be greater than start date.</div>
                        <?php
						}?> 
                        <?php 
						if($msg==1)
						{
						?>
                        <div class="success">Batch detail has been saved successfully</div>
                        <?php
						}?> 
                        <?php 
						if($batcherror==1)
						{
						?>
                        <div class="error">This Batch is available</div>
                        <?php
						}?>  
						<!-- main content -->
        
                        <form action="#" method="POST" id="batch" name="batch" enctype="multipart/form-data">
                        <?php $courselist=$courseObj->selectorgall(); 
							if(count($courselist)>0)
							{?>
						<div class="row">
							<div class="col-sm-12">
								<div class="panel panel-default">
									<!--<div class="panel-heading">
										<h4 class="panel-title">Simple Validation</h4>
									</div>-->
									<div class="panel-body">
										
                                           
                                            <div class="form_sep">
												<label for="Timezone" class="req">Course Name</label>
												<select name="course" id="course" class="form-control" data-required="true">
                                                <option value="">Select Course</option>
                                                <?php foreach($courselist as $list)
												{?>
                                                <option value="<?php echo $list->id; ?>"><?php echo $list->course_name; ?></option>
                                                <?php } ?>
												</select>
											</div>
											<div class="form_sep">
												<label for="reg_input_name" class="req">Batch Name</label>
												<input type="text" id="batch" name="batch" class="form-control" data-required="true" >
											</div>
                                         
                                            
										    <div class="form_sep">
												<label class="req">Start Date</label>
												<div class="input-group date startdate" data-date-format="yyyy-mm-dd">
													<input  name="start_date" id="start_date" class="form-control input_validate" type="text" data-required="true" data-type="dateIso" value="">
													<span class="input-group-addon"><i class="icon-calendar"></i></span>
												</div>
											</div>
                                            
                                            <div class="form_sep">
												<label class="req">End Date</label>
												<div class="input-group date enddate" data-date-format="yyyy-mm-dd">
													<input  name="end_date" id="end_date" class="form-control input_validate" type="text" data-required="true" data-type="dateIso" value="">
													<span class="input-group-addon"><i class="icon-calendar"></i></span>
												</div>
											</div>
									</div>
								</div>
							</div>
						</div>
						<div class="row">
							<div class="col-sm-5">
							<div class="form_sep">
							<button class="btn btn-success" type="submit" name="batch_submit" id="batch_submit" >Save</button>
							</div>
                            </div>
                           <?php 
						   }
						   else
						   {
						  ?>
							  <div class="warning">You have to add course details before adding batch.<a href="course.php">Click Here</a> to add course.</div>  
						   <?php } ?>
                            
						</div>
						</form>
                        <div style="margin-top:20px;">
						<div class="row">
							<div class="col-sm-12"> 
							<div class="panel panel-default">
                           
							<?php $batchlist=$batchObj->selectorgall(); 
							if(count($batchlist)>0)
							{?>
                            <div class="panel-heading">
										<h4 class="panel-title"> Batch List </h4>
									</div>
							<div class="panel_controls">
										<div class="row">
											<div class="col-sm-4">
												<label for="table_search">Search:</label>
												<input type="text" id="table_search" class="form-control">
											</div>
											<div class="col-sm-3 col-xs-6">
												
											</div>
											<div class="col-sm-3 col-xs-6">
												
											</div>
										</div>
									</div>
                            <table id="resp_table" class="table toggle-square" data-filter="#table_search" data-page-size="40">
										<thead>
											<tr>
												<th data-toggle="true">Course name</th>
												<th data-hide="phone,tablet">Batch Name</th>
												<th data-hide="phone,tablet"> Start Date</th>
                                                <th data-hide="phone,tablet"> End Date</th>
                                                <th data-hide="phone,tablet"> View / Edit</th>
                                                <th > Delete</th>
											</tr>
										</thead>
										<tbody>
                                        <?php foreach($batchlist as $list)
										{?>
											<tr>
                                            <td><?php  $courseObj->select($list->course_id); echo $courseObj->course_name; ?></td>
                                            <td><?php echo $list->batch; ?></td>
                                            <td><?php echo date('d-m-Y',strtotime($list->start_date)); ?></td>
                                            <td><?php echo date('d-m-Y',strtotime($list->end_date)); ?></td>
                                            <td><a href="<?php echo VIEW_SITE_URL; ?>batch.php?id=<?php echo $list->id; ?>"><img src="img/edit.png" /></a></td>
                                            <td><?php if($list->id==58){} else{ ?><a href="#"><img src="img/error.png" class="deletebatch" name="del" id="del" del_id="<?php echo $list->id; ?>" title="Remove " /></a><?php } ?></td>
                                            </tr>
                                        <?php } ?>
											
										</tbody>
										<tfoot class="hide-if-no-paging">
											<tr>
												<td colspan="6" class="text-center">
													<ul class="pagination pagination-sm"></ul>
												</td>
											</tr>
										</tfoot>
									</table>
                            <?php } ?>
							</div>
                            </div>
						</div>
						</div>
							
						</div>
					</div>
				
			</section>
			<div id="footer_space"></div>
		</div>
	<?php include('inc/footer.php'); ?>