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

<?php

class FTController 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 getFT($id = null){ 
        
        $step = Input::get('step');
        $categories = array('' => '--select--') + Category::FP();       

        $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($this->is_profile_req())
        {
            return View::make('ft.info');
        }
                
        
        if($id>0)
        {
            $abs = Abstracts::find($id);
            
            if($abs != null)
            {
                if($abs->user_id != CustomClass::getUserId())
                {
                     return Redirect::to('dashboard');
                }
                else if($abs->status_id ==CustomClass::$Submitted)
                {
                   return Redirect::to('dashboard');
                } 

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

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

                 //dump creat table after step new fp
                $abs = new Abstracts();
                $abs->user_id    = CustomClass::getUserId();  
                $abs->abs_type   = CustomClass::$FT;      
                $abs->save();
                return Redirect::to('ft/'.urlencode(Helper::encrypt($abs->abs_id)));
            }
        }

        return View::make('ft.ft')
                    ->with('abs',$abs) 
                    ->with('pres_auth_id',$pres_auth_id)                   
                    ->with('categories',$categories)
                    ->with('membership',$membership)
                    ->with('step',$step);
    }
    
    
    // 30 days once update profile for faculty talks abstracts 
    public function is_profile_req()
    {
        $user = User::find(CustomClass::getUserId());
        $current_dt = date('Y-m-d H:i:s');
        // $profile_updated_on = date('Y-m-d H:i:s', strtotime());
        
        $update_30days = date('Y-m-d H:i:s', strtotime('+30 day',strtotime($user->profile_updated_on)));
        //if user profile updated before 30 day true then redirect to profile pdate 
        if($update_30days < $current_dt)
        {
            return true;
        }  
        else
        {
            return false;
        } 
    }
    
    

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

    //FP view
    public function view($id){      
        $categories = array('' => '--select--') + Category::lists('name','Category_id');        
        
        if($id != null )
            $id = intval(urldecode(Helper::decrypt($id)));

        $abs = null;

        if($id>0)
        {
            $abs         = Abstracts::find($id);
            

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

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

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

  
    

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

            //for Response
            $arr = [];
            $code = 0;
            $msg = "";
            $data = "";
            
            $abs_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();        
            $membership = CustomClass::GetMembership();  

            $is_edit = true;

            $pres_auth_id = 0;

            $abs_upload = [];

            if($abs_id >0)
            {
                $abs = Abstracts::find($abs_id); 
            }    
            else
                $abs = new Abstracts(); 

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

                    }
                    else
                    {

                        $abs->abs_type               = CustomClass::$FT;
                        $abs->category_id            = Input::get('ddlSection');                    
                        $abs->original_category_id   = Input::get('ddlSection');
                        $abs->user_id                = CustomClass::getUserId();                                                               
                        $abs->save();

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

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

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

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

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

                    }
                    else
                    {
                        $abs->user_id              = CustomClass::getUserId();
                        $abs->submitted_on         = date('Y-m-d H:i:s');
                        $abs->title                = Helper::trimAndTruncate(Input::get('txtTitle'),200);  
                        $abs->resume               = Helper::trimAndTruncate(Input::get('txtResume'),1200);                                       
                        $abs->save();
                        
                        $code   = 1;
                                    
                        $code   = 1;
                        $data   = View::make('ft.step5')->with('abs',$abs)
                                        ->with('categories',$categories)
                                        ->with('membership',$membership)->render();    
                    }
                }      
                if($step ==3)
                {   
                    if($abs->status_id ==CustomClass::$Submitted)
                    {
                        $code   = 0;
                        $msg    = AppMessage::$FT_ALREADY_SUBMIT ." <a href=". url('/dashboard'). " >Please, check the status in Dashboard</a>";    
                        $data   = "";

                    }
                    else
                    {

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

               }     
               if($step == 5)
               {

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

                    }
                    else
                    {

                        
                        if(!($abs->abs_no >0))
                        {
                            $is_edit            = false;                        
                            $abs->submitted_at  = date('Y-m-d H:i:s');
                            $abs->status_id     = CustomClass::$Submitted;                        
                            $abs->MidYear     = 1;  //default value is 1 for mid-year   
                            $result =    Abstracts::usp_generate_abs_no(CustomClass::$FT,$abs->abs_id);
                            $abs->abs_no = $result[0]->abs_no;
                        }
                        
                        $abs->save();

                       

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

                        

                         if($is_edit)
                        {
                            $this->ft_mail_data($user,$abs,$categories);       
                        }
                        else
                        {
                            $this->ft_mail($user,$abs,$categories);
                        }

                        $code = 1;
                        $data = View::make('ft.success')->with('abs',$abs)->render();
                        
                   }
                }
            }
            else 
            {
                if($step == 2)
                {   
                    $code = 1;
                    $data = View::make('ft.step1')
                                ->with('abs',$abs)
                                ->with('pres_auth_id',$pres_auth_id)
                                ->with('categories',$categories)
                                ->with('membership',$membership)->render();
                }   
                if($step == 3)
                {   
                    $code = 1;
                    $data = View::make('ft.step2')
                                ->with('abs',$abs)->render();
                }   
                if($step == 4)
                {   
                    $code   = 1;
                    $data   = View::make('ft.step3')->with('abs',$abs)
                                ->render();
                }  
                if($step == 5)
                {   
                    $code   = 1;
                    $data   = View::make('ft.step3')->with('abs',$abs)
                                                     ->render();    
                }                
            }
            
        } catch (Exception $e) {
            Log::error('FTController - store :'.$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_FTPA_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::$FT && $value->role_id==CustomClass::$PresentingAuthor && $value->status_id == CustomClass::$Submitted)
                    {
                        $pa_count++;
                    }
                }

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

    

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

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


        return $isretified;

    }


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

                                        $message->to($user->email);                                             
                                        $message->cc(CustomClass::$BackupId);
                                    }
                                });  
        }
    }


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

                                    $message->subject(sprintf(Subject::$ft_ca,$abs->abs_no)); 
                                    if(CustomClass::$IsEmailTest)
                                    {
                                        $message->to(CustomClass::$TestMailId);   
                                    }                          
                                    else
                                    {
                                        $message->to($user->email);                                                                             
                                        $message->cc(CustomClass::$BackupId);
                                    }                                
                                    

                                });  
        }
    }



  




}


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