<?php

namespace App\Http\Controllers;

use App\Models\PostData;
use App\Models\PostImage;
use App\Models\PostLike;
use App\Models\comments_adds;
use Illuminate\Http\Request;
use App\Models\Education;
use App\Models\UserModel;
use App\Models\Organisation;
use App\Models\Follower;
use App\Models\social_media_link;
use Illuminate\Support\Facades\Session;

class PostController extends Controller
{
  // Upload Post
  public function UploadPost(Request $request)
  {
    $email_id = $request->postEmailid;
    $postText = $request->postboxx;
    $fullName = $request->fullname;
    $imgPath = "";

    $datee = date('Y-m-d H_i_s') . '';


    // Count # of uploaded files in array
    $total = (int) count($_FILES['uploadImg']['name']);
    for ($i = 0; $i < $total; $i++) {
      //Get the temp file path
      $tmpFilePath = $_FILES['uploadImg']['tmp_name'][$i];
      $file_name = $_FILES["uploadImg"]["name"][$i];
      $ext = pathinfo($file_name, PATHINFO_EXTENSION);
      $postimgeName = $i . "." . $ext;
      //Make sure we have a file path
      if ($tmpFilePath != "") {
        $path = public_path("PostImages/" . $email_id . "/" . $datee);
        //Setup our new file path

        if (!file_exists($path)) {
          mkdir($path, 0777, true);
        }
        //Upload the file into the temp dir
        if (move_uploaded_file($tmpFilePath, "PostImages/" . $email_id . "/" . $datee . "/" . $postimgeName)) {

          //Handle other code here

        }
      }
    }

    //...............................................................................
// Count # of uploaded files in array
    $total = (int) count($_FILES['uploadImg1']['name']);
    for ($i = 0; $i < $total; $i++) {
      //Get the temp file path
      $tmpFilePath = $_FILES['uploadImg1']['tmp_name'][$i];
      $file_name = $_FILES["uploadImg1"]["name"][$i];
      $ext = pathinfo($file_name, PATHINFO_EXTENSION);
      $postimgeName = $i . "2." . $ext;
      //Make sure we have a file path
      if ($tmpFilePath != "") {
        $path = public_path("PostImages/" . $email_id . "/" . $datee);
        //Setup our new file path

        if (!file_exists($path)) {
          mkdir($path, 0777, true);
        }
        //Upload the file into the temp dir
        if (move_uploaded_file($tmpFilePath, "PostImages/" . $email_id . "/" . $datee . "/" . $postimgeName)) {

          //Handle other code here

        }
      }
    }
    //...............................................................................
// Count # of uploaded files in array
    $total = (int) count($_FILES['uploadImg2']['name']);
    for ($i = 0; $i < $total; $i++) {
      //Get the temp file path
      $tmpFilePath = $_FILES['uploadImg2']['tmp_name'][$i];
      $file_name = $_FILES["uploadImg2"]["name"][$i];
      $ext = pathinfo($file_name, PATHINFO_EXTENSION);
      $postimgeName = $i . "3." . $ext;
      //Make sure we have a file path
      if ($tmpFilePath != "") {
        $path = public_path("PostImages/" . $email_id . "/" . $datee);
        //Setup our new file path

        if (!file_exists($path)) {
          mkdir($path, 0777, true);
        }
        //Upload the file into the temp dir
        if (move_uploaded_file($tmpFilePath, "PostImages/" . $email_id . "/" . $datee . "/" . $postimgeName)) {

          //Handle other code here

        }
      }
    }
    //...............................................................................
// Count # of uploaded files in array
    $total = (int) count($_FILES['uploadImg3']['name']);
    for ($i = 0; $i < $total; $i++) {
      //Get the temp file path
      $tmpFilePath = $_FILES['uploadImg3']['tmp_name'][$i];
      $file_name = $_FILES["uploadImg3"]["name"][$i];
      $ext = pathinfo($file_name, PATHINFO_EXTENSION);
      $postimgeName = $i . "4." . $ext;
      //Make sure we have a file path
      if ($tmpFilePath != "") {
        $path = public_path("PostImages/" . $email_id . "/" . $datee);
        //Setup our new file path

        if (!file_exists($path)) {
          mkdir($path, 0777, true);
        }
        //Upload the file into the temp dir
        if (move_uploaded_file($tmpFilePath, "PostImages/" . $email_id . "/" . $datee . "/" . $postimgeName)) {

          //Handle other code here

        }
      }
    }
    //...............................................................................
// Count # of uploaded files in array
    $total = (int) count($_FILES['uploadImg4']['name']);
    for ($i = 0; $i < $total; $i++) {
      //Get the temp file path
      $tmpFilePath = $_FILES['uploadImg4']['tmp_name'][$i];
      $file_name = $_FILES["uploadImg4"]["name"][$i];
      $ext = pathinfo($file_name, PATHINFO_EXTENSION);
      $postimgeName = $i . "5." . $ext;
      //Make sure we have a file path
      if ($tmpFilePath != "") {
        $path = public_path("PostImages/" . $email_id . "/" . $datee);
        //Setup our new file path

        if (!file_exists($path)) {
          mkdir($path, 0777, true);
        }
        //Upload the file into the temp dir
        if (move_uploaded_file($tmpFilePath, "PostImages/" . $email_id . "/" . $datee . "/" . $postimgeName)) {

          //Handle other code here

        }
      }
    }

    //...............................................................................
// Count # of uploaded files in array
    $total = (int) count($_FILES['uploadImg5']['name']);
    for ($i = 0; $i < $total; $i++) {
      //Get the temp file path
      $tmpFilePath = $_FILES['uploadImg5']['tmp_name'][$i];
      $file_name = $_FILES["uploadImg5"]["name"][$i];
      $ext = pathinfo($file_name, PATHINFO_EXTENSION);
      $postimgeName = $i . "6." . $ext;
      //Make sure we have a file path
      if ($tmpFilePath != "") {
        $path = public_path("PostImages/" . $email_id . "/" . $datee);
        //Setup our new file path

        if (!file_exists($path)) {
          mkdir($path, 0777, true);
        }
        //Upload the file into the temp dir
        if (move_uploaded_file($tmpFilePath, "PostImages/" . $email_id . "/" . $datee . "/" . $postimgeName)) {

          //Handle other code here

        }
      }
    }

    //...............................................................................
// Count # of uploaded files in array
    $total = (int) count($_FILES['uploadImg6']['name']);
    for ($i = 0; $i < $total; $i++) {
      //Get the temp file path
      $tmpFilePath = $_FILES['uploadImg6']['tmp_name'][$i];
      $file_name = $_FILES["uploadImg6"]["name"][$i];
      $ext = pathinfo($file_name, PATHINFO_EXTENSION);
      $postimgeName = $i . "7." . $ext;
      //Make sure we have a file path
      if ($tmpFilePath != "") {
        $path = public_path("PostImages/" . $email_id . "/" . $datee);
        //Setup our new file path

        if (!file_exists($path)) {
          mkdir($path, 0777, true);
        }
        //Upload the file into the temp dir
        if (move_uploaded_file($tmpFilePath, "PostImages/" . $email_id . "/" . $datee . "/" . $postimgeName)) {

          //Handle other code here

        }
      }
    }
    //...............................................................................
// Count # of uploaded files in array
    $total = (int) count($_FILES['uploadImg7']['name']);
    for ($i = 0; $i < $total; $i++) {
      //Get the temp file path
      $tmpFilePath = $_FILES['uploadImg7']['tmp_name'][$i];
      $file_name = $_FILES["uploadImg7"]["name"][$i];
      $ext = pathinfo($file_name, PATHINFO_EXTENSION);
      $postimgeName = $i . "8." . $ext;
      //Make sure we have a file path
      if ($tmpFilePath != "") {
        $path = public_path("PostImages/" . $email_id . "/" . $datee);
        //Setup our new file path

        if (!file_exists($path)) {
          mkdir($path, 0777, true);
        }
        //Upload the file into the temp dir
        if (move_uploaded_file($tmpFilePath, "PostImages/" . $email_id . "/" . $datee . "/" . $postimgeName)) {

          //Handle other code here

        }
      }
    }
    //...............................................................................
// Count # of uploaded files in array
    $total = (int) count($_FILES['uploadImg8']['name']);
    for ($i = 0; $i < $total; $i++) {
      //Get the temp file path
      $tmpFilePath = $_FILES['uploadImg8']['tmp_name'][$i];
      $file_name = $_FILES["uploadImg8"]["name"][$i];
      $ext = pathinfo($file_name, PATHINFO_EXTENSION);
      $postimgeName = $i . "." . $ext;
      //Make sure we have a file path
      if ($tmpFilePath != "") {
        $path = public_path("PostImages/" . $email_id . "/" . $datee);
        //Setup our new file path

        if (!file_exists($path)) {
          mkdir($path, 0777, true);
        }
        //Upload the file into the temp dir
        if (move_uploaded_file($tmpFilePath, "PostImages/" . $email_id . "/" . $datee . "/" . $postimgeName)) {

          //Handle other code here

        }
      }
    }
    $profil_picture = "";
    $postimgeName = Session::get('imgnamearray');
    Session::put('imgnamearray', NULL);

    PostData::create([
      'email_id' => $email_id,
      'FullName' => $fullName,
      'PostText' => $postText,
      'DateTime' => $datee,
      'PostImgeName' => $datee,
      'isJobPost' => 'No'
    ]);


        return redirect()->route('home');


  }

  public function UploadPostMobile(Request $request)
  {
    $email_id = $request->postEmailid;
    $postText = $request->postboxx;
    $fullName = $request->fullname;
    $imgPath = "";

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


    //   $error=array();
// $extension=array("jpeg","jpg","png","gif");
// foreach($_FILES["uploadImg"]["tmp_name"] as $key=>$tmp_name) {
//             $file_name = $_FILES["uploadImg"]["name"];
//             $file_size = $_FILES["uploadImg"]["size"];
//             $file_tmp = $_FILES["uploadImg"]["tmp_name"];
//             $file_type = $_FILES["uploadImg"]["type"];

    //             $file = explode('.',$_FILES["uploadImg"]["name"]);
//             $file_raw = end($file);
//             $file_ext = strtolower($file_raw);
//           $postimgeName=$email_id. $datee.$file_ext;
//                 move_uploaded_file($file_tmp,"PostImages/".$email_id."/".$postimgeName);


    // }








    // Count # of uploaded files in array
    $total = (int) count($_FILES['uploadImg']['name']);

    // Loop through each file
    for ($i = 0; $i < $total; $i++) {

      //Get the temp file path
      $tmpFilePath = $_FILES['uploadImg']['tmp_name'][$i];
      $file_name = $_FILES["uploadImg"]["name"][$i];
      $ext = pathinfo($file_name, PATHINFO_EXTENSION);
      $postimgeName = $i . "." . $ext;
      //Make sure we have a file path
      if ($tmpFilePath != "") {
        $path = public_path("PostImages/" . $email_id . "/" . $datee);
        //Setup our new file path

        if (!file_exists($path)) {
          mkdir($path, 0777, true);
        }
        //Upload the file into the temp dir
        if (move_uploaded_file($tmpFilePath, "PostImages/" . $email_id . "/" . $datee . "/" . $postimgeName)) {

          //Handle other code here

        }
      }
    }

    // Count # of uploaded files in array
    $total = (int) count($_FILES['uploadImg1']['name']);

    // Loop through each file
    for ($i = 0; $i < $total; $i++) {

      //Get the temp file path
      $tmpFilePath = $_FILES['uploadImg1']['tmp_name'][$i];
      $file_name = $_FILES["uploadImg1"]["name"][$i];
      $ext = pathinfo($file_name, PATHINFO_EXTENSION);
      $postimgeName = $i . "1." . $ext;
      //Make sure we have a file path
      if ($tmpFilePath != "") {
        $path = public_path("PostImages/" . $email_id . "/" . $datee);
        //Setup our new file path

        if (!file_exists($path)) {
          mkdir($path, 0777, true);
        }
        //Upload the file into the temp dir
        if (move_uploaded_file($tmpFilePath, "PostImages/" . $email_id . "/" . $datee . "/" . $postimgeName)) {

          //Handle other code here

        }
      }
    }

    // Count # of uploaded files in array
    $total = (int) count($_FILES['uploadImg2']['name']);

    // Loop through each file
    for ($i = 0; $i < $total; $i++) {

      //Get the temp file path
      $tmpFilePath = $_FILES['uploadImg2']['tmp_name'][$i];
      $file_name = $_FILES["uploadImg2"]["name"][$i];
      $ext = pathinfo($file_name, PATHINFO_EXTENSION);
      $postimgeName = $i . "2." . $ext;
      //Make sure we have a file path
      if ($tmpFilePath != "") {
        $path = public_path("PostImages/" . $email_id . "/" . $datee);
        //Setup our new file path

        if (!file_exists($path)) {
          mkdir($path, 0777, true);
        }
        //Upload the file into the temp dir
        if (move_uploaded_file($tmpFilePath, "PostImages/" . $email_id . "/" . $datee . "/" . $postimgeName)) {

          //Handle other code here

        }
      }
    }

    // Count # of uploaded files in array
    $total = (int) count($_FILES['uploadImg3']['name']);

    // Loop through each file
    for ($i = 0; $i < $total; $i++) {

      //Get the temp file path
      $tmpFilePath = $_FILES['uploadImg3']['tmp_name'][$i];
      $file_name = $_FILES["uploadImg3"]["name"][$i];
      $ext = pathinfo($file_name, PATHINFO_EXTENSION);
      $postimgeName = $i . "3." . $ext;
      //Make sure we have a file path
      if ($tmpFilePath != "") {
        $path = public_path("PostImages/" . $email_id . "/" . $datee);
        //Setup our new file path

        if (!file_exists($path)) {
          mkdir($path, 0777, true);
        }
        //Upload the file into the temp dir
        if (move_uploaded_file($tmpFilePath, "PostImages/" . $email_id . "/" . $datee . "/" . $postimgeName)) {

          //Handle other code here

        }
      }
    }

    // Count # of uploaded files in array
    $total = (int) count($_FILES['uploadImg4']['name']);

    // Loop through each file
    for ($i = 0; $i < $total; $i++) {

      //Get the temp file path
      $tmpFilePath = $_FILES['uploadImg4']['tmp_name'][$i];
      $file_name = $_FILES["uploadImg4"]["name"][$i];
      $ext = pathinfo($file_name, PATHINFO_EXTENSION);
      $postimgeName = $i . "4." . $ext;
      //Make sure we have a file path
      if ($tmpFilePath != "") {
        $path = public_path("PostImages/" . $email_id . "/" . $datee);
        //Setup our new file path

        if (!file_exists($path)) {
          mkdir($path, 0777, true);
        }
        //Upload the file into the temp dir
        if (move_uploaded_file($tmpFilePath, "PostImages/" . $email_id . "/" . $datee . "/" . $postimgeName)) {

          //Handle other code here

        }
      }
    }

    // Count # of uploaded files in array
    $total = (int) count($_FILES['uploadImg5']['name']);

    // Loop through each file
    for ($i = 0; $i < $total; $i++) {

      //Get the temp file path
      $tmpFilePath = $_FILES['uploadImg5']['tmp_name'][$i];
      $file_name = $_FILES["uploadImg5"]["name"][$i];
      $ext = pathinfo($file_name, PATHINFO_EXTENSION);
      $postimgeName = $i . "5." . $ext;
      //Make sure we have a file path
      if ($tmpFilePath != "") {
        $path = public_path("PostImages/" . $email_id . "/" . $datee);
        //Setup our new file path

        if (!file_exists($path)) {
          mkdir($path, 0777, true);
        }
        //Upload the file into the temp dir
        if (move_uploaded_file($tmpFilePath, "PostImages/" . $email_id . "/" . $datee . "/" . $postimgeName)) {

          //Handle other code here

        }
      }
    }

    // Count # of uploaded files in array
    $total = (int) count($_FILES['uploadImg6']['name']);

    // Loop through each file
    for ($i = 0; $i < $total; $i++) {

      //Get the temp file path
      $tmpFilePath = $_FILES['uploadImg6']['tmp_name'][$i];
      $file_name = $_FILES["uploadImg6"]["name"][$i];
      $ext = pathinfo($file_name, PATHINFO_EXTENSION);
      $postimgeName = $i . "6." . $ext;
      //Make sure we have a file path
      if ($tmpFilePath != "") {
        $path = public_path("PostImages/" . $email_id . "/" . $datee);
        //Setup our new file path

        if (!file_exists($path)) {
          mkdir($path, 0777, true);
        }
        //Upload the file into the temp dir
        if (move_uploaded_file($tmpFilePath, "PostImages/" . $email_id . "/" . $datee . "/" . $postimgeName)) {

          //Handle other code here

        }
      }
    }

    // Count # of uploaded files in array
    $total = (int) count($_FILES['uploadImg7']['name']);

    // Loop through each file
    for ($i = 0; $i < $total; $i++) {

      //Get the temp file path
      $tmpFilePath = $_FILES['uploadImg7']['tmp_name'][$i];
      $file_name = $_FILES["uploadImg7"]["name"][$i];
      $ext = pathinfo($file_name, PATHINFO_EXTENSION);
      $postimgeName = $i . "7." . $ext;
      //Make sure we have a file path
      if ($tmpFilePath != "") {
        $path = public_path("PostImages/" . $email_id . "/" . $datee);
        //Setup our new file path

        if (!file_exists($path)) {
          mkdir($path, 0777, true);
        }
        //Upload the file into the temp dir
        if (move_uploaded_file($tmpFilePath, "PostImages/" . $email_id . "/" . $datee . "/" . $postimgeName)) {

          //Handle other code here

        }
      }
    }

    // Count # of uploaded files in array
    $total = (int) count($_FILES['uploadImg8']['name']);

    // Loop through each file
    for ($i = 0; $i < $total; $i++) {

      //Get the temp file path
      $tmpFilePath = $_FILES['uploadImg8']['tmp_name'][$i];
      $file_name = $_FILES["uploadImg8"]["name"][$i];
      $ext = pathinfo($file_name, PATHINFO_EXTENSION);
      $postimgeName = $i . "8." . $ext;
      //Make sure we have a file path
      if ($tmpFilePath != "") {
        $path = public_path("PostImages/" . $email_id . "/" . $datee);
        //Setup our new file path

        if (!file_exists($path)) {
          mkdir($path, 0777, true);
        }
        //Upload the file into the temp dir
        if (move_uploaded_file($tmpFilePath, "PostImages/" . $email_id . "/" . $datee . "/" . $postimgeName)) {

          //Handle other code here

        }
      }
    }

    $profil_picture = "";

    $postimgeName = Session::get('imgnamearray');

    Session::put('imgnamearray', NULL);

    PostData::create([
      'email_id' => $email_id,
      'FullName' => $fullName,
      'PostText' => $postText,
      'DateTime' => $datee,
      'PostImgeName' => $datee,
    ]);

    return redirect()->route('homemob');
  }

  // Upload Image
  public function UploadPostImg(Request $request)
  {


    $countfiles = count($_FILES['uploadImg']['name']);

    // Upload Location
    $upload_location = "PostImages/";

    // To store uploaded files path
    $files_arr = array();

    // Loop all files
    for ($index = 0; $index < $countfiles; $index++) {

      if (isset($_FILES['uploadImg']['name'][$index]) && $_FILES['uploadImg']['name'][$index] != '') {
        // File name
        $filename = $_FILES['uploadImg']['name'][$index];

        // Get extension
        $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));

        // Valid image extension
        $valid_ext = array("png", "jpeg", "jpg");

        // Check extension
        if (in_array($ext, $valid_ext)) {

          // File path
          $path = $upload_location . $filename;

          // Upload file
          if (move_uploaded_file($_FILES['uploadImg']['tmp_name'][$index], $path)) {
            $files_arr[] = $path;
          }
        }
      }
    }

    echo json_encode($files_arr);
    die;






























    // $oldV = Session::get('imgnamearray');

    // $email_id = $request->postEmailid;
    // $imgPath = "";

    // $email_id = "hassan@gmail.com";
    // $profil_picture = "";

    // $position = strpos($email_id, '@');

    // $postimgeName = substr($email_id, 0, $position);

    // $postimgeName = $postimgeName.rand(1,300000);

    // // $file_ext1 = strtolower(end(explode('.',$_FILES['uploadImg']['name'])));
    // $file = explode('.',$_FILES['uploadImg']['name']);
    // $file_raw = end($file);
    // $file_ext1 = strtolower($file_raw);


    // if(strlen($file_ext1)){
    //     $postimgeName = $postimgeName .'.'.$file_ext1;
    // }else{
    //     $postimgeName ='NULL';
    // }

    // PostImage::create([
    //     'email_id' => $email_id,
    //     'img_name' => $postimgeName,
    // ]);

    // if(isset($_FILES['uploadImg'])){
    //     $errors = array();
    //     $file_name = $_FILES['uploadImg']['name'];
    //     $file_size = $_FILES['uploadImg']['size'];
    //     $file_tmp = $_FILES['uploadImg']['tmp_name'];
    //     $file_type = $_FILES['uploadImg']['type'];

    //     $file = explode('.',$_FILES['uploadImg']['name']);
    //     $file_raw = end($file);
    //     $file_ext = strtolower($file_raw);

    //     $extensions = array("jpeg","jpg","png");

    //     if(strlen($oldV) >2){
    //         Session::put('imgnamearray', $oldV.':'.$postimgeName);
    //     }
    //     else{
    //         Session::put('imgnamearray', $postimgeName);
    //     }

    //     if(empty($errors) == true){
    //         move_uploaded_file($file_tmp,"PostImages/".$postimgeName);

    //     }
    //     else{
    //         print_r($errors);
    //     }
    //   }
  }
  public function searchResult()
  {
    if (isset($_GET["term"])) {
      $found1 = false;
      $found2 = false;
      $found3 = false;

      $searchCriteria = $_GET["term"];
      session::put('searchBy', $searchCriteria);

      $delimiter = ' ';
      $words = explode($delimiter, $searchCriteria);
      foreach ($words as $word) {
        $result4 = UserModel::where('first_name', 'LIKE', "%" . str_replace(' ', '', $word) . "%")->orwhere('second_name', 'LIKE', "%" . str_replace(' ', '', $word) . "%")->get();
        if (count($result4) == 0) {
          break;
        }
      }


      $session_emailId = Session::get('emailId');
      $counterRec = 0;

      if (count($result4) > 0) {
        $found1 = true;
        foreach ($result4 as $roww) {
          if($roww['account_status']=='Active'){


          $counterRec = $counterRec + 1;
          if ($counterRec == 5) {
            break;
          }
          $firstName = $roww["first_name"];
          $secondName = $roww["second_name"];
          $imageName = $roww["profile_picture"];
          $emailIDD = $roww['email_id'];
          $temp_array = array();
          //   $temp_array['value'] ='UserProfile?email_ID_Visiter='.$emailIDD.'&email_ID_User='.$session_emailId.'"';
          $temp_array['label'] = '<img src="ProfileImages/Images/' . $imageName . '" width="40" height="40" style="border-radius: 50%;" />&nbsp;&nbsp;&nbsp;' . $firstName . ' ' . $secondName . '';

          // $temp_array['label']  ='<a href="UserProfile?email_ID_Visiter='.$emailIDD.'&email_ID_User='.$session_emailId.'" style="color:black;background-color: transparent;border-color: transparent;display:block" >'.$temp_array['label'] .'</a>';

          $session_emailId = str_replace("'", "", $session_emailId);
          $emailIDD = "'" . $emailIDD . "'";
          $session_emailId = "'" . $session_emailId . "'";

          $temp_array['label'] = '<a href="javascript:navigateSearchProfile(' . $emailIDD . ',' . $session_emailId . ');" style="color:black;background-color: transparent;border-color: transparent;display:block" >' . $temp_array['label'] . '</a>';
          $output[] = $temp_array;
        }

        }
      }

      // $result4 = Education::where('first_name', 'LIKE',"%".str_replace(' ', '', $searchCriteria)."%")->orwhere('second_name','LIKE', "%".str_replace(' ', '', $searchCriteria)."%")->get();

      // $delimiter = ' ';
      // $words = explode($delimiter, $searchCriteria);

      // foreach ($words as $word) {
      //   $result4 = Education::where('first_name', 'LIKE', "%" . str_replace(' ', '', $word) . "%")->orwhere('second_name', 'LIKE', "%" . str_replace(' ', '', $word) . "%")->get();

      //   if (count($result4) == 0) {
      //     break;
      //   }
      // }
      // $session_emailId = Session::get('emailId');
      // $counterRec = 0;
      // if (count($result4) > 0) {
      //   $found2 = true;
      //   foreach ($result4 as $roww) {
      //     $counterRec = $counterRec + 1;
      //     if ($counterRec == 5) {
      //       break;
      //     }
      //     $firstName = $roww["first_name"];
      //     $secondName = $roww["second_name"];
      //     $imageName = $roww["profile_picture"];
      //     $emailIDD = $roww['email_id'];
      //     $temp_array = array();
      //     //   $temp_array['value'] ='UserProfile?email_ID_Visiter='.$emailIDD.'&email_ID_User='.$session_emailId.'"';
      //     $temp_array['label'] = '<img src="ProfileImages/Images/' . $imageName . '" width="40" height="40" style="border-radius: 50%;" />&nbsp;&nbsp;&nbsp;' . $firstName . ' ' . $secondName . '';

      //     // $temp_array['label']  ='<a href="UserProfile?email_ID_Visiter='.$emailIDD.'&email_ID_User='.$session_emailId.'" style="color:black;background-color: transparent;border-color: transparent;display:block" >'.$temp_array['label'] .'</a>';
      //     $session_emailId = str_replace("'", "", $session_emailId);
      //     $emailIDD = "'" . $emailIDD . "'";
      //     $session_emailId = "'" . $session_emailId . "'";
      //     $temp_array['label'] = '<a href="javascript:navigateSearchProfile(' . $emailIDD . ',' . $session_emailId . ');" style="color:black;background-color: transparent;border-color: transparent;display:block" >' . $temp_array['label'] . '</a>';
      //     $output[] = $temp_array;

      //   }
      // }
      //  $result4 = Organisation::where('first_name', 'LIKE',"%".str_replace(' ', '', $searchCriteria)."%")->orwhere('second_name','LIKE', "%".str_replace(' ', '', $searchCriteria)."%")->get();

      // $delimiter = ' ';
      // $words = explode($delimiter, $searchCriteria);
      // foreach ($words as $word) {
      //   $result4 = Organisation::where('first_name', 'LIKE', "%" . str_replace(' ', '', $word) . "%")->orwhere('second_name', 'LIKE', "%" . str_replace(' ', '', $word) . "%")->orwhere('entreprise_name', 'LIKE', "%" . str_replace(' ', '', $word) . "%")->get();
      //   if (count($result4) == 0) {
      //     break;
      //   }
      // }


      // $session_emailId = Session::get('emailId');
      // $counterRec = 0;
      // if (count($result4) > 0) {
      //   $found3 = true;
      //   foreach ($result4 as $roww) {
      //     if($roww['account_status']=='Active'){
      //     $counterRec = $counterRec + 1;
      //     if ($counterRec == 5) {
      //       break;
      //     }
      //     $firstName = $roww["first_name"];
      //     $secondName = $roww["second_name"];
      //     $imageName = $roww["profile_picture"];
      //     $emailIDD = $roww['email_id'];
      //     $org_name = $roww['entreprise_name'];

      //     $temp_array = array();
      //     //   $temp_array['value'] ='UserProfile?email_ID_Visiter='.$emailIDD.'&email_ID_User='.$session_emailId.'"';
      //     $temp_array['label'] = '<img src="ProfileImages/Images/' . $imageName . '" width="40" height="40" style="border-radius: 50%;" />&nbsp;&nbsp;&nbsp;' . $org_name . ' ' . " " . '';

      //     $session_emailId = str_replace("'", "", $session_emailId);
      //     $emailIDD = "'" . $emailIDD . "'";
      //     $session_emailId = "'" . $session_emailId . "'";
      //     $temp_array['label'] = '<a href="javascript:navigateSearchProfile(' . $emailIDD . ',' . $session_emailId . ');" style="color:black;background-color: transparent;border-color: transparent;display:block" >' . $temp_array['label'] . '</a>';
      //     $output[] = $temp_array;

      //   }}
      // }





      if ($found1 == false && $found2 == false && $found3 == false) {
        $output['value'] = '';
        $output['label'] = 'No Record Found';
      } else {
        $output['value'] = '&nbsp; &nbsp; &nbsp; &nbsp<a href="UserSearchResult" style="color:blue">View More!</a> ';

      }

      session::put('ViewSearch', 'All');
      session::put('PageCount', '1');


      echo json_encode($output);
    }

  }

  public function addFollows(Request $request)
  {
    $session_emailId = Session::get('emailId');
    $emailId = $request->email_id;

    Follower::create([
      'email_id' => $emailId,
      'follower_email_id' => $session_emailId,

    ]);

  }
  public function addUnFollows(Request $request)
  {
    $session_emailId = Session::get('emailId');
    $emailId = $request->email_id;


    Follower::where([['email_id', '=', $emailId], ['follower_email_id', '=', $session_emailId]])->delete();


  }



  public function AddingComments(Request $request)
  {
    $session_emailId = Session::get('emailId');
    $emailId = $request->email_id;
    $commentTxt = $request->commentsTxt;
    $postID = $request->post_id;


    comments_adds::create([
      'user_email' => $emailId,
      'liker_email' => $session_emailId,
      'comments_txt' => $commentTxt,
      'post_id' => $postID,

    ]);
    echo "done";


  }

  public function UserSearchResult()
  {
    return view("UserSearchResult");
  }

  public function LikePost(Request $request)
  {
    $session_emailId = Session::get('emailId');
    $emailId = $request->email_id;

    $postID = $request->postID;

    $result6 = PostLike::where([['user_email', '=', $emailId], ['liker_email', '=', $session_emailId], ['post_id', '=', $postID]])->get();

    if (count($result6) > 0) {
      PostLike::where([['user_email', '=', $emailId], ['liker_email', '=', $session_emailId], ['post_id', '=', $postID]])->delete();
      echo "unlike";
    } else {
      PostLike::create([
        'user_email' => $emailId,
        'liker_email' => $session_emailId,
        'post_id' => $postID,
        'like_unlike' => 'Like',

      ]);
      echo "done";
    }

  }

  public function addSocialLink(Request $request)
  {
    $session_emailId = Session::get('emailId');
    $urlLink = $request->urlLink;
    $type = $request->urlType;
    social_media_link::where([['email_id', '=', $session_emailId], ['url_type', '=', $type]])->delete();
    social_media_link::create([
      'email_id' => $session_emailId,
      'url_link' => $urlLink,
      'url_type' => $type,

    ]);

    print_r(json_encode("Updated"));
  }


  public function deleteLink(Request $request)
  {
    $session_emailId = Session::get('emailId');
    $type = $request->linkType;

    social_media_link::where([['email_id', '=', $session_emailId], ['url_type', '=', $type]])->delete();


  }

  public function checkUserType(){
    $userType="";
    $email_id=Session::get('emailId');
    $resultSet=  UserModel::where('email_id','=',$email_id)->get();
    $fullName="";
    $userType="";
     if (count($resultSet)>0) {

      foreach ($resultSet as $roww) {
        $userType=$roww['role'];
      }


     }

    //  else {
    //      $resultSet=  Organisation::where('email_id','=',$email_id)->get();
    //      if (count($resultSet)>0) {
    //          $userType='organization';

    //      }else {
    //           $resultSet=  Education::where('email_id','=',$email_id)->get();
    //      if (count($resultSet)>0) {
    //          $userType='education';

    //      }
    //  }
    //  }
     return  $userType;
}


}