AjaxController.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use \App\Helpers\PageSL;
  5. use App\User;
  6. use App\Models\MarketCountry;
  7. use App\Models\University;
  8. use App\Models\Department;
  9. use App\Models\ReferUser;
  10. use App\Models\ResearchInterest;
  11. use App\Models\Requirement;
  12. use App\Models\Publication;
  13. use App\StudentProposal;
  14. use App\Proposal;
  15. use App\Institution;
  16. use App\Score;
  17. use App\Workexperience;
  18. use Carbon\Carbon;
  19. use Session;
  20. use Mail;
  21. use Auth;
  22. use Hash;
  23. use Illuminate\Support\Str;
  24. class AjaxController extends Controller
  25. {
  26. public function get($name, Request $req)
  27. {
  28. if($name=='available_ref_no_search') {
  29. }elseif(empty($name)){
  30. return response([
  31. 'msg'=>'Invalid request please insert correct value!.'
  32. ], 403);
  33. }
  34. }
  35. public function post($name, Request $req)
  36. {
  37. if($name =='teacher_change_password') {
  38. $validator=\Validator::make($req->all(), [
  39. 'old_password'=>'required',
  40. 'new_password_confirmation'=>'required',
  41. 'new_password'=>[
  42. 'required',
  43. 'confirmed',
  44. 'min:8',
  45. //'regex:/[a-z]/',
  46. //'regex:/[A-Z]/',
  47. //'regex:/[0-9]/',
  48. //'regex:/[@$!%*#?&]/',
  49. ]
  50. ]);
  51. // [
  52. // 'regex' => 'The :attribute must contain at least one lowercase, uppercase, digit and special character.'
  53. // ]);
  54. if($validator->fails()){
  55. $errors=$validator->errors()->all();
  56. return response(['msg'=>$errors[0]], 422);
  57. }
  58. $user=auth_user('teacher');
  59. if(\Illuminate\Support\Facades\Hash::check($req->old_password, $user->password)) {
  60. $user->password=bcrypt($req->new_password);
  61. $user->update();
  62. return ['msg'=>'Your login password updated successfully!. Please use your new password for next time login.'];
  63. }else{
  64. return response(
  65. ['msg'=>'Sorry!, old password does not match with login credential.'],
  66. 403
  67. );
  68. }
  69. }elseif($name=="teacher_user_status_change"){
  70. $user=auth_user('teacher');
  71. $teacher =User::find($req->id);
  72. $teacher->apply_status =$req->status;
  73. $teacher->update();
  74. $data['name'] = $teacher->first_name.' '.$teacher->last_name;
  75. $data['receive_email']=$teacher->email;
  76. $user_mail = $teacher->email;
  77. $from = 'asraful@revinr.com';
  78. if($teacher->apply_status==1){
  79. Mail::send('email.approve_teacher_email',$data, function ($message) use ($user_mail,$from) {
  80. $message->from($from);
  81. $message->to($user_mail)->subject('Account Activation Confirmation');
  82. });
  83. }
  84. return response(
  85. ['msg'=>'Successfully saved.']
  86. );
  87. }elseif($name=="set_country"){
  88. $user =Auth::guard('admin')->user();
  89. if($req->checked == 'true'){
  90. $mc = new MarketCountry;
  91. $mc->country_id = $req->id;
  92. $mc->status = 1;
  93. $mc->added_by = $user->id;
  94. $mc->save();
  95. return response(
  96. ['msg'=>'Added Successfully.']
  97. );
  98. }else{
  99. MarketCountry::where('country_id', $req->id)->delete();
  100. return response(
  101. ['msg'=>'Removed Successfully.']
  102. );
  103. }
  104. }elseif($name=="add_country_wise_uni"){
  105. $user =Auth::guard('admin')->user();
  106. $validator=\Validator::make($req->all(), [
  107. 'country_id'=>'required',
  108. 'university_name'=>'required',
  109. 'university_website'=>'required',
  110. ]);
  111. if($validator->fails()){
  112. $errors=$validator->errors()->all();
  113. return response(['msg'=>$errors[0]], 422);
  114. }
  115. $data =new University;
  116. $data->country_id =$req->country_id;
  117. $data->name =$req->university_name;
  118. $data->web_address =$req->university_website;
  119. $data->save();
  120. return response(
  121. ['msg'=>'Saved Successfully.']
  122. );
  123. }elseif($name=="add_department"){
  124. $user =Auth::guard('admin')->user();
  125. $validator=\Validator::make($req->all(), [
  126. 'dapartment'=>'required',
  127. ]);
  128. if($validator->fails()){
  129. $errors=$validator->errors()->all();
  130. return response(['msg'=>$errors[0]], 422);
  131. }
  132. $data =new Department;
  133. $data->name =$req->dapartment;
  134. $data->status =1;
  135. $data->save();
  136. return response(
  137. ['msg'=>'Department saved successfully.']
  138. );
  139. }elseif($name=="update_profile"){
  140. $validator=\Validator::make($req->all(), [
  141. 'first_name'=>'required',
  142. 'last_name'=>'required',
  143. 'university_id'=>'required',
  144. 'department'=>'required',
  145. 'designation'=>'required',
  146. ]);
  147. if($validator->fails()){
  148. $errors=$validator->errors()->all();
  149. return response(['msg'=>$errors[0]], 422);
  150. }
  151. $data = User::find($req->id);
  152. $data->first_name =$req->first_name;
  153. $data->last_name =$req->last_name;
  154. $data->university_id =$req->university_id;
  155. $data->university_name =NULL;
  156. $data->department =$req->department;
  157. $data->others_department =NULL;
  158. $data->designation =$req->designation;
  159. $data->update();
  160. return response(
  161. ['msg'=>'Saved successfully.']
  162. );
  163. }elseif($name=="save_student_refer_friend"){
  164. $user =Auth::user();
  165. $validator=\Validator::make($req->all(), [
  166. 'name'=>'required',
  167. 'email'=>'required|email|max:255'
  168. ]);
  169. if($validator->fails()){
  170. $errors=$validator->errors()->all();
  171. return response(['msg'=>$errors[0]], 422);
  172. }
  173. $std_proposal =StudentProposal::where(
  174. 'student_id',$user->id
  175. )->where(
  176. 'proposal_submit_status',1
  177. )->first();
  178. if(empty($std_proposal)){
  179. return response(
  180. ['msg'=>'Sorry! you have to submit a proposal first.'],403
  181. );
  182. }
  183. $user_data = new User;
  184. $user_data->first_name = $req->name;
  185. $user_data->email =$req->email;
  186. $user_data->invitation_date =now();
  187. $user_data->user_type =1;
  188. $user_data->register_type =6; // 6= student refer a friend for a application proposal
  189. $user_data->created_by =$user->id;
  190. $user_data->save();
  191. $refer =new ReferUser;
  192. $refer->name =$req->name;
  193. $refer->email =$req->email;
  194. $refer->refer_by =$user->id;
  195. $refer->teacher_id =$std_proposal->teacher_id;
  196. $refer->save();
  197. if($refer->save()){
  198. $data['name'] = $refer->name;
  199. $data['teacher_id'] = $refer->teacher_id;
  200. $data['student_id'] = $user_data->id;
  201. $data['std_email'] = $refer->email;
  202. $data['applicant_name'] = $user->first_name.' '.$user->last_name;
  203. $data['receive_email']=$refer->email;
  204. $user_mail = $refer->email;
  205. $from = 'asraful@revinr.com';
  206. Mail::send('email.refer_a_friend_email',$data, function ($message) use ($user_mail,$from) {
  207. $message->from($from);
  208. $message->to($user_mail)->subject('Recommendation - Research Admission Platform for Finding a Research Superviso.');
  209. });
  210. }
  211. return response(
  212. ['msg'=>'Saved successfully.']
  213. );
  214. }elseif($name=="research_interest"){
  215. $validator=\Validator::make($req->all(), [
  216. 'research'=>'required',
  217. ]);
  218. if($validator->fails()){
  219. $errors=$validator->errors()->all();
  220. return response(['msg'=>$errors[0]], 422);
  221. }
  222. $data = new ResearchInterest;
  223. $data->teacher_id =$req->id;
  224. $data->research =$req->research;
  225. $data->save();
  226. return response(
  227. ['msg'=>'Saved successfully.']
  228. );
  229. }elseif($name=="edit_university_save"){
  230. $user=Auth::guard('admin')->user();
  231. $validator=\Validator::make($req->all(), [
  232. 'country_id'=>'required',
  233. 'university_name'=>'required',
  234. 'university_website'=>'required',
  235. ]);
  236. if($validator->fails()){
  237. $errors=$validator->errors()->all();
  238. return response(['msg'=>$errors[0]], 422);
  239. }
  240. $data =University::find($req->edit_id);
  241. $data->country_id =$req->country_id;
  242. $data->name =$req->university_name;
  243. $data->web_address =$req->university_website;
  244. $data->update();
  245. return response([
  246. 'msg'=>'Update Successfully.'
  247. ]);
  248. }elseif($name=="delete_university_info"){
  249. $user=Auth::guard('admin')->user();
  250. $data =University::find($req->delete_id);
  251. $data->delete();
  252. return response([
  253. 'msg'=>'Successfully Deleted'
  254. ]);
  255. }elseif($name=="delete_department_info"){
  256. $user=Auth::guard('admin')->user();
  257. $data =Department::find($req->delete_id);
  258. $data->delete();
  259. return response([
  260. 'msg'=>'Successfully Deleted'
  261. ]);
  262. }elseif($name=="edit_department_save"){
  263. $user=Auth::guard('admin')->user();
  264. $validator=\Validator::make($req->all(), [
  265. 'department'=>'required',
  266. ]);
  267. if($validator->fails()){
  268. $errors=$validator->errors()->all();
  269. return response(['msg'=>$errors[0]], 422);
  270. }
  271. $data =Department::find($req->edit_id);
  272. $data->name =$req->department;
  273. $data->update();
  274. return response([
  275. 'msg'=>'Successfully updated.'
  276. ]);
  277. }elseif($name=="concept_status_update"){
  278. $data =StudentProposal::find($req->id);
  279. $data->concept =$req->value;
  280. $data->update();
  281. return response(
  282. ['msg'=>'Updated successfully.']
  283. );
  284. }elseif($name=="proposal_status_update"){
  285. $proposal =StudentProposal::find($req->id);
  286. $proposal->proposal_status =$req->value;
  287. $proposal->proposal_status_date =now();
  288. $proposal->feedback_msg =NULL;
  289. $proposal->feedback_reason =NULL;
  290. $proposal->update();
  291. if($req->value){
  292. $user_data = User::find($proposal->student_id);
  293. $user_data->freez_profile =2; // 2 = [In Review,Pause,Interested,Terminate]
  294. $user_data->update();
  295. }
  296. // Status wise email send
  297. $teacher =User::find($proposal->teacher_id);
  298. $student =User::find($proposal->student_id);
  299. $data['teacher'] = $teacher->first_name.' '.$teacher->last_name;
  300. $data['student'] = $student->first_name.' '.$student->last_name;
  301. $data['receive_email']=$student->email;
  302. $from = 'asraful@revinr.com';
  303. $user_mail = $student->email;
  304. //-----Hold----
  305. if($proposal->proposal_status == 4){
  306. $data['doc_requirement_list']=Requirement::where('std_proposal_id',$proposal->id)->get();
  307. Mail::send('email.hold_status_email',$data, function ($message) use ($user_mail,$from) {
  308. $message->from($from);
  309. $message->to($user_mail)->subject('Request for additional Documents and Information');
  310. });
  311. if(!empty($student)) {
  312. \Notification::send($student, new \App\Notifications\ProposalStatusNotification($proposal,"Hold",$teacher));
  313. }
  314. }
  315. //-----Interested----
  316. if($proposal->proposal_status == 5){
  317. Mail::send('email.interested_status_email',$data, function ($message) use ($user_mail,$from) {
  318. $message->from($from);
  319. $message->to($user_mail)->subject('Expression of Interest in Supervising Your Research Application');
  320. });
  321. if(!empty($student)) {
  322. \Notification::send($student, new \App\Notifications\ProposalStatusNotification($proposal,"Interested",$teacher));
  323. }
  324. }
  325. //-----Terminate----
  326. if($proposal->proposal_status == 7){
  327. Mail::send('email.terminate_status_email',$data, function ($message) use ($user_mail,$from) {
  328. $message->from($from);
  329. $message->to($user_mail)->subject('Your doctoral application has been terminated.');
  330. });
  331. if(!empty($student)) {
  332. \Notification::send($student, new \App\Notifications\ProposalStatusNotification($proposal,"Terminate",$teacher));
  333. }
  334. }
  335. return response(
  336. ['msg'=>'Saved successfully.']
  337. );
  338. }elseif($name=="accept_status_update"){
  339. $data =StudentProposal::find($req->id);
  340. $data->accepted_status =1;
  341. $data->accepted_date =now();
  342. $data->update();
  343. $user_accepted = User::find($data->student_id);
  344. $user_accepted->freez_profile =0;
  345. $user_accepted->update();
  346. return response([
  347. 'msg'=>'Updated successfully.'
  348. ]);
  349. }elseif($name=="proposal_quality_rate_star_update"){
  350. $data =StudentProposal::find($req->id);
  351. $data->proposal_quality =$req->value;
  352. $data->update();
  353. return response([
  354. 'msg'=>'Updated successfully.'
  355. ]);
  356. }elseif($name=="teacher_is_available"){
  357. $user =Auth::guard('teacher')->user();
  358. $data =User::find($user->id);
  359. if($req->checked =="true"){
  360. $data->is_available =0;
  361. }else{
  362. $data->is_available =1;
  363. }
  364. $data->update();
  365. return response(
  366. ['msg'=>"Updated Successfully."]
  367. );
  368. }elseif($name=="student_q_form"){
  369. $validator=\Validator::make($req->all(), [
  370. 'name'=>'required',
  371. 'email'=>'required|email|max:255'
  372. ]);
  373. if($validator->fails()){
  374. $errors=$validator->errors()->all();
  375. return response(['msg'=>$errors[0]], 422);
  376. }
  377. $user =User::where('email',$req->email)->where('user_type',1)->first();
  378. if($user){
  379. $is_student_proposal_exists =StudentProposal::where(
  380. 'teacher_id',$req->id
  381. )->where(
  382. 'student_id',$user->id
  383. )->whereIn(
  384. 'proposal_status',[1,2,3,4] // 1 =New; 2 =In Review; 3=Push; 4=Hold;
  385. )->exists();
  386. if($is_student_proposal_exists){
  387. return response(
  388. ['msg'=>'You have already received an invitation. Please login to your account to submit'],403
  389. );
  390. }else{
  391. $student_proposal =new StudentProposal;
  392. $student_proposal->student_id =$user->id;
  393. $student_proposal->teacher_id =$req->id;
  394. $student_proposal->draft_status =1;
  395. $student_proposal->save();
  396. $refer =new ReferUser;
  397. $refer->name =$req->name;
  398. $refer->email =$req->email;
  399. $refer->refer_by =$user->id;
  400. $refer->teacher_id =$req->id;
  401. $refer->q_form_status =1;
  402. $refer->save();
  403. }
  404. }else{
  405. $user_data =new User;
  406. $user_data->first_name =$req->name;
  407. $user_data->email =$req->email;
  408. $user_data->user_type =1;
  409. $user_data->status =0;
  410. $user_data->register_type =3; // 1=invitation ; 2= landing/wishlish; 3 =q_form ; 4=student_wishlist
  411. $user_data->invitation_date =now();
  412. $user_data->wishlist_teacher_id =$req->id;
  413. $user_data->save();
  414. $student_proposal =new StudentProposal;
  415. $student_proposal->student_id =$user_data->id;
  416. $student_proposal->teacher_id =$req->id;
  417. $student_proposal->draft_status =1;
  418. $student_proposal->save();
  419. $refer =new ReferUser;
  420. $refer->name =$req->name;
  421. $refer->email =$req->email;
  422. $refer->refer_by =$user_data->id;
  423. $refer->teacher_id =$req->id;
  424. $refer->q_form_status =1;
  425. $refer->save();
  426. if($refer->save()){
  427. $teacher = User::find($refer->teacher_id);
  428. if($teacher->others_department){
  429. $department =$teacher->others_department;
  430. }else{
  431. $department = cn($teacher,'department_name.name','');
  432. }
  433. if($teacher->university_name){
  434. $university =$teacher->university_name;
  435. }else{
  436. $university = cn($teacher,'university.name','');
  437. }
  438. $data['name'] = $refer->name;
  439. $data['student_id'] = $user_data->id;
  440. $data['teacher'] = $teacher->first_name.' '.$teacher->last_name;
  441. $data['arn'] = $teacher->ref_no;
  442. $data['designation'] = $teacher->designation;
  443. $data['department'] = $department;
  444. $data['university'] = $university;
  445. $data['email'] =$refer->email;
  446. $data['receive_email']=$refer->email;
  447. $user_mail = $refer->email;
  448. $from = 'asraful@revinr.com';
  449. Mail::send('email.q_form_email',$data, function ($message) use ($user_mail,$from) {
  450. $message->from($from);
  451. $message->to($user_mail)->subject('Invitation to submit your doctoral application');
  452. });
  453. }
  454. }
  455. return response(
  456. ['msg'=>'Saved successfully.']
  457. );
  458. }elseif($name=="q_apply_wishlist_registration_save"){
  459. $validator=\Validator::make($req->all(), [
  460. 'first_name'=>'required',
  461. 'last_name'=>'required',
  462. 'dob'=>'required',
  463. 'gender'=>'required',
  464. 'nationality'=>'required',
  465. 'email'=>'required',
  466. 'password_confirmation'=>'required',
  467. 'password'=>[
  468. 'required',
  469. 'confirmed',
  470. 'min:8',
  471. ]
  472. ]);
  473. if($validator->fails()){
  474. $errors=$validator->errors()->all();
  475. return response(['msg'=>$errors[0]], 422);
  476. }
  477. $token =Str::random(64);
  478. $user_check = User::where(
  479. 'id',$req->id
  480. )->where(
  481. 'sign_up',1
  482. )->first();
  483. if($user_check){
  484. // return redirect()->to("/login")->with('success','You are already registered. Please login here.');
  485. return response(
  486. ['msg'=>'You are already registered.','action'=>'redirect']
  487. );
  488. }
  489. $user_data = User::find($req->id);
  490. $user_data->first_name =$req->first_name;
  491. $user_data->last_name =$req->last_name;
  492. $user_data->first_name =$req->first_name;
  493. $user_data->nationality =$req->nationality;
  494. $user_data->dob =\Carbon\Carbon::parse($req->dob)->format('Y-m-d');
  495. $user_data->gender =$req->gender;
  496. $user_data->password =Hash::make($req->password);
  497. $user_data->status =0;
  498. $user_data->sign_up =1;
  499. $user_data->registered_date =now();
  500. //$user_data->email_verification=1;
  501. $user_data->remember_token=$token;
  502. //$user_data->email_verified_at=now();
  503. $user_data->update();
  504. $data['name'] = $user_data->first_name .' '.$user_data->last_name;
  505. $data['token']=$token;
  506. $data['receive_email']=$user_data->email;
  507. $user_mail = $user_data->email;
  508. $from = 'asraful@revinr.com';
  509. Mail::send('email.q_apply_wishlist_registration_email',$data, function ($message) use ($user_mail,$from) {
  510. $message->from($from);
  511. $message->to($user_mail)->subject('Thank You for joining us!');
  512. });
  513. return response(
  514. ['msg'=>'Successfully saved. Please check your email for verify.']
  515. );
  516. }elseif($name=="invitation_register_save"){
  517. $new_rules=[
  518. 'others_department'=>'required',
  519. ];
  520. $validator=\Validator::make($req->all(),$new_rules, [
  521. 'first_name'=>'required',
  522. 'last_name'=>'required',
  523. 'email'=>'required',
  524. 'university'=>'required',
  525. 'others_department.required'=>'Department field is required.',
  526. 'website'=>'required',
  527. 'designation'=>'required',
  528. 'password_confirmation'=>'required',
  529. 'password'=>[
  530. 'required',
  531. 'confirmed',
  532. 'min:8',
  533. ]
  534. ]);
  535. if($validator->fails()){
  536. $errors=$validator->errors()->all();
  537. return response(['msg'=>$errors[0]], 422);
  538. }
  539. $isExists = User::where(
  540. 'id',$req->id
  541. )->where(
  542. 'user_type',2
  543. )->where(
  544. 'sign_up',1
  545. )->first();
  546. if($isExists){
  547. return response(
  548. ['msg'=>'You are already registered.','action'=>'redirect']
  549. );
  550. }else{
  551. $user_data = User::find($req->id);
  552. $user_data->first_name =$req->first_name;
  553. $user_data->last_name =$req->last_name;
  554. $user_data->university_name =$req->university;
  555. $user_data->ref_no = name_initials($req->first_name,$req->last_name).''.teacherRefNoGenerate();
  556. //$user_data->department =$req->department;
  557. $user_data->others_department =$req->others_department;
  558. $user_data->designation =$req->designation;
  559. $user_data->uni_website =$req->website;
  560. $user_data->password =Hash::make($req->password);
  561. $user_data->status =1;
  562. $user_data->sign_up = 1; // 1=signup
  563. $user_data->user_type = 2;
  564. $user_data->registered_date = now();
  565. $user_data->update();
  566. if($user_data->update()){
  567. $data['name'] = $user_data->first_name .' '.$user_data->last_name;
  568. $data['receive_email']=$user_data->email;
  569. $user_mail = $user_data->email;
  570. $from = 'asraful@revinr.com';
  571. Mail::send('email.register_teacher_email',$data, function ($message) use ($user_mail,$from) {
  572. $message->from($from);
  573. $message->to($user_mail)->subject('We’re excited to have you as a member of our community');
  574. });
  575. }
  576. }
  577. return response(
  578. ['msg'=>'Registration successfully saved.']
  579. );
  580. }elseif($name=="delete_doc_required"){
  581. $requirements=Requirement::find($req->delete_id);
  582. $requirements->delete();
  583. return response([
  584. 'msg'=>'Deleted Successfully.'
  585. ]);
  586. }elseif($name=="document_required_upload_save"){
  587. $rules=[
  588. 'id'=>'required',
  589. 'document_file' => 'required',
  590. ];
  591. $validator=\Validator::make($req->all(), $rules);
  592. if($validator->fails()){
  593. $errors=$validator->errors()->all();
  594. return response(['msg'=>$errors[0]], 422);
  595. }
  596. $data=Requirement::find($req->id);
  597. $std_ref = StudentProposal::find($data->std_proposal_id);
  598. if($req->document_file){
  599. $destinationPath = public_path('/uploads/required_doc');
  600. $file = $req->document_file;
  601. $ext = $file->getClientOriginalExtension();
  602. $fileName = 'document_file_'.$std_ref->student_apply_ref.'.'.$ext;
  603. if(file_exists($destinationPath.'/'.$fileName)){
  604. @unlink($destinationPath.'/'.$fileName);
  605. }
  606. $file->move($destinationPath, $fileName);
  607. $data->document_file = $fileName;
  608. }
  609. $data->update();
  610. return response([
  611. 'msg'=>'Successfully uploaded.'
  612. ]);
  613. }elseif($name=="update_proposal"){
  614. $user=auth_user();
  615. $validator=\Validator::make($req->all(), [
  616. 'title'=>'required',
  617. 'methology'=>'required',
  618. 'department'=>'required',
  619. ]);
  620. if($validator->fails()){
  621. $errors=$validator->errors()->all();
  622. return response(['msg'=>$errors[0]], 422);
  623. }
  624. $data =Proposal::find($req->edit_id);
  625. $data->title =$req->title;
  626. $data->methology= $req->methology;
  627. $data->department= $req->department;
  628. $data->status= $req->status;
  629. if($req->documentfile){
  630. $destinationPath = public_path('/uploads/proposal');
  631. $file = $req->documentfile;
  632. $ext = $file->getClientOriginalExtension();
  633. $fileName = time().'documentfile_'.'.'.$ext;
  634. if(file_exists($destinationPath.'/'.$fileName)){
  635. @unlink($destinationPath.'/'.$fileName);
  636. }
  637. $file->move($destinationPath, $fileName);
  638. $data->document_file = $fileName;
  639. }
  640. $data->update();
  641. return response([
  642. 'msg'=>'Successfully updated.'
  643. ]);
  644. }elseif($name=="edit_register_teacher_save"){
  645. $validator=\Validator::make($req->all(), [
  646. 'first_name'=>'required',
  647. 'last_name'=>'required',
  648. 'university'=>'required',
  649. 'department'=>'required',
  650. 'designation'=>'required',
  651. 'destination'=>'required',
  652. ]);
  653. if($validator->fails()){
  654. $errors=$validator->errors()->all();
  655. return response(['msg'=>$errors[0]], 422);
  656. }
  657. $user_data = User::find($req->edit_id);
  658. $user_data->first_name =$req->first_name;
  659. $user_data->last_name =$req->last_name;
  660. $user_data->university_id =$req->university;
  661. $user_data->university_name = NULL;
  662. $user_data->department =$req->department;
  663. $user_data->others_department = NULL;
  664. $user_data->designation =$req->designation;
  665. $user_data->nationality =$req->destination;
  666. $user_data->update();
  667. return response(
  668. ['msg'=>'Successfully updated.']
  669. );
  670. }elseif($name=="landing_invitation_email_send"){
  671. $user_data =User::find($req->id);
  672. $user_data->invitation_date =now();
  673. $user_data->update();
  674. if($user_data->update()){
  675. $data['name'] = $user_data->first_name .' '.$user_data->last_name;
  676. $data['receive_email']=$user_data->email;
  677. $user_mail = $user_data->email;
  678. $data['teacher_id'] = $user_data->id;
  679. $data['email'] = $user_data->email;
  680. $from = 'asraful@revinr.com';
  681. Mail::send('email.invitation_to_supervisor_email',$data, function ($message) use ($user_mail,$from) {
  682. $message->from($from);
  683. $message->to($user_mail)->subject('Manage Doctoral Applicants with Ease - You’re invited!');
  684. });
  685. }
  686. return response(
  687. ['msg'=>'Invitation sent successfully.']
  688. );
  689. }elseif($name=="delete_research_info"){
  690. $user=Auth::guard('teacher')->user();
  691. $data =ResearchInterest::find($req->delete_id);
  692. $data->delete();
  693. return response([
  694. 'msg'=>'Successfully Deleted'
  695. ]);
  696. }elseif($name=="edit_research_save"){
  697. $user=Auth::guard('teacher')->user();
  698. $validator=\Validator::make($req->all(), [
  699. 'research'=>'required',
  700. ]);
  701. if($validator->fails()){
  702. $errors=$validator->errors()->all();
  703. return response(['msg'=>$errors[0]], 422);
  704. }
  705. $data =ResearchInterest::find($req->edit_id);
  706. $data->research =$req->research;
  707. $data->update();
  708. return response([
  709. 'msg'=>'Successfully updated.'
  710. ]);
  711. }elseif($name=="add_proposal_publication"){
  712. $student=Auth::user();
  713. $validator=\Validator::make($req->all(), [
  714. 'publication'=>'required',
  715. 'status'=>'required',
  716. ]);
  717. if($validator->fails()){
  718. $errors=$validator->errors()->all();
  719. return response(['msg'=>$errors[0]], 422);
  720. }
  721. $data =new Publication;
  722. $data->student_id =$student->id;
  723. $data->publication =$req->publication;
  724. $data->status =$req->status;
  725. $data->save();
  726. return response([
  727. 'msg'=>'Successfully saved.'
  728. ]);
  729. }elseif($name=="update_publication"){
  730. $student=Auth::user();
  731. $validator=\Validator::make($req->all(), [
  732. 'publication'=>'required',
  733. 'status'=>'required',
  734. ]);
  735. if($validator->fails()){
  736. $errors=$validator->errors()->all();
  737. return response(['msg'=>$errors[0]], 422);
  738. }
  739. $data =Publication::find($req->edit_id);
  740. $data->student_id = $student->id;
  741. $data->publication = $req->publication;
  742. $data->status = $req->status;
  743. $data->update();
  744. return response([
  745. 'msg'=>'Successfully updated.'
  746. ]);
  747. }elseif($name=="delete_publication_info"){
  748. $data =Publication::find($req->delete_id);
  749. $data->delete();
  750. return response([
  751. 'msg'=>'Successfully deleted.'
  752. ]);
  753. }elseif($name=="is_attended_conference_status"){
  754. $data =User::find($req->uid);
  755. if($req->checked =='yes'){
  756. $data->is_attended_conference =1; // 1=yes
  757. }else{
  758. $data->is_attended_conference =2; // 2=no
  759. }
  760. $data->update();
  761. return response([
  762. 'msg'=>'Successfully saved.'
  763. ]);
  764. }elseif($name=="work_experience_status_update"){
  765. $data =User::find($req->uid);
  766. if($req->value =='yes'){
  767. $data->is_work_experience =1; // 1=yes
  768. }else{
  769. $data->is_work_experience =2; // 2=no
  770. }
  771. $data->update();
  772. return response([
  773. 'msg'=>'Successfully saved.'
  774. ]);
  775. }elseif($name=="publication_status_update"){
  776. $data =User::find($req->uid);
  777. if($req->value =='yes'){
  778. $data->is_publication =1; // 1=yes
  779. }else{
  780. $data->is_publication =2; // 2=no
  781. }
  782. $data->update();
  783. return response([
  784. 'msg'=>'Successfully saved.'
  785. ]);
  786. }elseif($name=="education_status_update"){
  787. $data =User::find($req->uid);
  788. if($req->value =='yes'){
  789. $data->is_education =1; // 1=yes
  790. }else{
  791. $data->is_education =2; // 2=no
  792. }
  793. $data->update();
  794. return response([
  795. 'msg'=>'Successfully saved.'
  796. ]);
  797. }elseif($name=="update_education_history"){
  798. $student=Auth::user();
  799. $validator=\Validator::make($req->all(), [
  800. 'academiclevel'=>'required',
  801. 'subject'=>'required',
  802. 'institution'=>'required',
  803. 'passingyear'=>'required',
  804. 'result'=>'required',
  805. ]);
  806. if($validator->fails()){
  807. $errors=$validator->errors()->all();
  808. return response(['msg'=>$errors[0]], 422);
  809. }
  810. $institution= Institution::find($req->edit_id);
  811. $institution->student_id= $student->id;
  812. $institution->academic_level= $req->academiclevel;
  813. $institution->subject= $req->subject;
  814. $institution->institution= $req->institution;
  815. $institution->passing_year= $req->passingyear;
  816. $institution->result= $req->result;
  817. $institution->update();
  818. return response([
  819. 'msg'=>'Successfully updated.'
  820. ]);
  821. }elseif($name=="delete_education_info"){
  822. $data =Institution::find($req->delete_id);
  823. $data->delete();
  824. return response([
  825. 'msg'=>'Successfully deleted.'
  826. ]);
  827. }elseif($name=="update_english_languge_proficiency"){
  828. $student=Auth::user();
  829. $validator=\Validator::make($req->all(), [
  830. 'testdate'=>'required',
  831. 'expirationdate'=>'required',
  832. 'testname'=>'required',
  833. 'overallscore'=>'required',
  834. 'listening'=>'required',
  835. 'speaking'=>'required',
  836. 'writing'=>'required',
  837. 'reading'=>'required',
  838. ]);
  839. if($validator->fails()){
  840. $errors=$validator->errors()->all();
  841. return response(['msg'=>$errors[0]], 422);
  842. }
  843. $score= Score::find($req->edit_id);
  844. $score->student_id= $student->id;
  845. $score->test_date= Carbon::parse($req->testdate)->format('Y-m-d');
  846. $score->expiration_date= Carbon::parse($req->expirationdate)->format('Y-m-d');
  847. $score->test_name= $req->testname;
  848. $score->overall_score= $req->overallscore;
  849. $score->listening= $req->listening;
  850. $score->writing= $req->speaking;
  851. $score->reading= $req->writing;
  852. $score->speaking= $req->reading;
  853. $score->update();
  854. return response([
  855. 'msg'=>'Successfully updated.'
  856. ]);
  857. }elseif($name=="delete_score_info"){
  858. $data =Score::find($req->delete_id);
  859. $data->delete();
  860. return response([
  861. 'msg'=>'Successfully deleted.'
  862. ]);
  863. }elseif($name=="update_work_experience"){
  864. $student=Auth::user();
  865. $validator=\Validator::make($req->all(), [
  866. 'companyname'=>'required',
  867. 'designation'=>'required',
  868. 'startdate'=>'required',
  869. 'enddate'=>'required',
  870. ]);
  871. if($validator->fails()){
  872. $errors=$validator->errors()->all();
  873. return response(['msg'=>$errors[0]], 422);
  874. }
  875. $work_experience= Workexperience::find($req->edit_id);
  876. $work_experience->student_id= $student->id;
  877. $work_experience->company_name= $req->companyname;
  878. $work_experience->designation= $req->designation;
  879. if($req->currently_working=='on'){
  880. $work_experience->currently_working=1;
  881. }else{
  882. $work_experience->currently_working=0;
  883. }
  884. $work_experience->start_date= date($req->startdate.'-'.$req->startmonth.'-01');
  885. $work_experience->end_date= date($req->enddate.'-'.$req->endmonth.'-01');
  886. $work_experience->update();
  887. return response([
  888. 'msg'=>'Successfully updated.'
  889. ]);
  890. }elseif($name=="delete_work_experience_info"){
  891. $data =Workexperience::find($req->delete_id);
  892. $data->delete();
  893. return response([
  894. 'msg'=>'Successfully deleted.'
  895. ]);
  896. }elseif($name=="test_score_status_update"){
  897. $data =User::find($req->uid);
  898. if($req->value =='yes'){
  899. $data->is_test_score =1; // 1=yes
  900. }else{
  901. $data->is_test_score =2; // 2=no
  902. }
  903. $data->update();
  904. return response([
  905. 'msg'=>'Successfully saved.'
  906. ]);
  907. }elseif($name=="all_publication_delete"){
  908. Publication::where('student_id',$req->uid)->delete();
  909. return response([
  910. 'msg'=>'Successfully delete.'
  911. ]);
  912. }elseif($name=="all_education_history_delete"){
  913. Institution::where('student_id',$req->uid)->delete();
  914. return response([
  915. 'msg'=>'Successfully delete.'
  916. ]);
  917. }elseif($name=="all_work_experience_delete"){
  918. Workexperience::where('student_id',$req->uid)->delete();
  919. return response([
  920. 'msg'=>'Successfully delete.'
  921. ]);
  922. }elseif($name=="all_test_score_delete"){
  923. Score::where('student_id',$req->uid)->delete();
  924. return response([
  925. 'msg'=>'Successfully delete.'
  926. ]);
  927. }elseif($name=="update_feedback_msg"){
  928. $data =StudentProposal::find($req->edit_id);
  929. $data->feedback_msg =$req->feedback_msg;
  930. $data->update();
  931. return response(['msg'=>'Updated successfully.']);
  932. }elseif($name=="delete_student_feedback_msg"){
  933. $data =StudentProposal::find($req->delete_id);
  934. $data->feedback_msg =NULL;
  935. $data->update();
  936. return response(['msg'=>'Deleted successfully.']);
  937. }
  938. }
  939. }