EVOLUTION-NINJA
Edit File: chapter_wise_materials.php
<?php echo view('includes/user_header'); ?> <style> table { /*width: 100%;*/ border-collapse: collapse; margin-top: 20px; } th, td { border: 1px solid black; padding: 10px; text-align: left; } th { background-color: #f4f4f4; } .upd_form button{ background-color: #468662; color: white; padding: 5px; border-radius: 12px; } </style> <div id="page-wrapper"> <input type="hidden" value="<?php echo $topic_id; ?>" class="topic_id"> <!-- /.row --> <!-- /.row --> <div class="row my_header"> <h3 style="padding-bottom:10px;border-bottom:1px solid #ccc;margin-bottom:20px;"><?php if ($chapter_result) { echo $chapter_result->chapter_name; echo ': '; echo htmlspecialchars($chapter_result->topic_name); } ?> - Materials Details</h3> <div class="col-md-2"></div> <div class="row my_header" style="margin: 0 !important;"> <br> <ul class="nav nav-pills" style="background:white; padding:15px; border-radius: 10px; margin-bottom: 20px; background-color: #FFFFFF;"> <li class="active"><a data-toggle="pill" href="#video">Video File</a></li> <li><a data-toggle="pill" href="#pdf">PDF File</a></li> <li><a data-toggle="pill" href="#images">Images</a></li> <li><a data-toggle="pill" href="#assessment">Assessments</a></li> <li><a data-toggle="pill" href="#testupload">Test Upload</a></li> </ul> <div class="tab-content" style="background:white; padding:15px; border-radius: 10px; background-color: #FFFFFF;"> <div id="video" class="tab-pane fade in active"> <div class="row" id="video_uploads_div"></div><!-- row ----> <div class="row" id="blank_video_uploads_div"> </div><!-- row ----> </div><!-- video ----> <div id="pdf" class="tab-pane fade"> <div class="row" id="pdf_uploads_div"></div><!-- row ----> <div class="row" id="blank_pdf_uploads_div"> </div><!-- row ----> </div><!-- pdf ----> <div id="images" class="tab-pane fade"> <div class="row" id="image_uploads_div"></div><!-- row ----> <div class="row" id="blank_image_uploads_div"> </div><!-- row ----> </div><!-- images ----> <div id="assessment" class="tab-pane fade"> <div class="row" id="assessment_uploads_div"></div><!-- row --> <form id="uploadForm" class="upd_form" enctype="multipart/form-data"> <input type="hidden" name="referrer_url" value="<?= current_url(); ?>"> <input type="file" name="file" id="fileInput" accept="image/*,application/pdf"><br> <button type="submit">Upload Asessments</button> </form> <h2>Uploaded Assessments</h2> <table id="uploaded_files_table"> <thead> <tr> <th>Id</th> <th>File Name</th> <th>View File</th> <th>Delete File</th> <th>Status</th> <!--<th>Uploaded At</th>--> </tr> </thead> <tbody id="uploaded_files"></tbody> </table> <div class="row" id="blank_assessment_uploads_div"></div><!-- row --> </div><!-- assessment --> <div id="testupload" class="tab-pane fade"> <div class="row" id="test_uploads_div"></div><!-- row --> <form id="testUploadForm" class="upd_form" enctype="multipart/form-data"> <input type="hidden" name="referrer_url" value="<?= current_url(); ?>"> <input type="file" name="file" id="testFileInput" accept="image/*,application/pdf"><br> <button type="submit">Upload Test File</button> </form> <h2>Uploaded Test Files</h2> <table id="test_uploaded_files_table"> <thead> <tr> <th>Id</th> <th>File Name</th> <th>View File</th> <th>Delete File</th> <th>Status</th> </tr> </thead> <tbody id="test_uploaded_files"></tbody> </table> <div class="row" id="blank_test_uploads_div"></div><!-- row --> </div><!-- testupload --> <input type="hidden" id="faculty_id" /> <input type="hidden" id="chapter_id" /> <div id="questions" class="tab-pane fade"> <div class="row" id="question_uploads_div"> <div id="" class="table-responsive"> <div id="questiontab" style="margin-top:3%" class="grid table-responsive"> <table id="list3"></table> <div id="pager3"></div> <div id="dialogSelectRow" title="Warning" style="display:none"> <p>Please select row</p> </div> </div> </div> </div><!-- row ----> </div><!-- images ----> </div> </div><!-- /.row --> <div class="col-md-2"></div> </div> <!-- /.row --> </div> <style> .pdf_file { padding-bottom: 15px; } .pdf_file img { width: 100px; padding-bottom: 15px; } .video-group , .pdf-group , .image-group{ margin-bottom: 20px; border: 2px solid #ddd; border-radius: 8px; padding: 15px; background-color: #f9f9f9; } /* Style for the month header */ .video-group h3, .pdf-group h3 , .image-group h3 { text-align: center; /* Centering the text */ font-size: 18px; color: #fff; /* White text */ cursor: pointer; padding: 10px 0; background-color: green; /* Background color for the month div */ border-radius: 5px; } /* Hover effect for the month header */ .video-group h3:hover, .pdf-group h3:hover , .image-group h3:hover{ background-color: #0056b3; /* Darker blue on hover */ } </style> <script> $(document).ready(function () { var topic_id = $('.topic_id').val(); call_uploads(topic_id); function call_uploads(topic_id) { var segment = '<?= current_url(true)->getSegment(1) ?>'; $.ajax({ type: 'post', url: "<?php echo site_url('chapter_wise_material_list'); ?>", data: { 'topic_id': topic_id }, success: function (response) { console.log(response); if (response.result == 1) { var video_fields = ''; var pdf_fields = ''; var image_fields = ''; var assessment_field=''; var blank_video = '<div class="col-sm-4 video"><p>No video available</p></div>'; var blank_pdf = '<div class="col-sm-4 video"><p>No PDF available</p></div>'; var blank_image = '<div class="col-sm-4 video"><p>No image available</p></div>'; var assessment_field='<div class="col-sm-4 video"><p>No assesment available</p></div>'; var video_monthly_groups = {}; var pdf_monthly_groups = {}; var image_monthly_groups = {}; $.each(response.message, function (vx, vy) { // Handle Videos if (vy.video && vy.video !== "[]") { var videos = JSON.parse(vy.video); var month = new Date(vy.created_at).toLocaleString('en-us', { month: 'long', year: 'numeric' }); if (!video_monthly_groups[month]) { video_monthly_groups[month] = ''; } $.each(videos, function (key, val) { video_monthly_groups[month] += ` <div class="col-sm-12 col-md-4 col-lg-3 video"> <video width="100%" height="300" controls style="border-radius: 5px;"> <source src="<?php echo base_url('public/subject_videos'); ?>/${val}" type="video/mp4"> </video> <div class="col-sm-12 video_content"> <p style="text-align:left"> <b>Material Name:</b> ${val.substr(10)}<br> <b>Subject Name:</b> ${vy.sub_domain}<br> <b>Faculty Name:</b> ${vy.username}<br> <b>Added Date:</b> ${vy.created_at} </p> </div> </div>`; }); } // Handle PDFs if (vy.pdf && vy.pdf !== "[]") { var pdfs = JSON.parse(vy.pdf); var month = new Date(vy.created_at).toLocaleString('en-us', { month: 'long', year: 'numeric' }); if (!pdf_monthly_groups[month]) { pdf_monthly_groups[month] = ''; } $.each(pdfs, function (key, val) { pdf_monthly_groups[month] += ` <div class="col-sm-4 pdf_file"> <a href="<?php echo base_url('public/subject_pdf'); ?>/${val}" target="_blank"> <img src="<?php echo base_url('public/assets/images/pdf_file.png'); ?>" class="img-responsive center-block"> </a> <p style="text-align:center"> <b>Material Name:</b> ${val.substr(10)}<br> <b>Subject Name:</b> ${vy.sub_domain}<br> <b>Faculty Name:</b> ${vy.username}<br> <b>Added Date:</b> ${vy.created_at} </p> ${segment !== 'chapter-wise-materials' ? `<p style="text-align:center"> <a style="text-decoration:none;" href="<?php echo base_url('public/subject_pdf'); ?>/${val}" target="_blank" download> <button type="button">Download</button> </a> </p>` : ''} </div>`; }); } // Handle Images if (vy.image && vy.image !== "[]") { var images = JSON.parse(vy.image); var month = new Date(vy.created_at).toLocaleString('en-us', { month: 'long', year: 'numeric' }); if (!image_monthly_groups[month]) { image_monthly_groups[month] = ''; } $.each(images, function (key, val) { image_monthly_groups[month] += ` <div class="col-sm-4 images_file"> <a href="javascript:void(0);" target="_blank"> <img src="<?php echo base_url('public/subject_images'); ?>/${val}" class="img-responsive center-block"> </a> <p style="text-align:center"> <b>Material Name:</b> ${val.substr(10)}<br> <b>Subject Name:</b> ${vy.sub_domain}<br> <b>Faculty Name:</b> ${vy.username}<br> <b>Added Date:</b> ${vy.created_at} </p> ${segment !== 'chapter-wise-materials' ? `<p style="text-align:center"> <a style="text-decoration:none;" href="<?php echo base_url('public/subject_images'); ?>/${val}" target="_blank" download> <button type="button">Download</button> </a> </p>` : ''} </div>`; }); } }); $(document).ready(function () { fetchFiles(); $('#uploadForm').submit(function (e) { e.preventDefault(); var formData = new FormData(this); $.ajax({ url: "<?php echo base_url('upload/assessment')?>", type: 'POST', data: formData, contentType: false, processData: false, success: function (response) { if (response.status === 'success') { fetchFiles(); $('#uploadForm').trigger("reset"); } else { alert('Upload failed: ' + response.message); } } }); }); function fetchFiles() { const baseUrl = "<?= base_url() ?>"; $.ajax({ url: "<?php echo base_url('fetch/assessments') ?>", type: 'GET', dataType: 'json', success: function (response) { var filesHTML = ''; if (response.files.length > 0) { $.each(response.files, function (index, file) { let statusHTML = file.status === 'pending' ? '<span style="color: orange;">Pending</span>' : '<span style="color: green;">Approved</span>'; filesHTML += ` <tr> <td>${index + 1}</td> <td>${file.file_name}</td> <td style="text-align: center;"><a href="${baseUrl}${file.file_path}" target="_blank">View</a></td> <td style="text-align: center;"> ${file.status === 'pending' ? `<button class="deletee-btn" data-id="${file.id}" style="color: red;">Delete</button>` : `<button class="deletee-btn" data-id="${file.id}" style="color: grey;" disabled>Delete</button>`} </td> <td>${statusHTML}</td> </tr>`; }); } else { filesHTML = `<tr><td colspan="5" style="text-align: center;">No files uploaded yet.</td></tr>`; } $('#uploaded_files').html(filesHTML); }, error: function () { alert('Error fetching files. Please try again.'); } }); } // ===== Test Upload Form Submission ===== $('#testUploadForm').submit(function (e) { e.preventDefault(); var formData = new FormData(this); $.ajax({ url: "<?php echo base_url('upload_test')?>", // Controller method to handle test upload type: 'POST', data: formData, contentType: false, processData: false, success: function (response) { if (response.status === 'success') { fetchTestFiles(); $('#testUploadForm').trigger("reset"); } else { alert('Test upload failed: ' + response.message); } } }); }); // ===== Fetch Test Uploaded Files ===== function fetchTestFiles() { const baseUrl = "<?= base_url() ?>"; $.ajax({ url: "<?php echo base_url('fetch_tests') ?>", // Controller method to fetch test uploads type: 'GET', dataType: 'json', success: function (response) { var filesHTML = ''; if (response.files.length > 0) { $.each(response.files, function (index, file) { let statusHTML = file.status === 'pending' ? '<span style="color: orange;">Pending</span>' : '<span style="color: green;">Approved</span>'; filesHTML += ` <tr> <td>${index + 1}</td> <td>${file.file_name}</td> <td style="text-align: center;"><a href="${baseUrl}${file.file_path}" target="_blank">View</a></td> <td style="text-align: center;"> ${file.status === 'pending' ? `<button class="delete-test-btn" data-id="${file.id}" style="color: red;">Delete</button>` : `<button class="delete-test-btn" data-id="${file.id}" style="color: grey;" disabled>Delete</button>`} </td> <td>${statusHTML}</td> </tr>`; }); } else { filesHTML = `<tr><td colspan="5" style="text-align: center;">No test files uploaded yet.</td></tr>`; } $('#test_uploaded_files').html(filesHTML); }, error: function () { alert('Error fetching test files.'); } }); } fetchTestFiles(); }); // Handle delete button click $(document).on('click', '.deletee-btn', function () { var fileId = $(this).data('id'); if (confirm("Are you sure you want to delete this file?")) { $.ajax({ url: "<?php echo base_url('delete/assessment') ?>", type: 'POST', data: { id: fileId }, dataType: 'json', success: function (response) { if (response.status === 'success') { alert('File deleted successfully!'); // If you're using DataTables window.location.reload(); } else { alert('Delete failed: ' + response.message); } }, error: function (xhr, status, error) { console.error(xhr.responseText); // Log error details for debugging alert('Error deleting file.'); } }); } }); // Handle delete button click for test uploads $(document).on('click', '.delete-test-btn', function () { var fileId = $(this).data('id'); if (confirm("Are you sure you want to delete this test file?")) { $.ajax({ url: "<?= base_url('delete_test') ?>", // Must be inside .php type: 'POST', data: { id: fileId }, dataType: 'json', success: function (response) { if (response.status === 'success') { alert('Test file deleted successfully!'); // If you're using DataTables window.location.reload(); } else { alert('Delete failed: ' + response.message); } }, error: function (xhr) { console.error("Error:", xhr.responseText); alert('Error deleting test file.'); } }); } }); // Append grouped videos $.each(video_monthly_groups, function (month, videos_html) { video_fields += ` <div class="video-group"> <h3 class="video-month" data-month="${month}">${month}</h3> <div class="row video-items" style="display:none">${videos_html}</div> </div>`; }); // Append grouped PDFs $.each(pdf_monthly_groups, function (month, pdf_html) { pdf_fields += ` <div class="pdf-group"> <h3 class="pdf-month" data-month="${month}">${month}</h3> <div class="row pdf-items" style="display:none">${pdf_html}</div> </div>`; }); // Append grouped images $.each(image_monthly_groups, function (month, image_html) { image_fields += ` <div class="image-group"> <h3 class="image-month" data-month="${month}">${month}</h3> <div class="row image-items" style="display:none">${image_html}</div> </div>`; }); // Append to the HTML $("#video_uploads_div").html(video_fields || blank_video); $("#pdf_uploads_div").html(pdf_fields || blank_pdf); $("#image_uploads_div").html(image_fields || blank_image); // Toggle visibility on month click $('.video-month').click(function () { var month = $(this).data('month'); $(this).next('.video-items').toggle(); }); $('.pdf-month').click(function () { var month = $(this).data('month'); $(this).next('.pdf-items').toggle(); }); $('.image-month').click(function () { var month = $(this).data('month'); $(this).next('.image-items').toggle(); }); } } }); } }); </script> <?php echo view('includes/user_footer'); ?>