/**
  * Delete a student registration request
  *
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function deleteRequest(Request $request)
 {
     $rollNo = $request['rollNo'];
     // Delete the request from all associated tables
     AllocatedElective::where('rollNo', $rollNo)->delete();
     Grade::where('rollNo', $rollNo)->delete();
     HostelStaffRequest::destroy($rollNo);
     TeacherRequest::destroy($rollNo);
     AdminStaffRequest::destroy($rollNo);
     LibraryStaffRequest::destroy($rollNo);
     ChiefWardenStaffRequest::destroy($rollNo);
     // If the student has been verified, then decrement his/her semester
     if (CurrentStudentState::find($rollNo)->approved == true) {
         $student = Student::find($rollNo);
         $student->semNo = $student->semNo - 1;
         $student->save();
     }
     CurrentStudentState::destroy($rollNo);
     return redirect('/teachers/semesterRegistration/studentRequests/all');
 }
 /**
  * Set registration process active / in-active
  *
  * @param $user
  * @return mixed
  */
 public function toggleRegistrationProcess($user)
 {
     if ($user === 'staff') {
         if ($this->isRegistrationActive('staff')) {
             unlink(storage_path() . '/app/activeForStaff');
             // Clear the tables
             Grade::truncate();
             ElectiveCount::truncate();
             TeacherRequest::truncate();
             AllocatedElective::truncate();
             AdminStaffRequest::truncate();
             HostelStaffRequest::truncate();
             CurrentStudentState::truncate();
             LibraryStaffRequest::truncate();
             ChiefWardenStaffRequest::truncate();
             Teacher::where('semNo', '>', '0')->update(['semNo' => null]);
         } else {
             touch(storage_path() . '/app/activeForStaff');
         }
     } else {
         if ($user === 'students') {
             if ($this->isRegistrationActive('student')) {
                 unlink(storage_path() . '/app/activeForStudents');
             } else {
                 touch(storage_path() . '/app/activeForStudents');
             }
         }
     }
     return redirect()->back();
 }
 /**
  * Add fee and hostel details of the student and
  * send the corresponding approval requests
  *
  * @param Request $request
  * @return mixed
  */
 public function addFeeAndHostelDetails(Request $request)
 {
     $currentStudentState = $this->getCurrentStudentState();
     /*
      * Check if the fee receipt image is present. If present, then upload
      * the image and send the approval request to the teacher, otherwise
      * send the approval request to accounts branch for verification
      */
     if ($request->hasFile('image')) {
         $this->validate($request, ['image' => 'image|required|max:2048'], ['image' => 'The file must be a valid image file.']);
         if ($request->file('image')->isValid()) {
             $image = $request->file('image');
             $rollNo = Auth::guard('student')->user()->rollNo;
             // Set the image parameters
             $imageQuality = 70;
             $imagePath = env('IMAGE_DIR') . '/feeReceipts/' . $rollNo . '.jpg';
             // Save the image
             Image::make($image->getRealPath())->save($imagePath, $imageQuality);
             /*
              * Update the image path in the database
              * and send the request to the teacher
              */
             TeacherRequest::create(['rollNo' => Auth::guard('student')->user()->rollNo, 'semNo' => $currentStudentState->semNo, 'status' => 'new', 'imagePath' => $imagePath]);
         } else {
             return redirect()->back()->withErrors('Upload unsuccessful!!!');
         }
     } else {
         $loanCase = $currentStudentState->loanCase;
         // Send the request to accounts branch
         AdminStaffRequest::create(['rollNo' => Auth::guard('student')->user()->rollNo, 'status' => 'new', 'loanCase' => $loanCase]);
     }
     /*
      * Check if the hostelId is present. If present, then send the approval request to the
      * concerned hostel, otherwise send the approval request to chief warden office
      */
     if ($request->has('hostelId')) {
         $currentStudentState->hostelId = $request['hostelId'];
         $currentStudentState->save();
         // Send the request to the concerned hostel
         HostelStaffRequest::create(['rollNo' => Auth::guard('student')->user()->rollNo, 'hostelId' => $request['hostelId'], 'status' => 'new']);
     } else {
         // Send the request to chief warden office for approval
         ChiefWardenStaffRequest::create(['rollNo' => Auth::guard('student')->user()->rollNo, 'status' => 'new']);
     }
     // Send the request to library for approval
     LibraryStaffRequest::create(['rollNo' => Auth::guard('student')->user()->rollNo, 'status' => 'new']);
     $currentStudentState->step = 2;
     $currentStudentState->save();
     // Now redirect to next step
     return redirect('/students/semesterRegistration/courseDetails');
 }
 /**
  * Hold a student registration request
  *
  * @param Request $request
  * @return mixed
  */
 public function holdRequest(Request $request)
 {
     if (!$this->isRegistrationActive('staff')) {
         return view($this->inactiveView);
     }
     $rollNo = $request['rollNo'];
     $remarks = $request['remarks'];
     // Update the status of the student request as
     // pending and add the appropriate remarks
     LibraryStaffRequest::find($rollNo)->update(['status' => 'pending', 'remarks' => $remarks]);
     return redirect('/libraryStaffs/semesterRegistration/studentRequests/new');
 }