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

<?php

class BOARCController extends BaseController {

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

    	$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);
            $arc        = $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() . 'arc.arc')
        			->with('arc',$arc)
                    ->with('pres_auth_id',$pres_auth_id)
        			->with('categories',$categories)
        			->with('ca',$ca)
        			->with('step',$step);
    }    


    //ARC 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::$ARC,CustomClass::$ChiefAuthor,null,null,null); 
            
           
            if(empty($data))
            {
                $data = "";
                $code = 0;
                $msg  = "record not found";
            }
            else
            {                
                $code = 1;
                $msg  = "";
            }


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

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

         return Response::json($arr); 
    }

    //ARC 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::$ARC,CustomClass::$PresentingAuthor,null,null,null); 
            
           
            if(empty($data))
            {
                $data = "";
                $code = 0;
                $msg  = "record not found";
            }
            else
            {                
                $code = 1;
                $msg  = "";
            }


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

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

         return Response::json($arr); 
    }

     //ARC 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::$ARC,CustomClass::$CoAuthor,null,null,null);             
           
            if(empty($data))
            {
                $data = "";
                $code = 0;
                $msg  = "record not found";
            }
            else
            {                
                $code = 1;
                $msg  = "";
            }


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

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

         return Response::json($arr); 
    }


    //ARC 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('BOARCController - getSearchMembersCA'.$e->getMessage());
            $msg =AppMessage::$GENERAL_ERROR;

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

         return Response::json($arr); 
    }


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

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

         return Response::json($arr); 
    }

    

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

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

            
            $abs_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::ARC();                    
            $membership = CustomClass::GetMembership();  

            $pres_auth_id = 0;
            $abs_upload = [];

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

             if($arc != null)
            {
               $result    = Abstracts::usp_get_abstracts(null,null,null,null,$abs_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)
                {                   
                    $arc->abs_type       = CustomClass::$ARC;                    
                    $arc->category_id    = Input::get('ddlSection');                                          
                    $arc->original_category_id   = Input::get('ddlSection');
                    $arc->user_id        = Input::get('hdnCAId');                       
                    $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 = Input::get('hdnCAId');
                        $author->abs_id  = $arc->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() . 'arc.step2')->with('arc',$arc)->render();;     
                    //}                
                }                 

                if($step ==2)
                {   
                        // $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_COA_Count($vt_id);                   

                    $code   = 1;
                    $data   = View::make($this->bo_path() . '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($this->bo_path() . '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)             
               {
                    $arc->is_in_india             = Input::get('rbtnIndia');  
                    $arc->is_already_published    = Input::get('rbtnIsAlreadyPublished');  
                    $arc->save();

                    $arr    = $this->get_COA_Count($abs_id);
                    $pa     = Abstracts::usp_get_authors(null,CustomClass::$ARC,CustomClass::$PresentingAuthor,$abs_id,null,null); 
                    if(isset($pa[0]))
                    {
                        $pa =  $pa[0];
                    }
                    $code   = 1;
                    $data   = View::make($this->bo_path() .'arc.step5')->with('arc',$arc)
                                ->with('coas',$arr["coas"])
                                ->with('pa',$pa)
                                ->with('categories',$categories)
                                ->with('ca',$ca)
                                ->with('isMaxCount',$arr["isMaxCount"])->render();                       
               }
               if($step == 5)
               {                   
                    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();

                    //ARC 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];
                    }

                    // $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() .'arc.success')->with('arc',$arc)->with('coas',$arr["coas"])->render();    
                    
               }
            }
            else 
            {
                if($step == 2)
                {   
                    $code = 1;
                    $data = View::make($this->bo_path() .'arc.step1')
                                ->with('arc',$arc)
                                ->with('abs_upload',$abs_upload)
                                ->with('pres_auth_id',$pres_auth_id)
                                ->with('categories',$categories)                                
                                ->with('ca',$ca)
                                ->with('membership',$membership)->render();
                }   
                if($step == 3)
                {   
                    $code = 1;
                    $data = View::make($this->bo_path() .'arc.step2')
                                ->with('arc',$arc)
                                ->with('abs_upload',$abs_upload)->render();
                }   
                if($step == 4)
                {   
                    // $arr    = $this->get_COA_Count($vt_id);                   

                    $code   = 1;
                    $data   = View::make($this->bo_path() .'arc.step3')->with('arc',$arc)
                    ->with('abs_upload',$abs_upload)->render();
                }                
                if($step == 5)
                {                       
                    $code   = 1;
                    $data   = View::make($this->bo_path() .'arc.step3')->with('arc',$arc)
                                    ->with('abs_upload',$abs_upload)->render();
                }   
            }
            
        } catch (Exception $e) {
            Log::error('BOARCController - 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 = "";
            
            $abs_id         = intval(Input::get('abs_id'));
            $ca_user_id    = intval(Input::get('ca_user_id')); 

            $caauthor = Authors::where('abs_id',$abs_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  = $abs_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('BOARCController - 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 = "";
            
            $abs_id         = intval(Input::get('abs_id'));
            $pa_user_id    = intval(Input::get('pa_user_id')); 

            $paauthor = Authors::where('abs_id',$abs_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  = $abs_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('BOARCController - 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 = "";
            
            $abs_id          = intval(Input::get('abs_id'));
            $coa_user_id    = intval(Input::get('coa_user_id')); 

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

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

            //use for validation
            $arr = $this->get_COA_Count($abs_id,$coa_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_COA_Count($abs_id);
            //var_dump($arr);
            
            $data = View::make($this->bo_path() .'arc.step3')
                                ->with('arc',$arc)
                                ->with('coas',$arr["coas"])
                                ->with('isMaxCount',$arr["isMaxCount"])->render();
            
        } catch (Exception $e) {
            Log::error('BOARCController - 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   = "";

            $abs_id = intval(Input::get('abs_id'));
            $ca_id = intval(Input::get('ca_id'));
            
            $ca =  Authors::where('abs_id',$abs_id)->where('user_id',$ca_id)->where('role_id',CustomClass::$ChiefAuthor)->first();
           
            $ca->delete();
            $code = 1;            
            
        } catch (Exception $e) {
            Log::error('BOARCController - 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   = "";

            $abs_id = intval(Input::get('abs_id'));
            $pa_id = intval(Input::get('pa_id'));
            
            $pa =  Authors::where('abs_id',$abs_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('BOARCController - 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   = "";

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

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

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

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

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



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

              
            $coas           = Abstracts::usp_get_authors(null,CustomClass::$ARC,CustomClass::$CoAuthor,$abs_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 arc
    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($arc->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_COA_Count($arc->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