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

if(isset($_REQUEST['start'])){
$start=$_REQUEST['start']-1;
}
else {
$start=0;
}
?>
<?php
 
if(isset($_REQUEST['submit'])=="submit"){ 
$dataexist=array("scheduledate");
$required = array("scheduledate");
$values = $_POST;
 
 
unset($values['submit']);
unset($values['mode']);
/*$customurl=array("customurl"=>$slugexist);
$values=array_merge($values,$customurl);*/
$userid=array("user_id"=>$user_id);
$values=array_merge($values,$userid);
$images=$helper->multiple_image_upload($_FILES['frm_filename_images'],"gallery");
$images2=$helper->multiple_image_upload($_FILES['frm_filename_images2'],"gallery");
if($_REQUEST['mode']=="add"){
$message=$helper->insert($table,$values,$required,$dataexist);
    foreach($images as $image){
	   $helper->insert_multiple_images($image,$message['id'],"tbl_before_images","scheduleid");
   }
   foreach($images2 as $image1){
	   $helper->insert_multiple_images($image1,$message['id'],"tbl_after_images","scheduleid");
   }
}
if($_REQUEST['mode']=="edit"){
$message=$helper->update($table, $values,array("user_id"=>$user_id,$field_id=>$_REQUEST['contentid']),$required);
     foreach($images as $image){
	   $helper->insert_multiple_images($image,$_REQUEST['contentid'],"tbl_before_images","scheduleid");
    }
	foreach($images2 as $image1){
	   $helper->insert_multiple_images($image1,$_REQUEST['contentid'],"tbl_after_images","scheduleid");
   }
}

}
?>
 <div class="content-wrapper">  
  <section class="content-header">
      <h1><?php echo $maintitle;?></h1>
      <ol class="breadcrumb">
        <li><a href="dashboard.php"><i class="fa fa-dashboard"></i> <?php echo AL_DASHBOARD;?></a></li>
        <li class="active"><?php echo $maintitle;?></li>
      </ol>
    </section>
<section class="content">
    <?php
	if($mode=="add" || $mode=="edit"){ 
	?>
     <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">
                <a href="<?php echo $page;?>"><button class="btn btn-danger btn-flat">&nbsp; <?php echo AL_LISTALL;?> <?php echo $maintitle;?></button></a>
                   
                </div>
              </div>
            </div> 
            </div> 
            </div>
<?php
if($mode=="edit"){
$contentdetails=$helper->select($table,"*",array($field_id=>$_REQUEST['contentid']));

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


     <div class="col-md-10">
          <!-- Horizontal Form -->
          <div class="box box-info">
            <div class="box-header with-border">
              <h3 class="box-title"> <?php echo $_REQUEST['mode'];?> <?php echo $maintitle;?></h3>
              <div class="box-tools pull-right">
                <div class="btn-group">
               
                </div>
              </div>
            </div>
            
            <?php
			if($message!=""){
			?>
            <button class="btn btn-block btn-success btn-flat" type="button"><?php echo $message['message'];?></button>
			<?php	
			}
			?>
            <!-- /.box-header -->
            <!-- form start -->
            <form class="form-horizontal" action="" method="post" enctype="multipart/form-data">
            <input type="hidden" name="mode" value="<?php echo $_REQUEST['mode'];?>"/>
             <input type="hidden" name="projectid" value="<?php echo $_REQUEST['projectid'];?>" />
              <div class="box-body">
              
                </div>
                
                
                 
                
                <div class="form-group">
                  <label for="inputPassword3" class="col-sm-3 control-label"><?php echo AL_DESCRIPTION;?></label>

                  <div class="col-sm-8">
                    <textarea class="form-control" name="description" id="description" placeholder="Description"><?php echo html_entity_decode($contentdetails[0]['description']);?></textarea>
                  </div>
                </div>
               <div class="form-group">
                <label for="inputEmail3" class="col-sm-3 control-label">Schedule 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="scheduledate" type="text" value="<?php echo $contentdetails[0]['scheduledate'];?>" class="form-control pull-right" id="datepicker">
                </div>
                </div>
                <!-- /.input group -->
              </div> 
              
              <div class="form-group">
                  <label for="inputPassword3" class="col-sm-3 control-label">Work Details</label>

                  <div class="col-sm-8">
                      <textarea id="editor1" name="workdetails" rows="10" cols="80">
                                            <?php echo $contentdetails[0]['workdetails'];?>
                    </textarea>
                  </div>
                </div>
            
              <div class="box-header with-border">
              <h3 class="box-title">Images Before Maintenance</h3>
              </div>
               <div class="form-group">
                  <label for="inputEmail3" class="col-sm-3 control-label">Upload Images</label>
                  <div class="col-sm-8">
                    <input type="file" class="" name="frm_filename_images[]" multiple>
                  </div>
                </div>
                <?php
				 $allimages= $helper->select("tbl_before_images","*",array("scheduleid"=>$_REQUEST['contentid']));
				 if(count($allimages)>0){
				?>
               <div class="form-group">
                 <?php
				 foreach($allimages as $image){
				 ?> 
                  <div class="col-sm-2">
                  <a class="fancybox" href="<?php echo $site_url;?>images/gallery/<?php echo $image['image'];?>" data-fancybox-group="gallery"><img class="img-responsive" src="<?php echo $site_url;?>thumb.php?src=<?php echo $site_url;?>images/gallery/<?php echo $image['image'];?>&w=160&h=160"/></a>
                   <a href="<?php echo $site_url;?><?php echo $page;?>?mode=edit&mode1=imgdelete&imgid=<?php echo $image['imageid'];?>&contentid=<?php echo $_REQUEST['contentid'];?>" onclick="return getConfirmation()"><span class="label label-danger"><i class="fa fa-times"></i> Delete</span></a><br/>
                  </div>
                 <?php
				 }
				 ?>
                </div>
                <?php
				}
				?>
                <div class="box-header with-border">
              <h3 class="box-title">Images After Maintenance</h3>
              </div>
              <div class="form-group">
                  <label for="inputEmail3" class="col-sm-3 control-label">Upload Images</label>
                  <div class="col-sm-8">
                    <input type="file" class="" name="frm_filename_images2[]" multiple>
                  </div>
                </div>
                <?php
				 $allimages= $helper->select("tbl_after_images","*",array("scheduleid"=>$_REQUEST['contentid']));
				 if(count($allimages)>0){
				?>
               <div class="form-group">
                 <?php
				 foreach($allimages as $image){
				 ?> 
                  <div class="col-sm-2">
                  <a class="fancybox" href="<?php echo $site_url;?>images/gallery/<?php echo $image['image'];?>" data-fancybox-group="gallery"><img class="img-responsive" src="<?php echo $site_url;?>thumb.php?src=<?php echo $site_url;?>images/gallery/<?php echo $image['image'];?>&w=160&h=160"/></a>
                   <a href="<?php echo $site_url;?><?php echo $page;?>?mode=edit&mode1=imgdelete&imgid=<?php echo $image['imageid'];?>&contentid=<?php echo $_REQUEST['contentid'];?>" onclick="return getConfirmation()"><span class="label label-danger"><i class="fa fa-times"></i> Delete</span></a><br/>
                  </div>
                 <?php
				 }
				 ?>
                </div>
                <?php
				}
				?>
              
              <div class="form-group">
                <label for="inputEmail3" class="col-sm-3 control-label">Status</label>
				<div class="col-sm-6">
                <div class="input-group date">
                <select class="form-control pull-right" name="status">
                <option <?php if($contentdetails[0]['status']=="Open"){ ?> selected <?php } ?> value="Open">Open</option>
                <option <?php if($contentdetails[0]['status']=="Close"){ ?> selected <?php } ?> value="Close">Close</option>
                </select>
                 
                </div>
                </div>
                <!-- /.input group -->
              </div>
              </div>
              <!-- /.box-body -->
              <div class="box-footer">
                <button type="reset" class="btn btn-default"><?php echo AL_CANCEL;?></button>
                <input type="submit" name="submit" value="<?php echo AL_SUBMIT;?>" class="btn btn-info pull-right"/>
             
              </div>
              <!-- /.box-footer -->
            </form>
          </div>
         
        </div>
        </div>
        <?php
	    }
		else {
                 
	    ?>
        <?php
		if($mode=="delete"){
			 $message=$helper->delete($table, array($field_id=>$_REQUEST['contentid']));
		}
		?>
          <?php
		if($mode=="approve"){
			$helper->update($table, array("status"=>1),array($field_id=>$_REQUEST['contentid']), array());
		}
		?>
         <?php
		if($mode=="pending"){
			$helper->update($table, array("status"=>2),array($field_id=>$_REQUEST['contentid']), array());
		}
		?>
        <div class="row">
        <div class="col-xs-12">
          <div class="box">
            <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" data-toggle="tooltip" title="Add <?php echo $maintitle;?>">
                <div class="btn-group">
                <div class="searchbox">
                <form action="" method="post"> 
                  <input name="scheduledate" placeholder="search by date" type="text" value="<?php echo $contentdetails[0]['scheduledate'];?>" class="searchtext" id="datepicker">
                <button class="btn btn-danger btn-flat searchbtn" type="submit"><i class="glyphicon  glyphicon-search"></i>&nbsp;Search</button>
                </form>
                </div>
                 
                   
                </div>
              </div>
            </div>
            
             <?php
			 if($searchdate!=""){
			$curdate=$searchdate;
			 }
			 else {
			$curdate=date("Y-m-d");
			$nextdate=date('Y-m-d', strtotime($curdate. ' + 30days'));
			 }
			 $where=" and scheduledate between '$curdate' and '$nextdate' ";
			$listtypes=$helper->selectbetweenlimit($table,"*",$where,$start,$limit,array("scheduledate"=>"ASC"));			 
			?>
            <!-- /.box-header -->
            <div class="box-body table-responsive no-padding">
            <?php
			if($message!=""){
			?>
            <button class="btn btn-block btn-danger btn-flat" type="button"><?php echo $message['message'];?></button>
			<?php	
			}
			?>
              <table class="table table-hover">
                <tr>
                  <th><?php echo AL_SERIALNO;?></th>
                   <th>Schedule Date</th>    
                   <th>Description</th>                 
                  <th><?php echo AL_STATUS;?></th>
                  <th><?php echo AL_ACTION;?></th>
                   <th>Report</th>
                </tr>
                <?php
				$i=($start*$limit)+1;
				foreach($listtypes as $type){
				?>
                 <?php
				  if($_REQUEST['start']>0){
					  $limitpage=$_REQUEST['start'];
				  }
				  else {
					  $limitpage=1;
				  }
				 
                    
				  ?>
                <tr>
                  <td><?php echo $i;?></td>
                   
                  <td><?php echo $type['scheduledate'];?></td>
                  <td><?php echo $type['description'];?></td>
                  <td>	
                   <span class="label label-danger"><?php echo $type['status'];?></span>
                  </td>
                  <td>
                  <a href="<?php echo $site_url;?><?php echo $page;?>?userid=<?php echo $_REQUEST['userid'];?>&mode=edit&contentid=<?php echo $type[$field_id];?>&start=<?php echo $limitpage;?>&projectis=<?php echo $type['projectid'];?>"><span class="label label-primary"><i class="fa fa-edit"></i> <?php echo AL_EDIT;?></span></a>
                   </td>
                   <td><a class="fancybox fancybox.iframe" target="_self" href="<?php echo $site_url;?>report.php?scheduleid=<?php echo $type[$field_id];?>&start=<?php echo $limitpage;?>"><span class="label label-success">Report</span></a></td>
                    
                </tr>
                 
                <?php
				$i=$i+1;
				}
				?>
                
                
              </table>
              <?php
			   $counter_list= $helper->countofdata($table,array(),$limit,array("status"=>"ASC"));
			  include('pagination/pagination.php');
			  ?>
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>
             
      </div>
      <?php
		   
                    
                }
		?>

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