ModalController.php 21 KB

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