<?php include('header.php');?>
<?php include('sidebar.php');?>
 <?php
$maintitle="Schedule";
$page="schedule.php";
$table="tbl_schedule";
$field_id="scheduleid";
$mode=$_REQUEST['mode'];
$content_id=$_REQUEST['scheduleid']; 

if(isset($_REQUEST['start'])){
$start=$_REQUEST['start']-1;
}
else {
$start=0;
}
if(isset($_REQUEST['submit'])=="Search"){
	$projectid=$_REQUEST['projectid'];
	$startdate=$_REQUEST['startdate'];
	$enddate=$_REQUEST['enddate'];
	$listreport=$helper->selectreport($table,"*",$projectid,$startdate,$enddate); 
}
?>
<div class="content-wrapper">     
<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>
            <div class="col-sm-12"> 
          <div class="box box-success">
         <div class="box-header">
            <div class="col-sm-12">
            <form action="" method="post">
            <div class="col-sm-4"> 
                 <label for="inputEmail3" class="col-sm-12 control-label">Client Name</label>
                  <div class="col-sm-12">
                  <?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 <?php if($client['clientid']==$contentdetails[0]['clientid']){ echo "selected";}?> value="<?php echo $client['clientid'];?>"><?php echo $client['companyname'];?></option>
                  <?php
				  }
				  ?>
                  </select>
                 </div>
                </div>
                <div class="col-sm-4"> 
                 <label for="inputEmail3" class="col-sm-12 control-label">Branch Name</label>
                  <div class="col-sm-12">
                  <?php
                  $branches= $helper->select("tbl_branch","branchid,branchname",array());				   
				  ?>
                  <select name="branchid" class="form-control" id="branchid">
                  <?php
				  foreach($branches as $branch){
				  ?>
                  <option <?php if($client['clientid']==$contentdetails[0]['clientid']){ echo "selected";}?> value="<?php echo $branch['branchid'];?>"><?php echo $branch['branchname'];?></option>
                  <?php
				  }
				  ?>
                  </select>
                 </div>
                </div>
                <div class="col-sm-4"> 
                 <label for="inputEmail3" class="col-sm-12 control-label">Project Name</label>
                  <div class="col-sm-12">
                  <select name="projectid" class="form-control" id="projectid">
                  <option value="">---Select Project---</option>
                  </select>
                 <?php /*?> <?php
                  $projects= $helper->select("tbl_projects","projectid,title",array());				   
				  ?>
                  <select name="projectid" class="form-control" id="projectid">
                  <?php
				  foreach($projects as $project){
				  ?>
                  <option <?php if($client['clientid']==$contentdetails[0]['clientid']){ echo "selected";}?> value="<?php echo $project['projectid'];?>"><?php echo $project['title'];?></option>
                  <?php
				  }
				  ?>
                  </select><?php */?>
                 </div>
                </div>
                 
            </div>
            <div class="col-sm-12">
                  <div class="col-sm-4"> 
                 <label for="inputEmail3" class="col-sm-12 control-label">From Date</label>
                  <div class="col-sm-12">
              <input name="startdate" placeholder="From Date" type="text" value="<?php echo $contentdetails[0]['startdate'];?>" class="form-control pull-right" id="datepicker">
                 </div>
                </div>
                <div class="col-sm-4"> 
                 <label for="inputEmail3" class="col-sm-12 control-label">To Date</label>
                  <div class="col-sm-12">
                 <input name="enddate" placeholder="End Date" type="text" value="<?php echo $contentdetails[0]['enddate'];?>" class="form-control pull-right" id="datepicker2">
              
                 </div>
                </div>
                <div class="col-sm-4"> 
                 <label for="inputEmail3" class="col-sm-12 control-label">&nbsp;</label>
                  <div class="col-sm-12">
                 <input type="submit" name="submit" class="btn btn-info pull-right" value="Search" >
                 </div>
                </div>
                 </div>
                 </form>
                 </div>
              </div>
            </div>
<?php 
$contentdetails=$helper->select($table,"*",array($field_id=>$content_id));
?>
 <!-- Add / Edit / Delete --> 


     <div class="col-md-12">
          <!-- Horizontal Form -->
          <div class="box box-info">
           <form class="form-horizontal" action="" method="post" enctype="multipart/form-data">             
              <div class="box-body">
                  <div id="print">
               <?php
			   if($listreport!=""){
				?>
               <table width="700px" height="600px" cellpadding="10" cellspacing="10" border="1" class="printtable">
               <tr><th>Project Details</th>
                   <th>Branch Details</th>
                   <th>Client Details</th></tr>
               <tr><td width="30%">
                   <?php 
                   $projectdetails=$helper->select("tbl_projects","*",array("projectid"=>$projectid));     
                   $servicedetails=$helper->select("tbl_services","*",array("serviceid"=>$projectdetails[0]['service']));  
                    ?>
                             <p><b><?php echo $projectdetails[0]['title'];?></b><br/>
                              <b>Service:</b> <?php echo $servicedetails[0]['title'];?><br/>                           
                              <b>Package:</b> <?php echo  $projectdetails[0]['package'];?>
                              <br/><?php echo  $projectdetails[0]['description'];?><br/><b>Start Date:</b><?php echo  $projectdetails[0]['startdate'];?><br/>
                              <b>End Date:</b> <?php echo  $projectdetails[0]['enddate'];?></p>
                   </td>
                   <td width="30%">
                     <?php 
                   $branchdetails=$helper->select("tbl_branch","*",array("branchid"=>$projectdetails[0]['branchid'])); 
                    ?> 
                       <p><b><?php echo $branchdetails[0]['branchname'];?></b><br/>
                        <b>Contact:</b> <?php echo $branchdetails[0]['firstname'];?><br/>
                        <b>Ph:</b> <?php echo $branchdetails[0]['phone'];?><br/>
                         <b>Mob:</b> <?php echo $branchdetails[0]['mobile'];?><br/>
                         <b>Address:</b> <?php echo $branchdetails[0]['address'];?><br/>
                         <b>City:</b> <?php echo $branchdetails[0]['city'];?><br/>
                       </p>
                   </td>
                   <td width="30%">
                     <?php 
                   $clientdetails=$helper->select("tbl_client","*",array("clientid"=>$branchdetails[0]['clientid']));  
                    ?>
                       <p><b><?php echo $clientdetails[0]['companyname'];?></b><br/>
                        <b>Contact:</b> <?php echo $clientdetails[0]['firstname'];?><br/>
                        <b>Email:</b> <?php echo $clientdetails[0]['email'];?><br/>
                        <b>Ph:</b> <?php echo $clientdetails[0]['phone'];?><br/>
                         <b>Mob:</b> <?php echo $clientdetails[0]['mobile'];?><br/>
                         <b>Address:</b> <?php echo $clientdetails[0]['address'];?><br/>
                         <b>City:</b> <?php echo $clientdetails[0]['city'];?><br/>
                       </p>
                   </td>
               </tr>
               <tr><td colspan="3">
               <?php
			   foreach($listreport as $report){
			   ?>
               			<table width="700px" cellpadding="10" cellspacing="10" border="0">
                        <tr><td colspan="3" style="text-align:center;"><b>Schedule Date : <?php echo $report['scheduledate'];?></b></td></tr>
                        <tr><td width="150px"><b>Work Details</b></td><td width="10px">:</td><td><?php echo $report['workdetails'];?></td></tr>
                         <tr><td><b>Task Details</b></td><td>:</td><td><?php echo $report['description'];?></td></tr>
                         <tr><td><b>Task Status</b></td><td>:</td><td><?php echo $report['status'];?></td></tr>
                         <tr><td><b>After Maintainance</b></td><td>:</td>
                             <td>
                              <?php
							   $allimages= $helper->select("tbl_after_images","*",array("scheduleid"=>$report['scheduleid']));
							   if(count($allimages)>0){                                 
				                               foreach($allimages as $image){
                                                                   ?>
                                                                   <a class="imglist"><img class="img-responsive" src="<?php echo $site_url;?>thumb.php?src=<?php echo $site_url;?>images/gallery/<?php echo $image['image'];?>&w=80&h=80"/></a>
                                                              <?php
                                                                   }
				 
							   }
							  ?>
                             </td>
                         </tr>
                         <tr><td><b>Before Maintainance</b></td><td>:</td>
                             <td>
                              <?php
							   $allimages= $helper->select("tbl_before_images","*",array("scheduleid"=>$report['scheduleid']));
							   if(count($allimages)>0){                                 
				                               foreach($allimages as $image){
                                                                   ?>
                                                                   <a class="imglist"><img class="img-responsive" src="<?php echo $site_url;?>thumb.php?src=<?php echo $site_url;?>images/gallery/<?php echo $image['image'];?>&w=80&h=80"/></a>
                                                              <?php
                                                                   }
				 
							   }
							  ?>
                             </td>
                         </tr>
                        </table>
                  <?php
			   }
			   ?>
               
               </td></tr>
               </table>
               <?php
			   }
			   ?>
              </div>
                  <style type="text/css">
.print_button {
	background:#000;
	width:auto;
	padding:5px 10px;
	color:#fff;
	font-weight:bold;
	border:none;
	}
</style>
<p style="text-align:center;"><br/><button class="print_button" onclick="javascript:printDiv('print')"/>Print Report</button></p>
<script language="javascript" type="text/javascript">
        function printDiv(divID) {
            //Get the HTML of div
            var divElements = document.getElementById(divID).innerHTML;
            //Get the HTML of whole page
            var oldPage = document.body.innerHTML;

            //Reset the page's HTML with div's HTML only
            document.body.innerHTML = 
              "<html><head><title></title></head><body>" + 
              divElements + "</body>";

            //Print Page
            window.print();

            //Restore orignal HTML
            document.body.innerHTML = oldPage;

          
        }
    </script>
                </div>
           </form>
                
                
          </div>
         
        </div>
        </div>
        

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