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/PPController.php

<?php

class PPController 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 getPP($id = null){ 

    	$categories = array('' => '--select--') + Category::FP();    	
    	$pres_types = array('' => '--select--') + PresType::lists('type','presentation_type_id');

    	$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)
		{
			$fp	= Abstracts::find($id);
            if($fp != null)
            {
                if($fp->user_id != CustomClass::getUserId())
                {
                     return Redirect::to('dashboard');
                }
                else if($fp->status_id ==CustomClass::$Submitted)
                {
                   return Redirect::to('dashboard');
                } 

                $pa_author = Authors::where('abs_id',$fp->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
        {
             //dump creat table after step new fp
            $fp = new Abstracts();
            $fp->user_id    = CustomClass::getUserId();  
            $fp->abs_type   = CustomClass::$PP;      
            $fp->save();
            return Redirect::to('pp/'.urlencode(Helper::encrypt($fp->abs_id)));

           // if($this->is_closed())
           // {
           //  return Redirect::to('dashboard');
           // }
        }

        return View::make('pp.pp')
        			->with('fp',$fp) 
                    ->with('pres_auth_id',$pres_auth_id)                   
        			->with('categories',$categories)
        			->with('pres_types',$pres_types)
        			->with('membership',$membership);
    }

    //if FP count =< count 4 then close 
    public function is_closed()
    {
        $fps = Abstracts::where('user_id',CustomClass::getUserId())->get();
        if(!(CustomClass::$PP_Count > count($fps)))
        {
            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)));

        $fp = null;

        if($id>0)
        {
            $fp         = Abstracts::find($id);
            $arr        = $this->get_PPCOA_Count($id);

            
            $pa         = Abstracts::usp_get_authors(null,CustomClass::$PP,CustomClass::$PresentingAuthor,$id,null,null); 
            if(isset($pa[0]))
            {
                $pa =  $pa[0];
            }

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

            return View::make('pp.view')->with('fp',$fp)
                                    ->with('coas',$arr["coas"])
                                    ->with('pa',$pa)
                                    ->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::$PP,CustomClass::$PresentingAuthor,null,CustomClass::$UserType_PP_PA,null); 
           
            if(empty($data))
            {
                $data = "";
                $code = 0;
                $msg  = "record not found";
            }
            else
            {                
                $code = 1;
                $msg  = "";
            }


        } catch (Exception $e) {
            Log::error('PPController - 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::$PP,CustomClass::$CoAuthor,null,CustomClass::$UserType_PP_COA,null); 
           
            if(empty($data))
            {
                $data = "";
                $code = 0;
                $msg  = "record not found";
            }
            else
            {                
                $code = 1;
                $msg  = "";
            }


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

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

         return Response::json($arr); 
    }


    //PP 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('PPController - 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 = "";
            
            $fp_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::FP();        
            $pres_types = array('' => '--select--') + PresType::lists('type','presentation_type_id');
            $membership = CustomClass::GetMembership();  

            $is_edit = true;

            $pres_auth_id = 0;

            if($fp_id >0)
                $fp = Abstracts::find($fp_id);         
            else
                $fp = new Abstracts(); 

            if($fp != null)
            {
               $pa_author = Authors::where('abs_id',$fp->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($fp->status_id ==CustomClass::$Submitted)
                    {
                        $code   = 0;
                        $msg    = AppMessage::$PP_ALREADY_SUBMIT ." <a href=". url('/dashboard'). " >Please, check the status in Dashboard</a>";    
                        $data   = "";

                    }
                    else
                    {

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

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

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

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

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

                    }
                    else
                    {
                        $fp->title      = Helper::trimAndTruncate(Input::get('txtTitle'),200);  
                        $fp->synopsis   = Helper::trimAndTruncate(Input::get('txtSynopsis'),3000);                                       
                        $fp->save();

                        $arr    = $this->get_PPCOA_Count($fp_id);                            

                        $code   = 1;
                        $data   = View::make('pp.step3')->with('fp',$fp)
                                    ->with('coas',$arr["coas"])
                                    ->with('isMaxCount',$arr["isMaxCount"])->render();
                    }
                }      
                if($step ==3)
                {   
                    if($fp->status_id ==CustomClass::$Submitted)
                    {
                        $code   = 0;
                        $msg    = AppMessage::$PP_ALREADY_SUBMIT ." <a href=". url('/dashboard'). " >Please, check the status in Dashboard</a>";    
                        $data   = "";

                    }
                    else
                    {

                        if($this->IsRatifiedMembers($fp))
                        {                         
                            $code   = 1;
                            $data   = View::make('pp.step4')->with('fp',$fp)->render();     
                        }
                        else
                        {
                            $code   = 0;
                            $msg    = AppMessage::$PP_RATIFIED_MEMBER;    
                            $data   = "";
                        }
                    }

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

                    }
                    else
                    {

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

                        $arr    = $this->get_PPCOA_Count($fp_id);                    
                        $pa         = Abstracts::usp_get_authors(null,CustomClass::$PP,CustomClass::$PresentingAuthor,$fp_id,null,null); 
                        if(isset($pa[0]))
                        {
                            $pa =  $pa[0];
                        }
                        $code   = 1;
                        $data   = View::make('pp.step5')->with('fp',$fp)
                                    ->with('coas',$arr["coas"])
                                    ->with('pa',$pa)
                                    ->with('categories',$categories)
                                    ->with('pres_types',$pres_types)
                                    ->with('membership',$membership)
                                    ->with('isMaxCount',$arr["isMaxCount"])->render();   
                    }
                }                
               if($step == 5)
               {

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

                    }
                    else
                    {

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

                           

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

                            $arr = $this->get_PPCOA_Count($fp_id);

                             if($is_edit)
                            {
                                $this->pp_mail_data($user,$pa,$fp,$arr['coas'],$categories,$pres_types);       
                            }
                            else
                            {
                                $this->pp_mail($user,$pa,$fp,$arr['coas'],$categories);
                            }

                            

                            $code = 1;
                            $data = View::make('pp.success')->with('fp',$fp)->with('coas',$arr["coas"])->render();
                        }
                   }
                }
            }
            else 
            {
                if($step == 2)
                {   
                    $code = 1;
                    $data = View::make('pp.step1')
                                ->with('fp',$fp)
                                ->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('pp.step2')
                                ->with('fp',$fp)->render();
                }   
                if($step == 4)
                {   
                    $arr    = $this->get_PPCOA_Count($fp_id);                   

                    $code   = 1;
                    $data   = View::make('pp.step3')->with('fp',$fp)
                                ->with('coas',$arr["coas"])
                                ->with('isMaxCount',$arr["isMaxCount"])->render();
                }  
                if($step == 5)
                {   
                    $code   = 1;
                    $data   = View::make('pp.step4')->with('fp',$fp)->render();    
                }                
            }
            
        } catch (Exception $e) {
            Log::error('PPController - 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 = "";
            
            $fp_id         = intval(Input::get('fp_id'));
            $pa_user_id    = intval(Input::get('pa_user_id')); 

            $paauthor = Authors::where('abs_id',$fp_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  = $fp_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_PPPA_Count($pa_user_id);
                
                if($count >= CustomClass::$PP_Count)
                {
                    $code = 0;
                    $msg  = AppMessage::$PP_PA_Count;
                }             
                else 
                {
                    $code = 1;
                    $pa_author->save();
                }
            }
            else
            {
                $code = 1;
            }
            
        } catch (Exception $e) {
            Log::error('PPController - storePA :'.$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 = "";
            
            $fp_id          = intval(Input::get('fp_id'));
            $coa_user_id    = intval(Input::get('coa_user_id')); 


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

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

            //use for validation
            $arr = $this->get_PPCOA_Count($fp_id,$coa_user_id);

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

            //use for get coi list
            $arr = $this->get_PPCOA_Count($fp_id);
            
            $data = View::make('pp.step3')
                                ->with('fp',$fp)
                                ->with('coas',$arr["coas"])
                                ->with('isMaxCount',$arr["isMaxCount"])->render();
            
        } catch (Exception $e) {
            Log::error('PPController - 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 GetMaxFPNoPlusOne()
    {
         $fpno = FP::max('fp_no');
         return (intval($fpno) + 1); 
    }

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

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

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

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

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

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

            // $code = 1;
            // $data = View::make('pp.step3')
            //                     ->with('fp',$fp)
            //                     ->with('coas',$arr["coas"])
            //                     ->with('isMaxCount',$arr["isMaxCount"])->render();
            
            
        } catch (Exception $e) {
            Log::error('PPController - 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   = "";

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

            $coa->delete();
            
            $fp = Abstracts::find($fp_id);         

            $arr = $this->get_PPCOA_Count($fp_id);

            $code = 1;
            $data = View::make('pp.step3')
                                ->with('fp',$fp)
                                ->with('coas',$arr["coas"])
                                ->with('isMaxCount',$arr["isMaxCount"])->render();
            
            
        } catch (Exception $e) {
            Log::error('PPController - 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_PPPA_Count($pa_uid)
    {           

        try {
                $isMaxCount     = false;

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

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


    //Get COA and COA Count for validation 
    public function get_PPCOA_Count($fp_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::$PP,CustomClass::$CoAuthor,$fp_id,null,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::$PP_COA_Count)
                {
                  $isMaxCount = true;
                }    
        } catch (Exception $e) {
            Log::error('PPController - get_PPCOA_Count :'.$e->getMessage());    
        }
                     

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

    }

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

        $ca  = App::make('UserController')->getUserDetails($fp->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::$PP,CustomClass::$PresentingAuthor,$fp->abs_id,null,null); 
            if(isset($pa[0]))
            {
                $pa =  $pa[0];
                if($pa->user_type_id==CustomClass::$Ratified_Member)
                {
                    $isretified = true;                     
                }            
            }


        $arr = $this->get_PPCOA_Count($fp->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 pp_mail($user,$pa,$fp,$coa,$categories)
    {
        if(CustomClass::$IsEmailEnabled)
        {
             $isMailSend  =  Mail::send('emails.pp.chiefauthor', array('user' => $user,'fp' =>$fp,'coa' =>$coa,'pa'=>$pa,'categories'=>$categories), function($message) use ($coa,$fp,$user,$pa)
                                {       
                                    $message->subject(sprintf(Subject::$pp_ca,$fp->abs_no)); 
                                    if(CustomClass::$IsEmailTest)
                                    {
                                        $message->to(CustomClass::$TestMailId);   
                                    }
                                    else
                                    {
                                        $message->to($user->email, $user->first_name);                                             
                                        if(isset($coa) && count($coa)>0)                        
                                        {
                                            foreach ($coa as $value) {
                                                $message->cc($value->email,$value->name);
                                            }    
                                        }                                    
                                        if(isset($pa) && !empty($pa))
                                        {
                                            $message->cc($pa->email,$pa->name);
                                        }
                                        $message->bcc(CustomClass::$BackupId);
                                    }
                                });  
        }
    }


    //FP Mail Send add cc COA
    public function pp_mail_data($user,$pa,$fp,$coa,$categories,$pres_types)
    {
        if(CustomClass::$IsEmailEnabled)
        {
             $isMailSend  =  Mail::send('emails.pp.chiefauthor_data', array('user' => $user,'fp' =>$fp,'pa'=>$pa,'coas' =>$coa,'categories' => $categories ,'pres_types' =>$pres_types), function($message) use ($coa,$fp,$user,$pa)
                                {   

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

                                });  
        }
    }



   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   = "PP";

            $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('PPController - getPAAwards :'.$e->getMessage());          
            $msg =AppMessage::$GENERAL_ERROR;
            $code=0;
        }

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

    }

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

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

                $result = DB::select("call usp_consent_judge_pp($category_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('PPController - ConsentJudge'.$e->getMessage());
                $msg =AppMessage::$GENERAL_ERROR;
            }
            return View::make("msg")->with('msg',$msg);    
    }

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



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


 public function uploadPP($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)){
                                        Log::info("is 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','=',2)
                                              ->where('selection_type_id',4)
                                             //->whereIn('selection_type_id',array(4))
                                             ->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)
                       {
                        Log::info("is abs");
                            return View::make("pp.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('PPController - uploadPP :'.$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 = 'PPUploads';
            $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)
            {             
                return Redirect::to("pp/upload". (isset($auto_login)? "/" . $auto_login:"")   ."?abs_id=".$abs_id)->with('msgSuccess','File Uploaded Sucessfully');             
            } 
        }

        } catch (Exception $e) {            
               Log::error('PPController - postUpload :'.$e->getMessage());          
              return Redirect::to("pp/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('PPController - 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('PPController - deleteUpload'.$e->getMessage());
            $msg =AppMessage::$GENERAL_ERROR;

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

         return Response::json($arr); 
    }

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


    
     /******************************* PPP Upload *******************************************/


 public function uploadPPP($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)){

                    //Log::info("is 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','=',2)
                                             // ->where('presentation_type_id',3)
                                             ->whereIn('selection_type_id',array(11))
                                             ->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)
                       {
                           // Log::info("is abs");
                            return View::make("fp.upload_ppp")->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('PPController - uploadPPP :'.$e->getMessage());          
            $msg =AppMessage::$GENERAL_ERROR;
            echo $e->getMessage(); 
            
            }
    }

     public function postUploadPPP() {

    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 = 'PPPUploads';
            $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)
            {             
                return Redirect::to("ppp/upload". (isset($auto_login)? "/" . $auto_login:"")   ."?abs_id=".$abs_id)->with('msgSuccess','File Uploaded Sucessfully');             
            } 
        }

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

        }

  }
  public function getUploadPPP(){
        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('PPController - getUploadPPP'.$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 deleteUploadPPP(){
        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('PPController - deleteUploadPPP'.$e->getMessage());
            $msg =AppMessage::$GENERAL_ERROR;

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

         return Response::json($arr); 
    }

    /******************************* end PPP Upload *******************************************/




}

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