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

<?php

class BOVTController extends BaseController {

    public function bo_path()
    {
        return "backoffice/abstracts/";
    }
    
    //VT get
    public function getVT($id = null){    	
    	$categories = array('' => '--select--') + Category::VT();    	

    	$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)
		{            
			$result    = Abstracts::usp_get_abstracts(null,null,null,null,$id,null,null,null,null,null,null,null);
            $vt        = $result['abstracts'][0];
            $authors   = $result['authors'];
            $ca = null;
            foreach ($authors as $key => $value) {
                if($value->role_id==CustomClass::$ChiefAuthor)
                {
                    $ca =$value;
                }
                if($value->role_id==CustomClass::$PresentingAuthor)
                {
                    $pres_auth_id =$value->user_id;
                }
            }
		}        

        return View::make($this->bo_path() . 'vt.vt')
        			->with('vt',$vt)
                    ->with('pres_auth_id',$pres_auth_id)
        			->with('categories',$categories)
        			->with('ca',$ca);
    }    


    //VT Search user for Chief Author
    public function getSearchMembersCA(){
        try {

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

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

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


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

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

         return Response::json($arr); 
    }

    //VT Search user for Presenting Author
    public function getSearchMembersPA(){
        try {

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

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

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


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

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

         return Response::json($arr); 
    }

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

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

            $search =  Helper::trimAndTruncate(Input::get('search'),250);
            $data   = Abstracts::usp_get_authors($search,CustomClass::$VT,CustomClass::$CoAuthor,null,null,null);             
           
            if(empty($data))
            {
                $data = "";
                $code = 0;
                $msg  = "record not found";
            }
            else
            {                
                $code = 1;
                $msg  = "";
            }


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

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

         return Response::json($arr); 
    }


    //VT Get Chief Author
    public function getCADetails(){
        try {

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

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

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


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

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

         return Response::json($arr); 
    }


    //VT 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('BOVTController - getSearchMembersPA'.$e->getMessage());
            $msg =AppMessage::$GENERAL_ERROR;

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

         return Response::json($arr); 
    }

    

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

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

            
            $vt_id      = intval(Input::get('hdnId'));
            $ca_id      = intval(Input::get('hdnCAId'));
            $pa_id      = intval(Input::get('hdnPAId'));
            $is_next    = intval(Input::get('hdnIsNext'));
            $step       = intval(Input::get("hdnStep"));

            $is_edit    = true;


            //for first step only 
            $categories = array('' => '--select--') + Category::VT();                    
            $membership = CustomClass::GetMembership();  

            $pres_auth_id = 0;


            if($vt_id >0)
                $vt = Abstracts::find($vt_id);         
            else
                $vt = new Abstracts(); 

             if($vt != null)
            {
               $result    = Abstracts::usp_get_abstracts(null,null,null,null,$vt_id,null,null,null,null,null,null,null);
                //$fp        = $result['abstracts'][0];
                $authors   = $result['authors'];
                    foreach ($authors as $key => $value) {
                        if($value->role_id==CustomClass::$ChiefAuthor)
                        {
                            $ca =$value;
                        }
                        if($value->role_id==CustomClass::$PresentingAuthor)
                        {
                            $pres_auth_id =$value->user_id;
                        }
                }   
            }

            if($is_next == 1)
            {
                if($step ==1)
                {                   
                    $vt->abs_type       = CustomClass::$VT;                    
                    $vt->category_id    = Input::get('ddlSection');                                          
                    $vt->original_category_id   = Input::get('ddlSection');
                    $vt->user_id        = Input::get('hdnCAId');                       
                    $vt->save();

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

                    // $count = $this->get_VTPA_Count($pres_auth_id);

                    // if($count >= CustomClass::$VT_Count)
                    // {
                    //     $code   = 0;
                    //     $msg    = AppMessage::$VT_PA_Count;    
                    //     $data   = "";
                    // }
                    // else
                    // {
                        $code = 1;
                        $data = View::make($this->bo_path() . 'vt.step2')->with('vt',$vt)->render();;     
                    //}                
                }                 

                if($step ==2)
                {   
                    $vt->title      = Helper::trimAndTruncate(Input::get('txtTitle'),200);  
                    $vt->synopsis   = Helper::trimAndTruncate(Input::get('txtSynopsis'),3000);                                       
                    $vt->save();

                    $arr    = $this->get_COA_Count($vt_id);                   

                    $code   = 1;
                    $data   = View::make($this->bo_path() . 'vt.step3')->with('vt',$vt)
                                ->with('coas',$arr["coas"])
                                ->with('isMaxCount',$arr["isMaxCount"])->render();                    
                }      
                if($step ==3)
                {   
                    if($this->IsRatifiedMembers($vt))
                    {                        
                        $code   = 1;
                        $data   = View::make($this->bo_path() .'vt.step4')->with('vt',$vt)->render();     
                    }
                    else
                    {
                        $code   = 0;
                        $msg    = AppMessage::$VT_RATIFIED_MEMBER;    
                        $data   = "";
                    }                    
               }   
               if($step == 4)             
               {
                    $vt->is_in_india             = Input::get('rbtnIndia');  
                    $vt->is_already_published    = Input::get('rbtnIsAlreadyPublished');  
                    $vt->save();

                    $arr    = $this->get_COA_Count($vt_id);
                    $pa     = Abstracts::usp_get_authors(null,CustomClass::$VT,CustomClass::$PresentingAuthor,$vt_id,null,null); 
                    if(isset($pa[0]))
                    {
                        $pa =  $pa[0];
                    }
                    $code   = 1;
                    $data   = View::make($this->bo_path() .'vt.step5')->with('vt',$vt)
                                ->with('coas',$arr["coas"])
                                ->with('pa',$pa)
                                ->with('categories',$categories)
                                ->with('ca',$ca)
                                ->with('isMaxCount',$arr["isMaxCount"])->render();                       
               }
               if($step == 5)
               {                   
                    if(!($vt->abs_no>0))
                    {
                        $is_edit           = false;                              
                        $vt->submitted_at  = date('Y-m-d H:i:s');
                        $vt->status_id     = CustomClass::$Submitted;                        
                        $result            = Abstracts::usp_generate_abs_no(CustomClass::$VT,$vt->abs_id);
                        $vt->abs_no        = $result[0]->abs_no;
                    }
                    
                    $vt->save();

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

                    $arr = $this->get_COA_Count($vt_id);

                    // if($is_edit)
                    // {
                    //     $this->vt_mail_data($user,$pa,$vt,$arr['coas'],$categories);    
                    // }
                    // else
                    // {
                    //     $this->vt_mail($user,$pa,$vt,$arr['coas'],$categories);    
                    // }
                    
                    $code = 1;
                    $data = View::make($this->bo_path() .'vt.success')->with('vt',$vt)->with('coas',$arr["coas"])->render();    
                    
               }
            }
            else 
            {
                if($step == 2)
                {   
                    $code = 1;
                    $data = View::make($this->bo_path() .'vt.step1')
                                ->with('vt',$vt)
                                ->with('pres_auth_id',$pres_auth_id)
                                ->with('categories',$categories)                                
                                ->with('ca',$ca)->render();
                }   
                if($step == 3)
                {   
                    $code = 1;
                    $data = View::make($this->bo_path() .'vt.step2')
                                ->with('vt',$vt)->render();
                }   
                if($step == 4)
                {   
                    $arr    = $this->get_COA_Count($vt_id);                   

                    $code   = 1;
                    $data   = View::make($this->bo_path() .'vt.step3')->with('vt',$vt)
                                ->with('coas',$arr["coas"])
                                ->with('isMaxCount',$arr["isMaxCount"])->render();
                }                
                if($step == 5)
                {                       
                    $code   = 1;
                    $data   = View::make($this->bo_path() .'vt.step4')->with('vt',$vt)->render();
                }   
            }
            
        } catch (Exception $e) {
            Log::error('BOVTController - store :'.$e->getMessage());          
            $msg =AppMessage::$GENERAL_ERROR;
        }

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

    //CA Store
    public function storeCA()
    {
        try {

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

            $caauthor = Authors::where('abs_id',$vt_id)->where('role_id',CustomClass::$ChiefAuthor)->first();
            if($caauthor == null)
            {
                //chief author            
                $ca_author = new Authors();
                $ca_author->user_id = $ca_user_id;   
                $ca_author->abs_id  = $vt_id;
                $ca_author->role_id = CustomClass::$ChiefAuthor;
                $ca_author->consent_status_id = CustomClass::$Selected;                
                $code = 1;
                $ca_author->save();
            }
            else
            {
                $code = 1;
            }
            
        } catch (Exception $e) {
            Log::error('BOVTController - storeCA :' .$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 = "";
            
            $vt_id         = intval(Input::get('vt_id'));
            $pa_user_id    = intval(Input::get('pa_user_id')); 

            $paauthor = Authors::where('abs_id',$vt_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  = $vt_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_VTPA_Count($pa_user_id);
                
                // if($count >= CustomClass::$VT_Count)
                // {
                //     $code = 0;
                //     $msg  = AppMessage::$VT_PA_Count;
                // }             
                // else 
                // {
                    $code = 1;
                    $pa_author->save();
                //}
            }
            else
            {
                $code = 1;
            }

          
            
        } catch (Exception $e) {
            Log::error('BOVTController - 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 = "";
            
            $vt_id          = intval(Input::get('vt_id'));
            $coa_user_id    = intval(Input::get('coa_user_id')); 

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

            $vt = Abstracts::find($vt_id);   

            //use for validation
            $arr = $this->get_COA_Count($vt_id,$coa_user_id);

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

            //use for get coi list
            $arr = $this->get_COA_Count($vt_id);
            //var_dump($arr);
            
            $data = View::make($this->bo_path() .'vt.step3')
                                ->with('vt',$vt)
                                ->with('coas',$arr["coas"])
                                ->with('isMaxCount',$arr["isMaxCount"])->render();
            
        } catch (Exception $e) {
            Log::error('BOVTController - storeCOA :'.$e->getMessage());          
            $msg =AppMessage::$GENERAL_ERROR;
        }

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


    //CA Remove
    public function removeCA()
    {
        try {

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

            $vt_id = intval(Input::get('vt_id'));
            $ca_id = intval(Input::get('ca_id'));
            
            $ca =  Authors::where('abs_id',$vt_id)->where('user_id',$ca_id)->where('role_id',CustomClass::$ChiefAuthor)->first();
           
            $ca->delete();
            $code = 1;            
            
        } catch (Exception $e) {
            Log::error('BOVTController - removeCA :'.$e->getMessage());          
            $msg =AppMessage::$GENERAL_ERROR;            
        }

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

    }



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

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

            $vt_id = intval(Input::get('vt_id'));
            $pa_id = intval(Input::get('pa_id'));
            
            $pa =  Authors::where('abs_id',$vt_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($vt_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('BOVTController - removePA :'.$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   = "";

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

            $coa->delete();
            
            $vt = Abstracts::find($vt_id);         

            $arr = $this->get_COA_Count($vt_id);

            $code = 1;
            $data = View::make($this->bo_path() .'vt.step3')
                                ->with('vt',$vt)
                                ->with('coas',$arr["coas"])
                                ->with('isMaxCount',$arr["isMaxCount"])->render();
            
            
        } catch (Exception $e) {
            Log::error('BOVTController - 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_VTPA_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::$VT && $value->role_id==CustomClass::$PresentingAuthor && $value->status_id == CustomClass::$Submitted)
                    {
                        $pa_count++;
                    }
                }

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



    //Get COA and COA Count for validation 
    public function get_COA_Count($vt_id,$coa_uid = null)
    {           
            $isMaxCount     = false;
            $isDuplicate    = false; 

              
            $coas           = Abstracts::usp_get_authors(null,CustomClass::$VT,CustomClass::$CoAuthor,$vt_id,null,null);               

            $coa_uids       = [];                

            foreach ($coas as $key => $value) {  
                    if($coa_uid == $value->user_id)              
                    {
                        $isDuplicate =true;
                    }
                    
                    array_push($coa_uids, $value->user_id);    
            }


            if(count(array_unique($coa_uids)) >=  CustomClass::$VT_COA_Count)
            {
              $isMaxCount = true;
            }             

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

    }

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

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

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


        // $pa  = App::make('UserController')->getUserDetails($vt->pres_auth_id); 
        // if(!empty($pa->membership_no))
        // {
        //     $isretified = true; 
        // }            
            $pa         = Abstracts::usp_get_authors(null,CustomClass::$VT,CustomClass::$PresentingAuthor,$vt->abs_id,null,null); 
            if(isset($pa[0]))
            {
                $pa =  $pa[0];
                 if($pa->user_type_id==CustomClass::$Ratified_Member)
                {
                    $isretified = true; 
                }            
            }


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

        return $isretified;

    }

}

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