<?php include('header.php');?>
<?php include('sidebar.php');?>
 
<?php
$maintitle="Services";
$page="services.php";
$table="services";
$field_id="service_id";
$mode=$_REQUEST['mode'];
$content_id=$_REQUEST['contentid'];
if(isset($_REQUEST['start'])){
$start=$_REQUEST['start']-1;
}
else {
$start=0;
}
?>
<?php
if(isset($_REQUEST['submit'])=="submit"){
$high_quality=$_POST['high_quality'];
$customer_service=$_POST['customer_service'];
$constant_dev=$_POST['constant_dev'];
$environment_friendly=$_POST['environment_friendly'];
$recycling=$_POST['recycling'];
$quality_paper=$_POST['quality_paper'];
$intro=$_POST['intro'];

unset($values['submit']);
unset($values['mode']);
$userid=array("user_id"=>$user_id);

if($_REQUEST['mode']=="add"){
	
$message=mysqli_query($con,"insert into services(intro,high_quality,customer_service,constant_dev,environment_friendly,recycling,quality_paper,image) values('$intro','$high_quality','$customer_service','$constant_dev','$environment_friendly','$recycling','$quality_paper','')");
$sel_max=mysqli_query($con,"select max(service_id) as maxslider from services");
$res_max=mysqli_fetch_array($sel_max);
$mid=$res_max['maxslider'];

$extension = pathinfo($_FILES["image"]["name"], PATHINFO_EXTENSION);
$newname= "image-".$mid.".".$extension;
$image = $_FILES['image']['name'];
$target = "../images/service/".$newname;
if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
$message=mysqli_query($con,"update services set image='$newname' where service_id='$mid'");
$message = "Item Added Successfully";
}


}
	
if($_REQUEST['mode']=="edit"){
	
$high_quality=$_POST['high_quality'];
$customer_service=$_POST['customer_service'];
$constant_dev=$_POST['constant_dev'];
$environment_friendly=$_POST['environment_friendly'];
$recycling=$_POST['recycling'];
$quality_paper=$_POST['quality_paper'];

	mysqli_query($con, "update services set intro='$intro',high_quality='$high_quality',customer_service='$customer_service',constant_dev='$constant_dev',environment_friendly='$environment_friendly',recycling='$recycling',quality_paper='$quality_paper' where service_id=$content_id");
$oldimage=$_POST['oldimage'];
	$image = $_FILES['image']['name'];
	if($image!=''){
		$extension = pathinfo($_FILES["image"]["name"], PATHINFO_EXTENSION);
$newname= "image-".$content_id.".".$extension;
  	$target = "../images/service/".$newname;
 
  	$sql = "update services set image='$newname' where service_id=$content_id";
  	mysqli_query($con, $sql);
 
  	if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
  	$msg = "Image uploaded successfully";
  	}else{
  	$msg = "Failed to upload image";
  	}
	}
	$message = "Item Updated Successfully";
}


}
?>

<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">
    <?php
	if($mode=="add" || $mode=="edit"){ 
	?>
     <div class="row">
         <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;List All <?php echo $maintitle;?></button></a>
                   
                </div>
              </div>
            </div> 
            </div> 
            </div>

 <!-- Add / Edit / Delete --> 
<?php
if($mode=="edit"){
	$cc=mysqli_query($con,"select * from services where service_id=".$_REQUEST['contentid']);
$contentdetails=mysqli_fetch_array($cc);
}
?>
<div class="col-md-12">
          
          <div class="box box-info">
            <div class="box-header with-border">
              <h3 class="box-title">Add <?php echo $maintitle;?></h3>
            </div>
            
            
            <div class="nav-tabs-custom">
            
             <form class="form-horizontal" action="" method="post" enctype="multipart/form-data">
            <div class="tab-content">
              <div class="active tab-pane" id="activity">
                 <?php
			if($message!=""){
			?>
            <button class="btn btn-block btn-success btn-flat" type="button"><?php echo $message;?></button>
			<?php	
			}
			?>
            <!-- /.box-header -->
            <!-- form start -->
           
            <input type="hidden" name="mode" value="<?php echo $_REQUEST['mode'];?>"/>
              <div class="box-body">
             
                <div class="form-group">
                  <label for="inputPassword3" class="col-sm-3 control-label">Introduction</label>

                  <div class="col-sm-8">
                      <textarea id="editor2" name="intro" rows="10" cols="80">
                                            <?php echo $contentdetails['intro'];?>
                    </textarea>
                  </div>
                </div>
         
                <div class="form-group">
                  <label for="inputPassword3" class="col-sm-3 control-label">High Quality</label>

                  <div class="col-sm-8">
                      <textarea id="editor2" name="high_quality" rows="10" cols="80">
                                            <?php echo $contentdetails['high_quality'];?>
                    </textarea>
                  </div>
                </div>
         
		   <div class="form-group">
                  <label for="inputPassword3" class="col-sm-3 control-label">Customer Service</label>

                  <div class="col-sm-8">
                      <textarea id="editor2" name="customer_service" rows="10" cols="80">
                                            <?php echo $contentdetails['customer_service'];?>
                    </textarea>
                  </div>
                </div>
         
		   <div class="form-group">
                  <label for="inputPassword3" class="col-sm-3 control-label">Constant Development</label>

                  <div class="col-sm-8">
                      <textarea id="editor2" name="constant_dev" rows="10" cols="80">
                                            <?php echo $contentdetails['constant_dev'];?>
                    </textarea>
                  </div>
                </div>
         
		   <div class="form-group">
                  <label for="inputPassword3" class="col-sm-3 control-label">Environment Friendly</label>

                  <div class="col-sm-8">
                      <textarea id="editor2" name="environment_friendly" rows="10" cols="80">
                                            <?php echo $contentdetails['environment_friendly'];?>
                    </textarea>
                  </div>
                </div>
         
		   <div class="form-group">
                  <label for="inputPassword3" class="col-sm-3 control-label">Recycling</label>

                  <div class="col-sm-8">
                      <textarea id="editor2" name="recycling" rows="10" cols="80">
                                            <?php echo $contentdetails['recycling'];?>
                    </textarea>
                  </div>
                </div>
            <div class="form-group">
                  <label for="inputPassword3" class="col-sm-3 control-label">Quality Paper</label>

                  <div class="col-sm-8">
                      <textarea id="editor2" name="quality_paper" rows="10" cols="80">
                                            <?php echo $contentdetails['quality_paper'];?>
                    </textarea>
                  </div>
                </div>
                 <div class="form-group">
                  <label for="inputEmail3" class="col-sm-3 control-label">Image (570px x 500px)</label>
					<div class="col-sm-8">
                    <input type="file"  name="image"  class="form-control">
                <?php    if($mode=="edit"){ ?>
                    <img src="../images/service/<?php echo $contentdetails['image'];?>" style="width: 20%;">
                    <?php } ?>
                  </div>
                </div>
              </div>
              <!-- /.box-body -->
              
            
              </div>
              <!-- /.tab-pane -->
            
              
              <!-- /.tab-pane -->
             <div class="box-footer">
                <button type="reset" class="btn btn-default">Cancel</button>
                <input type="submit" name="submit" value="Submit" class="btn btn-info pull-right"/>
                 
              </div>
              <!-- /.box-footer -->
             
            </div>
            <!-- /.tab-content -->
            </form>
          </div>
    
          </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">
                <a href="<?php echo $page;?>?mode=add"><button class="btn btn-danger btn-flat"><i class="glyphicon  glyphicon-plus"></i>&nbsp;Add New <?php echo $maintitle;?></button></a>
                   
                </div>
              </div> -->
            </div>
            <?php
			$listtypes=mysqli_query($con,"select * from services");			 
			?>
            <!-- /.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;?></button>
			<?php	
			}
			?>
              <table class="table table-hover">
                <tr>
                  <th>Sl.no</th>
                  <th>Description</th>
                  <th>Action</th>
                </tr>
                <?php
				$i=($start*$limit)+1;
				while($type=mysqli_fetch_array($listtypes)){
				?>
                 <?php
				  if($_REQUEST['start']>0){
					  $limitpage=$_REQUEST['start'];
				  }
				  else {
					  $limitpage=1;
				  }
				 
                    
				  ?>
                <tr>
                  <td><?php echo $i;?></td>
               
				  <td ><?php echo $type['high_quality'];?></td>
              
                  <td>
                  <a href="<?php echo $site_url;?>admin/<?php echo $page;?>?mode=edit&contentid=<?php echo $type[$field_id];?>&start=<?php echo $limitpage;?>"><span class="label label-primary"><i class="fa fa-edit"></i> Edit</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>
    <!-- /.content -->
  </div>
<?php include('footer.php');  ?>



<script>
CKEDITOR.replace('intro');
CKEDITOR.replace('high_quality');
CKEDITOR.replace('customer_service');
CKEDITOR.replace('constant_dev');
CKEDITOR.replace('environment_friendly');
CKEDITOR.replace('recycling');
CKEDITOR.replace('quality_paper');
</script>