default.php
264 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package VikAppointments |
| 4 | * @subpackage core |
| 5 | * @author E4J s.r.l. |
| 6 | * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. |
| 7 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 | * @link https://vikwp.com |
| 9 | */ |
| 10 | |
| 11 | // No direct access |
| 12 | defined('ABSPATH') or die('No script kiddies please!'); |
| 13 | |
| 14 | JHtml::fetch('bootstrap.tooltip', '.hasTooltip'); |
| 15 | |
| 16 | $vik = VAPApplication::getInstance(); |
| 17 | |
| 18 | $head = $this->handler->getColumns(); |
| 19 | $rows = $this->rows; |
| 20 | |
| 21 | ?> |
| 22 | |
| 23 | <form action="index.php" method="post" name="adminForm" id="adminForm"> |
| 24 | |
| 25 | <?php |
| 26 | if (!count($rows)) |
| 27 | { |
| 28 | echo $vik->alert(JText::translate('JGLOBAL_NO_MATCHING_RESULTS'), 'warning', false, array('style' => 'margin-top: 10px;')); |
| 29 | } |
| 30 | else |
| 31 | { |
| 32 | ?> |
| 33 | <div class="scrollable-hor"> |
| 34 | <table cellpadding="4" cellspacing="0" border="0" width="100%" class="<?php echo $vik->getAdminTableClass(); ?>"> |
| 35 | <?php echo $vik->openTableHead(); ?> |
| 36 | <tr> |
| 37 | <?php |
| 38 | foreach ($head as $k => $column) |
| 39 | { |
| 40 | ?> |
| 41 | <th class="<?php echo $vik->getAdminThClass('nowrap'); ?>" style="text-align: center;"> |
| 42 | <input type="checkbox" name="columns[]" value="<?php echo $k; ?>" id="export_col_<?php echo $k; ?>" checked="checked" /> |
| 43 | |
| 44 | <label for="export_col_<?php echo $k; ?>"> |
| 45 | <?php echo $column->label; ?> |
| 46 | </label> |
| 47 | </th> |
| 48 | <?php |
| 49 | } |
| 50 | ?> |
| 51 | </tr> |
| 52 | <?php echo $vik->closeTableHead(); ?> |
| 53 | |
| 54 | <?php |
| 55 | for ($i = 0, $n = count($rows); $i < $n; $i++) |
| 56 | { |
| 57 | $row = $rows[$i]; |
| 58 | ?> |
| 59 | <tr class="row<?php echo ($i % 2); ?>"> |
| 60 | <?php |
| 61 | foreach ($head as $k => $label) |
| 62 | { |
| 63 | ?> |
| 64 | <td style="text-align: center;"> |
| 65 | <div> |
| 66 | <?php |
| 67 | $value = $row[$k]; |
| 68 | |
| 69 | $value_no_html = strip_tags((string) $value); |
| 70 | |
| 71 | /** |
| 72 | * Show the first 64 characters when higher than 80. |
| 73 | * |
| 74 | * @since 1.7 |
| 75 | */ |
| 76 | if (strlen($value_no_html) > 80) |
| 77 | { |
| 78 | echo trim(mb_substr($value_no_html, 0, 64, 'UTF-8')) . '...'; |
| 79 | |
| 80 | if (strlen($value_no_html) > 800) |
| 81 | { |
| 82 | // avoid to display more than 800 characters |
| 83 | $value = trim(mb_substr($value_no_html, 0, 800, 'UTF-8')) . '...'; |
| 84 | } |
| 85 | |
| 86 | // then display a tooltip with the remaining text |
| 87 | ?> |
| 88 | <i class="fas fa-info-circle hasTooltip" title="<?php echo $this->escape($value); ?>"></i> |
| 89 | <?php |
| 90 | } |
| 91 | else |
| 92 | { |
| 93 | echo $value; |
| 94 | } |
| 95 | ?> |
| 96 | </div> |
| 97 | </td> |
| 98 | <?php |
| 99 | } |
| 100 | ?> |
| 101 | </tr> |
| 102 | <?php |
| 103 | } |
| 104 | ?> |
| 105 | |
| 106 | </table> |
| 107 | </div> |
| 108 | |
| 109 | <div style="text-align: center;"> |
| 110 | <small><?php echo JText::sprintf('VAPEXPORTTABLEFOOTER', $n, $this->handler->getTotalCount()); ?></small> |
| 111 | </div> |
| 112 | <?php |
| 113 | } |
| 114 | ?> |
| 115 | |
| 116 | <?php echo JHtml::fetch('form.token'); ?> |
| 117 | |
| 118 | <input type="hidden" name="task" value="" /> |
| 119 | <input type="hidden" name="option" value="com_vikappointments" /> |
| 120 | <input type="hidden" name="import_type" value="<?php echo $this->type; ?>" /> |
| 121 | |
| 122 | <?php |
| 123 | foreach ($this->args as $k => $v) |
| 124 | { |
| 125 | ?> |
| 126 | <input type="hidden" name="<?php echo $k; ?>" value="<?php echo $this->escape($v); ?>" /> |
| 127 | <input type="hidden" name="import_args[<?php echo $k; ?>]" value="<?php echo $this->escape($v); ?>" /> |
| 128 | <?php |
| 129 | } |
| 130 | |
| 131 | foreach ($this->cid as $id) |
| 132 | { |
| 133 | ?> |
| 134 | <input type="hidden" name="cid[]" value="<?php echo $this->escape($id); ?>" /> |
| 135 | <?php |
| 136 | } |
| 137 | |
| 138 | echo JHtml::fetch( |
| 139 | 'bootstrap.renderModal', |
| 140 | 'jmodal-download', |
| 141 | array( |
| 142 | 'title' => JText::translate('VAPMAINTITLEVIEWEXPORT'), |
| 143 | 'closeButton' => true, |
| 144 | 'keyboard' => false, |
| 145 | 'bodyHeight' => 60, |
| 146 | 'footer' => '<button type="button" class="btn btn-success" id="export-btn">' . JText::translate('JAPPLY') . '</button>', |
| 147 | ), |
| 148 | $this->loadTemplate('params') |
| 149 | ); |
| 150 | ?> |
| 151 | |
| 152 | </form> |
| 153 | |
| 154 | <style> |
| 155 | .export-column-disabled > * { |
| 156 | opacity: 0.4; |
| 157 | } |
| 158 | </style> |
| 159 | |
| 160 | <script> |
| 161 | |
| 162 | jQuery(function($) { |
| 163 | const columns = $('input[name="columns[]"]'); |
| 164 | |
| 165 | // handle change event to toggle the status of the columns |
| 166 | // to include within the export query |
| 167 | columns.on('change', function() { |
| 168 | const checked = $(this).is(':checked'); |
| 169 | const index = columns.index(this); |
| 170 | |
| 171 | $('#adminForm table tr').each(function() { |
| 172 | let td = $(this).find('td').eq(index); |
| 173 | |
| 174 | if (td.length && checked) { |
| 175 | td.removeClass('export-column-disabled'); |
| 176 | } else { |
| 177 | td.addClass('export-column-disabled'); |
| 178 | } |
| 179 | }); |
| 180 | |
| 181 | // cache column status |
| 182 | cacheColumnStatus($(this).val(), checked); |
| 183 | }); |
| 184 | |
| 185 | const cacheKey = 'export.<?php echo $this->type; ?>.disabled'; |
| 186 | |
| 187 | /** |
| 188 | * Helper function used to cache the status of the disabled |
| 189 | * columns within the browser session storage. |
| 190 | */ |
| 191 | const cacheColumnStatus = (column, status) => { |
| 192 | if (typeof sessionStorage === 'undefined') { |
| 193 | // the browser doesn't support session storage |
| 194 | return false; |
| 195 | } |
| 196 | |
| 197 | // get list of disabled columns |
| 198 | let disabled = getDisabledColumns(); |
| 199 | |
| 200 | // find index of columns within the list, if any |
| 201 | let index = disabled.indexOf(column); |
| 202 | |
| 203 | if (status) { |
| 204 | // enabled, so the column must be removed from the list |
| 205 | if (index !== -1) { |
| 206 | disabled.splice(index, 1); |
| 207 | } |
| 208 | } else { |
| 209 | // disabled, so the column must be included within the list |
| 210 | if (index === -1) { |
| 211 | disabled.push(column); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | // save cache |
| 216 | sessionStorage.setItem(cacheKey, disabled.join(',')); |
| 217 | }; |
| 218 | |
| 219 | /** |
| 220 | * Helper function used to retrieve the disabled |
| 221 | * columns from the browser session storage. |
| 222 | */ |
| 223 | const getDisabledColumns = () => { |
| 224 | if (typeof sessionStorage === 'undefined') { |
| 225 | // the browser doesn't support session storage |
| 226 | return []; |
| 227 | } |
| 228 | |
| 229 | // get list of disabled columns |
| 230 | let disabled = sessionStorage.getItem(cacheKey); |
| 231 | |
| 232 | if (!disabled) { |
| 233 | // create new array from scratch |
| 234 | disabled = []; |
| 235 | } else { |
| 236 | // create array from string |
| 237 | disabled = disabled.split(/\s*,\s*/g); |
| 238 | } |
| 239 | |
| 240 | return disabled; |
| 241 | }; |
| 242 | |
| 243 | // auto-disable cached columns during page loading |
| 244 | getDisabledColumns().forEach((column) => { |
| 245 | $('input[name="columns[]"][value="' + column + '"]') |
| 246 | .prop('checked', false) |
| 247 | .trigger('change'); |
| 248 | }); |
| 249 | }); |
| 250 | |
| 251 | function vapOpenJModal(id, url, jqmodal) { |
| 252 | <?php echo $vik->bootOpenModalJS(); ?> |
| 253 | } |
| 254 | |
| 255 | Joomla.submitbutton = function(task) { |
| 256 | if (task == 'export') { |
| 257 | vapOpenJModal('download', null, true); |
| 258 | } else { |
| 259 | Joomla.submitform(task, document.adminForm); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | </script> |
| 264 |