Feat: books published

This commit is contained in:
Sallu9007
2025-03-31 22:57:21 +05:30
parent b2060c47e2
commit 2aa0cf0449
11 changed files with 853 additions and 61 deletions

View File

@@ -34,5 +34,8 @@ class AdminController extends Controller
{
return view('publications.index');
}
public function viewBooksPublishedResponses()
{
return view('booksPublished.index');
}
}

View File

@@ -0,0 +1,183 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Yajra\DataTables\Facades\DataTables;
use App\Models\BooksPublished;
use Illuminate\Support\Facades\Storage;
class BooksPublishedController extends Controller
{
public function edit($id)
{
$booksPublished = BooksPublished::findOrFail($id);
return view('booksPublished.edit', compact('booksPublished'));
}
public function update(Request $request, $id)
{
try {
$booksPublished = BooksPublished::findOrFail($id);
// Validate the request data
$validated = $request->validate([
'author' => 'required|string',
'title' => 'required|string',
'publisher' => 'required|string',
'issn' => [
'nullable',
'string',
'regex:/^(\d{4}-\d{3}[\dX]|\d{8}|\d{4}\s\d{3}[\dX])$/'
],
'date_of_publication' => 'required|date',
'proof_file' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip',
], [
'issn.regex' => 'The ISSN format is invalid. It should be in the format XXXX-XXXX or XXXXXXXX.'
]);
// Handle the file upload if a new file is provided
if ($request->hasFile('proof_file')) {
// Delete old file if exists
if ($booksPublished->proof && Storage::disk('public')->exists($booksPublished->proof)) {
Storage::disk('public')->delete($booksPublished->proof);
}
// Extract year from start_date
$year = date('Y', strtotime($validated['date_of_publication']));
$username = $booksPublished->user->name;
$originalName = $request->file('proof_file')->getClientOriginalName();
$fileName = $username . '_' . $originalName;
// Create path structure: year/faculty_name/BooksPublished
$folderPath = 'proofs/' . $year . '/' . $username . '/BooksPublished';
// Store file in the specified path
$paperFilePath = $request->file('proof_file')->storeAs($folderPath, $fileName, 'public');
$booksPublished->proof = $paperFilePath;
}
// Update other fields
$booksPublished->author = $validated['author'];
$booksPublished->title = $validated['title'];
$booksPublished->publisher = $validated['publisher'];
$booksPublished->issn = $validated['issn'];
$booksPublished->date_of_publication = $validated['date_of_publication'];
$booksPublished->save();
$userRole = auth()->user()->role->name;
if ($userRole === 'Admin') {
return redirect()->route('admin.BooksPublishedResponses')
->with('status', 'Publication updated successfully');
} elseif ($userRole === 'Coordinator') {
return redirect()->route('coordinator.BooksPublishedResponses')
->with('status', 'Publication updated successfully');
} else {
// For regular users
return redirect()->route('faculty.BooksPublishedResponses')
->with('status', 'Publication updated successfully');
}
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
return back()->withErrors(['error' => 'Publication 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 destroy($id)
{
$booksPublished = BooksPublished::findOrFail($id);
// Delete the file if it exists
if ($booksPublished->proof && Storage::disk('public')->exists($booksPublished->proof)) {
Storage::disk('public')->delete($booksPublished->proof);
}
$booksPublished->delete();
return response()->json(['success' => 'Publication deleted successfully']);
}
public function getBooksPublishedResponses()
{
$user = auth()->user();
$isAdmin = $user->role->name === 'Admin';
$isCoordinator = $user->role->name === 'Coordinator';
// Query based on role
if ($isAdmin) {
// Admin sees all records
$booksPublisheds = BooksPublished::with('user', 'department');
} elseif ($isCoordinator) {
// Coordinator sees only their department's records
$booksPublisheds = BooksPublished::with('user', 'department')
->whereHas('user', function ($query) use ($user) {
$query->where('department_id', $user->department_id);
});
} else {
// Regular users see only their own records
$booksPublisheds = BooksPublished::with('user', 'department')
->where('faculty_id', $user->id);
}
return DataTables::of($booksPublisheds)
->addColumn('user_name', function ($booksPublished) {
return $booksPublished->user->name ?? 'Unknown';
})
->addColumn('department_name', function ($booksPublished) {
return $booksPublished->department->name ?? 'Unknown';
})
->addColumn('author', function ($booksPublished) {
return $booksPublished->author ?? 'Unknown';
})
->addColumn('title', function ($booksPublished) {
return $booksPublished->title ?? 'Unknown';
})
->addColumn('publisher', function ($booksPublished) {
return $booksPublished->publisher ?? 'Unknown';
})
->addColumn('issn', function ($booksPublished) {
return $booksPublished->issn ?? 'NA';
})
->addColumn('date_of_publication', function ($booksPublished) {
return \Carbon\Carbon::parse($booksPublished->date_of_publication)->format('d-m-Y');
})
->addColumn('action', function ($booksPublished) {
$actions = [];
// View proof button for everyone
if ($booksPublished->proof) {
$actions[] = '<a href="' . asset('storage/' . $booksPublished->proof) . '" target="_blank" class="btn btn-sm btn-primary mr-1">View</a>';
} 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.BooksPublished.edit', $booksPublished->id);
} elseif ($userRole === 'Coordinator') {
$editRoute = route('coordinator.BooksPublished.edit', $booksPublished->id);
} else {
$editRoute = route('faculty.BooksPublished.edit', $booksPublished->id);
}
$actions[] = '<a href="' . $editRoute . '" class="btn btn-sm btn-info mx-1">Edit</a>';
$deleteRoute = route('booksPublished.destroy', $booksPublished->id);
$actions[] = '<button type="button" class="btn btn-sm btn-danger delete-btn" data-id="' . $booksPublished->id . '" data-url="' . $deleteRoute . '">Delete</button>';
return implode(' ', $actions);
})
->rawColumns(['action'])
->make(true);
}
}

View File

@@ -36,4 +36,9 @@ class CoordinatorController extends Controller
return view('publications.index');
}
public function viewBooksPublishedResponses()
{
return view('booksPublished.index');
}
}

View File

@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\ActivitiesAttended;
use App\Models\ActivitiesOrganised;
use App\Models\BooksPublished;
use App\Models\IvOrganised;
use App\Models\Publication;
@@ -60,6 +61,17 @@ class FacultyController extends Controller
return view('publications.index');
}
public function BooksPublishedForm()
{
// Logic to show the response form
return view('faculty.booksPublished-form');
}
public function viewBooksPublishedResponses()
{
return view('booksPublished.index');
}
public function ActivitiesAttendedFormResponse(Request $request)
{
try {
@@ -270,73 +282,132 @@ class FacultyController extends Controller
}
public function PublicationsFormResponse(Request $request)
{
try {
// Validate the request data
$validated = $request->validate([
'first_author_name' => 'required|string',
'co_authors' => 'nullable|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',
'title' => 'required|string',
'affiliation' => 'required|string',
'organizing_institute' => 'required|string',
'venue_address' => 'required|string',
'is_peer_reviewed' => 'required|in:yes,no',
'scopus_link' => 'nullable|url',
'sci_link' => 'nullable|url',
'paper_file' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip',
]);
{
try {
// Validate the request data
$validated = $request->validate([
'first_author_name' => 'required|string',
'co_authors' => 'nullable|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',
'title' => 'required|string',
'affiliation' => 'required|string',
'organizing_institute' => 'required|string',
'venue_address' => 'required|string',
'is_peer_reviewed' => 'required|in:yes,no',
'scopus_link' => 'nullable|url',
'sci_link' => 'nullable|url',
'paper_file' => '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
$paperFilePath = null;
if ($request->hasFile('paper_file')) {
$originalName = $request->file('paper_file')->getClientOriginalName();
$username = auth()->user()->name;
$fileName = $username . '_' . $originalName;
// Handle the file upload
$paperFilePath = null;
if ($request->hasFile('paper_file')) {
$originalName = $request->file('paper_file')->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/Publications
$folderPath = 'proofs/' . $year . '/' . $username . '/Publications';
// Create path structure: year/faculty_name/Publications
$folderPath = 'proofs/' . $year . '/' . $username . '/Publications';
// Store file in the specified path
$paperFilePath = $request->file('paper_file')->storeAs($folderPath, $fileName, 'public');
// Store file in the specified path
$paperFilePath = $request->file('paper_file')->storeAs($folderPath, $fileName, 'public');
}
// Save the response to the database
Publication::create([
'department_id' => auth()->user()->department->id,
'first_author_name' => $validated['first_author_name'],
'co_authors' => $validated['co_authors'],
'start_date' => $startDateTime,
'end_date' => $endDateTime,
'num_days' => $validated['num_days'],
'activity_type' => $validated['activity_type'],
'title' => $validated['title'],
'affiliation' => $validated['affiliation'],
'organizing_institute' => $validated['organizing_institute'],
'venue_address' => $validated['venue_address'],
'is_peer_reviewed' => $validated['is_peer_reviewed'],
'scopus_link' => $validated['scopus_link'],
'sci_link' => $validated['sci_link'],
'paper_file' => $paperFilePath,
'faculty_id' => auth()->user()->id,
]);
return redirect()->route('faculty.dashboard')->with('status', 'Publication details submitted successfully');
} catch (\Exception $e) {
// Handle the exception and provide an error message
return back()->withErrors('An error occurred while submitting your publication: ' . $e->getMessage());
}
}
public function BooksPublishedFormResponse(Request $request)
{
// dd($request->all());
try {
// Validate the request data
$validated = $request->validate([
'author' => 'required|string',
'title' => 'required|string',
'publisher' => 'required|string',
'issn' => [
'nullable',
'string',
'regex:/^(\d{4}-\d{3}[\dX]|\d{8}|\d{4}\s\d{3}[\dX])$/'
],
'date_of_publication' => 'required|date',
'proof_file' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip',
], [
'issn.regex' => 'The ISSN format is invalid. It should be in the format XXXX-XXXX or XXXXXXXX.'
]);
// Save the response to the database
Publication::create([
'department_id' => auth()->user()->department->id,
'first_author_name' => $validated['first_author_name'],
'co_authors' => $validated['co_authors'],
'start_date' => $startDateTime,
'end_date' => $endDateTime,
'num_days' => $validated['num_days'],
'activity_type' => $validated['activity_type'],
'title' => $validated['title'],
'affiliation' => $validated['affiliation'],
'organizing_institute' => $validated['organizing_institute'],
'venue_address' => $validated['venue_address'],
'is_peer_reviewed' => $validated['is_peer_reviewed'],
'scopus_link' => $validated['scopus_link'],
'sci_link' => $validated['sci_link'],
'paper_file' => $paperFilePath,
'faculty_id' => auth()->user()->id,
]);
// Handle the file upload
$proofFilePath = null;
if ($request->hasFile('proof_file')) {
$originalName = $request->file('proof_file')->getClientOriginalName();
$username = auth()->user()->name;
$fileName = $username . '_' . $originalName;
return redirect()->route('faculty.dashboard')->with('status', 'Publication details submitted successfully');
} catch (\Exception $e) {
// Handle the exception and provide an error message
return back()->withErrors('An error occurred while submitting your publication: ' . $e->getMessage());
// Extract year from start_date
$year = date('Y', strtotime($validated['date_of_publication']));
// Create path structure: year/faculty_name/Publications
$folderPath = 'proofs/' . $year . '/' . $username . '/Publications';
// Store file in the specified path
$proofFilePath = $request->file('proof_file')->storeAs($folderPath, $fileName, 'public');
}
// dd($proofFilePath);
// Save the response to the database
BooksPublished::create([
'department_id' => auth()->user()->department->id,
'author' => $validated['author'],
'title' => $validated['title'],
'publisher' => $validated['publisher'],
'issn' => $validated['issn'],
'date_of_publication' => $validated['date_of_publication'],
'proof' => $proofFilePath,
'faculty_id' => auth()->user()->id,
]);
return redirect()->route('faculty.dashboard')->with('status', 'Publication details submitted successfully');
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
return back()->withErrors(['error' => 'Publication 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();
}
}
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class BooksPublished extends Model
{
use HasFactory;
protected $table = 'books_published';
protected $fillable = [
'department_id',
'faculty_id',
'author',
'title',
'publisher',
'issn',
'date_of_publication',
'proof',
];
protected $casts = [
'date_of_publication' => 'date',
];
/**
* Get the department that owns the publication.
*/
public function department()
{
return $this->belongsTo(Department::class);
}
/**
* Get the faculty user that owns the publication.
*/
public function user()
{
return $this->belongsTo(User::class, 'faculty_id');
}
}

View File

@@ -0,0 +1,48 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('books_published', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('department_id');
$table->unsignedBigInteger('faculty_id'); // Faculty who uploaded the publication
$table->text('author');
$table->string('title');
$table->string('publisher');
$table->string('issn', 9)->nullable();
$table->date('date_of_publication');
$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();
});
// Add ISSN format check constraint manually
DB::statement("ALTER TABLE books_published ADD CONSTRAINT chk_issn_format CHECK (issn REGEXP '^[0-9]{4}-[0-9]{3}[0-9X]$')");
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('books_published');
}
};

View File

@@ -0,0 +1,107 @@
@extends('layouts.app')
@section('content')
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-6">
<div class="bg-white overflow-hidden shadow sm:rounded-lg">
<div class="px-4 py-5 sm:px-6">
<h3 class="text-xl leading-6 font-semibold text-gray-900">
Edit Publication
</h3>
</div>
<div class="px-4 py-5 sm:p-6">
@if ($errors->any())
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<form action="{{ request()->is('admin/*') ? route('admin.BooksPublished.update', $booksPublished->id) : (request()->is('coordinator/*') ? route('coordinator.BooksPublished.update', $booksPublished->id) : route('faculty.BooksPublished.update', $booksPublished->id)) }}" method="POST" enctype="multipart/form-data">
@csrf
@method('PUT')
<div class="space-y-6">
<!-- Author Information -->
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label for="author" class="block text-sm font-medium text-gray-700">Author Name</label>
<input type="text" name="author" id="author" value="{{ old('author', $booksPublished->author) }}" class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md" required>
</div>
</div>
<!-- Publication Title -->
<div>
<label for="title" class="block text-sm font-medium text-gray-700">Publication Title</label>
<input type="text" name="title" id="title" value="{{ old('title', $booksPublished->title) }}" class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md" required>
</div>
<!-- Publication Venue Information -->
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label for="publisher" class="block text-sm font-medium text-gray-700">Publisher Name</label>
<input type="text" name="publisher" id="publisher" value="{{ old('publisher', $booksPublished->publisher) }}" class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md" required>
</div>
</div>
<div>
<label for="issn" class="block text-sm font-medium text-gray-700">ISSN/eISSN number</label>
<input type="text" name="issn" id="issn" value="{{ old('issn', $booksPublished->issn) }}" class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md" required>
</div>
<!-- Department and Faculty Name -->
<div class="grid grid-cols-2 sm:grid-cols-2 gap-4">
<div>
<label for="department" class="block text-sm font-medium text-gray-700">Department</label>
<input type="text" name="department" id="department" value="{{ $booksPublished->department->name ?? 'Unknown' }}" class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md bg-gray-100" disabled>
</div>
<div>
<label for="faculty_name" class="block text-sm font-medium text-gray-700">Faculty Name</label>
<input type="text" name="faculty_name" id="faculty_name" value="{{ $booksPublished->user->name ?? 'Unknown' }}" class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md bg-gray-100" disabled>
</div>
</div>
<!-- Date Information -->
<div class="grid grid-cols-2 gap-4">
<div>
<label for="date_of_publication" class="block text-sm font-medium text-gray-700">Start Date</label>
<input type="date" name="date_of_publication" id="date_of_publication" value="{{ old('date_of_publication', \Carbon\Carbon::parse($booksPublished->date_of_publication)->format('Y-m-d')) }}" class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md" required onchange="calculateDays()">
</div>
</div>
<!-- Proof File -->
<div>
<label for="proof_file" class="block text-sm font-medium text-gray-700">Upload Proof</label>
@if ($booksPublished->proof_file)
<div class="mb-2">
<span class="text-sm text-gray-600">Current file:</span>
<a href="{{ asset('storage/' . $booksPublished->proof_file) }}" target="_blank" class="ml-2 text-blue-600 hover:text-blue-800">View</a>
</div>
@endif
<input type="file" name="proof_file" id="proof_file" class="mt-1 block w-full text-sm text-gray-500
file:mr-4 file:py-2 file:px-4
file:rounded-full file:border-0
file:text-sm file:font-semibold
file:bg-blue-50 file:text-blue-700
hover:file:bg-blue-100">
<p class="mt-1 text-xs text-gray-500">Accepted formats: JPG, JPEG, PNG, PDF, DOC, DOCX, ZIP</p>
</div>
</div>
<!-- Submit Button -->
<div class="mt-6 flex items-center justify-end">
<a href="{{ request()->is('admin/*') ? route('admin.BooksPublishedResponses') : (request()->is('coordinator/*') ? route('coordinator.BooksPublishedResponses') : route('faculty.BooksPublishedResponses')) }}" class="bg-gray-200 py-2 px-4 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 hover:bg-gray-300 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500 mr-3">
Cancel
</a>
<button type="submit" class="inline-flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-black">
Update
</button>
</div>
</form>
</div>
</div>
</div>
@endsection

View File

@@ -0,0 +1,186 @@
@extends('layouts.app')
@section('content')
<div class="max-w-full mx-auto px-4 sm:px-6 lg:px-8">
<div class="bg-white overflow-hidden shadow sm:rounded-lg">
<div class="px-4 py-5 sm:px-6">
<h3 class="text-xl leading-6 font-semibold text-gray-900">
All Books Published
</h3>
</div>
<div class="px-4 py-5 sm:px-6">
<div class="overflow-x-auto w-full max-w-screen-lg mx-auto">
<table id="booksPublished-table" class="table-auto w-full table-striped border-collapse border border-gray-200 rounded-lg">
<thead class="bg-gray-100">
<tr>
<th class="px-4 py-2 border border-gray-200">ID</th>
<th class="px-4 py-2 border border-gray-200">Title</th>
<th class="px-4 py-2 border border-gray-200">Author</th>
<th class="px-4 py-2 border border-gray-200">Publisher</th>
<th class="px-4 py-2 border border-gray-200">Date of Publication</th>
<th class="px-4 py-2 border border-gray-200">ISSN/eISSN number</th>
<th class="px-4 py-2 border border-gray-200">Department</th>
<th class="px-4 py-2 border border-gray-200">Actions</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div>
@endsection
@section('scripts')
<!-- DataTables JS -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.13.1/css/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.13.1/css/dataTables.bootstrap5.min.css">
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.datatables.net/1.13.1/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.13.1/js/dataTables.bootstrap5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/2.2.3/js/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/buttons/2.2.3/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/2.2.3/js/buttons.print.min.js"></script>
<script>
$(document).ready(function() {
const sheetName = "Publications";
var initAjaxRoute = function(route) {
table = $("#booksPublished-table").DataTable({
fnDestroy: true,
processing: true,
serverSide: true,
responsive: true,
ajax: {
url: route,
},
columns: [{
data: 'id',
name: 'id'
},
{
data: 'title',
name: 'title',
orderable: true
},
{
data: 'author',
name: 'author',
orderable: true
},
{
data: 'publisher',
name: 'publisher',
orderable: true
},
{
data: 'date_of_publication',
name: 'date_of_publication',
orderable: true
},
{
data: 'issn',
name: 'issn',
orderable: false
},
{
data: 'department_name',
name: 'department_name',
orderable: false
},
{
data: 'action',
name: 'action',
orderable: false,
searchable: false
},
],
columnDefs: [{
targets: '_all',
className: 'text-center wrap-text'
}, ],
dom: 'Bfrtip',
buttons: [{
extend: 'copy',
title: sheetName,
exportOptions: exportOptions()
},
{
extend: 'csv',
title: sheetName,
exportOptions: exportOptions()
},
{
extend: 'excel',
title: sheetName,
exportOptions: exportOptions()
},
{
extend: 'pdf',
title: sheetName,
exportOptions: exportOptions()
},
{
extend: 'print',
title: sheetName,
exportOptions: exportOptions()
}
]
});
};
// Delete button event handler
$('#booksPublished-table').on('click', '.delete-btn', function() {
if (confirm('Are you sure you want to delete this record?')) {
const id = $(this).data('id');
const url = $(this).data('url');
$.ajax({
url: url,
type: 'DELETE',
data: {
"_token": "{{ csrf_token() }}"
},
success: function(result) {
table.ajax.reload();
alert('Publication deleted successfully');
},
error: function(error) {
console.error(error);
alert('Error deleting publication');
}
});
}
});
function exportOptions() {
return {
columns: ':visible',
format: {
body: function(data, row, column, node) {
if ($(node).find('select').length) {
return $(node).find("select option:selected").text();
}
return $(node).text();
}
}
};
}
// Set appropriate route based on user role
const userRole = "{{ auth()->user()->role->name }}";
let dataRoute = "{{ route('admin.BooksPublishedResponses.data') }}";
if (userRole === 'Coordinator') {
dataRoute = "{{ route('coordinator.BooksPublishedResponses.data') }}";
}
if (userRole === 'Faculty') {
dataRoute = "{{ route('faculty.BooksPublishedResponses.data') }}";
}
initAjaxRoute(dataRoute);
});
</script>
@endsection

View File

@@ -0,0 +1,98 @@
@extends('layouts.app')
@section('content')
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white overflow-hidden shadow sm:rounded-lg">
<div class="px-4 py-5 sm:px-6">
<h3 class="text-lg leading-6 font-medium text-gray-900">
Submit Book Publication Details
</h3>
<p class="mt-1 max-w-2xl text-sm text-gray-500">
Fill in the details of your publication.
</p>
</div>
@if ($errors->any())
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<div class="border-t border-gray-200">
<form method="POST" action="{{ route('faculty.BooksPublishedFormResponse') }}" enctype="multipart/form-data">
@csrf
<div class="px-4 py-5 sm:px-6">
<div class="space-y-6">
<!-- Author Information -->
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label for="author" class="block text-sm font-medium text-gray-700">Author Name</label>
<input type="text" name="author" id="author" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" required>
</div>
</div>
<!-- Publication Title -->
<div>
<label for="title" class="block text-sm font-medium text-gray-700">Publication Title</label>
<input type="text" name="title" id="title" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" required>
</div>
<!-- Publication Venue Information -->
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label for="publisher" class="block text-sm font-medium text-gray-700">Publisher Name</label>
<input type="text" name="publisher" id="publisher" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" required>
</div>
</div>
<div>
<label for="issn" class="block text-sm font-medium text-gray-700">ISSN/eISSN number</label>
<input type="text" name="issn" id="issn" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" required>
</div>
<!-- Department and Faculty Name -->
<div class="grid grid-cols-2 sm:grid-cols-2 gap-4">
<div>
<label for="department" class="block text-sm font-medium text-gray-700">Department</label>
<input type="text" name="department" id="department" value="{{ auth()->user()->department->name }}" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm bg-gray-100" disabled>
</div>
<div>
<label for="faculty_name" class="block text-sm font-medium text-gray-700">Faculty Name</label>
<input type="text" name="faculty_name" id="faculty_name" value="{{ auth()->user()->name }}" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm bg-gray-100" disabled>
<input type="hidden" name="faculty_id" value="{{ auth()->user()->id }}">
</div>
</div>
<!-- Date Information -->
<div class="grid grid-cols-2 gap-4">
<div>
<label for="date_of_publication" class="block text-sm font-medium text-gray-700">Date Of Publication</label>
<input type="date" name="date_of_publication" id="date_of_publication" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" required onchange="calculateDays()">
</div>
</div>
<!-- proof File -->
<div>
<label for="proof_file" class="block text-sm font-medium text-gray-700">Upload Proof</label>
<input type="file" name="proof_file" id="proof_file" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" accept=".jpg,.jpeg,.png,.pdf,.doc,.docx,.zip" required>
<p class="mt-1 text-xs text-gray-500">Accepted formats: JPG, JPEG, PNG, PDF, DOC, DOCX, ZIP</p>
</div>
</div>
</div>
<!-- Submit Button -->
<div class="px-4 py-3 sm:px-6 text-center mt-4">
<button type="submit" class="inline-flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-black">
Submit Publication
</button>
</div>
</form>
</div>
</div>
</div>
@endsection

View File

@@ -30,6 +30,9 @@
<x-nav-link :href="route('admin.PublicationsResponses')" :active="request()->routeIs('admin.PublicationsResponses')">
{{ __('Publications') }}
</x-nav-link>
<x-nav-link :href="route('admin.BooksPublishedResponses')" :active="request()->routeIs('admin.BooksPublishedResponses')">
{{ __('Books Published') }}
</x-nav-link>
<!-- Coordinator Routes -->
@elseif(auth()->user()->role->name === 'Coordinator')
@@ -45,6 +48,9 @@
<x-nav-link :href="route('coordinator.PublicationsResponses')" :active="request()->routeIs('coordinator.PublicationsResponses')">
{{ __('Publications') }}
</x-nav-link>
<x-nav-link :href="route('coordinator.BooksPublishedResponses')" :active="request()->routeIs('coordinator.BooksPublishedResponses')">
{{ __('Books Published') }}
</x-nav-link>
<!-- Faculty Routes with Dropdowns -->
@elseif(auth()->user()->role->name === 'Faculty')
@@ -112,6 +118,21 @@
</div>
</div>
</div>
<!-- Books Published Dropdown -->
<div class="relative" x-data="{ open: false }">
<button @click="open = !open" @click.away="open = false" class="inline-flex items-center px-1 pt-1 border-b-2 border-transparent text-sm font-medium leading-5 text-gray-500 hover:text-gray-700 hover:border-gray-300 focus:outline-none focus:text-gray-700 focus:border-gray-300 transition duration-150 ease-in-out">
{{ __('Books Published') }}
<svg class="ml-1 -mr-0.5 h-4 w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" />
</svg>
</button>
<div x-show="open" x-transition:enter="transition ease-out duration-100" x-transition:enter-start="transform opacity-0 scale-95" x-transition:enter-end="transform opacity-100 scale-100" x-transition:leave="transition ease-in duration-75" x-transition:leave-start="transform opacity-100 scale-100" x-transition:leave-end="transform opacity-0 scale-95" class="absolute z-50 mt-2 w-48 rounded-md shadow-lg origin-top-right right-0" style="display: none;">
<div class="rounded-md ring-1 ring-black ring-opacity-5 py-1 bg-white">
<a href="{{ route('faculty.BooksPublishedForm') }}" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">{{ __('Submit Response') }}</a>
<a href="{{ route('faculty.BooksPublishedResponses') }}" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">{{ __('View Responses') }}</a>
</div>
</div>
</div>
</div>
@endif
</div>

View File

@@ -8,6 +8,7 @@ use App\Http\Controllers\RoleController;
use App\Http\Controllers\DepartmentController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\AdminController;
use App\Http\Controllers\BooksPublishedController;
use App\Http\Controllers\CoordinatorController;
use App\Http\Controllers\FacultyController;
use App\Http\Controllers\IvOrganisedController;
@@ -52,6 +53,9 @@ Route::delete('/iv-organised/{id}', [IvOrganisedController::class, 'destroy'])->
// Publications common routes
Route::delete('/publication/{id}', [PublicationsController::class, 'destroy'])->name('publications.destroy');
// Books Published common routes
Route::delete('/booksPublished/{id}', [BooksPublishedController::class, 'destroy'])->name('booksPublished.destroy');
// Admin routes
Route::middleware(['auth', CheckRole::class . ':Admin'])->group(function () {
Route::get('/admin', [AdminController::class, 'index'])->name('admin.dashboard');
@@ -83,6 +87,13 @@ Route::middleware(['auth', CheckRole::class . ':Admin'])->group(function () {
Route::get('/admin/publication/{id}/edit', [PublicationsController::class, 'edit'])->name('admin.Publications.edit');
Route::put('/admin/publication/{id}', [PublicationsController::class, 'update'])->name('admin.Publications.update');
Route::delete('/admin/publication/{id}', [PublicationsController::class, 'destroy'])->name('admin.Publications.destroy');
// Books Published Routes
Route::get('/admin/BooksPublishedResponses', [AdminController::class, 'viewBooksPublishedResponses'])->name('admin.BooksPublishedResponses');
Route::get('/admin/BooksPublishedResponses/data', [BooksPublishedController::class, 'getBooksPublishedResponses'])->name('admin.BooksPublishedResponses.data');
Route::get('/admin/booksPublished/{id}/edit', [BooksPublishedController::class, 'edit'])->name('admin.BooksPublished.edit');
Route::put('/admin/booksPublished/{id}', [BooksPublishedController::class, 'update'])->name('admin.BooksPublished.update');
Route::delete('/admin/booksPublished/{id}', [BooksPublishedController::class, 'destroy'])->name('admin.BooksPublished.destroy');
});
// Coordinator routes
@@ -116,6 +127,13 @@ Route::middleware(['auth', CheckRole::class . ':Coordinator'])->group(function (
Route::get('/coordinator/publication/{id}/edit', [PublicationsController::class, 'edit'])->name('coordinator.Publications.edit');
Route::put('/coordinator/publication/{id}', [PublicationsController::class, 'update'])->name('coordinator.Publications.update');
Route::delete('/coordinator/publication/{id}', [PublicationsController::class, 'destroy'])->name('coordinator.Publications.destroy');
// BooksPublished Routes
Route::get('/coordinator/BooksPublishedResponses', [CoordinatorController::class, 'viewBooksPublishedResponses'])->name('coordinator.BooksPublishedResponses');
Route::get('/coordinator/BooksPublishedResponses/data', [BooksPublishedController::class, 'getBooksPublishedResponses'])->name('coordinator.BooksPublishedResponses.data');
Route::get('/coordinator/booksPublished/{id}/edit', [BooksPublishedController::class, 'edit'])->name('coordinator.BooksPublished.edit');
Route::put('/coordinator/booksPublished/{id}', [BooksPublishedController::class, 'update'])->name('coordinator.BooksPublished.update');
Route::delete('/coordinator/booksPublished/{id}', [BooksPublishedController::class, 'destroy'])->name('coordinator.BooksPublished.destroy');
});
// Faculty routes
@@ -153,6 +171,14 @@ Route::middleware(['auth', CheckRole::class . ':Faculty'])->group(function () {
Route::get('/faculty/PublicationsResponses/data', [PublicationsController::class, 'getPublicationsResponses'])->name('faculty.PublicationsResponses.data');
Route::get('/faculty/publication/{id}/edit', [PublicationsController::class, 'edit'])->name('faculty.Publications.edit');
Route::put('/faculty/publication/{id}', [PublicationsController::class, 'update'])->name('faculty.Publications.update');
// Books Published Routes
Route::get('/faculty/BooksPublishedForm', [FacultyController::class, 'BooksPublishedForm'])->name('faculty.BooksPublishedForm');
Route::post('/faculty/BooksPublishedFormResponse', [FacultyController::class, 'BooksPublishedFormResponse'])->name('faculty.BooksPublishedFormResponse');
Route::get('/faculty/BooksPublishedResponses', [FacultyController::class, 'viewBooksPublishedResponses'])->name('faculty.BooksPublishedResponses');
Route::get('/faculty/BooksPublishedResponses/data', [BooksPublishedController::class, 'getBooksPublishedResponses'])->name('faculty.BooksPublishedResponses.data');
Route::get('/faculty/booksPublished/{id}/edit', [BooksPublishedController::class, 'edit'])->name('faculty.BooksPublished.edit');
Route::put('/faculty/booksPublished/{id}', [BooksPublishedController::class, 'update'])->name('faculty.BooksPublished.update');
});
// API Resources