ModalController.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use App\Proposal;
  6. use App\User;
  7. use App\StudentProposal;
  8. use App\Country;
  9. use App\Models\ReferUser;
  10. use App\Models\Admin;
  11. use App\Models\Requirement;
  12. use App\Models\University;
  13. use App\Models\Publication;
  14. use App\Workexperience;
  15. use App\Institution;
  16. use App\Score;
  17. use Hash;
  18. use DB;
  19. use Session;
  20. use Auth;
  21. use Mail;
  22. class ModalController extends Controller{
  23. public function get(Request $req, $name){
  24. $user = Auth::user();
  25. $carbon=new \Carbon\Carbon;
  26. $data=[
  27. 'name'=>$name,
  28. 'carbon'=>$carbon
  29. ];
  30. if($name=="apply_student_proposal"){
  31. $student =Auth::user();
  32. $data['teacher'] = User::find($req->t_id);
  33. $data['student'] = User::find($student->id);
  34. $data['proposal']= Proposal::where('student_id',$user->id)->get();
  35. }elseif($name=="update_student_proposal"){
  36. $data['std_proposal'] =StudentProposal::find($req->id);
  37. $data['teacher'] = User::find($req->teacher_id);
  38. $data['student'] = User::find($req->student_id);
  39. $data['proposal']= Proposal::where('student_id',$req->student_id)->get();
  40. $data['years']=range((int)date('Y'), date('Y')+1);
  41. }elseif($name=="view_apply_proposal"){
  42. $data['std_proposal'] =StudentProposal::find($req->id);
  43. }elseif($name=="view_student_proposal"){
  44. $data['proposal']= Proposal::where(
  45. 'student_id',$user->id
  46. )->where(
  47. 'id',$req->id
  48. )->first();
  49. }elseif($name=="add_destination"){
  50. }elseif($name=="add_wishlist"){
  51. $user =Auth::guard('teacher')->user();
  52. $data['refer'] = new ReferUser;
  53. }elseif($name=="teacher_invited"){
  54. $data['admin'] =Admin::find($req->id);
  55. }elseif($name=="add_doc_required"){
  56. $data['std_proposal']=StudentProposal::find($req->id);
  57. }elseif($name=="edit_doc_required"){
  58. $data['requirements']=Requirement::find($req->id);
  59. }elseif($name=="landing_register_form"){
  60. $data['countries'] =Country::where('status',1)->orderBy('name','ASC')->get();
  61. //$data['universities'] =University::orderBy('name','ASC')->get();
  62. }elseif($name=="send_email_document_information"){
  63. $data['std_proposal']=StudentProposal::find($req->id);
  64. }else $name='default';
  65. return view("modal_pages.{$name}", $data);
  66. }
  67. public function post(Request $req, $name){
  68. $user=Auth::user();
  69. $carbon=new \Carbon\Carbon;
  70. if($name=='apply_student_proposal'){
  71. $new_rules=[
  72. 'proposal_id'=>'required',
  73. ];
  74. $validator=\Validator::make($req->all(),$new_rules,[
  75. 'proposal_id.required'=>'Please complete your profile to submit your proposal.',
  76. 'startdate'=>'required',
  77. 'startmonth'=>'required',
  78. ]);
  79. if($validator->fails()){
  80. $errors=$validator->errors()->all();
  81. return response(['msg'=>$errors[0]], 422);
  82. }
  83. $already_exists = StudentProposal::where('student_id',$req->student_id)->where('proposal_submit_status',1)->exists();
  84. if($already_exists){
  85. return response(['msg'=>'Sorry! You already submitted. You can not submit proposal.'],403);
  86. }
  87. $publication =User::where('id',$req->student_id)->whereNull('is_publication')->exists();
  88. $worK_exp =User::where('id',$req->student_id)->whereNull('is_work_experience')->exists();
  89. $institution =User::where('id',$req->student_id)->whereNull('is_education')->exists();
  90. $score =User::where('id',$req->student_id)->whereNull('is_test_score')->exists();
  91. if($publication || $worK_exp || $institution || $score){
  92. return response(['msg'=>'you didn\'t complete your profile.'],403);
  93. }
  94. $student_proposal =new StudentProposal;
  95. $student_proposal->student_id =$req->student_id;
  96. $student_proposal->teacher_id =$req->teacher_id;
  97. $student_proposal->proposal_id =$req->proposal_id;
  98. $student_proposal->start_year =$req->startdate;
  99. $student_proposal->start_month =$req->startmonth;
  100. $student_proposal->student_apply_ref =studentRefNoGenerate();
  101. $student_proposal->proposal_submit_status = 1;
  102. $student_proposal->submitted_date = now();
  103. $student_proposal->created_by =$req->student_id;
  104. $student_proposal->save();
  105. $student_data =User::find($student_proposal->student_id);
  106. $student_data->freez_profile =1;
  107. $student_data->update();
  108. $teacher =User::find($student_proposal->teacher_id);
  109. if($teacher->university_name){
  110. $university =$teacher->university_name;
  111. }else{
  112. $university = cn($teacher,'university.name','');
  113. }
  114. if($student_data){
  115. $data['name'] = $student_data->first_name.' '.$student_data->last_name;
  116. $data['teacher'] = $teacher->first_name.' '.$teacher->last_name;
  117. $data['university'] = $university;
  118. $data['submission_date'] = $student_data->created_at;
  119. $data['receive_email']=$student_data->email;
  120. //$data['arn'] = $teacher->ref_no;
  121. $user_mail =$student_data->email;
  122. $from = 'asraful@revinr.com';
  123. Mail::send('email.student_proposal_email',$data, function ($message) use ($user_mail,$from,$student_proposal) {
  124. $message->from($from);
  125. $message->to($user_mail)->subject('Apply Ref:' .$student_proposal->student_apply_ref. '- Proposal has been submitted successfully ');
  126. });
  127. }
  128. $proposal =Proposal::where(
  129. 'student_id',$student_proposal->student_id
  130. )->where(
  131. 'id',$student_proposal->proposal_id
  132. )->first();
  133. if($teacher){
  134. $data['name'] = $teacher->first_name.' '.$teacher->last_name;
  135. $data['std_name'] = $user->first_name.' '.$user->last_name;
  136. $data['proposal_title'] =$proposal->title;
  137. $data['date_time']=$student_proposal->submitted_date;
  138. $data['receive_email']=$teacher->email;
  139. $user_mail =$teacher->email;
  140. $from = 'asraful@revinr.com';
  141. Mail::send('email.teacher_proposal_email',$data, function ($message) use ($user_mail,$from) {
  142. $message->from($from);
  143. $message->to($user_mail)->subject('New Proposal Received - Action Required');
  144. });
  145. }
  146. return response(['msg'=>'Proposal send successfully.']);
  147. }elseif($name=="update_student_proposal"){
  148. $new_rules=[
  149. 'proposal_id'=>'required',
  150. ];
  151. $validator=\Validator::make($req->all(),$new_rules,[
  152. 'proposal_id.required'=>'Please complete your profile to submit your proposal.',
  153. 'startdate'=>'required',
  154. 'startmonth'=>'required',
  155. ]);
  156. if($validator->fails()){
  157. $errors=$validator->errors()->all();
  158. return response(['msg'=>$errors[0]], 422);
  159. }
  160. $already_exists = StudentProposal::where('student_id',$req->student_id)->where('proposal_submit_status',1)->exists();
  161. if($already_exists){
  162. return response(['msg'=>'Sorry! You already submitted. You can not submit proposal.'],403);
  163. }
  164. $publication =User::where('id',$req->student_id)->whereNull('is_publication')->exists();
  165. $worK_exp =User::where('id',$req->student_id)->whereNull('is_work_experience')->exists();
  166. $institution =User::where('id',$req->student_id)->whereNull('is_education')->exists();
  167. $score =User::where('id',$req->student_id)->whereNull('is_test_score')->exists();
  168. if($publication || $worK_exp || $institution || $score){
  169. return response(['msg'=>'you didn\'t complete your profile.'],403);
  170. }
  171. $student_proposal =StudentProposal::find($req->id);
  172. $student_proposal->proposal_id =$req->proposal_id;
  173. $student_proposal->start_year =$req->startdate;
  174. $student_proposal->start_month =$req->startmonth;
  175. $student_proposal->student_apply_ref =studentRefNoGenerate();
  176. $student_proposal->proposal_submit_status = 1;
  177. $student_proposal->submitted_date = now();
  178. $student_proposal->created_by =$req->student_id;
  179. $student_proposal->draft_status =0; // Q-Form
  180. $student_proposal->update();
  181. $student_data =User::find($student_proposal->student_id);
  182. $student_data->freez_profile =1;
  183. $student_data->update();
  184. $teacher =User::find($student_proposal->teacher_id);
  185. if($teacher->university_name){
  186. $university =$teacher->university_name;
  187. }else{
  188. $university = cn($teacher,'university.name','');
  189. }
  190. if($student_data){
  191. $data['name'] = $student_data->first_name.' '.$student_data->last_name;
  192. $data['teacher'] = $teacher->first_name.' '.$teacher->last_name;
  193. $data['university'] = $university;
  194. $data['submission_date'] = $student_data->created_at;
  195. $data['receive_email']=$student_data->email;
  196. //$data['arn'] = $proposal_user->ref_no;
  197. $user_mail =$student_data->email;
  198. $from = 'asraful@revinr.com';
  199. Mail::send('email.student_proposal_email',$data, function ($message) use ($user_mail,$from,$student_proposal) {
  200. $message->from($from);
  201. $message->to($user_mail)->subject('Apply Ref:' .$student_proposal->student_apply_ref. '- Proposal has been submitted successfully ');
  202. });
  203. }
  204. $proposal =Proposal::where(
  205. 'student_id',$student_proposal->student_id
  206. )->where(
  207. 'id',$student_proposal->proposal_id
  208. )->first();
  209. if($teacher){
  210. $data['name'] = $teacher->first_name.' '.$teacher->last_name;
  211. $data['std_name'] = $student_data->first_name.' '.$student_data->last_name;
  212. $data['proposal_title'] =$proposal->title;
  213. $data['date_time']=$student_proposal->submitted_date;
  214. $data['receive_email']=$teacher->email;
  215. $user_mail =$teacher->email;
  216. $from = 'asraful@revinr.com';
  217. Mail::send('email.teacher_proposal_email',$data, function ($message) use ($user_mail,$from) {
  218. $message->from($from);
  219. $message->to($user_mail)->subject('New Proposal Received - Action Required');
  220. });
  221. }
  222. return response(['msg'=>'Successfully updated.']);
  223. }elseif($name=="add_wishlist"){
  224. $teacher =Auth::guard('teacher')->user();
  225. $validator=\Validator::make($req->all(), [
  226. 'name'=>'required',
  227. 'email'=>'required|email|max:255'
  228. ]);
  229. if($validator->fails()){
  230. $errors=$validator->errors()->all();
  231. return response(['msg'=>$errors[0]], 422);
  232. }
  233. $is_user_exists=User::where('email',$req->email)->where('user_type',1)->exists();
  234. if($is_user_exists){
  235. $user_notify =User::where('email',$req->email)->where('user_type',1)->first();
  236. // $isUserExists = User::where(
  237. // 'email',$req->email
  238. // )->where(
  239. // 'user_type',2
  240. // )->where(function($q){
  241. // $q->where('sign_up',1)->orWhere('sign_up',0);
  242. // })->exists();
  243. // if($isUserExists){
  244. // return response([
  245. // 'msg'=>'Already there is an account associated this email ID. Please login to your account.'
  246. // ],403);
  247. // }
  248. $is_student_proposal_exists =StudentProposal::where(
  249. 'teacher_id',$teacher->id
  250. )->where(
  251. 'student_id',$user_notify->id
  252. )->whereIn(
  253. 'proposal_status',[1,2,3,4] // 1 =New; 2 =In Review; 3=Push; 4=Hold;
  254. )->exists();
  255. if($is_student_proposal_exists){
  256. return response(
  257. ['msg'=>'Already pending your proposal. Please wait for approving.'],403
  258. );
  259. }else{
  260. $refer =new ReferUser;
  261. $refer->name =$req->name;
  262. $refer->email =$req->email;
  263. $refer->refer_by =$teacher->id;
  264. $refer->teacher_id =$teacher->id;
  265. $refer->save();
  266. }
  267. }else{
  268. $user_data =new User;
  269. $user_data->first_name =$req->name;
  270. $user_data->email =$req->email;
  271. $user_data->user_type =1;
  272. $user_data->status =0;
  273. $user_data->register_type =4; // 1=invitation ; 2= landing/wishlish; 3 =q_form ; 4=student-wishlist
  274. $user_data->invitation_date =now();
  275. $user_data->wishlist_teacher_id =$teacher->id;
  276. $user_data->save();
  277. $refer =new ReferUser;
  278. $refer->name =$req->name;
  279. $refer->email =$req->email;
  280. $refer->refer_by =$teacher->id;
  281. $refer->teacher_id =$teacher->id;
  282. $refer->save();
  283. $user_notify =User::where('email',$req->email)->where('user_type',1)->first();
  284. $data['name'] = $refer->name;
  285. $data['teacher_id'] = $refer->teacher_id;
  286. $data['student_id'] = $user_notify->id;
  287. $data['std_email'] = $refer->email;
  288. $data['teacher'] = $teacher->first_name.' '.$teacher->last_name;
  289. $data['arn'] = $teacher->ref_no;
  290. $data['designation'] = $teacher->designation;
  291. $data['department'] = $teacher->others_department;
  292. $data['university'] = $teacher->university_name;
  293. $data['receive_email']=$refer->email;
  294. $user_mail = $refer->email;
  295. $from = 'asraful@revinr.com';
  296. Mail::send('email.wishlist_email',$data, function ($message) use ($user_mail,$from) {
  297. $message->from($from);
  298. $message->to($user_mail)->subject('Research Admission Platform Sign-Up');
  299. });
  300. }
  301. return response(
  302. ['msg'=>'Wishlist saved successfully.']
  303. );
  304. }elseif($name=="teacher_invited"){
  305. $admin =Admin::find($req->id);
  306. $validator=\Validator::make($req->all(), [
  307. 'name'=>'required',
  308. 'email'=>'required|email|max:255'
  309. ]);
  310. if($validator->fails()){
  311. $errors=$validator->errors()->all();
  312. return response(['msg'=>$errors[0]], 422);
  313. }
  314. $isUserExists = User::where(
  315. 'email',$req->email
  316. )->where(
  317. 'user_type',2
  318. )->where(function($q){
  319. $q->where('sign_up',1)->orWhere('sign_up',0);
  320. })->exists();
  321. if($isUserExists){
  322. return response([
  323. 'msg'=>'Already there is an account associated this email ID.'
  324. ],403);
  325. }else{
  326. $user_data =new User;
  327. $user_data->first_name =$req->name;
  328. $user_data->email =$req->email;
  329. $user_data->admin_invite_id =$admin->id;
  330. $user_data->user_type =2;
  331. $user_data->register_type =1; // 1=invitation ; 2=wishlist/landing
  332. $user_data->invitation_date =now();
  333. $user_data->save();
  334. $teacher_user =User::where('email',$req->email)->where('user_type',2)->first();
  335. $refer =new ReferUser;
  336. $refer->name =$req->name;
  337. $refer->email =$req->email;
  338. $refer->refer_by =$admin->id;
  339. $refer->teacher_id =$teacher_user->id;
  340. $refer->save();
  341. $data['name'] = $refer->name;
  342. $data['teacher_id'] = $teacher_user->id;
  343. $data['applicant_name'] = $admin->first_name.' '.$admin->last_name;
  344. $data['email']=$refer->email;
  345. $data['receive_email']=$refer->email;
  346. $user_mail = $refer->email;
  347. $from = 'asraful@revinr.com';
  348. if($req->is_currently_open==1){
  349. Mail::send('email.invitation_to_supervisor_email_with_checked',$data, function ($message) use ($user_mail,$from) {
  350. $message->from($from);
  351. $message->to($user_mail)->subject('Accepting doctoral applications! Expedite the process with pre-screening proposals');
  352. });
  353. }else{
  354. Mail::send('email.invitation_to_supervisor_email',$data, function ($message) use ($user_mail,$from) {
  355. $message->from($from);
  356. $message->to($user_mail)->subject('Optimize Your Workflow: Join our Innovative Doctoral Applicant Management Solution');
  357. });
  358. }
  359. }
  360. $already_invited =ReferUser::where('email',$refer->email)->count();
  361. if($already_invited > 1) {
  362. return response(
  363. ['msg'=>"Successfully saved. Already invitation send {$already_invited} times."]
  364. );
  365. }else{
  366. return response(
  367. ['msg'=>'Invitation saved successfully.']
  368. );
  369. }
  370. }elseif($name=="add_doc_required"){
  371. $user=auth_user();
  372. $new_rules=[
  373. 'others'=>'required|array',
  374. 'others.*.requirement_title'=>'required',
  375. ];
  376. $validator=\Validator::make($req->all(),$new_rules,[
  377. 'others.*.requirement_title.required'=>'Please!, fill-up all requirement field.'
  378. ]);
  379. if($validator->fails()){
  380. $errors=$validator->errors()->all();
  381. return response(['msg'=>$errors[0]], 422);
  382. }
  383. $std_proposal=StudentProposal::find($req->id);
  384. foreach($req->others as $row){
  385. Requirement::create([
  386. 'std_proposal_id'=>$std_proposal->id,
  387. 'requirement_title'=>$row['requirement_title'],
  388. 'need_upload'=>$row['need_upload'],
  389. 'created_by'=>$user->id
  390. ]);
  391. }
  392. return response([
  393. 'msg'=>'Successfully Saved.'
  394. ]);
  395. }elseif($name=="edit_doc_required"){
  396. $requirements=Requirement::find($req->id);
  397. $requirements->requirement_title =$req->requirement_title;
  398. $requirements->need_upload =$req->need_upload;
  399. $requirements->update();
  400. return response([
  401. 'msg'=>'Successfully updated.'
  402. ]);
  403. }elseif($name=="landing_register_form"){
  404. $validator=\Validator::make($req->all(), [
  405. 'name'=>'required',
  406. 'email'=>'required|email|max:255'
  407. ]);
  408. if($validator->fails()){
  409. $errors=$validator->errors()->all();
  410. return response(['msg'=>$errors[0]], 422);
  411. }
  412. $isUserExists = User::where(
  413. 'email',$req->email
  414. )->where(
  415. 'user_type',2
  416. )->where(function($q){
  417. $q->where('sign_up',1)->orWhere('sign_up',0);
  418. })->exists();
  419. if($isUserExists){
  420. return response([
  421. 'msg'=>'Already there is an account associated this email ID. Please login to your account.'
  422. ],403);
  423. }else{
  424. $user_data =new User;
  425. $user_data->first_name =$req->name;
  426. $user_data->email =$req->email;
  427. $user_data->nationality =$req->country_id;
  428. $user_data->university_name =$req->university;
  429. $user_data->uni_website =$req->uni_website;
  430. $user_data->user_type =2;
  431. $user_data->register_type =2; // 1=invitation ; 2= landing/wishlish
  432. // $user_data->invitation_date =now();
  433. $user_data->save();
  434. $user =User::where('email',$req->email)->where('user_type',2)->first();
  435. $refer =new ReferUser;
  436. $refer->name =$req->name;
  437. $refer->email =$req->email;
  438. $refer->teacher_id =$user->id;
  439. $refer->save();
  440. }
  441. return response(
  442. ['msg'=>'Successfully saved.']
  443. );
  444. }
  445. return response(['msg'=>'No name argument found.'], 403);
  446. }
  447. }