diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 5d3c59e..48c68af 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -38,4 +38,16 @@ class AdminController extends Controller { return view('booksPublished.index'); } + public function viewExternalEngagementResponses() + { + return view('externalEngagement.index'); + } + public function viewOnlineCoursesResponses() + { + return view('onlineCourses.index'); + } + public function viewPatentsResponses() + { + return view('patents.index'); + } } diff --git a/app/Http/Controllers/CoordinatorController.php b/app/Http/Controllers/CoordinatorController.php index 455774e..5feb1e6 100644 --- a/app/Http/Controllers/CoordinatorController.php +++ b/app/Http/Controllers/CoordinatorController.php @@ -41,4 +41,17 @@ class CoordinatorController extends Controller return view('booksPublished.index'); } + public function viewExternalEngagementResponses() + { + return view('externalEngagement.index'); + } + public function viewOnlineCoursesResponses() + { + return view('onlineCourses.index'); + } + public function viewPatentsResponses() + { + return view('patents.index'); + } + } diff --git a/app/Http/Controllers/ExternalEngagementController.php b/app/Http/Controllers/ExternalEngagementController.php new file mode 100644 index 0000000..f1f05e0 --- /dev/null +++ b/app/Http/Controllers/ExternalEngagementController.php @@ -0,0 +1,227 @@ +validate([ + 'activity' => 'required|string', + 'activity_description' => 'required|string', + 'inviting_organization' => 'required|string', + 'start_date' => 'required|date', + 'end_date' => 'required|date', + 'num_days' => 'required|integer', + 'proof' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip', + ]); + + // Handle the file upload if a new file is provided + if ($request->hasFile('proof')) { + // Delete old file if exists + if ($externalEngagement->proof && Storage::disk('public')->exists($externalEngagement->proof)) { + Storage::disk('public')->delete($externalEngagement->proof); + } + + // Extract year from start_date + $year = date('Y', strtotime($validated['start_date'])); + $username = $externalEngagement->user->name; + + $originalName = $request->file('proof')->getClientOriginalName(); + $fileName = $username . '_' . $originalName; + + // Create path structure: year/faculty_name + $folderPath = 'proofs/' . $year . '/' . $username . '/External Engagement'; + + // Store file in the specified path + $proofPath = $request->file('proof')->storeAs($folderPath, $fileName, 'public'); + + $externalEngagement->proof = $proofPath; + } + + + // Update other fields + $externalEngagement->activity = $validated['activity']; + $externalEngagement->activity_description = $validated['activity_description']; + $externalEngagement->inviting_organization = $validated['inviting_organization']; + $externalEngagement->start_date = $validated['start_date']; + $externalEngagement->end_date = $validated['end_date']; + $externalEngagement->num_days = $validated['num_days']; + + $externalEngagement->save(); + + $userRole = auth()->user()->role->name; + + if ($userRole === 'Admin') { + return redirect()->route('admin.ExternalEngagementResponses') + ->with('status', 'External Engagement updated successfully'); + } elseif ($userRole === 'Coordinator') { + return redirect()->route('coordinator.ExternalEngagementResponses') + ->with('status', 'External Engagement updated successfully'); + } else { + // For regular users + return redirect()->route('faculty.ExternalEngagementResponses') + ->with('status', 'External Engagement updated successfully'); + } + } + + public function destroy($id) + { + $externalEngagement = ExternalEngagement::findOrFail($id); + + // Delete the file if it exists + if ($externalEngagement->proof && Storage::disk('public')->exists($externalEngagement->proof)) { + Storage::disk('public')->delete($externalEngagement->proof); + } + + $externalEngagement->delete(); + + return response()->json(['success' => 'External Engagement record deleted successfully']); + } + + public function getExternalEngagementResponses() + { + $user = auth()->user(); + $isAdmin = $user->role->name === 'Admin'; + $isCoordinator = $user->role->name === 'Coordinator'; + + // Query based on role + if ($isAdmin) { + // Admin sees all records + $externalEngagements = ExternalEngagement::with('user', 'department'); + } elseif ($isCoordinator) { + // Coordinator sees only their department's records + $externalEngagements = ExternalEngagement::with('user', 'department') + ->whereHas('user', function ($query) use ($user) { + $query->where('department_id', $user->department_id); + }); + } else { + // Regular users see only their own records + $externalEngagements = ExternalEngagement::with('user', 'department') + ->where('faculty_id', $user->id); + } + + + return DataTables::of($externalEngagements) + ->addColumn('user_name', function ($externalEngagement) { + return $externalEngagement->user->name ?? 'Unknown'; + }) + ->addColumn('department_name', function ($externalEngagement) { + return $externalEngagement->department->name ?? 'Unknown'; + }) + ->addColumn('activity', function ($externalEngagement) { + return $externalEngagement->activity ?? 'Unknown'; + }) + ->addColumn('activity_description', function ($externalEngagement) { + return $externalEngagement->activity_description ?? 'Unknown'; + }) + ->addColumn('inviting_organization', function ($externalEngagement) { + return $externalEngagement->inviting_organization ?? 'Unknown'; + }) + ->addColumn('start_date', function ($externalEngagement) { + return \Carbon\Carbon::parse($externalEngagement->start_date)->format('d-m-Y'); + }) + ->addColumn('end_date', function ($externalEngagement) { + return \Carbon\Carbon::parse($externalEngagement->end_date)->format('d-m-Y'); + }) + ->addColumn('num_days', function ($externalEngagement) { + return $externalEngagement->num_days ?? 'Unknown'; + }) + ->addColumn('action', function ($externalEngagement) { + $actions = []; + + // View proof button for everyone + if ($externalEngagement->proof) { + $actions[] = 'View'; + } else { + $actions[] = 'No Proof'; + } + + // Edit button with role-appropriate route + $userRole = auth()->user()->role->name; + // Determine the appropriate route based on user role + if ($userRole === 'Admin') { + $editRoute = route('admin.ExternalEngagement.edit', $externalEngagement->id); + } elseif ($userRole === 'Coordinator') { + $editRoute = route('coordinator.ExternalEngagement.edit', $externalEngagement->id); + } else { + $editRoute = route('faculty.ExternalEngagement.edit', $externalEngagement->id); + } + + $actions[] = 'Edit'; + + $deleteRoute = route('externalEngagement.destroy', $externalEngagement->id); + $actions[] = ''; + + return implode(' ', $actions); + }) + ->rawColumns(['action']) + ->make(true); + } + + public function store(Request $request) + { + // Validate the request data + $validated = $request->validate([ + 'activity' => 'required|string', + 'activity_description' => 'required|string', + 'inviting_organization' => 'required|string', + 'start_date' => 'required|date', + 'end_date' => 'required|date', + 'num_days' => 'required|integer', + 'faculty_id' => 'required|exists:users,id', + 'department_id' => 'required|exists:departments,id', + 'proof' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip', + ]); + + // Create new record + $externalEngagement = new ExternalEngagement(); + $externalEngagement->activity = $validated['activity']; + $externalEngagement->activity_description = $validated['activity_description']; + $externalEngagement->inviting_organization = $validated['inviting_organization']; + $externalEngagement->start_date = $validated['start_date']; + $externalEngagement->end_date = $validated['end_date']; + $externalEngagement->num_days = $validated['num_days']; + $externalEngagement->faculty_id = $validated['faculty_id']; + $externalEngagement->department_id = $validated['department_id']; + + // Handle the file upload + if ($request->hasFile('proof')) { + $user = auth()->user(); + $year = date('Y', strtotime($validated['start_date'])); + $username = $user->name; + + $originalName = $request->file('proof')->getClientOriginalName(); + $fileName = $username . '_' . $originalName; + + // Create path structure: year/faculty_name + $folderPath = 'proofs/' . $year . '/' . $username . '/External Engagement'; + + // Store file in the specified path + $proofPath = $request->file('proof')->storeAs($folderPath, $fileName, 'public'); + + $externalEngagement->proof = $proofPath; + } + + $externalEngagement->save(); + + return redirect()->route('faculty.ExternalEngagementResponses') + ->with('status', 'External Engagement submitted successfully'); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/FacultyController.php b/app/Http/Controllers/FacultyController.php index b691e04..aa27aaf 100644 --- a/app/Http/Controllers/FacultyController.php +++ b/app/Http/Controllers/FacultyController.php @@ -6,7 +6,10 @@ use Illuminate\Http\Request; use App\Models\ActivitiesAttended; use App\Models\ActivitiesOrganised; use App\Models\BooksPublished; +use App\Models\ExternalEngagement; use App\Models\IvOrganised; +use App\Models\OnlineCourse; +use App\Models\Patent; use App\Models\Publication; class FacultyController extends Controller @@ -72,6 +75,41 @@ class FacultyController extends Controller return view('booksPublished.index'); } + public function ExternalEngagementForm() + { + // Logic to show the response form + return view('faculty.externalEngagement-form'); + } + + public function viewExternalEngagementResponses() + { + return view('externalEngagement.index'); + } + + public function OnlineCoursesForm() + { + // Logic to show the response form + return view('faculty.onlineCourses-form'); + } + + public function viewOnlineCoursesResponses() + { + return view('onlineCourses.index'); + } + + public function PatentsForm() + { + // Logic to show the response form + return view('faculty.patents-form'); + } + + public function viewPatentsResponses() + { + return view('patents.index'); + } + + + public function ActivitiesAttendedFormResponse(Request $request) { try { @@ -410,4 +448,170 @@ class FacultyController extends Controller return back()->withErrors(['error' => 'An error occurred: ' . $e->getMessage()])->withInput(); } } + public function ExternalEngagementFormResponse(Request $request) + { + // dd($request->all()); + try { + // Validate the request data + $validated = $request->validate([ + 'activity' => 'required|string', + 'activity_description' => 'required|string', + 'inviting_organization' => 'required|string', + 'start_date' => 'required|date', + 'end_date' => 'required|date', + 'num_days' => 'required|integer', + 'proof' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip' + ]); + + // Handle the file upload + $proofFilePath = null; + if ($request->hasFile('proof')) { + $originalName = $request->file('proof')->getClientOriginalName(); + $username = auth()->user()->name; + $fileName = $username . '_' . $originalName; + + // Extract year from start_date + $year = date('Y', strtotime($validated['start_date'])); + + // Create path structure: year/faculty_name/Publications + $folderPath = 'proofs/' . $year . '/' . $username . '/External Engagement'; + + // Store file in the specified path + $proofFilePath = $request->file('proof')->storeAs($folderPath, $fileName, 'public'); + } + // dd($proofFilePath); + + // Save the response to the database + ExternalEngagement::create([ + 'department_id' => auth()->user()->department->id, + 'activity' => $validated['activity'], + 'activity_description' => $validated['activity_description'], + 'inviting_organization' => $validated['inviting_organization'], + 'start_date' => $validated['start_date'], + 'end_date' => $validated['end_date'], + 'num_days' => $validated['num_days'], + 'proof' => $proofFilePath, + 'faculty_id' => auth()->user()->id, + ]); + + return redirect()->route('faculty.dashboard')->with('status', 'External Engagement details submitted successfully'); + } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) { + return back()->withErrors(['error' => 'External Engagement not found.']); + } catch (\Illuminate\Validation\ValidationException $e) { + return back()->withErrors($e->validator)->withInput(); + } catch (\Exception $e) { + return back()->withErrors(['error' => 'An error occurred: ' . $e->getMessage()])->withInput(); + } + } + public function OnlineCoursesFormResponse(Request $request) + { + // dd($request->all()); + try { + // Validate the request data + $validated = $request->validate([ + 'course' => 'required|string', + 'offered_by' => 'required|string', + 'start_date' => 'required|date', + 'end_date' => 'required|date', + 'num_days' => 'required|integer', + 'proof' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip', + ]); + + // Handle the file upload + $proofFilePath = null; + if ($request->hasFile('proof')) { + $originalName = $request->file('proof')->getClientOriginalName(); + $username = auth()->user()->name; + $fileName = $username . '_' . $originalName; + + // Extract year from start_date + $year = date('Y', strtotime($validated['start_date'])); + + // Create path structure: year/faculty_name/Publications + $folderPath = 'proofs/' . $year . '/' . $username . '/Online Course'; + + // Store file in the specified path + $proofFilePath = $request->file('proof')->storeAs($folderPath, $fileName, 'public'); + } + // dd($proofFilePath); + + // Save the response to the database + OnlineCourse::create([ + 'department_id' => auth()->user()->department->id, + 'course' => $validated['course'], + 'offered_by' => $validated['offered_by'], + 'start_date' => $validated['start_date'], + 'end_date' => $validated['end_date'], + 'num_days' => $validated['num_days'], + 'proof' => $proofFilePath, + 'faculty_id' => auth()->user()->id, + ]); + + return redirect()->route('faculty.dashboard')->with('status', 'Online Course details submitted successfully'); + } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) { + return back()->withErrors(['error' => 'Online Course not found.']); + } catch (\Illuminate\Validation\ValidationException $e) { + return back()->withErrors($e->validator)->withInput(); + } catch (\Exception $e) { + return back()->withErrors(['error' => 'An error occurred: ' . $e->getMessage()])->withInput(); + } + } + public function PatentsFormResponse(Request $request) + { + // dd($request->all()); + try { + // Validate the request data + $validated = $request->validate([ + 'title' => 'required|string', + 'investigator' => 'required|string', + 'application_no' => 'required|string', + 'type' => 'required|string', + 'date_of_submission' => 'required|date', + 'date_of_filling' => 'required|date', + 'status' => 'required|string', + 'proof' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip', + ]); + + // Handle the file upload + $proofFilePath = null; + if ($request->hasFile('proof')) { + $originalName = $request->file('proof')->getClientOriginalName(); + $username = auth()->user()->name; + $fileName = $username . '_' . $originalName; + + // Extract year from start_date + $year = date('Y', strtotime($validated['date_of_submission'])); + + // Create path structure: year/faculty_name/Publications + $folderPath = 'proofs/' . $year . '/' . $username . '/Patents'; + + // Store file in the specified path + $proofFilePath = $request->file('proof')->storeAs($folderPath, $fileName, 'public'); + } + // dd($proofFilePath); + + + // Save the response to the database + Patent::create([ + 'department_id' => auth()->user()->department->id, + 'title' => $validated['title'], + 'investigator' => $validated['investigator'], + 'application_no' => $validated['application_no'], + 'type' => $validated['type'], + 'date_of_submission' => $validated['date_of_submission'], + 'date_of_filling' => $validated['date_of_filling'], + 'status' => $validated['status'], + 'proof' => $proofFilePath, + 'faculty_id' => auth()->user()->id, + ]); + + return redirect()->route('faculty.dashboard')->with('status', 'Patent/Copyright details submitted successfully'); + } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) { + return back()->withErrors(['error' => 'Patent/Copyright not found.']); + } catch (\Illuminate\Validation\ValidationException $e) { + return back()->withErrors($e->validator)->withInput(); + } catch (\Exception $e) { + return back()->withErrors(['error' => 'An error occurred: ' . $e->getMessage()])->withInput(); + } + } } diff --git a/app/Http/Controllers/OnlineCoursesController.php b/app/Http/Controllers/OnlineCoursesController.php new file mode 100644 index 0000000..a36004c --- /dev/null +++ b/app/Http/Controllers/OnlineCoursesController.php @@ -0,0 +1,220 @@ +validate([ + 'course' => 'required|string', + 'offered_by' => 'required|string', + 'start_date' => 'required|date', + 'end_date' => 'required|date', + 'num_days' => 'required|integer', + 'proof' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip', + ]); + + // Handle the file upload if a new file is provided + if ($request->hasFile('proof')) { + // Delete old file if exists + if ($onlineCourse->proof && Storage::disk('public')->exists($onlineCourse->proof)) { + Storage::disk('public')->delete($onlineCourse->proof); + } + + // Extract year from start_date + $year = date('Y', strtotime($validated['start_date'])); + $username = $onlineCourse->user->name; + + $originalName = $request->file('proof')->getClientOriginalName(); + $fileName = $username . '_' . $originalName; + + // Create path structure: year/faculty_name + $folderPath = 'proofs/' . $year . '/' . $username . '/Online Courses'; + + // Store file in the specified path + $proofPath = $request->file('proof')->storeAs($folderPath, $fileName, 'public'); + + $onlineCourse->proof = $proofPath; + } + + + // Update other fields + $onlineCourse->course = $validated['course']; + $onlineCourse->offered_by = $validated['offered_by']; + $onlineCourse->start_date = $validated['start_date']; + $onlineCourse->end_date = $validated['end_date']; + $onlineCourse->num_days = $validated['num_days']; + + $onlineCourse->save(); + + $userRole = auth()->user()->role->name; + + if ($userRole === 'Admin') { + return redirect()->route('admin.OnlineCoursesResponses') + ->with('status', 'online Course updated successfully'); + } elseif ($userRole === 'Coordinator') { + return redirect()->route('coordinator.OnlineCoursesResponses') + ->with('status', 'online Course updated successfully'); + } else { + // For regular users + return redirect()->route('faculty.OnlineCoursesResponses') + ->with('status', 'online Course updated successfully'); + } + } + + public function destroy($id) + { + $onlineCourse = OnlineCourse::findOrFail($id); + + // Delete the file if it exists + if ($onlineCourse->proof && Storage::disk('public')->exists($onlineCourse->proof)) { + Storage::disk('public')->delete($onlineCourse->proof); + } + + $onlineCourse->delete(); + + return response()->json(['success' => 'online Course record deleted successfully']); + } + + public function getOnlineCoursesResponses() + { + $user = auth()->user(); + $isAdmin = $user->role->name === 'Admin'; + $isCoordinator = $user->role->name === 'Coordinator'; + + // Query based on role + if ($isAdmin) { + // Admin sees all records + $onlineCourses = OnlineCourse::with('user', 'department'); + } elseif ($isCoordinator) { + // Coordinator sees only their department's records + $onlineCourses = OnlineCourse::with('user', 'department') + ->whereHas('user', function ($query) use ($user) { + $query->where('department_id', $user->department_id); + }); + } else { + // Regular users see only their own records + $onlineCourses = OnlineCourse::with('user', 'department') + ->where('faculty_id', $user->id); + } + + + return DataTables::of($onlineCourses) + ->addColumn('user_name', function ($onlineCourse) { + return $onlineCourse->user->name ?? 'Unknown'; + }) + ->addColumn('department_name', function ($onlineCourse) { + return $onlineCourse->department->name ?? 'Unknown'; + }) + ->addColumn('course', function ($onlineCourse) { + return $onlineCourse->course ?? 'Unknown'; + }) + ->addColumn('offered_by', function ($onlineCourse) { + return $onlineCourse->offered_by ?? 'Unknown'; + }) + ->addColumn('start_date', function ($onlineCourse) { + return \Carbon\Carbon::parse($onlineCourse->start_date)->format('d-m-Y'); + }) + ->addColumn('end_date', function ($onlineCourse) { + return \Carbon\Carbon::parse($onlineCourse->end_date)->format('d-m-Y'); + }) + ->addColumn('num_days', function ($onlineCourse) { + return $onlineCourse->num_days ?? 'Unknown'; + }) + ->addColumn('action', function ($onlineCourse) { + $actions = []; + + // View proof button for everyone + if ($onlineCourse->proof) { + $actions[] = 'View'; + } else { + $actions[] = 'No Proof'; + } + + // Edit button with role-appropriate route + $userRole = auth()->user()->role->name; + // Determine the appropriate route based on user role + if ($userRole === 'Admin') { + $editRoute = route('admin.OnlineCourses.edit', $onlineCourse->id); + } elseif ($userRole === 'Coordinator') { + $editRoute = route('coordinator.OnlineCourses.edit', $onlineCourse->id); + } else { + $editRoute = route('faculty.OnlineCourses.edit', $onlineCourse->id); + } + + $actions[] = 'Edit'; + + $deleteRoute = route('onlineCourses.destroy', $onlineCourse->id); + $actions[] = ''; + + return implode(' ', $actions); + }) + ->rawColumns(['action']) + ->make(true); + } + + public function store(Request $request) + { + // Validate the request data + $validated = $request->validate([ + 'course' => 'required|string', + 'offered_by' => 'required|string', + 'start_date' => 'required|date', + 'end_date' => 'required|date', + 'num_days' => 'required|integer', + 'faculty_id' => 'required|exists:users,id', + 'department_id' => 'required|exists:departments,id', + 'proof' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip', + ]); + + // Create new record + $onlineCourse = new OnlineCourse(); + $onlineCourse->course = $validated['course']; + $onlineCourse->offered_by = $validated['offered_by']; + $onlineCourse->start_date = $validated['start_date']; + $onlineCourse->end_date = $validated['end_date']; + $onlineCourse->num_days = $validated['num_days']; + $onlineCourse->faculty_id = $validated['faculty_id']; + $onlineCourse->department_id = $validated['department_id']; + + // Handle the file upload + if ($request->hasFile('proof')) { + $user = auth()->user(); + $year = date('Y', strtotime($validated['start_date'])); + $username = $user->name; + + $originalName = $request->file('proof')->getClientOriginalName(); + $fileName = $username . '_' . $originalName; + + // Create path structure: year/faculty_name + $folderPath = 'proofs/' . $year . '/' . $username . '/Online Courses'; + + // Store file in the specified path + $proofPath = $request->file('proof')->storeAs($folderPath, $fileName, 'public'); + + $onlineCourse->proof = $proofPath; + } + + $onlineCourse->save(); + + return redirect()->route('faculty.OnlineCoursesResponses') + ->with('status', 'online Course submitted successfully'); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/PatentsController.php b/app/Http/Controllers/PatentsController.php new file mode 100644 index 0000000..3ed5b79 --- /dev/null +++ b/app/Http/Controllers/PatentsController.php @@ -0,0 +1,235 @@ +validate([ + 'title' => 'required|string', + 'investigator' => 'required|string', + 'application_no' => 'required|string', + 'type' => 'required|string', + 'date_of_submission' => 'required|date', + 'date_of_filling' => 'required|date', + 'status' => 'required|string', + 'proof' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip', + ]); + + // Handle the file upload if a new file is provided + if ($request->hasFile('proof')) { + // Delete old file if exists + if ($patent->proof && Storage::disk('public')->exists($patent->proof)) { + Storage::disk('public')->delete($patent->proof); + } + + // Extract year from start_date + $year = date('Y', strtotime($validated['date_of_submission'])); + $username = $patent->user->name; + + $originalName = $request->file('proof')->getClientOriginalName(); + $fileName = $username . '_' . $originalName; + + // Create path structure: year/faculty_name + $folderPath = 'proofs/' . $year . '/' . $username . '/Patents'; + + // Store file in the specified path + $proofPath = $request->file('proof')->storeAs($folderPath, $fileName, 'public'); + + $patent->proof = $proofPath; + } + + + // Update other fields + $patent->title = $validated['title']; + $patent->investigator = $validated['investigator']; + $patent->application_no = $validated['application_no']; + $patent->type = $validated['type']; + $patent->date_of_submission = $validated['date_of_submission']; + $patent->date_of_filling = $validated['date_of_filling']; + $patent->status = $validated['status']; + + $patent->save(); + + $userRole = auth()->user()->role->name; + + if ($userRole === 'Admin') { + return redirect()->route('admin.PatentsResponses') + ->with('status', 'patent updated successfully'); + } elseif ($userRole === 'Coordinator') { + return redirect()->route('coordinator.PatentsResponses') + ->with('status', 'patent updated successfully'); + } else { + // For regular users + return redirect()->route('faculty.PatentsResponses') + ->with('status', 'patent updated successfully'); + } + } + + public function destroy($id) + { + $patent = Patent::findOrFail($id); + + // Delete the file if it exists + if ($patent->proof && Storage::disk('public')->exists($patent->proof)) { + Storage::disk('public')->delete($patent->proof); + } + + $patent->delete(); + + return response()->json(['success' => 'patent record deleted successfully']); + } + + public function getPatentsResponses() + { + $user = auth()->user(); + $isAdmin = $user->role->name === 'Admin'; + $isCoordinator = $user->role->name === 'Coordinator'; + + // Query based on role + if ($isAdmin) { + // Admin sees all records + $patents = Patent::with('user', 'department'); + } elseif ($isCoordinator) { + // Coordinator sees only their department's records + $patents = Patent::with('user', 'department') + ->whereHas('user', function ($query) use ($user) { + $query->where('department_id', $user->department_id); + }); + } else { + // Regular users see only their own records + $patents = Patent::with('user', 'department') + ->where('faculty_id', $user->id); + } + + + return DataTables::of($patents) + ->addColumn('user_name', function ($patent) { + return $patent->user->name ?? 'Unknown'; + }) + ->addColumn('department_name', function ($patent) { + return $patent->department->name ?? 'Unknown'; + }) + ->addColumn('title', function ($patent) { + return $patent->title ?? 'Unknown'; + }) + ->addColumn('investigator', function ($patent) { + return $patent->investigator ?? 'Unknown'; + }) + ->addColumn('application_no', function ($patent) { + return $patent->application_no ?? 'Unknown'; + }) + ->addColumn('type', function ($patent) { + return $patent->type ?? 'Unknown'; + }) + ->addColumn('date_of_submission', function ($patent) { + return \Carbon\Carbon::parse($patent->date_of_submission)->format('d-m-Y'); + }) + ->addColumn('date_of_filling', function ($patent) { + return \Carbon\Carbon::parse($patent->date_of_filling)->format('d-m-Y'); + }) + ->addColumn('status', function ($patent) { + return $patent->status ?? 'Unknown'; + }) + ->addColumn('action', function ($patent) { + $actions = []; + + // View proof button for everyone + if ($patent->proof) { + $actions[] = 'View'; + } else { + $actions[] = 'No Proof'; + } + + // Edit button with role-appropriate route + $userRole = auth()->user()->role->name; + // Determine the appropriate route based on user role + if ($userRole === 'Admin') { + $editRoute = route('admin.Patents.edit', $patent->id); + } elseif ($userRole === 'Coordinator') { + $editRoute = route('coordinator.Patents.edit', $patent->id); + } else { + $editRoute = route('faculty.Patents.edit', $patent->id); + } + + $actions[] = 'Edit'; + + $deleteRoute = route('patents.destroy', $patent->id); + $actions[] = ''; + + return implode(' ', $actions); + }) + ->rawColumns(['action']) + ->make(true); + } + + public function store(Request $request) + { + // Validate the request data + $validated = $request->validate([ + 'title' => 'required|string', + 'investigator' => 'required|string', + 'application_no' => 'required|string', + 'type' => 'required|string', + 'date_of_submission' => 'required|date', + 'date_of_filling' => 'required|date', + 'status' => 'required|string', + 'faculty_id' => 'required|exists:users,id', + 'department_id' => 'required|exists:departments,id', + 'proof' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip', + ]); + + // Create new record + $patent = new Patent(); + $patent->title = $validated['title']; + $patent->investigator = $validated['investigator']; + $patent->application_no = $validated['application_no']; + $patent->type = $validated['type']; + $patent->date_of_submission = $validated['date_of_submission']; + $patent->date_of_filling = $validated['date_of_filling']; + $patent->status = $validated['status']; + $patent->faculty_id = $validated['faculty_id']; + $patent->department_id = $validated['department_id']; + + // Handle the file upload + if ($request->hasFile('proof')) { + $user = auth()->user(); + $year = date('Y', strtotime($validated['date_of_submission'])); + $username = $user->name; + + $originalName = $request->file('proof')->getClientOriginalName(); + $fileName = $username . '_' . $originalName; + + // Create path structure: year/faculty_name + $folderPath = 'proofs/' . $year . '/' . $username . '/Patents'; + + // Store file in the specified path + $proofPath = $request->file('proof')->storeAs($folderPath, $fileName, 'public'); + + $patent->proof = $proofPath; + } + + $patent->save(); + + return redirect()->route('faculty.PatentsResponses') + ->with('status', 'patent submitted successfully'); + } + +} \ No newline at end of file diff --git a/app/Models/ExternalEngagement.php b/app/Models/ExternalEngagement.php new file mode 100644 index 0000000..2609a18 --- /dev/null +++ b/app/Models/ExternalEngagement.php @@ -0,0 +1,40 @@ + 'date', + 'end_date' => 'date', + ]; + + // Relationship with User (Faculty) + public function user() + { + return $this->belongsTo(User::class, 'faculty_id'); + } + + // Relationship with Department + public function department() + { + return $this->belongsTo(Department::class, 'department_id'); + } +} \ No newline at end of file diff --git a/app/Models/OnlineCourse.php b/app/Models/OnlineCourse.php new file mode 100644 index 0000000..3a6c361 --- /dev/null +++ b/app/Models/OnlineCourse.php @@ -0,0 +1,39 @@ + 'date', + 'end_date' => 'date', + ]; + + // Relationship with User (Faculty) + public function user() + { + return $this->belongsTo(User::class, 'faculty_id'); + } + + // Relationship with Department + public function department() + { + return $this->belongsTo(Department::class, 'department_id'); + } +} \ No newline at end of file diff --git a/app/Models/Patent.php b/app/Models/Patent.php new file mode 100644 index 0000000..00fa675 --- /dev/null +++ b/app/Models/Patent.php @@ -0,0 +1,37 @@ +belongsTo(User::class, 'faculty_id'); + } + + // Relationship with Department + public function department() + { + return $this->belongsTo(Department::class, 'department_id'); + } +} \ No newline at end of file diff --git a/database/migrations/2025_04_01_181810_create_external_engagements_table.php b/database/migrations/2025_04_01_181810_create_external_engagements_table.php new file mode 100644 index 0000000..6f4be80 --- /dev/null +++ b/database/migrations/2025_04_01_181810_create_external_engagements_table.php @@ -0,0 +1,46 @@ +id(); + $table->unsignedBigInteger('department_id'); + $table->unsignedBigInteger('faculty_id'); // Faculty who uploaded the publication + + $table->string('activity'); + $table->text('activity_description'); + $table->string('inviting_organization'); + $table->date('start_date'); + $table->date('end_date'); + $table->integer('num_days'); + $table->string('proof')->nullable(); // For file path + + // Foreign keys + $table->foreign('department_id')->references('id')->on('departments')->onDelete('cascade'); + $table->foreign('faculty_id')->references('id')->on('users')->onDelete('cascade'); + + // Indexes for better performance + $table->index('department_id'); + $table->index('faculty_id'); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('external_engagements_'); + } +}; diff --git a/database/migrations/2025_04_01_182552_create_online_courses_table.php b/database/migrations/2025_04_01_182552_create_online_courses_table.php new file mode 100644 index 0000000..eb1e7ec --- /dev/null +++ b/database/migrations/2025_04_01_182552_create_online_courses_table.php @@ -0,0 +1,46 @@ +id(); + $table->unsignedBigInteger('department_id'); + $table->unsignedBigInteger('faculty_id'); // Faculty who uploaded the publication + + $table->string('course'); + $table->string('offered_by'); + $table->date('start_date'); + $table->date('end_date'); + $table->integer('num_days'); + $table->string('proof')->nullable(); // For file path + + + // Foreign keys + $table->foreign('department_id')->references('id')->on('departments')->onDelete('cascade'); + $table->foreign('faculty_id')->references('id')->on('users')->onDelete('cascade'); + + // Indexes for better performance + $table->index('department_id'); + $table->index('faculty_id'); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('online_courses'); + } +}; diff --git a/database/migrations/2025_04_01_182630_create_patents_table.php b/database/migrations/2025_04_01_182630_create_patents_table.php new file mode 100644 index 0000000..98e18d7 --- /dev/null +++ b/database/migrations/2025_04_01_182630_create_patents_table.php @@ -0,0 +1,47 @@ +id(); + $table->unsignedBigInteger('department_id'); + $table->unsignedBigInteger('faculty_id'); // Faculty who uploaded the publication + + $table->string('title'); + $table->string('investigator'); + $table->string('application_no'); + $table->string('type'); + $table->date('date_of_submission'); + $table->date('date_of_filling'); + $table->string('status'); + $table->string('proof')->nullable(); // For file path + + // Foreign keys + $table->foreign('department_id')->references('id')->on('departments')->onDelete('cascade'); + $table->foreign('faculty_id')->references('id')->on('users')->onDelete('cascade'); + + // Indexes for better performance + $table->index('department_id'); + $table->index('faculty_id'); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('patents'); + } +}; diff --git a/resources/views/externalEngagement/edit.blade.php b/resources/views/externalEngagement/edit.blade.php new file mode 100644 index 0000000..9bdc7cd --- /dev/null +++ b/resources/views/externalEngagement/edit.blade.php @@ -0,0 +1,126 @@ +@extends('layouts.app') + +@section('content') +
| ID | +Faculty | +Department | +Activity | +Activity Description | +Inviting Organization | +Start Date | +End Date | +Num Days | +Actions | +
|---|
+ Fill in the details of your External Engagement. +
++ Fill in the details of your Online Course. +
++ Fill in the details of your Patents. +
+| ID | +Faculty | +Department | +Course | +Offered By | +Start Date | +End Date | +Num Days | +Actions | +
|---|
| ID | +Faculty | +Department | +Title | +Investigator | +Application No | +Type | +Date Of Submission | +Date Of Filling | +Status | +Actions | +
|---|