<?php
include("../../check.php");
session_start();
 if(isset($_GET['del'])){
     echo $del = $_GET['del'];
     $getall = $getData->runQuery("SELECT * FROM `customer` where id='$del'");
     $filename = "pdf/".$getall[0]['pdf'];
     //echo "DELETE FROM `customer` WHERE id='$del'";
     //die();
    unlink($filename);
     $getData->runQuery("DELETE FROM `customer` WHERE id='$del'");
     $_SESSION['message']="<span class='text-success'>Data deleted successfully</span>";
     header("Location: index.php");
 }
 if(isset($_POST['imgSubmit'])){
     
     
     $name = $_POST['name'];
     $scope_of_business = $_POST['scope_of_business'];
     $remark = $_POST['remark'];
     $address = $_POST['address'];
     $address2 = $_POST['address2'];
     $body =  $_POST['body'];
     $sess_id = $_SESSION['user_id'];
     
     $standard = $_POST['standard'];
     $standard = implode(',',$standard);
     //die();

     $show_pass = rand();
     $user_pw = md5($show_pass);
     
     $getall = $getData->numRows("SELECT * FROM `customer` where user_id='$email'");
  
    
     if(empty($_POST['dataid'])){  // numRows


             $sattus = $getData->runQuery("INSERT INTO `customer`(`master_id`,`remark`, `scope_of_business`, `name`, `address`, `address2`,`standard`, `body`) VALUES ('$sess_id','$remark','$scope_of_business','$name','$address','$address2','$standard', '$body')");
             if($getall == 0){
                 $_SESSION['message']="<span class='text-success'>Data inserted successfully</span>";
                 header("Location: index.php");
                 
             }else{
                 $_SESSION['message']="<span class='text-danger'>Data insertion failed ! try another email id</span>";
                 header("Location: index.php");
                 
             }
             
     }else{
         $id = $_POST['dataid'];
              //$getall = $getData->runQuery("SELECT * FROM `customer` where id='$id'");
              //$filename = "img/".$getall[0]['img'];
              //unlink($filename);
              $update = $getData->runQuery("UPDATE `customer` SET `scope_of_business`='$scope_of_business',`name`='$name',`remark`='$remark',address='$address',address2='$address2',standard='$standard', body='$body' WHERE id='$id'");
                 $_SESSION['message']="<span class='text-success'>Data updated successfully</span>";
                 header("Location: index.php");
     }
 }
 
  if($_POST['status']){
     $id = $_POST['status'];
     $getall = $getData->runQuery("SELECT * FROM `draft` where id='$id'");
     if($getall[0]['status'] == "A"){
         $getData->runQuery("UPDATE `draft` SET `status`='I' WHERE id='$id'");
         echo '<span class="badge badge-danger">Inactive</span>';
         
     }else{
         $getData->runQuery("UPDATE `draft` SET `status`='A' WHERE id='$id'");
         echo '<span class="badge badge-success">Active</span>';
     }
 }
?>