<?php

namespace App\Http\Controllers;

use App\Models\Log;
use App\Models\Indexing;
use App\Models\EBM;
use App\Models\Journal;
use App\Models\Manuscript;
use App\Models\Country;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\View;
use Auth;
use DB;
use File;

class EBMRoleController extends BenthamController
{
    public function EditorRole(Request $request, $page = "", $id = "")
    {
        if ($page == 'list') {
            $id = $request->get('editor_id');
            $editor_roles = EBM::GetEbmRolebyEditorID($id);

            return View::make('admin.editorial_board_member.ebm_role.ebm_role_list', with([
                'editor_roles' => $editor_roles
            ]));
        }

        if ($page == 'add') {

            $ebm_verification_id = request()->get('ebm_verification_id');

            if (!empty($ebm_verification_id)) {
                $param['editor_id'] = request()->get('editor_id');
                $editor_data = EBM::GetEditorbyID($param['editor_id']);
                $param['name'] = $editor_data->fname . ' ' . $editor_data->mname . ' ' . $editor_data->lname;
            } else {
                $param['editor_id'] = $request->get('editor_id');
                $param['name'] = $request->get('name');
            }

            $journal_list = EBM::GetJournalList();
            $role_list = EBM::GetAllEbmRole();
            $region_list = EBM::GetAllRegions();

            return View::make('admin.editorial_board_member.ebm_role.ebm_role_add', with([
                'journal_list' => $journal_list, 'role_list' => $role_list, 'param' => $param, 'region_list' => $region_list, 'ebm_verification_id' => $ebm_verification_id
            ]));
        }

        if ($page == 'store') {

            if (!empty($request->get('ebm_verification_id'))) {
                $ebm_verification_id = $request->get('ebm_verification_id');
                $ebm_request_delete = DB::table('tbl_ebm_verification')->where('ebm_verification_id', $ebm_verification_id)->delete();
            }

            $param['editor_id'] = $request->editor_id;
            $param['verification_status'] = 'pending';
            $editor_data = EBM::GetVerificationEditorsList($param);
            // dd($editor_data);

            if ($editor_data->count() == 0) {

                $req = array();

                $req['journal_id']          = 'required';
                $req['ebm_role_id']         = 'required';
                $req['ebm_status']          = 'required';
                $req['cv_name']             = 'required|mimes:pdf,doc,docx';
                $req['email_accp_name']     = 'required|mimes:pdf,doc,docx';
                $req['agreement_form_name'] = 'required|mimes:pdf,doc,docx';
                $req['eic_approval']        = 'required|mimes:pdf,doc,docx';
                $req['director_approval']   = 'required|mimes:pdf,doc,docx';

                $validator = Validator::make($request->all(), $req);

                if ($validator->fails()) {

                    return Redirect::back()->withErrors($validator);
                } else {

                    //------------------------------Region---------------------------------
                    if ($request->ebm_role_id == 4 && !empty($request->region_id)) {
                        $region_id = $request->region_id;
                    } else {
                        $region_id = "";
                    }

                    $data = array(
                        'journal_id'                       => $request->journal_id,
                        'editor_id'                        => $request->editor_id,
                        'ebm_role_id'                      => $request->ebm_role_id,
                        'region_id'                        => $region_id,
                        'section'                          => $request->section,
                        'conditional_ebm'                  => $request->conditional_ebm,
                        'executive_ge'                     => $request->executive_ge,
                        'acceptance_date'                  => $request->acceptance_date,
                        'acceptance_email_text'            => $request->acceptance_email_text,
                        'resign_date'                      => $request->resign_date,
                        'resign_email_text'                => $request->resign_email_text,
                        'ebm_status'                       => $request->ebm_status,
                        'source'                           => $request->source,
                        'email_accp_created_on'            => time(),
                        'added_by'                         => Auth::user()->id,
                        'created_on'                       => time(),
                        'updated_by'                       => Auth::user()->id,
                        'updated_on'                       => now(),
                        'ebm_verification_comment'         => 'Add Editor Role',
                        'ebm_verification_status'          => 'pending',
                    );

                    $ebmverificationId = EBM::AddEditorRoleVerification($data);

                    //----------------------Upload CV-------------------------------
                    $cv_name_type = "";
                    $CV_Name = "";
                    $cv_path = 'ebm_cv/';
                    $cv_file_path = config('constants.admin.ebm_root_path') . $cv_path;

                    if ($request->hasFile('cv_name')) {
                        $cv_name = $request->file('cv_name');
                        $cv_name_type = $cv_name->getClientMimeType();
                        $extension = $cv_name->getClientOriginalExtension();
                        $CV_Name = $ebmverificationId . '.' . $extension;

                        if (!is_dir($cv_file_path)) {
                            mkdir($cv_file_path, 0755, true);
                        }

                        $cv_name->move($cv_file_path, $CV_Name);
                    }

                    //----------------------Upload Acceptance Email-------------------------------
                    $accept_email_type = "";
                    $Accept_Email = "";
                    $acceptance_email = 'ebm_acceptance_email/';
                    $acceptance_email_file_path = config('constants.admin.ebm_root_path') . $acceptance_email;

                    if ($request->hasFile('email_accp_name')) {
                        $accept_email = $request->file('email_accp_name');
                        $accept_email_type = $accept_email->getClientMimeType();
                        $extension = $accept_email->getClientOriginalExtension();
                        $Accept_Email = $ebmverificationId . '.' . $extension;

                        if (!is_dir($acceptance_email_file_path)) {
                            mkdir($acceptance_email_file_path, 0755, true);
                        }

                        $accept_email->move($acceptance_email_file_path, $Accept_Email);
                    }

                    //----------------------Upload Agreement Form-------------------------------
                    $agreement_form_type = "";
                    $Agreement = "";
                    $agreement_form = 'agreement_form/';
                    $agreement_form_file_path = config('constants.admin.ebm_root_path') . $agreement_form;

                    if ($request->hasFile('agreement_form_name')) {
                        $agreement = $request->file('agreement_form_name');
                        $agreement_form_type = $agreement->getClientMimeType();
                        $extension = $agreement->getClientOriginalExtension();
                        $Agreement = $ebmverificationId . '.' . $extension;

                        if (!is_dir($agreement_form_file_path)) {
                            mkdir($agreement_form_file_path, 0755, true);
                        }

                        $agreement->move($agreement_form_file_path, $Agreement);
                    }

                    //----------------------EiC's Approval-------------------------------
                    $eic_approval_form_type = "";
                    $EIC_Approval = "";

                    $eic_approval = 'eic_approval/';
                    $eic_approval_file_path = config('constants.admin.ebm_root_path') . $eic_approval;

                    if ($request->hasFile('eic_approval')) {
                        $EIC_approval = $request->file('eic_approval');
                        $eic_approval_form_type = $EIC_approval->getClientMimeType();
                        $extension = $EIC_approval->getClientOriginalExtension();
                        $EIC_Approval = $ebmverificationId . '.' . $extension;

                        if (!is_dir($eic_approval_file_path)) {
                            mkdir($eic_approval_file_path, 0755, true);
                        }

                        $EIC_approval->move($eic_approval_file_path, $EIC_Approval);
                    }

                    //----------------------Dr.Sahab Approval-------------------------------
                    $director_approval_name_type = "";
                    $Director_Approval = "";
                    $director_approval = 'director_approval/';
                    $director_approval_file_path = config('constants.admin.ebm_root_path') . $director_approval;

                    if ($request->hasFile('director_approval')) {
                        $director = $request->file('director_approval');
                        $director_approval_name_type = $director->getClientMimeType();
                        $extension = $director->getClientOriginalExtension();
                        $Director_Approval = $ebmverificationId . '.' . $extension;

                        if (!is_dir($director_approval_file_path)) {
                            mkdir($director_approval_file_path, 0755, true);
                        }

                        $director->move($director_approval_file_path, $Director_Approval);
                    }

                    $update_data = array(
                        'cv_content_type'                  => $cv_name_type,
                        'cv_name'                          => $CV_Name,
                        'email_content_type'               => $accept_email_type,
                        'email_accp_name'                  => $Accept_Email,
                        'agreement_form_content_type'      => $agreement_form_type,
                        'agreement_form_name'              => $Agreement,
                        'eic_approval'                     => $EIC_Approval,
                        'eic_approval_content_type'        => $eic_approval_form_type,
                        'director_approval_content_type'   => $director_approval_name_type,
                        'director_approval'                => $Director_Approval,
                    );

                    $editor_role_update = EBM::UpdateEbmVerification($ebmverificationId, $update_data);

                    return redirect()->route('editorial_board_member.index')->with('success', 'Editor role add request has been send to verification department.');
                }
            } else {
                return redirect()->route('editorial_board_member.index')->with('error', 'There is already pending request against this editor.');
            }
        }

        if ($page == 'edit') {

            $ebm_verification_id = request()->get('ebm_verification_id');

            $editor = EBM::GetEBMRolebyID($id);
            $journal_list = EBM::GetJournalList();
            $role_list = Manuscript::GetAllEbmRole();
            $region_list = EBM::GetAllRegions();

            return View::make('admin.editorial_board_member.ebm_role.ebm_role_edit', with([
                'journal_list' => $journal_list, 'role_list' => $role_list, 'editor' => $editor, 'region_list' => $region_list, 'ebm_verification_id' => $ebm_verification_id
            ]));
        }

        if ($page == 'toggle-status') {
            $param['editor_id'] = $request->get('editor_id');
            $param['verification_status'] = 'pending';
            $editor_data = EBM::GetVerificationEditorsList($param);

            if ($editor_data->count() == 0) {
                $data = EBM::GetEditorbyID($request->get('editor_id'));
                $data->created_on            = now();
                $data->added_by              = Auth::user()->id;
                $data->verification_comment  = 'Editor Status ' . ucfirst($request->get('toggle'));
                $data->verification_status   = 'pending';

                $arrayData = (array) $data;

                $arrayData['status_change_comment'] = $request->status_change_comment;
                $editor_add = EBM::AddEditorVerification($arrayData);

                return redirect()->route('editorial_board_member.index')->with('success', 'Editor status change request has been send to verification department.');
            } else {
                return redirect()->route('editorial_board_member.index')->with('error', 'There is already pending request against this editor.');
            }
        }

        if ($page == 'update') {

            if (!empty($request->get('ebm_verification_id'))) {
                $ebm_verification_id = $request->get('ebm_verification_id');
                $ebm_request_delete = DB::table('tbl_ebm_verification')->where('ebm_verification_id', $ebm_verification_id)->delete();
            }

            $param['editor_id'] = $request->editor_id;
            $param['verification_status'] = 'pending';
            $editor_data = EBM::GetVerificationEditorsList($param);

            if ($editor_data->count() == 0) {

                $req = array();
                $ebm_verification_id = "";

                if (isset($request->cv_name)) {
                    $req['cv_name'] = 'mimes:pdf,doc,docx';
                }
                if (isset($request->email_accp_name)) {
                    $req['email_accp_name'] = 'mimes:pdf,doc,docx';
                }
                if (isset($request->agreement_form)) {
                    $req['agreement_form_name'] = 'mimes:pdf,doc,docx';
                }
                if (isset($request->eic_approval)) {
                    $req['eic_approval'] = 'mimes:pdf,doc,docx';
                }
                if (isset($request->director_approval)) {
                    $req['director_approval'] = 'mimes:pdf,doc,docx';
                }

                $validator = Validator::make($request->all(), $req);

                if ($validator->fails()) {

                    return Redirect::back()->withErrors($validator);
                } else {

                    $ebm = EBM::GetEBMbyID($request->ebm_id);
                    $ebmArray = (array) $ebm;
                    $changedAttributes = '';

                    //------------------Conditional EBM and Executive Guest Editor----------
                    if (empty($request->conditional_ebm) && $ebm->conditional_ebm == 'Y') {
                        $update_editor_role['conditional_ebm'] = 'N';
                        $changedAttributes .= 'conditional_ebm,';
                    }

                    if (empty($request->executive_ge) && $ebm->executive_ge == 'Y') {
                        $update_editor_role['executive_ge'] = 'N';
                        $changedAttributes .= 'executive_ge,';
                    }

                    //------------------------------Region---------------------------------
                    if ($request->ebm_role_id == 4 && !empty($request->region_id)) {
                        $update_editor_role['region_id'] = $request->region_id;
                        $changedAttributes .= 'region_id,';
                    }

                    $requestData = $request->except(['_token', '_wysihtml5_mode', 'name', 'cv_name', 'email_accp_name', 'agreement_form_name', 'eic_approval', 'director_approval', 'region_id', 'ebm_verification_id']);

                    foreach ($requestData as $attribute => $value) {

                        if (trim($request->input($attribute)) != trim($ebmArray[$attribute])) {

                            $update_editor_role[$attribute] = $request->input($attribute);
                            $changedAttributes .= $attribute . ',';
                        }
                    }

                    //---------------------Update Other Column----------------------
                    $update_editor_role['ebm_id']  = $request->ebm_id;
                    $update_editor_role['editor_id']  = $request->editor_id;
                    $update_editor_role['ebm_verification_comment']  = 'Edit Editor Role';
                    $update_editor_role['ebm_verification_status']  = 'pending';
                    $update_editor_role['ebm_changes']  = $changedAttributes;
                    $update_editor_role['added_by']   = Auth::user()->id;
                    $update_editor_role['created_on'] = time();

                    if (!empty($changedAttributes)) {
                        $ebm_verification_id = EBM::AddEditorRoleVerification($update_editor_role);
                    }

                    //----------------------Upload CV-------------------------------
                    $cv_path = 'ebm_cv/';
                    $cv_file_path = config('constants.admin.ebm_root_path') . $cv_path;

                    if ($request->hasFile('cv_name')) {
                        $CV_Name = $request->file('cv_name');
                        $update_editor_role_file['cv_content_type'] = $CV_Name->getClientMimeType();
                        $extension = $CV_Name->getClientOriginalExtension();

                        if (!empty($ebm->cv_name)) {
                            $start = explode('.', $ebm->cv_name);
                            $cv_name = $start[0];
                            $update_editor_role_file['cv_name'] = $cv_name . '.' . $extension;
                        } else {
                            $update_editor_role_file['cv_name'] = $ebm_verification_id . '.' . $extension;
                        }

                        if (!is_dir($cv_file_path)) {
                            mkdir($cv_file_path, 0755, true);
                        }

                        $CV_Name->move($cv_file_path, $update_editor_role_file['cv_name']);
                        $update_editor_role_file['cv_updated_on'] = now();

                        $changedAttributes .= 'cv_content_type,cv_name,cv_updated_on,';
                    }

                    //----------------------Upload Acceptance Email-------------------------------
                    $acceptance_email = 'ebm_acceptance_email/';
                    $acceptance_email_file_path = config('constants.admin.ebm_root_path') . $acceptance_email;

                    if ($request->hasFile('email_accp_name')) {
                        $accept_email = $request->file('email_accp_name');
                        $update_editor_role_file['email_content_type'] = $accept_email->getClientMimeType();
                        $extension = $accept_email->getClientOriginalExtension();

                        if (!empty($ebm->email_accp_name)) {
                            $start = explode('.', $ebm->email_accp_name);
                            $email_accp_name = $start[0];
                            $update_editor_role_file['email_accp_name'] = $email_accp_name . '.' . $extension;
                        } else {
                            $update_editor_role_file['email_accp_name'] = $ebm_verification_id . '.' . $extension;
                        }

                        if (!is_dir($acceptance_email_file_path)) {
                            mkdir($acceptance_email_file_path, 0755, true);
                        }

                        $accept_email->move($acceptance_email_file_path, $update_editor_role_file['email_accp_name']);
                        $update_editor_role_file['email_accp_created_on'] = now();

                        $changedAttributes .= 'email_content_type,email_accp_name,email_accp_created_on,';
                    }

                    //----------------------Upload Agreement Form-------------------------------
                    $agreement_form = 'agreement_form/';
                    $agreement_form_file_path = config('constants.admin.ebm_root_path') . $agreement_form;

                    if ($request->hasFile('agreement_form_name')) {
                        $agreement = $request->file('agreement_form_name');
                        $update_editor_role_file['agreement_form_content_type'] = $agreement->getClientMimeType();
                        $extension = $agreement->getClientOriginalExtension();

                        if (!empty($ebm->agreement_form_name)) {
                            $start = explode('.', $ebm->agreement_form_name);
                            $agreement_form_name = $start[0];
                            $update_editor_role_file['agreement_form_name'] = $agreement_form_name . '.' . $extension;
                        } else {
                            $update_editor_role_file['agreement_form_name'] = $ebm_verification_id . '.' . $extension;
                        }

                        if (!is_dir($agreement_form_file_path)) {
                            mkdir($agreement_form_file_path, 0755, true);
                        }

                        $agreement->move($agreement_form_file_path, $update_editor_role_file['agreement_form_name']);
                        $update_editor_role_file['agreement_form_updated_on'] = now();

                        $changedAttributes .= 'agreement_form_content_type,agreement_form_name,agreement_form_updated_on,';
                    }

                    //----------------------EiC's Approval-------------------------------
                    $eic_approval = 'eic_approval/';
                    $eic_approval_file_path = config('constants.admin.ebm_root_path') . $eic_approval;

                    if ($request->hasFile('eic_approval')) {
                        $EIC_approval = $request->file('eic_approval');
                        $update_editor_role_file['eic_approval_content_type'] = $EIC_approval->getClientMimeType();
                        $extension = $EIC_approval->getClientOriginalExtension();

                        if (!empty($ebm->eic_approval)) {
                            $start = explode('.', $ebm->eic_approval);
                            $eic_approval = $start[0];
                            $update_editor_role_file['eic_approval'] = $eic_approval . '.' . $extension;
                        } else {
                            $update_editor_role_file['eic_approval'] = $ebm_verification_id . '.' . $extension;
                        }

                        if (!is_dir($eic_approval_file_path)) {
                            mkdir($eic_approval_file_path, 0755, true);
                        }

                        $EIC_approval->move($eic_approval_file_path, $update_editor_role_file['eic_approval']);
                        $update_editor_role_file['eic_approval_updated_on'] = time();

                        $changedAttributes .= 'eic_approval_content_type,eic_approval,eic_approval_updated_on,';
                    }

                    //----------------------Dr.Sahab Approval-------------------------------
                    $director_approval = 'director_approval/';
                    $director_approval_file_path = config('constants.admin.ebm_root_path') . $director_approval;

                    if ($request->hasFile('director_approval')) {
                        $director = $request->file('director_approval');
                        $update_editor_role_file['director_approval_content_type'] = $director->getClientMimeType();
                        $extension = $director->getClientOriginalExtension();

                        if (!empty($ebm->director_approval)) {
                            $start = explode('.', $ebm->director_approval);
                            $director_approval = $start[0];
                            $update_editor_role_file['director_approval'] = $director_approval . '.' . $extension;
                        } else {
                            $update_editor_role_file['director_approval'] = $ebm_verification_id . '.' . $extension;
                        }

                        if (!is_dir($director_approval_file_path)) {
                            mkdir($director_approval_file_path, 0755, true);
                        }

                        $director->move($director_approval_file_path, $update_editor_role_file['director_approval']);
                        $update_editor_role_file['director_approval_updated_on'] = time();

                        $changedAttributes .= 'director_approval_content_type,director_approval,director_approval_updated_on,';
                    }

                    if (!empty($changedAttributes)) {

                        $update_editor_role_file['ebm_changes']  = $changedAttributes;

                        if ($ebm_verification_id != "") {
                            $editor_role_update = EBM::UpdateEbmVerification($ebm_verification_id, $update_editor_role_file);
                        } else {
                            //---------------------Update Other Column----------------------
                            $update_editor_role_file['ebm_id']  = $request->ebm_id;
                            $update_editor_role_file['editor_id']  = $request->editor_id;
                            $update_editor_role_file['ebm_verification_comment']  = 'Edit Editor Role';
                            $update_editor_role_file['ebm_verification_status']  = 'pending';
                            $update_editor_role_file['added_by']   = Auth::user()->id;
                            $update_editor_role_file['created_on'] = time();
                            $ebm_verification_id = EBM::AddEditorRoleVerification($update_editor_role_file);
                        }

                        return redirect()->route('editorial_board_member.index')->with('success', 'Request for changes in editor role has been send to verification department.');
                    } else {
                        return redirect()->route('editorial_board_member.index');
                    }
                }
            } else {
                return redirect()->route('editorial_board_member.index')->with('error', 'There is already pending request against this editor.');
            }
        }

        if ($page == 'delete') {

            $data = EBM::GetEBMRolebyID($id);
            $param['editor_id'] = $data->editor_id;
            $param['verification_status'] = 'pending';
            $editor_data = EBM::GetVerificationEditorsList($param);

            if ($editor_data->count() == 0) {

                $ebm_role = DB::table('tbl_ebm as e')->select('e.*')->where('e.ebm_id', '=', $id)->first();

                $ebm_role->created_on                = time();
                $ebm_role->added_by                  = Auth::user()->id;
                $ebm_role->ebm_verification_comment  = 'Delete Editor Role';
                $ebm_role->ebm_verification_status   = 'pending';

                $arrayData = (array) $ebm_role;

                $arrayData['role_delete_comment'] = $request->role_delete_comment;
                $editor_role = EBM::AddEditorRoleVerification($arrayData);

                return redirect()->route('editorial_board_member.index')->with('success', 'Request to delete editor role has been send to verification department.');
            } else {
                return redirect()->route('editorial_board_member.index')->with('error', 'There is already pending request against this editor.');
            }
        }

        if ($page == 'download_cv') {

            $cv_path = 'ebm_cv/' . $id;
            $cv_file_path = config('constants.admin.ebm_root_path') . $cv_path;

            $headers = array(
                'Content-Type: application/pdf',
            );

            return Response::download($cv_file_path, $id, $headers);
        }

        if ($page == 'download_email_accp') {

            $cv_path = 'ebm_acceptance_email/' . $id;
            $cv_file_path = config('constants.admin.ebm_root_path') . $cv_path;

            $headers = array(
                'Content-Type: application/pdf',
            );

            return Response::download($cv_file_path, $id, $headers);
        }

        if ($page == 'download_eic_approval') {

            $cv_path = 'eic_approval/' . $id;
            $cv_file_path = config('constants.admin.ebm_root_path') . $cv_path;

            $headers = array(
                'Content-Type: application/pdf',
            );

            return Response::download($cv_file_path, $id, $headers);
        }

        if ($page == 'download_director_approval') {

            $cv_path = 'director_approval/' . $id;
            $cv_file_path = config('constants.admin.ebm_root_path') . $cv_path;

            $headers = array(
                'Content-Type: application/pdf',
            );

            return Response::download($cv_file_path, $id, $headers);
        }

        if ($page == 'download_agreement_form') {

            $cv_path = 'agreement_form/' . $id;
            $cv_file_path = config('constants.admin.ebm_root_path') . $cv_path;

            $headers = array(
                'Content-Type: application/pdf',
            );

            return Response::download($cv_file_path, $id, $headers);
        }

        if ($page == 'pending_list') {

            $pending_editors_list = "";
            $param['paginate']    = 10;
            $param['email']       = trim($request->get('email'));
            $param['user_id']       = Auth::user()->id;

            $param['verification_status'] = 'pending';
            $pending_editors_list = EBM::GetVerificationEditorsList($param);

            return view('admin.editorial_board_member.verification_request', ['pending_editors_list' => $pending_editors_list, 'page' => $page, 'param' => $param]);
        }

        if ($page == 'approve_list') {

            $approve_editors_list = "";
            $param['paginate']    = 10;
            $param['email']       = trim($request->get('email'));
            $param['user_id']       = Auth::user()->id;

            $param['verification_status'] = 'approve';
            $approve_editors_list = EBM::GetApproveorRejectListofEBM($param);

            return view('admin.editorial_board_member.verification_request', ['approve_editors_list' => $approve_editors_list, 'page' => $page, 'param' => $param]);
        }

        if ($page == 'reject_list') {

            $reject_editors_list = "";
            $param['paginate']    = 10;
            $param['email']       = trim($request->get('email'));
            $param['user_id']       = Auth::user()->id;

            $param['verification_status'] = 'reject';
            $reject_editors_list = EBM::GetApproveorRejectListofEBM($param);

            return view('admin.editorial_board_member.verification_request', ['reject_editors_list' => $reject_editors_list, 'page' => $page, 'param' => $param]);
        }

        if ($page == 'delete_editor_pending_request') {

            $update_editor['verification_status']  = 'delete';
            $update_editor['updated_on'] = now();
            $update_editor['updated_by'] = Auth::user()->id;
            $delete = EBM::UpdateEditorVerification($id, $update_editor);

            return redirect()->back()->with('success', 'Your request has been delete.');
        }

        if ($page == 'delete_editor_role_pending_request') {

            $update_editor_role['ebm_verification_status']  = 'delete';
            $update_editor_role['updated_on'] = now();
            $update_editor_role['updated_by'] = Auth::user()->id;
            $delete = EBM::UpdateEbmVerification($id, $update_editor_role);

            return redirect()->back()->with('success', 'Your request has been delete.');
        }

        if ($page == 'edit_editor_pending_request') {

            $verification_id = $id;
            $column_name = 'editor_id';

            $editor_verification = EBM::GetVerificationEditorbyID($verification_id, $column_name);
            $editorId = $editor_verification->editor_id;

            return redirect()->route('editorial_board_member.edit', ['verification_id' => $verification_id, 'editorial_board_member' => $editorId]);
        }

        if ($page == 'edit_editor_role_pending_request') {

            $ebm_verification_id = $id;
            $column_name = 'ebm_id,ebm_verification_comment,editor_id';

            $ebm_verification = EBM::GetEbmVerificationEditorbyID($ebm_verification_id, $column_name);
            $ebm_verification_comment = $ebm_verification->ebm_verification_comment;
            $editor_id = $ebm_verification->editor_id;
            $ebm_id = $ebm_verification->ebm_id;

            if ($ebm_verification_comment == 'Edit Editor Role') {

                return Redirect::route('editor_role', ['page' => 'edit', 'ebm_verification_id' => $ebm_verification_id, 'id' => $ebm_id]);
            } else {

                return Redirect::route('editor_role', ['page' => 'add', 'ebm_verification_id' => $ebm_verification_id, 'editor_id' => $editor_id]);
            }
        }
    }
}
