<?php include('../inc/header.php'); 
$clientObj->select($org_id);
if(isset($_GET['id']))
{
	$id=sanitize($_GET['id']);
	$check_batch=$batchObj->check_batch($id);
	
	if($check_batch==-1)
	{
	$checkerror=1;
	}
	else
	{
	$batchObj->select($id);
	}
}
if(isset($_POST['editbatch']))
{
	
	$cid=$batchObj->course_id;
	$batchname=sanitize($_POST['batch']);
	$check_batch=$batchObj->checkbatchname($batchname,$cid);
	if($check_batch==-1 || $check_batch==$id){
	$startdate=sanitize($_POST['start_date']);
	$end_date=sanitize($_POST['end_date']);
	if($startdate<$end_date)
	{
	$batchObj->course_id=$batchObj->course_id;
	$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->update($id);
	$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);
	$deletemsg=1;
}
/* 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="#">Settings</a></li>
      <li><a href="<?php echo SITE_URL; ?>batch.php">Batch</a></li>
      <li><span>View / Edit 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> View / Edit Batch </strong></div>
      <!-- main content --> 
      <!--Message-->
      <?php if($msg==1){ ?>
      <div class="success">Batch has been updated successfully</div>
      <?php } ?>
      <?php if($dateerror==1){ ?>
      <div class="error">End Date cannot be less than start date</div>
      <?php } ?>
      <?php 
						if($batcherror==1)
						{
						?>
                        <div class="error">This Batch is available</div>
                        <?php
						}?>  
	  <?php if(!$deletemsg==1){ ?>
      
      <!--Message-->
      <?php  if(!$checkerror==1)
						 { ?>
      <div class="row">
        <div class="col-sm-12">
          <div class="user_heading">
            <div class="row">
              <div class="col-sm-2 hidden-xs"> 
                
                <!--<img src="<?php //echo SITE_URL; ?><?php //echo $userphotoObj->path; ?>" alt="" class="img-thumbnail user_avatar">--> 
              </div>
              <div class="col-sm-10">
                <div class="user_heading_info">
                  <div class="user_actions pull-right"> <a href="#" class="edit_form" data-toggle="tooltip" data-placement="top auto" title="Edit Batch"><span class="icon-edit"></span></a> 
                    <?php if($batchObj->id==58){} else{ ?><a href="#" class="deletebatch" del_id="<?php echo $batchObj->id; ?>" data-toggle="tooltip" data-placement="top auto" title="Remove Batch"><span class="icon-remove"></span></a> <?php } ?>
                  </div>
                  <h1><?php echo $clientObj->school_name; ?></h1>
                  <h2>View / Edit Batch Details</h2>
                </div>
              </div>
            </div>
          </div>
          <div class="user_content">
            <div class="row">
              <div class="col-sm-10 col-sm-offset-2">
                <form name="edit_batch" id="edit_batch" class="form-horizontal user_form" action="#" method="POST" enctype="multipart/form-data">
                  <div class="form-group">
                    <label class="col-sm-2 control-label " >Course Name</label>
                    <div class="col-sm-10 editable">
                      <p class="form-control-static">
                        <?php $courseObj->select($batchObj->course_id); echo $courseObj->course_name; ?>
                      </p>
                      <div class="hidden_control">
                        <input type="text" class="form-control" id="" name="" value="<?php echo $courseObj->course_name; ?>"   readonly="readonly">
                      </div>
                    </div>
                  </div>
                  <div class="form-group">
                    <label class="col-sm-2 control-label req" >Batch Name</label>
                    <div class="col-sm-10 editable">
                      <p class="form-control-static"><?php echo $batchObj->batch;  ?></p>
                      <div class="hidden_control">
                        <input type="text" class="form-control" id="batch" name="batch" data-required="true" value="<?php echo $batchObj->batch; ?>"   >
                      </div>
                    </div>
                  </div>
                  <div class="form-group">
                    <label class="col-sm-2 control-label req">Start Date</label>
                    <div class="col-sm-10 editable">
                      <p class="form-control-static"><?php echo date('d-m-Y',strtotime($batchObj->start_date)); ?></p>
                      <div class="hidden_control">
                        <div class="input-group date editstartdate" 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="<?php echo $batchObj->start_date; ?>">
                          <span class="input-group-addon"><i class="icon-calendar"></i></span> </div>
                      </div>
                    </div>
                  </div>
                  <div class="form-group">
                    <label class="col-sm-2 control-label req">End Date</label>
                    <div class="col-sm-10 editable">
                      <p class="form-control-static"><?php echo date('d-m-Y',strtotime($batchObj->end_date)); ?></p>
                      <div class="hidden_control">
                        <div class="input-group date editenddate" 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="<?php echo $batchObj->end_date; ?>">
                          <span class="input-group-addon"><i class="icon-calendar"></i></span> </div>
                      </div>
                    </div>
                  </div>
                  <div class="form_submit clearfix" style="display:none">
                    <div class="row">
                      <div class="col-sm-10 col-sm-offset-2">
                        <button type="submit" class="btn btn-success" name="editbatch" id="editbatch">Save</button>
                      </div>
                    </div>
                  </div>
                </form>
              </div>
            </div>
          </div>
        </div>
      </div>
      <?php } else { ?>
      <div class="error">Unauthorized Access</div>
      <?php 
						header('location:../index.php');
						} ?>
                        
                        <?php } else { ?><div class="success">Batch has been deleted successfully</div>
      <?php } ?>
    </div>
  </div>
</section>
<div id="footer_space"></div>
</div>
<?php include('../inc/footer.php'); ?>