AjaxController.php 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088
  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. $data =StudentProposal::find($req->id);
  286. $data->proposal_status =$req->value;
  287. $data->proposal_status_date =now();
  288. $data->feedback_msg =NULL;
  289. $data->update();
  290. if($req->value){
  291. $user_data = User::find($data->student_id);
  292. $user_data->freez_profile =2; // 2 = [In Review,Pause,Interested]
  293. $user_data->update();
  294. }
  295. return response(
  296. ['msg'=>'Updated successfully.']
  297. );
  298. }elseif($name=="proposal_feedback_update"){
  299. $validator=\Validator::make($req->all(), [
  300. 'message'=>'required',
  301. ]);
  302. if($validator->fails()){
  303. $errors=$validator->errors()->all();
  304. return response(['msg'=>$errors[0]], 422);
  305. }
  306. $data =StudentProposal::find($req->id);
  307. $data->proposal_status =$req->proposal_status;
  308. $data->feedback_msg =$req->message;
  309. $data->proposal_status_date =now();
  310. $data->update();
  311. if($req->proposal_status ==3){ // 3= rejected
  312. $user_rejected = User::find($data->student_id);
  313. $user_rejected->freez_profile =0;
  314. $user_rejected->update();
  315. }
  316. return response(
  317. ['msg'=>'Updated successfully.']
  318. );
  319. }elseif($name=="accept_status_update"){
  320. $data =StudentProposal::find($req->id);
  321. $data->accepted_status =1;
  322. $data->accepted_date =now();
  323. $data->update();
  324. $user_accepted = User::find($data->student_id);
  325. $user_accepted->freez_profile =0;
  326. $user_accepted->update();
  327. return response([
  328. 'msg'=>'Updated successfully.'
  329. ]);
  330. }elseif($name=="proposal_quality_rate_star_update"){
  331. $data =StudentProposal::find($req->id);
  332. $data->proposal_quality =$req->value;
  333. $data->update();
  334. return response([
  335. 'msg'=>'Updated successfully.'
  336. ]);
  337. }elseif($name=="teacher_is_available"){
  338. $user =Auth::guard('teacher')->user();
  339. $data =User::find($user->id);
  340. if($req->checked =="true"){
  341. $data->is_available =1;
  342. }else{
  343. $data->is_available =0;
  344. }
  345. $data->update();
  346. return response(
  347. ['msg'=>"Updated Successfully."]
  348. );
  349. }elseif($name=="student_q_form"){
  350. $validator=\Validator::make($req->all(), [
  351. 'name'=>'required',
  352. 'email'=>'required|email|max:255'
  353. ]);
  354. if($validator->fails()){
  355. $errors=$validator->errors()->all();
  356. return response(['msg'=>$errors[0]], 422);
  357. }
  358. $user =User::where('email',$req->email)->where('user_type',1)->first();
  359. if($user){
  360. $is_student_proposal_exists =StudentProposal::where(
  361. 'teacher_id',$req->id
  362. )->where(
  363. 'student_id',$user->id
  364. )->whereIn(
  365. 'proposal_status',[1,2,3,4] // 1 =New; 2 =In Review; 3=Push; 4=Hold;
  366. )->exists();
  367. if($is_student_proposal_exists){
  368. return response(
  369. ['msg'=>'Already pending a proposal'],403
  370. );
  371. }else{
  372. $student_proposal =new StudentProposal;
  373. $student_proposal->student_id =$user->id;
  374. $student_proposal->teacher_id =$req->id;
  375. $student_proposal->draft_status =1;
  376. $student_proposal->save();
  377. $refer =new ReferUser;
  378. $refer->name =$req->name;
  379. $refer->email =$req->email;
  380. $refer->refer_by =$user->id;
  381. $refer->teacher_id =$req->id;
  382. $refer->q_form_status =1;
  383. $refer->save();
  384. }
  385. }else{
  386. $user_data =new User;
  387. $user_data->first_name =$req->name;
  388. $user_data->email =$req->email;
  389. $user_data->user_type =1;
  390. $user_data->status =0;
  391. $user_data->register_type =3; // 1=invitation ; 2= landing/wishlish; 3 =q_form ; 4=student_wishlist
  392. $user_data->invitation_date =now();
  393. $user_data->wishlist_teacher_id =$req->id;
  394. $user_data->save();
  395. $student_proposal =new StudentProposal;
  396. $student_proposal->student_id =$user->id;
  397. $student_proposal->teacher_id =$req->id;
  398. $student_proposal->draft_status =1;
  399. $student_proposal->save();
  400. $refer =new ReferUser;
  401. $refer->name =$req->name;
  402. $refer->email =$req->email;
  403. $refer->refer_by =$user->id;
  404. $refer->teacher_id =$req->id;
  405. $refer->q_form_status =1;
  406. $refer->save();
  407. if($refer->save()){
  408. $teacher = User::find($refer->teacher_id);
  409. if($teacher->others_department){
  410. $department =$teacher->others_department;
  411. }else{
  412. $department = cn($teacher,'department_name.name','');
  413. }
  414. if($teacher->university_name){
  415. $university =$teacher->university_name;
  416. }else{
  417. $university = cn($teacher,'university.name','');
  418. }
  419. $data['name'] = $refer->name;
  420. $data['student_id'] = $user->id;
  421. $data['teacher'] = $teacher->first_name.' '.$teacher->last_name;
  422. $data['arn'] = $teacher->ref_no;
  423. $data['designation'] = $teacher->designation;
  424. $data['department'] = $department;
  425. $data['university'] = $university;
  426. $data['email'] =$refer->email;
  427. $data['receive_email']=$refer->email;
  428. $user_mail = $refer->email;
  429. $from = 'asraful@revinr.com';
  430. Mail::send('email.q_form_email',$data, function ($message) use ($user_mail,$from) {
  431. $message->from($from);
  432. $message->to($user_mail)->subject('Invitation to submit your doctoral application');
  433. });
  434. }
  435. }
  436. return response(
  437. ['msg'=>'Saved successfully.']
  438. );
  439. }elseif($name=="q_apply_wishlist_registration_save"){
  440. $validator=\Validator::make($req->all(), [
  441. 'first_name'=>'required',
  442. 'last_name'=>'required',
  443. 'dob'=>'required',
  444. 'gender'=>'required',
  445. 'nationality'=>'required',
  446. 'email'=>'required',
  447. 'password_confirmation'=>'required',
  448. 'password'=>[
  449. 'required',
  450. 'confirmed',
  451. 'min:8',
  452. ]
  453. ]);
  454. if($validator->fails()){
  455. $errors=$validator->errors()->all();
  456. return response(['msg'=>$errors[0]], 422);
  457. }
  458. $token =Str::random(64);
  459. $user_check = User::where(
  460. 'id',$req->id
  461. )->where(
  462. 'sign_up',1
  463. )->first();
  464. if($user_check){
  465. // return redirect()->to("/login")->with('success','You are already registered. Please login here.');
  466. return response(
  467. ['msg'=>'You are already registered.','action'=>'redirect']
  468. );
  469. }
  470. $user_data = User::find($req->id);
  471. $user_data->first_name =$req->first_name;
  472. $user_data->last_name =$req->last_name;
  473. $user_data->first_name =$req->first_name;
  474. $user_data->nationality =$req->nationality;
  475. $user_data->dob =\Carbon\Carbon::parse($req->dob)->format('Y-m-d');
  476. $user_data->gender =$req->gender;
  477. $user_data->password =Hash::make($req->password);
  478. $user_data->status =0;
  479. $user_data->sign_up =1;
  480. $user_data->registered_date =now();
  481. //$user_data->email_verification=1;
  482. $user_data->remember_token=$token;
  483. //$user_data->email_verified_at=now();
  484. $user_data->update();
  485. $data['name'] = $user_data->first_name .' '.$user_data->last_name;
  486. $data['token']=$token;
  487. $data['receive_email']=$user_data->email;
  488. $user_mail = $user_data->email;
  489. $from = 'asraful@revinr.com';
  490. Mail::send('email.q_apply_wishlist_registration_email',$data, function ($message) use ($user_mail,$from) {
  491. $message->from($from);
  492. $message->to($user_mail)->subject('Thank You for joining us!');
  493. });
  494. return response(
  495. ['msg'=>'Successfully saved. Please check your email for verify.']
  496. );
  497. }elseif($name=="invitation_register_save"){
  498. $validator=\Validator::make($req->all(), [
  499. 'first_name'=>'required',
  500. 'last_name'=>'required',
  501. 'email'=>'required',
  502. 'university'=>'required',
  503. 'others_department'=>'required',
  504. 'designation'=>'required',
  505. 'password_confirmation'=>'required',
  506. 'password'=>[
  507. 'required',
  508. 'confirmed',
  509. 'min:8',
  510. ]
  511. ]);
  512. if($validator->fails()){
  513. $errors=$validator->errors()->all();
  514. return response(['msg'=>$errors[0]], 422);
  515. }
  516. $isExists = User::where(
  517. 'id',$req->id
  518. )->where(
  519. 'user_type',2
  520. )->where(
  521. 'sign_up',1
  522. )->first();
  523. if($isExists){
  524. return response(
  525. ['msg'=>'You are already registered.','action'=>'redirect']
  526. );
  527. }else{
  528. $user_data = User::find($req->id);
  529. $user_data->first_name =$req->first_name;
  530. $user_data->last_name =$req->last_name;
  531. $user_data->university_name =$req->university;
  532. $user_data->ref_no = name_initials($req->first_name,$req->last_name).''.teacherRefNoGenerate();
  533. //$user_data->department =$req->department;
  534. $user_data->others_department =$req->others_department;
  535. $user_data->designation =$req->designation;
  536. $user_data->uni_website =$req->website;
  537. $user_data->password =Hash::make($req->password);
  538. $user_data->status =1;
  539. $user_data->sign_up = 1; // 1=signup
  540. $user_data->user_type = 2;
  541. $user_data->registered_date = now();
  542. $user_data->update();
  543. if($user_data->update()){
  544. $data['name'] = $user_data->first_name .' '.$user_data->last_name;
  545. $data['receive_email']=$user_data->email;
  546. $user_mail = $user_data->email;
  547. $from = 'asraful@revinr.com';
  548. Mail::send('email.register_teacher_email',$data, function ($message) use ($user_mail,$from) {
  549. $message->from($from);
  550. $message->to($user_mail)->subject('We’re excited to have you as a member of our community');
  551. });
  552. }
  553. }
  554. return response(
  555. ['msg'=>'Registration successfully saved.']
  556. );
  557. }elseif($name=="delete_doc_required"){
  558. $requirements=Requirement::find($req->delete_id);
  559. $requirements->delete();
  560. return response([
  561. 'msg'=>'Deleted Successfully.'
  562. ]);
  563. }elseif($name=="document_required_upload_save"){
  564. $rules=[
  565. 'id'=>'required',
  566. 'document_file' => 'required',
  567. ];
  568. $validator=\Validator::make($req->all(), $rules);
  569. if($validator->fails()){
  570. $errors=$validator->errors()->all();
  571. return response(['msg'=>$errors[0]], 422);
  572. }
  573. $data=Requirement::find($req->id);
  574. $std_ref = StudentProposal::find($data->std_proposal_id);
  575. if($req->document_file){
  576. $destinationPath = public_path('/uploads/required_doc');
  577. $file = $req->document_file;
  578. $ext = $file->getClientOriginalExtension();
  579. $fileName = 'document_file_'.$std_ref->student_apply_ref.'.'.$ext;
  580. if(file_exists($destinationPath.'/'.$fileName)){
  581. @unlink($destinationPath.'/'.$fileName);
  582. }
  583. $file->move($destinationPath, $fileName);
  584. $data->document_file = $fileName;
  585. }
  586. $data->update();
  587. return response([
  588. 'msg'=>'Successfully uploaded.'
  589. ]);
  590. }elseif($name=="update_proposal"){
  591. $user=auth_user();
  592. $validator=\Validator::make($req->all(), [
  593. 'title'=>'required',
  594. 'methology'=>'required',
  595. 'department'=>'required',
  596. ]);
  597. if($validator->fails()){
  598. $errors=$validator->errors()->all();
  599. return response(['msg'=>$errors[0]], 422);
  600. }
  601. $data =Proposal::find($req->edit_id);
  602. $data->title =$req->title;
  603. $data->methology= $req->methology;
  604. $data->department= $req->department;
  605. $data->status= $req->status;
  606. if($req->documentfile){
  607. $destinationPath = public_path('/uploads/proposal');
  608. $file = $req->documentfile;
  609. $ext = $file->getClientOriginalExtension();
  610. $fileName = time().'documentfile_'.'.'.$ext;
  611. if(file_exists($destinationPath.'/'.$fileName)){
  612. @unlink($destinationPath.'/'.$fileName);
  613. }
  614. $file->move($destinationPath, $fileName);
  615. $data->document_file = $fileName;
  616. }
  617. $data->update();
  618. return response([
  619. 'msg'=>'Successfully updated.'
  620. ]);
  621. }elseif($name=="edit_register_teacher_save"){
  622. $validator=\Validator::make($req->all(), [
  623. 'first_name'=>'required',
  624. 'last_name'=>'required',
  625. 'university'=>'required',
  626. 'department'=>'required',
  627. 'designation'=>'required',
  628. ]);
  629. if($validator->fails()){
  630. $errors=$validator->errors()->all();
  631. return response(['msg'=>$errors[0]], 422);
  632. }
  633. $user_data = User::find($req->edit_id);
  634. $user_data->first_name =$req->first_name;
  635. $user_data->last_name =$req->last_name;
  636. $user_data->university_id =$req->university;
  637. $user_data->university_name = NULL;
  638. $user_data->department =$req->department;
  639. $user_data->others_department = NULL;
  640. $user_data->designation =$req->designation;
  641. $user_data->uni_website =$req->uni_website;
  642. $user_data->update();
  643. return response(
  644. ['msg'=>'Successfully updated.']
  645. );
  646. }elseif($name=="landing_invitation_email_send"){
  647. $user_data =User::find($req->id);
  648. $user_data->invitation_date =now();
  649. $user_data->update();
  650. if($user_data->update()){
  651. $data['name'] = $user_data->first_name .' '.$user_data->last_name;
  652. $data['receive_email']=$user_data->email;
  653. $user_mail = $user_data->email;
  654. $data['teacher_id'] = $user_data->id;
  655. $data['email'] = $user_data->email;
  656. $from = 'asraful@revinr.com';
  657. Mail::send('email.invitation_to_supervisor_email',$data, function ($message) use ($user_mail,$from) {
  658. $message->from($from);
  659. $message->to($user_mail)->subject('Manage Doctoral Applicants with Ease - You’re invited!');
  660. });
  661. }
  662. return response(
  663. ['msg'=>'Invitation sent successfully.']
  664. );
  665. }elseif($name=="delete_research_info"){
  666. $user=Auth::guard('teacher')->user();
  667. $data =ResearchInterest::find($req->delete_id);
  668. $data->delete();
  669. return response([
  670. 'msg'=>'Successfully Deleted'
  671. ]);
  672. }elseif($name=="edit_research_save"){
  673. $user=Auth::guard('teacher')->user();
  674. $validator=\Validator::make($req->all(), [
  675. 'research'=>'required',
  676. ]);
  677. if($validator->fails()){
  678. $errors=$validator->errors()->all();
  679. return response(['msg'=>$errors[0]], 422);
  680. }
  681. $data =ResearchInterest::find($req->edit_id);
  682. $data->research =$req->research;
  683. $data->update();
  684. return response([
  685. 'msg'=>'Successfully updated.'
  686. ]);
  687. }elseif($name=="add_proposal_publication"){
  688. $student=Auth::user();
  689. $validator=\Validator::make($req->all(), [
  690. 'publication'=>'required',
  691. 'status'=>'required',
  692. ]);
  693. if($validator->fails()){
  694. $errors=$validator->errors()->all();
  695. return response(['msg'=>$errors[0]], 422);
  696. }
  697. $data =new Publication;
  698. $data->student_id =$student->id;
  699. $data->publication =$req->publication;
  700. $data->status =$req->status;
  701. $data->save();
  702. return response([
  703. 'msg'=>'Successfully saved.'
  704. ]);
  705. }elseif($name=="update_publication"){
  706. $student=Auth::user();
  707. $validator=\Validator::make($req->all(), [
  708. 'publication'=>'required',
  709. 'status'=>'required',
  710. ]);
  711. if($validator->fails()){
  712. $errors=$validator->errors()->all();
  713. return response(['msg'=>$errors[0]], 422);
  714. }
  715. $data =Publication::find($req->edit_id);
  716. $data->student_id = $student->id;
  717. $data->publication = $req->publication;
  718. $data->status = $req->status;
  719. $data->update();
  720. return response([
  721. 'msg'=>'Successfully updated.'
  722. ]);
  723. }elseif($name=="delete_publication_info"){
  724. $data =Publication::find($req->delete_id);
  725. $data->delete();
  726. return response([
  727. 'msg'=>'Successfully deleted.'
  728. ]);
  729. }elseif($name=="is_attended_conference_status"){
  730. $data =User::find($req->uid);
  731. if($req->checked =='yes'){
  732. $data->is_attended_conference =1; // 1=yes
  733. }else{
  734. $data->is_attended_conference =2; // 2=no
  735. }
  736. $data->update();
  737. return response([
  738. 'msg'=>'Successfully saved.'
  739. ]);
  740. }elseif($name=="work_experience_status_update"){
  741. $data =User::find($req->uid);
  742. if($req->value =='yes'){
  743. $data->is_work_experience =1; // 1=yes
  744. }else{
  745. $data->is_work_experience =2; // 2=no
  746. }
  747. $data->update();
  748. return response([
  749. 'msg'=>'Successfully saved.'
  750. ]);
  751. }elseif($name=="publication_status_update"){
  752. $data =User::find($req->uid);
  753. if($req->value =='yes'){
  754. $data->is_publication =1; // 1=yes
  755. }else{
  756. $data->is_publication =2; // 2=no
  757. }
  758. $data->update();
  759. return response([
  760. 'msg'=>'Successfully saved.'
  761. ]);
  762. }elseif($name=="education_status_update"){
  763. $data =User::find($req->uid);
  764. if($req->value =='yes'){
  765. $data->is_education =1; // 1=yes
  766. }else{
  767. $data->is_education =2; // 2=no
  768. }
  769. $data->update();
  770. return response([
  771. 'msg'=>'Successfully saved.'
  772. ]);
  773. }elseif($name=="update_education_history"){
  774. $student=Auth::user();
  775. $validator=\Validator::make($req->all(), [
  776. 'academiclevel'=>'required',
  777. 'subject'=>'required',
  778. 'institution'=>'required',
  779. 'passingyear'=>'required',
  780. 'result'=>'required',
  781. ]);
  782. if($validator->fails()){
  783. $errors=$validator->errors()->all();
  784. return response(['msg'=>$errors[0]], 422);
  785. }
  786. $institution= Institution::find($req->edit_id);
  787. $institution->student_id= $student->id;
  788. $institution->academic_level= $req->academiclevel;
  789. $institution->subject= $req->subject;
  790. $institution->institution= $req->institution;
  791. $institution->passing_year= $req->passingyear;
  792. $institution->result= $req->result;
  793. $institution->update();
  794. return response([
  795. 'msg'=>'Successfully updated.'
  796. ]);
  797. }elseif($name=="delete_education_info"){
  798. $data =Institution::find($req->delete_id);
  799. $data->delete();
  800. return response([
  801. 'msg'=>'Successfully deleted.'
  802. ]);
  803. }elseif($name=="update_english_languge_proficiency"){
  804. $student=Auth::user();
  805. $validator=\Validator::make($req->all(), [
  806. 'testdate'=>'required',
  807. 'expirationdate'=>'required',
  808. 'testname'=>'required',
  809. 'overallscore'=>'required',
  810. 'listening'=>'required',
  811. 'speaking'=>'required',
  812. 'writing'=>'required',
  813. 'reading'=>'required',
  814. ]);
  815. if($validator->fails()){
  816. $errors=$validator->errors()->all();
  817. return response(['msg'=>$errors[0]], 422);
  818. }
  819. $score= Score::find($req->edit_id);
  820. $score->student_id= $student->id;
  821. $score->test_date= Carbon::parse($req->testdate)->format('Y-m-d');
  822. $score->expiration_date= Carbon::parse($req->expirationdate)->format('Y-m-d');
  823. $score->test_name= $req->testname;
  824. $score->overall_score= $req->overallscore;
  825. $score->listening= $req->listening;
  826. $score->writing= $req->speaking;
  827. $score->reading= $req->writing;
  828. $score->speaking= $req->reading;
  829. $score->update();
  830. return response([
  831. 'msg'=>'Successfully updated.'
  832. ]);
  833. }elseif($name=="delete_score_info"){
  834. $data =Score::find($req->delete_id);
  835. $data->delete();
  836. return response([
  837. 'msg'=>'Successfully deleted.'
  838. ]);
  839. }elseif($name=="update_work_experience"){
  840. $student=Auth::user();
  841. $validator=\Validator::make($req->all(), [
  842. 'companyname'=>'required',
  843. 'designation'=>'required',
  844. 'startdate'=>'required',
  845. 'enddate'=>'required',
  846. ]);
  847. if($validator->fails()){
  848. $errors=$validator->errors()->all();
  849. return response(['msg'=>$errors[0]], 422);
  850. }
  851. $work_experience= Workexperience::find($req->edit_id);
  852. $work_experience->student_id= $student->id;
  853. $work_experience->company_name= $req->companyname;
  854. $work_experience->designation= $req->designation;
  855. if($req->currently_working=='on'){
  856. $work_experience->currently_working=1;
  857. }else{
  858. $work_experience->currently_working=0;
  859. }
  860. $work_experience->start_date= date($req->startdate.'-'.$req->startmonth.'-01');
  861. $work_experience->end_date= date($req->enddate.'-'.$req->endmonth.'-01');
  862. $work_experience->update();
  863. return response([
  864. 'msg'=>'Successfully updated.'
  865. ]);
  866. }elseif($name=="delete_work_experience_info"){
  867. $data =Workexperience::find($req->delete_id);
  868. $data->delete();
  869. return response([
  870. 'msg'=>'Successfully deleted.'
  871. ]);
  872. }elseif($name=="test_score_status_update"){
  873. $data =User::find($req->uid);
  874. if($req->value =='yes'){
  875. $data->is_test_score =1; // 1=yes
  876. }else{
  877. $data->is_test_score =2; // 2=no
  878. }
  879. $data->update();
  880. return response([
  881. 'msg'=>'Successfully saved.'
  882. ]);
  883. }elseif($name=="all_publication_delete"){
  884. Publication::where('student_id',$req->uid)->delete();
  885. return response([
  886. 'msg'=>'Successfully delete.'
  887. ]);
  888. }elseif($name=="all_education_history_delete"){
  889. Institution::where('student_id',$req->uid)->delete();
  890. return response([
  891. 'msg'=>'Successfully delete.'
  892. ]);
  893. }elseif($name=="all_work_experience_delete"){
  894. Workexperience::where('student_id',$req->uid)->delete();
  895. return response([
  896. 'msg'=>'Successfully delete.'
  897. ]);
  898. }elseif($name=="all_test_score_delete"){
  899. Score::where('student_id',$req->uid)->delete();
  900. return response([
  901. 'msg'=>'Successfully delete.'
  902. ]);
  903. }elseif($name=="update_feedback_msg"){
  904. $data =StudentProposal::find($req->edit_id);
  905. $data->feedback_msg =$req->feedback_msg;
  906. $data->update();
  907. return response(['msg'=>'Updated successfully.']);
  908. }elseif($name=="delete_student_feedback_msg"){
  909. $data =StudentProposal::find($req->delete_id);
  910. $data->feedback_msg =NULL;
  911. $data->update();
  912. return response(['msg'=>'Deleted successfully.']);
  913. }
  914. }
  915. }