Skip to content

Commit

Permalink
Initial start of adding exporting for AlexWinder#4
Browse files Browse the repository at this point in the history
  • Loading branch information
zaydons committed Dec 28, 2024
1 parent 4f3b12b commit 39ea17f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
37 changes: 35 additions & 2 deletions html/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,23 @@
// Table ID to relate to the datatable, as identified in the <table> and in the <script>, needed to identify which tables to make into datatables
$datatables_table_id = 'contacts';
// No datatable option required for this page
$datatables_option = null;
$datatables_option = 'dom: \'Bfrtip\', // Define the layout for buttons and table controls
buttons: [
\'csv\', // CSV Export button
{
extend: \'colvis\', // Column visibility button
columns: \':not(.noVis)\', // Exclude columns with the class `noVis`
collectionLayout: \'four-column\', // Control layout of the visibility dropdown
text: \'Column visibility\', // Text for the button
titleAttr: \'Select columns to display\' // Tooltip for the button
}
],
columnDefs: [
{
targets: 1, // Column index to apply class `noVis`
className: \'noVis\' // Add this class for exclusion in the visibility button
}
]';

// Obtain all contacts from the database, which will be used to populate the table
$contacts = new Contact();
Expand All @@ -32,11 +48,24 @@
<!-- CONTENT -->
<?php $session->output_message(); ?>

<table id="<?php echo $datatables_table_id; ?>">
<table class="display nowrap" id="<?php echo $datatables_table_id; ?>">
<?php
if (date_default_timezone_get()) {
echo 'date_default_timezone_set: ' . date_default_timezone_get() . '<br />';
}

if (ini_get('date.timezone')) {
echo 'date.timezone: ' . ini_get('date.timezone');
}
?>
<thead>
<tr>
<th>Name</th>
<th>Address</th>
<th>Address Line 2</th>
<th>Town</th>
<th>Postal Code</th>
<th>State</th>
<th>Mobile Number</th>
<th>Email Address</th>
<th>Actions</th>
Expand All @@ -49,7 +78,11 @@
?>
<tr>
<td><?php echo htmlentities($contacts->full_name($contact["first_name"], $contact["middle_name"], $contact["last_name"])); ?></td>
<td><?php echo htmlentities($contact["address_line_1"]); ?></td>
<td><?php echo htmlentities($contact["address_line_2"]); ?></td>
<td><?php echo htmlentities($contact["address_town"]); ?></td>
<td><?php echo htmlentities($contact["address_post_code"]); ?></td>
<td><?php echo htmlentities($contact["address_county"]); ?></td>
<td><?php if(!empty($contact["contact_number_mobile"])) { echo htmlentities($contacts->format_phone_number($contact["contact_number_mobile"])); } else { echo "NOT SPECIFIED"; }; ?></td>
<td><?php if(!empty($contact["contact_email"])) { echo "<a href=\"mailto:" . htmlentities($contact["contact_email"]) . "\">" . htmlentities($contact["contact_email"]) . "</a>"; } else { echo "NOT SPECIFIED"; }; ?></td>
<td><a href="<?php echo PAGELINK_CONTACTSVIEW; ?>?i=<?php echo urlencode($contact["contact_id"]); ?>">View</a></td>
Expand Down
11 changes: 9 additions & 2 deletions includes/layout.head.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@
$datatables_source = <<<FILEDOC
<!-- DataTables -->
<link rel="stylesheet" type="text/css" href="assets/DataTables/1.10.15/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="assets/DataTables/1.10.15/js/jquery.dataTables.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.5/css/jquery.dataTables.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/2.4.1/css/buttons.dataTables.min.css">
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script src="https://cdn.datatables.net/1.13.5/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/buttons/2.4.1/js/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/buttons/2.4.1/js/buttons.colVis.min.js"></script>
<script src="https://cdn.datatables.net/buttons/2.4.1/js/buttons.html5.min.js"></script>
FILEDOC;
echo $datatables_source;
Expand Down

0 comments on commit 39ea17f

Please sign in to comment.