Ejemplo n.º 1
0
 public function getResponders(Request $request)
 {
     $subCategory = $request['sub_category'];
     $objSubCategory = SubCategory::where('slug', '=', $subCategory)->first();
     $objCaseResponder = CaseResponder::where('category', '=', $objSubCategory->category)->where('sub_category', '=', $objSubCategory->id)->first();
     if ($objCaseResponder->sub_sub_category == 0) {
         $firstResponders = explode(",", $objCaseResponder->first_responder);
         $response = array();
         foreach ($firstResponders as $firstResponder) {
             $user = \DB::table('users')->join('departments', 'users.department', '=', 'departments.id')->join('positions', 'users.position', '=', 'positions.id')->where('users.id', '=', $firstResponder)->select(\DB::raw("\n                                    `users`.`id`,\n                                    `users`.`email`,\n                                    (select CONCAT(`users`.`name`, ' ',`users`.`surname`) ) as names,\n                                    `departments`.`name` as department,\n                                    `positions`.`name` as position\n\n                                    "))->first();
             $response[] = $user;
         }
         return $response;
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     \Log::info("Elie Ishimwe");
     $nowDate = \Carbon\Carbon::now('Africa/Johannesburg')->toDateTimeString();
     //$endDate = \Carbon\Carbon::now('Africa/Johannesburg')->addMinutes(5);
     $cases = CaseReport::where('accepted_at', '=', '0000-00-00 00:00:00')->where('referred_at', '<>', '0000-00-00 00:00:00')->get();
     \Log::info("Cases:");
     \Log::info($cases);
     foreach ($cases as $case) {
         if ($case->sub_sub_category > 0) {
             $firstRespondersObj = CaseResponder::where("sub_sub_category", '=', $case->sub_sub_category)->select('firstResponder')->get();
             \Log::info("First Responders");
             \Log::info($firstRespondersObj);
             \Log::info(sizeof($firstRespondersObj));
             $secondRespondersObj = CaseResponder::where("sub_sub_category", '=', $case->sub_sub_category)->select('secondResponder')->get();
             \Log::info("Second Responders");
             \Log::info($secondRespondersObj);
             \Log::info(sizeof($secondRespondersObj));
             if (sizeof($firstRespondersObj) > 0) {
                 $firstResponders = explode(",", $firstRespondersObj->firstResponder);
                 foreach ($firstResponders as $firstResponder) {
                     $firstResponderUser = User::find($firstResponder);
                     $data = array('name' => $firstResponderUser->name, 'caseID' => $case->id, 'caseDesc' => $case->description, 'caseReporter' => $case->description);
                     \Mail::send('emails.firstNotification', $data, function ($message) use($firstResponderUser) {
                         $message->from('*****@*****.**', 'Siyaleader');
                         $message->to($firstResponderUser->username)->subject("Siyaleader Notification - New Case Notification:");
                     });
                 }
             }
             /* if (sizeof($secondRespondersObj) > 0) {
             
                                 $secondResponders  = explode(",",$secondRespondersObj->secondResponder);
             
                                 foreach ($secondResponders as $secondResponder) {
             
                                     $secondResponderUser = User::find($secondResponder);
                                     $caseOwner           = new CaseOwner();
                                     $caseOwner->user     = $secondResponder ;
                                     $caseOwner->caseId   = $case->id;
                                     $caseOwner->type     = 2;
                                     $caseOwner->active   = 1;
                                     $caseOwner->save();
             
                                      $data = array(
                                                     'name'   =>$secondResponderUser->name,
                                                     'caseID' =>$case->id,
                                                     'caseDesc' => $case->description,
                                                     'caseReporter' => $case->description,
                                                 );
             
                                     \Mail::send('emails.responder',$data, function($message) use ($secondResponderUser) {
                                         $message->from('*****@*****.**', 'Siyaleader');
                                         $message->to($secondResponderUser->username)->subject("Siyaleader Notification - New Case Reported:");
             
                                     });
             
             
                                 }
             
                            }*/
         }
     }
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function subSubResponder($id)
 {
     $firstRespondersObj = CaseResponder::where("sub_sub_category", '=', $id)->select('firstResponder')->first();
     $secondRespondersObj = CaseResponder::where("sub_sub_category", '=', $id)->select('secondResponder')->first();
     $thirdRespondersObj = CaseResponder::where("sub_sub_category", '=', $id)->select('thirdResponder')->first();
     $response = array();
     if (sizeof($firstRespondersObj) > 0) {
         $firstResponders = explode(",", $firstRespondersObj->firstResponder);
         if ($firstRespondersObj->firstResponder > 0) {
             foreach ($firstResponders as $firstResponder) {
                 $user = \DB::table('users')->where('id', '=', $firstResponder)->select(\DB::raw("\n                                                    id,\n                                                    (select CONCAT(name, ' ',surname) ) as firstResponder\n\n                                                    "))->first();
                 $response[] = $user;
             }
         }
     }
     if (sizeof($secondRespondersObj) > 0) {
         $secondResponders = explode(",", $secondRespondersObj->secondResponder);
         if ($secondRespondersObj->secondResponder > 0) {
             foreach ($secondResponders as $secondResponder) {
                 $user = \DB::table('users')->where('id', '=', $secondResponder)->select(\DB::raw("\n                                            id,\n                                            (select CONCAT(name, ' ',surname) ) as secondResponder\n\n                                            "))->first();
                 $response[] = $user;
             }
         }
     }
     if (sizeof($thirdRespondersObj) > 0) {
         $thirdResponders = explode(",", $thirdRespondersObj->thirdResponder);
         if ($thirdRespondersObj->thirdResponder > 0) {
             foreach ($thirdResponders as $thirdResponder) {
                 $user = \DB::table('users')->where('id', '=', $thirdResponder)->select(\DB::raw("\n                                            id,\n                                            (select CONCAT(name, ' ',surname) ) as thirdResponder\n\n                                            "))->first();
                 $response[] = $user;
             }
         }
     }
     return $response;
 }
 public function store(Report $report, Request $request)
 {
     \Log::info("Request " . $request);
     $category = \Input::get('category');
     \Log::info('GET Category ' . $category);
     $sub_category = \Input::get('sub_category');
     \Log::info('GET Sub Category ' . $sub_category);
     $sub_sub_category = \Input::get('sub_sub_category');
     \Log::info('GET Sub Sub Category ' . $sub_sub_category);
     $sub_sub_category = empty($sub_sub_category) ? " " : $sub_sub_category;
     $description = \Input::get('description');
     \Log::info('Get Description :' . $description);
     $description = empty($description) ? " " : $description;
     $gps_lat = \Input::get('gps_lat');
     \Log::info('GPS Lat :' . $gps_lat);
     $gps_lng = \Input::get('gps_lng');
     \Log::info('GPS Lng :' . $gps_lng);
     $user_email = \Input::get('user_email');
     \Log::info('Email :' . $user_email);
     $priority = \Input::get('priorities');
     $priority = empty($priority) ? "Normal" : $priority;
     \Log::info('Priority :' . $priority);
     $headers = apache_request_headers();
     $response = array();
     \Log::info("Request " . $request);
     if (count($_FILES) > 0) {
         $files = $_FILES['img'];
         $name = uniqid('img-' . date('Ymd') . '-');
         $temp = explode(".", $files['name']);
         $name = $name . '.' . end($temp);
         if (file_exists("uploads/" . $name)) {
             echo $_FILES["img"]["name"] . "already exists. ";
         } else {
             $img_url = "uploads/" . $name;
             $target_file = "uploads/{$name}";
             $resized_file = "uploads/{$name}";
             $wmax = 600;
             $hmax = 480;
             $fileExt = 'jpg';
             if (move_uploaded_file($_FILES["img"]["tmp_name"], $img_url)) {
                 $this->ak_img_resize($target_file, $resized_file, $wmax, $hmax, $fileExt);
             }
         }
     }
     $img_url = isset($img_url) ? $img_url : "uploads/noimage.png";
     if (isset($headers['api_key'])) {
         $userNew = UserNew::where('api_key', '=', $headers['api_key_new'])->first();
         if (sizeof($userNew) > 0) {
             $objCat = DepartmentCategory::where('name', '=', $category)->first();
             \Log::info('Category Object :' . $objCat);
             $department = Department::where('id', '=', $objCat->department)->first();
             \Log::info('Department Object : ' . $department);
             $objSubCat = DepartmentSubCategory::where('name', '=', $sub_category)->first();
             $SubCatName = sizeof($objSubCat) > 0 ? $objSubCat->name : "";
             if (strlen($sub_sub_category) > 1) {
                 $objSubSubCat = DepartmentSubSubCategory::where('name', '=', $sub_sub_category)->first();
                 $objSubSub = $objSubSubCat->id;
             } else {
                 $objSubSubCat = 0;
                 $objSubSub = 0;
             }
             $case = new CaseReport();
             $case->description = $description;
             $case->user = $userNew->id;
             $case->reporter = $userNew->id;
             $case->department = $department->id;
             $case->category = $objCat->id;
             $case->sub_category = $objSubCat->id;
             $case->sub_sub_category = $objSubSub;
             $case->priority = $priority;
             $case->status = 'Pending';
             $case->gps_lat = $gps_lat;
             $case->precinct = 5;
             $case->img_url = $img_url;
             $case->gps_lng = $gps_lng;
             $case->save();
             $caseOwner = new CaseOwner();
             $caseOwner->user = $userNew->id;
             $caseOwner->caseId = $case->id;
             $caseOwner->type = 0;
             $caseOwner->active = 1;
             $caseOwner->save();
             $response["message"] = "Report created successfully";
             $response['error'] = FALSE;
             $data = array('name' => $userNew->name, 'caseID' => $case->id, 'caseDesc' => $case->description);
             \Mail::send('emails.sms', $data, function ($message) use($userNew) {
                 $message->from('*****@*****.**', 'Siyaleader');
                 $message->to($userNew->username)->subject("Siyaleader Notification - New Case Reported:");
             });
             if (is_object($objSubSubCat)) {
                 $firstRespondersObj = CaseResponder::where("sub_sub_category", '=', $objSubSubCat->id)->select('firstResponder')->first();
                 /*$secondRespondersObj = CaseResponder::where("sub_sub_category",'=',$objSubSubCat->id)
                                                                 ->select('secondResponder')->first();
                 
                                     $thirdRespondersObj  = CaseResponder::where("sub_sub_category",'=',$objSubSubCat->id)
                                                                 ->select('thirdResponder')->first();
                                     */
                 if (sizeof($firstRespondersObj) > 0) {
                     $case->status = "Referred";
                     $case->referred_at = \Carbon\Carbon::now('Africa/Johannesburg')->toDateTimeString();
                     $case->save();
                     $firstResponders = explode(",", $firstRespondersObj->firstResponder);
                     if ($firstRespondersObj->firstResponder > 0) {
                         foreach ($firstResponders as $firstResponder) {
                             $firstResponderUser = UserNew::find($firstResponder);
                             $caseOwner = new CaseOwner();
                             $caseOwner->user = $firstResponder;
                             $caseOwner->caseId = $case->id;
                             $caseOwner->type = 1;
                             $caseOwner->active = 1;
                             $caseOwner->save();
                             $data = array('name' => $firstResponderUser->name, 'caseID' => $case->id, 'caseDesc' => $case->description, 'caseReporter' => $case->description);
                             \Mail::send('emails.responder', $data, function ($message) use($firstResponderUser) {
                                 $message->from('*****@*****.**', 'Siyaleader');
                                 $message->to($firstResponderUser->username)->subject("Siyaleader Notification - New Case Reported:");
                             });
                             $cellphone = $firstResponderUser->email;
                             \Mail::send('emails.caseEscalatedSMS', $data, function ($message) use($cellphone) {
                                 $message->from('*****@*****.**', 'Siyaleader');
                                 $message->to('*****@*****.**')->subject("REFER: {$cellphone}");
                             });
                         }
                     }
                 }
                 /*     if (sizeof($secondRespondersObj) > 0) {
                 
                                         $secondResponders  = explode(",",$secondRespondersObj->secondResponder);
                 
                                         if($secondRespondersObj->secondResponder > 0) {
                 
                                             foreach ($secondResponders as $secondResponder) {
                 
                 
                                                 $secondResponderUser = UserNew::find($secondResponder);
                                                 $caseOwner          = new CaseOwner();
                                                 $caseOwner->user    = $secondResponder ;
                                                 $caseOwner->caseId  = $case->id;
                                                 $caseOwner->type    = 2;
                                                 $caseOwner->active  = 1;
                                                 $caseOwner->save();
                 
                                                  $data = array(
                                                         'name'   =>$secondResponderUser->name,
                                                         'caseID' =>$case->id,
                                                         'caseDesc' => $case->description,
                                                         'caseReporter' => $case->description,
                                                     );
                 
                                                 \Mail::send('emails.responder',$data, function($message) use ($secondResponderUser)
                                                 {
                                                     $message->from('*****@*****.**', 'Siyaleader');
                                                     $message->to($secondResponderUser->username)->subject("Siyaleader Notification - New Case Reported:");
                 
                                                 });
                 
                                             }
                 
                 
                 
                                         }
                                     }
                 */
                 /*        if (sizeof($thirdRespondersObj) > 0) {
                 
                                         $thirdResponders  = explode(",",$thirdRespondersObj->thirdResponder);
                 
                                         if($thirdRespondersObj->thirdResponder > 0) {
                 
                                             foreach ($thirdResponders as $thirdResponder) {
                 
                 
                                                 $thirdResponderUser = UserNew::find($thirdResponder);
                                                 $caseOwner          = new CaseOwner();
                                                 $caseOwner->user    = $thirdResponder ;
                                                 $caseOwner->caseId  = $case->id;
                                                 $caseOwner->type    = 3;
                                                 $caseOwner->active  = 1;
                                                 $caseOwner->save();
                 
                                                  $data = array(
                                                         'name'   =>$thirdResponderUser->name,
                                                         'caseID' =>$case->id,
                                                         'caseDesc' => $case->description,
                                                         'caseReporter' => $case->description,
                                                     );
                 
                                                 \Mail::send('emails.responder',$data, function($message) use ($thirdResponderUser)
                                                 {
                                                     $message->from('*****@*****.**', 'Siyaleader');
                                                     $message->to($thirdResponderUser->username)->subject("Siyaleader Notification - New Case Reported:");
                 
                                                 });
                 
                                             }
                 
                 
                 
                                         }
                                     }*/
             }
             if (sizeof($objSubCat) > 0 && $objSubSubCat == "") {
                 $firstRespondersObj = CaseResponder::where("sub_category", '=', $objSubCat->id)->select('firstResponder')->first();
                 /*  $secondRespondersObj = CaseResponder::where("sub_category",'=',$objSubCat->id)
                                                                 ->select('secondResponder')->first();
                 
                                     $thirdRespondersObj  = CaseResponder::where("sub_category",'=',$objSubCat->id)
                                                                 ->select('thirdResponder')->first();
                 
                                 */
                 if (sizeof($firstRespondersObj) > 0) {
                     $case->status = "Referred";
                     $case->referred_at = \Carbon\Carbon::now('Africa/Johannesburg')->toDateTimeString();
                     $case->save();
                     $firstResponders = explode(",", $firstRespondersObj->firstResponder);
                     if ($firstRespondersObj->firstResponder > 0) {
                         foreach ($firstResponders as $firstResponder) {
                             $firstResponderUser = UserNew::find($firstResponder);
                             $caseOwner = new CaseOwner();
                             $caseOwner->user = $firstResponder;
                             $caseOwner->caseId = $case->id;
                             $caseOwner->type = 1;
                             $caseOwner->active = 1;
                             $caseOwner->save();
                             $data = array('name' => $firstResponderUser->name, 'caseID' => $case->id, 'caseDesc' => $case->description, 'caseReporter' => $case->description);
                             \Mail::send('emails.responder', $data, function ($message) use($firstResponderUser) {
                                 $message->from('*****@*****.**', 'Siyaleader');
                                 $message->to($firstResponderUser->username)->subject("Siyaleader Notification - New Case Reported:");
                             });
                             $cellphone = $firstResponderUser->cellphone;
                             \Mail::send('emails.caseEscalatedSMS', $data, function ($message) use($cellphone) {
                                 $message->from('*****@*****.**', 'Siyaleader');
                                 $message->to('*****@*****.**')->subject("REFER: {$cellphone}");
                             });
                         }
                     }
                 }
                 /*     if (sizeof($secondRespondersObj) > 0) {
                 
                                         $secondResponders  = explode(",",$secondRespondersObj->secondResponder);
                 
                                         if($secondRespondersObj->secondResponder > 0) {
                 
                                             foreach ($secondResponders as $secondResponder) {
                 
                 
                                                 $secondResponderUser = UserNew::find($secondResponder);
                                                 $caseOwner          = new CaseOwner();
                                                 $caseOwner->user    = $secondResponder ;
                                                 $caseOwner->caseId  = $case->id;
                                                 $caseOwner->type    = 2;
                                                 $caseOwner->active  = 1;
                                                 $caseOwner->save();
                 
                                                  $data = array(
                                                         'name'   =>$secondResponderUser->name,
                                                         'caseID' =>$case->id,
                                                         'caseDesc' => $case->description,
                                                         'caseReporter' => $case->description,
                                                     );
                 
                                                 \Mail::send('emails.responder',$data, function($message) use ($secondResponderUser)
                                                 {
                                                     $message->from('*****@*****.**', 'Siyaleader');
                                                     $message->to($secondResponderUser->username)->subject("Siyaleader Notification - New Case Reported:");
                 
                                                 });
                 
                                             }
                 
                 
                 
                                         }
                                     }*/
                 /*if (sizeof($thirdRespondersObj) > 0) {
                 
                                         $thirdResponders  = explode(",",$thirdRespondersObj->thirdResponder);
                 
                                         if($thirdRespondersObj->thirdResponder > 0) {
                 
                                             foreach ($thirdResponders as $thirdResponder) {
                 
                 
                                                 $thirdResponderUser = UserNew::find($thirdResponder);
                                                 $caseOwner          = new CaseOwner();
                                                 $caseOwner->user    = $thirdResponder ;
                                                 $caseOwner->caseId  = $case->id;
                                                 $caseOwner->type    = 3;
                                                 $caseOwner->active  = 1;
                                                 $caseOwner->save();
                 
                                                  $data = array(
                                                         'name'   =>$thirdResponderUser->name,
                                                         'caseID' =>$case->id,
                                                         'caseDesc' => $case->description,
                                                         'caseReporter' => $case->description,
                                                     );
                 
                                                 \Mail::send('emails.responder',$data, function($message) use ($thirdResponderUser)
                                                 {
                                                     $message->from('*****@*****.**', 'Siyaleader');
                                                     $message->to($thirdResponderUser->username)->subject("Siyaleader Notification - New Case Reported:");
                 
                                                 });
                 
                                             }
                 
                 
                 
                                         }
                                     }*/
             }
             return \Response::json($response, 201);
         } else {
             $response['message'] = 'Access Denied. Invalid Api key';
             $response['error'] = TRUE;
             return \Response::json($response, 401);
         }
     } else {
         $response['message'] = 'Access Denied. Invalid Api key';
         $response['error'] = TRUE;
         return \Response::json($response, 401);
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function captureCase(Request $request)
 {
     $reporter = $request['caseReporter'];
     $caseSeverity = $request['caseSeverity'];
     $userObj = User::where('username', '=', $reporter)->first();
     if (sizeof($userObj) <= 0) {
         $userAddressbookObj = addressbook::where('email', '=', $reporter)->first();
     }
     $user = sizeof($userObj) <= 0 ? $userAddressbookObj->id : $userObj->id;
     $addressbook = sizeof($userObj) <= 0 ? 1 : 0;
     $userName = sizeof($userObj) <= 0 ? $userAddressbookObj->FirstName : $userObj->name;
     $userSurname = sizeof($userObj) <= 0 ? $userAddressbookObj->Surname : $userObj->surname;
     $userEmail = sizeof($userObj) <= 0 ? $userAddressbookObj->email : $userObj->username;
     $cell = sizeof($userObj) <= 0 ? $userAddressbookObj->cellphone : $userObj->email;
     $caseDescription = $request['caseDescription'];
     $precinctObj = Municipality::where('slug', '=', $request['caseMunicipality'])->first();
     $categoryObj = Category::where('slug', '=', $request['caseCategory'])->first();
     $subCategoryObj = SubCategory::where('slug', '=', $request['caseSubCategory'])->first();
     if ($request['caseSubSubCategory'] > 0) {
         $subSubCategoryObj = SubSubCategory::where('slug', '=', $request['caseSubSubCategory'])->first();
         $subSubCategory = $subSubCategoryObj->id;
     } else {
         $subSubCategory = 0;
     }
     $gps = explode(",", $request['GPS']);
     $caseObj = new CaseReport();
     $caseObj->description = htmlentities($caseDescription);
     $caseObj->user = \Auth::user()->id;
     $caseObj->reporter = $user;
     $caseObj->addressbook = $addressbook;
     $caseObj->precinct = $precinctObj->id;
     $caseObj->category = $categoryObj->id;
     $caseObj->sub_category = $subCategoryObj->id;
     $caseObj->sub_sub_category = $subSubCategory;
     $caseObj->gps_lat = $gps[0];
     $caseObj->gps_lng = $gps[1];
     $caseObj->severity = $caseSeverity;
     $caseObj->status = "Pending";
     $caseObj->save();
     $data = array('name' => $userName, 'caseID' => $caseObj->id, 'caseDesc' => $caseObj->description);
     $caseOwner = new CaseOwner();
     $caseOwner->user = $user;
     $caseOwner->caseId = $caseObj->id;
     $caseOwner->type = 0;
     $caseOwner->active = 1;
     $caseOwner->save();
     \Mail::send('emails.sms', $data, function ($message) use($userEmail) {
         $message->from('*****@*****.**', 'Siyaleader');
         $message->to($userEmail)->subject("Siyaleader Notification - New Case Reported:");
     });
     if ($caseSeverity <= 4) {
         $severityData = array('severity' => $caseObj->severity, 'name' => $userName . ' ' . $userSurname, 'cell' => $cell, 'category' => $categoryObj->name, 'caseId' => $caseObj->id);
         \Mail::send('emails.severity', $severityData, function ($message) {
             $message->from('*****@*****.**', 'Siyaleader');
             $message->to('*****@*****.**')->subject("SEVERE");
         });
         $criticalTeam = CriticalTeam::all();
         foreach ($criticalTeam as $critical) {
             $caseOwner = new CaseOwner();
             $caseOwner->user = $critical->user;
             $caseOwner->caseId = $caseObj->id;
             $caseOwner->type = 5;
             //Critical Team
             $caseOwner->active = 1;
             $caseOwner->save();
             \Mail::send('emails.severity', $severityData, function ($message) use($critical) {
                 $userObj = User::find($critical->user);
                 $message->from('*****@*****.**', 'Siyaleader');
                 $message->to($userObj->username)->subject("Siyaleader Notification - New Severe Case Reported:");
             });
         }
     }
     if ($subSubCategory > 0) {
         $subSubCatResponders = CaseResponder::where('sub_sub_category', '=', $subSubCategory)->first();
         if (sizeof($subSubCatResponders) > 0) {
             if ($subSubCatResponders->firstResponder) {
                 $firstResponderUser = User::find($subSubCatResponders->firstResponder);
                 $caseOwner = new CaseOwner();
                 $caseOwner->user = $subSubCatResponders->firstResponder;
                 $caseOwner->caseId = $caseObj->id;
                 $caseOwner->type = 1;
                 $caseOwner->active = 1;
                 $caseOwner->save();
                 $data = array('name' => $firstResponderUser->name, 'caseID' => $caseObj->id, 'caseDesc' => $caseObj->description, 'caseReporter' => $caseObj->description);
                 \Mail::send('emails.responder', $data, function ($message) use($firstResponderUser) {
                     $message->from('*****@*****.**', 'Siyaleader');
                     $message->to($firstResponderUser->username)->subject("Siyaleader Notification - New Case Reported:");
                 });
             }
             if ($subSubCatResponders->secondResponder) {
                 $secondResponderUser = User::find($subSubCatResponders->secondResponder);
                 $caseOwner = new CaseOwner();
                 $caseOwner->user = $subSubCatResponders->secondResponder;
                 $caseOwner->caseId = $caseObj->id;
                 $caseOwner->type = 2;
                 $caseOwner->active = 1;
                 $caseOwner->save();
                 $data = array('name' => $secondResponderUser->name, 'caseID' => $caseObj->id, 'caseDesc' => $caseObj->description, 'caseReporter' => $caseObj->description);
                 \Mail::send('emails.responder', $data, function ($message) use($secondResponderUser) {
                     $message->from('*****@*****.**', 'Siyaleader');
                     $message->to($secondResponderUser->username)->subject("Siyaleader Notification - New Case Reported:");
                 });
             }
             if ($subSubCatResponders->thirdResponder) {
                 $thirdResponderUser = User::find($subSubCatResponders->thirdResponder);
                 $caseOwner = new CaseOwner();
                 $caseOwner->user = $subSubCatResponders->thirdResponder;
                 $caseOwner->caseId = $caseObj->id;
                 $caseOwner->type = 3;
                 $caseOwner->active = 1;
                 $caseOwner->save();
                 $data = array('name' => $thirdResponderUser->name, 'caseID' => $caseObj->id, 'caseDesc' => $caseObj->description, 'caseReporter' => $caseObj->description);
                 \Mail::send('emails.responder', $data, function ($message) use($thirdResponderUser) {
                     $message->from('*****@*****.**', 'Siyaleader');
                     $message->to($thirdResponderUser->username)->subject("Siyaleader Notification - New Case Reported:");
                 });
             }
         }
     }
     if ($subSubCategory == 0) {
         $subCatResponders = CaseResponder::where('sub_category', '=', $subCategoryObj->id)->first();
         if (sizeof($subCatResponders) > 0) {
             if ($subCatResponders->firstResponder) {
                 $firstResponderUser = User::find($subCatResponders->firstResponder);
                 $caseOwner = new CaseOwner();
                 $caseOwner->user = $subCatResponders->firstResponder;
                 $caseOwner->caseId = $caseObj->id;
                 $caseOwner->type = 1;
                 $caseOwner->active = 1;
                 $caseOwner->save();
                 $data = array('name' => $firstResponderUser->name, 'caseID' => $caseObj->id, 'caseDesc' => $caseObj->description, 'caseReporter' => $caseObj->description);
                 \Mail::send('emails.responder', $data, function ($message) use($firstResponderUser) {
                     $message->from('*****@*****.**', 'Siyaleader');
                     $message->to($firstResponderUser->username)->subject("Siyaleader Notification - New Case Reported:");
                 });
             }
             if ($subCatResponders->secondResponder) {
                 $secondResponderUser = User::find($subCatResponders->secondResponder);
                 $caseOwner = new CaseOwner();
                 $caseOwner->user = $subCatResponders->secondResponder;
                 $caseOwner->caseId = $caseObj->id;
                 $caseOwner->type = 2;
                 $caseOwner->active = 1;
                 $caseOwner->save();
                 $data = array('name' => $secondResponderUser->name, 'caseID' => $caseObj->id, 'caseDesc' => $caseObj->description, 'caseReporter' => $caseObj->description);
                 \Mail::send('emails.responder', $data, function ($message) use($secondResponderUser) {
                     $message->from('*****@*****.**', 'Siyaleader');
                     $message->to($secondResponderUser->username)->subject("Siyaleader Notification - New Case Reported:");
                 });
             }
             if ($subCatResponders->thirdResponder) {
                 $thirdResponderUser = User::find($subCatResponders->thirdResponder);
                 $caseOwner = new CaseOwner();
                 $caseOwner->user = $subCatResponders->thirdResponder;
                 $caseOwner->caseId = $caseObj->id;
                 $caseOwner->type = 3;
                 $caseOwner->active = 1;
                 $caseOwner->save();
                 $data = array('name' => $thirdResponderUser->name, 'caseID' => $caseObj->id, 'caseDesc' => $caseObj->description, 'caseReporter' => $caseObj->description);
                 \Mail::send('emails.responder', $data, function ($message) use($thirdResponderUser) {
                     $message->from('*****@*****.**', 'Siyaleader');
                     $message->to($thirdResponderUser->username)->subject("Siyaleader Notification - New Case Reported:");
                 });
             }
         }
     }
     return redirect()->back();
 }