diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index efccd2c..1e5ed67 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -26,5 +26,9 @@ class AdminController extends Controller { return view('activities-organised.index'); } + public function viewIvOrganisedResponses() + { + return view('iv-organised.index'); + } } diff --git a/app/Http/Controllers/CoordinatorController.php b/app/Http/Controllers/CoordinatorController.php index 41c0884..dab6be4 100644 --- a/app/Http/Controllers/CoordinatorController.php +++ b/app/Http/Controllers/CoordinatorController.php @@ -20,10 +20,15 @@ class CoordinatorController extends Controller { return view('activities-attended.index'); } - + public function viewActivitiesOrganisedResponses() { return view('activities-organised.index'); } + public function viewIvOrganisedResponses() + { + return view('iv-organised.index'); + } + } diff --git a/app/Http/Controllers/FacultyController.php b/app/Http/Controllers/FacultyController.php index b3f053b..37cf60c 100644 --- a/app/Http/Controllers/FacultyController.php +++ b/app/Http/Controllers/FacultyController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\ActivitiesAttended; use App\Models\ActivitiesOrganised; +use App\Models\IvOrganised; class FacultyController extends Controller { @@ -36,6 +37,17 @@ class FacultyController extends Controller return view('activities-organised.index'); } + public function IvOrganisedForm() + { + // Logic to show the response form + return view('faculty.iv-organised-form'); + } + + public function viewIvOrganisedResponses() + { + return view('iv-organised.index'); + } + public function ActivitiesAttendedFormResponse(Request $request) { // dd($request->all(),"hello"); @@ -62,7 +74,6 @@ class FacultyController extends Controller $startDateTime = date('Y-m-d H:i:s', strtotime("{$validated['start_date']} {$validated['start_time']}")); $endDateTime = date('Y-m-d H:i:s', strtotime("{$validated['end_date']} {$validated['end_time']}")); - // Handle the file upload // Handle the file upload $proofPath = null; if ($request->hasFile('proof')) { @@ -74,7 +85,7 @@ class FacultyController extends Controller $year = date('Y', strtotime($validated['start_date'])); // Create path structure: year/faculty_name - $folderPath = 'proofs/' . $year . '/' . $username; + $folderPath = 'proofs/' . $year . '/' . $username . 'Activities-Attended'; // Store file in the specified path $proofPath = $request->file('proof')->storeAs($folderPath, $fileName, 'public'); @@ -107,75 +118,143 @@ class FacultyController extends Controller } public function ActivitiesOrganisedFormResponse(Request $request) -{ - try { - // Validate the request data - $validated = $request->validate([ - 'title' => 'required|string', - 'resource_person_name' => 'required|string', - 'resource_person_organization' => 'required|string', - 'target_audience' => 'required|string', - 'number_of_participants' => 'required|integer', - 'objective' => 'required|string', - 'outcomes' => 'required|string', - 'venue' => 'required|string', - 'start_date' => 'required|date', - 'start_time' => 'required|date_format:H:i', - 'end_date' => 'required|date', - 'end_time' => 'required|date_format:H:i', - 'num_days' => 'required|integer', - 'activity_type' => 'required|string', - 'category' => 'required|string', - 'level' => 'required|string', - 'proof' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip', - ]); + { + try { + // Validate the request data + $validated = $request->validate([ + 'title' => 'required|string', + 'resource_person_name' => 'required|string', + 'resource_person_organization' => 'required|string', + 'target_audience' => 'required|string', + 'number_of_participants' => 'required|integer', + 'objective' => 'required|string', + 'outcomes' => 'required|string', + 'venue' => 'required|string', + 'start_date' => 'required|date', + 'start_time' => 'required|date_format:H:i', + 'end_date' => 'required|date', + 'end_time' => 'required|date_format:H:i', + 'num_days' => 'required|integer', + 'activity_type' => 'required|string', + 'category' => 'required|string', + 'level' => 'required|string', + 'proof' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip', + ]); - // Combine start date and time - $startDateTime = date('Y-m-d H:i:s', strtotime("{$validated['start_date']} {$validated['start_time']}")); - $endDateTime = date('Y-m-d H:i:s', strtotime("{$validated['end_date']} {$validated['end_time']}")); + // Combine start date and time + $startDateTime = date('Y-m-d H:i:s', strtotime("{$validated['start_date']} {$validated['start_time']}")); + $endDateTime = date('Y-m-d H:i:s', strtotime("{$validated['end_date']} {$validated['end_time']}")); - // Handle the file upload - $proofPath = null; - if ($request->hasFile('proof')) { - $originalName = $request->file('proof')->getClientOriginalName(); - $username = auth()->user()->name; - $fileName = $username . '_' . $originalName; + // Handle the file upload + $proofPath = 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'])); + // Extract year from start_date + $year = date('Y', strtotime($validated['start_date'])); - // Create path structure: year/faculty_name - $folderPath = 'proofs/' . $year . '/' . $username; + // Create path structure: year/faculty_name + $folderPath = 'proofs/' . $year . '/' . $username . 'Activities-Organised'; - // Store file in the specified path - $proofPath = $request->file('proof')->storeAs($folderPath, $fileName, 'public'); + // Store file in the specified path + $proofPath = $request->file('proof')->storeAs($folderPath, $fileName, 'public'); + } + + // Save the response to the database + ActivitiesOrganised::create([ + 'title' => $validated['title'], + 'resource_person_name' => $validated['resource_person_name'], + 'resource_person_organization' => $validated['resource_person_organization'], + 'target_audience' => $validated['target_audience'], + 'number_of_participants' => $validated['number_of_participants'], + 'objective' => $validated['objective'], + 'outcomes' => $validated['outcomes'], + 'department_id' => auth()->user()->department->id, + 'faculty_id' => auth()->user()->id, + 'venue' => $validated['venue'], + 'start_date' => $startDateTime, + 'end_date' => $endDateTime, + 'num_days' => $validated['num_days'], + 'activity_type' => $validated['activity_type'], + 'category' => $validated['category'], + 'level' => $validated['level'], + 'proof' => $proofPath, + ]); + + return redirect()->route('faculty.dashboard')->with('status', 'Response submitted successfully'); + } catch (\Exception $e) { + // Handle the exception and provide an error message + return back()->withErrors('An error occurred while submitting your response: ' . $e->getMessage()); } + } - // Save the response to the database - ActivitiesOrganised::create([ - 'title' => $validated['title'], - 'resource_person_name' => $validated['resource_person_name'], - 'resource_person_organization' => $validated['resource_person_organization'], - 'target_audience' => $validated['target_audience'], - 'number_of_participants' => $validated['number_of_participants'], - 'objective' => $validated['objective'], - 'outcomes' => $validated['outcomes'], - 'department_id' => auth()->user()->department->id, - 'faculty_id' => auth()->user()->id, - 'venue' => $validated['venue'], - 'start_date' => $startDateTime, - 'end_date' => $endDateTime, - 'num_days' => $validated['num_days'], - 'activity_type' => $validated['activity_type'], - 'category' => $validated['category'], - 'level' => $validated['level'], - 'proof' => $proofPath, - ]); + public function IvOrganisedFormResponse(Request $request) + { + try { + // Validate the request data + $validated = $request->validate([ + 'faculty_id' => 'required|exists:users,id', + 'start_date' => 'required|date', + 'start_time' => 'required|date_format:H:i', + 'end_date' => 'required|date', + 'end_time' => 'required|date_format:H:i', + 'company_name' => 'required|string', + 'company_address' => 'required|string', + 'resource_person_name' => 'required|string', + 'resource_person_contact_details' => 'required|string', + 'target_audience' => 'required|string', + 'student_year' => 'nullable|string', + 'number_of_participants' => 'required|integer', + 'objective' => 'required|string', + 'outcomes' => 'required|string', + 'proof' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip', + ]); - return redirect()->route('faculty.dashboard')->with('status', 'Response submitted successfully'); - } catch (\Exception $e) { - // Handle the exception and provide an error message - return back()->withErrors('An error occurred while submitting your response: ' . $e->getMessage()); + // Combine start date and time + $startDateTime = date('Y-m-d H:i:s', strtotime("{$validated['start_date']} {$validated['start_time']}")); + $endDateTime = date('Y-m-d H:i:s', strtotime("{$validated['end_date']} {$validated['end_time']}")); + + // Handle the file upload + $proofPath = 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 + $folderPath = 'proofs/' . $year . '/' . $username . '/Iv_organised'; + + // Store file in the specified path + $proofPath = $request->file('proof')->storeAs($folderPath, $fileName, 'public'); + } + + // Save the response to the database + IvOrganised::create([ + 'faculty_id' => auth()->user()->id, + 'start_date' => $startDateTime, + 'end_date' => $endDateTime, + 'company_name' => $validated['company_name'], + 'company_address' => $validated['company_address'], + 'resource_person_name' => $validated['resource_person_name'], + 'resource_person_contact_details' => $validated['resource_person_contact_details'], + 'target_audience' => $validated['target_audience'], + 'student_year' => $validated['student_year'], + 'number_of_participants' => $validated['number_of_participants'], + 'objective' => $validated['objective'], + 'outcomes' => $validated['outcomes'], + 'department_id' => auth()->user()->department->id, + 'proof' => $proofPath, + ]); + + return redirect()->route('faculty.dashboard')->with('status', 'Industrial Visit details submitted successfully'); + } catch (\Exception $e) { + // Handle the exception and provide an error message + return back()->withErrors('An error occurred while submitting your response: ' . $e->getMessage()); + } } } -} diff --git a/app/Http/Controllers/IvOrganisedController.php b/app/Http/Controllers/IvOrganisedController.php new file mode 100644 index 0000000..8f46d8d --- /dev/null +++ b/app/Http/Controllers/IvOrganisedController.php @@ -0,0 +1,255 @@ +validate([ + 'company_name' => 'required|string', + 'company_address' => 'required|string', + 'resource_person_name' => 'required|string', + 'resource_person_contact_details' => 'required|string', + 'target_audience' => 'required|string', + 'student_year' => 'nullable|string', + 'number_of_participants' => 'required|integer', + 'objective' => 'required|string', + 'outcomes' => 'required|string', + 'start_date' => 'required|date', + 'start_time' => 'required|date_format:H:i', + 'end_date' => 'required|date', + 'end_time' => 'required|date_format:H:i', + 'proof' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip', + ]); + + // Combine start date and time + $startDateTime = date('Y-m-d H:i:s', strtotime("{$validated['start_date']} {$validated['start_time']}")); + $endDateTime = date('Y-m-d H:i:s', strtotime("{$validated['end_date']} {$validated['end_time']}")); + + // Handle the file upload if a new file is provided + if ($request->hasFile('proof')) { + // Delete old file if exists + if ($response->proof && Storage::disk('public')->exists($response->proof)) { + Storage::disk('public')->delete($response->proof); + } + + // Extract year from start_date + $year = date('Y', strtotime($validated['start_date'])); + $username = $response->user->name; + + $originalName = $request->file('proof')->getClientOriginalName(); + $fileName = $username . '_' . $originalName; + + // Create path structure: year/faculty_name + $folderPath = 'proofs/' . $year . '/' . $username; + + // Store file in the specified path + $proofPath = $request->file('proof')->storeAs($folderPath, $fileName, 'public'); + + $response->proof = $proofPath; + } + + // Update other fields + $response->company_name = $validated['company_name']; + $response->company_address = $validated['company_address']; + $response->resource_person_name = $validated['resource_person_name']; + $response->resource_person_contact_details = $validated['resource_person_contact_details']; + $response->target_audience = $validated['target_audience']; + $response->student_year = $validated['student_year']; + $response->number_of_participants = $validated['number_of_participants']; + $response->objective = $validated['objective']; + $response->outcomes = $validated['outcomes']; + $response->start_date = $startDateTime; + $response->end_date = $endDateTime; + + $response->save(); + + $userRole = auth()->user()->role->name; + + if ($userRole === 'Admin') { + return redirect()->route('admin.IvOrganisedResponses') + ->with('status', 'Industrial visit updated successfully'); + } elseif ($userRole === 'Coordinator') { + return redirect()->route('coordinator.IvOrganisedResponses') + ->with('status', 'Industrial visit updated successfully'); + } else { + // For regular users + return redirect()->route('faculty.IvOrganisedResponses') + ->with('status', 'Industrial visit updated successfully'); + } + } + + public function destroy($id) + { + $response = IvOrganised::findOrFail($id); + + // Delete the file if it exists + if ($response->proof && Storage::disk('public')->exists($response->proof)) { + Storage::disk('public')->delete($response->proof); + } + + $response->delete(); + + return response()->json(['success' => 'Industrial visit record deleted successfully']); + } + + public function getIvOrganisedResponses() + { + $user = auth()->user(); + $isAdmin = $user->role->name === 'Admin'; + $isCoordinator = $user->role->name === 'Coordinator'; + + // Query based on role + if ($isAdmin) { + // Admin sees all records + $responses = IvOrganised::with('user', 'department'); + } elseif ($isCoordinator) { + // Coordinator sees only their department's records + $responses = IvOrganised::with('user', 'department') + ->whereHas('user', function ($query) use ($user) { + $query->where('department_id', $user->department_id); + }); + } else { + // Regular users see only their own records + $responses = IvOrganised::with('user', 'department') + ->where('faculty_id', $user->id); + } + + return DataTables::of($responses) + ->addColumn('user_name', function ($response) { + return $response->user->name ?? 'Unknown'; + }) + ->addColumn('department_name', function ($response) { + return $response->department->name ?? 'Unknown'; + }) + ->addColumn('start_date', function ($response) { + return \Carbon\Carbon::parse($response->start_date)->format('d-m-Y'); + }) + ->addColumn('start_time', function ($response) { + return \Carbon\Carbon::parse($response->start_date)->format('h:i A'); + }) + ->addColumn('end_date', function ($response) { + return \Carbon\Carbon::parse($response->end_date)->format('d-m-Y'); + }) + ->addColumn('end_time', function ($response) { + return \Carbon\Carbon::parse($response->end_date)->format('h:i A'); + }) + ->addColumn('action', function ($response) { + $actions = []; + + // View proof button for everyone + if ($response->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.IvOrganised.edit', $response->id); + } elseif ($userRole === 'Coordinator') { + $editRoute = route('coordinator.IvOrganised.edit', $response->id); + } else { + $editRoute = route('faculty.IvOrganised.edit', $response->id); + } + + $actions[] = 'Edit'; + + $deleteRoute = route('ivOrganised.destroy', $response->id); + $actions[] = ''; + + return implode(' ', $actions); + }) + ->rawColumns(['action']) + ->make(true); + } + + public function store(Request $request) + { + // Validate the request data + $validated = $request->validate([ + 'company_name' => 'required|string', + 'company_address' => 'required|string', + 'resource_person_name' => 'required|string', + 'resource_person_contact_details' => 'required|string', + 'target_audience' => 'required|string', + 'student_year' => 'nullable|string', + 'number_of_participants' => 'required|integer', + 'objective' => 'required|string', + 'outcomes' => 'required|string', + 'start_date' => 'required|date', + 'start_time' => 'required|date_format:H:i', + 'end_date' => 'required|date', + 'end_time' => 'required|date_format:H:i', + 'faculty_id' => 'required|exists:users,id', + 'department_id' => 'required|exists:departments,id', + 'proof' => 'required|mimes:jpg,jpeg,png,pdf,doc,docx,zip', + ]); + + // Combine start date and time + $startDateTime = date('Y-m-d H:i:s', strtotime("{$validated['start_date']} {$validated['start_time']}")); + $endDateTime = date('Y-m-d H:i:s', strtotime("{$validated['end_date']} {$validated['end_time']}")); + + // Create new record + $ivOrganised = new IvOrganised(); + $ivOrganised->company_name = $validated['company_name']; + $ivOrganised->company_address = $validated['company_address']; + $ivOrganised->resource_person_name = $validated['resource_person_name']; + $ivOrganised->resource_person_contact_details = $validated['resource_person_contact_details']; + $ivOrganised->target_audience = $validated['target_audience']; + $ivOrganised->student_year = $validated['student_year']; + $ivOrganised->number_of_participants = $validated['number_of_participants']; + $ivOrganised->objective = $validated['objective']; + $ivOrganised->outcomes = $validated['outcomes']; + $ivOrganised->start_date = $startDateTime; + $ivOrganised->end_date = $endDateTime; + $ivOrganised->faculty_id = $validated['faculty_id']; + $ivOrganised->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; + + // Store file in the specified path + $proofPath = $request->file('proof')->storeAs($folderPath, $fileName, 'public'); + + $ivOrganised->proof = $proofPath; + } + + $ivOrganised->save(); + + return redirect()->route('faculty.IvOrganisedResponses') + ->with('status', 'Industrial visit submitted successfully'); + } + + public function create() + { + return view('iv-organised.create'); + } +} \ No newline at end of file diff --git a/app/Models/IvOrganised.php b/app/Models/IvOrganised.php new file mode 100644 index 0000000..a200e74 --- /dev/null +++ b/app/Models/IvOrganised.php @@ -0,0 +1,48 @@ + 'datetime', + 'end_date' => 'datetime', + 'number_of_participants' => 'integer', + ]; + + // 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/database/migrations/2025_03_23_210251_create_iv_organiseds_table.php b/database/migrations/2025_03_23_210251_create_iv_organiseds_table.php new file mode 100644 index 0000000..d5bf579 --- /dev/null +++ b/database/migrations/2025_03_23_210251_create_iv_organiseds_table.php @@ -0,0 +1,43 @@ +id(); + $table->unsignedBigInteger('faculty_id'); // Organising faculty (Convenor/Coordinator) + $table->dateTime('start_date'); + $table->dateTime('end_date'); + $table->string('company_name'); // Name of the Company/field/institute + $table->text('company_address'); // Address of the company/field/institute + $table->string('resource_person_name'); + $table->text('resource_person_contact_details'); + $table->string('target_audience'); // (faculty/student) + $table->string('student_year')->nullable(); // Year of study if students + $table->integer('number_of_participants'); + $table->text('objective'); + $table->text('outcomes'); + $table->unsignedBigInteger('department_id'); + $table->string('proof')->nullable(); // For file path + $table->foreign('faculty_id')->references('id')->on('users')->onDelete('cascade'); + $table->foreign('department_id')->references('id')->on('departments')->onDelete('cascade'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('iv_organiseds'); + } +}; \ No newline at end of file diff --git a/resources/views/faculty/iv-organised-form.blade.php b/resources/views/faculty/iv-organised-form.blade.php new file mode 100644 index 0000000..4aa6c65 --- /dev/null +++ b/resources/views/faculty/iv-organised-form.blade.php @@ -0,0 +1,154 @@ +@extends('layouts.app') + +@section('content') +
+ Fill in the details of the industrial visit you organised. +
+| ID | +Company Name | +Resource Person | +Target Audience | +Department | +Faculty | +Start Date | +End Date | +Student Year | +Participants | +Actions | +
|---|