<?php include('../inc/header.php'); 
$clientObj->select($org_id);
if(isset($_GET['id']))
{
	$id=sanitize($_GET['id']);
	$check_subject=$subjectObj->check_subject($id);
	
	if($check_subject==-1)
	{
	$checkerror=1;
	}
	else
	{
	$subjectObj->select($id);
	}
}
if(isset($_POST['editsubject']))
{   
    $course=$subjectObj->course_id;
	$batch=sanitize($_POST['batch']);
	$subjectname=sanitize($_POST['subject']);
	if(!$batch=='')
	{
	$check_subject=$subjectObj->checksubjectname($course,$batch,$subjectname);
	if($check_subject==-1 || $check_subject==$id){
	$subjectObj->course_id=$course;
	$subjectObj->batch_id=sanitize($_POST['batch']);
	$subjectObj->subject=sanitize($_POST['subject']);
	$subjectObj->staff='nil';
	$subjectObj->org_id=$org_id;
	$subjectObj->update($check_subject);
	$msg=1;
	$msg=1;
	} else { $samename=1;}
	}
	else
	{
		$error=1;
	}	
}
/* Delete Course */ 
if(isset($_POST['delsubmit']))
{
	$id=sanitize($_POST['del_id']);
	$subjectObj->select($id);
	$subjectObj->delete($id);
	$deletemsg=1;
}
/* Delete Course */

?>
<!--Delete Form-->               
<form action="#" name="delete_subjectform" id="delete_subjectform" 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; ?>subjects.php">Subjects</a></li>
      <li><span>View / Edit Subject</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 Subject </strong></div>
      <!-- main content --> 
      <!--Message-->
      <?php if($msg==1){ ?>
      <div class="success">Subject has been updated successfully</div>
      <?php } ?>
      <?php 
						if($samename==1)
						{
						?>
                        <div class="error">This Subject name is available.</div>
                        <?php
						}?> 
                         <?php 
						if($error==1)
						{
						?>
                        <div class="error">Please add batch name.</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 Subject"><span class="icon-edit"></span></a> 
                    <a href="#" class="deletesubject" del_id="<?php echo $subjectObj->id; ?>" data-toggle="tooltip" data-placement="top auto" title="Remove Subject"><span class="icon-remove"></span></a> 
                  </div>
                  <h1><?php echo $clientObj->school_name; ?></h1>
                  <h2>View / Edit Subject 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_subject" id="edit_subject" class="form-horizontal user_form" action="#" method="POST" enctype="multipart/form-data">
                  <div class="form-group">
                    <label class="col-sm-2 control-label req" >Course Name</label>
                    <div class="col-sm-10 editable">
                      <p class="form-control-static">
                        <?php $courseObj->select($subjectObj->course_id); echo $courseObj->course_name; ?>
                      </p>
                      <div class="hidden_control">
                      <input type="text" value="<?php $courseObj->select($subjectObj->course_id); echo $courseObj->course_name; ?>" class="form-control" 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 $batchObj->select($subjectObj->batch_id); echo $batchObj->batch;  ?></p>
                      <div class="hidden_control">
                      <div id="batch_div">
                        <?php $batchlist=$batchObj->selectbatch($subjectObj->course_id); ?>
                        <select name="batch" id="batch" class="form-control" data-required="true">
                                                <option value="">Select Batch</option>
                                                <?php foreach($batchlist as $list)
												{?>
                                                <option value="<?php echo $list->id; ?>" <?php if($subjectObj->batch_id==$list->id){?> selected="selected" <?php } ?>><?php echo $list->batch; ?></option>
                                                <?php } ?>
												</select>
                       </div>
                      </div>
                    </div>
                  </div>
                  <div class="form-group">
                    <label class="col-sm-2 control-label req" >Subject Name</label>
                    <div class="col-sm-10 editable">
                      <p class="form-control-static"><?php echo $subjectObj->subject;  ?></p>
                      <div class="hidden_control">
                        <input type="text" class="form-control" id="subject" name="subject" data-required="true" value="<?php echo $subjectObj->subject; ?>"   >
                      </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="editsubject" id="editsubject">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">Subject has been deleted successfully</div>
      <?php } ?>
    </div>
  </div>
</section>
<div id="footer_space"></div>
</div>
<?php include('../inc/footer.php'); ?>