<?php
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
  $action = $_GET['action'];
  include('config.php');
  include('common_functions.php');
  include('common_functions_app.php');
  switch ($action) {


     case 'get_contact': {
        getContact($_GET);
        break;
      }

  
      case 'delete_category' : { 
          deleteCategory($_GET);
          break;
      }


      case 'delete_components' : { 
          deleteComponent($_GET);
          break;
      }


      

       case 'get_category': {
        getCategory($_GET);
        break;
      }

      case 'get_equipment': {
        getEquipment($_GET);
        break;
      }

      case 'get_equipment_name' :{
      getEquipmentName($_GET);
      break;
    }

      case 'delete_equipment' : { 
          deleteEquipment($_GET);
          break;
      }

       case 'delete_inspection' : { 
          deleteInspection($_GET);
          break;
      }

        case 'delete_due_date' : { 
          deleteDueDate($_GET);
          break;
      }

      

       case 'get_inspection': {
        getInspection($_GET);
        break;
      }
       case 'get_inspection_history': {
        getInspectionHistory($_GET);
        break;
      }

       case 'get_inspection_request': {
        getInspectionRequest($_GET);
        break;
      }


      

       case 'delete_maintainance' : { 
          deleteMaintainance($_GET);
          break;
      }

       case 'get_maintainance': {
        getMaintainance($_GET);
        break;
      }


       case 'get_inspection_type': {
        getInspectionType($_GET);
        break;
      }

        case 'delete_inspection_type' : { 
          deleteInspectionType($_GET);
          break;
      }


    default:
      $record = array('success' => false, 'msg' => 'Invalid Action', 'data' => array());
      jsonSendEncode($record);
  }
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  $action = $_POST['action'];
  include('config.php');
  include('common_functions.php');
  include('common_functions_app.php');
  switch ($action) {
    case 'add_manage_category': {
        addCategory($_POST);
        break;
      }

      case 'add_manage_inspection_type': {
        addInspectionType($_POST);
        break;
      }


      

      case 'add_equipment': {
        addEquipment($_POST);
        break;
      }

       case 'edit_equipment': {
        EditEquipment($_POST);
        break;
      }

        case 'add_inspection': {
        addInspection($_POST);
        break;
      }

        case 'add_inspection_request': {
        addInspectionRequest($_POST);
        break;
      }

       case 'edit_inspection': {
        EditInspection($_POST);
        break;
      }


      case 'add_maintainance': {
        addMaintainance($_POST);
        break;
      }


       case 'edit_maintainance': {
        EditMaintainance($_POST);
        break;
      }

    

       case 'add_subadmin' : { // category delete
    addSubadmin($_POST);
    break;
  }


    

      case 'edit_user': {
        editUser($_POST);
        break;
      } 
   
      

    case 'contact_reply': {
        sendReply($_POST);
        break;
      }


    case 'edit_manage_category': {
        EditCategory($_POST);
        break;
      }

       case 'edit_manage_inspection_type': {
        editInspectionType($_POST);
        break;
      }

       

    default:
      $record = array('success' => false, 'msg' => 'Invalid Action', 'data' => array());
      jsonSendEncode($record);
  }
}

//-----------------------------catgory check edit------------------------------//
//---------------------------check for category exists-----------------------------//

//-------------------------check category add--------------------------//
function CategoryCheckadd1($data)
{
  global $mysqli;
  include_once('language_message.php');
  //print_r($data);
  if (empty($data['name'])) {
    echo 'false';
  } else {
    $name      = $data['name'];
    //$category_id        = decode($data['id']);
    //-------------------------- check user email --------------------------
    $check_category = $mysqli->prepare("SELECT category_id from category_master where delete_flag='0' and category_name=? and type=0 ");
    $check_category->bind_param("s", $name);
    $check_category->execute();
    $check_category->store_result();
    $check_category_count = $check_category->num_rows;
    if ($check_category_count > 0) {
      echo 'false';
    } else {
      echo "true";
    }
  }
}

function categoryCheckadd1Event($data)
{
  global $mysqli;
  include_once('language_message.php');
  //print_r($data);
  if (empty($data['name'])) {
    echo 'false';
  } else {
    $name      = $data['name'];
    //$category_id        = decode($data['id']);
    //-------------------------- check user email --------------------------
    $check_category = $mysqli->prepare("SELECT category_id from category_master where delete_flag='0' and category_name=? and type=1 ");
    $check_category->bind_param("s", $name);
    $check_category->execute();
    $check_category->store_result();
    $check_category_count = $check_category->num_rows;
    if ($check_category_count > 0) {
      echo 'false';
    } else {
      echo "true";
    }
  }
}

//----------------------channel check edit----------------------------------//

//-------------------------check category add--------------------------//

//-----------------------------add category-----------------------------------------//

//---------------------------------start of get contact details------------------------------//
function getContact($data)
{

  global $mysqli;
  include_once('language_message.php');

  //print_r($data);

  if (empty($data['type'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $type     = $data['type'];
    $srno = 1;

    //for($i=0; $i<50; $i++){

    if ($type == 'all') {
      $check_data = $mysqli->prepare("SELECT contact_id,user_id,name,email,message,createtime from contact_us_master where delete_flag='0'  order by contact_id desc");
    }


    $check_data->execute();
    $check_data->store_result();
    $check_data_count = $check_data->num_rows;

    if ($check_data_count > 0) {
      $check_data->bind_result($contact_id, $user_id, $name, $email, $message, $createtime);
      while ($check_data->fetch()) {
        $createtime = date('Y-m-d h:i:a', strtotime($createtime));
        //$user_id = encode($user_id);


        $checkbox_html = '<div class="checkbox checkbox-inverse checkbox-circle mb-2">
                                                <input type="checkbox" class="checkbox_all_action" id="btn_checkbox_action' . $contact_id . '" value="' . $contact_id . '">
                                                <label for="btn_checkbox_action' . $contact_id . '">
                                                </label>
                                            </div>';
        $reply_html  = '<div class="btn-group m-b-10">
                            <a href="sendreply.php?id=' . encode($contact_id) . '" class="fas fa-reply style="color: #51ad13 !important;"></a>
                        </div>';

        $contact_arr[] = array('srno' => $srno, 'contact_id' => $contact_id, 'name' => $name, 'Reply' => $reply_html, 'select' => $checkbox_html, 'createtime' => $createtime, 'email' => $email, 'message' => $message);
        $srno++;
      }
    }

    if (empty($contact_arr)) {
      $contact_arr = array();
    }

    $record = array('success' => true, 'msg' => $msgDataFound, 'contact_arr' => $contact_arr);
    jsonSendEncode($record);
  }
}

//---------------------------------end of get contact details------------------------------//

//-------------------------send Reply function starts------------------------------// 
function sendReply($data)
{
  global $mysqli;
  include_once('language_message.php');
  include_once('mailFunctions.php');
  include_once('site_config.php');

  if (empty($data['contact_id']) || empty($data['title']) || empty($data['message']) || empty($data['email'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $id = decode($data['contact_id']);
    $email = $data['email'];
    $name = $data['name'];
    $message = $data['message'];
    $subject = $data['title'];


    $postData['name'] = $name;
    $postData['email'] = $email;
    $postData['message'] = $message;
    $postData['subject'] = $subject;

    $postData['fromName'] = $appName;
    $postData['app_name'] = $appName;
    $postData['app_logo'] = $appLogo;
    $postData['mail_title'] = "Reply";

    $subject = "Reply";
    $mailBody = mailBodyContactUs($postData);;
    $mailResponse = mailSend($postData['email'], $postData['fromName'], $subject, $mailBody);

    if ($mailResponse == 'yes') {
      $record = array('success' => true, 'msg' => $ReplySendSuccess, 'data' => array());
      jsonSendEncode($record);
    } else {
      $record = array('success' => false, 'msg' => $ReplySendError, 'data' => array());
      jsonSendEncode($record);
    }
  }
}



//-------------------------get channel-------------------------------------------//

function getChannel($data)
{
  global $mysqli;
  global $onerror;
  include_once('language_message.php');
  include_once('site_config.php');
  //print_r($data);
  if (empty($data['type'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {

    $user_id = decode($data['user_id']);
    $user_type = $data['user_type'];
    $type     = $data['type'];
    $srno = 1;
    //for($i=0; $i<50; $i++){
    if ($user_type == 0) {
      if ($type == 'all') {
        $check_data = $mysqli->prepare("SELECT channel_id,name,image, active_flag,createtime from channel_master where delete_flag='0' order by channel_id desc");
      }
    } else {
      if ($type == 'all') {
        $check_data = $mysqli->prepare("SELECT channel_id,name,image, active_flag,createtime from channel_master where delete_flag='0' and user_id = '" . $user_id . "' order by channel_id desc");
      }
    }

    $check_data->execute();
    $check_data->store_result();
    $check_data_count = $check_data->num_rows;
    if ($check_data_count > 0) {
      $check_data->bind_result($channel_id, $name, $image, $active_flag, $createtime);
      while ($check_data->fetch()) {
        $createtime = date('Y-m-d h:i A', strtotime($createtime));

        $subscribe = getSubscribecount($channel_id);
        //$user_id = encode($user_id);
        if ($image == '' || $image == null || $image == 'NA') {
          $image_html = '<img  width="50px" src="../webservice/images/Noimage.png" class="rounded-circle circle-border m-b-md img-fix img-responsive" name="image" id="previewholder" style="width: 70px; height: 70px;" alt="" 
          >';
        } else {
          $image_html = '<img  width="50px" src="../webservice/images/' . $image . '" class="rounded-circle circle-border m-b-md img-fix img-responsive" name="image" id="previewholder" style="width: 70px; height: 70px;" alt="" 
          >';
        }

        if ($active_flag == '1') {
          $active_flag_text = '0';
          $active_flag_html = '<label class="btn btn-success btn-sm"> Active</label>';
        } else {
          $active_flag_text = '1';
          $active_flag_html = '<label class="btn btn-danger btn-sm"> in-active</label>';
        }
        $checkbox_html = '<div class="checkbox checkbox-inverse checkbox-circle mb-2">
        <input type="checkbox" class="checkbox_all_action" id="btn_checkbox_action' . $channel_id . '" value="' . $channel_id . '">
        <label for="btn_checkbox_action' . $channel_id . '">
        </label>
        </div>';


        $action_html = '<div class="btn-group">
        <button type="button"
        class="btn btn-primary dropdown-toggle float-button-light"
        id="primary-dropdown-outline" data-toggle="dropdown" aria-expanded="false">
        Action
        </button>
        <ul class="dropdown-menu dropdown-menu-primary" style=" margin: 2px -56px 0;" aria-labelledby="primary-dropdown"
        role="menu">

        <li><a class="dropdown-item" href="view_channel.php?id=' . encode($channel_id) . '""><i class="dw dw-eye" ></i> View</a>

        <li><a class="dropdown-item" href="edit_channel.php?id=' . encode($channel_id) . '""><i class="dw dw-eye" ></i>Edit</a>

         <li> <a  class="float-button-light dropdown-item" href="javascript:void(0)" data-id="' . $channel_id . '" onClick="btnDeleteConfirm(this)"><i class="dw dw-delete-3"></i>Delete</a>




        </li>
        <li>
        <a class="dropdown-item" href="javascript:void(0)" class="dropdown-item" data-user-status="' . $active_flag_text . '" data-id="' . $channel_id . '"onClick="btnUserActivateDeactivateConfirm(this)"><i class="dw dw-delete-3"></i> Active/in-active</a>
        </li>
        </ul>
        </div>';
        //         $country_details=getCountryData($country_id);
        // if($country_details!="NA"){
        //     $currency_symbol=$country_details['symbol'];
        // }
        //         // <li><a href="edit_user.php?id='.encode($user_id).'" class="dropdown-item">Edit</a></li>
        //         if($mobile==""){
        //         $mobile_html="NA";
        //         }
        //         else{
        //             $mobile_html='('.$phone_code.')'.$mobile;
        //         }
        $channel_arr[] = array('srno' => $srno, 'channel_id' => $channel_id, 'name' => $name, 'active_flag' => $active_flag_html, 'action' => $action_html, 'select' => $checkbox_html, 'createtime' => $createtime, 'image' => $image_html, 'subscribe' => $subscribe);
        $srno++;
      }
    }
    if (empty($channel_arr)) {
      $channel_arr = array();
    }
    $record = array('success' => true, 'msg' => $msgDataFound, 'data' => array('channel_arr' => $channel_arr));
    jsonSendEncode($record);
  }
}







//------------------------edit channel--------------------------------------------//





//-----------------------new code starts--------------------------------------------------//






function EditCategory($data)
{
   //print_r($data);die;
  global $mysqli;
  global $onerror;

  include_once('language_message.php');
  // echo "hello"; die;
  if (empty($data['id'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $cat_id     =   decode($data['id']);
   // $image = $data['image'];
    $category_name =$data['cat_name'];
    // $category_id        = decode($data['id']);


    // Now check category Already added   

    $check_category = $mysqli->prepare("SELECT category_id from category_master where delete_flag='0' and category_name=? and category_id != ?");
  $check_category->bind_param("si", $category_name,$cat_id);
  $check_category->execute();
  $check_category->store_result();
  $check_category_count = $check_category->num_rows;
  if ($check_category_count > 0) {

    $record = array('success' => false, 'msg' => $msgCategoryExist, 'data' => array());
    jsonSendEncode($record);
  }      

   
    $updatetime     =   date('Y-m-d H:i:s');
    $update_all     =   $mysqli->prepare("UPDATE category_master SET category_name=?, updatetime=? WHERE category_id=?");
    $update_all->bind_param("ssi", $category_name, $updatetime, $cat_id);
    $update_all->execute();
    $update = $mysqli->affected_rows;
    if ($update <= 0) {
      $record =   array('success' => false, 'msg' => $msgCategoryUpdate, 'data' => array());
      jsonSendEncode($record);
    };
    $record     =   array('success' => true, 'msg' => $msgCategoryUpdate, 'data' => array());
    jsonSendEncode($record);
  }
}












function categoryCheckEdit11($data)
{
  global $mysqli;
  include_once('language_message.php');
  //print_r($data);
  if (empty($data['name'])) {
    echo 'false';
  } else {
    $category      = $data['name'];
    $cat_id  = $data['id'];
    //-------------------------- check user email --------------------------
    $check_channel = $mysqli->prepare("SELECT category_id from category_master where delete_flag='0' and category_name = ? and category_id != ? and type=0");
    $check_channel->bind_param("si", $category, $cat_id);
    $check_channel->execute();
    $check_channel->store_result();
    $check_channel_count = $check_channel->num_rows;
    if ($check_channel_count > 0) {
      echo 'false';
    } else {
      echo "true";
    }
  }
}

function categoryCheckEdit11Event($data)
{
  global $mysqli;
  include_once('language_message.php');
  //print_r($data);
  if (empty($data['name'])) {
    echo 'false';
  } else {
    $category      = $data['name'];
    $cat_id  = $data['id'];
    //-------------------------- check user email --------------------------
    $check_channel = $mysqli->prepare("SELECT category_id from category_master where delete_flag='0' and category_name = ? and category_id != ? and type=1");
    $check_channel->bind_param("si", $category, $cat_id);
    $check_channel->execute();
    $check_channel->store_result();
    $check_channel_count = $check_channel->num_rows;
    if ($check_channel_count > 0) {
      echo 'false';
    } else {
      echo "true";
    }
  }
}


//------------------new code starts--------------------------------//








function deleteBanner($data)
{

  //echo"<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  if (empty($data['cat_id'])) {
    $record =   array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $cat_id    = $data['cat_id'];
    $check_user_id = $mysqli->prepare("SELECT banner_id from banner_master where delete_flag='0' and banner_id=?");
    $check_user_id->bind_param("i", $cat_id);
    $check_user_id->execute();
    $check_user_id->store_result();
    $check_user_id_count = $check_user_id->num_rows;
    if ($check_user_id_count <= 0) {
      $record = array('success' => false, 'msg' => $msgBannerNotExist, 'data' => array());
      jsonSendEncode($record);
    }
    $delete_flag    =   1;
    $updatetime     =   date('Y-m-d H:i:s');
    // Delete Query
    $update_all     =   $mysqli->prepare("UPDATE banner_master set delete_flag=?, updatetime=? WHERE banner_id=?");
    $update_all->bind_param("isi", $delete_flag, $updatetime, $cat_id);
    $update_all->execute();
    $update         =   $mysqli->affected_rows;
    if ($update <= 0) {
      $record     =   array('success' => false, 'msg' => $getBannerDeleteError, 'data' => array());
      jsonSendEncode($record);
    }
    $record         =   array('success' => true, 'msg' => $getBannerDelete, 'data' => array());
    jsonSendEncode($record);
  }
}










function getListingCategory($data)
{
  global $mysqli;
  global $onerror;
  //global $item_onerror;
  include_once('language_message.php');
  //include_once('site_config.php');
  //print_r($data);
  if (empty($data['type'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $type     = $data['type'];
    $srno = 1;
    //for($i=0; $i<50; $i++){
    if ($type == 'all') {
      $check_data = $mysqli->prepare("SELECT `category_id`, `category_name`, `image`, `createtime` FROM `category_master` where delete_flag=0 and type = 0 order by category_id desc");
    }
    $check_data->execute();
    $check_data->store_result();
    $check_data_count = $check_data->num_rows;
    if ($check_data_count > 0) {
      $check_data->bind_result($category_id, $category_name, $image, $createtime);
      while ($check_data->fetch()) {
        $createtime = date('d-m-Y h:i A', strtotime($createtime));
        //$countrycode = getCountryCode($country_id);
        //$user_id = encode($user_id);

        $image_html = '<img  width="50px" src="../webservice/images/' . $image . '" class="rounded-circle circle-border m-b-md img-fix img-responsive" name="profile_image" id="previewholder" style="width: 70px; height: 70px;" alt="" onerror="this.src=' . $onerror . ';" >';

        $action_html = '


    <div class="btn-group">

                          

                        

                        



                        <button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown">Action</button>

                          <div class="dropdown-menu dropdown-menu-end">

                          

                            <a class="dropdown-item"  href="#myModal1" data-bs-toggle="modal"  data-id="' . encode($category_id) . '"   data-name="' . $category_name . '"  data-image="' . $image . '"onClick="btnEditCategory(this)"><i class="fa fa-edit"></i>&nbsp;Edit</a>





                            <a class="dropdown-item"  data-id="' . $category_id . '" onClick="btnUserDeleteConfirm(this)"><i class="fa fa-trash"></i>&nbsp;Delete</a>

                            

                          

                          </div>



                        </div>





  ';


        $user_arr[] = array('srno' => $srno, 'category_id' => $category_id, 'action' => $action_html, 'category_name' => $category_name, 'createtime' => $createtime, 'image' => $image_html);
        $srno++;
      }
    }
    if (empty($user_arr)) {
      $user_arr = array();
    }
    $record = array('success' => true, 'msg' => $msgDataFound, 'data' => array('user_arr' => $user_arr));
    jsonSendEncode($record);
  }
}


function getBanner($data)
{
  global $mysqli;
  global $onerror;
  //global $item_onerror;
  include_once('language_message.php');
  //include_once('site_config.php');
  //print_r($data);
  if (empty($data['type'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $type     = $data['type'];
    $srno = 1;
    //for($i=0; $i<50; $i++){
    if ($type == 'all') {
      $check_data = $mysqli->prepare("SELECT `banner_id`, `image`,`createtime` FROM `banner_master`  where delete_flag=0 order by banner_id desc");
    }
    $check_data->execute();
    $check_data->store_result();
    $check_data_count = $check_data->num_rows;
    if ($check_data_count > 0) {
      $check_data->bind_result($banner_id, $image,$createtime);
      while ($check_data->fetch()) {
        $createtime = date('d-m-Y h:i A', strtotime($createtime));
        //$countrycode = getCountryCode($country_id);
        //$user_id = encode($user_id);

        $image_html = '<img  width="50px" src="../webservice/images/' . $image . '" class="rounded-circle circle-border m-b-md img-fix img-responsive" name="profile_image" id="previewholder" style="width: 70px; height: 70px;" alt="" onerror="this.src=' . $onerror . ';" >';

        $action_html = '


    <div class="btn-group">

                          

                        

                        



                        <button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown">Action</button>

                          <div class="dropdown-menu dropdown-menu-end">

                          

                            <a class="dropdown-item"  href="#myModal1" data-bs-toggle="modal"  data-id="' . $banner_id . '" data-image="' . $image . '"onClick="btnEditCategory(this)"><i class="fa fa-edit"></i>&nbsp;Edit</a>





                            <a class="dropdown-item"  data-id="' . $banner_id . '" onClick="btnUserDeleteConfirm(this)"><i class="fa fa-trash"></i>&nbsp;Delete</a>

                            

                          

                          </div>



                        </div>





  ';


        $user_arr[] = array('srno' => $srno, 'category_id' => $banner_id, 'action' => $action_html, 'image' => $image_html);
        $srno++;
      }
    }
    if (empty($user_arr)) {
      $user_arr = array();
    }
    $record = array('success' => true, 'msg' => $msgDataFound, 'data' => array('user_arr' => $user_arr));
    jsonSendEncode($record);
  }
}






function  addCategory($data)
{

  //echo "<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  include_once('site_config.php');
  include_once('mailFunctions.php');
  if (empty($_POST['cat_name'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  }



  $category_name = $data['cat_name'];

  $check_category = $mysqli->prepare("SELECT category_id from category_master where delete_flag='0' and category_name=? ");
  $check_category->bind_param("s", $category_name);
  $check_category->execute();
  $check_category->store_result();
  $check_category_count = $check_category->num_rows;
  if ($check_category_count > 0) {

    $record = array('success' => false, 'msg' => $msgCategoryExist, 'data' => array());
    jsonSendEncode($record);
  }



  






  //-------------------------- check user email --------------------------

  $updatetime = date('Y-m-d H:i:s');
  $createtime = date('Y-m-d H:i:s');

  $type = '1';

  $sql = "INSERT INTO `category_master`( `category_name`,  `createtime`, `updatetime`)  VALUES (?,?,?)";
  $result = $mysqli->prepare($sql);
  $result->bind_param('sss', $category_name, $createtime, $updatetime);
  $result->execute();
  $row = $mysqli->affected_rows;
  if ($row <= 0) {
    $record = array('success' => false, 'msg' => $CategoryNotAdded, 'data' => array());
    jsonSendEncode($record);
  }


  $record = array('success' => true, 'msg' => $CategoryAdded, 'data' => array());
  jsonSendEncode($record);
}

function  addListingCategory($data)
{

  //echo "<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  include_once('site_config.php');
  include_once('mailFunctions.php');
  if (empty($_POST['cat_name'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  }



  $category = trim($data['cat_name']);

  $check_category = $mysqli->prepare("SELECT category_id from category_master where delete_flag='0' and category_name=? and type=0 ");
  $check_category->bind_param("s", $category);
  $check_category->execute();
  $check_category->store_result();
  $check_category_count = $check_category->num_rows;
  if ($check_category_count > 0) {

    $record = array('success' => false, 'msg' => $ListingCategoryAddedalready, 'data' => array());
    jsonSendEncode($record);
  }




  if (!empty($_FILES['image']['name'])) {
    $user_image = $_FILES['image'];
    // Code to upload the file starts
    $file = $user_image;
    $folder_name = '../webservice/images';
    $file_type = 'image';
    $upload_status = uploadFile($file, $folder_name, $file_type);
    if ($upload_status == 'error') {
      $record = array('success' => false, 'msg' => $msgErrorFileUpload, 'data' => array());
      jsonSendEncode($record);
    }
    $image = $upload_status;
    // Code to upload the file starts
  } else {
    $image =  $image_get;
  }






  //-------------------------- check user email --------------------------

  $updatetime = date('Y-m-d H:i:s');
  $createtime = date('Y-m-d H:i:s');

  $type = '0';

  $sql = "INSERT INTO `category_master`(`category_id`, `category_name`, `image`, `type`, `createtime`, `updatetime`)  VALUES (?,?,?,?,?,?)";
  $result = $mysqli->prepare($sql);
  $result->bind_param('ississ', $category_id, $category, $image, $type, $createtime, $updatetime);
  $result->execute();
  $row = $mysqli->affected_rows;
  if ($row <= 0) {
    $record = array('success' => false, 'msg' => $ListingCategoryNotAdded, 'data' => array());
    jsonSendEncode($record);
  }


  $record = array('success' => true, 'msg' => $ListingCategoryAdded, 'data' => array());
  jsonSendEncode($record);
}



function  addBanner($data)
{

  //echo "<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  include_once('site_config.php');
  include_once('mailFunctions.php');
  // if(empty($_POST['cat_name'])){
  //         $record=array('success'=>false, 'msg'=>$msgEmptyAll, 'data'=>array()); 
  //         jsonSendEncode($record);
  // }



  // $category=trim($data['cat_name']);



  if (!empty($_FILES['image']['name'])) {
    $user_image = $_FILES['image'];
    // Code to upload the file starts
    $file = $user_image;
    $folder_name = '../webservice/images';
    $file_type = 'image';
    $upload_status = uploadFile($file, $folder_name, $file_type);
    if ($upload_status == 'error') {
      $record = array('success' => false, 'msg' => $msgErrorFileUpload, 'data' => array());
      jsonSendEncode($record);
    }
    $image = $upload_status;
    // Code to upload the file starts
  } else {
    $image =  $image_get;
  }






  //-------------------------- check user email --------------------------

  $updatetime = date('Y-m-d H:i:s');
  $createtime = date('Y-m-d H:i:s');



  $sql = "INSERT INTO `banner_master`(`image`, `createtime`, `updatetime`)  VALUES (?,?,?)";
  $result = $mysqli->prepare($sql);
  $result->bind_param('sss', $image, $createtime, $updatetime);
  $result->execute();
  $row = $mysqli->affected_rows;
  if ($row <= 0) {
    $record = array('success' => false, 'msg' => $bannerNotAdded, 'data' => array());
    jsonSendEncode($record);
  }


  $record = array('success' => true, 'msg' => $BannerAdded, 'data' => array());
  jsonSendEncode($record);
}


//     function  editCategory($data){

//  // echo "<pre>";print_r($data);exit;
// global $mysqli;
// include_once('language_message.php');
// include_once('site_config.php');
// //include_once('mailFunctions.php');

// $id =$data['id'];

//   $category=$data['category'];
// $item_type=$data['item_type1'];






// //-------------------------- check user email --------------------------

//  $updatetime=date('Y-m-d H:i:s');







// //-------------------------- check user email --------------------------

//  $updatetime=date('Y-m-d H:i:s');


// $updatetime=date('Y-m-d H:i:s');
// $update_all=$mysqli->prepare("UPDATE item_category_master SET  item_category_name=? ,store_type=? ,updatetime=? WHERE item_category_id=?");
// $update_all->bind_param('sisi',$category,$item_type,$updatetime,$id);
// $update_all->execute();
// //echo 'error='.mysqli_error($mysqli);
// $update=$mysqli->affected_rows;
// if($update<=0){
//   $record=array('success'=>false,'msg' =>$msgItemNotUpdate, 'data'=>array());
//   jsonSendEncode($record);
// }
// $record=array('success'=>true,'msg' =>$msgItemUpdate, 'data'=>array());
// jsonSendEncode($record);


//     //     $mailContent                =   '';
//     // $mailContent                .=  '<p style="font-family:Arial, Helvetica, sans-serif; font-size:15px; color:#333333; margin-top:0">
//     // User Name- '.ucfirst($project_name).'</p>';
//     // $mailContent                .= '<p style="font-family:Arial, Helvetica, sans-serif; font-size:15px; color:#333333; margin-top:0">
//     // User Email- '.$email.'</p>';
//     // $mailContent                .= '<p style="font-family:Arial, Helvetica, sans-serif; font-size:15px; color:#333333; margin-top:0"> Password- '.$npassword.'</p>';
//     // $mailContent                .= '<p>Click the link for login &nbsp;<a href="'.$Project_login.'">click here</a></p>';

//     // $postData['fromName']       =   'Construction';
//     // $postData['app_name']       =   $appName;
//     // $postData['app_logo']       =   $appLogo;
//     // $postData['app_bg']         =   'app_bg'; 
//     // $postData['mailContent']      =   $mailContent;
//     // $postData['email']          =   $email;
//     // $postData['name']          =   $project_name;
//     // $subject                    =  "Project Login Details";
//     // $postData['mail_msg']       =   $subject;
//     // $postData['Password']   = $password;
//     // $mailBody = mailBodyProjectSignupData1($postData);
//     // $mailResponse = mailSend($postData['email'],$postData['fromName'], $subject, $mailBody);
//     // $user_id=$mysqli->insert_id;

//     }















function addFAQFinder($data)
{
  global $mysqli;
  //print_r($data);exit;
  include_once('language_message.php');
  $question    =   $data['question'];
  $answer    =   $data['answer'];
 
  $delete_flag    =   0;
  $createtime     =   date('Y-m-d H:i:s');
  $updatetime     =   date('Y-m-d H:i:s');
  
  // echo "INSERT into faq_master(`question`,`answer`,`delete_flag`, `createtime`, `updatetime`) values($question,$answer,$delete_flag,$createtime, $updatetime)";die;
  $insert_all   = $mysqli->prepare("INSERT into faq_master(`question`,`answer`,`delete_flag`, `createtime`, `updatetime`) values(?,?,?,?,?)");
  $insert_all->bind_param("ssiss", $question, $answer, $delete_flag, $createtime, $updatetime);
  $insert_all->execute();
  $insert     = $mysqli->affected_rows;
  if ($insert <= 0) {
    $record   = array('success' => false, 'msg' => $FaqNotAdded, 'data' => array());
    jsonSendEncode($record);
  }


  // echo "<pre>";print_r($category_count);exit;
  $record = array('success' => true, 'msg' => $FaqAdded, 'data' => array());
  // print_r($record);die;
  jsonSendEncode($record);
}



function getFaq($data)
{
  global $mysqli;
  global $onerror;
  include_once('language_message.php');
  include_once('site_config.php');
  // print_r($data);die;
  if (empty($data['type'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $type     = $data['type'];
    $faq_type     = $data['faq_type'];
    $srno = 1;
    //for($i=0; $i<50; $i++){
    if ($type == 'all') {
     
        $check_data = $mysqli->prepare("SELECT `faq_id`, `question`, `answer` ,`createtime` FROM `faq_master` where delete_flag=0  order by faq_id desc");
      
    }
    $check_data->execute();
    $check_data->store_result();
    $check_data_count = $check_data->num_rows;
    if ($check_data_count > 0) {
      $check_data->bind_result($faq_id, $question, $answer, $createtime);
      while ($check_data->fetch()) {

        $checkbox_html = '<div class="checkbox checkbox-inverse checkbox-circle mb-2">
        <input type="checkbox" class="checkbox_all_action" id="btn_checkbox_action' . $faq_id . '" value="' . $faq_id . '">
        <label for="btn_checkbox_action' . $faq_id . '">
        </label>
        </div>';

        
        $action_html = '<div class="btn-group">
                <button type="button"
                class="btn btn-primary dropdown-toggle float-button-light"
                id="primary-dropdown-outline" data-bs-toggle="dropdown" aria-expanded="false">
                Action
                </button>
                <ul class="dropdown-menu dropdown-menu-primary" style=" margin: 2px -56px 0;" aria-labelledby="primary-dropdown"
                role="menu">
               ';

       
          $action_html .= ' <li><a class="dropdown-item" href="javascript:void(0)" data-id="' . $faq_id . '"   data-question="' . $question . '"   data-answer="' . $answer . '"  onClick="btnEditCategory(this)"><i class="fa fa-edit"></i>&nbsp;Edit</a><li>';
       
        $action_html .=  '<li> <a  class="dropdown-item" href="javascript:void(0)" data-id="' . $faq_id . '" onClick="btnUserDeleteConfirm(this)"><i class="fa fa-trash"></i>&nbsp;Delete</a>
                </li>
               
                </ul>
                </div>';
        $user_arr[] = array('srno' => $srno, 'faq_id' => $faq_id, 'question' => $question, 'answer' => $answer, 'action' => $action_html, 'select' => $checkbox_html);
        $srno++;
      }
    }
    // print_r($user_arr);die;
    if (empty($user_arr)) {
      $user_arr = array();
    }
    $record = array('success' => true, 'msg' => $msgDataFound, 'data' => array('user_arr' => $user_arr));
    jsonSendEncode($record);
  }
}



























function CityCheckadd1($data)
{
  global $mysqli;
  include_once('language_message.php');
  //print_r($data);
  if (empty($data['name'])) {
    echo 'false';
  } else {
    $name      = $data['name'];
    $sat_name      = $data['sat_name'];
    //$category_id        = decode($data['id']);
    //-------------------------- check user email --------------------------
    $check_category = $mysqli->prepare("SELECT city_id from city_master where delete_flag='0' and city_name=? and state_id=?");
    $check_category->bind_param("si", $name, $sat_name);
    $check_category->execute();
    $check_category->store_result();
    $check_category_count = $check_category->num_rows;
    if ($check_category_count > 0) {
      echo 'false';
    } else {
      echo "true";
    }
  }
}







function getInnocence($data)
{
  global $mysqli;
  global $onerror;
  //global $item_onerror;
  include_once('language_message.php');
  //include_once('site_config.php');
  //print_r($data);exit;
  if (empty($data['type'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $type     = $data['type'];

    $srno = 1;
    //for($i=0; $i<50; $i++){
    if ($type == 'all') {

      $check_data = $mysqli->prepare("SELECT `innocence_id`, `innocence_name`,`email`, `phone_number`, `address`, `createtime` FROM `innocence_master` where delete_flag=0 order by innocence_id desc");
    }

    $check_data->execute();
    $check_data->store_result();
    $check_data_count = $check_data->num_rows;
    if ($check_data_count > 0) {
      $check_data->bind_result($innocence_id, $innocence_name, $email, $phone_number, $address, $createtime);
      while ($check_data->fetch()) {
        $createtime = date('d-m-Y h:i A', strtotime($createtime));

        //$user_id = encode($user_id);



        $action_html = '


    <div class="btn-group">

                          

                        

                        



                        <button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown">Action</button>

                          <div class="dropdown-menu dropdown-menu-end">

                          

                            <a class="dropdown-item"  href="#" data-bs-toggle="modal"  data-id="' . $innocence_id . '"   data-name="' . $innocence_name . '"  data-phone="' . $phone_number . '"  data-address="' . $address . '"  data-email="' . $email . '" onClick="btnEditCategory(this)"><i class="fa fa-edit"></i>&nbsp;Edit</a>





                            <a class="dropdown-item"  data-id="' . $innocence_id . '" onClick="btnUserDeleteConfirm(this)"><i class="fa fa-trash"></i>&nbsp;Delete</a>

                            

                          

                          </div>



                        </div>





  ';


        $user_arr[] = array('srno' => $srno, 'innocence_id' => $innocence_id, 'action' => $action_html, 'innocence_name' => $innocence_name, 'createtime' => $createtime, 'phone_number' => '+1 ' . $phone_number, 'address' => $address, 'email' => $email);
        $srno++;
      }
    }
    if (empty($user_arr)) {
      $user_arr = array();
    }
    $record = array('success' => true, 'msg' => $msgDataFound, 'data' => array('user_arr' => $user_arr));
    jsonSendEncode($record);
  }
}


//edit Weblink function end

function EditWeblink($data)
{
  // print_r($data);die;
  global $mysqli;
  global $onerror;

  include_once('language_message.php');
  // echo "hello"; die;
  if (empty($data['weblink_id'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $weblink_id     =  $data['weblink_id'];

    $weblink_1 = $data['customer_care'];
    // print_r($weblink_1);die;
    $weblink_2 = $data['cashback_and_offers'];
    $weblink_3 = $data['become_a_merchant'];

    // Now check  Already added         
    $check_email_mobile = $mysqli->prepare("SELECT  weblink_id from weblink_master where delete_flag=0 and weblink_id=?");
    $check_email_mobile->bind_param("i", $weblink_id);
    $check_email_mobile->execute();
    $check_email_mobile->store_result();
    $check_email_mobile_count = $check_email_mobile->num_rows;
    if ($check_email_mobile_count <= 0) {
      $record = array('success' => false, 'msg' => $msgInvalidId, 'data' => array());
      jsonSendEncode($record);
    }
    $check_email_mobile->bind_result($weblink_id);
    $check_email_mobile->fetch();


    $updatetime     =   date('Y-m-d H:i:s');

    $update_all     =   $mysqli->prepare("UPDATE weblink_master SET weblink_1=?, weblink_2=?, weblink_3=?,updatetime=? WHERE weblink_id=?");
    $update_all->bind_param("ssssi", $weblink_1, $weblink_2, $weblink_3, $updatetime, $weblink_id);
    $update_all->execute();
    $update = $mysqli->affected_rows;
    if ($update <= 0) {
      $record =   array('success' => false, 'msg' => $msgWebLinkNotUpdate, 'data' => array());
      jsonSendEncode($record);
    };
    $record     =   array('success' => true, 'msg' => $msgWebLinkSuccessUpdate, 'data' => array());
    jsonSendEncode($record);
  }
}

//edit Weblink function end

//edit subscription price function end



//edit subscription price end

























//  function getFeedLike($data) {
//   global $mysqli;
//   global $onerror;
//   global $country_code;
//   include_once('language_message.php');
//   //include_once('site_config.php');
//   //print_r($data);
//   if(empty($data['type'])) {
//     $record=array('success'=>false, 'msg'=>$msgEmptyAll, 'data'=>array());
//     jsonSendEncode($record);
//   } else {
//     $type     = $data['type'];








//     $feed_id =decode($data['feed_id']);
//     $srno=1;
//     //for($i=0; $i<50; $i++){
//     if($type == 'all'){
//       $check_data=$mysqli->prepare("SELECT `feed_like_id`,  `user_id`, `createtime` FROM `feed_like_master` where delete_flag='0' and feed_id=$feed_id and status =1  order by feed_like_id desc");
//     } 
//     $check_data->execute();
//     $check_data->store_result();
//     $check_data_count=$check_data->num_rows;
//     if($check_data_count >0) {
//       $check_data->bind_result($feed_like_id,$user_id,$createtime);
//       while($check_data->fetch()){
//         $createtime=date('d-m-Y h:i A',strtotime($createtime));


//         //$countrycode = getCountryCode($country_id);
//         //$user_id = encode($user_id);

//         $userData =getUserDetails($user_id);
//         $userName=$userData['name'];
//         $userEmail=$userData['email'];
//         $userImage=$userData['image'];

//            $image_html = '<img  width="50px" src="../webservice/images/'.$userImage.'" class="rounded-circle circle-border m-b-md img-fix img-responsive" name="profile_image" id="previewholder" style="width: 70px; height: 70px;" alt="" onerror="this.src='.$onerror.';" >';






//         $feed_arr[] = array('srno'=>$srno, 'feed_like_id'=>$feed_like_id,'userName'=>$userName,'userEmail'=>$userEmail,  'createtime'=>$createtime,'image_html'=>$image_html);
//         $srno++;
//       }
//     }
//     if(empty($feed_arr)){
//       $feed_arr = array();
//     }
//     $record=array('success'=>true, 'msg'=>$msgDataFound, 'data'=>array('feed_arr'=>$feed_arr));
//     jsonSendEncode($record);
//   }
// }





  













// echo "("INSERT INTO `artist_master`(`artist_id`, `event_id`, `artist_name`, `artist_image`, `delete_flag`, `active_flag`) VALUES ('2','2','arijit','asdd','0','0')")";











//for user start

//for user end






function getTicketsData($data)
{
  global $mysqli;
  global $onerror;
  global $country_code;
  include_once('language_message.php');
  //include_once('site_config.php');
  // print_r($data);
  if (empty($data['type'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $type     = $data['type'];
    $srno = 1;
    //for($i=0; $i<50; $i++){
    if ($type == 'all') {
      $check_data = $mysqli->prepare("SELECT `booking_id`, `event_id`, `ticket_nos`, `number_of_kids`, `number_of_adults`, `transaction_id`, `payment_status`, `user_id`, `booking_status`, `ticket_code`, `qr_image`, `booking_number`,`address`, `active_flag`, `createtime` FROM `booking_master`where delete_flag='0'  order by booking_id desc");
    }
    // $check_data->bind_param("i",$event_id);
    $check_data->execute();
    $check_data->store_result();
    $check_data_count = $check_data->num_rows;
    if ($check_data_count > 0) {
      $check_data->bind_result($booking_id, $event_id, $ticket_nos, $number_of_kids, $number_of_adults, $transaction_id, $payment_status, $user_id, $booking_status, $ticket_code, $qr_image, $booking_number, $address, $active_flag, $createtime);
      while ($check_data->fetch()) {
        $createtime = date('d-m-Y h:i A', strtotime($createtime));

        if ($booking_status == '1') {
          $booking_status_text = '1';
          $booking_status_html = '<label class="btn btn-success btn-sm">Confirmed</label>';
        } else {
          $booking_status_text = '2';
          $booking_status_html = '<label class="btn btn-danger btn-sm">Not-Confirmed</label>';
        }
        // $CatName = getCategoryName($category_id);
        // $eventcategory = getCategoryNameForEvents($event_id);
        // $category_name=$eventcategory['category_name'];


        $event_name = getEventNameforview($event_id);


        $username = getUserDetails($user_id);
        if ($username != "NA") {
          $customer_name = $username['name'];
        }
        // $image_html = '<img  width="50px" src="../webservice/images/'.$eventcategory.'" class="rounded-circle circle-border m-b-md img-fix img-responsive" name="profile_image" id="previewholder" style="width: 70px; height: 70px;" alt="" onerror="this.src='.$onerror.';" >';






        $action_html = '

        <div class="btn-group">

                                                    <button type="button" class="btn btn-primary btn-outline dropdown-toggle float-button-light" id="primary-dropdown-outline" data-bs-toggle="dropdown" aria-expanded="false">

                                                        Action

                                                    </button>

                                                    <ul class="dropdown-menu dropdown-menu-primary" style=" margin: 2px -56px 0;" aria-labelledby="primary-dropdown" role="menu">

                                                        <li><a href="view_tickets.php?id=' . encode($booking_id) . '"" class="dropdown-item"><i class="fa fa-eye"></i>    &nbspView</a></li> 

                                                    </ul>

                                                </div>




      
';
        $service_arr[] = array('srno' => $srno, 'booking_id' => $booking_id, 'ticket_nos' => $ticket_nos, 'number_of_kids' => $number_of_kids, 'number_of_adults' => $number_of_adults, 'transaction_id' => $transaction_id, 'action' => $action_html, 'createtime' => $createtime, 'user_id' => $customer_name, 'booking_status' => $booking_status_html, 'ticket_code' => '#' . $ticket_code, 'booking_number' => $booking_number, 'event_name' => $event_name, 'address' => $address);
        $srno++;
      }
    }
    if (empty($service_arr)) {
      $service_arr = array();
    }
    $record = array('success' => true, 'msg' => $msgDataFound, 'data' => array('service_arr' => $service_arr));
    jsonSendEncode($record);
  }
}


// tickets for user start

function getTicketsDataUser($data)
{
  global $mysqli;
  global $onerror;
  global $country_code;
  include_once('language_message.php');
  //include_once('site_config.php');
  // print_r($data);
  if (empty($data['type'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $type     = $data['type'];
    $user_id     = decode($data['user_id']);



    $srno = 1;
    //for($i=0; $i<50; $i++){
    if ($type == 'all') {

      // echo "SELECT `booking_id`, `event_id`, `ticket_nos`, `number_of_kids`, `number_of_adults`, `transaction_id`, `payment_status`, `user_id`, `booking_status`, `ticket_code`, `qr_image`, `booking_number`,`address`, `active_flag`, `createtime` FROM `booking_master`where delete_flag='0' and user_id=$user_id  order by booking_id desc";die;


      $check_data = $mysqli->prepare("SELECT `booking_id`, `event_id`, `ticket_nos`, `number_of_kids`, `number_of_adults`, `transaction_id`, `payment_status`, `user_id`, `booking_status`, `ticket_code`, `qr_image`, `booking_number`,`address`, `active_flag`, `createtime` FROM `booking_master`where delete_flag='0' and user_id=?  order by booking_id desc");
    }
    $check_data->bind_param("i", $user_id);
    $check_data->execute();
    $check_data->store_result();
    $check_data_count = $check_data->num_rows;
    if ($check_data_count > 0) {
      $check_data->bind_result($booking_id, $event_id, $ticket_nos, $number_of_kids, $number_of_adults, $transaction_id, $payment_status, $user_id, $booking_status, $ticket_code, $qr_image, $booking_number, $address, $active_flag, $createtime);
      while ($check_data->fetch()) {
        $createtime = date('d-m-Y h:i A', strtotime($createtime));

        if ($booking_status == '1') {
          $booking_status_text = '1';
          $booking_status_html = '<label class="btn btn-success btn-sm">Confirmed</label>';
        } else {
          $booking_status_text = '2';
          $booking_status_html = '<label class="btn btn-danger btn-sm">Not-Confirmed</label>';
        }
        // $CatName = getCategoryName($category_id);
        $eventname = geteventName($event_id);

        $username = getUserDetails($user_id);
        $customer_name = $username['name'];
        // $image_html = '<img  width="50px" src="../webservice/images/'.$eventcategory.'" class="rounded-circle circle-border m-b-md img-fix img-responsive" name="profile_image" id="previewholder" style="width: 70px; height: 70px;" alt="" onerror="this.src='.$onerror.';" >';






        $action_html = '

        <div class="btn-group">

                                                    <button type="button" class="btn btn-primary btn-outline dropdown-toggle float-button-light" id="primary-dropdown-outline" data-bs-toggle="dropdown" aria-expanded="false">

                                                        Action

                                                    </button>

                                                    <ul class="dropdown-menu dropdown-menu-primary" style=" margin: 2px -56px 0;" aria-labelledby="primary-dropdown" role="menu">

                                                        <li><a href="view_tickets.php?id=' . encode($booking_id) . '"" class="dropdown-item"><i class="fa fa-eye"></i>    &nbspView</a></li> 

                                                    </ul>

                                                </div>




      
';
        $service_arr[] = array('srno' => $srno, 'booking_id' => $booking_id, 'ticket_nos' => $ticket_nos, 'number_of_kids' => $number_of_kids, 'number_of_adults' => $number_of_adults, 'transaction_id' => $transaction_id, 'action' => $action_html, 'createtime' => $createtime, 'user_id' => $customer_name, 'booking_status' => $booking_status_html, 'ticket_code' => '#' . $ticket_code, 'booking_number' => $booking_number, 'event_name' => $eventname, 'address' => $address);
        $srno++;
      }
    }
    if (empty($service_arr)) {
      $service_arr = array();
    }
    $record = array('success' => true, 'msg' => $msgDataFound, 'data' => array('service_arr' => $service_arr));
    jsonSendEncode($record);
  }
}


// tickets for user end






function getTicketsDataByEvents($data)
{
  global $mysqli;
  global $onerror;
  global $country_code;
  include_once('language_message.php');
  //include_once('site_config.php');
  // print_r($data);
  if (empty($data['type'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $type     = $data['type'];
    $event_id     = decode($data['event_id']);

    // print_r($event_id);die;
    $srno = 1;
    //for($i=0; $i<50; $i++){
    if ($type == 'all') {
      $check_data = $mysqli->prepare("SELECT `booking_id`, `event_id`, `ticket_nos`, `number_of_kids`, `number_of_adults`, `transaction_id`, `payment_status`, `user_id`, `booking_status`, `ticket_code`, `qr_image`, `booking_number`,`address`, `active_flag`, `createtime` FROM `booking_master`where delete_flag='0' and event_id=? ");
    }
    $check_data->bind_param("i", $event_id);
    $check_data->execute();
    $check_data->store_result();
    $check_data_count = $check_data->num_rows;
    if ($check_data_count > 0) {
      $check_data->bind_result($booking_id, $event_id, $ticket_nos, $number_of_kids, $number_of_adults, $transaction_id, $payment_status, $user_id, $booking_status, $ticket_code, $qr_image, $booking_number, $address, $active_flag, $createtime);
      while ($check_data->fetch()) {
        $createtime = date('d-m-Y h:i A', strtotime($createtime));

        if ($booking_status == '1') {
          $booking_status_text = '1';
          $booking_status_html = '<label class="btn btn-success btn-sm">Confirmed</label>';
        } else {
          $booking_status_text = '2';
          $booking_status_html = '<label class="btn btn-danger btn-sm">Not-Confirmed</label>';
        }
        // $CatName = getCategoryName($category_id);
        // $ticket=getTicketsData($event_id);
        // $eventcategory = getCategoryNameForEvents($event_id);
        // $category_name=$eventcategory['category_name'];
        $username = getUserDetails($user_id);
        $customer_name = $username['name'];

        $event_name = getEventNameforview($event_id);
        // $eve_name=$event_name['title'];
        // print_r($event_name);die;

        // $image_html = '<img  width="50px" src="../webservice/images/'.$eventcategory.'" class="rounded-circle circle-border m-b-md img-fix img-responsive" name="profile_image" id="previewholder" style="width: 70px; height: 70px;" alt="" onerror="this.src='.$onerror.';" >';






        $action_html = '

        <div class="btn-group">

                                                    <button type="button" class="btn btn-primary btn-outline dropdown-toggle float-button-light" id="primary-dropdown-outline" data-bs-toggle="dropdown" aria-expanded="false">

                                                        Action

                                                    </button>

                                                    <ul class="dropdown-menu dropdown-menu-primary" style=" margin: 2px -56px 0;" aria-labelledby="primary-dropdown" role="menu">

                                                        <li><a href="view_tickets.php?id=' . encode($booking_id) . '"" class="dropdown-item"><i class="fa fa-eye">   </i>       &nbspView</a></li> 

                                                    </ul>

                                                </div>




      
';
        $service_arr[] = array('srno' => $srno, 'booking_id' => $booking_id, 'ticket_nos' => $ticket_nos, 'number_of_kids' => $number_of_kids, 'number_of_adults' => $number_of_adults, 'transaction_id' => $transaction_id, 'action' => $action_html, 'createtime' => $createtime, 'user_id' => $customer_name, 'booking_status' => $booking_status_html, 'ticket_code' => '#' . $ticket_code, 'booking_number' => $booking_number, 'event_name' => $event_name, 'address' => $address);
        $srno++;
      }
    }
    if (empty($service_arr)) {
      $service_arr = array();
    }
    $record = array('success' => true, 'msg' => $msgDataFound, 'data' => array('service_arr' => $service_arr));
    jsonSendEncode($record);
  }
}


function  editService($data)
{

  //echo "<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  include_once('site_config.php');
  include_once('mailFunctions.php');
  if (empty($_POST['sname'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  }


  $service_id = decode($data['service_id']);
  $sname = trim($data['sname']);
  $semail = $data['semail'];
  $ditems = trim($data['ditems']);
  $mnum = $data['mnum'];
  $selectname = $data['selectname'];
  $address = $data['address'];
  $latitude = $data['latitude'];
  $longitude = $data['longitude'];
  $website_url = $data['url'];

  if (empty($mnum)) {
    $mnum = 'NA';
  } else {
    $mnum = $data['mnum'];
  }



  $check_email_mobile = $mysqli->prepare("SELECT service_image from service_master where delete_flag=0 and service_id=?");
  $check_email_mobile->bind_param("i", $service_id);
  $check_email_mobile->execute();
  $check_email_mobile->store_result();
  $check_email_mobile_count = $check_email_mobile->num_rows;
  if ($check_email_mobile_count <= 0) {
    $record = array('success' => false, 'msg' => $msgInvalidId, 'data' => array());
    jsonSendEncode($record);
  }
  $check_email_mobile->bind_result($image_get);
  $check_email_mobile->fetch();

  $image = '';
  if (!empty($_FILES['image']['name'])) {
    $file = $_FILES['image'];
    $folder_name = '../webservice/images';
    $file_type = 'image';
    $upload_status = uploadFile($file, $folder_name, $file_type);
    if ($upload_status == 'error') {
      $record = array('success' => 'false', 'msg' => $msgErrorFileUpload);
      jsonSendEncode($record);
    }
    $image = $upload_status;
  } else {
    $image = $image_get;
  }
  $updatetime     =   date('Y-m-d H:i:s');
  $update_all     =   $mysqli->prepare("UPDATE service_master SET service_category_id =?,service_name=?,service_description=?,service_location=?,website_url=?,latitude=?,longitude=?,service_image=?,service_email=?,service_phone_number=?, updatetime=? WHERE service_id=?");
  $update_all->bind_param('issssssssisi', $selectname, $sname, $ditems, $address, $website_url, $latitude, $longitude, $image, $semail, $mnum, $updatetime, $service_id);
  $update_all->execute();
  $update = $mysqli->affected_rows;
  if ($update <= 0) {
    $record =   array('success' => false, 'msg' => $msgserviceNotUpdate, 'data' => array());
    jsonSendEncode($record);
  }






  //-------------------------- check user email --------------------------








  $record = array('success' => true, 'msg' => $msgserviceUpdate, 'data' => array());
  jsonSendEncode($record);
}

function  editEbookEvent($data)
{

  //echo "<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  include_once('site_config.php');
  include_once('mailFunctions.php');
  if (empty($_POST['title'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  }


  $event_id = decode($data['id']);
  $title = $data['title'];
  $description = $data['description'];
  $recommend_status = $data['recommend_status'];

  $check_email_mobile = $mysqli->prepare("SELECT image from event_master where delete_flag=0 and event_id=?");
  $check_email_mobile->bind_param("i", $event_id);
  $check_email_mobile->execute();
  $check_email_mobile->store_result();
  $check_email_mobile_count = $check_email_mobile->num_rows;
  if ($check_email_mobile_count <= 0) {
    $record = array('success' => false, 'msg' => $msgInvalidId, 'data' => array());
    jsonSendEncode($record);
  }
  $check_email_mobile->bind_result($image_get);
  $check_email_mobile->fetch();

  $image = '';
  if (!empty($_FILES['image']['name'])) {
    $file = $_FILES['image'];
    $folder_name = '../webservice/images';
    $file_type = 'image';
    $upload_status = uploadFile($file, $folder_name, $file_type);
    if ($upload_status == 'error') {
      $record = array('success' => 'false', 'msg' => $msgErrorFileUpload);
      jsonSendEncode($record);
    }
    $image = $upload_status;
  } else {
    $image = $image_get;
  }
  $updatetime     =   date('Y-m-d H:i:s');
  $update_all     =   $mysqli->prepare("UPDATE event_master SET description =?,title=?,image=?, updatetime=?, recommend_status=? WHERE event_id=?");
  $update_all->bind_param('ssssii', $description, $title, $image, $updatetime, $recommend_status, $event_id);
  $update_all->execute();
  $update = $mysqli->affected_rows;
  if ($update <= 0) {
    $record =   array('success' => false, 'msg' => $msgEventNotUpdate, 'data' => array());
    jsonSendEncode($record);
  }

  $record = array('success' => true, 'msg' => $msgEventUpdate, 'data' => array());
  jsonSendEncode($record);
}


//Function Starts for edit ebook
function  editEbook($data)
{
  // echo "<pre>";print_r($data);exit();
  global $mysqli;
  include_once('language_message.php');
  include_once('site_config.php');
  include_once('mailFunctions.php');
  if (empty($_POST['title'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  }


  $ebook_id = decode($data['id']);
  // print_r($ebook_id);die;
  // $description = $data['description'];
  $title = $data['title'];
  $price = $data['price'];
  $descriptions = $data['description'];
  $recommend_status = $data['recommend_status'];

  $check_email_mobile = $mysqli->prepare("SELECT `ebook_id` FROM `ebook_master`WHERE  delete_flag='0'  and ebook_id=?");
  $check_email_mobile->bind_param("i", $ebook_id);
  $check_email_mobile->execute();
  $check_email_mobile->store_result();
  $check_email_mobile_count = $check_email_mobile->num_rows;
  if ($check_email_mobile_count <= 0) {
    $record = array('success' => false, 'msg' => $msgInvalidId, 'data' => array());
    jsonSendEncode($record);
  }
  $check_email_mobile->bind_result($ebook_id_get);
  $check_email_mobile->fetch();

  $updatetime     =   date('Y-m-d H:i:s');

  $check_email_mobile1 = $mysqli->prepare("SELECT `image`,pdf_url FROM `ebook_master`WHERE  delete_flag='0'  and ebook_id=?");
  $check_email_mobile1->bind_param("i", $ebook_id);
  $check_email_mobile1->execute();
  $check_email_mobile1->store_result();
  $check_email_mobile_count1 = $check_email_mobile1->num_rows;
  if ($check_email_mobile_count1 <= 0) {
    $record = array('success' => false, 'msg' => $msgInvalidId, 'data' => array());
    jsonSendEncode($record);
  }
  $check_email_mobile1->bind_result($image_get,$pdf_url_get);
  $check_email_mobile1->fetch();

  $updatetime     =   date('Y-m-d H:i:s');



  if (!empty($_FILES['image']['name'])) {
    $user_image = $_FILES['image'];
    // Code to upload the file starts
    $file = $user_image;
    $folder_name = '../webservice/images';
    $file_type = 'image';
    $upload_status = uploadFile($file, $folder_name, $file_type);
    if ($upload_status == 'error') {
      $record = array('success' => false, 'msg' => $msgErrorFileUpload, 'data' => array());
      jsonSendEncode($record);
    }
    $image = $upload_status;
    // Code to upload the file starts
  } else {
    $image =  $image_get;
  }

  if (!empty($_FILES['pdf_url']['name'])) {
    $user_image = $_FILES['pdf_url'];
    // Code to upload the file starts
    $file = $user_image;
    $folder_name = '../webservice/pdf_file';
    $file_type = 'pdf';
    $upload_status = uploadFile($file, $folder_name, $file_type);
    if ($upload_status == 'error') {
      $record = array('success' => false, 'msg' => $msgErrorFileUpload, 'data' => array());
      jsonSendEncode($record);
    }
    $pdf_url = $upload_status;
    // Code to upload the file starts
  } else {
    $pdf_url =  $pdf_url_get;
  }

  $update_all     =   $mysqli->prepare("UPDATE ebook_master SET title=?,price=?,descriptions=?,updatetime=?,pdf_url=?,image=?,recommend_status=? WHERE ebook_id=?");
  $update_all->bind_param('ssssssii', $title, $price, $descriptions, $updatetime, $pdf_url, $image,$recommend_status, $ebook_id);
  $update_all->execute();
  $update = $mysqli->affected_rows;


  if ($update <= 0) {
    $record =   array('success' => false, 'msg' => $msgebookNotUpdate, 'data' => array());
    jsonSendEncode($record);
  }


  $record = array('success' => true, 'msg' => $msgebookUpdate, 'data' => array());
  jsonSendEncode($record);
}
//Function end for edit ebook

//Function Starts for edit education
function  editEducation($data)
{
  // echo "<pre>";print_r($data);exit();
  global $mysqli;
  include_once('language_message.php');
  include_once('site_config.php');
  include_once('mailFunctions.php');
  if (empty($_POST['name'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  }


  $education_id = decode($data['id']);
  // print_r($education_id);die;

  $name = $data['name'];

  $check_email_mobile = $mysqli->prepare("SELECT `education_id` FROM `education_master`WHERE  delete_flag='0'  and education_id=?");
  $check_email_mobile->bind_param("i", $education_id);
  $check_email_mobile->execute();
  $check_email_mobile->store_result();
  $check_email_mobile_count = $check_email_mobile->num_rows;
  if ($check_email_mobile_count <= 0) {
    $record = array('success' => false, 'msg' => $msgInvalidId, 'data' => array());
    jsonSendEncode($record);
  }
  $check_email_mobile->bind_result($education_id_get);
  $check_email_mobile->fetch();

  $updatetime     =   date('Y-m-d H:i:s');

  $update_all     =   $mysqli->prepare("UPDATE education_master SET name=?,updatetime=? WHERE education_id=?");
  $update_all->bind_param('ssi', $name, $updatetime, $education_id);
  $update_all->execute();
  $update = $mysqli->affected_rows;


  if ($update <= 0) {
    $record =   array('success' => false, 'msg' => $msgEducationNotUpdate, 'data' => array());
    jsonSendEncode($record);
  }


  $record = array('success' => true, 'msg' => $msgEducationUpdate, 'data' => array());
  jsonSendEncode($record);
}
//Function end for edit education

//Function Starts for edit ebook training
function  editEbookTraining($data)
{
  // echo "<pre>";print_r($data);exit();
  global $mysqli;
  include_once('language_message.php');
  include_once('site_config.php');
  include_once('mailFunctions.php');
  if (empty($_POST['description'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  }


  $ebook_training_id = decode($data['id']);
  // print_r($ebook_id);die;
  $ebook_id = $data['ebook_id'];  
  $title = $data['title'];  
  $rules = $data['rules'];  
  $description = $data['description'];
  $training_type = $data['training_type'];
  if ($training_type==1) {
    $ebook_id = $data['ebook_id'];
  }else{
    $ebook_id=0;
  }
    $recommend_status = $data['recommend_status'];
  $exercise_training_type = $data['exercise_training_type'];
  // print_r($exercise_training_type);die;
  $max_no_of_player = $data['max_no_of_player'];
  $min_no_of_player = $data['min_no_of_player'];
  $focus = $data['focus'];
  $matchfield = $data['matchfield'];
  $tactical = $data['tactical'];
  $informational = $data['informational'];
  $conditional = $data['conditional'];
  $selller_type = $data['selller_type'];

  $exercise_type = $data['exercise_type'];

  $updatetime     =   date('Y-m-d H:i:s');

  $check_email_mobile1 = $mysqli->prepare("SELECT `image`,exercise_image FROM `ebook_training_master`WHERE  delete_flag='0'  and ebook_training_id=?");
  $check_email_mobile1->bind_param("i", $ebook_training_id);
  $check_email_mobile1->execute();
  $check_email_mobile1->store_result();
  $check_email_mobile_count1 = $check_email_mobile1->num_rows;
  if ($check_email_mobile_count1 <= 0) {
    $record = array('success' => false, 'msg' => $msgInvalidId, 'data' => array());
    jsonSendEncode($record);
  }
  $check_email_mobile1->bind_result($image_get,$exercise_image_get);
  $check_email_mobile1->fetch();

  $updatetime     =   date('Y-m-d H:i:s');



  if (!empty($_FILES['image']['name'])) {
    $user_image = $_FILES['image'];
    // Code to upload the file starts
    $file = $user_image;
    $folder_name = '../webservice/images';
    $file_type = 'image';
    $upload_status = uploadFile($file, $folder_name, $file_type);
    if ($upload_status == 'error') {
      $record = array('success' => false, 'msg' => $msgErrorFileUpload, 'data' => array());
      jsonSendEncode($record);
    }
    $image = $upload_status;
    // Code to upload the file starts
  } else {
    $image =  $image_get;
  }

    if (!empty($_FILES['exercise_image']['name'])) {
    $user_image = $_FILES['exercise_image'];
    // Code to upload the file starts
    $file = $user_image;
    $folder_name = '../webservice/images';
    $file_type = 'exercise_image';
    $upload_status = uploadFile($file, $folder_name, $file_type);
    if ($upload_status == 'error') {
      $record = array('success' => false, 'msg' => $msgErrorFileUpload, 'data' => array());
      jsonSendEncode($record);
    }
    $exercise_image = $upload_status;
    // Code to upload the file starts
  } else {
    $exercise_image =  $exercise_image_get;
  }

// echo "UPDATE ebook_training_master SET ebook_id=$ebook_id,description=$description,training_type=$training_type,updatetime=$updatetime,image=$image, recommend_status=$recommend_status, exercise_training_type=$exercise_training_type, max_no_of_player=$max_no_of_player, min_no_of_player=$min_no_of_player,focus=$focus,matchfield=$matchfield,tactical=$tactical,informational=$informational,conditional=$conditional,exercise_image=$exercise_image,selller_type=$selller_type WHERE ebook_training_id=$ebook_training_id";die;

  $update_all     =   $mysqli->prepare("UPDATE ebook_training_master SET ebook_id=?,training_type=?,description=?,image=?,updatetime=?,recommend_status=?,exercise_training_type=?,max_no_of_player=?,min_no_of_player=?,selller_type=?,tactical=?,informational=?,conditional=?,exercise_image=?,focus=?,matchfield=?,exercise_type=?,title=?,rules=? WHERE ebook_training_id=?");
  $update_all->bind_param('issssssssssssssssssi', $ebook_id, $training_type, $description, $image, $updatetime, $recommend_status, $exercise_training_type, $max_no_of_player, $min_no_of_player, $selller_type, $tactical, $informational, $conditional, $exercise_image, $focus, $matchfield, $exercise_type, $title, $rules, $ebook_training_id);
  $update_all->execute();
  $update = $mysqli->affected_rows;


  if ($update <= 0) {
    $record =   array('success' => false, 'msg' => $msgebookTrainingNotUpdate, 'data' => array());
    jsonSendEncode($record);
  }


  $record = array('success' => true, 'msg' => $msgebookTrainingUpdate, 'data' => array());
  jsonSendEncode($record);
}
//Function end for edit ebook training

//Function Starts for edit ebook training
function  editEbookVideo($data)
{
  // echo "<pre>";print_r($data);exit();
  global $mysqli;
  include_once('language_message.php');
  include_once('site_config.php');
  include_once('mailFunctions.php');
  if (empty($_POST['title'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  }


  $ebook_video_id = decode($data['id']);
  // print_r($ebook_id);die;
  // $ebook_id = $data['ebook_id'];  
  $video_type = $data['video_type'];
  // print_r($video_type);die;

    if ($video_type==1) {
    $ebook_id = $data['ebook_id'];
  }else{
    $ebook_id=0;
  }
  $title = $data['title'];

  $updatetime     =   date('Y-m-d H:i:s');

  $check_email_mobile1 = $mysqli->prepare("SELECT `image`,video_url FROM `ebook_video_master`WHERE  delete_flag='0'  and ebook_video_id=?");
  $check_email_mobile1->bind_param("i", $ebook_video_id);
  $check_email_mobile1->execute();
  $check_email_mobile1->store_result();
  $check_email_mobile_count1 = $check_email_mobile1->num_rows;
  if ($check_email_mobile_count1 <= 0) {
    $record = array('success' => false, 'msg' => $msgInvalidId, 'data' => array());
    jsonSendEncode($record);
  }
  $check_email_mobile1->bind_result($image_get,$video_url_get);
  $check_email_mobile1->fetch();

  $updatetime     =   date('Y-m-d H:i:s');



  if (!empty($_FILES['image']['name'])) {
    $user_image = $_FILES['image'];
    // Code to upload the file starts
    $file = $user_image;
    $folder_name = '../webservice/images';
    $file_type = 'image';
    $upload_status = uploadFile($file, $folder_name, $file_type);
    if ($upload_status == 'error') {
      $record = array('success' => false, 'msg' => $msgErrorFileUpload, 'data' => array());
      jsonSendEncode($record);
    }
    $image = $upload_status;
    // Code to upload the file starts
  } else {
    $image =  $image_get;
  }

      if(!empty($_FILES['video']['name'])){
            $user_image = $_FILES['video'];
            // Code to upload the file starts
            $file=$user_image;
            $folder_name='../webservice/videos/';
            $file_type='video';
            $upload_status=uploadFile($file, $folder_name, $file_type);
            if($upload_status == 'error') {
            $record=array('success'=>false, 'msg' =>$msgErrorFileUpload, 'data'=>array());
            jsonSendEncode($record);
            }
            $video_url = $upload_status;
            // Code to upload the file starts
          } else {
             $video_url =  $video_url_get;
          }

// print_r($video);die;




  $update_all     =   $mysqli->prepare("UPDATE ebook_video_master SET ebook_id=?,video_type=?,video_url=?,title=?,image=?,updatetime=? WHERE ebook_video_id=?");
  $update_all->bind_param('ssssssi', $ebook_id, $video_type, $video_url, $title, $image, $updatetime, $ebook_video_id);
  $update_all->execute();
  $update = $mysqli->affected_rows;


  if ($update <= 0) {
    $record =   array('success' => false, 'msg' => $msgebookVideoNotUpdate, 'data' => array());
    jsonSendEncode($record);
  }


  $record = array('success' => true, 'msg' => $msgebookVideoUpdate, 'data' => array());
  jsonSendEncode($record);
}
//Function end for edit ebook training


function  editEvents($data)
{

  // echo "<pre>";print_r($data);exit();
  global $mysqli;
  include_once('language_message.php');
  include_once('site_config.php');
  include_once('mailFunctions.php');
  if (empty($_POST['service_name'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  }



  $event_id = decode($data['event_id']);
  $event_date_time = $data['event_date_time'];
  $event_end_datetime = $data['event_end_datetime'];
  $event_ticket_price = $data['event_ticket_price'];
  $total_tickets = $data['total_tickets'];
  $description = $data['description'];
  $title = $data['service_name'];
  $landmark = $data['landmark'];
  $selectname = $data['selectname'];
  $address = $data['service_location'];
  $terms_and_conditions = $data['TandC'];
  $note = $data['note'];
  //print_r($address);die;
  $latitude = $data['latitude'];
  $longitude = $data['longitude'];




  // if(empty($mnum)){
  //  $mnum ='NA';
  // }else{
  //   $mnum=$data['mnum'];
  // }



  $check_email_mobile = $mysqli->prepare("SELECT `event_id` FROM `event_master`WHERE  delete_flag='0'  and event_id=?");
  $check_email_mobile->bind_param("i", $event_id);
  $check_email_mobile->execute();
  $check_email_mobile->store_result();
  $check_email_mobile_count = $check_email_mobile->num_rows;
  if ($check_email_mobile_count <= 0) {
    $record = array('success' => false, 'msg' => $msgInvalidId, 'data' => array());
    jsonSendEncode($record);
  }
  $check_email_mobile->bind_result($event_id_get);
  $check_email_mobile->fetch();

  $updatetime     =   date('Y-m-d H:i:s');







  $check_email_mobile1 = $mysqli->prepare("SELECT `image` FROM `event_image_master`WHERE  delete_flag='0'  and event_id=?");
  $check_email_mobile1->bind_param("i", $event_id);
  $check_email_mobile1->execute();
  $check_email_mobile1->store_result();
  $check_email_mobile_count1 = $check_email_mobile1->num_rows;
  if ($check_email_mobile_count1 <= 0) {
    $record = array('success' => false, 'msg' => $msgInvalidId, 'data' => array());
    jsonSendEncode($record);
  }
  $check_email_mobile1->bind_result($image_get);
  $check_email_mobile1->fetch();

  $updatetime     =   date('Y-m-d H:i:s');



  if (!empty($_FILES['image']['name'])) {
    $user_image = $_FILES['image'];
    // Code to upload the file starts
    $file = $user_image;
    $folder_name = '../webservice/images';
    $file_type = 'image';
    $upload_status = uploadFile($file, $folder_name, $file_type);
    if ($upload_status == 'error') {
      $record = array('success' => false, 'msg' => $msgErrorFileUpload, 'data' => array());
      jsonSendEncode($record);
    }
    $image = $upload_status;
    // Code to upload the file starts
  } else {
    $image =  $image_get;
  }




  $update_event_image     =   $mysqli->prepare("UPDATE event_image_master SET  image=?,updatetime=? WHERE event_id=?");
  $update_event_image->bind_param('ssi', $image, $updatetime, $event_id);
  $update_event_image->execute();
  $update_image = $mysqli->affected_rows;




  //        echo    "UPDATE event_master SET category_id='37',event_date_time='2022-09-03 17:55:00',address='pune',latitude='22.719567',longitude='75.8577255',event_ticket_price='600',total_tickets='668',title='hello',description='myname12323434',updatetime='2022-09-03 18:13:54'
  // WHERE event_id='7'";exit();
  $update_all     =   $mysqli->prepare("UPDATE event_master SET category_id=?,event_date_time=?,address=?,latitude=?,longitude=?,event_ticket_price=?,total_tickets=?,title=?,description=?, terms_and_conditions=?, note=?,updatetime=?,landmark=?,event_end_datetime=? WHERE event_id=?");
  $update_all->bind_param('isssssssssssssi', $selectname, $event_date_time, $address, $latitude, $longitude, $event_ticket_price, $total_tickets, $title, $description, $terms_and_conditions, $note, $updatetime, $landmark, $event_end_datetime, $event_id);
  $update_all->execute();
  $update = $mysqli->affected_rows;




  $artist_name_arr = $data['artist_name'];
  if (!empty($artist_name_arr)) {
    $len = count($artist_name_arr);

    if ($len > 0) {

      if (!empty($_FILES['artist_image']['name'][0])) {
        $user_image = $_FILES['artist_image'];
        // Code to upload the file starts
        $file = $user_image;
        $folder_name = '../webservice/images';
        $file_type = 'image';
        $upload_status = uploadFileMultiple($file, $folder_name, $file_type);
        // print_r($upload_status);
        // die;
        if ($upload_status == 'error') {
          $record = array('success' => false, 'msg' => $msgErrorFileUpload, 'data' => array());
          jsonSendEncode($record);
        }
        $image_arr = $upload_status;
      }
      for ($i = 0; $i < $len; $i++) {
        $artist_name = $artist_name_arr[$i];
        $artist_image = $image_arr[$i];


        $result = $mysqli->prepare("INSERT INTO `artist_master`(`event_id`, `artist_name`, `artist_image`, `createtime`, `updatetime`) VALUES (?,?,?,?,?)");
        $result->bind_param('issss', $event_id, $artist_name, $artist_image, $createtime, $updatetime);
        $result->execute();
        $row = $mysqli->affected_rows;
      }
    }
  }


  if ($update <= 0) {
    $record =   array('success' => false, 'msg' => $msgeventNotUpdate, 'data' => array());
    jsonSendEncode($record);
  }


  $record = array('success' => true, 'msg' => $msgeventUpdate, 'data' => array());
  jsonSendEncode($record);
}
function deleteEvents($data)
{

  //echo"<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  if (empty($data['event_id'])) {
    $record =   array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $event_id    = $data['event_id'];
    $check_user_id = $mysqli->prepare("SELECT event_id from event_master where delete_flag='0' and event_id=?");
    $check_user_id->bind_param("i", $event_id);
    $check_user_id->execute();
    $check_user_id->store_result();
    $check_user_id_count = $check_user_id->num_rows;
    if ($check_user_id_count <= 0) {
      $record = array('success' => false, 'msg' => $msgeventNotExist, 'data' => array());
      jsonSendEncode($record);
    }
    $delete_flag    =   1;
    $updatetime     =   date('Y-m-d H:i:s');
    // Delete Query
    $update_all     =   $mysqli->prepare("UPDATE event_master set delete_flag=?, updatetime=? WHERE event_id=?");
    $update_all->bind_param("isi", $delete_flag, $updatetime, $event_id);
    $update_all->execute();
    $update         =   $mysqli->affected_rows;
    if ($update <= 0) {
      $record     =   array('success' => false, 'msg' => $geteventDeleteError, 'data' => array());
      jsonSendEncode($record);
    }
    $record         =   array('success' => true, 'msg' => $geteventDelete, 'data' => array());
    jsonSendEncode($record);
  }
}


function deleteArtistsDetails($data)
{

  //echo"<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  if (empty($data['id'])) {
    $record =   array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $artist_id    = $data['id'];
    $check_user_id = $mysqli->prepare("SELECT artist_id from artist_master where delete_flag='0' and artist_id=?");
    $check_user_id->bind_param("i", $artist_id);
    $check_user_id->execute();
    $check_user_id->store_result();
    $check_user_id_count = $check_user_id->num_rows;
    if ($check_user_id_count <= 0) {
      $record = array('success' => false, 'msg' => $msgeventNotExist, 'data' => array());
      jsonSendEncode($record);
    }
    $delete_flag    =   1;
    $updatetime     =   date('Y-m-d H:i:s');
    // Delete Query
    $update_all     =   $mysqli->prepare("UPDATE artist_master set delete_flag=?, updatetime=? WHERE artist_id=?");
    $update_all->bind_param("isi", $delete_flag, $updatetime, $artist_id);
    $update_all->execute();
    $update         =   $mysqli->affected_rows;
    if ($update <= 0) {
      $record     =   array('success' => false, 'msg' => $geteventDeleteError, 'data' => array());
      jsonSendEncode($record);
    }
    $record         =   array('success' => true, 'msg' => $geteventDelete, 'data' => array());
    jsonSendEncode($record);
  }
}


function ApproveStatus($data)
{
  global $mysqli;
  include_once('language_message.php');
  include('mailFunctions.php');
  include('site_config.php');
  //print_r($data);
  if (empty($data['user_id'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $user_id = decode($data['user_id']);
    // print_r($user_id);die;
    // echo'user_id='.$user_id;

    //$user_id = decode($user_id);
    $active_flag    = 1;
    $check_user_id = $mysqli->prepare("SELECT `approve_flag`,`user_id` FROM `business_master` where delete_flag='0' and business_id=? ");
    $check_user_id->bind_param("i", $user_id);
    $check_user_id->execute();
    $check_user_id->store_result();
    $check_user_id_count = $check_user_id->num_rows;
    if ($check_user_id_count <= 0) {
      $record = array('success' => false, 'msg' => $msgUserNotExist, 'data' => array());
      jsonSendEncode($record);
    }

    $check_user_id->bind_result($approve_flag, $user_id_get);
    $check_user_id->fetch();

    $userData = getUserDetails($user_id_get);
    $name = $userData['name'];
    $email = $userData['email'];
    // echo "$email";die;

    $active_flag_html = 'Your business has been Approve by admin.';

    $postData['fromName']       =   $appName;
    $postData['app_name']       =   $appName;
    $postData['app_logo']       =   $appLogo;
    $postData['app_bg']         =   'app_bg';
    $postData['name']           =   $name;
    $postData['email']          =   $email;
    $postData['mailContent']    = $active_flag_html;
    $postData['approve_flag']   =   $approve_flag;
    $subject =  "Account Info";
    $postData['mail_msg']     =   $subject;
    //$postData['Image']=$img_url_user_main.$image;
    $mailBody = mailBodyApprove($postData);
    $mailResponse = mailSend($postData['email'], $postData['fromName'], $subject, $mailBody);

    $updatetime = date('Y-m-d H:i:s');
    $update_all = $mysqli->prepare("UPDATE business_master set approve_flag=?, updatetime=? WHERE business_id=?");
    $update_all->bind_param("ssi", $active_flag, $updatetime, $user_id);
    $update_all->execute();
    //echo 'error='.mysqli_error($mysqli);
    $update = $mysqli->affected_rows;
    if ($update <= 0) {
      $record = array('success' => false, 'msg' => $msgDataNotUpdate, 'data' => array());
      jsonSendEncode($record);
    }
    //$user_id = encode($user_id);

    $user_id_notification = 1;
    $other_user_id_notification = $user_id_get;
    $action_id = $user_id;

    $action = 'approved';
    //$action_id = $product_name;
    $title   =  'Business Approved';
    $title_2 =  $title;
    $title_3 =  $title;
    $title_4 =  $title;
    $message   = 'Your business has been approved';
    $message_2 = $message;
    $message_3 = $message;
    $message_4 = $message;
    $action_data = array('user_id' => $user_id_notification, 'other_user_id' => $other_user_id_notification, 'action_id' => $action_id, 'action' => $action);
    // $action_json=json_encode($action_data);
    //set aray
    //print_r($action_data);
    $notification_arr_check = getNotificationArrSingle($user_id_notification, $other_user_id_notification, $action, $action_id, $title, $title_2, $title_3, $title_4, $message, $message_2, $message_3, $message_4, $action_data);
    if ($notification_arr_check != 'NA') {
      $notification_arr[] = $notification_arr_check;
    }





    $record = array('success' => true, 'msg' => $msgBusinessApporveSuccess, 'data' => array('notification_arr' => $notification_arr));
    jsonSendEncode($record);
  }
}








function getFriendList($data)
{
  global $mysqli;
  global $onerror;
  global $country_code;
  include_once('language_message.php');
  //include_once('site_config.php');
  //print_r($data);
  if (empty($data['type'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $type     = $data['type'];
    $srno = 1;
    $user_id = decode($data['user_id']);
    //for($i=0; $i<50; $i++){
    if ($type == 'all') {
      $check_data = $mysqli->prepare("SELECT `friend_id`, `user_id`, `other_user_id`, `status`, `createtime`FROM `friend_master` where delete_flag='0' and user_id=$user_id order by friend_id desc");
    }
    $check_data->execute();
    $check_data->store_result();
    $check_data_count = $check_data->num_rows;
    if ($check_data_count > 0) {
      $check_data->bind_result($friend_id, $user_id, $other_user_id, $status, $createtime);
      while ($check_data->fetch()) {
        $createtime = date('d-m-Y h:i A', strtotime($createtime));


        $userData = getUserDetails($other_user_id);
        $userName = $userData['name'];
        $userEmail = $userData['email'];
        $userimage = $userData['image'];

        if ($status == 0) {
          $status_text = '<label class="badge badge-warning">Pending</label>';
        } else  if ($status == 1) {
          $status_text = '<label class="badge badge-info">Requested</label>';
        } else  if ($status == 2) {
          $status_text = '<label class="badge badge-success">Accepted</label>';
        } else {
          $status_text = '<label class="badge badge-danger">Rejected</label>';
        }


        $image_html = '<img  width="50px" src="../webservice/images/' . $userimage . '" class="rounded-circle circle-border m-b-md img-fix img-responsive" name="profile_image" id="previewholder" style="width: 70px; height: 70px;" alt="" onerror="this.src=' . $onerror . ';" >';






        $action_html = '

        <div class="btn-group">

                                                    <button type="button" class="btn btn-primary btn-outline dropdown-toggle float-button-light" id="primary-dropdown-outline" data-bs-toggle="dropdown" aria-expanded="false">

                                                        Action

                                                    </button>

                                                    <ul class="dropdown-menu dropdown-menu-primary" style=" margin: 2px -56px 0;" aria-labelledby="primary-dropdown" role="menu">

                                                        <li><a href="view_worker.php?id=' . encode($other_user_id) . '"" class="dropdown-item"><i class="fa fa-eye"></i>View</a></li>

                          
                                                   


                                                        

                                                    </ul>

                                                </div>




      
';
        $service_arr[] = array('srno' => $srno, 'friend_id' => $friend_id, 'userName' => $userName, 'userEmail' => $userEmail, 'action' => $action_html, 'createtime' => $createtime, 'image' => $image_html, 'status' => $status_text);
        $srno++;
      }
    }
    if (empty($service_arr)) {
      $service_arr = array();
    }
    $record = array('success' => true, 'msg' => $msgDataFound, 'data' => array('service_arr' => $service_arr));
    jsonSendEncode($record);
  }
}




function InnoceneCheckemail($data)
{
  global $mysqli;
  include_once('language_message.php');
  //print_r($data);
  if (empty($data['email'])) {
    echo 'false';
  } else {
    $name      = $data['email'];

    //$category_id        = decode($data['id']);
    //-------------------------- check user email --------------------------
    $check_category = $mysqli->prepare("SELECT innocence_id from innocence_master where delete_flag='0' and email=?");
    $check_category->bind_param("s", $name);
    $check_category->execute();
    $check_category->store_result();
    $check_category_count = $check_category->num_rows;
    if ($check_category_count > 0) {
      echo 'false';
    } else {
      echo "true";
    }
  }
}


function InnocenceCheckEditemail($data)
{
  global $mysqli;
  include_once('language_message.php');
  //'print_r($data);
  if (empty($data['email'])) {
    echo 'false';
  } else {
    $category      = $data['email'];

    $city_id  = $data['id'];
    //-------------------------- check user email --------------------------
    $check_channel = $mysqli->prepare("SELECT innocence_id from innocence_master where delete_flag='0' and email= ? and innocence_id != ?  ");
    $check_channel->bind_param("si", $category, $city_id);
    $check_channel->execute();
    $check_channel->store_result();
    $check_channel_count = $check_channel->num_rows;
    if ($check_channel_count > 0) {
      echo 'false';
    } else {
      echo "true";
    }
  }
}


function getFeedBuisnessPhotosOnly($data)
{
  global $mysqli;
  global $onerror;
  global $country_code;
  include_once('language_message.php');
  //include_once('site_config.php');
  // print_r($data);
  // exit();
  if (empty($data['type'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $type     = $data['type'];
    $business_id     = decode($data['business_id']);
    $srno = 1;

    $check_data = $mysqli->prepare("SELECT post_id,description from post_master where business_id = ?");
  }
  $check_data->bind_param("i", $business_id);
  $check_data->execute();
  $check_data->store_result();
  $check_data_count = $check_data->num_rows;
  if ($check_data_count > 0) {
    $check_data->bind_result($post_id, $description);
    while ($check_data->fetch()) {
      $check_data = $mysqli->prepare("SELECT `pv_id`, `path`, `type`, `thumbnail`, `createtime`, `updatetime` FROM `post_photo_video_master`  where delete_flag='0' and post_id=?  order by pv_id desc");
      $check_data->bind_param("i", $post_id);
      $check_data->execute();
      $check_data->store_result();
      $check_data_count = $check_data->num_rows;
      if ($check_data_count > 0) {
        $check_data->bind_result($pv_id, $path, $type, $thumbnail, $createtime, $updatetime);
        while ($check_data->fetch()) {
          $createtime = date('d-m-Y h:i A', strtotime($createtime));

          if ($type == 0) {
            $status = "'img'";
            $image_html = '<div href="#img_view" style="text-align: center;">
                      <a href="#img_view">
                      <img  width="50px" src="../webservice/images/' . $path . '" class="rounded-circle circle-border m-b-md img-fix img-responsive" name="profile_image" id="previewholder" style="width: 70px; height: 70px;" onerror="this.src=' . $onerror . ';"alt=""  onclick="view_img(this,' . $status . ')">
                             <div class="open_my_popup" id="img_view">
                            <div class="imgae_view_bg"></div>
                            <div class="view_popup"> <img src="" id="image_here" class="image_here" /> </div>
                             <a class="close_my_popup" onclick="closePopup();"><img src="assets/images/close.png" /></a></div>
                             </a>
                         </div>';
          } else {

            $status = "'video'";
            $image_html = '<div href="#video_view" style="text-align: center;">
                      <a href="#video_view">
  
  
                              <video width="50px"  height="50px" class=" circle-border m-b-md img-fix img-responsive" name="profile_image" id="previewholder" style="width: 70px; height: 70px;" onerror="this.src=' . $onerror . ';"alt=""  onclick="view_img(this,' . $status . ')" controls>
                                <source src="../webservice/videos/' . $path . '" type="video/mp4">
                                
                                
                              </video>
  
                             <div class="open_my_popup" id="video_view">
                            <div class="imgae_view_bg"></div>
                            <div class="view_popup"> <img src="" id="image_here" class="image_here" /> </div>
                             <a class="close_my_popup" onclick="closePopup();"><img src="assets/images/close.png" /></a></div>
                             </a>
                         </div>';
          }
        }
        $business_photo_arr[] = array('srno' => $srno, 'post_id' => $post_id, 'description' => $description, 'image' => $image_html, 'business_id' => $business_id, 'createtime' => $createtime, 'updatetime' => $updatetime);
        $srno++;
      }
    }
    // print_r($photo_arr);die;
    if (empty($business_photo_arr)) {
      $business_photo_arr = 'NA';
    }
    $record = array('success' => true, 'msg' => $msgDataFound, 'data' => array('photo_arr' => $business_photo_arr));
    jsonSendEncode($record);
  }
}


//----------------------------------------------------new code-----------------------------------------

function  addProfession($data)
{

  // echo "<pre>";
  // print_r($data);
  // exit;
  global $mysqli;
  include_once('language_message.php');
  include_once('site_config.php');
  include_once('mailFunctions.php');
  if (empty($_POST['name'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  }


  $name = $data['name'];
  // print_r($title);die;
  
  //-------------------------- check user email --------------------------
  $updatetime = date('Y-m-d H:i:s');
  $createtime = date('Y-m-d H:i:s');
//echo "INSERT INTO `education_master`( name, createtime, updatetime) VALUES ($name, $createtime, $updatetime)";die;
  $result = $mysqli->prepare("INSERT INTO `profession_master`( name, createtime, updatetime) VALUES (?,?,?)");
  $result->bind_param('sss', $name, $createtime, $updatetime);
  $result->execute();
  $row = $mysqli->affected_rows;
  if ($row <= 0) {
    $record = array('success' => false, 'msg' => $professionNotAdded, 'data' => array());
    jsonSendEncode($record);
  }

  $record = array('success' => true, 'msg' => $professionAdded, 'data' => array());
  jsonSendEncode($record);
}


function  editProfession($data)
{
  // echo "<pre>";print_r($data);exit();
  global $mysqli;
  include_once('language_message.php');
  include_once('site_config.php');
  include_once('mailFunctions.php');
  if (empty($_POST['name'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  }


  $profession_id = decode($data['id']);
  // print_r($education_id);die;

  $name = $data['name'];

  

  $updatetime     =   date('Y-m-d H:i:s');

  $update_all     =   $mysqli->prepare("UPDATE profession_master SET name=?,updatetime=? WHERE profession_id=?");
  $update_all->bind_param('ssi', $name, $updatetime, $profession_id);
  $update_all->execute();
  $update = $mysqli->affected_rows;


  if ($update <= 0) {
    $record =   array('success' => false, 'msg' => $msgprofessionNotUpdate, 'data' => array());
    jsonSendEncode($record);
  }


  $record = array('success' => true, 'msg' => $msgprofessionUpdate, 'data' => array());
  jsonSendEncode($record);
}

function professionCheckadd($data)
{
  global $mysqli;
  include_once('language_message.php');
  //print_r($data);
  if (empty($data['name'])) {
    echo 'false';
  } else {
    $name      = $data['name'];
    //$category_id        = decode($data['id']);
    //-------------------------- check user email --------------------------
    $check_category = $mysqli->prepare("SELECT profession_id from profession_master where delete_flag='0' and name=? ");
    $check_category->bind_param("s", $name);
    $check_category->execute();
    $check_category->store_result();
    $check_category_count = $check_category->num_rows;
    if ($check_category_count > 0) {
      echo 'false';
    } else {
      echo "true";
    }
  }
}


function professionCheckEdit($data)
{
  global $mysqli;
  include_once('language_message.php');
  //print_r($data);
  if (empty($data['name'])) {
    echo 'false';
  } else {
    $category      = $data['name'];
    $cat_id  = decode($data['id']);
    //-------------------------- check user email --------------------------
    $check_channel = $mysqli->prepare("SELECT profession_id from profession_master where delete_flag='0' and name = ? and profession_id != ? ");
    $check_channel->bind_param("si", $category, $cat_id);
    $check_channel->execute();
    $check_channel->store_result();
    $check_channel_count = $check_channel->num_rows;
    if ($check_channel_count > 0) {
      echo 'false';
    } else {
      echo "true";
    }
  }
}


function getProfessionData($data)
{
  global $mysqli;
  global $onerror;
  global $country_code;
  include_once('language_message.php');
  //include_once('site_config.php');
  //print_r($data);
  if (empty($data['type'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $type     = $data['type'];
    $srno = 1;
    //for($i=0; $i<50; $i++){
    if ($type == 'all') {
      $check_data = $mysqli->prepare("SELECT `profession_id`, `name`,`createtime` FROM `profession_master`  where delete_flag='0' order by profession_id desc");
    }
    $check_data->execute();
    $check_data->store_result();
    $check_data_count = $check_data->num_rows;
    if ($check_data_count > 0) {
      $check_data->bind_result($profession_id, $name,$createtime);
      while ($check_data->fetch()) {
        $createtime = date('d-m-Y h:i A', strtotime($createtime));


        



        $action_html = '

        <div class="btn-group">

                                                    <button type="button" class="btn btn-primary btn-outline dropdown-toggle float-button-light" id="primary-dropdown-outline" data-bs-toggle="dropdown" aria-expanded="false">

                                                        Action

                                                    </button>

                                                    <ul class="dropdown-menu dropdown-menu-primary" style=" margin: 2px -56px 0;" aria-labelledby="primary-dropdown" role="menu">

                            <a class="dropdown-item"  href="#myModal1" data-bs-toggle="modal"  data-id="'.encode($profession_id).'"   data-name="'.$name.'"  onClick="btnEditCategory(this)"><i class="fa fa-edit"></i>&nbsp;Edit</a>




                                                 <a class="dropdown-item"  href="javascript:void(0)" data-id="' . $profession_id . '"  onClick="btnUserDeleteConfirm(this)"><i class="fa fa-trash" "></i>&nbsp;Delete</a>

                            



                                                        

                                                    </ul>

                                                </div>




      
';
        $pro_arr[] = array('srno' => $srno, 'profession_id' => $profession_id, 'name' => $name,  'createtime' => $createtime,'action'=>$action_html);
        $srno++;
      }
    }
    if (empty($feed_arr)) {
      $feed_arr = array();
    }
    $record = array('success' => true, 'msg' => $msgDataFound, 'data' => array('pro_arr' => $pro_arr));
    jsonSendEncode($record);
  }
}


function deleteProfession($data)
{

  //echo"<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  if (empty($data['cat_id'])) {
    $record =   array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $pro_id    = $data['cat_id'];

    // echo "SELECT post_id from post_master where delete_flag='0' and post_id=$post_id";die;

    $check_user_id = $mysqli->prepare("SELECT profession_id from profession_master where delete_flag='0' and profession_id=?");
    $check_user_id->bind_param("i", $pro_id);
    $check_user_id->execute();
    $check_user_id->store_result();
    $check_user_id_count = $check_user_id->num_rows;
    if ($check_user_id_count <= 0) {
      $record = array('success' => false, 'msg' => $msgprofessionNotExist, 'data' => array());
      jsonSendEncode($record);
    }
    $delete_flag    =   1;
    $updatetime     =   date('Y-m-d H:i:s');
    // Delete Query
    $update_all     =   $mysqli->prepare("UPDATE profession_master set delete_flag=?, updatetime=? WHERE profession_id=?");
    $update_all->bind_param("isi", $delete_flag, $updatetime, $pro_id);
    $update_all->execute();
    $update         =   $mysqli->affected_rows;
    if ($update <= 0) {
      $record     =   array('success' => false, 'msg' => $getprofessionDeleteError, 'data' => array());
      jsonSendEncode($record);
    }
    $record         =   array('success' => true, 'msg' => $getprofessionDelete, 'data' => array());
    jsonSendEncode($record);
  }
}

function educationCheckadd($data)
{
  global $mysqli;
  include_once('language_message.php');
  //print_r($data);
  if (empty($data['name'])) {
    echo 'false';
  } else {
    $name      = $data['name'];
    //$category_id        = decode($data['id']);
    //-------------------------- check user email --------------------------
    $check_category = $mysqli->prepare("SELECT education_id from education_master where delete_flag='0' and name=? ");
    $check_category->bind_param("s", $name);
    $check_category->execute();
    $check_category->store_result();
    $check_category_count = $check_category->num_rows;
    if ($check_category_count > 0) {
      echo 'false';
    } else {
      echo "true";
    }
  }
}


function educationCheckEdit($data)
{
  global $mysqli;
  include_once('language_message.php');
  //print_r($data);
  if (empty($data['name'])) {
    echo 'false';
  } else {
    $category      = $data['name'];
    $cat_id  = decode($data['id']);
    //-------------------------- check user email --------------------------
    $check_channel = $mysqli->prepare("SELECT education_id from education_master where delete_flag='0' and name = ? and education_id != ? ");
    $check_channel->bind_param("si", $category, $cat_id);
    $check_channel->execute();
    $check_channel->store_result();
    $check_channel_count = $check_channel->num_rows;
    if ($check_channel_count > 0) {
      echo 'false';
    } else {
      echo "true";
    }
  }
}


function  addDiamond($data)
{

  // echo "<pre>";
  // print_r($data);
  // exit;
  global $mysqli;
  include_once('language_message.php');
  include_once('site_config.php');
  include_once('mailFunctions.php');
  if (empty($_POST['name'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  }


  $name = $data['name'];
  $price = $data['price'];
  // print_r($title);die;
  
  //-------------------------- check user email --------------------------
  $updatetime = date('Y-m-d H:i:s');
  $createtime = date('Y-m-d H:i:s');
//echo "INSERT INTO `education_master`( name, createtime, updatetime) VALUES ($name, $createtime, $updatetime)";die;
  $result = $mysqli->prepare("INSERT INTO `diamond_master`( no_of_diamond, price,createtime, updatetime) VALUES (?,?,?,?)");
  $result->bind_param('isss', $name,$price, $createtime, $updatetime);
  $result->execute();
  $row = $mysqli->affected_rows;
  if ($row <= 0) {
    $record = array('success' => false, 'msg' => $diamonNotAdded, 'data' => array());
    jsonSendEncode($record);
  }

  $record = array('success' => true, 'msg' => $diamonAdded, 'data' => array());
  jsonSendEncode($record);
}

function getDiamondData($data)
{
  global $mysqli;
  global $onerror;
  global $country_code;
  include_once('language_message.php');
  //include_once('site_config.php');
  //print_r($data);
  if (empty($data['type'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $type     = $data['type'];
    $srno = 1;
    //for($i=0; $i<50; $i++){
    if ($type == 'all') {
      $check_data = $mysqli->prepare("SELECT `diamond_id`, `no_of_diamond`,`price`,`createtime` FROM `diamond_master`  where delete_flag='0' order by diamond_id desc");
    }
    $check_data->execute();
    $check_data->store_result();
    $check_data_count = $check_data->num_rows;
    if ($check_data_count > 0) {
      $check_data->bind_result($diamond_id, $no_of_diamond,$price,$createtime);
      while ($check_data->fetch()) {
        $createtime = date('d-m-Y h:i A', strtotime($createtime));


        



        $action_html = '

        <div class="btn-group">

                                                    <button type="button" class="btn btn-primary btn-outline dropdown-toggle float-button-light" id="primary-dropdown-outline" data-bs-toggle="dropdown" aria-expanded="false">

                                                        Action

                                                    </button>

                                                    <ul class="dropdown-menu dropdown-menu-primary" style=" margin: 2px -56px 0;" aria-labelledby="primary-dropdown" role="menu">

                            <a class="dropdown-item"  href="#myModal1" data-bs-toggle="modal"  data-id="'.encode($diamond_id).'"   data-name="'.$no_of_diamond.'"  data-price="'.$price.'" onClick="btnEditCategory(this)"><i class="fa fa-edit"></i>&nbsp;Edit</a>




                                                 <a class="dropdown-item"  href="javascript:void(0)" data-id="' . $diamond_id . '"  onClick="btnUserDeleteConfirm(this)"><i class="fa fa-trash" "></i>&nbsp;Delete</a>

                            



                                                        

                                                    </ul>

                                                </div>




      
';
        $dmd_arr[] = array('srno' => $srno, 'diamond_id' => $diamond_id, 'no_of_diamond' => $no_of_diamond, 'price'=>$price, 'createtime' => $createtime,'action'=>$action_html);
        $srno++;
      }
    }
    if (empty($feed_arr)) {
      $feed_arr = array();
    }
    $record = array('success' => true, 'msg' => $msgDataFound, 'data' => array('dmd_arr' => $dmd_arr));
    jsonSendEncode($record);
  }
}


function  editDiamond($data)
{
  // echo "<pre>";print_r($data);exit();
  global $mysqli;
  include_once('language_message.php');
  include_once('site_config.php');
  include_once('mailFunctions.php');
  if (empty($_POST['name'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  }


  $diamond_id = decode($data['id']);
  // print_r($education_id);die;

  $name = $data['name'];
  $price = $data['price'];

  

  $updatetime     =   date('Y-m-d H:i:s');

  $update_all     =   $mysqli->prepare("UPDATE diamond_master SET no_of_diamond=?,price=?,updatetime=? WHERE diamond_id=?");
  $update_all->bind_param('issi', $name,$price, $updatetime, $diamond_id);
  $update_all->execute();
  $update = $mysqli->affected_rows;


  if ($update <= 0) {
    $record =   array('success' => false, 'msg' => $msgdiamonNotUpdate, 'data' => array());
    jsonSendEncode($record);
  }


  $record = array('success' => true, 'msg' => $msgdiamonUpdate, 'data' => array());
  jsonSendEncode($record);
}


function deleteDiamond($data)
{

  //echo"<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  if (empty($data['cat_id'])) {
    $record =   array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $pro_id    = $data['cat_id'];

    // echo "SELECT post_id from post_master where delete_flag='0' and post_id=$post_id";die;

    $check_user_id = $mysqli->prepare("SELECT diamond_id from diamond_master where delete_flag='0' and diamond_id=?");
    $check_user_id->bind_param("i", $pro_id);
    $check_user_id->execute();
    $check_user_id->store_result();
    $check_user_id_count = $check_user_id->num_rows;
    if ($check_user_id_count <= 0) {
      $record = array('success' => false, 'msg' => $msgdiamonNotExist, 'data' => array());
      jsonSendEncode($record);
    }
    $delete_flag    =   1;
    $updatetime     =   date('Y-m-d H:i:s');
    // Delete Query
    $update_all     =   $mysqli->prepare("UPDATE diamond_master set delete_flag=?, updatetime=? WHERE diamond_id=?");
    $update_all->bind_param("isi", $delete_flag, $updatetime, $pro_id);
    $update_all->execute();
    $update         =   $mysqli->affected_rows;
    if ($update <= 0) {
      $record     =   array('success' => false, 'msg' => $getdiamonDeleteError, 'data' => array());
      jsonSendEncode($record);
    }
    $record         =   array('success' => true, 'msg' => $getdiamonDelete, 'data' => array());
    jsonSendEncode($record);
  }
}



function  addGift($data)
{

  //echo "<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  include_once('site_config.php');
  include_once('mailFunctions.php');
  if (empty($_POST['name'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  }



  $name = trim($data['name']);
  $diamond = trim($data['diamond']);
  $qty = trim($data['qty']);
  $host_price = $data['hprice'];

 



  if (!empty($_FILES['image']['name'])) {
    $user_image = $_FILES['image'];
    // Code to upload the file starts
    $file = $user_image;
    $folder_name = '../webservice/images';
    $file_type = 'image';
    $upload_status = uploadFile($file, $folder_name, $file_type);
    if ($upload_status == 'error') {
      $record = array('success' => false, 'msg' => $msgErrorFileUpload, 'data' => array());
      jsonSendEncode($record);
    }
    $image = $upload_status;
    // Code to upload the file starts
  } else {
    $image =  $image_get;
  }






  //-------------------------- check user email --------------------------

  $updatetime = date('Y-m-d H:i:s');
  $createtime = date('Y-m-d H:i:s');

  
  $sql = "INSERT INTO `gift_master`(`image`, `name`, `diamond_point`, `no_of_x`,`host_price`, `createtime`, `updatetime`)  VALUES (?,?,?,?,?,?,?)";
  $result = $mysqli->prepare($sql);
  $result->bind_param('ssiisss',  $image, $name,$diamond,$qty,$host_price, $createtime, $updatetime);
  $result->execute();
  $row = $mysqli->affected_rows;
  if ($row <= 0) {
    $record = array('success' => false, 'msg' => $GiftNotAdded, 'data' => array());
    jsonSendEncode($record);
  }


  $record = array('success' => true, 'msg' => $GiftAdded, 'data' => array());
  jsonSendEncode($record);
}



function getGift($data)
{
  global $mysqli;
  global $onerror;
  //global $item_onerror;
  include_once('language_message.php');
  //include_once('site_config.php');

  //print_r($data);
  if (empty($data['type'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $type     = $data['type'];
    $srno = 1;
    //for($i=0; $i<50; $i++){
    if ($type == 'all') {
      $check_data = $mysqli->prepare("SELECT `gift_id`, `image`, `name`, `diamond_point`, `no_of_x`,`host_price`, `createtime` FROM `gift_master` where delete_flag=0  order by gift_id desc");
    }
    $check_data->execute();
    $check_data->store_result();
    $check_data_count = $check_data->num_rows;
    if ($check_data_count > 0) {
      $check_data->bind_result($gift_id, $image, $name,$diamond_point,$no_of_x,$host_price, $createtime);
      while ($check_data->fetch()) {
        $createtime = date('d-m-Y h:i A', strtotime($createtime));
        //$countrycode = getCountryCode($country_id);
        //$user_id = encode($user_id);

        $image_html = '<img  width="50px" src="../webservice/images/' . $image . '" class="rounded-circle circle-border m-b-md img-fix img-responsive" name="profile_image" id="previewholder" style="width: 70px; height: 70px;" alt="" onerror="this.src=' . $onerror . ';" >';

        $action_html = '


    <div class="btn-group">

                          

                        

                        



                        <button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown">Action</button>

                          <div class="dropdown-menu dropdown-menu-end">

                          

                            <a class="dropdown-item"  href="#myModal1" data-bs-toggle="modal"  data-id="' . encode($gift_id) . '"   data-name="' . $name . '"  data-image="' . $image . '"  data-diamond="' . $diamond_point . '"  data-qty="' . $no_of_x . '" data-hprice="' . $host_price . '"  onClick="btnEditCategory(this)"><i class="fa fa-edit"></i>&nbsp;Edit</a>

                          



                            <a class="dropdown-item"  data-id="' . $gift_id . '" onClick="btnUserDeleteConfirm(this)"><i class="fa fa-trash"></i>&nbsp;Delete</a>

                            

                          

                          </div>



                        </div>





  ';


        $user_arr[] = array('host_price'=>$host_price,'srno' => $srno, 'gift_id' => $gift_id, 'action' => $action_html, 'name' => $name, 'createtime' => $createtime, 'image' => $image_html,'diamond'=>$diamond_point,'qty'=>$no_of_x);
        $srno++;
      }
    }
    if (empty($user_arr)) {
      $user_arr = array();
    }
    $record = array('success' => true, 'msg' => $msgDataFound, 'data' => array('user_arr' => $user_arr));
    jsonSendEncode($record);
  }
}

















function getRatingAndReviews($data) {
  global $mysqli;
  global $onerror;
  global $country_code;
  include_once('language_message.php');
  //include_once('site_config.php');
  //print_r($data);
  if(empty($data['type'])) {
    $record=array('success'=>false, 'msg'=>$msgEmptyAll, 'data'=>array());
    jsonSendEncode($record);
  } else {
    $type     = $data['type'];
    $user_id     = decode($data['user_id']);
    $srno=1;
    //for($i=0; $i<50; $i++){
    if($type == 'all'){


        // echo "SELECT `rating_id`, `user_id`, `other_user_id`, `job_id`, `rating`, `createtime`, `updatetime`, `review` FROM `rating_master`  where delete_flag='0' and user_id=$user_id order by rating_id desc";die;
      $check_data=$mysqli->prepare("SELECT `rating_id`, `user_id`, `other_user_id`, `rating`, `createtime`, `updatetime`, `review` FROM `rating_master`  where delete_flag='0' and other_user_id=? order by rating_id desc");
    } 
    $check_data->bind_param('i',$user_id);
    $check_data->execute();
    $check_data->store_result();
    $check_data_count=$check_data->num_rows;
    if($check_data_count >0) {
      $check_data->bind_result($rating_id,$user_id,$other_user_id,$rating,$createtime,$updatetime,$review);
      while($check_data->fetch()){
        $createtime=date('d-m-Y h:i A',strtotime($createtime));

        $userData =getUserDetails($user_id);
        $userName=$userData['name'];
        
      
                $numberTodecimal = number_format($rating, 1);
                $second_number   = round($rating, 0, PHP_ROUND_HALF_UP);
                //echo "second_number=".$second_number;die();
                $numberTostring  = explode('.', $rating);
                $star_rating_img = '';

                if ($numberTostring[0] > 0) {
                    for ($i = 1; $i <= 5; $i++) {
                        if ($i <= $numberTostring[0]) {
                            $star_rating_img .= '<i class="fa fa-star" style="color: #ffc107 !important;"></i>';
                            //echo "numberTostring= > 0";print_r($star_rating_img);die();
                        } else {
                            if ($i <= $second_number) {
                                $star_rating_img .= '<i class="fa fa-star-half-o" style="color: #ffc107 !important;"></i>';
                            } else {
                                $star_rating_img .= '<i class="fa fa-star-o" style="color: #ffc107 !important;"></i>';
                            }
                        }
                    }
                } else {
                    for ($i = 1; $i <= 5; $i++) {
                        $star_rating_img .= '<i class="fa fa-star-o" style="color: #ffc107 !important;"></i>';
                    }
                }

                $action_html = '

                <div class="btn-group">

                                                    <button type="button" class="btn btn-primary btn-outline dropdown-toggle float-button-light" id="primary-dropdown-outline" data-bs-toggle="dropdown" aria-expanded="false">

                                                        Action

                                                    </button>

                                                    <ul class="dropdown-menu dropdown-menu-primary" style=" margin: 2px -56px 0;" aria-labelledby="primary-dropdown" role="menu">

                                                       
                                                         
</li>
<li>
                            <a class="dropdown-item"  data-id="' . $rating_id . '" onClick="btnUserDeleteConfirmrating(this)"><i class="fa fa-trash"></i>&nbsp;Delete</a>
</li>
                                                    </ul>

                                                </div>
';


       

        $job_arr[] = array('srno'=>$srno,'rating_id'=>$rating_id,'user_id'=>$user_id,'other_user_id'=>$other_user_id,'rating'=>$star_rating_img,'createtime'=>$createtime,'updatetime'=>$updatetime,'review'=>$review,'name'=>$userName,'action'=>$action_html);
        $srno++;
      }
    }
    if(empty($job_arr)){
      $job_arr = array();
    }
    $record=array('success'=>true, 'msg'=>$msgDataFound, 'data'=>array('job_arr'=>$job_arr));
    jsonSendEncode($record);
  }
}


function getGiftUser($data)
{
  global $mysqli;
  global $onerror;
  //global $item_onerror;
  include_once('language_message.php');
  //include_once('site_config.php');

  //print_r($data);
  if (empty($data['type'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $type     = $data['type'];
    $user_id     = decode($data['user_id']);
    $srno = 1;
    //for($i=0; $i<50; $i++){
    if ($type == 'all') {
      $check_data = $mysqli->prepare("SELECT `gift_send_id`, `gift_id`, `diamond_point`, `user_id`, `other_user_id`, `createtime` FROM `gift_send_master` where delete_flag = 0  and other_user_id=$user_id order by gift_send_id desc");
    }
    $check_data->execute();
    $check_data->store_result();
    $check_data_count = $check_data->num_rows;
    if ($check_data_count > 0) {
      $check_data->bind_result($gift_send_id,$gift_id, $diamond_point,$user_id,$other_user_id,$createtime);
      while ($check_data->fetch()) {
        $createtime = date('d-m-Y h:i A', strtotime($createtime));
        //$countrycode = getCountryCode($country_id);
        //$user_id = encode($user_id);

      $userData =getUserDetails($user_id);
      $userName =$userData['name'];
      $gift =getGiftName($gift_id);

       $action_html = '


    <div class="btn-group">

                          

                        

                        



                        <button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown">Action</button>

                          <div class="dropdown-menu dropdown-menu-end">

                          

                          

                          



                            <a class="dropdown-item"  data-id="' . $gift_send_id . '" onClick="btnUserDeleteConfirmgift(this)"><i class="fa fa-trash"></i>&nbsp;Delete</a>

                            

                          

                          </div>



                        </div>





  ';


        $user_arr[] = array('srno' => $srno, 'gift' => $gift,  'userName' => $userName, 'createtime' => $createtime, 'diamond'=>$diamond_point,'action'=>$action_html);
        $srno++;
      }
    }
    if (empty($user_arr)) {
      $user_arr = array();
    }
    $record = array('success' => true, 'msg' => $msgDataFound, 'data' => array('user_arr' => $user_arr));
    jsonSendEncode($record);
  }
}






function getUserDiamond($data)
{
    global $mysqli;
    global $onerror;
    global $country_code;
    include_once('language_message.php');
    //include_once('site_config.php');
    // print_r($data);
    if (empty($data['type'])) {
        $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
        jsonSendEncode($record);
    } else {

        $user_id       = decode($data['user_id']);
        // print_r($user_id);die;
        $srno = 1;
        //for($i=0; $i<50; $i++){
            // echo "SELECT `ebook_buy_id`, `ebook_id`, `user_id`, `price`, `transaction_id`, `createtime`, `updatetime` FROM `ebook_buy_master` where delete_flag='0' and user_id=$user_id order by ebook_buy_id desc";die;
            $check_data = $mysqli->prepare("SELECT `buy_diamond_id`, `price`, `no_of_diamond`, `createtime` FROM `buy_diamond_master` where delete_flag='0' and user_id=? order by buy_diamond_id desc");
        $check_data->bind_param('i',$user_id);
        $check_data->execute();
        $check_data->store_result();
        $check_data_count = $check_data->num_rows;
        if ($check_data_count > 0) {
            $check_data->bind_result($buy_diamond_id,  $price, $no_of_diamond, $createtime);
            while ($check_data->fetch()) {
                $createtime = date('d-m-Y h:i A', strtotime($createtime));
                //$countrycode = getCountryCode($country_id);
                //$user_id = encode($user_id);
               
                
                $user_arr[] = array('srno' => $srno, 'buy_diamond_id' => $buy_diamond_id, 'price' => $price, 'no_of_diamond' => $no_of_diamond,  'createtime' => $createtime);
                $srno++;
            }
        }
        if (empty($user_arr)) {
            $user_arr = array();
        }
        $record = array('success' => true, 'msg' => $msgDataFound, 'data' => array('user_arr' => $user_arr));
        jsonSendEncode($record);
    }
}



function getVideocallList($data) {
  global $mysqli;
  global $onerror;
 //global $item_onerror;
  include_once('language_message.php');
  //include_once('site_config.php');

  //print_r($data);
  if(empty($data['type'])) {
    $record=array('success'=>false, 'msg'=>$msgEmptyAll, 'data'=>array());
    jsonSendEncode($record);
  } else {
    $type     = $data['type'];
    $srno=1;
    //for($i=0; $i<50; $i++){
    if($type == 'all'){
      $check_data=$mysqli->prepare("SELECT `video_call_id`, `user_id`, `other_user_id`, `price`,`duration`, `createtime` FROM `video_call_master` where delete_flag=0 order by video_call_id desc");
    } 
    $check_data->execute();
    $check_data->store_result();
    $check_data_count=$check_data->num_rows;
    if($check_data_count >0) {
      $check_data->bind_result($video_call_id,$user_id,$other_user_id,$price,$duration,$createtime);
      while($check_data->fetch()){
         $createtime=date('d-m-Y h:i A',strtotime($createtime));
        //$countrycode = getCountryCode($country_id);
        //$user_id = encode($user_id);

      $userData = getUserDetails($user_id);
      $userName = $userData['name'];

      $hostData = getUserDetails($other_user_id);
      $hostName = $hostData['name'];
      
     
        
    
                      
                
        $user_arr[] = array('video_call_id'=>$video_call_id,'srno'=>$srno, 'price'=>$price, 'hostName'=>$hostName,'createtime'=>$createtime,'userName'=>$userName,'duration'=>$duration);
        $srno++;
      }
    }
    if(empty($user_arr)){
      $user_arr = array();
    }
    $record=array('success'=>true, 'msg'=>$msgDataFound, 'data'=>array('user_arr'=>$user_arr));
    jsonSendEncode($record);
  }
}

function getWithdrawRequest($data) {
  global $mysqli;
  global $onerror;
 //global $item_onerror;
  include_once('language_message.php');
  //include_once('site_config.php');

  //print_r($data);
  if(empty($data['type'])) {
    $record=array('success'=>false, 'msg'=>$msgEmptyAll, 'data'=>array());
    jsonSendEncode($record);
  } else {
    $type     = $data['type'];
    $srno=1;
    //for($i=0; $i<50; $i++){
    if($type == 'all'){
      $check_data=$mysqli->prepare("SELECT `withdrawl_req_id`, `user_id`, `withdrawl_amount`,  `description`, `status`, `createtime` FROM `withdrawl_request_master` where delete_flag=0 order by withdrawl_req_id desc");
    } 
    $check_data->execute();
    $check_data->store_result();
    $check_data_count=$check_data->num_rows;
    if($check_data_count >0) {
      $check_data->bind_result($withdrawl_req_id,$user_id,$withdrawl_amount,$description,$status,$createtime);
      while($check_data->fetch()){
         $createtime=date('d-m-Y h:i A',strtotime($createtime));
        //$countrycode = getCountryCode($country_id);
        //$user_id = encode($user_id);

      $userData = getUserDetails($user_id);
      $userName = $userData['name'];
      
      if($status == 0){
        $statustext ='<label class=" badge badge-warning">Pending</lable>';
      }else if($status == 1){
        $statustext ='<label class=" badge badge-success">Accept</lable>';
      }else{
        $statustext='<label class=" badge badge-danger">Reject</lable>';
      }
        
    $action_html = '


    <div class="btn-group">

                          

                        

                        



                        <button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown">Action</button>

                          <div class="dropdown-menu dropdown-menu-end">

                          

                           



                            <a class="dropdown-item"  data-id="'.$withdrawl_req_id.'" onClick="btnUserDeleteConfirm(this)"><i class="fa fa-check"></i>&nbsp;Accept</a>
                            <a class="dropdown-item"  data-id="'.$withdrawl_req_id.'" onClick="btnUserDeleteConfirm1(this)"><i class="fa fa-times"></i>&nbsp;Reject</a>

                            

                          

                          </div>



                        </div>





  ';
                      
                
        $user_arr[] = array('description'=>$description,'srno'=>$srno, 'status'=>$statustext, 'action'=>$action_html, 'withdrawl_amount'=>$withdrawl_amount,'createtime'=>$createtime,'userName'=>$userName);
        $srno++;
      }
    }
    if(empty($user_arr)){
      $user_arr = array();
    }
    $record=array('success'=>true, 'msg'=>$msgDataFound, 'data'=>array('user_arr'=>$user_arr));
    jsonSendEncode($record);
  }
}

 function acceptRequest($data) {

          //echo"<pre>";print_r($data);exit;
                    global $mysqli;
                  include_once('language_message.php');
                  if(empty($data['cat_id'])) {
                    $record =   array('success'=>false, 'msg'=>$msgEmptyAll,'data'=>array()); 
                    jsonSendEncode($record); 
                  } 
                  else {
                     $request_id    =$data['cat_id'];
                    $check_user_id=$mysqli->prepare("SELECT withdrawl_req_id from withdrawl_request_master where delete_flag='0' and withdrawl_req_id=?");
                    $check_user_id->bind_param("i",$request_id);
                    $check_user_id->execute();
                    $check_user_id->store_result();
                    $check_user_id_count=$check_user_id->num_rows;
                    if($check_user_id_count <= 0) {
                      $record=array('success'=>false,'msg'=>$msgRequestNotExist, 'data'=>array());
                      jsonSendEncode($record);
                    }
                    $delete_flag    =   1;
                    $updatetime     =   date('Y-m-d H:i:s');
                    // Delete Query
                    $update_all     =   $mysqli->prepare("UPDATE withdrawl_request_master set status=?, updatetime=? WHERE withdrawl_req_id=?"); 
                    $update_all->bind_param("isi", $delete_flag, $updatetime, $request_id);
                    $update_all->execute();
                    $update         =   $mysqli->affected_rows;
                    if($update<=0){ 
                      $record     =   array('success'=>false, 'msg'=>$getRequestError, 'data'=>array()); 
                      jsonSendEncode($record); 
                    }
                    $record         =   array('success'=>true, 'msg'=>$getRequest, 'data'=>array()); 
                    jsonSendEncode($record);
                  }
                }
        

                function rejectRequest($data) {

                  //echo"<pre>";print_r($data);exit;
                            global $mysqli;
                          include_once('language_message.php');
                          if(empty($data['cat_id'])) {
                            $record =   array('success'=>false, 'msg'=>$msgEmptyAll,'data'=>array()); 
                            jsonSendEncode($record); 
                          } 
                          else {
                             $request_id    =$data['cat_id'];
                            $check_user_id=$mysqli->prepare("SELECT withdrawl_req_id from withdrawl_request_master where delete_flag='0' and withdrawl_req_id=?");
                            $check_user_id->bind_param("i",$request_id);
                            $check_user_id->execute();
                            $check_user_id->store_result();
                            $check_user_id_count=$check_user_id->num_rows;
                            if($check_user_id_count <= 0) {
                              $record=array('success'=>false,'msg'=>$msgRequestNotExist, 'data'=>array());
                              jsonSendEncode($record);
                            }
                            $delete_flag    =   2;
                            $updatetime     =   date('Y-m-d H:i:s');
                            // Delete Query
                            $update_all     =   $mysqli->prepare("UPDATE withdrawl_request_master set status=?, updatetime=? WHERE withdrawl_req_id=?"); 
                            $update_all->bind_param("isi", $delete_flag, $updatetime, $request_id);
                            $update_all->execute();
                            $update         =   $mysqli->affected_rows;
                            if($update<=0){ 
                              $record     =   array('success'=>false, 'msg'=>$getRequestrError, 'data'=>array()); 
                              jsonSendEncode($record); 
                            }
                            $record         =   array('success'=>true, 'msg'=>$getRequestr, 'data'=>array()); 
                            jsonSendEncode($record);
                          }
                        }


function getEducationData12($data)
{
  global $mysqli;
  global $onerror;
  global $country_code;
  include_once('language_message.php');
  //include_once('site_config.php');
  //print_r($data);
  if (empty($data['type'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $type     = $data['type'];
    $srno = 1;
    //for($i=0; $i<50; $i++){
    if ($type == 'all') {
      $check_data = $mysqli->prepare("SELECT `education_id`, `name`,`createtime` FROM `education_master`  where delete_flag='0' order by education_id desc");
    }
    $check_data->execute();
    $check_data->store_result();
    $check_data_count = $check_data->num_rows;
    if ($check_data_count > 0) {
      $check_data->bind_result($education_id, $name,$createtime);
      while ($check_data->fetch()) {
        $createtime = date('d-m-Y h:i A', strtotime($createtime));


        



        $action_html = '

        <div class="btn-group">

                                                    <button type="button" class="btn btn-primary btn-outline dropdown-toggle float-button-light" id="primary-dropdown-outline" data-bs-toggle="dropdown" aria-expanded="false">

                                                        Action

                                                    </button>

            <ul class="dropdown-menu dropdown-menu-primary" style=" margin: 2px -56px 0;" aria-labelledby="primary-dropdown" role="menu">

                            <a class="dropdown-item"  href="#myModal1" data-bs-toggle="modal"  data-id="'.encode($education_id).'"   data-name="'.$name.'"  onClick="btnEditCategory(this)"><i class="fa fa-edit"></i>&nbsp;Edit</a>




                                                 <a class="dropdown-item"  href="javascript:void(0)" data-id="' . $education_id . '"  onClick="btnUserDeleteConfirm(this)"><i class="fa fa-trash" "></i>&nbsp;Delete</a>

                            



                                                        

                                                    </ul>

                                                </div>




      
';
        $pro_arr[] = array('srno' => $srno, 'education_id' => $education_id, 'name' => $name,  'createtime' => $createtime,'action'=>$action_html);
        $srno++;
      }
    }
    if (empty($feed_arr)) {
      $feed_arr = array();
    }
    $record = array('success' => true, 'msg' => $msgDataFound, 'data' => array('pro_arr' => $pro_arr));
    jsonSendEncode($record);
  }
}

function verifyStatus($data)
{

  //echo"<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  if (empty($data['user_id'])) {
    $record =   array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $user_id    = decode($data['user_id']);
    $check_user_id = $mysqli->prepare("SELECT user_id from user_master where delete_flag='0' and user_id=?");
    $check_user_id->bind_param("i", $user_id);
    $check_user_id->execute();
    $check_user_id->store_result();
    $check_user_id_count = $check_user_id->num_rows;
    if ($check_user_id_count <= 0) {
      $record = array('success' => false, 'msg' => $msgUserNotExist, 'data' => array());
      jsonSendEncode($record);
    }
    $verify_flag    =   1;
    $updatetime     =   date('Y-m-d H:i:s');
    // Delete Query
    $update_all     =   $mysqli->prepare("UPDATE user_master set verify_flag=1, updatetime=? WHERE user_id=?");
    $update_all->bind_param("si", $updatetime, $user_id);
    $update_all->execute();
    $update         =   $mysqli->affected_rows;
    if ($update <= 0) {
      $record     =   array('success' => false, 'msg' => $msgStatusNotVerify, 'data' => array());
      jsonSendEncode($record);
    }
    $record         =   array('success' => true, 'msg' => $msgStatusVerify, 'data' => array());
    jsonSendEncode($record);
  }
}


function unverifyStatus($data)
{

  //echo"<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  if (empty($data['user_id'])) {
    $record =   array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $user_id    = decode($data['user_id']);
    $check_user_id = $mysqli->prepare("SELECT user_id from user_master where delete_flag='0' and user_id=?");
    $check_user_id->bind_param("i", $user_id);
    $check_user_id->execute();
    $check_user_id->store_result();
    $check_user_id_count = $check_user_id->num_rows;
    if ($check_user_id_count <= 0) {
      $record = array('success' => false, 'msg' => $msgUserNotExist, 'data' => array());
      jsonSendEncode($record);
    }
    $verify_flag    =   0;
    $updatetime     =   date('Y-m-d H:i:s');
    // Delete Query
    $update_all     =   $mysqli->prepare("UPDATE user_master set verify_flag=?, updatetime=? WHERE user_id=?");
    $update_all->bind_param("isi", $verify_flag, $updatetime, $user_id);
    $update_all->execute();
    $update         =   $mysqli->affected_rows;
    if ($update <= 0) {
      $record     =   array('success' => false, 'msg' => $msgStatusNotUnVerify, 'data' => array());
      jsonSendEncode($record);
    }
    $record         =   array('success' => true, 'msg' => $msgStatusUnVerify, 'data' => array());
    jsonSendEncode($record);
  }
}


function suggestedStatus($data)
{

  //echo"<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  if (empty($data['user_id'])) {
    $record =   array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $user_id    = decode($data['user_id']);
    $check_user_id = $mysqli->prepare("SELECT user_id from user_master where delete_flag='0' and user_id=?");
    $check_user_id->bind_param("i", $user_id);
    $check_user_id->execute();
    $check_user_id->store_result();
    $check_user_id_count = $check_user_id->num_rows;
    if ($check_user_id_count <= 0) {
      $record = array('success' => false, 'msg' => $msgUserNotExist, 'data' => array());
      jsonSendEncode($record);
    }
    $verify_flag    =   1;
    $updatetime     =   date('Y-m-d H:i:s');
    // Delete Query
    $update_all     =   $mysqli->prepare("UPDATE user_master set suggested_flag=1, updatetime=? WHERE user_id=?");
    $update_all->bind_param("si", $updatetime, $user_id);
    $update_all->execute();
    $update         =   $mysqli->affected_rows;
    if ($update <= 0) {
      $record     =   array('success' => false, 'msg' => $msgStatusNotSuggested, 'data' => array());
      jsonSendEncode($record);
    }
    $record         =   array('success' => true, 'msg' => $msgStatusSuggested, 'data' => array());
    jsonSendEncode($record);
  }
}

function unsuggestedStatus($data)
{

  //echo"<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  if (empty($data['user_id'])) {
    $record =   array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $user_id    = decode($data['user_id']);
    $check_user_id = $mysqli->prepare("SELECT user_id from user_master where delete_flag='0' and user_id=?");
    $check_user_id->bind_param("i", $user_id);
    $check_user_id->execute();
    $check_user_id->store_result();
    $check_user_id_count = $check_user_id->num_rows;
    if ($check_user_id_count <= 0) {
      $record = array('success' => false, 'msg' => $msgUserNotExist, 'data' => array());
      jsonSendEncode($record);
    }
    $suggested_flag    =   0;
    $updatetime     =   date('Y-m-d H:i:s');
    // Delete Query
    $update_all     =   $mysqli->prepare("UPDATE user_master set suggested_flag=?, updatetime=? WHERE user_id=?");
    $update_all->bind_param("isi", $verify_flag, $updatetime, $user_id);
    $update_all->execute();
    $update         =   $mysqli->affected_rows;
    if ($update <= 0) {
      $record     =   array('success' => false, 'msg' => $msgStatusNotUnSuggested, 'data' => array());
      jsonSendEncode($record);
    }
    $record         =   array('success' => true, 'msg' => $msgStatusUnSuggested, 'data' => array());
    jsonSendEncode($record);
  }
}




function  editUser($data)
{

  //echo "<pre>";print_r($data);exit();
  global $mysqli;
  include_once('language_message.php');
  include_once('site_config.php');
  include_once('mailFunctions.php');
  if (empty($_POST['user_id'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  }



  $user_id = decode($data['user_id']);
  
  $name = $data['name'];
  $mobile = $data['mobile'];
  $country = $data['country'];
  $dob = $data['dob'];
  $gender = $data['gender'];
  $height = $data['height'];
  $weight = $data['weight'];
  $education = $data['education'];
  $profession = $data['profession'];
  $bio = $data['bio'];
  
 




  



  
  $updatetime     =   date('Y-m-d H:i:s');







  $check_email_mobile1 = $mysqli->prepare("SELECT `image` FROM `user_master`WHERE  delete_flag='0'  and user_id=?");
  $check_email_mobile1->bind_param("i", $user_id);
  $check_email_mobile1->execute();
  $check_email_mobile1->store_result();
  $check_email_mobile_count1 = $check_email_mobile1->num_rows;
  if ($check_email_mobile_count1 <= 0) {
    $record = array('success' => false, 'msg' => $msgInvalidId, 'data' => array());
    jsonSendEncode($record);
  }
  $check_email_mobile1->bind_result($image_get);
  $check_email_mobile1->fetch();

  $updatetime     =   date('Y-m-d H:i:s');



  if (!empty($_FILES['image']['name'])) {
    $user_image = $_FILES['image'];
    // Code to upload the file starts
    $file = $user_image;
    $folder_name = '../webservice/images';
    $file_type = 'image';
    $upload_status = uploadFile($file, $folder_name, $file_type);
    if ($upload_status == 'error') {
      $record = array('success' => false, 'msg' => $msgErrorFileUpload, 'data' => array());
      jsonSendEncode($record);
    }
    $image = $upload_status;
    // Code to upload the file starts
  } else {
    $image =  $image_get;
  }








 
  $update_all     =   $mysqli->prepare("UPDATE user_master SET name=?,mobile=?,country_id=?,dob=?,gender=?,height_fit=?,weight=?,education_id=?,profession_id=?, biography=?, image=?,updatetime=? WHERE user_id=?");
  $update_all->bind_param('siisisiiisssi', $name, $mobile, $country, $dob, $gender, $height, $weight, $education, $profession, $bio, $image, $updatetime, $user_id);
  $update_all->execute();
  $update = $mysqli->affected_rows;
  if ($update <= 0) {
    $record =   array('success' => false, 'msg' => $msgUserNotUpdate, 'data' => array());
    jsonSendEncode($record);
  }

 if($data['type'] == 1){
$record = array('success' => true, 'msg' => $msgUserUpdate, 'data' => array());
 }else{
    $record = array('success' => true, 'msg' => $msgCharmUpdate, 'data' => array());
 }
  
  jsonSendEncode($record);
}


function deleteRating($data)
{

  //echo"<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  if (empty($data['cat_id'])) {
    $record =   array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $pro_id    = $data['cat_id'];

    // echo "SELECT post_id from post_master where delete_flag='0' and post_id=$post_id";die;

    $check_user_id = $mysqli->prepare("SELECT rating_id from rating_master where delete_flag='0' and rating_id=?");
    $check_user_id->bind_param("i", $pro_id);
    $check_user_id->execute();
    $check_user_id->store_result();
    $check_user_id_count = $check_user_id->num_rows;
    if ($check_user_id_count <= 0) {
      $record = array('success' => false, 'msg' => $msgdiamonNotExist, 'data' => array());
      jsonSendEncode($record);
    }
    $delete_flag    =   1;
    $updatetime     =   date('Y-m-d H:i:s');
    // Delete Query
    $update_all     =   $mysqli->prepare("UPDATE rating_master set delete_flag=?, updatetime=? WHERE rating_id=?");
    $update_all->bind_param("isi", $delete_flag, $updatetime, $pro_id);
    $update_all->execute();
    $update         =   $mysqli->affected_rows;
    if ($update <= 0) {
      $record     =   array('success' => false, 'msg' => $getratingDeleteError, 'data' => array());
      jsonSendEncode($record);
    }
    $record         =   array('success' => true, 'msg' => $getratingDelete, 'data' => array());
    jsonSendEncode($record);
  }
}


function deletePhoto($data)
{

  //echo"<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  if (empty($data['cat_id'])) {
    $record =   array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $pro_id    = $data['cat_id'];

    // echo "SELECT post_id from post_master where delete_flag='0' and post_id=$post_id";die;

    $check_user_id = $mysqli->prepare("SELECT user_image_id from user_image_master where delete_flag='0' and user_image_id=?");
    $check_user_id->bind_param("i", $pro_id);
    $check_user_id->execute();
    $check_user_id->store_result();
    $check_user_id_count = $check_user_id->num_rows;
    if ($check_user_id_count <= 0) {
      $record = array('success' => false, 'msg' => $msgdiamonNotExist, 'data' => array());
      jsonSendEncode($record);
    }
    $delete_flag    =   1;
    $updatetime     =   date('Y-m-d H:i:s');
    // Delete Query
    $update_all     =   $mysqli->prepare("UPDATE user_image_master set delete_flag=?, updatetime=? WHERE user_image_id=?");
    $update_all->bind_param("isi", $delete_flag, $updatetime, $pro_id);
    $update_all->execute();
    $update         =   $mysqli->affected_rows;
    if ($update <= 0) {
      $record     =   array('success' => false, 'msg' => $getprivatephotoDeleteError, 'data' => array());
      jsonSendEncode($record);
    }
    $record         =   array('success' => true, 'msg' => $getprivatephotoDelete, 'data' => array());
    jsonSendEncode($record);
  }
}



function deleteGiftUser($data)
{

  //echo"<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  if (empty($data['cat_id'])) {
    $record =   array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $cat_id    = $data['cat_id'];
    $check_user_id = $mysqli->prepare("SELECT gift_send_id from gift_send_master where delete_flag='0' and gift_send_id=?");
    $check_user_id->bind_param("i", $cat_id);
    $check_user_id->execute();
    $check_user_id->store_result();
    $check_user_id_count = $check_user_id->num_rows;
    if ($check_user_id_count <= 0) {
      $record = array('success' => false, 'msg' => $msgGiftNotExist, 'data' => array());
      jsonSendEncode($record);
    }
    $delete_flag    =   1;
    $updatetime     =   date('Y-m-d H:i:s');
    // Delete Query
    $update_all     =   $mysqli->prepare("UPDATE gift_send_master set delete_flag=?, updatetime=? WHERE gift_send_id=?");
    $update_all->bind_param("isi", $delete_flag, $updatetime, $cat_id);
    $update_all->execute();
    $update         =   $mysqli->affected_rows;
    if ($update <= 0) {
      $record     =   array('success' => false, 'msg' => $getGiftDeleteError, 'data' => array());
      jsonSendEncode($record);
    }
    $record         =   array('success' => true, 'msg' => $getGiftDelete, 'data' => array());
    jsonSendEncode($record);
  }
}


function deleteMomentUser($data)
{

  //echo"<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  if (empty($data['cat_id'])) {
    $record =   array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $cat_id    = $data['cat_id'];
    $check_user_id = $mysqli->prepare("SELECT moment_id from moment_master where delete_flag='0' and moment_id=?");
    $check_user_id->bind_param("i", $cat_id);
    $check_user_id->execute();
    $check_user_id->store_result();
    $check_user_id_count = $check_user_id->num_rows;
    if ($check_user_id_count <= 0) {
      $record = array('success' => false, 'msg' => $msgMomentNotExist, 'data' => array());
      jsonSendEncode($record);
    }
    $delete_flag    =   1;
    $updatetime     =   date('Y-m-d H:i:s');
    // Delete Query
    $update_all     =   $mysqli->prepare("UPDATE moment_master set delete_flag=?, updatetime=? WHERE moment_id=?");
    $update_all->bind_param("isi", $delete_flag, $updatetime, $cat_id);
    $update_all->execute();
    $update         =   $mysqli->affected_rows;
    if ($update <= 0) {
      $record     =   array('success' => false, 'msg' => $getMomentDeleteError, 'data' => array());
      jsonSendEncode($record);
    }
    $record         =   array('success' => true, 'msg' => $getMomentDelete, 'data' => array());
    jsonSendEncode($record);
  }
}




















function deleteCategory($data)
{

  //echo"<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  if (empty($data['cat_id'])) {
    $record =   array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $category_id    = $data['cat_id'];
    $check_user_id = $mysqli->prepare("SELECT category_id from category_master where delete_flag='0' and category_id=?");
    $check_user_id->bind_param("i", $category_id);
    $check_user_id->execute();
    $check_user_id->store_result();
    $check_user_id_count = $check_user_id->num_rows;
    if ($check_user_id_count <= 0) {
      $record = array('success' => false, 'msg' => $msgCategoryNotExist, 'data' => array());
      jsonSendEncode($record);
    }
    $delete_flag    =   1;
    $updatetime     =   date('Y-m-d H:i:s');
    // Delete Query
    $update_all     =   $mysqli->prepare("UPDATE category_master set delete_flag=?, updatetime=? WHERE category_id=?");
    $update_all->bind_param("isi", $delete_flag, $updatetime, $category_id);
    $update_all->execute();
    $update         =   $mysqli->affected_rows;
    if ($update <= 0) {
      $record     =   array('success' => false, 'msg' => $getCategoryDeleteError, 'data' => array());
      jsonSendEncode($record);
    }
    $record         =   array('success' => true, 'msg' => $getCategoryDelete, 'data' => array());
    jsonSendEncode($record);
  }
}














function getCategory($data)
{
  global $mysqli;
  global $onerror;
  //global $item_onerror;
  include_once('language_message.php');
  //include_once('site_config.php');

  //print_r($data);
  if (empty($data['type'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $type     = $data['type'];
    $srno = 1;
    //for($i=0; $i<50; $i++){
    if ($type == 'all') {
      $check_data = $mysqli->prepare("SELECT `category_id`, `category_name`, `createtime` FROM `category_master` where delete_flag=0  order by category_id desc");
    }
    $check_data->execute();
    $check_data->store_result();
    $check_data_count = $check_data->num_rows;
    if ($check_data_count > 0) {
      $check_data->bind_result($category_id, $category_name, $createtime);
      while ($check_data->fetch()) {
        $createtime = date('d-m-Y h:i A', strtotime($createtime));
        //$countrycode = getCountryCode($country_id);
        //$user_id = encode($user_id);

        // $image_html = '<img  width="50px" src="../webservice/images/' . $image . '" class="rounded-circle circle-border m-b-md img-fix img-responsive" name="profile_image" id="previewholder" style="width: 70px; height: 70px;" alt="" onerror="this.src=' . $onerror . ';" >';
        $category_name_html = '<a  href="view_equipment_type.php?id='.encode($category_id).'"  style="color:black" title="Click to view details">'.$category_name.'</a>';
        $action_html = '


           <div class="btn-group">

                          

                        

                        



                        <button type="button" class="btn btn-primary dropdown-toggle " data-bs-toggle="dropdown">Action</button>

                          <div class="dropdown-menu dropdown-menu-end">

                          

                            <a class="dropdown-item"  href="#myModal1" data-bs-toggle="modal"  data-id="' . encode($category_id) . '"   data-name="' . $category_name . '"  onClick="btnEditCategory(this)"><i class="fa fa-edit"></i>&nbsp;Edit</a>

                             <a class="dropdown-item"  href="add_equipment.php"><i class="fa fa-plus"></i>&nbsp;Add Equipment</a>

                              

                            <a class="dropdown-item"  data-id="' . $category_id . '" onClick="btnUserDeleteConfirm(this)"><i class="fa fa-trash"></i>&nbsp;Delete</a>

                            

                          

                          </div>



                        </div>





  ';


        $user_arr[] = array('srno' => $srno, 'category_id' => $category_id, 'action' => $action_html, 'category_name' => $category_name_html, 'createtime' => $createtime);
        $srno++;
      }
    }
    if (empty($user_arr)) {
      $user_arr = array();
    }
    $record = array('success' => true, 'msg' => $msgDataFound, 'data' => array('user_arr' => $user_arr));
    jsonSendEncode($record);
  }
}









































































function  addSubadmin($data){
 
    global $mysqli;
    include_once('language_message.php');
    include_once('site_config.php');
    include_once('mailFunctions.php');
    if(empty($_POST['name'])){
            $record=array('success'=>false, 'msg'=>$msgEmptyAll, 'data'=>array()); 
            jsonSendEncode($record);
    }
    
   

    $name=$data['name'];
    $mobile=$data['mobile'];
    

    
  
    $email=$data['email'];
    $role=$data['role'];
   
    
        
    $profile_complete=1;
    $user_type=1;

     // $permission_string = implode(',',$data['permission_option']);
   

   
    //-------------------------- check user email --------------------------
   
     $updatetime=date('Y-m-d H:i:s');
     $createtime=date('Y-m-d H:i:s');

      if(!empty($_FILES['image']['name'])){
          $user_image = $_FILES['image'];
          // Code to upload the file starts
          $file=$user_image;
          $folder_name='images';
          $file_type='image';
          $upload_status=uploadFile($file, $folder_name, $file_type);
          if($upload_status == 'error') {
            $record=array('success'=>false, 'msg' =>$msgErrorFileUpload, 'data'=>array());
            jsonSendEncode($record);
          }
          $image = $upload_status;
          // Code to upload the file starts
        }
    
          $sql = "INSERT INTO user_master (user_type,name,email,image,profile_complete,createtime,updatetime,role_id,mobile) VALUES (?,?,?,?,?,?,?,?,?)";
          $result = $mysqli->prepare($sql);
      $result->bind_param('isssissii',$user_type,$name,$email,$image,$profile_complete,$createtime,$updatetime,$role,$mobile);
          $result->execute();
          $row= $mysqli->affected_rows;
          if($row <= 0){
            $record=array('success'=>false,'msg' =>$UserNotAdded, 'data'=>array()); 
            jsonSendEncode($record); 
          }

       $check_email_all=$mysqli->prepare("SELECT user_id,name, password from user_master where delete_flag='0' and user_type =1 and email=?");
    $check_email_all->bind_param("s",$email);
    $check_email_all->execute();
    $check_email_all->store_result();
    $check_email=$check_email_all->num_rows;
    // echo "check_email=";print_r($check_email);die();
    if($check_email <= 0) {
      $record=array('success'=>false, 'msg'=>$msgInvalidEmail1, 'data'=>array()); 
      jsonSendEncode($record);    
    }
      else{


      $check_email_all->bind_result($user_id_get,$name_get, $password_get);
      $check_email_all->fetch();
      //$forgot_pass_identity = base64_encode($user_id);
      $fp_code = md5(uniqid());
      $resetPassLink = $siteURL.'create_password.php?uniqcode='.$fp_code;
      $mailContent = 'Recently your account is created by LeadsIMS admin!.<br/>To Create your password, visit the following link:
      <a href="'.$resetPassLink.'" style="float: unset; width: 25%; display: block; margin: 26px auto 0; background:#3906A5; text-align: center; vertical-align: middle; user-select: none; border: 1px solid transparent; padding: .375rem .75rem; font-size: .875rem; line-height: 1.5; border-radius: .25rem; transition: color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out; color: #fff;text-decoration: unset;">Create Password</a>';

      $active_flag  = 1;
      $user_type    = 1;
      $delete_flag  = 0;
      $createtime   = date('Y-m-d H:i:s');
      $updatetime   = date('Y-m-d H:i:s');
               
                
                // Now Insert Data Into Request Table
            
            $forgot_insert = $mysqli->prepare("INSERT INTO forgot_password_master(user_id,user_type, email,forgot_pass_identity, active_flag, delete_flag, createtime, updatetime) VALUES (?,?,?,?,?,?,?,?)");
            $forgot_insert->bind_param("iissiiss", $user_id_get,$user_type, $email , $fp_code, $active_flag, $delete_flag, $createtime, $updatetime);
            $forgot_insert->execute();
            $insert_id=$mysqli->affected_rows;
            if($insert_id<=0) { 
              $record = array('success'=>'false', 'msg' =>$msg_succ_forgot); 
              jsonSendEncode($record); 
            } 
            
            //mail Function call
            $postData['mailContent'] =  $mailContent;
            $postData['name']     = $name_get;
            $postData['email']    = $email;
            $postData['fromName'] = $appName;
            $postData['app_name'] = $appName;
            $postData['app_url']       =$app_url;
            $postData['app_logo']   = $appLogo;
            $subject =  "Invitation Link";

            // echo "postData=";print_r($postData);die();

            $mailBody = mailBodyCreatePasswordData($postData);
            // echo "postData=";print_r($mailBody);die();
            $mailResponse = mailSend($postData['email'], $postData['fromName'], $subject, $mailBody);
                
                // echo "postData=";print_r($mailResponse);die();
          if($mailResponse == 'yes'){
              $record=array('success'=>true, 'msg'=>$UserAdded, 'data'=>array());
            jsonSendEncode($record);
            
            } 
            else{
            $record=array('success'=>false, 'msg'=>$msgNotSendEmail, 'data'=>array()); 
              jsonSendEncode($record);
          }
               
        } 
         
         

      }


function getEquipment($data)
{
  global $mysqli;
  global $onerror;

  //global $item_onerror;
  include_once('language_message.php');
  include_once('site_config.php');
   global $siteURL2;

  //print_r($data);
  if (empty($data['type'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $type     = $data['type'];
    $srno = 1;
    //for($i=0; $i<50; $i++){
    if ($type == 'all') {
      $check_data = $mysqli->prepare("SELECT  `equipment_id`, `equipment_type_id`, `equipment_name`, `description`, `createtime`,`folder_no`,`equipment_history`, `user_id`,previous_inspection_date,inspection_due_date,components,inspection_finding,summary FROM `equipment_master` where delete_flag=0  order by equipment_id desc");
    }
    $check_data->execute();
    $check_data->store_result();
    $check_data_count = $check_data->num_rows;
    if ($check_data_count > 0) {
      $check_data->bind_result($equipment_id, $equipment_type_id, $equipment_name,$description,$createtime,$folder_no,$equipment_history,$user_id,$previous_inspection_date,$inspection_due_date,$components,$inspection_finding,$summary);
      while ($check_data->fetch()) {
        $createtime = date('d-m-Y h:i A', strtotime($createtime));

        if($previous_inspection_date ==NULL){
               $previous_inspection_date = '';
        }else{
              
               $previous_inspection_date = date('d-m-Y ', strtotime($previous_inspection_date));
        }

        //$eq_component =getEquipmentComponent($equipment_id);
        // if($attachment_file == ''){
        //  $attachment_html ='NA';
        // }else{
        //      $attachment_html ="<a href=".$img_url_user_main2.$attachment_file." target='_blank'>View File</a>";
        // }
     
         if($inspection_due_date ==NULL){
               $inspection_due_date = '';
        }else{
              
               $inspection_due_date = date('d-m-Y ', strtotime($inspection_due_date));
        }

        if(empty($summary)){
          $summary ='NA';
        }
    
       
        $equipmentTypeName = getCategoryName($equipment_type_id);
       
    $userData1 = getUserDetails($user_id);
         if($userData1 != 'NA'){
              $userName =$userData1['name'];
              
         }else{
           $userName ='NA';
             
         }
        $action_html = '


           <div class="btn-group">

                          

                        

                        



                        <button type="button" class="btn btn-primary dropdown-toggle " data-bs-toggle="dropdown">Action</button>

                          <div class="dropdown-menu dropdown-menu-end">

                          

                            <a class="dropdown-item"  href="edit_equipment.php?id='.encode($equipment_id).'" ><i class="fa fa-edit"></i>&nbsp;Edit equipment</a>

                          



                            <a class="dropdown-item"  data-id="' . $equipment_id . '" onClick="btnUserDeleteConfirm(this)"><i class="fa fa-trash"></i>&nbsp;Delete</a>

                            

                          

                          </div>



                        </div>





  ';


        $user_arr[] = array('srno' => $srno, 'equipment_id' => $equipment_id, 'action' => $action_html, 'equipment_name' => $equipment_name, 'createtime' => $createtime,'description'=>$description,'equipmentTypeName'=>$equipmentTypeName,'folder_no'=>$folder_no,'equipment_history'=>$equipment_history,'userName'=>$userName,'previous_inspection_date'=>$previous_inspection_date,'inspection_due_date'=>$inspection_due_date,'components'=>$components,'inspection_finding'=>$inspection_finding,'summary'=>$summary);
        $srno++;
      }
    }
    if (empty($user_arr)) {
      $user_arr = array();
    }
    $record = array('success' => true, 'msg' => $msgDataFound, 'data' => array('user_arr' => $user_arr));
    jsonSendEncode($record);
  }
}


function deleteEquipment($data)
{

  //echo"<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  if (empty($data['cat_id'])) {
    $record =   array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $equipment_id    = $data['cat_id'];
    $check_user_id = $mysqli->prepare("SELECT equipment_id from equipment_master where delete_flag='0' and equipment_id=?");
    $check_user_id->bind_param("i", $equipment_id);
    $check_user_id->execute();
    $check_user_id->store_result();
    $check_user_id_count = $check_user_id->num_rows;
    if ($check_user_id_count <= 0) {
      $record = array('success' => false, 'msg' => $msgEquipmentNotExist, 'data' => array());
      jsonSendEncode($record);
    }
    $delete_flag    =   1;
    $updatetime     =   date('Y-m-d H:i:s');
    // Delete Query
    $update_all     =   $mysqli->prepare("UPDATE equipment_master set delete_flag=?, updatetime=? WHERE equipment_id=?");
    $update_all->bind_param("isi", $delete_flag, $updatetime, $equipment_id);
    $update_all->execute();
    $update         =   $mysqli->affected_rows;
    if ($update <= 0) {
      $record     =   array('success' => false, 'msg' => $getEquipmentDeleteError, 'data' => array());
      jsonSendEncode($record);
    }
    $record         =   array('success' => true, 'msg' => $getEquipmentDelete, 'data' => array());
    jsonSendEncode($record);
  }
}

function  addEquipment($data)
{

  //echo "<pre>";print_r($_FILES);exit;
  global $mysqli;
  include_once('language_message.php');
  include_once('site_config.php');
  include_once('mailFunctions.php');
  if (empty($_POST['name'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  }



  $equipment_name = $data['name'];
  $folder_no = $data['fno'];
  $previousinspectionDate = $data['prevDate'];
  $inspectionduedate = $data['dueDate'];

  $inspectionFinding =$data['inspfind'];
  $equipment_type =$data['etype'];
  $description =$data['desp'];
  $ehistory=$data['ehistory'];
  $user_id =decode($data['user_id']);

   if(!empty($data['summary'])){
    $summary =$data['summary'];
  }else{
    $summary ='';
  }
 

  // $check_category = $mysqli->prepare("SELECT category_id from category_master where delete_flag='0' and category_name=? ");
  // $check_category->bind_param("s", $category_name);
  // $check_category->execute();
  // $check_category->store_result();
  // $check_category_count = $check_category->num_rows;
  // if ($check_category_count > 0) {

  //   $record = array('success' => false, 'msg' => $msgCategoryExist, 'data' => array());
  //   jsonSendEncode($record);
  // }
 //-------------------------- check user email --------------------------

  $updatetime = date('Y-m-d H:i:s');
  $createtime = date('Y-m-d H:i:s');

 

if (!empty($_FILES['attachment']['name'][0])) {
 $product_img   = $_FILES['attachment'];
            $file = $product_img;
            $folder_name = '../webservice/images';
            $file_type = 'image';
            $upload_status = uploadFileMultiple1($file, $folder_name, $file_type);
            // print_r($upload_status);
            if ($upload_status == 'error') {
                $record = array('success' => false, 'msg' => $msgErrorFileUpload, 'data' => array());
                jsonSendEncode($record);
            }
 $cmp =$data['cmp'];
            for ($i=0; $i <count($cmp) ; $i++) { 
  $sql ="INSERT INTO `equipment_master`(`equipment_type_id`, `equipment_name`, `description`,  `createtime`, `updatetime`,`folder_no`,`equipment_history`,`user_id`,`previous_inspection_date`,`inspection_due_date`,`inspection_finding`,`components`,`summary`)  VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)";
  $result = $mysqli->prepare($sql);
  $result->bind_param('issssssisssss', $equipment_type,$equipment_name,$description, $createtime, $updatetime,$folder_no,$ehistory,$user_id,$previousinspectionDate[$i],$inspectionduedate[$i],$inspectionFinding[$i],$cmp[$i],$summary);
  $result->execute();
  $row = $mysqli->affected_rows;
  if ($row <= 0) {
    $record = array('success' => false, 'msg' => $EquipmentNotAdded, 'data' => array());
    jsonSendEncode($record);
  }else{
   $last_equipment_id =$mysqli->insert_id;

   foreach ($upload_status as $images) {
                //echo "INSERT INTO product_image_master(product_id, pro_image, delete_flag, createdate) VALUES ($product_id,$upload_status,$delete_flag,$createtime)";
                $insertImage = $mysqli->prepare("INSERT INTO equipment_attachment_master( equipment_id,attachment,createtime,updatetime) VALUES (?,?,?,?)");
                $insertImage->bind_param("isss", $last_equipment_id, $images, $createtime,$updatetime);
                $insertImage->execute();
                $insertImageRowAffected = $mysqli->affected_rows;
                if ($insertImageRowAffected < 0) {
                    $record = array('success' => false, 'msg' => $msgProductImageAddedError, 'data' => array());
                    jsonSendEncode($record);
                }
            }
          
    
  }
    }
            




          // Code to upload the file starts
                        } else {
                          $cmp =$data['cmp'];
                          for ($i=0; $i <count($cmp) ; $i++) { 
  
  $sql ="INSERT INTO `equipment_master`(`equipment_type_id`, `equipment_name`, `description`,  `createtime`, `updatetime`,`folder_no`,`equipment_history`,`user_id`,`previous_inspection_date`,`inspection_due_date`,`inspection_finding`,`components`,`summary`)  VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)";
  $result = $mysqli->prepare($sql);
  $result->bind_param('issssssisssss', $equipment_type,$equipment_name,$description, $createtime, $updatetime,$folder_no,$ehistory,$user_id,$previousinspectionDate[$i],$inspectionduedate[$i],$inspectionFinding[$i],$cmp[$i],$summary);
  $result->execute();
  $row = $mysqli->affected_rows;
  if ($row <= 0) {
    $record = array('success' => false, 'msg' => $EquipmentNotAdded, 'data' => array());
    jsonSendEncode($record);
  }
    }
                        }
  

 

  
                 
              


  $record = array('success' => true, 'msg' => $EquipmentAdded, 'data' => array());
  jsonSendEncode($record);
}



function EditEquipment($data)
{
   //print_r($data);die;
  global $mysqli;
  global $onerror;

  include_once('language_message.php');
  // echo "hello"; die;
  if (empty($data['id'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $equipment_id     =   $data['id'];
  $equipment_name = $data['name'];
  $folder_no = $data['fno'];
  $equipment_type =$data['etype'];
  $description =$data['desp'];
  $ehistory =$data['ehistory'];
     $cmp =$data['cmp'];

  $previousinspectionDate = $data['prevDate'];
  $inspectionduedate = $data['dueDate'];
 
  $inspectionFinding =$data['inspfind'];
  $inspectionFinding =$data['inspfind'];

   if(!empty($data['summary'])){
    $summary =$data['summary'];
  }else{
    $summary ='';
  }
 


    // Now check category Already added   

  //   $check_category = $mysqli->prepare("SELECT category_id from category_master where delete_flag='0' and category_name=? and category_id != ?");
  // $check_category->bind_param("si", $category_name,$cat_id);
  // $check_category->execute();
  // $check_category->store_result();
  // $check_category_count = $check_category->num_rows;
  // if ($check_category_count > 0) {

  //   $record = array('success' => false, 'msg' => $msgCategoryExist, 'data' => array());
  //   jsonSendEncode($record);
  // } 


       

   
    $updatetime     =   date('Y-m-d H:i:s');
    $createtime     =   date('Y-m-d H:i:s');
    $update_all     =   $mysqli->prepare("UPDATE equipment_master SET equipment_type_id=?,equipment_name=?, description=?,updatetime=?,folder_no=?, equipment_history=?,previous_inspection_date=?,inspection_due_date=?,inspection_finding=?,components=?,summary=? WHERE equipment_id=?");
    $update_all->bind_param("issssssssssi",$equipment_type, $equipment_name,$description, $updatetime,$folder_no,$ehistory,$previousinspectionDate,$inspectionduedate,$inspectionFinding,$cmp,$summary, $equipment_id);
    $update_all->execute();
    $update = $mysqli->affected_rows;
    if ($update <= 0) {
      $record =   array('success' => false, 'msg' => $msgEquipmentNotUpdate, 'data' => array());
      jsonSendEncode($record);
    };


    if (!empty($_FILES['attachment']['name'][0])) {
 $product_img   = $_FILES['attachment'];
            $file = $product_img;
            $folder_name = '../webservice/images';
            $file_type = 'image';
            $upload_status = uploadFileMultiple1($file, $folder_name, $file_type);
            // print_r($upload_status);
            if ($upload_status == 'error') {
                $record = array('success' => false, 'msg' => $msgErrorFileUpload, 'data' => array());
                jsonSendEncode($record);
            }
foreach ($upload_status as $images) {
                //echo "INSERT INTO product_image_master(product_id, pro_image, delete_flag, createdate) VALUES ($product_id,$upload_status,$delete_flag,$createtime)";
                $insertImage = $mysqli->prepare("INSERT INTO equipment_attachment_master( equipment_id,attachment,createtime,updatetime) VALUES (?,?,?,?)");
                $insertImage->bind_param("isss", $equipment_id, $images, $createtime,$updatetime);
                $insertImage->execute();
                $insertImageRowAffected = $mysqli->affected_rows;
                if ($insertImageRowAffected < 0) {
                    $record = array('success' => false, 'msg' => $msgProductImageAddedError, 'data' => array());
                    jsonSendEncode($record);
                }
            }
            }


  

                   
                   
                 
    $record     =   array('success' => true, 'msg' => $msgEquipmentUpdate, 'data' => array());
    jsonSendEncode($record);
  }
}



function  addInspection($data)
{

  //echo "<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  include_once('site_config.php');
  include_once('mailFunctions.php');
  if (empty($_POST['ititle'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  }



  $inspection_title= $data['ititle'];
  $inspection_date = $data['idate'];
 $eng_id =$data['eng'];
  $equipment_type =$data['etype'];
  $equipment_id =$data['equipment'];
  $description =$data['desp'];
  $inspection_type =$data['instype'];

 
  $user_id =decode($data['user_id']);

  // $check_category = $mysqli->prepare("SELECT category_id from category_master where delete_flag='0' and category_name=? ");
  // $check_category->bind_param("s", $category_name);
  // $check_category->execute();
  // $check_category->store_result();
  // $check_category_count = $check_category->num_rows;
  // if ($check_category_count > 0) {

  //   $record = array('success' => false, 'msg' => $msgCategoryExist, 'data' => array());
  //   jsonSendEncode($record);
  // }
 //-------------------------- check user email --------------------------

  $updatetime = date('Y-m-d H:i:s');
  $createtime = date('Y-m-d H:i:s');

 

  $sql ="INSERT INTO `inspection_master`(`user_id`,`equipment_type_id`,`equipment_id`,`inspection_type_id`, `inspection_title`, `description`,`inspection_date`, `createtime`, `updatetime`,`added_by_id`)  VALUES (?,?,?,?,?,?,?,?,?,?)";
  $result = $mysqli->prepare($sql);
  $result->bind_param('iiiisssssi', $eng_id,$equipment_type,$equipment_id,$inspection_type,$inspection_title,$description,$inspection_date,$createtime, $updatetime,$user_id);
  $result->execute();
  $row = $mysqli->affected_rows;
  if ($row <= 0) {
    $record = array('success' => false, 'msg' => $InspectionNotAdded, 'data' => array());
    jsonSendEncode($record);
  }

  $last_id  =$mysqli->insert_id;
 
    $next_inspection_date =$data['answer'];
                for ($i=0; $i <count($next_inspection_date) ; $i++) { 
                  $sql = "INSERT INTO `next_inspection_date_master`(`inspection_id`, `next_inspection_date`,`createtime`,`updatetime`) VALUES(?,?,?,?)";
               $result = $mysqli->prepare($sql);
               $result->bind_param('isss',$last_id,$next_inspection_date[$i],$createtime,$updatetime);
               $result->execute();
               $row= $mysqli->affected_rows;
               if($row <= 0){
                 $record=array('success'=>false,'msg' =>$InspectionNotAdded, 'data'=>array()); 
                 jsonSendEncode($record); 
               }
                }
                 


  $record = array('success' => true, 'msg' => $InspectionAdded, 'data' => array());
  jsonSendEncode($record);
}


function EditInspection($data)
{
   //print_r($data);die;
  global $mysqli;
  global $onerror;

  include_once('language_message.php');
  // echo "hello"; die;
  if (empty($data['id'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $inspection_id     =   $data['id'];
   $inspection_title= $data['ititle'];
  $inspection_date = $data['idate'];
 $eng_id =$data['eng'];
  $equipment_type =$data['etype'];
  $equipment_id =$data['equipment'];
  $description =$data['desp'];
  $inspection_type =$data['instype'];



    // Now check category Already added   

  //   $check_category = $mysqli->prepare("SELECT category_id from category_master where delete_flag='0' and category_name=? and category_id != ?");
  // $check_category->bind_param("si", $category_name,$cat_id);
  // $check_category->execute();
  // $check_category->store_result();
  // $check_category_count = $check_category->num_rows;
  // if ($check_category_count > 0) {

  //   $record = array('success' => false, 'msg' => $msgCategoryExist, 'data' => array());
  //   jsonSendEncode($record);
  // }      

   
    $updatetime     =   date('Y-m-d H:i:s');
    $update_all     =   $mysqli->prepare("UPDATE inspection_master SET user_id=? , equipment_type_id=?,equipment_id =? ,inspection_type_id=?, inspection_title=?, description =? ,inspection_date=?, updatetime=? WHERE inspection_id=?");
    $update_all->bind_param("iiiissssi",$eng_id,$equipment_type,$equipment_id,$inspection_type,$inspection_title,$description,$inspection_date, $updatetime, $inspection_id);
    $update_all->execute();
    $update = $mysqli->affected_rows;
    if ($update <= 0) {
      $record =   array('success' => false, 'msg' => $msgInspectionNotUpdate, 'data' => array());
      jsonSendEncode($record);
    };

    $update_all1     =   $mysqli->prepare("DELETE FROM  next_inspection_date_master  WHERE inspection_id=?");
    $update_all1->bind_param("i",$inspection_id);
    $update_all1->execute();

    $next_inspection_date =$data['answer'];
                for ($i=0; $i <count($next_inspection_date) ; $i++) { 
                  $sql = "INSERT INTO `next_inspection_date_master`(`inspection_id`, `next_inspection_date`,`createtime`,`updatetime`) VALUES(?,?,?,?)";
               $result = $mysqli->prepare($sql);
               $result->bind_param('isss',$inspection_id,$next_inspection_date[$i],$createtime,$updatetime);
               $result->execute();
               $row= $mysqli->affected_rows;
               if($row <= 0){
                 $record=array('success'=>false,'msg' =>$InspectionNotAdded, 'data'=>array()); 
                 jsonSendEncode($record); 
               }
                }
    $record     =   array('success' => true, 'msg' => $msgInspectionUpdate, 'data' => array());
    jsonSendEncode($record);
  }
}


function deleteInspection($data)
{

  //echo"<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  if (empty($data['ins_id'])) {
    $record =   array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $inspection_id    = $data['ins_id'];
    $check_user_id = $mysqli->prepare("SELECT inspection_id from inspection_master where delete_flag='0' and inspection_id=?");
    $check_user_id->bind_param("i", $inspection_id);
    $check_user_id->execute();
    $check_user_id->store_result();
    $check_user_id_count = $check_user_id->num_rows;
    if ($check_user_id_count <= 0) {
      $record = array('success' => false, 'msg' => $msgInspectionNotExist, 'data' => array());
      jsonSendEncode($record);
    }
    $delete_flag    =   1;
    $updatetime     =   date('Y-m-d H:i:s');
    // Delete Query
    $update_all     =   $mysqli->prepare("UPDATE inspection_master set delete_flag=?, updatetime=? WHERE inspection_id=?");
    $update_all->bind_param("isi", $delete_flag, $updatetime, $inspection_id);
    $update_all->execute();
    $update         =   $mysqli->affected_rows;
    if ($update <= 0) {
      $record     =   array('success' => false, 'msg' => $getInspectionDeleteError, 'data' => array());
      jsonSendEncode($record);
    }
    $record         =   array('success' => true, 'msg' => $getInspectionDelete, 'data' => array());
    jsonSendEncode($record);
  }
}




function getInspection($data)
{
  global $mysqli;
  global $onerror;
  //global $item_onerror;
  include_once('language_message.php');
  //include_once('site_config.php');

  //print_r($data);
  if (empty($data['type'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $type     = $data['type'];
    $srno = 1;
    //for($i=0; $i<50; $i++){
    if ($type == 'all') {
      $check_data = $mysqli->prepare("SELECT  `inspection_id`,`user_id`, `equipment_type_id`,`equipment_id`, `inspection_type_id`, `inspection_title`, `inspection_date`,`description`, `createtime`,`added_by_id` FROM `inspection_master` where delete_flag=0  order by inspection_id desc");
    }
    $check_data->execute();
    $check_data->store_result();
    $check_data_count = $check_data->num_rows;
    if ($check_data_count > 0) {
      $check_data->bind_result($inspection_id,$user_id, $equipment_type_id,$equipment_id, $inspection_type_id,$inspection_title,$inspection_date,$description,$createtime,$added_by_id);
      while ($check_data->fetch()) {
        $createtime = date('d-m-Y h:i A', strtotime($createtime));
        $inspection_date = date('d-m-Y', strtotime($inspection_date));
         $equipment_name = getEquipmentNameall($equipment_id);
        $equipmentTypeName = getCategoryName($equipment_type_id);
        $inspection_type_name =getInspectionTypeName($inspection_type_id);
       
         $userData = getUserDetails($user_id);
         if($userData != 'NA'){
              $userName =$userData['name'];
              $userMobile =$userData['mobile'];
              $userEmail =$userData['email'];
              $userImage =$userData['image'];
              $image_html = '<img  width="50px" src="../webservice/images/' . $userImage . '" class="rounded-circle circle-border m-b-md img-fix img-responsive" name="profile_image" id="previewholder" style="width: 70px; height: 70px;" alt="" onerror="this.src=' . $onerror . ';" >';
         }else{
           $userName ='NA';
             $userMobile ='NA';
              $userEmail ='NA';
              $image_html ='NA';
         }

          $userData1 = getUserDetails($added_by_id);
         if($userData1 != 'NA'){
              $userName1 =$userData1['name'];
              
         }else{
           $userName1 ='NA';
             
         }
        $action_html = '


           <div class="btn-group">

                          

                        

                        



                        <button type="button" class="btn btn-primary dropdown-toggle " data-bs-toggle="dropdown">Action</button>

                          <div class="dropdown-menu dropdown-menu-end">

                          

                            <a class="dropdown-item"  href="edit_inspection.php?id='.encode($inspection_id).'" ><i class="fa fa-edit"></i>&nbsp;Edit inspection</a>

                          
                              <li><a href="view_inspection.php?id=' . encode($inspection_id) . '"" class="dropdown-item"><i class="fa fa-eye"></i>&nbsp;View</a></li>



                            <a class="dropdown-item"  data-id="' . $inspection_id . '" onClick="btnUserDeleteConfirm(this)"><i class="fa fa-trash"></i>&nbsp;Delete</a>

                            

                          

                          </div>



                        </div>





  ';


        $user_arr[] = array('srno' => $srno, 'inspection_id' => $inspection_id, 'action' => $action_html, 'inspection_title' => $inspection_title, 'createtime' => $createtime,'equipmentTypeName'=>$equipmentTypeName,'inspection_date'=>$inspection_date,'equipment_name'=>$equipment_name,'userName'=>$userName,'inspection_type_name'=>$inspection_type_name,'userMobile'=>$userMobile,'userEmail'=>$userEmail,'image_html'=>$image_html,'description'=>$description,'userName1'=>$userName1);
        $srno++;
      }
    }
    if (empty($user_arr)) {
      $user_arr = array();
    }
    $record = array('success' => true, 'msg' => $msgDataFound, 'data' => array('user_arr' => $user_arr));
    jsonSendEncode($record);
  }
}



function getInspectionHistory($data)
{
  global $mysqli;
  global $onerror;
  //global $item_onerror;
  include_once('language_message.php');
  //include_once('site_config.php');

  //print_r($data);
  if (empty($data['type'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $type     = $data['type'];
    $user_id     = decode($data['user_id']);
    $srno = 1;
    //for($i=0; $i<50; $i++){
    if ($type == 'all') {

        // echo "SELECT `inspection_request_id`, `inspection_id`, `user_id`, `inspection_type_id`, `inspection_title`, `inspection_date`, `createtime` FROM `inspection_request_master` where delete_flag=0 and user_id=$user_id order by inspection_request_id desc";die;
      $check_data = $mysqli->prepare("SELECT `inspection_request_id`, `inspection_id`, `user_id`, `inspection_type_id`, `inspection_title`, `inspection_date`, `createtime` FROM `inspection_request_master` where delete_flag=0 and inspection_id=? order by inspection_request_id desc");
    }
    $check_data->bind_param('i',$user_id);
    $check_data->execute();
    $check_data->store_result();
    $check_data_count = $check_data->num_rows;
    if ($check_data_count > 0) {
      $check_data->bind_result($inspection_request_id,$inspection_id, $user_id,$inspection_type_id, $inspection_title,$inspection_date,$createtime);
      while ($check_data->fetch()) {
        $createtime = date('d-m-Y h:i A', strtotime($createtime));
        $inspection_date = date('d-m-Y', strtotime($inspection_date));

        $getInspectiondetails=getInspectiondetails($inspection_id);
        // print_r($getInspectiondetails);
// $equipment_id='';
// $equipment_type_id='';
        if ($getInspectiondetails!='NA') {
                $equipment_id= $getInspectiondetails['equipment_id'];
                $equipment_type_id= $getInspectiondetails['equipment_type_id'];
          }else{
               $equipment_id= 0;
               $equipment_type_id= 0;
          }
        $equipment_name = getEquipmentNameall($equipment_id);
        $equipmentTypeName = getCategoryName($equipment_type_id);
        $inspection_type_name =getInspectionTypeName($inspection_type_id);
       
         // $userData = getUserDetails($user_id);
         // if($userData != 'NA'){
         //      $userName =$userData['name'];
         //      $userMobile =$userData['mobile'];
         //      $userEmail =$userData['email'];
         //      $userImage =$userData['image'];
         //      $image_html = '<img  width="50px" src="../webservice/images/' . $userImage . '" class="rounded-circle circle-border m-b-md img-fix img-responsive" name="profile_image" id="previewholder" style="width: 70px; height: 70px;" alt="" onerror="this.src=' . $onerror . ';" >';
         // }else{
         //   $userName ='NA';
         //     $userMobile ='NA';
         //      $userEmail ='NA';
         //      $image_html ='NA';
         // }

        // $action_html = '
        //    <div class="btn-group">
        //                 <button type="button" class="btn btn-primary dropdown-toggle " data-bs-toggle="dropdown">Action</button>
        //                   <div class="dropdown-menu dropdown-menu-end">
        //                     <a class="dropdown-item"  href="edit_inspection.php?id='.encode($inspection_id).'" ><i class="fa fa-edit"></i>&nbsp;Edit inspection</a>
        //                       <li><a href="view_inspection.php?id=' . encode($inspection_id) . '"" class="dropdown-item"><i class="fa fa-eye"></i>&nbsp;View</a></li>
        //                     <a class="dropdown-item"  data-id="' . $inspection_id . '" onClick="btnUserDeleteConfirm(this)"><i class="fa fa-trash"></i>&nbsp;Delete</a>
        //                   </div>
        //                 </div> ';


        $user_arr[] = array('srno' => $srno, 'inspection_request_id' => $inspection_request_id, 'inspection_id' => $inspection_id, 'user_id' => $user_id, 'inspection_type_name' => $inspection_type_name,'inspection_title'=>$inspection_title,'inspection_date'=>$inspection_date,'createtime'=>$createtime,'equipment_name'=>$equipment_name,'equipmentTypeName'=>$equipmentTypeName);
        $srno++;
      }
    }
    if (empty($user_arr)) {
      $user_arr = array();
    }
    $record = array('success' => true, 'msg' => $msgDataFound, 'data' => array('user_arr' => $user_arr));
    jsonSendEncode($record);
  }
}



function getEquipmentName($data) {

 // alert('hi');

  global $mysqli;
  global $onerror;
  include_once('language_message.php');
  include_once('site_config.php');
  //print_r($data);
  if(empty($data['sel2'])) {
    $record=array('success'=>false, 'msg'=>$msgEmptyAll, 'data'=>array());
    jsonSendEncode($record);
  } else {

    
    $cmp_id  = $data['sel2'];

   
    $srno=1;
  //echo "SELECT `sub_service_id`, `sub_service_name` FROM `sub_service_master`where delete_flag='0' and service_id=$cmp_id";exit;
 
      $check_data=$mysqli->prepare("SELECT `equipment_id`, `equipment_name` FROM `equipment_master`where delete_flag='0' and equipment_type_id=?");
 
    $check_data->bind_param('i',$cmp_id);
    $check_data->execute();
    $check_data->store_result();
    $check_data_count=$check_data->num_rows;
    if($check_data_count >0) {
      $check_data->bind_result($equipment_id,$equipment_name);
      while($check_data->fetch()){
         //$createtime=date('d-m-Y h:i A',strtotime($createtime));
      
        $user_arr[] = array('srno'=>$srno, 'equipment_id'=>$equipment_id,'equipment_name'=>$equipment_name);
        $srno++;
      }
    }
    if(empty($user_arr)){
      $user_arr = array();
    }
    $record=array('success'=>true, 'msg'=>$msgDataFound, 'data'=>array('user_arr'=>$user_arr));
    jsonSendEncode($record);
  }
}



function  addMaintainance($data)
{

  //echo "<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  include_once('site_config.php');
  include_once('mailFunctions.php');
  if (empty($_POST['ititle'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  }



  $maintainance_title= $data['ititle'];
  $maintainance_date = $data['idate'];

  if(!isset($data['nidate'])){
  $next_maintainance_date ='';
  }else{
  $next_maintainance_date =$data['nidate'];

  }
  
  $equipment_type =$data['etype'];
  $equipment_id =$data['equipment'];

  // $check_category = $mysqli->prepare("SELECT category_id from category_master where delete_flag='0' and category_name=? ");
  // $check_category->bind_param("s", $category_name);
  // $check_category->execute();
  // $check_category->store_result();
  // $check_category_count = $check_category->num_rows;
  // if ($check_category_count > 0) {

  //   $record = array('success' => false, 'msg' => $msgCategoryExist, 'data' => array());
  //   jsonSendEncode($record);
  // }
 //-------------------------- check user email --------------------------

  $updatetime = date('Y-m-d H:i:s');
  $createtime = date('Y-m-d H:i:s');

 

  $sql ="INSERT INTO `maintainance_master`(`equipment_type_id`,`equipment_id`, `maintainance_title`, `maintainance_date`,`maintainace_next_date`,  `createtime`, `updatetime`)  VALUES (?,?,?,?,?,?,?)";
  $result = $mysqli->prepare($sql);
  $result->bind_param('iisssss', $equipment_type,$equipment_id,$maintainance_title,$maintainance_date,$next_maintainance_date, $createtime, $updatetime);
  $result->execute();
  $row = $mysqli->affected_rows;
  if ($row <= 0) {
    $record = array('success' => false, 'msg' => $MaintainanceNotAdded, 'data' => array());
    jsonSendEncode($record);
  }


  $record = array('success' => true, 'msg' => $MaintainanceAdded, 'data' => array());
  jsonSendEncode($record);
}



function EditMaintainance($data)
{
   //print_r($data);die;
  global $mysqli;
  global $onerror;

  include_once('language_message.php');
  // echo "hello"; die;
  if (empty($data['id'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $maintainance_id     =   $data['id'];
$maintainance_title= $data['ititle'];
  $maintainance_date = $data['idate'];

  if(!isset($data['nidate'])){
  $next_maintainance_date ='';
  }else{
  $next_maintainance_date =$data['nidate'];

  }
  
  $equipment_type =$data['etype'];
  $equipment_id =$data['equipment'];


    // Now check category Already added   

  //   $check_category = $mysqli->prepare("SELECT category_id from category_master where delete_flag='0' and category_name=? and category_id != ?");
  // $check_category->bind_param("si", $category_name,$cat_id);
  // $check_category->execute();
  // $check_category->store_result();
  // $check_category_count = $check_category->num_rows;
  // if ($check_category_count > 0) {

  //   $record = array('success' => false, 'msg' => $msgCategoryExist, 'data' => array());
  //   jsonSendEncode($record);
  // }      

   
    $updatetime     =   date('Y-m-d H:i:s');
    $update_all     =   $mysqli->prepare("UPDATE maintainance_master SET equipment_type_id=?,equipment_id=?,maintainance_title=?, maintainance_date=?,maintainace_next_date=?, updatetime=? WHERE maintainance_id=?");
    $update_all->bind_param("iissssi",$equipment_type,$equipment_id, $maintainance_title,$maintainance_date,$next_maintainance_date, $updatetime, $maintainance_id);
    $update_all->execute();
    $update = $mysqli->affected_rows;
    if ($update <= 0) {
      $record =   array('success' => false, 'msg' => $msgMaintainanceNotUpdate, 'data' => array());
      jsonSendEncode($record);
    };
    $record     =   array('success' => true, 'msg' => $msgMaintainanceUpdate, 'data' => array());
    jsonSendEncode($record);
  }
}



function deleteMaintainance($data)
{

  //echo"<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  if (empty($data['main_id'])) {
    $record =   array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $maintainance_id    = $data['main_id'];
    $check_user_id = $mysqli->prepare("SELECT maintainance_id from maintainance_master where delete_flag='0' and maintainance_id=?");
    $check_user_id->bind_param("i", $maintainance_id);
    $check_user_id->execute();
    $check_user_id->store_result();
    $check_user_id_count = $check_user_id->num_rows;
    if ($check_user_id_count <= 0) {
      $record = array('success' => false, 'msg' => $msgMaintainanceNotExist, 'data' => array());
      jsonSendEncode($record);
    }
    $delete_flag    =   1;
    $updatetime     =   date('Y-m-d H:i:s');
    // Delete Query
    $update_all     =   $mysqli->prepare("UPDATE maintainance_master set delete_flag=?, updatetime=? WHERE maintainance_id=?");
    $update_all->bind_param("isi", $delete_flag, $updatetime, $maintainance_id);
    $update_all->execute();
    $update         =   $mysqli->affected_rows;
    if ($update <= 0) {
      $record     =   array('success' => false, 'msg' => $getMaintainanceDeleteError, 'data' => array());
      jsonSendEncode($record);
    }
    $record         =   array('success' => true, 'msg' => $getMaintainanceDelete, 'data' => array());
    jsonSendEncode($record);
  }
}



function getMaintainance($data)
{
  global $mysqli;
  global $onerror;
  //global $item_onerror;
  include_once('language_message.php');
  //include_once('site_config.php');

  //print_r($data);
  if (empty($data['type'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $type     = $data['type'];
   
    $srno = 1;
    //for($i=0; $i<50; $i++){
    if ($type == 'all') {
      $check_data = $mysqli->prepare("SELECT `maintainance_id`, `equipment_type_id`, `equipment_id`, `maintainance_title`, `maintainance_date`, `maintainace_next_date`, `createtime` FROM `maintainance_master` where delete_flag=0  order by maintainance_id desc");
    }
    $check_data->execute();
    $check_data->store_result();
    $check_data_count = $check_data->num_rows;
    if ($check_data_count > 0) {
      $check_data->bind_result($maintainance_id, $equipment_type_id,$equipment_id, $maintainance_title,$maintainance_date,$maintainace_next_date,$createtime);
      while ($check_data->fetch()) {
        $createtime = date('d-m-Y h:i A', strtotime($createtime));
        $maintainance_date = date('d-m-Y', strtotime($maintainance_date));
     
          $maintainace_next_date1 = 'NA';
        if($maintainace_next_date != '0000-00-00'){
          $maintainace_next_date1 = date('d-m-Y', strtotime($maintainace_next_date));
          
        }else{
           $maintainance_next_date1 ='NA';  
        }
        $equipmentTypeName = getCategoryName($equipment_type_id);
        $equipmentName =  getEquipmentNameall($equipment_id);
       

        $action_html = '


           <div class="btn-group">

                          

                        

                        



                        <button type="button" class="btn btn-primary dropdown-toggle " data-bs-toggle="dropdown">Action</button>

                          <div class="dropdown-menu dropdown-menu-end">

                          

                            <a class="dropdown-item"  href="edit_maintainance.php?id='.encode($maintainance_id).'" ><i class="fa fa-edit"></i>&nbsp;Edit Maintainance</a>

                          



                            <a class="dropdown-item"  data-id="' . $maintainance_id . '" onClick="btnUserDeleteConfirm(this)"><i class="fa fa-trash"></i>&nbsp;Delete</a>

                            

                          

                          </div>



                        </div>





  ';


        $user_arr[] = array('srno' => $srno, 'maintainance_id' => $maintainance_id, 'action' => $action_html, 'maintainance_title' => $maintainance_title, 'createtime' => $createtime,'next_maintainance_date'=>$maintainace_next_date1,'equipmentTypeName'=>$equipmentTypeName,'maintainance_date'=>$maintainance_date,'equipmentName'=>$equipmentName);
        $srno++;
      }
    }
    if (empty($user_arr)) {
      $user_arr = array();
    }
    $record = array('success' => true, 'msg' => $msgDataFound, 'data' => array('user_arr' => $user_arr));
    jsonSendEncode($record);
  }
}





function  addInspectionType($data)
{

  //echo "<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  include_once('site_config.php');
  include_once('mailFunctions.php');
  if (empty($_POST['cat_name'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  }



  $inspection_type = $data['cat_name'];

  


  $updatetime = date('Y-m-d H:i:s');
  $createtime = date('Y-m-d H:i:s');

  

  $sql = "INSERT INTO `inspection_type_master`( `inspection_type`,  `createtime`, `updatetime`)  VALUES (?,?,?)";
  $result = $mysqli->prepare($sql);
  $result->bind_param('sss', $inspection_type, $createtime, $updatetime);
  $result->execute();
  $row = $mysqli->affected_rows;
  if ($row <= 0) {
    $record = array('success' => false, 'msg' => $InspectionTypeNotAdded, 'data' => array());
    jsonSendEncode($record);
  }


  $record = array('success' => true, 'msg' => $InspectionTypeAdded, 'data' => array());
  jsonSendEncode($record);
}



function editInspectionType($data)
{
   //print_r($data);die;
  global $mysqli;
  global $onerror;

  include_once('language_message.php');
  // echo "hello"; die;
  if (empty($data['id'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $inspection_id     =   decode($data['id']);
   // $image = $data['image'];
    $inspection_type =$data['cat_name'];


    
   
    $updatetime     =   date('Y-m-d H:i:s');
    $update_all     =   $mysqli->prepare("UPDATE inspection_type_master SET inspection_type=?, updatetime=? WHERE inspection_type_id=?");
    $update_all->bind_param("ssi", $inspection_type, $updatetime, $inspection_id);
    $update_all->execute();
    $update = $mysqli->affected_rows;
    if ($update <= 0) {
      $record =   array('success' => false, 'msg' => $msgInspectionTypeNotUpdate, 'data' => array());
      jsonSendEncode($record);
    };
    $record     =   array('success' => true, 'msg' => $msgInspectionTypeUpdate, 'data' => array());
    jsonSendEncode($record);
  }
}



function getInspectionType($data)
{
  global $mysqli;
  global $onerror;
  //global $item_onerror;
  include_once('language_message.php');
  //include_once('site_config.php');

  //print_r($data);
  if (empty($data['type'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $type     = $data['type'];
    $srno = 1;
    //for($i=0; $i<50; $i++){
    if ($type == 'all') {
      $check_data = $mysqli->prepare("SELECT `inspection_type_id`, `inspection_type`, `createtime` FROM `inspection_type_master` where delete_flag=0  order by inspection_type_id desc");
    }
    $check_data->execute();
    $check_data->store_result();
    $check_data_count = $check_data->num_rows;
    if ($check_data_count > 0) {
      $check_data->bind_result($inspection_type_id, $inspection_type, $createtime);
      while ($check_data->fetch()) {
        $createtime = date('d-m-Y h:i A', strtotime($createtime));
     
        $action_html = '


           <div class="btn-group">

                          

                        

                        



                        <button type="button" class="btn btn-primary dropdown-toggle " data-bs-toggle="dropdown">Action</button>

                          <div class="dropdown-menu dropdown-menu-end">

                          

                            <a class="dropdown-item"  href="#myModal1" data-bs-toggle="modal"  data-id="' . encode($inspection_type_id) . '"   data-name="' . $inspection_type . '"  onClick="btnEditCategory(this)"><i class="fa fa-edit"></i>&nbsp;Edit</a>

                          

                              

                            <a class="dropdown-item"  data-id="' . $inspection_type_id . '" onClick="btnUserDeleteConfirm(this)"><i class="fa fa-trash"></i>&nbsp;Delete</a>

                            

                          

                          </div>



                        </div>





  ';


        $user_arr[] = array('srno' => $srno, 'inspection_type_id' => $inspection_type_id, 'action' => $action_html, 'inspection_type' => $inspection_type, 'createtime' => $createtime);
        $srno++;
      }
    }
    if (empty($user_arr)) {
      $user_arr = array();
    }
    $record = array('success' => true, 'msg' => $msgDataFound, 'data' => array('user_arr' => $user_arr));
    jsonSendEncode($record);
  }
}


function deleteInspectionType($data)
{

  //echo"<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  if (empty($data['ins_id'])) {
    $record =   array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $ins_id    = $data['ins_id'];
    $check_user_id = $mysqli->prepare("SELECT inspection_type_id from inspection_type_master where delete_flag='0' and inspection_type_id=?");
    $check_user_id->bind_param("i", $ins_id);
    $check_user_id->execute();
    $check_user_id->store_result();
    $check_user_id_count = $check_user_id->num_rows;
    if ($check_user_id_count <= 0) {
      $record = array('success' => false, 'msg' => $msgInspectionTypeNotExist, 'data' => array());
      jsonSendEncode($record);
    }
    $delete_flag    =   1;
    $updatetime     =   date('Y-m-d H:i:s');
    // Delete Query
    $update_all     =   $mysqli->prepare("UPDATE inspection_type_master set delete_flag=?, updatetime=? WHERE inspection_type_id=?");
    $update_all->bind_param("isi", $delete_flag, $updatetime, $ins_id);
    $update_all->execute();
    $update         =   $mysqli->affected_rows;
    if ($update <= 0) {
      $record     =   array('success' => false, 'msg' => $getInspectionTypeDeleteError, 'data' => array());
      jsonSendEncode($record);
    }
    $record         =   array('success' => true, 'msg' => $getInspectionTypeDelete, 'data' => array());
    jsonSendEncode($record);
  }
}




function deleteDueDate($data)
{

  //echo"<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  if (empty($data['due_date_id'])) {
    $record =   array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $due_date_id    = $data['due_date_id'];
    $check_user_id = $mysqli->prepare("SELECT next_inspection_date_id from next_inspection_date_master where delete_flag='0' and next_inspection_date_id=?");
    $check_user_id->bind_param("i", $due_date_id);
    $check_user_id->execute();
    $check_user_id->store_result();
    $check_user_id_count = $check_user_id->num_rows;
    if ($check_user_id_count <= 0) {
      $record = array('success' => false, 'msg' => $msgInspectionDueDateNotExist, 'data' => array());
      jsonSendEncode($record);
    }
    $delete_flag    =   1;
    $updatetime     =   date('Y-m-d H:i:s');
    // Delete Query
    $update_all     =   $mysqli->prepare("UPDATE next_inspection_date_master set delete_flag=?, updatetime=? WHERE next_inspection_date_id=?");
    $update_all->bind_param("isi", $delete_flag, $updatetime, $due_date_id);
    $update_all->execute();
    $update         =   $mysqli->affected_rows;
    if ($update <= 0) {
      $record     =   array('success' => false, 'msg' => $getInspectionDueDateDeleteError, 'data' => array());
      jsonSendEncode($record);
    }
    $record         =   array('success' => true, 'msg' => $getInspectionDueDateDelete, 'data' => array());
    jsonSendEncode($record);
  }
}



function getInspectionRequest($data)
{
  global $mysqli;
  global $onerror;
  //global $item_onerror;
  include_once('language_message.php');
  //include_once('site_config.php');

  //print_r($data);
  if (empty($data['type'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $type     = $data['type'];
    $srno = 1;
    //for($i=0; $i<50; $i++){
    $user_id =decode($data['user_id']);
    if ($type == 'all') {
      $check_data = $mysqli->prepare("SELECT  `inspection_id`,`user_id`, `equipment_type_id`,`equipment_id`, `inspection_type_id`, `inspection_title`, `inspection_date`,`description`, `createtime` FROM `inspection_master` where delete_flag=0  and user_id=? order by inspection_id desc");
    }
    $check_data->bind_param('i',$user_id);
    $check_data->execute();
    $check_data->store_result();
    $check_data_count = $check_data->num_rows;
    if ($check_data_count > 0) {
      $check_data->bind_result($inspection_id,$user_id, $equipment_type_id,$equipment_id, $inspection_type_id,$inspection_title,$inspection_date,$description,$createtime);
      while ($check_data->fetch()) {
        $createtime = date('d-m-Y h:i A', strtotime($createtime));
        $inspection_date = date('d-m-Y', strtotime($inspection_date));
         $equipment_name = getEquipmentNameall($equipment_id);
        $equipmentTypeName = getCategoryName($equipment_type_id);
        $inspection_type_name =getInspectionTypeName($inspection_type_id);
       
         $userData = getUserDetails($user_id);
         if($userData != 'NA'){
              $userName =$userData['name'];
              $userMobile =$userData['mobile'];
              $userEmail =$userData['email'];
              $userImage =$userData['image'];
              $image_html = '<img  width="50px" src="../webservice/images/' . $userImage . '" class="rounded-circle circle-border m-b-md img-fix img-responsive" name="profile_image" id="previewholder" style="width: 70px; height: 70px;" alt="" onerror="this.src=' . $onerror . ';" >';
         }else{
           $userName ='NA';
             $userMobile ='NA';
              $userEmail ='NA';
              $image_html ='NA';
         }
        $action_html = '


           <div class="btn-group">

                          

                        

                        



                        <button type="button" class="btn btn-primary dropdown-toggle " data-bs-toggle="dropdown">Action</button>

                          <div class="dropdown-menu dropdown-menu-end">

                          

                            <a class="dropdown-item"  href="edit_inspection_request.php?id='.encode($inspection_id).'" ><i class="fa fa-edit"></i>&nbsp;Add Inspection Request</a>

                          
                              <li><a href="view_inspection_request.php?id=' . encode($inspection_id) . '"" class="dropdown-item"><i class="fa fa-eye"></i>&nbsp;View</a></li>



                          
                            

                          

                          </div>



                        </div>





  ';


        $user_arr[] = array('srno' => $srno, 'inspection_id' => $inspection_id, 'action' => $action_html, 'inspection_title' => $inspection_title, 'createtime' => $createtime,'equipmentTypeName'=>$equipmentTypeName,'inspection_date'=>$inspection_date,'equipment_name'=>$equipment_name,'userName'=>$userName,'inspection_type_name'=>$inspection_type_name,'userMobile'=>$userMobile,'userEmail'=>$userEmail,'image_html'=>$image_html,'description'=>$description);
        $srno++;
      }
    }
    if (empty($user_arr)) {
      $user_arr = array();
    }
    $record = array('success' => true, 'msg' => $msgDataFound, 'data' => array('user_arr' => $user_arr));
    jsonSendEncode($record);
  }
}



function  addInspectionRequest($data)
{

  //echo "<pre>";print_r($data);print_r($_FILES);exit;
  global $mysqli;
  include_once('language_message.php');
  include_once('site_config.php');
  include_once('mailFunctions.php');
  if (empty($_POST['user_id'])) {
    $record = array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  }



  $user_id= decode($data['user_id']);
  $inspection_id =$data['id'];
  $inspection_date = $data['idate'];
 $inspection_title =$data['ititle'];
 
  $inspection_type_id =$data['inspection_type_id'];

  // $check_category = $mysqli->prepare("SELECT category_id from category_master where delete_flag='0' and category_name=? ");
  // $check_category->bind_param("s", $category_name);
  // $check_category->execute();
  // $check_category->store_result();
  // $check_category_count = $check_category->num_rows;
  // if ($check_category_count > 0) {

  //   $record = array('success' => false, 'msg' => $msgCategoryExist, 'data' => array());
  //   jsonSendEncode($record);
  // }
 //-------------------------- check user email --------------------------

  $updatetime = date('Y-m-d H:i:s');
  $createtime = date('Y-m-d H:i:s');



  if (!empty($_FILES['image']['name'][0])) {

      $updatetime = date('Y-m-d H:i:s');
  $createtime = date('Y-m-d H:i:s');



     $sql ="INSERT INTO `inspection_request_master`(`inspection_id`,`user_id`,`inspection_type_id`, `inspection_title`,`inspection_date`, `createtime`, `updatetime`)  VALUES (?,?,?,?,?,?,?)";
  $result = $mysqli->prepare($sql);
  $result->bind_param('iiissss', $inspection_id,$user_id,$inspection_type_id,$inspection_title,$inspection_date,$createtime, $updatetime);
  $result->execute();
  $row = $mysqli->affected_rows;
  if ($row <= 0) {
    $record = array('success' => false, 'msg' => $InspectionNotAdded, 'data' => array());
    jsonSendEncode($record);
  }

  $last_id  =$mysqli->insert_id;
 
    $next_inspection_date =$data['answer'];
                for ($i=0; $i <count($next_inspection_date) ; $i++) { 
                  $sql = "INSERT INTO `request_next_inspection_date_master`(`inspection_request_id`, `next_inspection_date`,`createtime`,`updatetime`) VALUES(?,?,?,?)";
               $result = $mysqli->prepare($sql);
               $result->bind_param('isss',$last_id,$next_inspection_date[$i],$createtime,$updatetime);
               $result->execute();
               $row= $mysqli->affected_rows;
               if($row <= 0){
                 $record=array('success'=>false,'msg' =>$InspectionNotAdded, 'data'=>array()); 
                 jsonSendEncode($record); 
               }
                }
                 
                          $user_image = $_FILES['image'];
          // Code to upload the file starts
                          $file = $user_image;
                          $folder_name = '../webservice/images';
                          $file_type = 'image';
                       
            $upload_status = uploadFileMultiple($file, $folder_name, $file_type);
            // print_r($upload_status);
            if ($upload_status == 'error') {
                $record = array('success' => false, 'msg' => $msgErrorFileUpload, 'data' => array());
                jsonSendEncode($record);
            }
            foreach ($upload_status as $images) {
                //echo "INSERT INTO product_image_master(product_id, pro_image, delete_flag, createdate) VALUES ($product_id,$upload_status,$delete_flag,$createtime)";
                $insertImage = $mysqli->prepare("INSERT INTO inspection_request_image_master(inspection_request_id, image, createtime,updatetime) VALUES (?,?,?,?)");
                $insertImage->bind_param("isss", $last_id, $images, $createtime,$updatetime);
                $insertImage->execute();
                $insertImageRowAffected = $mysqli->affected_rows;
                if ($insertImageRowAffected < 0) {
                    $record = array('success' => false, 'msg' => $msgProductImageAddedError, 'data' => array());
                    jsonSendEncode($record);
                }
            }


                         

          // Code to upload the file starts
                        } else {
  $updatetime = date('Y-m-d H:i:s');
  $createtime = date('Y-m-d H:i:s');


                          $sql ="INSERT INTO `inspection_request_master`(`inspection_id`,`user_id`,`inspection_type_id`, `inspection_title`,`inspection_date`, `createtime`, `updatetime`)  VALUES (?,?,?,?,?,?,?)";
  $result = $mysqli->prepare($sql);
  $result->bind_param('iiissss', $inspection_id,$user_id,$inspection_type_id,$inspection_title,$inspection_date,$createtime, $updatetime);
  $result->execute();
  $row = $mysqli->affected_rows;
  if ($row <= 0) {
    $record = array('success' => false, 'msg' => $InspectionNotAdded, 'data' => array());
    jsonSendEncode($record);
  }

  $last_id  =$mysqli->insert_id;
 
    $next_inspection_date =$data['answer'];
                for ($i=0; $i <count($next_inspection_date) ; $i++) { 
                  $sql = "INSERT INTO `request_next_inspection_date_master`(`inspection_request_id`, `next_inspection_date`,`createtime`,`updatetime`) VALUES(?,?,?,?)";
               $result = $mysqli->prepare($sql);
               $result->bind_param('isss',$last_id,$next_inspection_date[$i],$createtime,$updatetime);
               $result->execute();
               $row= $mysqli->affected_rows;
               if($row <= 0){
                 $record=array('success'=>false,'msg' =>$InspectionNotAdded, 'data'=>array()); 
                 jsonSendEncode($record); 
               }
                }
                 

                         
                        }

 

  

  $record = array('success' => true, 'msg' => $InspectionAdded, 'data' => array());
  jsonSendEncode($record);
}



function deleteComponent($data)
{

  //echo"<pre>";print_r($data);exit;
  global $mysqli;
  include_once('language_message.php');
  if (empty($data['cmp_id'])) {
    $record =   array('success' => false, 'msg' => $msgEmptyAll, 'data' => array());
    jsonSendEncode($record);
  } else {
    $cmp_id    = $data['cmp_id'];
    $check_user_id = $mysqli->prepare("SELECT equipment_component_id from equipment_component_master where delete_flag='0' and equipment_component_id=?");
    $check_user_id->bind_param("i", $cmp_id);
    $check_user_id->execute();
    $check_user_id->store_result();
    $check_user_id_count = $check_user_id->num_rows;
    if ($check_user_id_count <= 0) {
      $record = array('success' => false, 'msg' => $ComponentNotExist, 'data' => array());
      jsonSendEncode($record);
    }
    $delete_flag    =   1;
    $updatetime     =   date('Y-m-d H:i:s');
    // Delete Query
    $update_all     =   $mysqli->prepare("UPDATE equipment_component_master set delete_flag=?, updatetime=? WHERE equipment_component_id=?");
    $update_all->bind_param("isi", $delete_flag, $updatetime, $cmp_id);
    $update_all->execute();
    $update         =   $mysqli->affected_rows;
    if ($update <= 0) {
      $record     =   array('success' => false, 'msg' => $ComponentDeleteError, 'data' => array());
      jsonSendEncode($record);
    }
    $record         =   array('success' => true, 'msg' => $ComponentDelete, 'data' => array());
    jsonSendEncode($record);
  }
}












    



























                
        















