<?php include('header.php');?>
<?php include('sidebar.php');?>
<?php
$maintitle="Emergency Call";
$page="emergency-calls.php";
$table="tbl_emergency";
$field_id="emergencyid";
$mode=$_REQUEST['mode'];
$content_id=$_REQUEST['content_id'];
if(isset($_REQUEST['start'])){
$start=$_REQUEST['start']-1;
}
else {
$start=0;
}
?>
<?php
 
if(isset($_REQUEST['submit'])=="submit"){ 
$required = array();
$dataexist=array();
$values = $_POST;
unset($values['submit']);
unset($values['mode']);
unset($values['service']);
$userid=array("user_id"=>$user_id);
$values=array_merge($values,$userid);
$services=$_POST['service'];
$images=$helper->multiple_image_upload($_FILES['frm_filename_images'],"gallery");
$images2=$helper->multiple_image_upload($_FILES['frm_filename_images2'],"gallery");
if($_REQUEST['mode']=="edit"){
   $message=$helper->update($table, $values,array($field_id=>1),$required,$dataexist);
}
else {
	$message=$helper->insert($table,$values,$required,$dataexist);
	      foreach($services as $service){			   
                   $helper->tbl_emergency_services($service,$message['id'],"tbl_emergency_services");
           }
		   foreach($images as $image){
				 $helper->insert_multiple_images($image,$message['id'],"tbl_before_emergency","emergencyid");
			 }
		   foreach($images2 as $image1){
			   $helper->insert_multiple_images($image1,$message['id'],"tbl_after_emergency","emergencyid");
		   }
}

}
?>

<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1><?php echo $maintitle;?></h1>
      <ol class="breadcrumb">
        <li><a href="dashboard.php"><i class="fa fa-dashboard"></i> Dashboard</a></li>
        <li class="active"><?php echo $maintitle;?></li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content">
    
     <div class="row">
 <!-- Add / Edit / Delete --> 
          <div class="col-sm-12"> 
          <div class="box box-success">
         <div class="box-header">
              <i class="fa fa-building-o"></i>
              <h3 class="box-title"><?php echo $maintitle;?></h3>
              <div class="box-tools pull-right">
                <div class="btn-group">
                  
                </div>
              </div>
            </div> 
            </div> 
            </div>

 <!-- Add / Edit / Delete --> 

     
        <!-- /.col -->
        <div class="col-md-10">
          
          <div class="col-md-12">
          <!-- Horizontal Form -->
          <div class="box box-info">
            <div class="box-header with-border">
              <h3 class="box-title"><?php echo $maintitle;?></h3>
            </div>
            <!-- /.box-header -->
             
            <button class="btn btn-block btn-success btn-flat" type="button"><?php echo $message['message'];?></button>
			 
            <!-- form start -->
            <form class="form-horizontal" action="" method="post" enctype="multipart/form-data">
              <div class="box-body">
                <div class="form-group">
                     <input type="hidden" name="mode" value="add"/>
                  <label for="inputEmail3" class="col-sm-3 control-label">Client Name</label>

                  <div class="col-sm-8">
                     <?php
                  $clients= $helper->select("tbl_client","clientid,companyname",array());				   
				  ?>
                  <select name="clientid" class="form-control" id="clientid">
                   <option value="">---Select Client---</option>
                  <?php
				  foreach($clients as $client){
				  ?>
                  <option value="<?php echo $client['clientid'];?>"><?php echo $client['companyname'];?></option>
                  <?php
				  }
				  ?>
                  </select>
                  </div>
                </div>
                
                <div class="form-group">
                  <label for="inputEmail3" class="col-sm-3 control-label">Building Name</label>
                  <div class="col-sm-8">                   
                  <select name="branchid" class="form-control" id="branchid">
                 <option value="">---Select---</option>
                  </select>
                  </div>
                </div>
                <div class="form-group">
                  <label for="inputEmail3" class="col-sm-3 control-label">Title</label>
                  <div class="col-sm-8">
                  <input type="text" class="form-control" name="title"/>
                  </div>
                </div>
                <div class="form-group">
                <label for="inputEmail3" class="col-sm-3 control-label">Date</label>
				<div class="col-sm-6">
                <div class="input-group date">
                  <div class="input-group-addon">
                    <i class="fa fa-calendar"></i>
                  </div>
                  <input name="startdate" type="text" value="" class="form-control pull-right" id="datepicker">
                </div>
                </div>
                <!-- /.input group -->
              </div>
                <div class="form-group">
                
                  <label for="inputEmail3" class="col-sm-3 control-label">Services</label>

                  <div class="col-sm-8">
                  <?php
                  $services= $helper->select("tbl_services","serviceid,title",array());				   
				  ?>
                  <select name="service[]" class="form-control" id="branchid" multiple>
                  <?php
				  foreach($services as $service){
				  $service_active=$helper->check_types("tbl_project_services",'serviceid',$service['serviceid'],$content_id);	  
				  ?>
                  <option  value="<?php echo $service['serviceid'];?>"><?php echo $service['title'];?></option>
                  <?php
				  }
				  ?>
                  </select>
                   </div>
                </div>
                <div class="form-group">
                  <label for="inputEmail3" class="col-sm-3 control-label">Work Details</label>

                  <div class="col-sm-8">
                   <textarea id="editor1" name="workdetails" rows="10" cols="80">
                                           
                    </textarea>
                  </div>
                </div>
                <div class="form-group">
                  <label for="inputEmail3" class="col-sm-3 control-label">Images Before Maintenance</label>

                  <div class="col-sm-8">
                    <input type="file" class="" name="frm_filename_images[]" multiple>
                  </div>
                </div>
                <div class="form-group">
                  <label for="inputEmail3" class="col-sm-3 control-label">Images After Maintenance</label>

                  <div class="col-sm-8">
                    <input type="file" class="" name="frm_filename_images2[]" multiple>
                  </div>
                </div>
                 
                
              </div>
              <!-- /.box-body -->
              <div class="box-footer">
                <input type="submit" name="submit" value="Submit" class="btn btn-info pull-right"/>
              </div>
              <!-- /.box-footer -->
            </form>
          </div>
          <!-- /.box -->
           
        </div>
        </div>
        </div>
         

    </section>
    <!-- /.content -->
  </div>
<?php include('footer.php');  ?>