<div class="content-wrapper">
  <section class="content-header">
    <h1>
      <?= $page_title ?>
      <small><?= $page_desc ?></small>
    </h1>
    <ol class="breadcrumb">
     <li><a href="<?= base_url() ?>"><i class="fa fa-star-o" aria-hidden="true"></i>Home</a></li>
     <li><?= $menu ?></li>
     <li class="active"><?= $sub_menu ?></li>
   </ol>
  </section>
  <section class="content">
    <div class="row">
      <div class="col-md-12">
        <?php 
          $redirectUrl = (isset($vehicle_id) && !empty($vehicle_id))
                            ?'Vehicle/updateVehicle/'.$vehicle_id
                            :'Vehicle/createVehicle';
          if($this->session->flashdata('message')) { 
            $flashdata = $this->session->flashdata('message'); ?>
            <div class="alert alert-<?= $flashdata['class'] ?>">
             <button class="close" data-dismiss="alert" type="button">×</button>
             <?= $flashdata['message'] ?>
           </div>
        <?php } ?>
      </div>
      <div class="col-md-12">
        <div class="box box-warning">
          <div class="box-header with-border">
            <h3 class="box-title">Vehicle Details</h3>
          </div>
          <form role="form" action="<?=base_url($redirectUrl)?>" method="post" class="validate" data-parsley-validate="" enctype="multipart/form-data">
            <div class="box-body">
              <div class="col-md-12">
                <div class="col-md-6">
                  <div class="form-group">
                     <label>Vehicle Model</label>
                     <input type="text" class="form-control required" data-parsley-trigger="change" 
                      data-parsley-minlength="2" required="" name="vehicle_model" placeholder="Provide Vehicle Model" value="<?= (isset($vehicle_data) && isset($vehicle_data->vehicle_model))?$vehicle_data->vehicle_model:'' ?>">
                     <span class="glyphicon form-control-feedback"></span>
                  </div>
                </div>
                <div class="col-md-6">
                  <div class="form-group">
                    <label>Vehicle Type</label>
                    <select name="vehicle_type" class="form-control required" data-parsley-trigger="change" required="">
                      <option selected disabled>Choose Vechile Type</option>
                      <?php 
                        if(!empty($vehicle_types)){
                          foreach ($vehicle_types as $type) {
                            $cond = (isset($vehicle_data) && isset($vehicle_data->vehicle_type) && 
                                     !empty($vehicle_data->vehicle_type) && 
                                     $vehicle_data->vehicle_type == $type->vehicle_id)?'selected':'';
                            echo '<option '.$cond.' value="'.$type->vehicle_id.'">'.
                                    $type->vehicle_type.
                                  '</option>';
                          } 
                        }
                      ?>
                    </select>
                     <span class="glyphicon form-control-feedback"></span>
                  </div>
                </div>
              </div>
              <div class="col-md-12">
                <div class="col-md-6">
                  <div class="form-group">
                     <label style="padding-top:13px;">Registration No.</label>
                     <input type="text" class="form-control required" data-parsley-trigger="change" 
                     data-parsley-minlength="2" required="" name="vehicle_reg_no" placeholder="Enter Vehicle Registration Number" value="<?= (isset($vehicle_data) && isset($vehicle_data->vehicle_reg_no))?$vehicle_data->vehicle_reg_no:'' ?>">
                     <span class="glyphicon form-control-feedback"></span>
                  </div>
                </div>
                <div class="col-md-6">
                  <div class="form-group">
                    <label>Registration Proof</label>
                    <div class="col-md-12">
                      <div class="col-md-3">
                        <img id="vehicle_reg_image" src="<?= (isset($vehicle_data) && isset($vehicle_data->vehicle_reg_image))?base_url($vehicle_data->vehicle_reg_image):'' ?>" onerror="this.src='<?=base_url("assets/images/user_avatar.jpg")?>'" height="75" width="75" />
                      </div>
                      <div class="col-md-9" style="padding-top: 25px;">
                        <input name="vehicle_reg_image" type="file" accept="image/*" 
                        class="<?= (isset($vehicle_id) && !empty($vehicle_id))?'':'required' ?>" 
                        onchange="setImg(this,'vehicle_reg_image')" />
                      </div>
                    </div>
                  </div>
                </div>
              </div>
              <div class="col-md-12">
                <div class="col-md-6">
                  <div class="form-group">
                    <label>Model</label>
                    <select name="model" class="form-control required" data-parsley-trigger="change" onabort="" required="">
                      <option selected disabled>Choose Model</option>
                      <?php 
                        for($year=(int)date('Y')-20; $year<=date('Y'); $year++){
                          $cond = (isset($vehicle_data) && isset($vehicle_data->model) && 
                                   !empty($vehicle_data->model) && 
                                   $vehicle_data->model == $year)?'selected':'';
                          echo '<option '.$cond.' value="'.$year.'">'.$year.'</option>'; 
                        }
                      ?>
                    </select>
                     <span class="glyphicon form-control-feedback"></span>
                  </div>
                </div>
              </div>
              <div class="col-md-12">
                <div class="box-footer">
                  <div style="text-align: center;">
                    <button type="submit" class="btn btn-primary">Submit</button>
                  </div>
                </div>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </section>
</div>