<?php $is_owner = $this->db->get_where('admin' , array('admin_id' => $this->session->userdata('login_user_id')))->row()->owner_status;
?>
<div class="content-w">
		 
  <div class="content-i">
    <div class="content-box">
	<div class="row">
		<div class="col-sm-12">
		<?php echo form_open(base_url() . 'admin/generate_report');?>
      <div class="element-box lined-primary shadow">
		  <h5 class="form-header"><?php echo get_phrase('Report Generator');?></h5><br>
		  
		  <div class="form-group row">
				<label class="col-form-label col-sm-3" for=""> <?php echo "Report Type";?></label>
				<div class="col-sm-9">
					<div class="input-group">
					<div class="input-group-addon">
						<i class="picons-thin-icon-thin-0304_chat_contact_support_help_conversation"></i>
					</div>
					<select name="report_type" required id="report_type_select_box" class="form-control">
                        <option value=""><?php echo get_phrase('select');?></option>
                 <?php   if($is_owner==3){  }   else{?> <option value="Client">Customer Reports</option>
                        <option value="User">Technician Reports</option><?php }?>
                      <!--  <option value="Jobsheets">Jobsheets</option>!-->
                    </select>
                    
				  </div>
				</div>
			  </div>
		   
		  <div id="container_box">
				<div id="container_child_box">
				
		        </div> 
		   </div> 
			  	
              	  <div class="form-group row">
				<label class="col-form-label col-3" for=""> <?php echo get_phrase('Start Date');?></label>
				<div class="col-sm-9">
					<div class="input-group">
					<div class="input-group-addon">
						<i class="picons-thin-icon-thin-0023_calendar_month_day_planner_events"></i>
					</div>
				  		
				  		<input class="form-control" id="start_date" name="start_date" type="text">
				  </div>
				</div>
			  </div>
			  <div class="form-group row">
				<label class="col-form-label col-sm-3" for=""> <?php echo get_phrase('End Date');?></label>
				<div class="col-sm-9">
					<div class="input-group">
					<div class="input-group-addon">
						<i class="picons-thin-icon-thin-0023_calendar_month_day_planner_events"></i>
					</div>
				      
				        <input class="form-control" id="end_date" name="end_date" type="text">
				  </div>
				</div>
			  </div>
		  

		   <div class="form-buttons-w"align="center">
            <button class="btn btn-success btn-rounded"  type="submit"> <?php echo get_phrase('generate_report');?></button>
          
		</div>
		<?php echo form_close();?>
		
	</div>	
	</div>
</div>
</div>



<script>

     $(document).ready(function() {
    // what happens when you change report_type_select_box
    $('#report_type_select_box').change(function() {
        var report_type = $(this).val();
        var child = document.getElementById("container_child_box");
       
        
        if (report_type == null || report_type == '') {
            child.parentNode.removeChild(child);
        }
        
        if(report_type=="Client"){
            add_client_box();
            child.parentNode.removeChild(child);
            
        }
        if(report_type=="User"){
              add_user_box();
            child.parentNode.removeChild(child);
          
        }
          if(report_type=="Jobsheets"){
              add_client_box();
            child.parentNode.removeChild(child);
          
        }
    });
     });
</script>


<script>
// CREATING BLANK CLIENT INPUT
function add_client_box() {
  
    document.querySelector('#container_box').insertAdjacentHTML(
        'afterend',
        `<div class="form-group row" id="container_child_box">
            <label class="col-form-label col-sm-3" for=""> <?php echo "Client";?></label>
				<div class="col-sm-9">
					<div class="input-group">
					<div class="input-group-addon">
						<i class="picons-thin-icon-thin-0003_write_pencil_new_edit"></i>
					</div>
					<select name="client_id" class="form-control" required onchange="return get_class_students(this.value)">
                        <option value=""><?php echo get_phrase('select');?></option>
                        <?php 
                            $classes = $this->db->get('client')->result_array();
                            foreach ($classes as $row):
                        ?>
                            <option value="<?php echo $row['client_id'];?>"><?php echo $row['client_name'];?></option>
                        <?php endforeach;?>
                    </select>
				  </div>
				  </div>
			</div> `
    )
}

// CREATING BLANK USER INPUT
function add_user_box() {
    document.querySelector('#container_box').insertAdjacentHTML(
        'afterend',
        `<div class="form-group row" id="container_child_box">
            <label class="col-form-label col-sm-3" for=""> <?php echo "User";?></label>
				<div class="col-sm-9">
					<div class="input-group">
					<div class="input-group-addon">
						<i class="picons-thin-icon-thin-0003_write_pencil_new_edit"></i>
					</div>
					<select name="user_id" class="form-control" required onchange="return get_class_students(this.value)">
                        <option value=""><?php echo get_phrase('select');?></option>
                        <?php 
                            $classes = $this->db->get('admin')->result_array();
                            foreach ($classes as $row):
                        ?>
                            <option value="<?php echo $row['admin_id'];?>"><?php echo $row['name'];?></option>
                        <?php endforeach;?>
                    </select>
				  </div>
				  </div>
			</div> `
    )
}
</script>


<script type="text/javascript">
    $(function() {
  $('input[name="end_date"]').daterangepicker({
     singleDatePicker: true,
    locale: {
      format: 'DD-MM-YYYY'
    }
  });
  $('input[name="start_date"]').daterangepicker({
     singleDatePicker: true,
    locale: {
      format: 'DD-MM-YYYY'
    }
  });
});
</script>
