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

<?php

class UserController extends BaseController {

    //public $viewPrefix = 'auth/';

    //http://stackoverflow.com/questions/26666375/login-trouble-in-laravel-4-2
    //http://stackoverflow.com/questions/23134702/laravel-4-2-and-remember-me-update

    //login get
    public function getLogin(){
         $type = "";
         if(Input::has("type"))
          $type=Input::get("type");

        
        if(Auth::check())
	{
          return Redirect::to("dashboard");    
	}
        else
	{
//	echo 'login...';
        return View::make('auth.devlogin')->with('type',$type)->render();
	}


    }

    //login post
    public function postLogin(){
        try {
            //var_dump("login...");
            //exit();
            
            $type  = Input::get('type');
            $email = Input::get('email');
            $password = Input::get('password');

            $rules = array('email' => 'required', 'password' => 'required');
            $validator = Validator::make(array('email'=>$email, 'password'=>$password), $rules);

            if($validator->fails()){
               return Redirect::to('login')->with('msg_err','Please enter User name and Password');
            }

            if($type=="bo")  
            {
                $user = User::where('email',$email)->where('bo_login',$password)->first();
                if(empty($user))
                {
                  return Redirect::to('login?type=bo')->with('msg_err', 'Invalid credentials.');
                }
                else
                {
                   Auth::login($user);
                   return Redirect::to('/');
                }
       
            }
            else
            {
              if (Auth::attempt(array('email' => $email, 'password' => $password)))
                {

                    $um = UsersMembership::where('user_id',Auth::user()->user_id)->where('society_id',CustomClass::$AIOSSocietyId)->first(); 
                    if(!empty($um))
                    {
                        $um->last_login_at= date('Y-m-d H:i:s');
                        $um->save();
                    }
                    return Redirect::to('/');
                }
                else
                {
                    //Log::info("Invalid credentials");
                    return Redirect::to('login')->withInput()->with('msg_err','Invalid credentials.');
                }
             } 

        } catch (Exception $e) {
            Log::error('UserController - postLogin'.$e->getMessage());
            return Redirect::to('login')->withInput()->with('msg_err','error occurred. please try after some time');
        }
    }

    //sridhar auto login 
    public function Autologin($auto_login_id)
    {
        try 
        {
            
            $user = User::where('uuid',$auto_login_id)->first();            
            
            if($user != null)
            {
                Auth::login($user);
               if(Auth::check())
                {
                     $um = UsersMembership::where('user_id',Auth::user()->user_id)->where('society_id',CustomClass::$AIOSSocietyId)->first(); 
                    if(!empty($um))
                    {
                        $um->last_login_at= date('Y-m-d H:i:s');
                        $um->save();
                    }
                    
                    if(Input::has('redirect'))
                    {
                        return Redirect::to(Input::get('redirect'));
                    }
                    
                    
                    return Redirect::to('/');
                    
                    // return Redirect::to("dashboard");
                                 
                }
            }
            else
            {   
                return Redirect::to('/login');                
              
            }
        } catch (Exception $e) {
            Log::error("AuthController=>Autologin".$e->getMessage());
        }
    }

    public function logout()
    {
        Session::forget('Membership');
        Auth::logout();
        return Redirect::to('login');
    }


    //register get
    public function getRegister(){

                $countries      = Country::GetCountries();                         
                $years          = CustomClass::GetProfileYears() ;
                $FPCategories   = Category::FP();                
                $VTCategories   = Category::VT(); 

        return View::make('auth.register')->with('countries',$countries)
                                          ->with('FPCategories',$FPCategories)
                                        ->with('VTCategories',$VTCategories)
                                        ->with('years',$years);;
    }

//     //register post
//     public function postRegister(){
//         try {

//             $operationStatus = false;
           
            
//              $user  = new User();

//              $user->prefix      =  Helper::trimAndTruncate(Input::get('ddlPrefix'),10);
//              $user->first_name        =  Helper::trimAndTruncate(Input::get('txtName'),250);
//              $user->sur_name    =  Helper::trimAndTruncate(Input::get('txtLastName'),250);
//              $user->dob         =  Helper::toDBDate(Helper::trimAndTruncate(Input::get('txtDOB')));
//              $user->address1    =  Helper::trimAndTruncate(Input::get('txtAdd1'),250);
//              $user->address2    =  Helper::trimAndTruncate(Input::get('txtAdd2'),250);
//              $user->address3    =  Helper::trimAndTruncate(Input::get('txtAdd3'),250);
//              $user->city        =  Helper::trimAndTruncate(Input::get('txtCity'),250);
//              $user->state_id    =  Input::get('ddlState');
//              $user->pincode     =  Helper::trimAndTruncate(Input::get('txtPincode'),250);
//              $user->country_id  =  Input::get('ddlCountry');
//              $user->mobile_isd_code    =  Helper::trimAndTruncate(Input::get('txtISDcode'),5);
//              $user->mobile      =  Helper::trimAndTruncate(Input::get('txtMobile'),15);
//              $user->email       =  Helper::trimAndTruncate(Input::get('txtEmail'),250);
//              $user->password    =  Helper::trimAndTruncate(Input::get('password'),20);            
//              $user->phone_home  =  Helper::trimAndTruncate(Input::get('txtPhHome'),100);
//              $user->phone_office=  Helper::trimAndTruncate(Input::get('txtPhoffice'),100);


// //                var_dump($user->prefix);
// //                var_dump($user->first_name);
// //                var_dump($user->address1);
// //                var_dump($user->city);
// //                var_dump($user->state_id);
// //                var_dump($user->pincode);
// //                var_dump($user->mobile_isd_code);
// //                var_dump($user->mobile);
// //                var_dump($user->email);
// //                var_dump($user->password);

// // exit();




             
//             $validator = $this->validatorRegister($user);
//             if(isset($validator) && !$validator->fails())
//             {
//                 //Validation success
//                 $user->old_pwd   =  $user->password;
//                 $user->password  =  Hash::make($user->password);
//                 $user->verified_at = date('Y-m-d H:i:s');
                
//                 if($user->save())
//                 { 
//                         $um = UsersMembership::where('user_id',$user->user_id)->where('society_id',CustomClass::$AIOSSocietyId)->first();
                        
//                         if(!isset($um))
//                         {
//                             $um =new UsersMembership();
//                         }

//                         $um->society_id     = CustomClass::$AIOSSocietyId;
//                         $um->user_id        = $user->user_id;
//                         $um->user_status    = 1; 
//                         $um->save();


//                     $operationStatus = true;
//                 }

//             }else
//             {
//                 //Validation fails
//                 $temp='';
//                 $requiredCount = 0;
//                 $messages = $validator->messages();
//                 foreach ($messages->all() as $message)
//                 {
//                     if(preg_match('[required]', $message))
//                     {
//                         if($requiredCount == 0)
//                         {
//                           $temp = $temp .''. $message .'<br />';
//                           $requiredCount++;
//                         }
//                     }
//                     else
//                     {
//                         $temp =$temp .''. $message .'<br />';
//                     }
//                 }
//             }

//             if($operationStatus)
//             {

//                 $assets = [];

//                 //Create directory for the users to hold their documents/attachments 
//                 $directoryPath = public_path().'/uploads/'.$user->user_id ;
//                 if(!File::exists($directoryPath))
//                     File::makeDirectory($directoryPath, 0777, true);


//                 //Attachment profile picture
//                 $file = Input::file('fileProfile');
//                 if(isset($file) && $file->isValid())
//                 {
//                     $extension =  $file->getClientOriginalExtension();
//                     $fileName  =  CustomClass::$ASSET_USAGE_MEMBER_PROFILE_FILENAME;
//                     $fileNameWithExtension = $fileName.'.'.$extension;
//                     $destinationPath = $directoryPath."/".$fileNameWithExtension ;
//                     $path = 'uploads/'.$user->user_id."/".$fileNameWithExtension ;
//                     $file->move($directoryPath, $fileNameWithExtension);
//                     array_push($assets,array("user_id" => $user->user_id, "file_name" => $fileName, "extension" => $extension, "path" => $path, "created_at" => new DateTime(),"updated_at" =>  new DateTime() ));
//                 }  

//                 if(isset($assets) && count($assets) > 0)
//                     $operationStatus = Asset::insert($assets); 

//                 if(CustomClass::$IsEmailEnabled)
//                 {
//                     // $isMailSend  =  Mail::send('emails.auth.register', array('user' => $user), function($message) use ($user)
//                     //             {                             
//                     //                 $message->to($user->email, $user->first_name);                                             
//                     //                 $message->subject('aios-scientificcommittee.org login details');
//                     //             });  
//                 }

//                return Redirect::to('register')->with('msgSuccess',AppMessage::$REGISTER_SUCCESS);            }
//             else
//             {
//                 return Redirect::to('register')->withInput()->with('msgError',$temp);
//             }

//         } catch (Exception $e) {
//             Log::error('UserController - postRegister :'.$e->getMessage());
//             return Redirect::to('register')->withInput()->with('msgError',AppMessage::$GENERAL_ERROR);
//         }

//     }


    //Sridhar  On 22 Mar 2017 10:23 AM
    //Post Register form
    public function postRegister(){
        // try {

             $operationStatus = false;              

             $user  = new User();             
             //$user_id = $user->user_id;
             $user->prefix      =  Helper::trimAndTruncate(Input::get('ddlPrefix'),10);             
             $user->password    =  Helper::trimAndTruncate(Input::get('password'),20);                  
             $user->first_name        =  Helper::trimAndTruncate(Input::get('txtName'),250);
             $user->gender      =  Helper::trimAndTruncate(Input::get('ddlGender'),250);
             $user->dob         =  Helper::toDBDate(Helper::trimAndTruncate(Input::get('txtDOB')));
             $user->address1    =  Helper::trimAndTruncate(Input::get('txtAdd1'),250);
             $user->address2    =  Helper::trimAndTruncate(Input::get('txtAdd2'),250);
             $user->address3    =  Helper::trimAndTruncate(Input::get('txtAdd3'),250);
             $user->city        =  Helper::trimAndTruncate(Input::get('txtCity'),250);
             $user->state_id    =  Helper::trimAndTruncate(Input::get('ddlState'),250);
             $user->pincode     =  Helper::trimAndTruncate(Input::get('txtPincode'),250);
             $user->country_id  =  Helper::trimAndTruncate(Input::get('ddlCountry'),250);
             $user->mobile_isd_code  =  Helper::trimAndTruncate(Input::get('txtISDcode'),5);
             $user->mobile      =  Helper::trimAndTruncate(Input::get('txtMobile'),15);
             $user->email       =  Helper::trimAndTruncate(Input::get('txtEmail'),250);             
             $user->phone_home  =  Helper::trimAndTruncate(Input::get('txtPhHome'),100);
             $user->phone_office=  Helper::trimAndTruncate(Input::get('txtPhoffice'),100);

             

             $profile2 =new UsersProfile();
             $profile2->pg_degree_on        = Helper::setIntOrNUll(Input::get('ddlDegree'));
             $profile2->pg_diploma_on       = Helper::setIntOrNUll(Input::get('ddlDiploma'));
             $profile2->pg_dnb_on           = Helper::setIntOrNUll(Input::get('ddlDNB'));
             $profile2->pg_other            = Helper::trimAndTruncate(Input::get('txtPGOther'),100);
             $profile2->pg_other_on         = Helper::setIntOrNUll(Input::get('ddlPGOtherYear'));

             $profile2->any_fellowship      = Helper::setIntOrNUll(Input::get('rbtnFellowship'));
             $profile2->fellowship_speciality           = null;
             $profile2->fellowship_training_place       = null;
             $profile2->fellowship_training_duration    = null;             
             if($profile2->any_fellowship == 1)
             {
                 $profile2->fellowship_speciality           =  Input::has("ddlFellowshipCat")?implode(',', Input::get("ddlFellowshipCat")):'';
                 $profile2->fellowship_training_place       = Input::get("txtTrainingPlace");
                 $profile2->fellowship_training_duration    = Helper::trimAndTruncate(Input::get("txtTrainingDuration"),500);
             }
             
             $profile2->currentlyinto_type  = Input::get("rbtnCurrentlyInto");             
             
             $profile2->any_tec_experience  = Input::get("rbtnAnyTecExperience");




             $profile2->teaching_years      = null;
             if($profile2->any_tec_experience==1)
             {
                $profile2->teaching_years      = Helper::trimAndTruncate(Input::get("txtPGTeachingYear"),500);
             }

             $profile2->private_practice    = null;
             $profile2->pp_working_since    = null;
             $profile2->medical_college     = null;
             $profile2->mc_working_since    = null;
             $profile2->mc_working_as       = null;
             $profile2->government_job      = null;
             $profile2->gov_job_working_since       = null;
             $profile2->non_gov_job                 = null;
             $profile2->Non_gov_job_working_since   = null;
             if($profile2->currentlyinto_type==CustomClass::$Profile_PP)
             {
                $profile2->private_practice    = Input::has("ddlPrivatePractice")?implode(',', Input::get("ddlPrivatePractice")):'';
                $profile2->pp_working_since    = Helper::setIntOrNUll(Input::get("ddlPPWorkingSince"));   
             }
             else if($profile2->currentlyinto_type==CustomClass::$Profile_MC)
             {
                $profile2->medical_college     = Helper::trimAndTruncate(Input::get("txttMCNameofCollage"),500);
                $profile2->mc_working_since    = Helper::setIntOrNUll(Input::get("ddlMCWorkingSince"));
                $profile2->mc_working_as       = Helper::trimAndTruncate(Input::get("txtMCWorkingas"),500);
             }
             else if($profile2->currentlyinto_type==CustomClass::$Profile_GJ)
             {
                $profile2->government_job      = Helper::trimAndTruncate(Input::get("txtGJNameofPlace"),500);
                $profile2->gov_job_working_since       = Helper::setIntOrNUll(Input::get("ddlGJWorkingSince"));   
             }
             else if($profile2->currentlyinto_type==CustomClass::$Profile_NGJ)
             {
                $profile2->non_gov_job                 = Input::get("txtNGJNameofPlace");
                $profile2->Non_gov_job_working_since   = Helper::setIntOrNUll(Input::get("ddlNGJWorkingSince"));
             }
             
             
             $profile2->specilization               = Input::has("ddlSpecilization")?implode(',', Input::get("ddlSpecilization")):'';

             $profile2->participate_Judge           = Helper::setIntOrNUll(Input::get("rbtnParticipateJudge"));             
             $profile2->participate_evaluation      = Helper::setIntOrNUll(Input::get("rbtnParticipateEvaluation"));
             
             $profile2->participate_sections  = null;
             if($profile2->participate_Judge ==1 || $profile2->participate_evaluation ==1)
             {
                    $profile2->participate_sections           = Input::has("chkParticipate")?implode(',', Input::get("chkParticipate")):'';
             }             

             $profile2->any_remarks  = Helper::trimAndTruncate(Input::get("txtAnyRemarks"));

             
            $validator = $this->validatorUserUpdate($user,$profile2);
            if(isset($validator) && !$validator->fails())
            {
                
                
                $user->old_pwd   =  $user->password;
                $user->password  =  Hash::make($user->password);                    
                $user->verified_at = date('Y-m-d H:i:s');
                $user->profile_updated_on = date('Y-m-d H:i:s');

                if($user->save())
                { 
                    $profile2->user_id             = $user->user_id;
                    $profile2->save();

                    $um = new UsersMembership();                    
                    $um->society_id     = CustomClass::$AIOSSocietyId;
                    $um->user_id        = $user->user_id;
                    $um->user_status    = 1; 
                    $um->user_type_id   = 2; 
                    $um->save();
                    
                    $operationStatus = true;
                }

            }else
            {
                //Validation fails
                $temp='';
                $requiredCount = 0;
                $messages = $validator->messages();
                foreach ($messages->all() as $message)
                {
                    if(preg_match('[required]', $message))
                    {
                        if($requiredCount == 0)
                        {
                          $temp = $temp .''. $message .'<br />';
                          $requiredCount++;
                        }
                    }
                    else if(preg_match('[Year of Completion of Post Graduation]', $message))
                    {
                        if($requiredCount == 0)
                        {
                          $temp = $temp .''. $message .'<br />';
                          $requiredCount++;
                        }
                    }
                    else
                    {
                        $temp =$temp .''. $message .'<br />';
                    }
                }
            }

            if($operationStatus)
            {
                if(CustomClass::$IsEmailEnabled)
                {
                    $isMailSend  =  Mail::send('emails.auth.register', array('user' => $user), function($message) use ($user)
                                {                             
                                    $message->to($user->email, $user->first_name);                                             
                                    $message->subject('aios-scientificcommittee.org login details');
                                });  
                }

               return Redirect::to('register')->with('msgSuccess',AppMessage::$REGISTER_SUCCESS);  
            }
            else
            {
                return Redirect::to('register')->withInput()->with('msgError',$temp);
            }

        // } catch (Exception $e) {
        //     Log::error('UserController - postRegister :'.$e->getMessage());
        //     return Redirect::to('register')->withInput()->with('msgError',AppMessage::$GENERAL_ERROR);
        // }

    }


    public function validatorRegister($user,$profile)
    {
        try
        {

            $inputs = array(
                           'prefix'         => $user->prefix,
                           'name'           => $user->first_name,
                           'password'       => $user->password,
                           'new_confirm_password' => Input::get("password_confirmation"),
                           'address1'       => $user->address1,
                           'city'           => $user->city,
                           'state'          => $user->state_id,
                           'pincode'        => $user->pincode,
                           'mobile_isd_code'=> $user->mobile_isd_code,
                           'mobile'         => $user->mobile,
                           'email'          => $user->email,                           
                           'pg_degree_on'   => $profile->pg_degree_on,
                           'pg_diploma_on'  => $profile->pg_diploma_on,
                           'pg_dnb_on'      => $profile->pg_dnb_on,
                           'pg_other'       => $profile->pg_other,
                           'pg_other_on'    => $profile->pg_other_on,
                           'any_fellowship' => $profile->any_fellowship,
                           'fellowship_speciality' => $profile->fellowship_speciality,
                           'fellowship_training_place' => $profile->fellowship_training_place,
                           'fellowship_training_duration' => $profile->fellowship_training_duration,
                           'teaching_years' => $profile->teaching_years,
                           'currentlyinto_type' => $profile->currentlyinto_type,
                           'private_practice' => $profile->private_practice,
                           'pp_working_since' => $profile->pp_working_since,
                           'medical_college' => $profile->medical_college,
                           'mc_working_since' => $profile->mc_working_since,
                           'mc_working_as' => $profile->mc_working_as,
                           'government_job' => $profile->government_job,
                           'gov_job_working_since' => $profile->gov_job_working_since,
                           'non_gov_job' => $profile->non_gov_job,
                           'Non_gov_job_working_since' => $profile->Non_gov_job_working_since,
                           'specilization' => $profile->specilization,
                           'participate_Judge' => $profile->participate_Judge,
                           'participate_evaluation' => $profile->participate_evaluation,
                           'any_tec_experience' => $profile->any_tec_experience,
                           'participate_sections' => $profile->participate_sections,                           
                           );

            $rules  = array(    
                           'prefix'         => 'required',                   
                           'name'           => 'required',                                                   
                           'address1'       => 'required',                           
                           'city'           => 'required',
                           'state'          => 'required',
                           'pincode'        => 'required',
                           'mobile_isd_code'=> 'required',
                           'mobile'         => 'required',
                           /*'email'          => 'required|email|unique:users',  */
                           'email'          => 'required',
                           'pg_degree_on'   => 'required_without_all:pg_diploma_on,pg_dnb_on,pg_other,pg_other_on',
                           'pg_diploma_on'  => 'required_without_all:pg_degree_on,pg_dnb_on,pg_other,pg_other_on',
                           'pg_dnb_on'      => 'required_without_all:pg_degree_on,pg_diploma_on,pg_other,pg_other_on',
                           'pg_other'       => 'required_without_all:pg_degree_on,pg_diploma_on,pg_dnb_on,pg_other_on',
                           'pg_other_on'    => 'required_without_all:pg_degree_on,pg_diploma_on,pg_dnb_on,pg_other',
                           'any_fellowship' =>  'required',
                           'any_tec_experience' =>  'required',
                           'currentlyinto_type' =>  'required',
                           'specilization'      =>  'required',
                           'participate_Judge' =>  'required',
                           'participate_evaluation' =>  'required',                          

                            );

            $messages = array(
                           'required_without_all' => 'Please select atleast one "Year of Completion of Post Graduation"',
                           'pg_other_on.required' =>'Please select year Others (Please specify).',
                           'pg_other.required' =>'Please enter Others (Please specify).',                           
                           //'required'      => 'Please enter all required fields.',
                           'email.email'   => 'Please enter valid Email id.', 
                           'password.min'   => 'Your password must be at least 5 characters long', 
                           'new_confirm_password.same' => 'Please enter the same password'
                           );


            //overriding validation
            if(Input::get("rbtnPassword")==1)
            {
                $rules['password']       = 'required|min:5';   
                $rules['new_confirm_password'] = 'required|same:password';    
            }
            
            if (!empty($profile->pg_other))
            {
                $rules['pg_other_on'] = 'required';
            }
            else if (!empty($profile->pg_other_on))
            {
                $rules['pg_other'] = 'required';   
            }

            if($profile->any_fellowship == 1)
            {
                $rules['fellowship_speciality'] = 'required';      
                $rules['fellowship_training_place'] = 'required';      
                $rules['fellowship_training_duration'] = 'required';      
            }

             if($profile->any_tec_experience == 1)
            {
                $rules['teaching_years'] = 'required';                      
            }


            if($profile->currentlyinto_type == CustomClass::$Profile_PP)
            {
                $rules['private_practice'] = 'required';      
                $rules['pp_working_since'] = 'required';                      
            }
            else if($profile->currentlyinto_type == CustomClass::$Profile_MC)
            {
                $rules['medical_college'] = 'required';      
                $rules['mc_working_since'] = 'required';                      
                $rules['mc_working_as'] = 'required';                      
            }
            else if($profile->currentlyinto_type == CustomClass::$Profile_GJ)
            {
                $rules['government_job'] = 'required';      
                $rules['gov_job_working_since'] = 'required';                                      
            }
            else if($profile->currentlyinto_type == CustomClass::$Profile_NGJ)
            {
                $rules['non_gov_job'] = 'required';      
                $rules['Non_gov_job_working_since'] = 'required';                                      
            }

            if($profile->participate_Judge == 1)
            {
                $rules['participate_sections'] = 'required';                      
            }

            if($profile->participate_evaluation == 1)
            {
                $rules['participate_sections'] = 'required';                      
            }


            return Validator::make($inputs,$rules,$messages);

        } catch (Exception $e)
        {
            Log::error("UserController  - validatorRegister ".$e->getMessage());
        }
    }



    // public function validatorRegister($user)
    // {
    //     try
    //     {

    //         $inputs = array(
    //                        'prefix'         => $user->prefix,
    //                        'name'           => $user->first_name,
    //                        'address1'       => $user->address1,
    //                        'city'           => $user->city,
    //                        'state'          => $user->state_id,
    //                        'pincode'        => $user->pincode,
    //                        'mobile_isd_code'=> $user->mobile_isd_code,
    //                        'mobile'         => $user->mobile,
    //                        'email'          => $user->email,
    //                        'password'       => $user->password,
    //                        );

    //         $rules  = array(    
    //                        'prefix'         => 'required',                   
    //                        'name'           => 'required',                           
    //                        'address1'       => 'required',                           
    //                        'city'           => 'required',
    //                        'state'          => 'required',
    //                        'pincode'        => 'required',
    //                        'mobile_isd_code'=> 'required',
    //                        'mobile'         => 'required',
    //                        /*'email'          => 'required|email|unique:users',  */
    //                        'email'          => 'required',
    //                        'password'       => 'required'                           
    //                         );

    //         $messages = array(
    //                        'required'      => 'Please enter all required fields.',
    //                        'email.email'   => 'Please enter valid Email id.',                                                      
    //                        );
    //         return Validator::make($inputs,$rules,$messages);

    //     } catch (Exception $e)
    //     {
    //         Log::error("UserController  - validatorRegister ".$e->getMessage());
    //     }
    // }


    //Regiser 
    public function getMemberDetails($memNo){
         try {

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

            //login user id check 
               $user_id = CustomClass::getUserId();


           $datadb = DB::select("call usp_GetMemberDetails (1,'". Helper::trimAndTruncate($memNo,6) ."')");   
           
           $data =isset($datadb[0]) ? $datadb[0] : null ;

           
           if(empty($data))
           {
                $data = "";
                $code = 0;
                $msg  = "Please, enter a valid Member number";
           }
           else if($data->user_status == 1 && $data->user_id != $user_id)
           {
                $data = "";
                $code = 0;
                $msg  = "Sorry! Membership No already registered with us. You cannot register twice.";
           }           
           else
           {                
                $code = 1;
                $msg  = "";
           }


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

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

         return Response::json($arr); 
    }

    //Regiser 
    public function checkUsername($email){
         try {

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

            //login user id check 
            if(Input::has("user_id"))
            {
                $user_id = Input::get("user_id");  
            }
            else
            {
                $user_id = CustomClass::getUserId();
            }


           //$data = User::where('users.email',$email)->whereNotNull('password')->first();
            $data = User::where('users.email',$email)->first();
           

           if(empty($data))
           {                
                $code = 1;
                $msg  = "";
           }      
           else if($data->user_id == $user_id)    
           {
                $code = 1;
                $msg  = "";
           }
           else
           {
                $code = 0;
                $msg  = "Sorry! Email id already registered with us. You cannot register twice.";
           }


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

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

         return Response::json($arr); 
    }



    //profile get
    public function getProfile($uuid = null){
        
        
            if($uuid == null)
            {
                $user_id = CustomClass::getUserId();
                $user  = User::join('users_memberships','users.user_id', '=','users_memberships.user_id')
                        ->where('users.user_id',Auth::User()->user_id)
                        ->where('users_memberships.society_id',CustomClass::$AIOSSocietyId)->first();
            }
            else
            {
                //$user  = User::where('uuid',$uuid)->first();           
                $user  = User::join('users_memberships','users.user_id', '=','users_memberships.user_id')
                        ->where('users.uuid',$uuid)
                        ->where('users_memberships.society_id',CustomClass::$AIOSSocietyId)->first();
            }
             
            if(isset($user->user_id) && intval($user->user_id)>0)
            {
                $user_id =$user->user_id;    
            }
            else
            {
                return Redirect::to('/');
            }

        


                $profile2 = UsersProfile::where('user_id',$user->user_id)->first();

                $countries      = Country::GetCountries();                         
                $years          = CustomClass::GetProfileYears() ;
                $FPCategories   = Category::FP();                
                $VTCategories   = Category::VTProfile(); 
                       
                // foreach (Category::FP() as $key => $value) {
                //     $FPCategories[$value] = $value;
                // }

                // foreach (Category::VT() as $key => $value) {
                //     $VTCategories[$value] = $value;
                // }
                
                return View::make('auth.profile')->with('user',$user)
                                                    ->with('profile2',$profile2)
                                                    ->with('countries',$countries)
                                                    ->with('FPCategories',$FPCategories)
                                                    ->with('VTCategories',$VTCategories)
                                                    ->with('years',$years);





        
    }

    // //profile post
    // public function postProfile(){
    //     try {

    //          $operationStatus = false;
    //          $user_id = CustomClass::getUserId();

    //          $user  = User::find($user_id);
    //          $user->prefix      =  Helper::trimAndTruncate(Input::get('ddlPrefix'),10);
    //          $user->first_name        =  Helper::trimAndTruncate(Input::get('txtName'),250);
    //          $user->address1    =  Helper::trimAndTruncate(Input::get('txtAdd1'),250);
    //          $user->address2    =  Helper::trimAndTruncate(Input::get('txtAdd2'),250);
    //          $user->address3    =  Helper::trimAndTruncate(Input::get('txtAdd3'),250);
    //          $user->city        =  Helper::trimAndTruncate(Input::get('txtCity'),250);
    //          $user->state       =  Helper::trimAndTruncate(Input::get('txtState'),250);
    //          $user->pincode     =  Helper::trimAndTruncate(Input::get('txtPincode'),250);
    //          $user->country     =  Helper::trimAndTruncate(Input::get('txtCountry'),250);
    //          $user->mobile_isd_code    =  Helper::trimAndTruncate(Input::get('txtISDcode'),5);
    //          $user->mobile      =  Helper::trimAndTruncate(Input::get('txtMobile'),15);
    //          $user->email       =  Helper::trimAndTruncate(Input::get('txtEmail'),250);             
    //          $user->phone_home  =  Helper::trimAndTruncate(Input::get('txtPhHome'),100);
    //          $user->phone_office=  Helper::trimAndTruncate(Input::get('txtPhoffice'),100);
             
    //         $validator = $this->validatorProfile($user);
    //         if(isset($validator) && !$validator->fails())
    //         {
    //             //Validation success                
    //             $user->verified_at = date('Y-m-d H:i:s');
    //             if($user->save())
    //             { 
    //                 $um = UsersMembership::where('user_id',$user->user_id)->where('society_id',CustomClass::$AIOSSocietyId)->first();
    //                 if(isset($um))
    //                 {
    //                     $um->society_id     = CustomClass::$AIOSSocietyId;
    //                     $um->user_id        = $user->user_id;
    //                     $um->user_status    = 1; 
    //                     $um->save();
    //                 }

    //                 $operationStatus = true;
    //             }

    //         }else
    //         {
    //             //Validation fails
    //             $temp='';
    //             $requiredCount = 0;
    //             $messages = $validator->messages();
    //             foreach ($messages->all() as $message)
    //             {
    //                 if(preg_match('[required]', $message))
    //                 {
    //                     if($requiredCount == 0)
    //                     {
    //                       $temp = $temp .''. $message .'<br />';
    //                       $requiredCount++;
    //                     }
    //                 }
    //                 else
    //                 {
    //                     $temp =$temp .''. $message .'<br />';
    //                 }
    //             }
    //         }

    //         if($operationStatus)
    //         {

    //           return View::make('msg')->with('msg',"pu");

    //            // return Redirect::to('profile')->with('msgSuccess',AppMessage::$PROFILE_SUCCESS);
    //         }
    //         else
    //         {
    //             return Redirect::to('profile')->withInput()->with('msgError',$temp);
    //         }

    //     } catch (Exception $e) {
    //         Log::error('UserController - postRegister :'.$e->getMessage());
    //         return Redirect::to('profile')->withInput()->with('msgError',AppMessage::$GENERAL_ERROR);
    //     }

    // }

    


    //post user profile update
    //sridhar On 22 Mar 2017 10:55 AM    
    public function postProfile($uuid = null){
         try {
            $operationStatus = false;              
            $user = null;
            $user_id = 0;
            if($uuid == null)
            {
                $user_id = CustomClass::getUserId();
                $user  = User::find($user_id);           
            }
            else
            {
                $user  = User::where('uuid',$uuid)->first();           
            }
             
            if(isset($user->user_id) && intval($user->user_id)>0)
            {
                $user_id =$user->user_id;    
            }
            else
            {
                return Redirect::to('/');
            }

             
             
             $user->prefix      =  Helper::trimAndTruncate(Input::get('ddlPrefix'),10);
             if(Input::get("rbtnPassword")==1)
             {
                $user->password    =  Helper::trimAndTruncate(Input::get('password'),20);     
             }
             $user->first_name        =  Helper::trimAndTruncate(Input::get('txtName'),250);
             $user->gender      =  Helper::trimAndTruncate(Input::get('ddlGender'),250);
             $user->dob         =  Helper::toDBDate(Helper::trimAndTruncate(Input::get('txtDOB')));
             $user->address1    =  Helper::trimAndTruncate(Input::get('txtAdd1'),250);
             $user->address2    =  Helper::trimAndTruncate(Input::get('txtAdd2'),250);
             $user->address3    =  Helper::trimAndTruncate(Input::get('txtAdd3'),250);
             $user->city        =  Helper::trimAndTruncate(Input::get('txtCity'),250);
             $user->state_id    =  Helper::trimAndTruncate(Input::get('ddlState'),250);
             $user->pincode     =  Helper::trimAndTruncate(Input::get('txtPincode'),250);
             $user->country_id  =  Helper::trimAndTruncate(Input::get('ddlCountry'),250);
             $user->mobile_isd_code  =  Helper::trimAndTruncate(Input::get('txtISDcode'),5);
             $user->mobile      =  Helper::trimAndTruncate(Input::get('txtMobile'),15);
             $user->email       =  Helper::trimAndTruncate(Input::get('txtEmail'),250);             
             $user->phone_home  =  Helper::trimAndTruncate(Input::get('txtPhHome'),100);
             $user->phone_office=  Helper::trimAndTruncate(Input::get('txtPhoffice'),100);

             $user->mci_number  =  Helper::trimAndTruncate(Input::get('txtMCI_No'),50);
             $user->mci_state   =  Helper::trimAndTruncate(Input::get('txtMCI_State'),250);
             $user->is_mentor   =  Helper::setIntOrNUll(Input::get("rbtnis_mentor"));
             

             $profile2 = UsersProfile::where('user_id',$user_id)->first();
             if($profile2 == null)
             {
                $profile2 =new UsersProfile();
             }
           


             $profile2->user_id             = $user_id;
             $profile2->pg_degree_on        = Helper::setIntOrNUll(Input::get('ddlDegree'));
             $profile2->pg_diploma_on       = Helper::setIntOrNUll(Input::get('ddlDiploma'));
             $profile2->pg_dnb_on           = Helper::setIntOrNUll(Input::get('ddlDNB'));
             $profile2->pg_other            = Helper::trimAndTruncate(Input::get('txtPGOther'),100);
             $profile2->pg_other_on         = Helper::setIntOrNUll(Input::get('ddlPGOtherYear'));

             $profile2->any_fellowship      = Helper::setIntOrNUll(Input::get('rbtnFellowship'));
             $profile2->fellowship_speciality           = null;
             $profile2->fellowship_training_place       = null;
             $profile2->fellowship_training_duration    = null;             
             if($profile2->any_fellowship == 1)
             {
                 $profile2->fellowship_speciality           =  Input::has("ddlFellowshipCat")?implode(',', Input::get("ddlFellowshipCat")):'';
                 $profile2->fellowship_training_place       = Input::get("txtTrainingPlace");
                 $profile2->fellowship_training_duration    = Helper::trimAndTruncate(Input::get("txtTrainingDuration"),500);
             }
             
             $profile2->currentlyinto_type  = Input::get("rbtnCurrentlyInto");             
             
             $profile2->any_tec_experience  = Input::get("rbtnAnyTecExperience");




             $profile2->teaching_years      = null;
             if($profile2->any_tec_experience==1)
             {
                $profile2->teaching_years      = Helper::trimAndTruncate(Input::get("txtPGTeachingYear"),500);
             }

             $profile2->private_practice    = null;
             $profile2->pp_working_since    = null;
             $profile2->medical_college     = null;
             $profile2->mc_working_since    = null;
             $profile2->mc_working_as       = null;
             $profile2->government_job      = null;
             $profile2->gov_job_working_since       = null;
             $profile2->non_gov_job                 = null;
             $profile2->Non_gov_job_working_since   = null;
             if($profile2->currentlyinto_type==CustomClass::$Profile_PP)
             {
                $profile2->private_practice    = Input::has("ddlPrivatePractice")?implode(',', Input::get("ddlPrivatePractice")):'';
                $profile2->pp_working_since    = Helper::setIntOrNUll(Input::get("ddlPPWorkingSince"));   
             }
             else if($profile2->currentlyinto_type==CustomClass::$Profile_MC)
             {
                $profile2->medical_college     = Helper::trimAndTruncate(Input::get("txttMCNameofCollage"),500);
                $profile2->mc_working_since    = Helper::setIntOrNUll(Input::get("ddlMCWorkingSince"));
                $profile2->mc_working_as       = Helper::trimAndTruncate(Input::get("txtMCWorkingas"),500);
             }
             else if($profile2->currentlyinto_type==CustomClass::$Profile_GJ)
             {
                $profile2->government_job      = Helper::trimAndTruncate(Input::get("txtGJNameofPlace"),500);
                $profile2->gov_job_working_since       = Helper::setIntOrNUll(Input::get("ddlGJWorkingSince"));   
             }
             else if($profile2->currentlyinto_type==CustomClass::$Profile_NGJ)
             {
                $profile2->non_gov_job                 = Input::get("txtNGJNameofPlace");
                $profile2->Non_gov_job_working_since   = Helper::setIntOrNUll(Input::get("ddlNGJWorkingSince"));
             }
             
             
             $profile2->specilization               = Input::has("ddlSpecilization")?implode(',', Input::get("ddlSpecilization")):'';

             $profile2->participate_Judge           = Helper::setIntOrNUll(Input::get("rbtnParticipateJudge"));             
             $profile2->participate_evaluation      = Helper::setIntOrNUll(Input::get("rbtnParticipateEvaluation"));
             
             $profile2->participate_sections  = null;
             if($profile2->participate_Judge ==1 || $profile2->participate_evaluation ==1)
             {
                
                    $profile2->participate_sections           = Input::has("chkParticipate")?implode(',', Input::get("chkParticipate")):'';

                    /****** Added by Gowthami on 22 Jun 2017 ****/
                    /****** start code  ****/
                    $checkparticipate = [];
                    $dbupdatecheckparticipate=[];
                    $dbupdatecheckparticipatenew=[];

                    $checkparticipate = Input::has("chkParticipate")?Input::get("chkParticipate"):[];
                    $dbupdatecheckparticipate = UsersParticipateSections::where('user_id',$user_id)->get();

                    foreach ($dbupdatecheckparticipate as $key => $value) {
                        $category_id = $value->category_id;
                        array_push($dbupdatecheckparticipatenew,$category_id);
                    }
                             

                    $delete_catids =  array_diff($dbupdatecheckparticipatenew,$checkparticipate);
                    $insert_catids=  array_diff($checkparticipate,$dbupdatecheckparticipatenew );

                    if(isset($delete_catids) && count($delete_catids)>0)
                    {
                        UsersParticipateSections::where('user_id',$user_id)->whereIn('category_id',$delete_catids)->delete();
                    }
                    if(isset($insert_catids) && count($insert_catids)>0)
                    {   
                        foreach ($insert_catids as $key => $value) {
                           $profile3 = new UsersParticipateSections();
                           $profile3->category_id =  $value;
                           $profile3->user_id     =  $user_id;
                           $profile3->save();

                        }
                    }

                    /****** end code  ****/

           }
           else
           {
                UsersParticipateSections::where('user_id',$user_id)->delete();
           }               
           
                 /****** Sridhar On 2021-12-28 12:52 PM  ****/
                    /****** start code  ****/
                    $checkspecilization = [];
                    $dbupdatecheckspecilization=[];
                    $dbupdatecheckspecilizationnew=[];

                    $checkspecilization = Input::has("ddlSpecilization")?Input::get("ddlSpecilization"):[];
                    $dbupdatecheckspecilization = UsersSpecializations::where('user_id',$user_id)->get();

                    foreach ($dbupdatecheckspecilization as $key => $value) {
                        $category_id = $value->category_id;
                        array_push($dbupdatecheckspecilizationnew,$category_id);
                    }
                             

                    $spec_delete_catids =  array_diff($dbupdatecheckspecilizationnew,$checkspecilization);
                    $spec_insert_catids=  array_diff($checkspecilization,$dbupdatecheckspecilizationnew );

                    if(isset($spec_delete_catids) && count($spec_delete_catids)>0)
                    {
                        UsersSpecializations::where('user_id',$user_id)->whereIn('category_id',$spec_delete_catids)->delete();
                    }
                    if(isset($spec_insert_catids) && count($spec_insert_catids)>0)
                    {   
                        foreach ($spec_insert_catids as $key => $value) {
                           $profile3 = new UsersSpecializations();
                           $profile3->category_id =  $value;
                           $profile3->user_id     =  $user_id;
                           $profile3->save();

                        }
                    }

                    /****** end code  ****/

             $profile2->any_remarks  = Helper::trimAndTruncate(Input::get("txtAnyRemarks"));

             
            $validator = $this->validatorUserUpdate($user,$profile2);
            if(isset($validator) && !$validator->fails())
            {
                //Validation success                
                if(Input::get("rbtnPassword")==1)
                {
                    $user->old_pwd   =  $user->password;
                    $user->password  =  Hash::make($user->password);    
                }
                
                $user->verified_at = date('Y-m-d H:i:s');
                $user->profile_updated_on = date('Y-m-d H:i:s');

                if($user->save())
                { 
                    $profile2->save();

                    $um = UsersMembership::where('user_id',$user->user_id)->where('society_id',CustomClass::$AIOSSocietyId)->first();
                    if(isset($um))
                    {
                        $um->society_id     = CustomClass::$AIOSSocietyId;
                        $um->user_id        = $user->user_id;
                        $um->user_status    = 1; 
                        $um->save();
                    }

                    $operationStatus = true;
                }

            }else
            {
                //Validation fails
                $temp='';
                $requiredCount = 0;
                $messages = $validator->messages();
                foreach ($messages->all() as $message)
                {
                    if(preg_match('[required]', $message))
                    {
                        if($requiredCount == 0)
                        {
                          $temp = $temp .''. $message .'<br />';
                          $requiredCount++;
                        }
                    }
                    else if(preg_match('[Year of Completion of Post Graduation]', $message))
                    {
                        if($requiredCount == 0)
                        {
                          $temp = $temp .''. $message .'<br />';
                          $requiredCount++;
                        }
                    }
                    else
                    {
                        $temp =$temp .''. $message .'<br />';
                    }
                }
            }

            if($operationStatus)
            {
              return View::make('msg')->with('msg',"pu");
            }
            else
            {
                return Redirect::to('profile')->withInput()->with('msgError',$temp);
            }

        } catch (Exception $e) {
            Log::error('UserController - postProfile :'.$e->getMessage());
            return Redirect::to('profile')->withInput()->with('msgError',AppMessage::$GENERAL_ERROR);
        }

    }



    public function validatorProfile($user)
    {
        try
        {

            $inputs = array(
                           'prefix'         => $user->prefix,
                           'name'           => $user->first_name,
                           'address1'       => $user->address1,
                           'city'           => $user->city,
                           'state'          => $user->state,
                           'pincode'        => $user->pincode,
                           'mobile_isd_code'=> $user->mobile_isd_code,
                           'mobile'         => $user->mobile,
                           'email'          => $user->email,       
                           'is_mentor'      => $user->is_mentor
                           );

            $rules  = array(    
                           'prefix'         => 'required',                   
                           'name'           => 'required',                           
                           'address1'       => 'required',                           
                           'city'           => 'required',
                           'state'          => 'required',
                           'pincode'        => 'required',
                           'mobile_isd_code'=> 'required',
                           'mobile'         => 'required',
                           /*'email'          => 'required|email|unique:users',  */
                           'email'          => 'required',
                           'is_mentor'      => 'required'
                                                  
                            );

            $messages = array(
                           'required'      => 'Please enter all required fields.',
                           'email.email'   => 'Please enter valid Email id.',                                                      
                           );
            return Validator::make($inputs,$rules,$messages);

        } catch (Exception $e)
        {
            Log::error("UserController  - validatorRegister ".$e->getMessage());
        }
    }


    
    public function getUserDetails($user_id)
    {
        try
        {
            return User::join('users_memberships','users.user_id', '=','users_memberships.user_id')
                          ->select('users.*','users_memberships.*','users.first_name as name')  
                          ->where('users.user_id',$user_id)->first();

        } catch (Exception $e)
        {
            Log::error("UserController  - getUserDetails ".$e->getMessage());
        }
    }


    public function getStatesByCountry(){
         try {

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

            //login user id check 
            $country_id = intval(Input::get("country_id"));          

            $data      = State::GetStates($country_id);
            $code = 1;
            $msg  = "";

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

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

         return Response::json($arr); 
    }


    //Sridhar  On 15 Mar 2017 4:35 PM
    //user update From mail
    public function getUserUpdate($id){

        try {
            $user  = User::join('users_memberships','users.user_id', '=','users_memberships.user_id')
                 ->where('users.uuid',$id)
                 ->where('users_memberships.society_id',1)->first();

            if($user != null)
            {
                $profile2 = UsersProfile::where('user_id',$user->user_id)->first();

                $countries      = Country::GetCountries();                         
                $years          = CustomClass::GetProfileYears() ;
                $FPCategories   = Category::FP();                
                $VTCategories   = Category::VT(); 
                       
                // foreach (Category::FP() as $key => $value) {
                //     $FPCategories[$value] = $value;
                // }

                // foreach (Category::VT() as $key => $value) {
                //     $VTCategories[$value] = $value;
                // }
                
                return View::make('auth.userupdate')->with('user',$user)
                                                    ->with('profile2',$profile2)
                                                    ->with('countries',$countries)
                                                    ->with('FPCategories',$FPCategories)
                                                    ->with('VTCategories',$VTCategories)
                                                    ->with('years',$years);


            }
            else
            {            
                return View::make('msg2')->with('msg',"url");  
            }
            
        } catch (Exception $e) {
             Log::error('UserController - getUserUpdate :'.$e->getMessage());
             return View::make('msg2')->with('msg',AppMessage::$GENERAL_ERROR);  
        }
        

     
    }

    //post user profile update from mail
    //sridhar On 16 Mar 2017 12:28 PM
    //validation for user update
    public function postUserUpdate($id){
         try {

             $operationStatus = false;              

             $user  = User::where('uuid',$id)->first();             
             $user_id = $user->user_id;
             $user->prefix      =  Helper::trimAndTruncate(Input::get('ddlPrefix'),10);
             if(Input::get("rbtnPassword")==1)
             {
                $user->password    =  Helper::trimAndTruncate(Input::get('password'),20);     
             }
             $user->first_name        =  Helper::trimAndTruncate(Input::get('txtName'),250);
             $user->gender      =  Helper::trimAndTruncate(Input::get('ddlGender'),250);
             $user->dob         =  Helper::toDBDate(Helper::trimAndTruncate(Input::get('txtDOB')));
             $user->address1    =  Helper::trimAndTruncate(Input::get('txtAdd1'),250);
             $user->address2    =  Helper::trimAndTruncate(Input::get('txtAdd2'),250);
             $user->address3    =  Helper::trimAndTruncate(Input::get('txtAdd3'),250);
             $user->city        =  Helper::trimAndTruncate(Input::get('txtCity'),250);
             $user->state_id    =  Helper::trimAndTruncate(Input::get('ddlState'),250);
             $user->pincode     =  Helper::trimAndTruncate(Input::get('txtPincode'),250);
             $user->country_id  =  Helper::trimAndTruncate(Input::get('ddlCountry'),250);
             $user->mobile_isd_code  =  Helper::trimAndTruncate(Input::get('txtISDcode'),5);
             $user->mobile      =  Helper::trimAndTruncate(Input::get('txtMobile'),15);
             $user->email       =  Helper::trimAndTruncate(Input::get('txtEmail'),250);             
             $user->phone_home  =  Helper::trimAndTruncate(Input::get('txtPhHome'),100);
             $user->phone_office=  Helper::trimAndTruncate(Input::get('txtPhoffice'),100);

             $user->mci_number  =  Helper::trimAndTruncate(Input::get('txtMCI_No'),50);
             $user->mci_state   =  Helper::trimAndTruncate(Input::get('txtMCI_State'),250);

             $profile2 = UsersProfile::where('user_id',$user_id)->first();
             if($profile2 == null)
             {
                $profile2 =new UsersProfile();
             }


             $profile2->user_id             = $user_id;
             $profile2->pg_degree_on        = Helper::setIntOrNUll(Input::get('ddlDegree'));
             $profile2->pg_diploma_on       = Helper::setIntOrNUll(Input::get('ddlDiploma'));
             $profile2->pg_dnb_on           = Helper::setIntOrNUll(Input::get('ddlDNB'));
             $profile2->pg_other            = Helper::trimAndTruncate(Input::get('txtPGOther'),100);
             $profile2->pg_other_on         = Helper::setIntOrNUll(Input::get('ddlPGOtherYear'));

             $profile2->any_fellowship      = Helper::setIntOrNUll(Input::get('rbtnFellowship'));
             $profile2->fellowship_speciality           = null;
             $profile2->fellowship_training_place       = null;
             $profile2->fellowship_training_duration    = null;             
             if($profile2->any_fellowship == 1)
             {
                 $profile2->fellowship_speciality           =  Input::has("ddlFellowshipCat")?implode(',', Input::get("ddlFellowshipCat")):'';
                 $profile2->fellowship_training_place       = Input::get("txtTrainingPlace");
                 $profile2->fellowship_training_duration    = Helper::trimAndTruncate(Input::get("txtTrainingDuration"),500);
             }
             
             $profile2->currentlyinto_type  = Input::get("rbtnCurrentlyInto");             
             
             $profile2->any_tec_experience  = Input::get("rbtnAnyTecExperience");




             $profile2->teaching_years      = null;
             if($profile2->any_tec_experience==1)
             {
                $profile2->teaching_years      = Helper::trimAndTruncate(Input::get("txtPGTeachingYear"),500);
             }

             $profile2->private_practice    = null;
             $profile2->pp_working_since    = null;
             $profile2->medical_college     = null;
             $profile2->mc_working_since    = null;
             $profile2->mc_working_as       = null;
             $profile2->government_job      = null;
             $profile2->gov_job_working_since       = null;
             $profile2->non_gov_job                 = null;
             $profile2->Non_gov_job_working_since   = null;
             if($profile2->currentlyinto_type==CustomClass::$Profile_PP)
             {
                $profile2->private_practice    = Input::has("ddlPrivatePractice")?implode(',', Input::get("ddlPrivatePractice")):'';
                $profile2->pp_working_since    = Helper::setIntOrNUll(Input::get("ddlPPWorkingSince"));   
             }
             else if($profile2->currentlyinto_type==CustomClass::$Profile_MC)
             {
                $profile2->medical_college     = Helper::trimAndTruncate(Input::get("txttMCNameofCollage"),500);
                $profile2->mc_working_since    = Helper::setIntOrNUll(Input::get("ddlMCWorkingSince"));
                $profile2->mc_working_as       = Helper::trimAndTruncate(Input::get("txtMCWorkingas"),500);
             }
             else if($profile2->currentlyinto_type==CustomClass::$Profile_GJ)
             {
                $profile2->government_job      = Helper::trimAndTruncate(Input::get("txtGJNameofPlace"),500);
                $profile2->gov_job_working_since       = Helper::setIntOrNUll(Input::get("ddlGJWorkingSince"));   
             }
             else if($profile2->currentlyinto_type==CustomClass::$Profile_NGJ)
             {
                $profile2->non_gov_job                 = Input::get("txtNGJNameofPlace");
                $profile2->Non_gov_job_working_since   = Helper::setIntOrNUll(Input::get("ddlNGJWorkingSince"));
             }
             
             
             $profile2->specilization               = Input::has("ddlSpecilization")?implode(',', Input::get("ddlSpecilization")):'';

             $profile2->participate_Judge           = Helper::setIntOrNUll(Input::get("rbtnParticipateJudge"));             
             $profile2->participate_evaluation      = Helper::setIntOrNUll(Input::get("rbtnParticipateEvaluation"));
             
             $profile2->participate_sections  = null;
             if($profile2->participate_Judge ==1 || $profile2->participate_evaluation ==1)
             {
                    $profile2->participate_sections           = Input::has("chkParticipate")?implode(',', Input::get("chkParticipate")):'';
             }             

             $profile2->any_remarks  = Helper::trimAndTruncate(Input::get("txtAnyRemarks"));

             
            $validator = $this->validatorUserUpdate($user,$profile2);
            if(isset($validator) && !$validator->fails())
            {
                //Validation success                
                if(Input::get("rbtnPassword")==1)
                {
                    $user->old_pwd   =  $user->password;
                    $user->password  =  Hash::make($user->password);    
                }
                
                $user->verified_at = date('Y-m-d H:i:s');
                $user->profile_updated_on = date('Y-m-d H:i:s');

                if($user->save())
                { 
                    $profile2->save();

                    $um = UsersMembership::where('user_id',$user->user_id)->where('society_id',CustomClass::$AIOSSocietyId)->first();
                    if(isset($um))
                    {
                        $um->society_id     = CustomClass::$AIOSSocietyId;
                        $um->user_id        = $user->user_id;
                        $um->user_status    = 1; 
                        $um->save();
                    }

                    $operationStatus = true;
                }

            }else
            {
                //Validation fails
                $temp='';
                $requiredCount = 0;
                $messages = $validator->messages();
                foreach ($messages->all() as $message)
                {
                    if(preg_match('[required]', $message))
                    {
                        if($requiredCount == 0)
                        {
                          $temp = $temp .''. $message .'<br />';
                          $requiredCount++;
                        }
                    }
                    else if(preg_match('[Year of Completion of Post Graduation]', $message))
                    {
                        if($requiredCount == 0)
                        {
                          $temp = $temp .''. $message .'<br />';
                          $requiredCount++;
                        }
                    }
                    else
                    {
                        $temp =$temp .''. $message .'<br />';
                    }
                }
            }

            if($operationStatus)
            {

              return View::make('msg2')->with('msg',"pu");
            }
            else
            {
                return Redirect::to('userupdate/'.$id)->withInput()->with('msgError',$temp);
            }

        } catch (Exception $e) {
            Log::error('UserController - postUserUpdate :'.$e->getMessage());
            return Redirect::to('userupdate/'.$id)->withInput()->with('msgError',AppMessage::$GENERAL_ERROR);
        }

    }


    //sridhar On 16 Mar 2017 12:28 PM
    //validation for user update    
    public function validatorUserUpdate($user,$profile)
    {
        try
        {

            $inputs = array(
                           'prefix'         => $user->prefix,
                           'name'           => $user->first_name,
                           'password'       => $user->password,
                           'new_confirm_password' => Input::get("password_confirmation"),
                           'address1'       => $user->address1,
                           'city'           => $user->city,
                           'state'          => $user->state_id,
                           'pincode'        => $user->pincode,
                           'mobile_isd_code'=> $user->mobile_isd_code,
                           'mobile'         => $user->mobile,
                           'email'          => $user->email,                           
                           'pg_degree_on'   => $profile->pg_degree_on,
                           'pg_diploma_on'  => $profile->pg_diploma_on,
                           'pg_dnb_on'      => $profile->pg_dnb_on,
                           'pg_other'       => $profile->pg_other,
                           'pg_other_on'    => $profile->pg_other_on,
                           'any_fellowship' => $profile->any_fellowship,
                           'fellowship_speciality' => $profile->fellowship_speciality,
                           'fellowship_training_place' => $profile->fellowship_training_place,
                           'fellowship_training_duration' => $profile->fellowship_training_duration,
                           'teaching_years' => $profile->teaching_years,
                           'currentlyinto_type' => $profile->currentlyinto_type,
                           'private_practice' => $profile->private_practice,
                           'pp_working_since' => $profile->pp_working_since,
                           'medical_college' => $profile->medical_college,
                           'mc_working_since' => $profile->mc_working_since,
                           'mc_working_as' => $profile->mc_working_as,
                           'government_job' => $profile->government_job,
                           'gov_job_working_since' => $profile->gov_job_working_since,
                           'non_gov_job' => $profile->non_gov_job,
                           'Non_gov_job_working_since' => $profile->Non_gov_job_working_since,
                           'specilization' => $profile->specilization,
                           'participate_Judge' => $profile->participate_Judge,
                           'participate_evaluation' => $profile->participate_evaluation,
                           'any_tec_experience' => $profile->any_tec_experience,
                           'participate_sections' => $profile->participate_sections,                           
                           );

            $rules  = array(    
                           'prefix'         => 'required',                   
                           'name'           => 'required',                                                   
                           'address1'       => 'required',                           
                           'city'           => 'required',
                           'state'          => 'required',
                           'pincode'        => 'required',
                           'mobile_isd_code'=> 'required',
                           'mobile'         => 'required',
                           'email'          => 'required|email',                           
                           'pg_degree_on'   => 'required_without_all:pg_diploma_on,pg_dnb_on,pg_other,pg_other_on',
                           'pg_diploma_on'  => 'required_without_all:pg_degree_on,pg_dnb_on,pg_other,pg_other_on',
                           'pg_dnb_on'      => 'required_without_all:pg_degree_on,pg_diploma_on,pg_other,pg_other_on',
                           'pg_other'       => 'required_without_all:pg_degree_on,pg_diploma_on,pg_dnb_on,pg_other_on',
                           'pg_other_on'    => 'required_without_all:pg_degree_on,pg_diploma_on,pg_dnb_on,pg_other',
                           'any_fellowship' =>  'required',
                           'any_tec_experience' =>  'required',
                           'currentlyinto_type' =>  'required',
                           'specilization'      =>  'required',
                           'participate_Judge' =>  'required',
                           'participate_evaluation' =>  'required',                          

                            );

            $messages = array(
                           'required_without_all' => 'Please select atleast one "Year of Completion of Post Graduation"',
                           'pg_other_on.required' =>'Please select year Others (Please specify).',
                           'pg_other.required' =>'Please enter Others (Please specify).',                           
                           //'required'      => 'Please enter all required fields.',
                           'email.email'   => 'Please enter valid Email id.', 
                           'password.min'   => 'Your password must be at least 5 characters long', 
                           'new_confirm_password.same' => 'Please enter the same password'
                           );


            //overriding validation
            if(Input::get("rbtnPassword")==1)
            {
                $rules['password']       = 'required|min:5';   
                $rules['new_confirm_password'] = 'required|same:password';    
            }
            
            if (!empty($profile->pg_other))
            {
                $rules['pg_other_on'] = 'required';
            }
            else if (!empty($profile->pg_other_on))
            {
                $rules['pg_other'] = 'required';   
            }

            if($profile->any_fellowship == 1)
            {
                $rules['fellowship_speciality'] = 'required';      
                $rules['fellowship_training_place'] = 'required';      
                $rules['fellowship_training_duration'] = 'required';      
            }

             if($profile->any_tec_experience == 1)
            {
                $rules['teaching_years'] = 'required';                      
            }


            if($profile->currentlyinto_type == CustomClass::$Profile_PP)
            {
                $rules['private_practice'] = 'required';      
                $rules['pp_working_since'] = 'required';                      
            }
            else if($profile->currentlyinto_type == CustomClass::$Profile_MC)
            {
                $rules['medical_college'] = 'required';      
                $rules['mc_working_since'] = 'required';                      
                $rules['mc_working_as'] = 'required';                      
            }
            else if($profile->currentlyinto_type == CustomClass::$Profile_GJ)
            {
                $rules['government_job'] = 'required';      
                $rules['gov_job_working_since'] = 'required';                                      
            }
            else if($profile->currentlyinto_type == CustomClass::$Profile_NGJ)
            {
                $rules['non_gov_job'] = 'required';      
                $rules['Non_gov_job_working_since'] = 'required';                                      
            }

            if($profile->participate_Judge == 1)
            {
                $rules['participate_sections'] = 'required';                      
            }

            if($profile->participate_evaluation == 1)
            {
                $rules['participate_sections'] = 'required';                      
            }


            return Validator::make($inputs,$rules,$messages);

        } catch (Exception $e)
        {
            Log::error("UserController  - validatorUserUpdate ".$e->getMessage());
        }
    }

    /*
        Sridhar On 5Apr2017 10:38 AM
        User Type validation from users membership table
    */
    public function isUserType($user_id,$user_types)
    {
        try
        {
            $count = User::join('users_memberships','users.user_id', '=','users_memberships.user_id')
                          ->select('users.*','users_memberships.*','users.first_name as name')  
                          ->where('users.user_id',$user_id)
                          ->whereIn('users_memberships.user_type_id',explode(',', $user_types))->count();
            return $count>0?true:false;

        } catch (Exception $e)
        {
            Log::error("UserController  - getUserDetails ".$e->getMessage());
            return false;
        }
    }


     /*
        Sridhar On 09Feb2018 03:49 PM
        Send Custom Notification for users 
        can send SMS, app notifcation and email 
    */
    public function creatCustomNotification()
    {


        // try
        // {
            $selectedtype = 0;
            $showUser        = 0;
            $arrSearchedData = array();
           
            $search       = Input::has('search')?Input::get('search'):Input::get('txtSearch');
            // $user_type_id = '1,2,3';
            $user_type_id =  Input::has('user_type_id') ? Input::get('user_type_id') : '1,2,3';
        
            $users = [];

            if(Input::has('showUser') && intval(Input::get('showUser')) ==1 )
            {
                $selectedtype =4;
                $users        = Abstracts::usp_get_authors($search,null,null,null,$user_type_id,null);

                $showUser     = 1;
                
                if(isset($search))
                {                      
                    array_push($arrSearchedData,$search);
                }
            }

            $fp_sessions = DB::table('abstracts')->where('abs_type','=','FP')
                                                  ->whereNotNull('name_in_grid_id')
                                                  ->where('selection_type_id','=','2')
                                                  ->orderBy('name_in_grid_id','asc')
                                                  ->lists('name_in_grid','name_in_grid_id'); 

            $vt_sessions = Category::where('is_vt','1')->orderBy('name')
                                          ->lists('display_name', 'category_id');


            $pp_sessions = Category::where('is_fp','1')->orderBy('name')
                               ->lists('display_name', 'category_id');   

          return View::make('backoffice/customnotification')->with('users',$users)
                                                            ->with('showUser',$showUser)
                                                            ->with('search',$search)
                                                            ->with('arrSearchedData',$arrSearchedData)
                                                            ->with('selectedtype',$selectedtype)
                                                            ->with('fp_sessions',$fp_sessions)
                                                            ->with('vt_sessions',$vt_sessions)  
                                                            ->with('pp_sessions',$pp_sessions);

        // } catch (Exception $e)
        // {
        //     Log::error("UserController  - sendCustomNotification ".$e->getMessage());
        //     return false;
        // }
    }



     /*
        Sridhar On 10Feb2018 12:49 PM
        Send Custom Notification for users 
        can send SMS, app notifcation and email 
    */
    public function sendCustomNotification()
    {
        try
        {

            $usersMessages= [];
            $userssmsMessages = [];
            $usersemailMessages = [];

            $issample = Input::get('issample',0);
            $ispreview = Input::get('ispreview',0);

            

            $customUserType = Input::get('ddlCustomUserType');
            $chkApp = Input::get('chkApp');
            $chkSMS = Input::get('chkSMS');
            $txtNotification = trim(Input::get('txtNotification'));
            $txtEmailSubject = trim(Input::get('txtEmailSubject'));       
            $txtEmail = trim(Input::get('txtEmail'));       


            $rbtnUser = Input::get("rbtnUser");
            $txtMobileNos = Input::get("txtMobileNos");
            $txtEmailIds = Input::get("txtEmailIds");

            $txtMobileNos= isset($txtMobileNos)?trim($txtMobileNos):'';
            $txtEmailIds= isset($txtEmailIds)?trim($txtEmailIds):'';            

            $ddlFPSession = Input::get("ddlFPSession");
            $ddlVTSession = Input::get("ddlVTSession");
            $ddlPPSession = Input::get("ddlPPSession");


            if(!intval($customUserType)>0)
            {
                return Redirect::to('bo/sendnotifcation')->withInput()->with('msgError','Please select Filter');
            }
            else if(intval($customUserType)==4) //find user
            {
                if(!(intval($rbtnUser)>0))
                return Redirect::back()->withInput()->with('msgError','Please select Search User');
            }
            else if(intval($customUserType)==5) //Custom mobile and email entry
            {
             if(empty($txtMobileNos) && empty($txtEmailIds))
                return Redirect::back()->withInput()->with('msgError','Please enter Custom Mobie numbers or Email Ids');
            }
            else if(intval($customUserType)==6) //FP Session
            {
             if(empty($ddlFPSession))
                return Redirect::back()->withInput()->with('msgError','Please select FP Session');
            }
            else if(intval($customUserType)==7) //VT Session
            {
             if(empty($ddlVTSession))
                return Redirect::back()->withInput()->with('msgError','Please select VT Session');
            }
            else if(intval($customUserType)==8) //PP Session
            {
             if(empty($ddlPPSession))
                return Redirect::back()->withInput()->with('msgError','Please select PP Session');
            }

            if(empty($txtNotification) && empty($txtEmail))
            {
                return Redirect::to('bo/sendnotifcation')->withInput()->with('msgError','Please enter Notification');   
            }
            else if(!empty($txtNotification) &&  !(intval($chkApp) >0) && !(intval($chkSMS) >0))
            {
                return Redirect::to('bo/sendnotifcation')->withInput()->with('msgError','Please Select App Notification or SMS');   
            }
            else if(!empty($txtEmail) && empty($txtEmailSubject) && intval($ispreview)!=1)
            {
                
             return Redirect::to('bo/sendnotifcation')->withInput()->with('msgError','Please enter Email Subject');      
            }
          
           if(intval($customUserType)==4)
          {
            $result = [];
            if(intval($issample)==1)
            {
                   $obj = new stdClass();       
$obj->user_id = 4250;                
                   $obj->mobile  = "9952514049";
                   $obj->email   = "sridharan.r@numerotec.com";
                   $obj->name  = "Mr.sridhar";
                   $obj->membership_no = "S9999";

                   array_push($result, $obj);
            }
            else
            {

                $result = DB::select("select 
                                      u.user_id,
                                      case when u.prefix is null then
                                            concat(u.first_name,
                                                    ' ',
                                            ifnull(u.last_name, ''))
                                            else concat(u.prefix,
                                                '.',
                                                u.first_name,
                                                ' ',
                                                ifnull(u.last_name, ''))
                                        end as name,
                                        u.mobile,u.email,um.membership_no from users u 
                                        inner join users_memberships um on um.user_id = u.user_id
                                        where u.user_id =".$rbtnUser);
            }
          }
          else if(intval($customUserType)==5) //Custom mobie and email
          {
            if(intval($issample)==1)
            {
                $txtMobileNos = "9952514049";
                $txtEmailIds = "sridharan.r@numerotec.com";
            }

            $result = [];
            if(!empty($txtMobileNos))
            {
                $txtMobileNos = explode(',', $txtMobileNos);
                foreach ($txtMobileNos as $key => $value) {
                       $obj = new stdClass();                       
                       $obj->mobile   = trim($value);
                       array_push($result, $obj);
                }

            }
            
            if(!empty($txtEmailIds))
            {
                $txtEmailIds = explode(',', $txtEmailIds);
                foreach ($txtEmailIds as $key => $value) {
                           $obj = new stdClass();                       
                           $obj->email   = trim($value);
                           array_push($result, $obj);
                }
            }

          }
          else if(intval($customUserType)==6) //FP Sessions
          {
            $result = [];
            if(intval($issample)==1)
            {
                   $obj = new stdClass();          
$obj->user_id = 4250;             
                   $obj->mobile  = "9952514049";
                   $obj->email   = "sridharan.r@numerotec.com";
                   $obj->name  = "Mr.sridhar";
                   $obj->membership_no = "S9999";

                   array_push($result, $obj);
            }
            else
            {

                $result = DB::select("select distinct u.user_id,
                                  case when u.prefix is null then
                                        concat(u.first_name,
                                                ' ',
                                        ifnull(u.last_name, ''))
                                        else concat(u.prefix,
                                            '.',
                                            u.first_name,
                                            ' ',
                                            ifnull(u.last_name, ''))
                                end as name,
                                u.mobile,u.email,um.membership_no from abstracts a 
                            inner join authors au  on au.abs_id = a.abs_id
                            inner join users u on u.user_id =au.user_id
                             inner join users_memberships um on um.user_id = u.user_id  
                            where a.status_id =2 and selection_type_id =2 and a.name_in_grid_id =".$ddlFPSession);
            }
          }
          else if(intval($customUserType)==7) //VT Sessions
          {
            $result = [];
            if(intval($issample)==1)
            {
                   $obj = new stdClass();       
$obj->user_id = 4250;                
                   $obj->mobile  = "9952514049";
                   $obj->email   = "sridharan.r@numerotec.com";
                   $obj->name  = "Mr.sridhar";
                   $obj->membership_no = "S9999";

                   array_push($result, $obj);
            }
            else
            {
                $result = DB::select("select distinct 
                                    u.user_id,
                                    case when u.prefix is null then
                                        concat(u.first_name,
                                                ' ',
                                        ifnull(u.last_name, ''))
                                        else concat(u.prefix,
                                            '.',
                                            u.first_name,
                                            ' ',
                                            ifnull(u.last_name, ''))
                                    end as name,
                                    u.mobile,u.email,um.membership_no from abstracts a 
                                    inner join authors au  on au.abs_id = a.abs_id
                                    inner join users u on u.user_id =au.user_id
                                    inner join users_memberships um on um.user_id = u.user_id  
                                    where a.status_id =2 and selection_type_id =6 and a.category_id=".$ddlVTSession);
            }
          }
          else if(intval($customUserType)==8) //PP Sessions
          {
            $result = [];
            if(intval($issample)==1)
            {
                   $obj = new stdClass();     
                   $obj->user_id = 4250;                  
                   $obj->mobile  = "9952514049";
                   $obj->email   = "sridharan.r@numerotec.com";
                   $obj->name  = "Mr.sridhar";
                   $obj->membership_no = "S9999";

                   array_push($result, $obj);
            }
            else
            {
                $result = DB::select("select distinct 
                                    u.user_id,
                                          case when u.prefix is null then
                                                concat(u.first_name,
                                                        ' ',
                                                ifnull(u.last_name, ''))
                                                else concat(u.prefix,
                                                    '.',
                                                    u.first_name,
                                                    ' ',
                                                    ifnull(u.last_name, ''))
                                        end as name,
                                        u.mobile,u.email,um.membership_no from abstracts a 
                                    inner join authors au  on au.abs_id = a.abs_id
                                    inner join users u on u.user_id =au.user_id
                                     inner join users_memberships um on um.user_id = u.user_id  
                                    where a.status_id =2 and a.abs_type='PP' and a.category_id=".$ddlPPSession);
            }
          }
          else
          {
             $result = DB::select("call usp_get_custom_notification_users(".$customUserType.",".$issample.")");
          }
           

            Log::info('Custom Notification users count : '. count($result));     

            //Loop data
            foreach ($result as $key => $item) {


                //https://stackoverflow.com/questions/44078090/how-do-i-create-merge-tags-in-a-php-mysql-app
                $values = [];
                $values = array(
                    'name'                => isset($item->name)?$item->name:'',
                    'membership_no'       => isset($item->membership_no)?$item->membership_no:''             
                );

                

                if(!empty($txtNotification))    
                {                    
                    $str =     Helper::merge_tag($txtNotification,$values);

                    if(intval($chkApp)>0 && isset($item->user_id))
                    {                        
                       $obj = new stdClass();
                       $obj->user_id   = $item->user_id;                                               
                       $obj->message   = $str;
                        
                       array_push($usersMessages, $obj);

                    }

                    if(intval($chkSMS)>0)
                    {
                        if(!empty($item->mobile))
                        {
                            $objsms = new stdClass();  
                            $objsms->to   = [$item->mobile];                   
                            $objsms->message  = $str;
                            
                            array_push($userssmsMessages, $objsms);    
                        }                        
                    }

                }
                if(!empty($txtEmail))    
                {

                    $stremail =     Helper::merge_tag($txtEmail,$values);     
                    $subject  =  Helper::merge_tag($txtEmailSubject,$values);     

                    if(!empty($item->email))
                        {                            
                            $objemail = new stdClass();  
                            $objemail->email   = $item->email;                   
                            $objemail->html  = $stremail;
                            $objemail->subject =  $subject;

                            array_push($usersemailMessages, $objemail);    
                            if(intval($ispreview) ==1)
                            {
                                echo $stremail;
                                exit();
                            }
                        }                 
                }

            }   

           // echo "Notification <br />";
          //  var_dump($usersMessages);
         // echo "<br /> SMS <br />";
//        var_dump($userssmsMessages);
   //      echo "<br /> Email <br />";
        //    var_dump($usersemailMessages);            
          //  exit();

             if(count($usersMessages)>0) 
               {
                    try {
                           Helper::sendNotifications($usersMessages, "AIOS");             
                    } catch (Exception $e) {
                        echo "sendCustomNotification - sendNotifications : " . $e->getMessage();            
                        Log::error('UserController - sendCustomNotification -  sendNotifications : '.$e->getMessage());                   
                    }
               }
               if(count($userssmsMessages)>0)
               {
                 try {
                        Helper::smsBulk_v2($userssmsMessages, "AIOS");             
                    } catch (Exception $e) {
                        echo "sendCustomNotification - sendSMS : " . $e->getMessage();            
                        Log::error('UserController - sendCustomNotification -  sendSMS : '.$e->getMessage());                   
                    }
               }

               if(count($usersemailMessages)>0)
               {

                try {
                        $this->sendEmailNotification($usersemailMessages);             
                    } catch (Exception $e) {
                        echo "sendCustomNotification - sendEmail : " . $e->getMessage();            
                        Log::error('UserController - sendCustomNotification -  sendEmail : '.$e->getMessage());                   
                    } 
                }

                return Redirect::to('bo/sendnotifcation')->withInput()->with('msgSuccess','Notification Send Successfully.');      


        } catch (Exception $e)
        {
            Log::error("UserController  - sendCustomNotification ".$e->getMessage());
            return false;
        }
    }


    /*
        Author : Sridhar On 12 feb 2018 12.28  
    */
    static function sendEmailNotification($arrObjects)
    {      
        foreach ($arrObjects as $key => $obj) {
          if(!empty($obj->email))
          {
            Mail::queue('emails.notification.custom', array('html'=> $obj->html), function($message) use ($obj)
                                {   
                                    $message->subject($obj->subject);        
                                    $message->to($obj->email);                                                                                   
                                    $message->cc(CustomClass::$BackupId);      
                                });     
          }
        }
    }



    public function viewCertificate()
    {
        $user_id = Auth::User()->user_id;        
        $selected_abs = DB::table("certificate_2018")->where("is_present",1)->where("is_best",0)->where("user_id",$user_id)->get();
        $best_paper= [];
        $best_paper = DB::table("certificate_2018")->where("is_present",1)->where("is_best",1)->where("user_id",$user_id)->get();
       
        return View::make('certificate')->with('selected_abs',$selected_abs)->with('best_paper',$best_paper);
    }


   // Certificate Participation
    public function getCertificateDownload($id)
    {
        //PDF file is stored under project/public/download/info.pdf
        $id = urldecode(Helper::decrypt($id));        
        $certificate  = DB::table("certificate_2018")->find($id); 
        if(isset($certificate) && $certificate->is_present==1)
        {
            if($certificate->is_best ==1)
            {
                $file= public_path(). "/Certificate2018/BestPaper/".$certificate->cert_name;    
            }
            else
            {
                $file= public_path(). "/Certificate2018/Participation/".$certificate->cert_name;    
            }

            $headers = array(
                  'Content-Type: application/pdf',
                );
            return Response::download($file,$certificate->cert_name, $headers);
        }
        else
        {
            return Redirect::to('/');
        }
    }


public function Commitment()
        {
            try
            {
                
                $user_id  = Auth::user()->user_id;
                $order_by = 'order by sess_date, start_time,hall';

                $result = User::usp_get_data_for_agenda_mailer($user_id,$order_by);
                $users      = $result['users'];
                $abstracts  = $result['abstracts'];
                // $abs_users  = $result['abs_users'];

                $abstract = [];
                foreach ($abstracts as $key => $abs) 
                {
                    $abstract[$abs->user_id][] = $abs;
                }
                
                foreach ($users as $key => $user) 
                {
                    $name  = $user->name;
                    $email = $user->email;

                    $userID  = $user->user_id;
                    $subject = Subject::$Commitment;
                    // $sub     = $name . " - " . $subject;

                    $count  = 0;
                    $status = '';
                    
                 
                    try
                    {
                        if(isset($abstract[$userID]))
                        {
                            $mail_abs = [];
                            foreach ($abstract[$userID] as $abskey => $absvalue) 
                            {
                                $obj = new stdClass();

                                 
                                $date       = null;
                                $start_time = null;
                                $end_time   = null;
                                $hall       = null;
                                if((isset($absvalue->sess_date)) && !(empty($absvalue->sess_date)))
                                {
                                    $date  = date('d/m/Y',strtotime($absvalue->sess_date)).' | ';
                                }
                                if((isset($absvalue->start_time)) && !(empty($absvalue->start_time)))
                                {
                                    $start_time  = date('H:i',strtotime($absvalue->start_time)).' - ';
                                }
                                if((isset($absvalue->end_time)) && !(empty($absvalue->end_time)))
                                {
                                    $end_time  = date('H:i',strtotime($absvalue->end_time)).' @ ';
                                }
                                if((isset($absvalue->hall)) && !(empty($absvalue->hall)))
                                {
                                    $hall  = 'Hall: '. $absvalue->hall;
                                }
                                
                                $obj->venue   = $date.$start_time.$end_time .$hall;
                                $obj->role   = $absvalue->t_role;
                                $obj->avcode = $absvalue->av_code;

                                if($absvalue->abs_type == 'GP')
                                {
                                    $obj->abs_no  = '<a href="'. URL::to('/').'/viewabstract?abs_type='
                                                    . $absvalue->abs_type .'&abs_no='.$absvalue->abs_no.'" 
                                                     title="View" target="_blank">'.$absvalue->abs_type.''.$absvalue->abs_no
                                                    .'</a>';
                                    $obj->session  = '<a href="'. URL::to('/').'/viewabstract?abs_type='
                                                    . $absvalue->abs_type .'&abs_no='.$absvalue->abs_no.'" 
                                                     title="View" target="_blank">'.$absvalue->abs_type.''.$absvalue->abs_no
                                                    .' - '.$absvalue->title   .'</a>';
                                    // $obj->session = $absvalue->title;
                                }
                                else
                                {
                                    
                                    if(($absvalue->role == 'FP') || ($absvalue->role == 'PP')|| ($absvalue->role == 'IC') || 
                                        ($absvalue->role == 'VT'))
                                    {
                                        
                                        $obj->abs_no  = '<a href="'. URL::to('/').'/viewabstract?abs_type='
                                                    . $absvalue->abs_type .'&abs_no='.$absvalue->abs_no.'" 
                                                     title="View" target="_blank">'.$absvalue->abs_type.''.$absvalue->abs_no.'</a>';
                                        if($absvalue->role == 'PP')
                                        {
                                            $obj->session = '<a href="'. URL::to('/').'/viewabstract?abs_type='
                                                     . $absvalue->abs_type .'&abs_no='.$absvalue->abs_no.'" 
                                                      title="View" target="_blank">'.$absvalue->abs_type.''.$absvalue->abs_no
                                                      .' - Physical Poster Judgement - '.$absvalue->title.'</a>';
                                            //$obj->session = 'Physical Poster Judgement - '.$absvalue->title;
                                        }
                                        else
                                        {

                                            $obj->session = '<a href="'. URL::to('/').'/viewabstract?abs_type='
                                                     . $absvalue->abs_type .'&abs_no='.$absvalue->abs_no.'" 
                                                      title="View" target="_blank">'.$absvalue->abs_type.''.$absvalue->abs_no
                                                      .' - '.$absvalue->title.'</a>';
                                            //$obj->session = $absvalue->title;
                                        }
                    
                                    }
                                    elseif($absvalue->role == 'Key note address')
                                    {
                                        $obj->abs_no  = null;
                                        $obj->session = $absvalue->title;
                                        $obj->link = null;
                                    }
                                    else
                                    {
                                        $obj->abs_no  = null;
                                        if($absvalue->abs_type == 'PP')
                                        {
                                            // $obj->session = 'Physical Poster - '.$absvalue->category.' ('.$absvalue->role.')';
                                            $obj->session = 'Physical Poster - '.$absvalue->name_in_grid;
                                        }
                                        else if($absvalue->abs_type == 'FP')
                                        {
                                            // $obj->session = $absvalue->name_in_grid.' ('.$absvalue->role.')';
                                            $obj->session =  'Free Paper - '. $absvalue->name_in_grid;
                                        }
                                        else if($absvalue->abs_type == 'PPP')
                                        {
                                          // $obj->session = $absvalue->name_in_grid.' ('.$absvalue->role.')';
                                          $obj->session =  'Poster Podium Presentation - '. $absvalue->name_in_grid;
                                        }
                                        else
                                        {
                                            // $obj->session = $absvalue->name_in_grid.' ('.$absvalue->role.')';
                                            $obj->session =  $absvalue->name_in_grid;
                                        }
                                        $obj->link = null;
                                    }
                                }
                                $obj->category = $absvalue->category;
                                $key = null;
                                if($obj->abs_no  == null || empty($obj->abs_no))
                                {
                                    $key = $obj->venue.$obj->category;
                                }
                                else
                                {
                                    $key = $obj->venue.$obj->abs_no;
                                }
                                
                               $mail_abs[$key]  = $obj;
                            }
                            
                                 return View::make('commitment')->with('user',$user)
                                                                                 ->with('name',$name)
                                                                                 ->with('mail_abs',$mail_abs)
                                                                                 ->with('userID',$userID);
                          
                          
                        }
                        else
                        {
                            Log::info("abstracts empty : " . $userID);
                        }
                    }
                    catch(Exception $e)
                    {
                        Log::error('Mail Error user_id : '. $userID . ' - '. $e->getMessage());
                        echo $e->getMessage();
                    }
                    
                }
            }
            catch (Exception $e) 
            {
                Log::error('UserController - > Commitment' . $e->getMessage());
               // echo $e->getMessage();
            }
        }
        
        
        /*Sridhar On 15 Jun 2020 @ 10:57 PM */
        public function viewCreditPoints()
        {    
            $user_id = Input::get('user_id');
            if(!(intval($user_id)>0))
            {
                $user_id = Auth::User()->user_id;    
            }
            
            $result_2019_db = DB::select("call usp_get_2019_credit_points($user_id)");
            $result_2020_db = DB::select("call usp_get_2020_credit_points($user_id)");
            $result_2021_db = DB::select("call usp_get_2021_credit_points($user_id)");
            $result_2022_db = DB::select("call usp_get_2022_credit_points($user_id)");
            $result_current_year = DB::select("call usp_get_current_year_credit_points($user_id)");


            $list_AAC = UploadCreditPoint::where('user_id',$user_id)->where('title', 'AIOC 2019, Indore')->get();
            $list_IJO = UploadCreditPoint::where('user_id',$user_id)->where('title', 'IJO')->get();
            $list_CME = UploadCreditPoint::where('user_id',$user_id)->where('title', 'CME/PPP')->get();
            $list_ARC = UploadCreditPoint::where('user_id',$user_id)->where('title', 'ARC Sessions/LDP Sessions')->get();
            

            $list_AAC_2020 = UploadCreditPoint::where('user_id',$user_id)->where('title', 'AIOC 2020, Gurugram')->get();
            $list_IJO_2020 = UploadCreditPoint::where('user_id',$user_id)->where('title', 'IJO 2020')->get();
            $list_CME_2020 = UploadCreditPoint::where('user_id',$user_id)->where('title', 'CME/PPP 2020')->get();
            $list_ARC_2020 = UploadCreditPoint::where('user_id',$user_id)->where('title', 'ARC Sessions/LDP Sessions 2020')->get();
            
            $list_AAC_2021 = UploadCreditPoint::where('user_id',$user_id)->where('title', 'AIOC 2021')->get();
            $list_IJO_2021 = UploadCreditPoint::where('user_id',$user_id)->where('title', 'IJO 2021')->get();
            $list_CME_2021 = UploadCreditPoint::where('user_id',$user_id)->where('title', 'CME/PPP 2021')->get();
            $list_ARC_2021 = UploadCreditPoint::where('user_id',$user_id)->where('title', 'ARC Sessions/LDP Sessions 2021')->get();
            
            
            $list_AAC_2022 = UploadCreditPoint::where('user_id',$user_id)->where('title', 'AIOC 2022')->get();
            $list_IJO_2022 = UploadCreditPoint::where('user_id',$user_id)->where('title', 'IJO 2022')->get();
            $list_CME_2022 = UploadCreditPoint::where('user_id',$user_id)->where('title', 'CME/PPP 2022')->get();
            $list_ARC_2022 = UploadCreditPoint::where('user_id',$user_id)->where('title', 'ARC Sessions/LDP Sessions 2022')->get();
            
            
             
           $custom_points_db = CustomCreditPoint::where('user_id',$user_id)->get();

            $custom_points_2019 =[];
            $custom_points_2020 =[];
            $custom_points_2021 =[];
            $custom_points_2022 =[];
           
            foreach ($custom_points_db as $key => $value)
           {
                if($value->year  == 2019)
                {
                    $custom_points_2019[$value->credit_points_title] = $value;    
                }
                else if($value->year  == 2020)
                {
                    $custom_points_2020[$value->credit_points_title] = $value;    
                }
                else if($value->year  == 2021)
                {
                    $custom_points_2021[$value->credit_points_title] = $value;    
                }
                else if($value->year  == 2022)
                {
                    $custom_points_2022[$value->credit_points_title] = $value;    
                }
                
           }
           $result_2019 = [];
           foreach ($result_2019_db as $key => $value)
           {
                $result_2019[$value->cp_id] = $value;
           }
           
           $result_2020 = [];
           foreach ($result_2020_db as $key => $value)
           {
                $result_2020[$value->cp_id] = $value;
           }
           
           $result_2021 = [];
           foreach ($result_2021_db as $key => $value)
           {
                $result_2021[$value->cp_id] = $value;
           }
           $result_2022 = [];
           foreach ($result_2022_db as $key => $value)
           {
                $result_2022[$value->cp_id] = $value;
           }
           
            return View::make('credit_points')->with('result_2019',$result_2019)
                        ->with('result_2020',$result_2020)
                        ->with('result_2021',$result_2021)
                        ->with('result_2022',$result_2022)
                        ->with('result_current_year',$result_current_year)
                        ->with('user_id',$user_id)
                        ->with('list_AAC',$list_AAC)
                        ->with('list_IJO',$list_IJO)
                         ->with('list_CME',$list_CME)
                         ->with('list_ARC',$list_ARC)
                         ->with('list_AAC_2020',$list_AAC_2020)
                        ->with('list_IJO_2020',$list_IJO_2020)
                         ->with('list_CME_2020',$list_CME_2020)
                         ->with('list_ARC_2020',$list_ARC_2020)
                         ->with('list_AAC_2021',$list_AAC_2021)
                        ->with('list_IJO_2021',$list_IJO_2021)
                         ->with('list_CME_2021',$list_CME_2021)
                         ->with('list_ARC_2021',$list_ARC_2021)
                          ->with('list_AAC_2022',$list_AAC_2022)
                        ->with('list_IJO_2022',$list_IJO_2022)
                         ->with('list_CME_2022',$list_CME_2022)
                         ->with('list_ARC_2022',$list_ARC_2022)
                         ->with('custom_points_2019',$custom_points_2019)
                         ->with('custom_points_2020',$custom_points_2020)
                         ->with('custom_points_2021',$custom_points_2021)
                        ->with('custom_points_2022',$custom_points_2022) ;
        }
        
        
        public function responseAWSCreditPoints()
        {    
            
            try {

            
                $user_id = Input::get('user_id'); // user_id 
                $title = Input::get('title');
                $bucket = Input::get('bucket'); // s3 bucket name 
                $key = Input::get('key'); //s3 file path with file name  
                $etag = Input::get('etag'); // etag is uniqu file ids 
                $key_arr =  explode('/', $key);

                $msg = '';

                if($key_arr[0] == "AnnualAIOSConference2022")
                {
                    $title="AIOC 2022";

                }
                else if($key_arr[0] == "IJO2022")
                {
                    $title="IJO 2022";
                }
                else if($key_arr[0] == "CME-PPP-2022")
                {
                    $title="CME/PPP 2022";
                }
                else if($key_arr[0] == "ARC-LDP-2022")
                {
                    $title="ARC Sessions/LDP Sessions 2022";
                }
                else if($key_arr[0] == "AnnualAIOSConference2021")
                {
                    $title="AIOC 2021";

                }
                else if($key_arr[0] == "IJO2021")
                {
                    $title="IJO 2021";
                }
                else if($key_arr[0] == "CME-PPP-2021")
                {
                    $title="CME/PPP 2021";
                }
                else if($key_arr[0] == "ARC-LDP-2021")
                {
                    $title="ARC Sessions/LDP Sessions 2021";
                }
                 if($key_arr[0] == "AnnualAIOSConference2020")
                {
                    $title="AIOC 2020, Gurugram";

                }
                else if($key_arr[0] == "IJO2020")
                {
                    $title="IJO 2020";
                }
                else if($key_arr[0] == "CME-PPP-2020")
                {
                    $title="CME/PPP 2020";
                }
                else if($key_arr[0] == "ARC-LDP-2020")
                {
                    $title="ARC Sessions/LDP Sessions 2020";
                }
                else if($key_arr[0] == "AnnualAIOSConference2019")
                {
                    $title="AIOC 2019, Indore";

                }
                else if($key_arr[0] == "IJO")
                {
                    $title="IJO";
                }
                else if($key_arr[0] == "CME-PPP")
                {
                    $title="CME/PPP";
                }
                else if($key_arr[0] == "CME-PPP")
                {
                    $title="CME/PPP";
                }
                else if($key_arr[0] == "ARC-LDP")
                {
                    $title="ARC Sessions/LDP Sessions";
                }



                if(empty($etag) || empty($bucket))
                {
                    return Redirect::to("credit_points_2019?user_id=".$user_id)
                                ->with('msgError',AppMessage::$GENERAL_ERROR);    
                }

                $ucp =  UploadCreditPoint::where('user_id',$user_id)->where('title',$title)->first();

                if($ucp == null)
                {
                   $ucp =  new UploadCreditPoint();    
                }

               $ucp->user_id = $user_id;
               $ucp->title = $title;
               $ucp->bucket = $bucket;
               $ucp->key = $key;
               $ucp->etag = $etag;
               $ucp->is_verified = null;

               $ucp->save();

               $msg = 'File successfully uploaded.  The AIOS scientific committee team shall validate your profile and add the credit points in about 3 working days';
               
               

                return Redirect::to("credit_points?user_id=".$user_id)
                                    ->with('msgSuccess',$msg);    
            } catch (Exception $e) {
                Log::error('UserController - > responseAWSCreditPoints' . $e->getMessage());
               return Redirect::to("credit_points_2020?user_id=".$user_id)
                                ->with('msgError',AppMessage::$GENERAL_ERROR);      
            }
            
            

            
        }
        

        /*Sridhar On 21 Apr 2020 @ 12:09 PM */
        public function viewCreditPoints2020()
        {    
            $user_id = Input::get('user_id');
            if(!(intval($user_id)>0))
            {
                $user_id = Auth::User()->user_id;    
            }
            
            $result_2019_db = DB::select("call usp_get_2019_credit_points($user_id)");
            $result_2020_db = DB::select("call usp_get_2020_credit_points($user_id)");
            $result_current_year = DB::select("call usp_get_current_year_credit_points($user_id)");


            $list_AAC = UploadCreditPoint::where('user_id',$user_id)->where('title', 'AIOC 2019, Indore')->get();
            $list_IJO = UploadCreditPoint::where('user_id',$user_id)->where('title', 'IJO')->get();
            $list_CME = UploadCreditPoint::where('user_id',$user_id)->where('title', 'CME/PPP')->get();
            $list_ARC = UploadCreditPoint::where('user_id',$user_id)->where('title', 'ARC Sessions/LDP Sessions')->get();
            

            $list_AAC_2020 = UploadCreditPoint::where('user_id',$user_id)->where('title', 'AIOC 2020, Gurugram')->get();
            $list_IJO_2020 = UploadCreditPoint::where('user_id',$user_id)->where('title', 'IJO 2020')->get();
            $list_CME_2020 = UploadCreditPoint::where('user_id',$user_id)->where('title', 'CME/PPP 2020')->get();
            $list_ARC_2020 = UploadCreditPoint::where('user_id',$user_id)->where('title', 'ARC Sessions/LDP Sessions 2020')->get();
             
           $custom_points_db = CustomCreditPoint::where('user_id',$user_id)->get();

            $custom_points_2019 =[];
            $custom_points_2020 =[];
           
            foreach ($custom_points_db as $key => $value)
           {
                if($value->year  == 2019)
                {
                    $custom_points_2019[$value->credit_points_title] = $value;    
                }
                else if($value->year  == 2020)
                {
                    $custom_points_2020[$value->credit_points_title] = $value;    
                }
                
           }
           $result_2019 = [];
           foreach ($result_2019_db as $key => $value)
           {
                $result_2019[$value->cp_id] = $value;
           }
           
           $result_2020 = [];
           foreach ($result_2020_db as $key => $value)
           {
                $result_2020[$value->cp_id] = $value;
           }
           
            return View::make('credit_points_2020')->with('result_2019',$result_2019)
                        ->with('result_2020',$result_2020)
                        ->with('result_current_year',$result_current_year)
                        ->with('user_id',$user_id)
                        ->with('list_AAC',$list_AAC)
                        ->with('list_IJO',$list_IJO)
                         ->with('list_CME',$list_CME)
                         ->with('list_ARC',$list_ARC)
                         ->with('list_AAC_2020',$list_AAC_2020)
                        ->with('list_IJO_2020',$list_IJO_2020)
                         ->with('list_CME_2020',$list_CME_2020)
                         ->with('list_ARC_2020',$list_ARC_2020)
                         ->with('custom_points_2019',$custom_points_2019)
                         ->with('custom_points_2020',$custom_points_2020);
        }
        
        
        
        
        
        public function responseAWSCreditPoints2020()
        {    
            
            try {

            
                $user_id = Input::get('user_id'); // user_id 
                $title = Input::get('title');
                $bucket = Input::get('bucket'); // s3 bucket name 
                $key = Input::get('key'); //s3 file path with file name  
                $etag = Input::get('etag'); // etag is uniqu file ids 
                $key_arr =  explode('/', $key);

                $msg = '';


                if($key_arr[0] == "AnnualAIOSConference2020")
                {
                    $title="AIOC 2020, Gurugram";

                }
                else if($key_arr[0] == "IJO2020")
                {
                    $title="IJO 2020";
                }
                else if($key_arr[0] == "CME-PPP-2020")
                {
                    $title="CME/PPP 2020";
                }
                else if($key_arr[0] == "ARC-LDP-2020")
                {
                    $title="ARC Sessions/LDP Sessions 2020";
                }


                if(empty($etag) || empty($bucket))
                {
                    return Redirect::to("credit_points_2019?user_id=".$user_id)
                                ->with('msgError',AppMessage::$GENERAL_ERROR);    
                }

                $ucp =  UploadCreditPoint::where('user_id',$user_id)->where('key',$key)->first();

                if($ucp == null)
                {
                   $ucp =  new UploadCreditPoint();    
                }

               $ucp->user_id = $user_id;
               $ucp->title = $title;
               $ucp->bucket = $bucket;
               $ucp->key = $key;
               $ucp->etag = $etag;

               $ucp->save();

               $msg = 'File successfully uploaded.  The AIOS scientific committee team shall validate your profile and add the credit points in about 3 working days';
               
               

                return Redirect::to("credit_points_2020?user_id=".$user_id)
                                    ->with('msgSuccess',$msg);    
            } catch (Exception $e) {
                Log::error('UserController - > responseAWSCreditPoints2020' . $e->getMessage());
               return Redirect::to("credit_points_2020?user_id=".$user_id)
                                ->with('msgError',AppMessage::$GENERAL_ERROR);      
            }
            
            

            
        }
        
        
        

        /*Sridhar On 05 Apr 2019 @ 4:06 PM */
        public function viewCreditPoints2019()
        {    
            $user_id = Input::get('user_id');
            if(!(intval($user_id)>0))
            {
                $user_id = Auth::User()->user_id;    
            }
            
            $result_2019_db = DB::select("call usp_get_2019_credit_points($user_id)");
            $result_2020_db = DB::select("call usp_get_2020_credit_points($user_id)");
            $result_current_year = DB::select("call usp_get_current_year_credit_points($user_id)");



            $list_AAC = UploadCreditPoint::where('user_id',$user_id)->where('title', 'AIOC 2019, Indore')->get();
            //$list_AAC_20 = UploadCreditPoint::where('user_id',$user_id)->where('title', 'AIOC 2020, GURUGRAM')->get();
            $list_IJO = UploadCreditPoint::where('user_id',$user_id)->where('title', 'IJO')->get();
            $list_CME = UploadCreditPoint::where('user_id',$user_id)->where('title', 'CME/PPP')->get();
            $list_ARC = UploadCreditPoint::where('user_id',$user_id)->where('title', 'ARC Sessions/LDP Sessions')->get();
             
           $custom_points_db = CustomCreditPoint::where('user_id',$user_id)->get();

            $custom_points_2019 =[];
            $custom_points_2020 =[];
           
            foreach ($custom_points_db as $key => $value)
           {
                if($value->year  == 2019)
                {
                    $custom_points_2019[$value->credit_points_title] = $value;    
                }
                else if($value->year  == 2020)
                {
                    $custom_points_2020[$value->credit_points_title] = $value;    
                }
                
           }
           $result_2019 = [];
           foreach ($result_2019_db as $key => $value)
           {
                $result_2019[$value->cp_id] = $value;
           }
           
           $result_2020 = [];
           foreach ($result_2020_db as $key => $value)
           {
                $result_2020[$value->cp_id] = $value;
           }
           
            return View::make('credit_points_2019')->with('result_2019',$result_2019)
                        ->with('result_2020',$result_2020)
                        ->with('result_current_year',$result_current_year)
                        ->with('user_id',$user_id)
                        ->with('list_AAC',$list_AAC)
                        ->with('list_IJO',$list_IJO)
                         ->with('list_CME',$list_CME)
                         ->with('list_ARC',$list_ARC)
                         ->with('custom_points_2019',$custom_points_2019)
                         ->with('custom_points_2020',$custom_points_2020);
        }


        public function responseAWSCreditPoints2019()
        {    
            
            try {

            
                $user_id = Input::get('user_id'); // user_id 
                $title = Input::get('title');
                $bucket = Input::get('bucket'); // s3 bucket name 
                $key = Input::get('key'); //s3 file path with file name  
                $etag = Input::get('etag'); // etag is uniqu file ids 
                $key_arr =  explode('/', $key);

                $msg = '';


                if($key_arr[0] == "AnnualAIOSConference2019")
                {
                    $title="AIOC 2019, Indore";

                }
                else if($key_arr[0] == "IJO")
                {
                    $title="IJO";
                }
                else if($key_arr[0] == "CME-PPP")
                {
                    $title="CME/PPP";
                }
                else if($key_arr[0] == "CME-PPP")
                {
                    $title="CME/PPP";
                }
                else if($key_arr[0] == "ARC-LDP")
                {
                    $title="ARC Sessions/LDP Sessions";
                }


                if(empty($etag) || empty($bucket))
                {
                    return Redirect::to("credit_points_2019?user_id=".$user_id)
                                ->with('msgError',AppMessage::$GENERAL_ERROR);    
                }

                $ucp =  UploadCreditPoint::where('user_id',$user_id)->where('key',$key)->first();

                if($ucp == null)
                {
                   $ucp =  new UploadCreditPoint();    
                }

               $ucp->user_id = $user_id;
               $ucp->title = $title;
               $ucp->bucket = $bucket;
               $ucp->key = $key;
               $ucp->etag = $etag;

               $ucp->save();

               $msg = 'File successfully uploaded.  The AIOS scientific committee team shall validate your profile and add the credit points in about 3 working days';
               
               

                return Redirect::to("credit_points_2019?user_id=".$user_id)
                                    ->with('msgSuccess',$msg);    
            } catch (Exception $e) {
                Log::error('UserController - > responseAWSCreditPoints2019' . $e->getMessage());
               return Redirect::to("credit_points_2019?user_id=".$user_id)
                                ->with('msgError',AppMessage::$GENERAL_ERROR);      
            }
            
            

            
        }
        
        /******************************* Consent PresentingAuthor *****************************************/ 
        public function ConsentPresentingAuthor($id){
        try {

            $id  = urldecode(Helper::decrypt($id));  
            // var_dump($id);
            // exit();
            $exp = explode(',', $id);
            $author_id    = $exp[0];
            $consent_status_id  = $exp[1];            
            
            $msg = "";

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

        } catch (Exception $e) {
            Log::error('UserController - ConsentPresentingAuthor'.$e->getMessage());
            $msg =AppMessage::$GENERAL_ERROR;
        }
        return View::make("msg")->with('msg',$msg);    
    }
    
    
    public function ConsentConference($yesno_key,$uuid){
        $msg =   "";
        try {

            $user = User::where('uuid',$uuid)->first();
            if(isset($user))
            {
                if($user->AIOC2021SCParticipation == null)
                {
                    $user->AIOC2021SCParticipation = $yesno_key;
                    $user->save();
                    $msg = "Thank you for providing your response.";    
                }
                else
                {
                    $msg = "Your response has already been registered.  Thank you";    
                }
                
            }
            else
            {
                  $msg = "Invalid url";
            }

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


    /******************************* Consent PresentingAuthor *****************************************/ 
    
    
    /******************************* Consent Evaluator *****************************************/ 
        public function consentEvaluator($id){
        try {

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

            $result = DB::select("call usp_consent_evaluator($user_id,$consent_status_id,'".$abs_type."',$section_id)");            
            if(isset($result))
            {
                $msg = $result[0]->msg;    
            }
            else
            {
                $msg = AppMessage::$GENERAL_ERROR;       
            }

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



    public function consentParticipateEvaluator($id){
        try {

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

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

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

    /******************************* Consent Evaluator End *****************************************/ 




//Result Announcement
    public function ResultAnnouncement(){
       
        try {
            $abstracts          = [];
            $abstracts1          = [];
            $selected_list      = [];
            $authors            = [];
            $sessions           = [];
            $sample_mob_nos     = Input::has("sample_mob_nos")?Input::get("sample_mob_nos"):null;           
            $selection_type_id  = Input::has("selection_type")?Input::get("selection_type"):null;
            $name_in_grid_id    = Input::has("name_in_grid_id")?Input::get("name_in_grid_id"):null;
            $select_to          = Input::has("select_to")?Input::get("select_to"):null;
            $abs_ids            = Input::get('abs_ids');
            $checked_ids        = Input::get('chk');
            $sms_template       = Input::has("sms_template")?Input::get("sms_template"):null;
            $status_id          = 2;





            $selection_types_db     = Abstracts::join('selection_type','selection_type.selection_type_id','=','abstracts.selection_type_id')->whereIN('abstracts.abs_type',['FP','VT'])->distinct()->select('selection_type.selection_type_id','selection_type.type')->get();


            if(isset($selection_type_id) && intval($selection_type_id) > 0)
            {
                $sessions =Abstracts::whereNotNull('name_in_grid_id')
                                                    ->where('selection_type_id',$selection_type_id)
                                                   ->orderBy('name_in_grid','asc')
                                                   ->lists('name_in_grid','name_in_grid_id');


            }




            if(isset($name_in_grid_id))
            {
                $res1_order_by = 'Order by category_display_name,sno';
                $res2_order_by = 'Order by author_id desc';

                $result    = Abstracts::usp_get_abstracts_print(null,null,null,null,null,$selection_type_id,$status_id,null,null,$res1_order_by,$res2_order_by,null,null,null,null,null,$name_in_grid_id);
                $abstracts = $result["abstracts"];
                $authors   = $result["authors"]; 

                // var_dump($abstracts);
                // exit();


               
                // foreach ($abstracts_db as $key => $value) {
                //     if($value->name_in_grid_id == $name_in_grid_id )
                //         $abstracts[] =  $value;
                // }

                $abs_type      = 'KAFP';
                $res1_order_by = 'Order by abs_no';

                $result     = Abstracts::usp_get_abstracts_print(null,null,$abs_type,null,null,null,null,null,null,$res1_order_by,null,null,null);
                $abstracts1 = $result["abstracts"];  


                $selected_list = [];

                
                    foreach ($abstracts as $key => $value) {
                        if($select_to =="Semi Final" && $value->is_semi_final == 1)
                        {
                            $selected_list[$value->abs_id] =$value->abs_id;
                        }
                        elseif($select_to =="Final" && $value->is_final == 1)
                        {
                            $selected_list[$value->abs_id] =$value->abs_id;
                        }
                    }
                    foreach ($abstracts1 as $key => $value1) {
                        if($select_to =="Semi Final" && $value1->is_semi_final == 1)
                        {
                            $selected_list[$value1->abs_id] =$value1->abs_id;
                        }
                        elseif($select_to =="Final" && $value->is_final == 1)
                        {
                            $selected_list[$value1->abs_id] =$value1->abs_id;
                        }
                    }



            }



            // if(Input::get("go"))
            // {

            // }
            // else
            if(Input::get("btnsubmit"))
            {   
                

            // var_dump($checked_ids);




                $abs_list = Abstracts::whereIN('abs_id',$abs_ids)->get();

                foreach ($abs_list as $key => $abs) {
                    $can_save = false;
                    if($select_to =="Semi Final")
                    {  
                       // echo " enter " . $abs->abs_id;
                        // if(isset($checked_ids[$abs->abs_id]))
                        // {
                        //     echo " fine " . $abs->abs_id;
                        // }
                        if(intval($abs->is_semi_final) < 1 && isset($checked_ids[$abs->abs_id]))
                        {
                            //echo " in " . $abs->abs_id;
                            $can_save = true;
                            $abs->is_semi_final    =1;   
                        }                        
                        elseif (intval($abs->is_semi_final) >0 && !isset($checked_ids[$abs->abs_id]))
                        {
                            $can_save = true;
                            $abs->is_semi_final    =0;    
                        }
                        //echo " out " . $abs->abs_id;
                    }
                    elseif($select_to =="Final")
                    {
                        if(intval($abs->is_semi_final) < 1 && isset($checked_ids[$abs->abs_id]))
                        {
                            $can_save = true;
                            $abs->is_final    =1;   
                        }                        
                        elseif(intval($abs->is_semi_final) >0 && !isset($checked_ids[$abs->abs_id]))
                        {
                            $can_save = true;
                            $abs->is_final    =0;    
                        }
                    }                    
                    if($can_save)                        
                        $abs->save();
                }
                //exit();
                
                Session::flash('msgSuccess', 'Sesssion : '. $sessions[$name_in_grid_id] .' -  '. $select_to .' saved successfully');

            }


            $sms_template = nl2br($sms_template);
            if(isset($sample_mob_nos))
            {
              $sample_mob_nos = explode(',', $sample_mob_nos);
            }
            if(Input::get("btnSMSsample"))
            {
                //SendSMS_RA($sms_template,$select_to,$abs_ids,$is_sample,sample_mob_nos){
                $this->SendSMS_RA($sms_template,$select_to,$checked_ids,1,$sample_mob_nos);
            }
            if(Input::get("btnSMS"))
            {
                //SendSMS_RA($sms_template,$select_to,$abs_ids,$is_sample,sample_mob_nos){
                $this->SendSMS_RA($sms_template,$select_to,$checked_ids,0,$sample_mob_nos);
            }


            
            $selection_types = [];
            foreach ($selection_types_db as $key => $value) {
                $selection_types[$value->selection_type_id] = $value->type;
            }

            return View::make("result_announcement")->with('selection_type_id',$selection_type_id)
                                                    ->with('name_in_grid_id',$name_in_grid_id)
                                                    ->with('selection_types',$selection_types)
                                                     ->with('sessions',$sessions)
                                                     ->with('abstracts',$abstracts)
                                                     ->with('authors',$authors)
                                                     ->with('abstracts1',$abstracts1)
                                                     ->with('selected_list',$selected_list);    

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

     }

     //result_announcement SMS
     public function SendSMS_RA($sms_template,$select_to,$abs_ids,$is_sample,$sample_mob_nos){


        $res1_order_by = 'Order by category_display_name,sno';
        $res2_order_by = 'Order by author_id desc';
        $role_ids = '13,32,33,34,35,36';
        $status_id = 2;

        $result    = Abstracts::usp_get_abstracts_print($role_ids,null,null,null,implode(',', $abs_ids),null,$status_id,null,null,$res1_order_by,$res2_order_by,null,null,null,null,null,null);
        $abstracts_db = $result["abstracts"];
        $authors   = $result["authors"]; 

        $abstracts= [];        
        foreach ($abstracts_db as $key => $value) {
            $abstracts[$value->abs_id] = $value;
        }

        $sms_data = [];
        foreach ($authors as $key => $item) {

            $title = "";            
            if(empty($item->abs_no))
                $title=  strtoupper($item->title);
            else
                $title= strtoupper($item->abs_type.$item->abs_no .' - '. $item->title);

            $session  = "";           
           if($select_to =="Semi Final")
                $session = $abstracts[$item->abs_id]->name_in_grid;
            elseif($select_to =="Final")
                $session = $abstracts[$item->abs_id]->category_display_name;

            $tags = array(
                'NAME'          => isset($item->name)?$item->name:'',
                'MEMBERSHIPNO'  => isset($item->membership_no)?$item->membership_no:'',             
                'TITLE'         => $title,
                'SESSION'       => $session,
                'ROLE'          => isset($item->role)?$item->role:'', 
                'SELECTIONTYPE' => $abstracts[$item->abs_id]->selection_type,
            );


            $message =     Helper::merge_tag($sms_template,$tags);

            $objsms = new stdClass();              
            //$objsms->to   = [$item->mobile];  
            $objsms->to   = $sample_mob_nos;
            $objsms->message  = str_replace('<br />', '%0a', $message);
            array_push($sms_data, $objsms); 

            //if is sample sms data vairable frist data one set to sms 
            if($is_sample==1)
            {
                $objsms = $sms_data[0];  
                $objsms->to   = $sample_mob_nos;                    
                $sms_data = [];
                array_push($sms_data, $objsms); 
                
            }            
            

        }



        var_dump($sms_data);
        exit();
            

        // if(count($sms_data)>0)
        // {
        //     try {
        //         Helper::smsBulk_v2($sms_data, "RESULTANNOUNCEMENT");             
        //     } catch (Exception $e) {
        //         echo "SendSMS_RA - sendSMS : " . $e->getMessage();            
        //         Log::error('UserController - SendSMS_RA -  sendSMS : '.$e->getMessage());                   
        //     }
        // }
        

    }
    public function ResultAnnouncementScreen()
    {       
        try {

        $abs_id = Input::get('abs_id');


        $res1_order_by = 'Order by category_display_name,sno';
        $res2_order_by = 'Order by author_id desc';
        $role_ids = '13,32,33,34,35,36';
        $status_id = 2;


        $result    = Abstracts::usp_get_abstracts_print($role_ids,null,null,null,$abs_id,null,$status_id,null,null,$res1_order_by,$res2_order_by,null,null,null,null,null,null);
        $abstracts = $result["abstracts"];
        $authors   = $result["authors"]; 







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

     }
     
     
     /************************* Opt-In IJO *************************/

 public function SendEmailtoIJO($is_sample)
    {
        try
        {
            if($is_sample == 1)
            {
                $users = DB::table("users as u")
                            ->leftJoin("users_memberships as um", "um.user_id", "=", "u.user_id")
                            ->whereNull("u.deleted_at")
                            ->whereNull("um.deleted_at")
                            // ->where('um.user_type_id',1)
                            ->whereIn('u.user_id',[4250])
                            ->get();

                  var_dump($users);          
            }
            else
            {
                 $users = DB::table("users as u")
                        ->Join("users_memberships as um", "um.user_id", "=", "u.user_id")
                        // ->whereNull("u.deleted_at")
                        // ->where(DB::raw('date(u.ijo_mail_sent_at)'),'<',date('Y-m-d'))
                        ->whereNull("u.ijo_mail_sent_at")
                        ->whereIn('um.user_type_id',[2,3])
                        ->whereNull('is_removed_for_ijo_mail')
                        ->whereNull('opt_in_ijo')
                        ->limit(200)
                        ->get();
                            
                // var_dump($users); 
                // exit();            
                
            }
            
            
            if(isset($users) && count($users)>0)
            {
                // $mandrill =  new Mandrill(CustomClass::$Mandrill_Key);
                foreach($users as $user)
                {       
                    try
                    {
                        $tmp =User::find($user->user_id);
                        if(isset($tmp))
                        {
                            $tmp->ijo_mail_sent_at = date('Y-m-d H:i');
                            $tmp->save();
                            $email = $user->email;
                            $subject = "Important Information from Indian Journal of Ophthalmology - Must Opt-in by Oct 1 to Receive your Hard Copy";
                            // if(isset($user->first_name) && !empty($user->first_name))
                            // {
                            //     $full_name = (isset($user->prefix)?$user->prefix.' ':'Dr ') . (isset($user->last_name)?$user->last_name.' ' :'') . (isset($user->first_name)?$user->first_name:'');    
                            //     $subject = $full_name .', Reminder 7: to verify and confirm your profile (as on '. date('d/m/Y H:i').')';
                            // }
                            // else
                            // {
                                
                            //     $subject = 'Dr., Reminder 7: to verify and confirm your profile (as on '. date('d/m/Y H:i').')';
                            // }
                            if(isset($email) && !empty($email))
                            {
                                $mailContent = array( "u" => $user);
                                // $html        = View::make("live.emails.profile_req_update")->with($mailContent)->render();
                                
                                // $message = array(
                                //     'html' => $html,
                                //     'text' => '',
                                //     'subject' => $subject,
                                //     'from_email' => 'support@moseye.org',
                                //     'from_name' => 'MOS Profile Update Drive',
                                //     'to' => array(
                                //         array(
                                //             'email' => $email,
                                //             'name' => '',
                                //             'type' => 'to'
                                //         )
                                //     ),
                                //     // 'headers' => array('Reply-To' => 'sridharan.r@numerotec.com'),
                                //     // 'bcc_address' => 'sridharan.r@numerotec.com',
                                 
                                // );
                                // $async = true;
                                // $ip_pool = '';
                                // $send_at = '';
                                // $result = $mandrill->messages->send($message, $async, $ip_pool, $send_at);
                                
                                Mail::send('emails.opt_in_ijo', $mailContent, function($message) use ($email,$subject,$user) {
                                            $message->from('editorijo@aios.org', 'Dr.Santosh Honavar, Editor , IJO');
                                            $message->to($email)->subject($subject);
                                });
                            }
                        }    
                    } catch (Exception $e)
                    {
                        Log::error("UserController=>SendEmailtoIJO mailsend".$e->getMessage());
                    
                    }
                }
                
                if($is_sample==1)
                {
                    echo ($is_sample==1?"Sample ":"")."Email sent successfully";
                }
                else
                {
                    return Redirect::to('bo/send_mail_to_ijo/'.$is_sample);
                }
            }
            else
            {
                echo ($is_sample==1?"Sample ":"")."Email sent successfully";
            }    
            
            // return Redirect::to('/bo/home')->with("msgSuccess",($is_sample==1?"Sample ":"")."Email sent successfully");
                
            
        }
        catch(Exception $e)
        {
            Log::error('UserController=>SendEmailtoIJO '.$e->getMessage());
            echo $e->getMessage();
        }
    }



    public function OptinIJO($uuid){
        try {
          
            $msg = "";

            $user = User::where('uuid',$uuid)->first();
                      
            if(isset($user))
            {
                $user->ijo_opened_at = date('Y-m-d H:i:s');
                $user->save();
                
                $state = State::find($user->state_id);
                if(isset($state))
                    $user->state_name = $state->state_name;
                    
                return View::make("opt_in_ijo")->with('u',$user);            
            }
            else
            {
                return View::make("ijo_msg")->with('msg',"Invalid url");    
            }

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

    public function ConfirmOptinIJO($key){
        try {

            $id  = urldecode(Helper::decrypt($key));  
            if(isset($id))
            {
               
                $exp = explode('/', $id);

                $user_id    = $exp[0];
                $opt_in     = $exp[1];            
                
                $msg = "";

                $user = User::find($user_id);
                if(isset($user))
                {
                    if(is_null($user->opt_in_ijo))
                    {
                        $user->opt_in_ijo = date('Y-m-d H:i:s');
                        if($user->save())
                        {
                            return View::make("ijo_msg")->with('u',$user);  
                            // $msg = "Your providence has been recorded";
                        }
                        else
                        {
                            $msg = AppMessage::$GENERAL_ERROR;
                        }
                    } 
                    else
                    {
                        $msg = 'Your response has already been recorded on "'. date('d/M/y H:i',strtotime($user->opt_in_ijo)).'"';
                        // $msg = "Your response has already been provided.";
                    }   
                    
                }
                else
                {
                    $msg = AppMessage::$GENERAL_ERROR;  
                }
                
            }
            else
            {
                $msg = "Invalid url";
            }

        } catch (Exception $e) {
            Log::error('UserController - ConfirmOptinIJO'.$e->getMessage());
            $msg =AppMessage::$GENERAL_ERROR;
        }
        return View::make("ijo_msg")->with('msg',$msg);  
    }  
    
    
    //Sridharan.r On 2020-10-01 5:50 PM;
    //send Bulk SMS for IJO
    public function SendSMSIJO($is_sample)
    {
    	try
    	{
    	   if($is_sample == 1)
            {
                $users = DB::table("users as u")
                            ->leftJoin("users_memberships as um", "um.user_id", "=", "u.user_id")
                            ->whereNull("u.deleted_at")
                            ->whereNull("um.deleted_at")
                            // ->where('um.user_type_id',1)
                            ->whereIn('u.user_id',[4250])
                            ->get();

                //   var_dump($users);         
                //   exit();
            }
            else
            {
                 $users = DB::table("users as u")
                        ->Join("users_memberships as um", "um.user_id", "=", "u.user_id")
                        // ->whereNull("u.deleted_at")
                        ->where(DB::raw('date(u.ijo_sms_sent_at)'),'<',date('Y-m-d'))
                        // ->whereNull("u.ijo_sms_sent_at")
                        ->whereIn('um.user_type_id',[2,3])
                        ->whereNull('is_removed_for_ijo_mail')
                        ->whereNull('opt_in_ijo')
                        ->whereNull('ijo_opened_at')
                        ->whereNotNull('mobile')
                        ->limit(2000)
                        ->get();
                            
                // var_dump($users); 
                // exit();            
                
            }
    	    
    	    $userssmsMessages = [];
    	       
                foreach($users as $user)
                {   
                    $tmp = User::find($user->user_id);
                    if(isset($tmp))
                    {
                        $tmp->ijo_sms_sent_at = date('Y-m-d H:i');
                        $tmp->save();
                        
                        if(isset($user->mobile) && !empty($user->mobile))
                        {
                            $link = url('optinijo').'/'.$user->uuid;
                            if(isset($user->first_name) && !empty($user->first_name))
                            {
                                $full_name = (isset($user->prefix)?$user->prefix.' ':'Dr ') . (isset($user->last_name)?$user->last_name.' ' :'') . (isset($user->first_name)?$user->first_name:'');    
                            
                            }
                            else
                            {
                                
                                $full_name = 'Dr.';
                            }
                            
                            $objsms = new stdClass();  
                            $objsms->to   = [$user->mobile];
                            $objsms->message   = "Dear $full_name
Please click $link to opt-in to receive print copy of IJO. Deadline: 3/Oct 10 am.\n
All others will get a complete PDF and online access.\n

Thank you!
Dr Santosh G Honavar,
Editor, IJO"; 
                            
                            array_push($userssmsMessages, $objsms);
                        }    
                        
                    }    
                }
                
                if( count($userssmsMessages)>0)
                {   
                    try {
                            Helper::smsBulk_v2($userssmsMessages, "IJOSMS");             
                    } catch (Exception $e) {
                        echo "sendBulkSMS : " . $e->getMessage();            
                        Log::error('UserController -sendBulkSMS : '.$e->getMessage());                   
                    }
                }
                
               
                
            
                echo ($is_sample==1?"Sample ":"")."SMS sent successfully";
            
        }
    	catch(Exception $e)
    	{
    		Log::error('UserController=>SendSMSIJO '.$e->getMessage());
			echo $e->getMessage();
    	}
    }
    
    
    public function getChangeConference($abs_id){
        try {
          
            $msg = "";

            $abs = Abstracts::where('abs_id',$abs_id)->first();
                      
            if(isset($abs))
            {
                return View::make("conference")->with('abs',$abs);            
            }
            else
            {
                return AppMessage::$GENERAL_ERROR;
            }

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


}

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