$name, 'carbon'=>$carbon ]; if($name=="apply_student_proposal"){ $student =Auth::user(); $data['teacher'] = User::find($req->t_id); $data['student'] = User::find($student->id); $data['proposal']= Proposal::where('student_id',$user->id)->get(); }elseif($name=="update_student_proposal"){ $data['std_proposal'] =StudentProposal::find($req->id); $data['teacher'] = User::find($req->teacher_id); $data['student'] = User::find($req->student_id); $data['proposal']= Proposal::where('student_id',$req->student_id)->get(); $data['years']=range((int)date('Y'), date('Y')+1); }elseif($name=="view_apply_proposal"){ $data['std_proposal'] =StudentProposal::find($req->id); }elseif($name=="view_student_proposal"){ $data['proposal']= Proposal::where( 'student_id',$user->id )->where( 'id',$req->id )->first(); }elseif($name=="add_destination"){ }elseif($name=="add_wishlist"){ $user =Auth::guard('teacher')->user(); $data['refer'] = new ReferUser; }elseif($name=="teacher_invited"){ $data['admin'] =Admin::find($req->id); }elseif($name=="add_doc_required"){ $data['std_proposal']=StudentProposal::find($req->id); }elseif($name=="edit_doc_required"){ $data['requirements']=Requirement::find($req->id); }elseif($name=="landing_register_form"){ $data['countries'] =Country::where('status',1)->orderBy('name','ASC')->get(); //$data['universities'] =University::orderBy('name','ASC')->get(); }elseif($name=="send_email_document_information"){ $data['std_proposal']=StudentProposal::find($req->id); }else $name='default'; return view("modal_pages.{$name}", $data); } public function post(Request $req, $name){ $user=Auth::user(); $carbon=new \Carbon\Carbon; if($name=='apply_student_proposal'){ $new_rules=[ 'proposal_id'=>'required', ]; $validator=\Validator::make($req->all(),$new_rules,[ 'proposal_id.required'=>'Please complete your profile to submit your proposal.', 'startdate'=>'required', 'startmonth'=>'required', ]); if($validator->fails()){ $errors=$validator->errors()->all(); return response(['msg'=>$errors[0]], 422); } $already_exists = StudentProposal::where('student_id',$req->student_id)->where('proposal_submit_status',1)->exists(); if($already_exists){ return response(['msg'=>'Sorry! You already submitted. You can not submit proposal.'],403); } $publication =User::where('id',$req->student_id)->whereNull('is_publication')->exists(); $worK_exp =User::where('id',$req->student_id)->whereNull('is_work_experience')->exists(); $institution =User::where('id',$req->student_id)->whereNull('is_education')->exists(); $score =User::where('id',$req->student_id)->whereNull('is_test_score')->exists(); if($publication || $worK_exp || $institution || $score){ return response(['msg'=>'you didn\'t complete your profile.'],403); } $student_proposal =new StudentProposal; $student_proposal->student_id =$req->student_id; $student_proposal->teacher_id =$req->teacher_id; $student_proposal->proposal_id =$req->proposal_id; $student_proposal->start_year =$req->startdate; $student_proposal->start_month =$req->startmonth; $student_proposal->student_apply_ref =studentRefNoGenerate(); $student_proposal->proposal_submit_status = 1; $student_proposal->submitted_date = now(); $student_proposal->created_by =$req->student_id; $student_proposal->save(); $student_data =User::find($student_proposal->student_id); $student_data->freez_profile =1; $student_data->update(); $teacher =User::find($student_proposal->teacher_id); if($teacher->university_name){ $university =$teacher->university_name; }else{ $university = cn($teacher,'university.name',''); } if($student_data){ $data['name'] = $student_data->first_name.' '.$student_data->last_name; $data['teacher'] = $teacher->first_name.' '.$teacher->last_name; $data['university'] = $university; $data['submission_date'] = $student_data->created_at; $data['receive_email']=$student_data->email; //$data['arn'] = $teacher->ref_no; $user_mail =$student_data->email; $from = 'asraful@revinr.com'; Mail::send('email.student_proposal_email',$data, function ($message) use ($user_mail,$from,$student_proposal) { $message->from($from); $message->to($user_mail)->subject('Apply Ref:' .$student_proposal->student_apply_ref. '- Proposal has been submitted successfully '); }); } $proposal =Proposal::where( 'student_id',$student_proposal->student_id )->where( 'id',$student_proposal->proposal_id )->first(); if($teacher){ $data['name'] = $teacher->first_name.' '.$teacher->last_name; $data['std_name'] = $user->first_name.' '.$user->last_name; $data['proposal_title'] =$proposal->title; $data['date_time']=$student_proposal->submitted_date; $data['receive_email']=$teacher->email; $user_mail =$teacher->email; $from = 'asraful@revinr.com'; Mail::send('email.teacher_proposal_email',$data, function ($message) use ($user_mail,$from) { $message->from($from); $message->to($user_mail)->subject('New Proposal Received - Action Required'); }); } return response(['msg'=>'Proposal send successfully.']); }elseif($name=="update_student_proposal"){ $new_rules=[ 'proposal_id'=>'required', ]; $validator=\Validator::make($req->all(),$new_rules,[ 'proposal_id.required'=>'Please complete your profile to submit your proposal.', 'startdate'=>'required', 'startmonth'=>'required', ]); if($validator->fails()){ $errors=$validator->errors()->all(); return response(['msg'=>$errors[0]], 422); } $already_exists = StudentProposal::where('student_id',$req->student_id)->where('proposal_submit_status',1)->exists(); if($already_exists){ return response(['msg'=>'Sorry! You already submitted. You can not submit proposal.'],403); } $publication =User::where('id',$req->student_id)->whereNull('is_publication')->exists(); $worK_exp =User::where('id',$req->student_id)->whereNull('is_work_experience')->exists(); $institution =User::where('id',$req->student_id)->whereNull('is_education')->exists(); $score =User::where('id',$req->student_id)->whereNull('is_test_score')->exists(); if($publication || $worK_exp || $institution || $score){ return response(['msg'=>'you didn\'t complete your profile.'],403); } $student_proposal =StudentProposal::find($req->id); $student_proposal->proposal_id =$req->proposal_id; $student_proposal->start_year =$req->startdate; $student_proposal->start_month =$req->startmonth; $student_proposal->student_apply_ref =studentRefNoGenerate(); $student_proposal->proposal_submit_status = 1; $student_proposal->submitted_date = now(); $student_proposal->created_by =$req->student_id; $student_proposal->draft_status =0; // Q-Form $student_proposal->update(); $student_data =User::find($student_proposal->student_id); $student_data->freez_profile =1; $student_data->update(); $teacher =User::find($student_proposal->teacher_id); if($teacher->university_name){ $university =$teacher->university_name; }else{ $university = cn($teacher,'university.name',''); } if($student_data){ $data['name'] = $student_data->first_name.' '.$student_data->last_name; $data['teacher'] = $teacher->first_name.' '.$teacher->last_name; $data['university'] = $university; $data['submission_date'] = $student_data->created_at; $data['receive_email']=$student_data->email; //$data['arn'] = $proposal_user->ref_no; $user_mail =$student_data->email; $from = 'asraful@revinr.com'; Mail::send('email.student_proposal_email',$data, function ($message) use ($user_mail,$from,$student_proposal) { $message->from($from); $message->to($user_mail)->subject('Apply Ref:' .$student_proposal->student_apply_ref. '- Proposal has been submitted successfully '); }); } $proposal =Proposal::where( 'student_id',$student_proposal->student_id )->where( 'id',$student_proposal->proposal_id )->first(); if($teacher){ $data['name'] = $teacher->first_name.' '.$teacher->last_name; $data['std_name'] = $student_data->first_name.' '.$student_data->last_name; $data['proposal_title'] =$proposal->title; $data['date_time']=$student_proposal->submitted_date; $data['receive_email']=$teacher->email; $user_mail =$teacher->email; $from = 'asraful@revinr.com'; Mail::send('email.teacher_proposal_email',$data, function ($message) use ($user_mail,$from) { $message->from($from); $message->to($user_mail)->subject('New Proposal Received - Action Required'); }); } return response(['msg'=>'Successfully updated.']); }elseif($name=="add_wishlist"){ $teacher =Auth::guard('teacher')->user(); $validator=\Validator::make($req->all(), [ 'name'=>'required', 'email'=>'required|email|max:255' ]); if($validator->fails()){ $errors=$validator->errors()->all(); return response(['msg'=>$errors[0]], 422); } $is_user_exists=User::where('email',$req->email)->where('user_type',1)->exists(); if($is_user_exists){ $user_notify =User::where('email',$req->email)->where('user_type',1)->first(); // $isUserExists = User::where( // 'email',$req->email // )->where( // 'user_type',2 // )->where(function($q){ // $q->where('sign_up',1)->orWhere('sign_up',0); // })->exists(); // if($isUserExists){ // return response([ // 'msg'=>'Already there is an account associated this email ID. Please login to your account.' // ],403); // } $is_student_proposal_exists =StudentProposal::where( 'teacher_id',$teacher->id )->where( 'student_id',$user_notify->id )->whereIn( 'proposal_status',[1,2,3,4] // 1 =New; 2 =In Review; 3=Push; 4=Hold; )->exists(); if($is_student_proposal_exists){ return response( ['msg'=>'Already pending your proposal. Please wait for approving.'],403 ); }else{ $refer =new ReferUser; $refer->name =$req->name; $refer->email =$req->email; $refer->refer_by =$teacher->id; $refer->teacher_id =$teacher->id; $refer->save(); } }else{ $user_data =new User; $user_data->first_name =$req->name; $user_data->email =$req->email; $user_data->user_type =1; $user_data->status =0; $user_data->register_type =4; // 1=invitation ; 2= landing/wishlish; 3 =q_form ; 4=student-wishlist $user_data->invitation_date =now(); $user_data->wishlist_teacher_id =$teacher->id; $user_data->save(); $refer =new ReferUser; $refer->name =$req->name; $refer->email =$req->email; $refer->refer_by =$teacher->id; $refer->teacher_id =$teacher->id; $refer->save(); $user_notify =User::where('email',$req->email)->where('user_type',1)->first(); $data['name'] = $refer->name; $data['teacher_id'] = $refer->teacher_id; $data['student_id'] = $user_notify->id; $data['std_email'] = $refer->email; $data['teacher'] = $teacher->first_name.' '.$teacher->last_name; $data['arn'] = $teacher->ref_no; $data['designation'] = $teacher->designation; $data['department'] = $teacher->others_department; $data['university'] = $teacher->university_name; $data['receive_email']=$refer->email; $user_mail = $refer->email; $from = 'asraful@revinr.com'; Mail::send('email.wishlist_email',$data, function ($message) use ($user_mail,$from) { $message->from($from); $message->to($user_mail)->subject('Research Admission Platform Sign-Up'); }); } return response( ['msg'=>'Wishlist saved successfully.'] ); }elseif($name=="teacher_invited"){ $admin =Admin::find($req->id); $validator=\Validator::make($req->all(), [ 'name'=>'required', 'email'=>'required|email|max:255' ]); if($validator->fails()){ $errors=$validator->errors()->all(); return response(['msg'=>$errors[0]], 422); } $isUserExists = User::where( 'email',$req->email )->where( 'user_type',2 )->where(function($q){ $q->where('sign_up',1)->orWhere('sign_up',0); })->exists(); if($isUserExists){ return response([ 'msg'=>'Already there is an account associated this email ID.' ],403); }else{ $user_data =new User; $user_data->first_name =$req->name; $user_data->email =$req->email; $user_data->admin_invite_id =$admin->id; $user_data->user_type =2; $user_data->register_type =1; // 1=invitation ; 2=wishlist/landing $user_data->invitation_date =now(); $user_data->save(); $teacher_user =User::where('email',$req->email)->where('user_type',2)->first(); $refer =new ReferUser; $refer->name =$req->name; $refer->email =$req->email; $refer->refer_by =$admin->id; $refer->teacher_id =$teacher_user->id; $refer->save(); $data['name'] = $refer->name; $data['teacher_id'] = $teacher_user->id; $data['applicant_name'] = $admin->first_name.' '.$admin->last_name; $data['email']=$refer->email; $data['receive_email']=$refer->email; $user_mail = $refer->email; $from = 'asraful@revinr.com'; if($req->is_currently_open==1){ Mail::send('email.invitation_to_supervisor_email_with_checked',$data, function ($message) use ($user_mail,$from) { $message->from($from); $message->to($user_mail)->subject('Accepting doctoral applications! Expedite the process with pre-screening proposals'); }); }else{ Mail::send('email.invitation_to_supervisor_email',$data, function ($message) use ($user_mail,$from) { $message->from($from); $message->to($user_mail)->subject('Optimize Your Workflow: Join our Innovative Doctoral Applicant Management Solution'); }); } } $already_invited =ReferUser::where('email',$refer->email)->count(); if($already_invited > 1) { return response( ['msg'=>"Successfully saved. Already invitation send {$already_invited} times."] ); }else{ return response( ['msg'=>'Invitation saved successfully.'] ); } }elseif($name=="add_doc_required"){ $user=auth_user(); $new_rules=[ 'others'=>'required|array', 'others.*.requirement_title'=>'required', ]; $validator=\Validator::make($req->all(),$new_rules,[ 'others.*.requirement_title.required'=>'Please!, fill-up all requirement field.' ]); if($validator->fails()){ $errors=$validator->errors()->all(); return response(['msg'=>$errors[0]], 422); } $std_proposal=StudentProposal::find($req->id); foreach($req->others as $row){ Requirement::create([ 'std_proposal_id'=>$std_proposal->id, 'requirement_title'=>$row['requirement_title'], 'need_upload'=>$row['need_upload'], 'created_by'=>$user->id ]); } return response([ 'msg'=>'Successfully Saved.' ]); }elseif($name=="edit_doc_required"){ $requirements=Requirement::find($req->id); $requirements->requirement_title =$req->requirement_title; $requirements->need_upload =$req->need_upload; $requirements->update(); return response([ 'msg'=>'Successfully updated.' ]); }elseif($name=="landing_register_form"){ $validator=\Validator::make($req->all(), [ 'name'=>'required', 'email'=>'required|email|max:255' ]); if($validator->fails()){ $errors=$validator->errors()->all(); return response(['msg'=>$errors[0]], 422); } $isUserExists = User::where( 'email',$req->email )->where( 'user_type',2 )->where(function($q){ $q->where('sign_up',1)->orWhere('sign_up',0); })->exists(); if($isUserExists){ return response([ 'msg'=>'Already there is an account associated this email ID. Please login to your account.' ],403); }else{ $user_data =new User; $user_data->first_name =$req->name; $user_data->email =$req->email; $user_data->nationality =$req->country_id; $user_data->university_name =$req->university; $user_data->uni_website =$req->uni_website; $user_data->user_type =2; $user_data->register_type =2; // 1=invitation ; 2= landing/wishlish // $user_data->invitation_date =now(); $user_data->save(); $user =User::where('email',$req->email)->where('user_type',2)->first(); $refer =new ReferUser; $refer->name =$req->name; $refer->email =$req->email; $refer->teacher_id =$user->id; $refer->save(); } return response( ['msg'=>'Successfully saved.'] ); } return response(['msg'=>'No name argument found.'], 403); } }