/**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request)
 {
     $emails = ['*****@*****.**'];
     Mail::send('mails.welcome', ['name' => 'Angela Namikoye, Brian Phiri'], function ($message) use($emails) {
         $message->to($emails)->from('*****@*****.**', 'strath')->subject('This is test email');
     });
     $user = Auth::user()->regNo;
     student::where('studentNo', '=', $user)->update(['state' => 'Activated']);
     Session::flash('flash_msg', 'You have initiated the clearance process');
     return redirect('/student');
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request)
 {
     $user = Auth::user()->regNo;
     $res = DB::table('students')->select('faculty')->where('studentNo', '=', $user)->pluck('faculty');
     //Query below gets the email of the specific administrator
     $admin = DB::table('departments')->join('administrators', 'departments.administrator', '=', 'administrators.admin_id')->select('administrators.email')->where('departments.department_name', '=', $res)->pluck('email');
     Mail::send('mails.welcome', ['name' => 'Angela Namikoye, Brian Phiri'], function ($message) use($admin) {
         $message->to($admin)->from('*****@*****.**', 'Strathmore University')->subject('Clearance Request');
     });
     student::where('studentNo', '=', $user)->update(['state' => 'Activated']);
     Session::flash('flash_msg', 'You have initiated the clearance process');
     return redirect('/student');
 }
 public function studentPdf(Request $request)
 {
     $post = $request->all();
     $user = $post['student'];
     $std = student::where('studentNo', '=', $user)->first();
     $charge = charges::where('students_studentNo', '=', $user)->first();
     $serial = Serial::where('students_studentNo', '=', $user)->first();
     if ($charge->total == 0) {
         $html = PDF::make($std, $serial);
     } else {
         $html = PDF::create($std, $charge, $serial);
     }
     $mpdf = new mpdf();
     $mpdf->WriteHTML($html);
     $mpdf->Output();
 }
 public function index()
 {
     Cas::getCurrentUser();
     $user = session('cas_user');
     $client = new \GuzzleHttp\Client();
     // $response = $client->get('http://testserver.strathmore.edu:8082/dataservice/student/getStudent/'.$user);
     $responseStudent = file_get_contents('http://testserver.strathmore.edu:8082/dataservice/student/getStudent/' . $user);
     $responseStaff = file_get_contents('http://testserver.strathmore.edu:8082/dataservice/staff/getStaff/' . $user);
     // check to see if the logged in user is a student
     if ($responseStaff == '' && $responseStudent != '') {
         $student = json_decode($responseStudent, true);
         // check to see if student has already initiated the clearance process
         // if student has not requested to be cleared, he/she is taken to the clear request page
         $std = student::where('studentNo', '=', $user)->first();
         // for testing, delete after test
         // if($student['studentNo'] == '78699'){
         //   return redirect()->intended('/cafeteria');
         // }
         //If the query has a result ...
         if ($std === null) {
             return view('clearance.init')->with('student', $student);
         } else {
             $charge = charges::where('students_studentNo', '=', $user)->first();
             $comment = comment::where('students_studentNo', '=', $user)->first();
             return view('clearance.index')->with('std', $std)->with('charge', $charge)->with('comment', $comment);
         }
     } elseif ($responseStaff != '' && $responseStudent == '') {
         $staffMember = json_decode($responseStaff, true);
         $department_staff_belongs_to = $staffMember['departmentShortName'];
         $check_admin = DB::table('administrators')->where('payroll_number', '=', $staffMember['payroll_number'])->get();
         if ($check_admin == null) {
             return "Not Authorized";
         } else {
             // redirect the staff member to thier page depending on the school they admin..
             $is_auth = DB::table('administrators')->where('payroll_number', '=', $staffMember['payroll_number'])->select('administrators.state')->get();
             if ($is_auth != 'Authorised') {
                 return "Not Authorized";
             } else {
                 if ($department_staff_belongs_to == 'FIT') {
                     return redirect()->intended('/fit');
                 } else {
                     if ($department_staff_belongs_to == "SLS") {
                         return redirect()->intended('/sls');
                     } else {
                         if ($department_staff_belongs_to == "SBS") {
                             return redirect()->intended('/sbs');
                         } else {
                             if ($department_staff_belongs_to == "SFAE") {
                                 return redirect()->intended('/sfae');
                             } else {
                                 if ($department_staff_belongs_to == "CTH") {
                                     return redirect()->intended('/cth');
                                 } else {
                                     if ($department_staff_belongs_to == "SOA") {
                                         return redirect()->intended('/soa');
                                     } else {
                                         if ($department_staff_belongs_to == "MTI") {
                                             return redirect()->intended('/mti');
                                         } else {
                                             if ($department_staff_belongs_to == "SHSS") {
                                                 return redirect()->intended('/shss');
                                             } else {
                                                 if ($department_staff_belongs_to == "SMC") {
                                                     return redirect()->intended('/smc');
                                                 } else {
                                                     // if the admin does not admin a school. Query by department name
                                                     if ($department_staff_belongs_to == "CAFETERIA") {
                                                         return redirect()->intended('/cafeteria');
                                                     } else {
                                                         if ($department_staff_belongs_to == "LIBRARY") {
                                                             return redirect()->intended('/library');
                                                         } else {
                                                             if ($department_staff_belongs_to == "FINANCE") {
                                                                 return redirect()->intended('/finance');
                                                             } else {
                                                                 if ($department_staff_belongs_to == "FINANCIAL AID") {
                                                                     return redirect()->intended('/financialAid');
                                                                 } else {
                                                                     if ($department_staff_belongs_to == "GAMES") {
                                                                         return redirect()->intended('/games');
                                                                     } else {
                                                                         if ($department_staff_belongs_to == "EXTRA CURRICULAR ACTIVITIES") {
                                                                             return redirect()->intended('/extraCurricularActivities');
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show()
 {
     $user = Auth::user()->regNo;
     $std = student::where('studentNo', '=', $user)->first();
     $charge = charges::where('students_studentNo', '=', $user)->first();
     if ($charge->total == 0) {
         $html = PDF::make($std);
     } else {
         $html = PDF::create($std, $charge);
     }
     $mpdf = new mpdf();
     $mpdf->WriteHTML($html);
     $mpdf->Output();
 }