Sindbad~EG File Manager

Current Path : /home/numerotech/www/livemt2023.aios-scientificcommittee.org/app/controllers/
Upload File :
Current File : //home/numerotech/www/livemt2023.aios-scientificcommittee.org/app/controllers/ARCController.php

<?php

class ARCController extends BaseController {


    //IF id is null then create empty fp and redeirect to edit fp page
    //if id is not null then fp can edit 
    public function getARC($id = null){ 
        
        $step = Input::get('step');
        $categories = array('' => '--select--') + Category::ARC();       
        $pres_types = array('' => '--select--') + PresType::getPresType(CustomClass::getUserId());

        $membership = CustomClass::GetMembership();  

        $pres_auth_id = 0;

        try {
            if($id != null)
                $id = intval(urldecode(Helper::decrypt($id)));
        } catch (Exception $e) {
            return Redirect::to('dashboard');
        }
        
        if($id>0)
        {
            $arc = Abstracts::find($id);
            $abs_upload = AbsUpload::where('abs_id',$id)->get();
            
            if($arc != null)
            {
                if($arc->user_id != CustomClass::getUserId())
                {
                     return Redirect::to('dashboard');
                }
                else if($arc->status_id ==CustomClass::$Submitted)
                {
                   return Redirect::to('dashboard');
                } 

                $pa_author = Authors::where('abs_id',$arc->abs_id)->where('role_id',CustomClass::$PresentingAuthor)->first(); 
                if($pa_author !=null)
                {
                    $pres_auth_id =  $pa_author->user_id;
                }
            }
            else
            {
                return Redirect::to('dashboard');
            }
        }
        else
        {

            if($this->is_closed())
            {
                return Redirect::to('abstracts?type=PGT');
            }         
            else
            {

                 //dump creat table after step new fp
                $arc = new Abstracts();
                $arc->user_id    = CustomClass::getUserId();  
                $arc->abs_type   = CustomClass::$ARC;      
                $arc->save();
                return Redirect::to('arc/'.urlencode(Helper::encrypt($arc->abs_id)));
            }
           // if($this->is_closed())
           // {
           //  return Redirect::to('dashboard');
           // }
        }

        return View::make('arc.arc')
                    ->with('arc',$arc) 
                    ->with('abs_upload',$abs_upload)
                    ->with('pres_auth_id',$pres_auth_id)                   
                    ->with('categories',$categories)
                    ->with('pres_types',$pres_types)
                    ->with('membership',$membership)
                    ->with('step',$step);
    }

    //if FP count =< count 4 then close 
    public function is_closed()
    {
        $arcs = Abstracts::where('abs_type','ARC')->where('user_id',CustomClass::getUserId())->get();
        if(!(CustomClass::$ARC_Count > count($arcs)))
        {
            return true;
        }  
        else
        {
            return false;
        } 
    }

    //FP view
    public function view($id){      
        $categories = array('' => '--select--') + Category::lists('name','Category_id');        
        $pres_types = array('' => '--select--') + PresType::lists('type','presentation_type_id');
      
      

        if($id != null )
            $id = intval(urldecode(Helper::decrypt($id)));

        $arc = null;

        if($id>0)
        {
            $arc         = Abstracts::find($id);
            // $arr        = $this->get_ARCCOA_Count($id);
            // $arr        = $this->get_ARCGUIDE_Count($id);

            // $pa         = Abstracts::usp_get_authors(null,CustomClass::$ARC,CustomClass::$Guide,$id,null,null); 

            if(isset($pa[0]))
            {
                $pa =  $pa[0];
            }

            //$pa         = App::make('UserController')->getUserDetails($fp->pres_auth_id);
            $user       = App::make('UserController')->getUserDetails($arc->user_id); 

            return View::make('arc.view')->with('arc',$arc)
                                    ->with('categories',$categories)
                                    ->with('pres_types',$pres_types)
                                    ->with('user',$user); 
        }
                 
    }

    //FP Search user for Presenting Author
    public function getSearchMembersPA(){
        try {            $arr   = [];
            $data  = "";
            $msg   = "";            
            $code  = 0;

            $search = Helper::trimAndTruncate(Input::get('search'),250);
            //$fp_id  = intval(Input::get('fp_id'));

            //$data   = DB::select("call usp_SearchMembersForFPPA('".$search."',".$fp_id.")");   
            $data   = Abstracts::usp_get_authors($search,CustomClass::$FP,CustomClass::$PresentingAuthor,null,CustomClass::$UserType_FP_PA,null); 
           
            if(empty($data))
            {
                $data = "";
                $code = 0;
                $msg  = "record not found";
            }
            else
            {                
                $code = 1;
                $msg  = "";
            }


        } catch (Exception $e) {
            Log::error('ARCController - getSearchMembersPA'.$e->getMessage());
            $msg =AppMessage::$GENERAL_ERROR;

        }
        $arr = ['data' => $data, 'code' => $code, 'msg' => $msg];

         return Response::json($arr); 
    }

     //FP Search user for COA
    public function getSearchMembers(){
        try {

            $arr   = [];
            $data  = "";
            $msg   = "";            
            $code  = 0;

            $search =  Helper::trimAndTruncate(Input::get('search'),250);

            //$data = DB::select("call usp_SearchMembers ('".$search."')");   
             // $data   = Abstracts::usp_get_authors($search,CustomClass::$FP,CustomClass::$CoAuthor,null,CustomClass::$UserType_ARC_COA,null);

             $data   = Abstracts::usp_get_authors($search,CustomClass::$ARC,CustomClass::$Guide,null,CustomClass::$UserType_ARC_Guide,null);  
           
            if(empty($data))
            {
                $data = "";
                $code = 0;
                $msg  = "record not found";
            }
            else
            {                
                $code = 1;
                $msg  = "";
            }


        } catch (Exception $e) {
            Log::error('ARCController - getSearchMembers'.$e->getMessage());
            $msg =AppMessage::$GENERAL_ERROR;

        }
        $arr = ['data' => $data, 'code' => $code, 'msg' => $msg];

         return Response::json($arr); 
    }


    //FP Get Presenting Author
    public function getPADetails(){
        try {

            $arr   = [];
            $data  = "";
            $msg   = "";            
            $code  = 0;

            $pa_id  =  intval(Input::get('pa_id'));

            $data   = App::make('UserController')->getUserDetails($pa_id); 
           
            if(empty($data))
            {
                $data = "";
                $code = 0;                
            }
            else
            {                
                $code = 1;
                $msg  = "";
            }


        } catch (Exception $e) {
            Log::error('ARCController - getSearchMembersPA'.$e->getMessage());
            $msg =AppMessage::$GENERAL_ERROR;

        }
        $arr = ['data' => $data, 'code' => $code, 'msg' => $msg];

         return Response::json($arr); 
    }

    

    //FP Store
    public function store()
    {
        try {

            //for Response
            $arr = [];
            $code = 0;
            $msg = "";
            $data = "";
            
            $arc_id      = intval(Input::get('hdnId'));
            $pa_id      = intval(Input::get('hdnPAId'));
            $is_next    = intval(Input::get('hdnIsNext'));
            $step       = intval(Input::get("hdnStep"));


            //for first step only 
            $categories = array('' => '--select--') + Category::ARC();        
            $pres_types = array('' => '--select--') + PresType::lists('type','presentation_type_id');
            $membership = CustomClass::GetMembership();  

            $is_edit = true;

            $pres_auth_id = 0;

            $abs_upload = [];

            if($arc_id >0)
            {
                $arc = Abstracts::find($arc_id); 
                $abs_upload = AbsUpload::where('abs_id',$arc_id)->get();    
            }    
            else
                $arc = new Abstracts(); 

            if($arc != null)
            {
               $pa_author = Authors::where('abs_id',$arc->abs_id)->where('role_id',CustomClass::$PresentingAuthor)->first(); 
               if($pa_author !=null)
               {
                    $pres_auth_id =  $pa_author->user_id;
               } 
            }

            if($is_next == 1)
            {
                if($step ==1)
                {   

                    if($arc->status_id ==CustomClass::$Submitted)
                    {
                        $code   = 0;
                        $msg    = AppMessage::$ARC_ALREADY_SUBMIT ." <a href=". url('/dashboard'). " >Please, check the status in Dashboard</a>";    
                        $data   = "";

                    }
                    else
                    {

                        $arc->abs_type               = CustomClass::$ARC;
                        //$fp->pres_auth_id   = $pa_id;                   
                        $arc->category_id            = Input::get('ddlSection');                    
                        $arc->original_category_id   = Input::get('ddlSection');
                        // $arc->presentation_type_id   = Input::get('ddlType');       
                        $arc->user_id                = CustomClass::getUserId();                                                               
                        $arc->save();

                        //check and save chief instructor in author table 
                        $author = Authors::where('abs_id',$arc->abs_id)->where('role_id',CustomClass::$ChiefAuthor)->first();
                        if($author == null)
                        {
                            $author = new Authors();
                            $author->user_id = CustomClass::getUserId();   
                            $author->abs_id  = $arc->abs_id;
                            $author->role_id = CustomClass::$ChiefAuthor;
                            $author->consent_status_id = CustomClass::$Selected;
                            $author->save();
                        }   

                        //chief Author same PresentingAuthor
                        $author = Authors::where('abs_id',$arc->abs_id)->where('role_id',CustomClass::$PresentingAuthor)->first();
                        if($author == null)
                        {
                            $author = new Authors();
                            $author->user_id = CustomClass::getUserId();   
                            $author->abs_id  = $arc->abs_id;
                            $author->role_id = CustomClass::$PresentingAuthor;
                            $author->consent_status_id = CustomClass::$Selected;
                            $author->save();
                        }                   

                        $count = $this->get_ARCPA_Count($pres_auth_id);

                        if($count >= CustomClass::$ARC_Count)
                        {
                            $code   = 0;
                            $msg    = AppMessage::$ARC_PA_Count;    
                            $data   = "";
                        }
                        else
                        {
                            $code = 1;
                            $data = View::make('arc.step2')->with('arc',$arc)->render();     
                        }
                    }
                }                 

                if($step ==2)
                {   
                    if($arc->status_id ==CustomClass::$Submitted)
                    {
                        $code   = 0;
                        $msg    = AppMessage::$ARC_ALREADY_SUBMIT ." <a href=". url('/dashboard'). " >Please, check the status in Dashboard</a>";    
                        $data   = "";

                    }
                    else
                    {
                        $arc->user_id              = CustomClass::getUserId();
                        $arc->institution          = Helper::trimAndTruncate(Input::get('txtInstitute'),200);  
                        $arc->university           = Helper::trimAndTruncate(Input::get('txtUniversity'),200);  
                        $arc->mci_status           = Helper::trimAndTruncate(Input::get('txtMCIstate'),200);   
                        $arc->year_of_passing      = Helper::trimAndTruncate(Input::get('txtYearOfPassing'),200);  
                        $arc->guide                = Helper::trimAndTruncate(Input::get('txtGuide'),200);  
                        $arc->co_guide             = Helper::trimAndTruncate(Input::get('txtCoGuide'),200);  
                        $arc->hod                  = Helper::trimAndTruncate(Input::get('txtDepartment'),200);  
                        // $arc->arc_no               = $this->GetMaxARCNoPlusOne();  
                        $arc->submitted_on         = date('Y-m-d H:i:s');
                        $arc->title                = Helper::trimAndTruncate(Input::get('txtTitle'),300);  
                        $arc->synopsis             = Helper::trimAndTruncate(Input::get('txtSynopsis'),3000);                                       
                        $arc->save();

                        // $arr    = $this->get_ARCCOA_Count($arc_id);  
                        // $arr    = $this->get_ARCGUIDE_Count($arc_id);                          

                        $code   = 1;
                        $data   = View::make('arc.step3')->with('arc',$arc)
                                    ->with('abs_upload',$abs_upload)->render();
                    }
                }      
                if($step ==3)
                {   
                    if($arc->status_id ==CustomClass::$Submitted)
                    {
                        $code   = 0;
                        $msg    = AppMessage::$ARC_ALREADY_SUBMIT ." <a href=". url('/dashboard'). " >Please, check the status in Dashboard</a>";    
                        $data   = "";

                    }
                    else
                    {

                        // if($this->IsRatifiedMembers($arc))
                        // {                         
                            $code   = 1;
                            $data   = View::make('arc.step5')->with('arc',$arc)
                                        ->with('abs_upload',$abs_upload)
                                        ->with('categories',$categories)
                                        ->with('membership',$membership)->render();     
                        // }
                        // else
                        // {
                        //     $code   = 0;
                        //     $msg    = AppMessage::$ARC_RATIFIED_MEMBER;    
                        //     $data   = "";
                        // }
                    }

               }     
               if($step ==4)
                {   
                    if($arc->status_id ==CustomClass::$Submitted)
                    {
                        $code   = 0;
                        $msg    = AppMessage::$ARC_ALREADY_SUBMIT ." <a href=". url('/dashboard'). " >Please, check the status in Dashboard</a>";    
                        $data   = "";

                    }
                    else
                    {

                        $arc->is_in_india             = Input::get('rbtnIndia'); 
                        $arc->is_already_published    = Input::get('rbtnIsAlreadyPublished');   
                        $arc->lab_research            = Input::get('rbtnlab_research');   
                        if($arc->presentation_type_id == CustomClass::$Paper_or_EPoster || $arc->presentation_type_id == CustomClass::$EPoster_only)
                        {
                            $arc->is_consider_hp     = Input::get('rbtnIsConsiderhP');  
                        }
                        $arc->save();

                        // $arr    = $this->get_ARCCOA_Count($arc_id);  
                        // $arr    = $this->get_ARCGUIDE_Count($arc_id);

                        $pa         = Abstracts::usp_get_authors(null,CustomClass::$ARC,CustomClass::$PresentingAuthor,$arc_id,null,null); 
                        if(isset($pa[0]))
                        {
                            $pa =  $pa[0];
                        }
                        $code   = 1;
                        $data   = View::make('arc.step5')->with('arc',$arc)
                                    ->with('categories',$categories)
                                    ->with('pres_types',$pres_types)
                                    ->with('membership',$membership)
                                    ->with('isMaxCount',$arr["isMaxCount"])
                                    ->with('abs_upload',$abs_upload)->render();   
                    }
                }                
               if($step == 5)
               {

                    if($arc->status_id ==CustomClass::$Submitted)
                    {
                        $code   = 0;
                        $msg    = AppMessage::$ARC_ALREADY_SUBMIT ." <a href=". url('/dashboard'). " >Please, check the status in Dashboard</a>";    
                        $data   = "";

                    }
                    else
                    {

                        $count = $this->get_ARCPA_Count($pres_auth_id);
                       
                        if($count >= CustomClass::$ARC_Count)
                        {
                            $code   = 0;
                            $msg    = AppMessage::$ARC_PA_Count;    
                            $data   = "";
                        }
                        else
                        {
                            if(!($arc->abs_no >0))
                            {
                                $is_edit                    = false;                        
                                $arc->submitted_at           = date('Y-m-d H:i:s');
                                $arc->status_id      = CustomClass::$Submitted;                        
                                $result =    Abstracts::usp_generate_abs_no(CustomClass::$ARC,$arc->abs_id);
                                $arc->abs_no = $result[0]->abs_no;
                            }
                            
                            $arc->save();

                           

                            //FP mail    
                            $user = App::make('UserController')->getUserDetails($arc->user_id);
                            $pa         = Abstracts::usp_get_authors(null,CustomClass::$ARC,CustomClass::$PresentingAuthor,$arc->abs_id,null,null); 
                            if(isset($pa[0]))
                            {
                                $pa =  $pa[0];
                            }

                            

                             if($is_edit)
                            {
                                $this->arc_mail_data($user,$arc,$categories,$pres_types);       
                            }
                            else
                            {
                                $this->arc_mail($user,$arc,$categories,$pres_types);
                            }

                            

                            $code = 1;
                            $data = View::make('arc.success')->with('arc',$arc)->render();
                        }
                   }
                }
            }
            else 
            {
                if($step == 2)
                {   
                    $code = 1;
                    $data = View::make('arc.step1')
                                ->with('arc',$arc)
                                ->with('abs_upload',$abs_upload)
                                ->with('pres_auth_id',$pres_auth_id)
                                ->with('categories',$categories)
                                ->with('pres_types',$pres_types)
                                ->with('membership',$membership)->render();
                }   
                if($step == 3)
                {   
                    $code = 1;
                    $data = View::make('arc.step2')
                                ->with('arc',$arc)
                                ->with('abs_upload',$abs_upload)->render();
                }   
                if($step == 4)
                {   
                    // $arr    = $this->get_ARCCOA_Count($arc_id);  
                                 

                    $code   = 1;
                    $data   = View::make('arc.step3')->with('arc',$arc)
                                ->with('abs_upload',$abs_upload)->render();
                }  
                if($step == 5)
                {   
                    $code   = 1;
                    $data   = View::make('arc.step3')->with('arc',$arc)
                                                     ->with('abs_upload',$abs_upload)
                                                     ->render();    
                }                
            }
            
        } catch (Exception $e) {
            Log::error('ARCController - store :'.$e->getMessage());          
            $msg =AppMessage::$GENERAL_ERROR;
        }

        $arr = ['data' => $data, 'code' => $code, 'msg' => $msg];
        return Response::json($arr); 
    }

    //PA Store
    public function storePA()
    {
        try {

            //for Response
            $arr = [];
            $code = 0;
            $msg = "";
            $data = "";
            
            $arc_id         = intval(Input::get('arc_id'));
            $pa_user_id    = intval(Input::get('pa_user_id')); 

            $paauthor = Authors::where('abs_id',$arc_id)->where('role_id',CustomClass::$PresentingAuthor)->first();
            if($paauthor == null)
            {
                //presenting author            
                $pa_author = new Authors();
                $pa_author->user_id = $pa_user_id;   
                $pa_author->abs_id  = $arc_id;
                $pa_author->role_id = CustomClass::$PresentingAuthor;
                $pa_author->consent_status_id = CustomClass::$Selected;
                //$pa_author->save();            
                //$code = 1;

                //use for validation
                $count = $this->get_ARCPA_Count($pa_user_id);
                
                if($count >= CustomClass::$ARC_Count)
                {
                    $code = 0;
                    $msg  = AppMessage::$ARC_PA_Count;
                }             
                else 
                {
                    $code = 1;
                    $pa_author->save();
                }
            }
            else
            {
                 $code = 1; 
            }
            
        } catch (Exception $e) {
            Log::error('ARCController - storePA :'.$e->getMessage());          
            $msg =AppMessage::$GENERAL_ERROR;
        }

        $arr = ['data' => $data, 'code' => $code, 'msg' => $msg];
        return Response::json($arr);
    }


    public function storeGuide()
    {
        try {

            //for Response
            // $arr = [];
            $code = 0;
            $msg = "";
            $data = "";
            
            $arc_id          = intval(Input::get('arc_id'));
            $guide_user_id    = intval(Input::get('guide_user_id')); 


            $au_guide = new Authors();
            $au_guide->role_id       =     CustomClass::$Guide;
            $au_guide->abs_id        =     $arc_id;
            $au_guide->user_id       =     $guide_user_id;   
            $au_guide->consent_status_id = CustomClass::$Selected;                     
            $au_guide->is_present    =     1;

            $arc = Abstracts::find($arc_id);   

            //use for validation
            // $arr = $this->get_ARCCOA_Count($arc_id,$coa_user_id);
            // $arr    = $this->get_ARCGUIDE_Count($arc_id,$guide_user_id);

            // if($arr["isDuplicate"])
            // {
            //     $code = 0;
            //     $msg  = AppMessage::$ARC_GUIDE_Duplicate;
            // }
            // else if($arr["isMaxCount"])
            // {
            //     $code = 0;
            //     $msg  = AppMessage::$ARC_GUIDE_Count;
            // }             
            // else 
            // {
                $code = 1;
                $au_guide->save();
            // }


           $au_guide =  Authors::where('abs_id',$arc_id)->where('user_id',$guide_user_id)->where('role_id',CustomClass::$Guide)->first(); 

            //use for get coi list
            // $arr = $this->get_ARCCOA_Count($arc_id);
            // $arr    = $this->get_ARCGUIDE_Count($arc_id);
            
            $data = View::make('arc.step3')
                                ->with('arc',$arc)
                                ->with('au_guide',$au_guide)
                                ->with('guides',$arr["guides"])
                                ->with('isMaxCount',$arr["isMaxCount"])
                                ->with('abs_upload',$abs_upload)->render();
            
        } catch (Exception $e) {
            Log::error('ARCController - storeGuide :'.$e->getMessage());          
            $msg =AppMessage::$GENERAL_ERROR;
        }

        $arr = ['data' => $data, 'code' => $code, 'msg' => $msg];
        return Response::json($arr);
    }

    //COA Store
    public function storeCOA()
    {
        try {

            //for Response
            $arr = [];
            $code = 0;
            $msg = "";
            $data = "";
            
            $arc_id          = intval(Input::get('arc_id'));
            $coa_user_id    = intval(Input::get('coa_user_id')); 


            $coa = new Authors();
            $coa->role_id       =     CustomClass::$CoAuthor;
            $coa->abs_id        =     $arc_id;
            $coa->user_id       =     $coa_user_id;   
            $coa->consent_status_id = CustomClass::$Selected;                     
            $coa->is_present    =     1;

            $arc = Abstracts::find($arc_id);   

            //use for validation
            // $arr = $this->get_ARCCOA_Count($arc_id,$coa_user_id);
            $arr    = $this->get_ARCGUIDE_Count($arc_id,$guide_user_id);

            if($arr["isDuplicate"])
            {
                $code = 0;
                $msg  = AppMessage::$ARC_COA_Duplicate;
            }
            else if($arr["isMaxCount"])
            {
                $code = 0;
                $msg  = AppMessage::$ARC_COA_Count;
            }             
            else 
            {
                $code = 1;
                $coa->save();
            }
           

            //use for get coi list
            // $arr = $this->get_ARCCOA_Count($arc_id);
            $arr    = $this->get_ARCGUIDE_Count($arc_id);
            
            $data = View::make('arc.step3')
                                ->with('arc',$arc)
                                ->with('abs_upload',$abs_upload)->render();
            
        } catch (Exception $e) {
            Log::error('ARCController - storeCOA :'.$e->getMessage());          
            $msg =AppMessage::$GENERAL_ERROR;
        }

        $arr = ['data' => $data, 'code' => $code, 'msg' => $msg];
        return Response::json($arr);
    }


    //FP Get Max FPNo Plus  one
    // public function GetMaxARCNoPlusOne()
    // {
    //      $arcno = ARC::max('arc_no');
    //      return (intval($arcno) + 1); 
    // }

    //COA Remove
    public function removePA()
    {
        try {

            //for Response
            $arr    = [];
            $code   = 0;
            $msg    = "";
            $data   = "";

            $arc_id = intval(Input::get('arc_id'));
            $pa_id = intval(Input::get('pa_id'));
            
            $pa =  Authors::where('abs_id',$arc_id)->where('user_id',$pa_id)->where('role_id',CustomClass::$PresentingAuthor)->first();

            $pa->delete();
            $code = 1;            

            // $fp = Abstracts::find($fp_id);         

            // $arr = $this->get_ARCCOA_Count($fp_id);

            // $code = 1;
            // $data = View::make('fp.step3')
            //                     ->with('fp',$fp)
            //                     ->with('coas',$arr["coas"])
            //                     ->with('isMaxCount',$arr["isMaxCount"])->render();
            
            
        } catch (Exception $e) {
            Log::error('ARCController - removeCOA :'.$e->getMessage());          
            $msg =AppMessage::$GENERAL_ERROR;            
        }

        $arr = ['data' => $data, 'code' => $code, 'msg' => $msg];
        return Response::json($arr); 

    }


    //COA Remove
    public function removeCOA()
    {
        try {

            //for Response
            $arr    = [];
            $code   = 0;
            $msg    = "";
            $data   = "";

            $arc_id = intval(Input::get('arc_id'));
            $coa_id = intval(Input::get('coa_id'));
            
            $coa =  Authors::find($coa_id);

            $coa->delete();
            
            $arc = Abstracts::find($arc_id);         

            $arr = $this->get_ARCCOA_Count($arc_id);

            $code = 1;
            $data = View::make('arc.step3')
                                ->with('arc',$arc)
                                ->with('coas',$arr["coas"])
                                ->with('isMaxCount',$arr["isMaxCount"])
                                ->with('abs_upload',$abs_upload)->render();
            
            
        } catch (Exception $e) {
            Log::error('ARCController - removeCOA :'.$e->getMessage());          
            $msg =AppMessage::$GENERAL_ERROR;
        }

        $arr = ['data' => $data, 'code' => $code, 'msg' => $msg];
        return Response::json($arr); 

    }

    
    //Get PA Count for validation 
    public function get_ARCPA_Count($pa_uid)
    {           

        try {
                $isMaxCount     = false;

                $users   = null;
                $users   = Abstracts::usp_get_abstracts(null,null,null,null,null,null,null,$pa_uid,null,null,null,null); 
                $pa_count  = 0;
                foreach ($users["engaged"] as $key => $value) {
                    if($value->abs_type==CustomClass::$ARC && $value->role_id==CustomClass::$PresentingAuthor && $value->status_id == CustomClass::$Submitted)
                    {
                        $pa_count++;
                    }
                }

        } catch (Exception $e) {
            Log::error('ARCController - get_ARCPA_Count :'.$e->getMessage());    
        }
                     
        return $pa_count;
    }

    //Guide count for validation 
     public function get_ARCGUIDE_Count($arc_id,$guide_uid = null)
    {           

        try {
                $isMaxCount     = false;
                $isDuplicate    = false; 

                //ToDo: call sp from new version 
                //$coas           = DB::select('call usp_getCOAByFPId('.$fp_id.')');                            
                $coas = null;
                $coas   = Abstracts::usp_get_authors(null,CustomClass::$ARC,CustomClass::$Guide,$arc_id,CustomClass::$UserType_ARC_Guide,null); 

                

                $guide_uids       = [];                

                if(isset($guides) &&  count($guides) >0)
                {
                    foreach ($guides as $key => $value) {  
                        if($guide_uid == $value->user_id)              
                        {
                            $isDuplicate =true;
                        }
                        
                        array_push($guide_uids, $value->user_id);    
                    }    
                }
                else
                {
                    $guides = [];                
                }

                if(count(array_unique($guide_uids)) >=  CustomClass::$ARC_GUIDE_Count)
                {
                  $isMaxCount = true;
                }    
        } catch (Exception $e) {
            Log::error('ARCController - get_ARCGUIDE_Count :'.$e->getMessage());    
        }
                     

            return ["isMaxCount" => $isMaxCount,"isDuplicate" => $isDuplicate ,"guides" => $guides];

    }

    //Get COA and COA Count for validation 
    public function get_ARCCOA_Count($arc_id,$coa_uid = null)
    {           

        try {
                $isMaxCount     = false;
                $isDuplicate    = false; 

                //ToDo: call sp from new version 
                //$coas           = DB::select('call usp_getCOAByFPId('.$fp_id.')');                            
                $coas = null;
                $coas   = Abstracts::usp_get_authors(null,CustomClass::$ARC,CustomClass::$CoAuthor,$arc_id,CustomClass::$UserType_ARC_COA,null); 

                

                $coa_uids       = [];                

                if(isset($coas) &&  count($coas) >0)
                {
                    foreach ($coas as $key => $value) {  
                        if($coa_uid == $value->user_id)              
                        {
                            $isDuplicate =true;
                        }
                        
                        array_push($coa_uids, $value->user_id);    
                    }    
                }
                else
                {
                    $coas = [];                
                }

                if(count(array_unique($coa_uids)) >=  CustomClass::$ARC_COA_Count)
                {
                  $isMaxCount = true;
                }    
        } catch (Exception $e) {
            Log::error('ARCController - get_ARCCOA_Count :'.$e->getMessage());    
        }
                     

            return ["isMaxCount" => $isMaxCount,"isDuplicate" => $isDuplicate ,"coas" => $coas];

    }

    //RATIFIED MEMBER Check for fp
    public function IsRatifiedMembers($arc)
    {
        $isretified = false;

        $ca  = App::make('UserController')->getUserDetails($arc->user_id);

        if($ca->user_type_id==CustomClass::$Ratified_Member)
        {
            $isretified = true;             
        }        

        // $pa  = App::make('UserController')->getUserDetails($fp->pres_auth_id); 
        // if(!empty($pa->membership_no))
        // {
        //     $isretified = true; 
        // }            

            $pa         = Abstracts::usp_get_authors(null,CustomClass::$ARC,CustomClass::$PresentingAuthor,$arc->abs_id,null,null); 
            if(isset($pa[0]))
            {
                $pa =  $pa[0];
                if($pa->user_type_id==CustomClass::$Ratified_Member)
                {
                    $isretified = true;                     
                }            
            }


        $arr = $this->get_ARCCOA_Count($arc->abs_id);
      //  var_dump($arr['coas']);
        foreach ($arr['coas'] as $key => $value) {
            if($value->user_type_id==CustomClass::$Ratified_Member)
            {
                $isretified = true;                 
            }
        }



        return $isretified;

    }


    //FP Mail Send add cc COA
    public function arc_mail($user,$arc,$categories,$pres_types)
    {
        if(empty($user->email))
        {
            return;
        }
        if(CustomClass::$IsEmailEnabled)
        {
             $isMailSend  =  Mail::send('emails.arc.chiefauthor', array('user' => $user,'arc' =>$arc,'categories'=>$categories,'pres_types' =>$pres_types), function($message) use ($arc,$user)
                                {       
                                    $message->subject(sprintf(Subject::$arc_ca,$arc->abs_no)); 
                                    if(CustomClass::$IsEmailTest)
                                    {
                                        $message->to(CustomClass::$TestMailId);   
                                    }
                                    else
                                    {

                                        $message->to($user->email);                                             
                                        // if(isset($coa) && count($coa)>0)                        
                                        // {
                                            // foreach ($coa as $value) {           
                                                // if(!empty($user->email))                                     
                                                //     $message->cc($user->email);
                                            // }    
                                        // }                                    
                                        // if(isset($pa) && !empty($pa))
                                        // {
                                        //     if(!empty($pa->email))
                                        //         $message->cc($pa->email);
                                        // }
                                        $message->cc(CustomClass::$BackupId);
                                    }
                                });  
        }
    }


    //FP Mail Send add cc COA
    public function arc_mail_data($user,$arc,$categories,$pres_types)
    {
        if(empty($user->email))
        {
            return;
        }
        if(CustomClass::$IsEmailEnabled)
        {
             $isMailSend  =  Mail::send('emails.arc.chiefauthor_data', array('user' => $user,'arc' =>$arc,'categories' => $categories ,'pres_types' =>$pres_types), function($message) use ($arc,$user)
                                {   

                                    $message->subject(sprintf(Subject::$arc_ca,$arc->abs_no)); 
                                    if(CustomClass::$IsEmailTest)
                                    {
                                        $message->to(CustomClass::$TestMailId);   
                                    }                          
                                    else
                                    {
                                        $message->to($user->email);                                                                                 
                                        // if(isset($coa) && count($coa)>0)                        
                                        // {                                            
                                            // foreach ($coa as $value) {
                                                // if(!empty($user->email))
                                                //     $message->cc($value->email);
                                            // }    
                                        // }                                    
                                        // if(isset($pa) && !empty($pa))
                                        // {
                                        //     if(!empty($pa->email))
                                        //         $message->cc($pa->email);
                                        // }
                                        $message->cc(CustomClass::$BackupId);
                                    }                                
                                    

                                });  
        }
    }



    //PA Awards 
    public function getPAAwards()
    {
        try {

            //for Response
            $arr    = [];
            $code   = 0;
            $msg    = "";
            $data   = "";

            $pa_id      = intval(Input::get('pa_id'));
            $cat_id     = intval(Input::get('cat_id'));
            $abs_type    = Input::get('abs_type');
            


            $awards     = Awards::usp_get_awards($pa_id,$cat_id,$abs_type);            


            //$awards     = DB::select('call usp_get_pa_awards('.$pa_id.','.$cat_id.','.$type_id.')'); 
            $str        = "";
            $isAwa      = false;
            if (Count($awards) > 0)
                {
                    $str = "<b>Please note :</b>  The presenting author you have chosen is already a winner of <br />";

                    foreach ($awards as $key => $value)
                    {
                        $flag = false;
                        if ($value->abs_type == "FP")
                        {                           
                            
                            if ($value->category_id == $cat_id)
                            {
                                $flag = true;
                            }
                        }
                        else
                        {
                            $flag = true;
                        }
                        if ($flag)
                        {
                            $isAwa = true;
                            $str .= "\"" . $value->award_name . "\" - ".CustomClass::$ConferenceInitial. " " . $value->year . ".<br />";
                        }

                    }

                    if ($isAwa)
                    {
                        $str .= "Hence your submission would not be eligible to contest for the above award(s)";
                        $str .= "<br /><br />You may either change the presenting author or click \"NEXT\" to proceed further with the selected presenting author.";
                        $msg = $str;
                        $code = 1;
                    }
                    else
                    {
                        $code = 0;
                        $msg  = "";
                    }
                }
                else
                {
                    $code = 0;
                    $msg  = "";
                }
            
            
        } catch (Exception $e) {
            Log::error('ARCController - getPAAwards :'.$e->getMessage());          
            $msg =AppMessage::$GENERAL_ERROR;
            $code=0;
        }

        $arr = ['data' => $data, 'code' => $code, 'msg' => $msg];
        return Response::json($arr); 

    }

    /******************************* Upload *******************************************/


  public function uploadFP($id=null)
    {
           try{

                $user = null;
                $abs_id = Input::get('abs_id',0);

                if(!is_null($id))
                {
                    $user = User::where('uuid',$id)->first();
                }
                else
                {
                    $user = Auth::user();   
                }

                if(!is_null($user)){
               // $result     = Abstracts::usp_get_abstracts(null,null,'FP',null,null,null,1,$user->user_id,null,null,null,null);

               // $result   = $result['abstracts'];
                    $result = Abstracts::where('user_id', '=', $user->user_id)
                                             ->where('abs_type','ARC')
                                             ->where('status_id','>',0)
                                             // ->where('presentation_type_id',3)
                                             ->whereIn('selection_type_id',array(2))
                                             ->select(DB::raw('CONCAT(abs_type,abs_no, " - ",title) AS no'),'abs_id')
                                             ->orderby('abs_no')
                                             ->lists('no','abs_id');



                       if(isset($result) && count($result)>0)
                       {
                            return View::make("fp.upload")->with("user",$user)
                                                      ->with("result",$result)
                                                      ->with("abs_id",$abs_id);
                       }
                       else
                       {
                            return Redirect::to("abstracts");     
                       }
                        
                     }                                 
                 else
                    return Redirect::to("abstracts");
   

            }
            catch (Exception $e) {
            Log::error('ARCController - uploadFP :'.$e->getMessage());          
            $msg =AppMessage::$GENERAL_ERROR;
            echo $e->getMessage(); 
            
            }
    }


    public function uploadEP($id=null)
    {
           try{

                $user = null;
                $abs_id = Input::get('abs_id',0);

                if(!is_null($id))
                {
                    $user = User::where('uuid',$id)->first();
                }
                else
                {
                    $user = Auth::user();   
                }

                if(!is_null($user)){
               // $result     = Abstracts::usp_get_abstracts(null,null,'FP',null,null,null,1,$user->user_id,null,null,null,null);

               // $result   = $result['abstracts'];
                    $result = Abstracts::where('user_id', '=', $user->user_id)
                                             ->where('abs_type','FP')
                                             ->where('status_id','>',0)
                                             // ->where('presentation_type_id',3)
                                             ->whereIn('selection_type_id',array(3,9))
                                             ->select(DB::raw('CONCAT(abs_type,abs_no, " - ",title) AS no'),'abs_id')
                                             ->orderby('abs_no')
                                             ->lists('no','abs_id');



                       if(isset($result) && count($result)>0)
                       {
                            return View::make("fp.upload_ep")->with("user",$user)
                                                      ->with("result",$result)
                                                      ->with("abs_id",$abs_id);
                       }
                       else
                       {
                            return Redirect::to("abstracts");     
                       }
                        
                     }                                 
                 else
                    return Redirect::to("abstracts");
   

            }
            catch (Exception $e) {
            Log::error('ARCController - uploadEP :'.$e->getMessage());          
            $msg =AppMessage::$GENERAL_ERROR;
            echo $e->getMessage(); 
            
            }
    }

    public function postUpload() {

    try {

        // getting all of the post data
        $file = Input::file('uploadpdf');
        $abs_id =Input::get('fpid');
        $abs =Abstracts::where('abs_id', '=', $abs_id)->first();
        $abs_no=$abs->abs_no;
        $user =  User::find($abs->user_id);
        $auto_login=$user->uuid;
    
        $rules = array('file' => 'required'); //'required|mimes:png,gif,jpeg,txt,pdf,doc'
        $validator = Validator::make(array('file'=> $file), $rules);
        if($validator->passes()){
            $destinationPath = 'FPUploads';
            $extention = $file->getClientOriginalExtension();
            $filename = "FP".$abs_no.".".$extention;            

            $upload_success = $file->move($destinationPath, $filename);

            $fu = AbsUpload::where('abs_id', '=', $abs_id)->first();
            if(is_null($fu))
            {
               $fu = new AbsUpload();  
            }    

            $fu->file_name=$filename;
            $fu->path=$destinationPath;
            $fu->abs_id  =$abs_id;
            $fu->save();
            if($fu)
            {
                if($abs->selection_type_id == 2)
                 return Redirect::to("fp/upload". (isset($auto_login)? "/" . $auto_login:"")   ."?abs_id=".$abs_id)->with('msgSuccess','File Uploaded Sucessfully');
                else if($abs->selection_type_id == 3 || $abs->selection_type_id == 9)
                     return Redirect::to("ep/upload". (isset($auto_login)? "/" . $auto_login:"")   ."?abs_id=".$abs_id)->with('msgSuccess','File Uploaded Sucessfully');
            } 
        }

        } catch (Exception $e) {
            //echo $e->getMessage(); 
               Log::error('ARCController - postUpload :'.$e->getMessage());          
              return Redirect::to("fp/upload/".$auto_login)->with('msgError',AppMessage::$GENERAL_ERROR);  

        }

  }
  public function getUpload(){
        try {

            $arr   = [];
            $data  = "";
            $msg   = "";            
            $code  = 0;

            $abs_id =  Helper::trimAndTruncate(Input::get('fpid'),250);

            $abs   = Abstracts::find($abs_id);
            $selection_type_id =  $abs->selection_type_id;

            //$data = DB::select("call usp_SearchMembers ('".$search."')");   
             $data   = AbsUpload::where('abs_id', '=', $abs_id)->first();
           
            if(empty($data))
            {
                $data = "";
                $code = 0;
                $msg  = "record not found";
            }
            else
            {                
                $code = 1;
                $msg  = "";
            }


        } catch (Exception $e) {
            Log::error('ARCController - getUpload'.$e->getMessage());
            $msg =AppMessage::$GENERAL_ERROR;

        }
        $arr = ['data' => $data, 'code' => $code, 'msg' => $msg,'selection_type_id'=>$selection_type_id];

         return Response::json($arr); 
    }

    public function deleteUpload(){
        try {

            $arr   = [];
            $data  = "";
            $msg   = "";            
            $code  = 0;

            $abs_id =  Helper::trimAndTruncate(Input::get('fpid'),250);

            //$data = DB::select("call usp_SearchMembers ('".$search."')");   
             $data   = AbsUpload::where('abs_id', '=', $abs_id)->first();
             $file_path= $data->path .'/'. $data->file_name;
             $data->delete();
             unlink(public_path() .'/'. $file_path);


        } catch (Exception $e) {
            Log::error('ARCController - deleteUpload'.$e->getMessage());
            $msg =AppMessage::$GENERAL_ERROR;

        }
        $arr = ['data' => $data, 'code' => $code, 'msg' => $msg];

         return Response::json($arr); 
    }
/******************************* Upload *******************************************/

/******************************* Hyde park *****************************************/ 
 public function physicalHP($abs_id){
        try {
            
            $abs_id = intval(urldecode(Helper::decrypt($abs_id)));  
            $msg = "";
            $result = DB::select("call usp_physical_hydepark($abs_id)");            
            if(isset($result))
            {
                $msg = $result[0]->msg;    
            }
            else
            {
                $msg = AppMessage::$GENERAL_ERROR;       
            }

        } catch (Exception $e) {
            Log::error('ARCController - physicalHP'.$e->getMessage());
            $msg =AppMessage::$GENERAL_ERROR;
        }
        return View::make("msg")->with('msg',$msg);    
    }

/******************************* Hyde park *****************************************/ 


/******************************* Consent Judge *****************************************/ 
public function ConsentJudge($id){
        try {

            $id  = urldecode(Helper::decrypt($id));  
            $exp = explode(',', $id);
            $name_in_grid_id    = $exp[0];
            $user_id            = $exp[1];
            $role_id            = $exp[2];
            $consent_status_id  = $exp[3];            
            
            $msg = "";

            $result = DB::select("call usp_consent_judge($name_in_grid_id,$user_id,$role_id,$consent_status_id)");            
            if(isset($result))
            {
                $msg = $result[0]->msg;    
            }
            else
            {
                $msg = AppMessage::$GENERAL_ERROR;       
            }

        } catch (Exception $e) {
            Log::error('ARCController - ConsentJudge'.$e->getMessage());
            $msg =AppMessage::$GENERAL_ERROR;
        }
        return View::make("msg")->with('msg',$msg);    
}

/******************************* Consent Judge *****************************************/ 




/******************************* Change author order  *****************************************/ 
public function getChangeAuthorOrder($id){
        try {

            $abs_id  = urldecode(Helper::decrypt($id));  
            $abstracts  = [];
            $authors_db = [];
            $authors    = [];

            $result    = Abstracts::usp_get_abstracts(null,null,'FP',null,$abs_id,null,'1',null,null,NULL,null,null,null);
            $abstracts = $result['abstracts'];
            $authors_db   = $result['authors'];

            foreach ($authors_db as $key => $value) {
                $authors[$value->abs_id][] = $value;
            }
            
            $date = DateConfig::getDateConfig('FPROLECHANGE');
            $end_date   = $date->end_date;


            return View::make("fp.change_author_order")->with("id",$id)
                                                      ->with("abs",$abstracts[0])
                                                      ->with("authors",$authors)
                                                      ->with("end_date",$end_date);
            

        } catch (Exception $e) {
            Log::error('ARCController - ConsentJudge'.$e->getMessage());
            $msg =AppMessage::$GENERAL_ERROR;
        }
        return View::make("msg")->with('msg',$msg);    
}


public function postChangeAuthorOrder($id){
        try {

            $abs_id  = urldecode(Helper::decrypt($id));             

            $prst_author_id = Input::get("rbtnPresAuthor");
            $frist_author = Input::get("ddlFirstAuthor");
            $second_author = Input::get("ddlSecondAuthor");
            $third_author = Input::get("ddlThirdAuthor");
            $fourth_author = Input::get("ddlFourthAuthor");

            if(intval($prst_author_id)>0)            
            {
                $pa_author = Authors::where('abs_id',$abs_id)->where('role_id',CustomClass::$PresentingAuthor)->first();

                $pa_author->user_id = $prst_author_id;    
                $pa_author->save();
            }

            if(intval($frist_author)>0)
            {
                $chief_author = Authors::where('abs_id',$abs_id)->where('role_id',CustomClass::$ChiefAuthor)->first();
                $chief_author->user_id = $frist_author;    
                $chief_author->save();

                $abs = Abstracts::find($abs_id) ;
                $abs->user_id= $frist_author; 
                $abs->save();
            }

            $co_authors = Authors::where('abs_id',$abs_id)->where('role_id',CustomClass::$CoAuthor)->get();
            $i=1;
            foreach ($co_authors as $key => $value) {            
                if($i==1)
                {
                    $value->order_no =2;
                    $value->user_id = $second_author;                   
                    $value->save();
                }
                else     if($i==2)
                {
                    $value->order_no =3;
                    $value->user_id = $third_author;                   
                    $value->save();
                }
                else     if($i==3)
                {
                    $value->order_no =4;
                    $value->user_id = $fourth_author;                   
                    $value->save();
                }
                $i++;
            }

            return Redirect::to('/fp/change_author_order/'.$id)->with('msgSuccess','The order has been changed successfully');

        } catch (Exception $e) {
            Log::error('ARCController - postChangeAuthorOrder'.$e->getMessage());
            $msg =AppMessage::$GENERAL_ERROR;
            return Redirect::to('/fp/change_author_order/'.$id)->with('msgError',$msg);
        }
         //return View::make("msg")->with('msg',$msg);    
            
}

//Upload File Remove
    public function removeImage()
    {
        try {

            //for Response
            $arr    = [];
            $code   = 0;
            $msg    = "";
            $data   = "";

            $arc_id = intval(Input::get('abs_id'));
            $upload_id = intval(Input::get('upload_id'));
            
            
            
            
            $upload_id =  AbsUpload::find($upload_id);

            $upload_id->delete();
            
            $arc = Abstracts::find($arc_id);
            $abs_upload = AbsUpload::where('abs_id',$arc_id)->get();

            $code = 1;
            $data   = View::make('arc.step3')->with('arc',$arc)
                                    ->with('abs_upload',$abs_upload)->render();
            
        } catch (Exception $e) {
            Log::error('ARCController - removeImage :'.$e->getMessage());          
            $msg =AppMessage::$GENERAL_ERROR;
        }

        $arr = ['data' => $data, 'code' => $code, 'msg' => $msg];
        return Response::json($arr); 

    }

/******************************* Change author order *****************************************/ 


}


Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists