482 lines
17 KiB
PHP
482 lines
17 KiB
PHP
<!DOCTYPE html>
|
||
<html>
|
||
|
||
<head>
|
||
<?php
|
||
include 'header.php';
|
||
include 'config.php';
|
||
$user_id = $_GET['user_id'];
|
||
$name = $_GET['name'];
|
||
$company = $_GET['company'];
|
||
$role = $_GET['role'];
|
||
$uploader = 0;
|
||
$visible = false;
|
||
|
||
if ($role == $urole) {
|
||
$uploader = 1;
|
||
}
|
||
|
||
if ($role === $urole || $role === $arole || $role === $rrole || $role === $arole2 || $role === $arole3 || $role === $arole4) {
|
||
$visible = true;
|
||
}
|
||
|
||
$sql = "SELECT * FROM vault_users WHERE id=$user_id";
|
||
$result = $conn->query($sql);
|
||
$row = $result->fetch_assoc();
|
||
$company2 = $row['company2'];
|
||
?>
|
||
|
||
<script type="text/javascript" language="javascript" class="init">
|
||
var editor; // use a global for the submit and return data rendering in the examples
|
||
|
||
$(document).ready(function() {
|
||
editor = new $.fn.dataTable.Editor({
|
||
ajax: {
|
||
<?php
|
||
if ($uploader == 1) {
|
||
echo 'url: "documents2.php",';
|
||
} else {
|
||
echo ' url:"documents.php",';
|
||
}
|
||
?>
|
||
type: "POST",
|
||
data: function(d) {
|
||
// You can dynamically provide the data here
|
||
d.id = <?php echo $user_id ?>;
|
||
d.user = '<?php echo $name ?>';
|
||
d.company = '<?php echo $company ?>';
|
||
d.company2 = '<?php echo $company2 ?>';
|
||
// Make sure to return the updated data object
|
||
return d;
|
||
}
|
||
},
|
||
table: "#example",
|
||
fields: [{
|
||
label: "Type:",
|
||
name: "documents.type",
|
||
type: "select",
|
||
placeholder: "Select document type"
|
||
}, {
|
||
label: "Lot Number:",
|
||
name: "documents.lot_number",
|
||
}, {
|
||
label: "Description:",
|
||
name: "documents.description",
|
||
type: "textarea"
|
||
}, {
|
||
label: "Company:",
|
||
name: "documents.company",
|
||
type: "select",
|
||
placeholder: "Select company"
|
||
}, {
|
||
label: "Department:",
|
||
name: "documents.department",
|
||
type: "select",
|
||
placeholder: "Select department"
|
||
}, {
|
||
label: "Region:",
|
||
name: "documents.region",
|
||
type: "select"
|
||
}, {
|
||
label: "Province:",
|
||
name: "documents.province",
|
||
type: "select"
|
||
|
||
}, {
|
||
label: "City/Municipality:",
|
||
name: "documents.city",
|
||
type: "select"
|
||
}, {
|
||
label: "TCT Number:",
|
||
name: "documents.number"
|
||
}, {
|
||
label: "Total Area:",
|
||
name: "documents.area"
|
||
}, {
|
||
label: "Unit of Measure:",
|
||
name: "documents.unit",
|
||
type: "select",
|
||
placeholder: "Select unit of measure"
|
||
}, {
|
||
label: "File:",
|
||
name: "documents.file",
|
||
visible: <?php echo $visible ? 'true' : 'false'; ?>,
|
||
type: "upload",
|
||
display: function(file_id) {
|
||
// Extract the filename from the web_path
|
||
const filename = editor.file('files', file_id).web_path.split('/').pop();
|
||
|
||
// Display the PDF icon and filename
|
||
return `<i class="fa fa-file-pdf-o"></i> ${filename}`;
|
||
},
|
||
clearText: "Clear",
|
||
noImageText: 'No PDF',
|
||
|
||
}, {
|
||
label: "Vault Number:",
|
||
name: "documents.vault",
|
||
visible: <?php echo $visible ? 'true' : 'false'; ?>
|
||
}, {
|
||
label: "Folder Number:",
|
||
name: "documents.folder",
|
||
visible: <?php echo $visible ? 'true' : 'false'; ?>
|
||
}
|
||
|
||
]
|
||
});
|
||
editor.dependent('documents.region', '/api/province/index.php');
|
||
editor.dependent('documents.province', '/api/city/index.php');
|
||
$('#example').DataTable({
|
||
dom: "Bfrtip",
|
||
ajax: {
|
||
<?php
|
||
if ($uploader == 1) {
|
||
echo 'url: "documents2.php",';
|
||
} else {
|
||
echo ' url:"documents.php",';
|
||
}
|
||
?>
|
||
type: "POST",
|
||
data: function(d) {
|
||
// You can dynamically provide the data here
|
||
d.id = <?php echo $user_id ?>;
|
||
d.user = '<?php echo $name ?>';
|
||
d.company = '<?php echo $company ?>';
|
||
d.company2 = '<?php echo $company2 ?>';
|
||
// Make sure to return the updated data object
|
||
return d;
|
||
}
|
||
},
|
||
columns: [{
|
||
data: "documents.id"
|
||
},
|
||
{
|
||
data: "documents.date"
|
||
},
|
||
{
|
||
data: "type.name"
|
||
},
|
||
{
|
||
data: "documents.lot_number"
|
||
},
|
||
{
|
||
data: "documents.description"
|
||
},
|
||
{
|
||
data: "company.name"
|
||
},
|
||
{
|
||
data: "department.name"
|
||
},
|
||
{
|
||
data: "city.name"
|
||
},
|
||
{
|
||
data: "province.name"
|
||
},
|
||
{
|
||
data: "region.name"
|
||
},
|
||
{
|
||
data: "documents.number"
|
||
},
|
||
{
|
||
data: "documents.area"
|
||
},
|
||
{
|
||
data: "unit.name"
|
||
},
|
||
{
|
||
data: "documents.file",
|
||
visible: <?php echo $visible ? 'true' : 'false'; ?>,
|
||
render: function(file_id) {
|
||
if (file_id) {
|
||
// Extract the filename from the web_path
|
||
const filename = editor.file('files', file_id).web_path.split('/').pop();
|
||
|
||
// Display the PDF icon and filename
|
||
return `<i class="fa fa-file-pdf-o"></i> ${filename}`;
|
||
} else {
|
||
return 'No PDF';
|
||
}
|
||
},
|
||
title: 'PDF'
|
||
},
|
||
{
|
||
data: "documents.vault",
|
||
visible: <?php echo $visible ? 'true' : 'false'; ?>
|
||
},
|
||
{
|
||
data: "documents.folder",
|
||
visible: <?php echo $visible ? 'true' : 'false'; ?>
|
||
},
|
||
{
|
||
data: null,
|
||
render: function(data, type, row, meta) {
|
||
var visible = false;
|
||
<?php
|
||
if ($visible) {
|
||
echo "var visible = true;";
|
||
}
|
||
?>
|
||
var btns = '<a class="btn btn-default btn-sm" href="actions/request.php?doc_id=' +
|
||
data.documents.id + '&user_id=<?php echo $user_id; ?>&role=<?php echo $role; ?>">Request</a>';
|
||
if (visible) {
|
||
btns = '<a class="btn btn-default btn-sm" href="actions/print.php?doc_id=' +
|
||
data.documents.id + '" target="_blank">Print Labels</a> ' + btns;
|
||
|
||
// btns += ' <button class="btn btn-default btn-sm" onclick="openModal(\'' + data.documents.id + '\')">Add Table of Contents</button>';
|
||
var $doc_id = data.documents.id;
|
||
btns += ' <button class="btn btn-default btn-sm" onclick="openModal(\'' + $doc_id + '\')">Add Table of Contents</button>';
|
||
|
||
}
|
||
return btns;
|
||
}
|
||
}
|
||
],
|
||
select: true,
|
||
buttons: [
|
||
<?php
|
||
if ($role === $urole) {
|
||
echo '{ extend: "create", editor: editor },';
|
||
echo '{ extend: "edit", editor: editor },';
|
||
echo '{ extend: "remove", editor: editor }';
|
||
//echo '{ text: "Request", action: function (dt) { window.open("https://google.com","_self") } }';
|
||
}
|
||
?>
|
||
]
|
||
});
|
||
});
|
||
|
||
var selectedDocId;
|
||
|
||
function openModal(docId) {
|
||
console.log("Received docId:", docId);
|
||
|
||
selectedDocId = docId;
|
||
console.log(selectedDocId);
|
||
|
||
// Refresh DataTable with new docId
|
||
$('#toc').DataTable().ajax.reload();
|
||
|
||
// Show the modal
|
||
$('#myModal').modal('show');
|
||
}
|
||
</script>
|
||
</head>
|
||
|
||
<body class="dt-example dt-example-bootstrap" style="background-color: rgba(0, 0, 0, 0);">
|
||
<div class="demo-html">
|
||
<table id="example" class="display responsive nowrap" style="width:100%">
|
||
<!-- <table id="example" class="table table-striped table-bordered responsive" style="width:100%"> -->
|
||
<thead>
|
||
<tr>
|
||
<th>ID</th>
|
||
<th>Date</th>
|
||
<th>Type</th>
|
||
<th>Lot Number</th>
|
||
<th>Description</th>
|
||
<th>Company</th>
|
||
<th>Department</th>
|
||
<th>City/Municipality</th>
|
||
<th>Province</th>
|
||
<th>Region</th>
|
||
<th>TCT Number</th>
|
||
<th>Total Area</th>
|
||
<th>Unit of Measure</th>
|
||
<th>File</th>
|
||
<th>Vault Number</th>
|
||
<th>Folder Number</th>
|
||
<th>Action</th>
|
||
</tr>
|
||
</thead>
|
||
<tfoot>
|
||
<tr>
|
||
<th>ID</th>
|
||
<th>Date</th>
|
||
<th>Type</th>
|
||
<th>Lot Number</th>
|
||
<th>Description</th>
|
||
<th>Company</th>
|
||
<th>Department</th>
|
||
<th>City/Municipality</th>
|
||
<th>Province</th>
|
||
<th>Region</th>
|
||
<th>TCT Number</th>
|
||
<th>Total Area</th>
|
||
<th>Unit of Measure</th>
|
||
<th>File</th>
|
||
<th>Vault Number</th>
|
||
<th>Folder Number</th>
|
||
<th>Action</th>
|
||
</tr>
|
||
</tfoot>
|
||
</table>
|
||
</div>
|
||
</body>
|
||
|
||
|
||
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
|
||
<div class="modal-dialog">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<h4 class="modal-title" id="myModalLabel">Table of Contents</h4>
|
||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||
</div>
|
||
<div class="modal-body">
|
||
<div class="demo-html">
|
||
<table id="toc" class="display responsive nowrap" style="width:100%">
|
||
<thead>
|
||
<tr>
|
||
<th>ID</th>
|
||
<th>Document</th>
|
||
<th>Filing Tab Number</th>
|
||
<th>Document ID</th>
|
||
</tr>
|
||
</thead>
|
||
<tfoot>
|
||
<tr>
|
||
<th>ID</th>
|
||
<th>Document</th>
|
||
<th>Filing Tab Number</th>
|
||
<th>Document ID</th>
|
||
</tr>
|
||
</tfoot>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
<div class="modal-footer">
|
||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<style>
|
||
#myModal {
|
||
z-index: 10009 !important;
|
||
/* Adjust the z-index value as needed */
|
||
}
|
||
</style>
|
||
<script type="text/javascript" language="javascript" class="init">
|
||
var editor; // use a global for the submit and return data rendering in the examples
|
||
|
||
$(document).ready(function() {
|
||
editor = new $.fn.dataTable.Editor({
|
||
ajax: {
|
||
<?php
|
||
if ($uploader == 1) {
|
||
echo 'url: "toc.php",';
|
||
} else {
|
||
echo ' url:"documents.php",';
|
||
}
|
||
?>
|
||
type: "POST",
|
||
data: function(e) {
|
||
// You can dynamically provide the data here
|
||
e.id = <?php echo $user_id ?>;
|
||
e.user = '<?php echo $name ?>';
|
||
e.company = '<?php echo $company ?>';
|
||
e.company2 = '<?php echo $company2 ?>';
|
||
e.doc_id = selectedDocId || null;
|
||
// e.doc_id = selectedDocId; // Pass the selected document ID
|
||
// Make sure to return the updated data object
|
||
|
||
return e;
|
||
}
|
||
},
|
||
table: "#toc",
|
||
fields: [{
|
||
label: "Document:",
|
||
name: "table_of_content.document",
|
||
type: "text"
|
||
},
|
||
{
|
||
label: "Filing Tab Number:",
|
||
name: "table_of_content.number",
|
||
type: "text"
|
||
},
|
||
{
|
||
label: "Document ID",
|
||
name: "table_of_content.doc_id",
|
||
type: "hidden",
|
||
|
||
}
|
||
|
||
|
||
|
||
]
|
||
});
|
||
|
||
|
||
$('#toc').DataTable({
|
||
dom: "Bfrtip",
|
||
ajax: {
|
||
<?php
|
||
if ($uploader == 1) {
|
||
echo 'url: "toc.php",';
|
||
} else {
|
||
echo ' url:"documents.php",';
|
||
}
|
||
?>
|
||
type: "POST",
|
||
data: function(e) {
|
||
// You can dynamically provide the data here
|
||
e.id = <?php echo $user_id ?>;
|
||
e.user = '<?php echo $name ?>';
|
||
e.company = '<?php echo $company ?>';
|
||
e.company2 = '<?php echo $company2 ?>';
|
||
e.doc_id = selectedDocId || null ;
|
||
|
||
// Make sure to return the updated data object
|
||
return e;
|
||
}
|
||
},
|
||
columns: [{
|
||
data: "table_of_content.id"
|
||
},
|
||
{
|
||
data: "table_of_content.document"
|
||
},
|
||
{
|
||
data: "table_of_content.number"
|
||
},
|
||
{
|
||
data: "table_of_content.doc_id"
|
||
}
|
||
],
|
||
select: true,
|
||
buttons: [
|
||
<?php
|
||
if ($role === $urole) {
|
||
echo '{ extend: "create", editor: editor },';
|
||
echo '{ extend: "edit", editor: editor },';
|
||
echo '{ extend: "remove", editor: editor }';
|
||
}
|
||
?>
|
||
],
|
||
|
||
});
|
||
|
||
editor
|
||
.on('open', function() {
|
||
$('#myModal').modal('hide');
|
||
})
|
||
.on('close', function() {
|
||
$('#myModal').modal('show');
|
||
})
|
||
.on('initCreate', function() {
|
||
editor.field('table_of_content.doc_id').val(selectedDocId);
|
||
});
|
||
|
||
// editor.on('initCreate', function() {
|
||
// editor.field('table_of_content.doc_id').val(selectedDocId);
|
||
// });
|
||
|
||
|
||
// Initialize the DataTables Editor instance
|
||
// editor.create();
|
||
});
|
||
</script>
|
||
|
||
|
||
</html>
|