Highway to PSR2
[openemr.git] / interface / therapy_groups / therapy_groups_views / listGroups.php
blobf51de99c52b33257215e144d021880327c9ba707
1 <?php
2 /**
3 * interface/therapy_groups/therapy_groups_views/listGroups.php contains the group list view .
5 * In this view all therapy groups are listed with their details and links to their details screen.
7 * Copyright (C) 2016 Shachar Zilbershlag <shaharzi@matrix.co.il>
8 * Copyright (C) 2016 Amiel Elboim <amielel@matrix.co.il>
10 * LICENSE: This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 3
13 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
21 * @package OpenEMR
22 * @author Shachar Zilbershlag <shaharzi@matrix.co.il>
23 * @author Amiel Elboim <amielel@matrix.co.il>
24 * @link http://www.open-emr.org
27 <?php $edit = acl_check("groups", "gadd", false, 'write');?>
28 <?php $view = acl_check("groups", "gadd", false, 'view');?>
31 <?php require 'header.php'; ?>
32 <?php if ($view || $edit) :?>
34 <span class="hidden title"><?php echo xlt('Therapy Group Finder');?></span>
35 <div id="therapy_groups_list_container" class="container">
37 <!--------- ERRORS ----------->
38 <?php if ($deletion_try == 1 && $deletion_response['success'] == 0) :?>
39 <div class="row">
40 <div class="col-md-6 col-md-offset-3">
41 <div class="alert alert-danger text-center">
42 <p class="failed_message"><?php echo xlt($deletion_response['message']);?></p>
43 </div>
44 </div>
45 </div>
46 <?php endif ?>
48 <!---------- FILTERS SECTION ------------->
49 <?php if ($edit) :?>
50 <button id="clear_filters" class="btn"><?php echo xlt("Clear Filters")?></button>
51 <?php endif;?>
53 </br></br></br>
54 <div id="filters">
55 <div class="row">
56 <div class=" form-group col-md-2">
58 <label class="" for="group_name_filter"><?php echo xlt('Group Name');?>:</label>
59 <input type="text" class="form-control" id="group_name_filter" placeholder="" >
60 </div>
61 <div class=" form-group col-md-2">
62 <label class="" for="group_id_filter"><?php echo xlt('Group Id');?>:</label>
63 <input type="number" class="form-control" id="group_id_filter" placeholder="" >
64 </div>
65 <div class=" form-group col-md-2">
66 <label class="" for="group_type_filter"><?php echo xlt('Group Type');?>:</label>
67 <select type="text" class="form-control" id="group_type_filter" placeholder="" >
68 <option value=""><?php echo xlt('choose');?></option>
69 <?php foreach ($group_types as $type) :?>
70 <option value="<?php echo attr($type);?>"><?php echo text($type) ;?></option>
71 <?php endforeach; ?>
72 </select>
73 </div>
74 <div class=" form-group col-md-2">
75 <label class="" for="group_status_filter"><?php echo xlt('Status');?>:</label>
76 <select type="text" class="form-control" id="group_status_filter" placeholder="" >
77 <option value="<?php echo attr($statuses[10]); ?>"><?php echo xlt($statuses[10]);?></option>
78 <?php foreach ($statuses as $status) :?>
79 <?php if ($status != $statuses[10]) : ?>
80 <option value="<?php echo attr($status);?>"><?php echo xlt($status) ;?></option>
81 <?php endif; ?>
82 <?php endforeach; ?>
83 <option value="all"><?php echo xlt("all");?></option>
84 </select>
85 </div>
86 <div class=" form-group col-md-2">
87 <label class="" for="counselors_filter"><?php echo xlt('Main Counselors');?>:</label>
88 <select type="text" class="form-control" id="counselors_filter" placeholder="" >
89 <option value=""><?php echo xlt('choose');?></option>
90 <?php foreach ($counselors as $counselor) :?>
91 <option value="<?php echo attr($counselor);?>"><?php echo text($counselor) ;?></option>
92 <?php endforeach; ?>
93 </select>
94 </div>
95 </div>
96 <div class="row">
97 <div class=" form-group col-md-2">
98 <label class="" for="group_from_start_date_filter"><?php echo xlt('Starting Date From');?>:</label>
99 <input type="text" class="form-control datepicker" id="group_from_start_date_filter" placeholder="" >
100 </div>
101 <div class=" form-group col-md-2">
102 <label class="" for="group_to_start_date_filter"><?php echo xlt('Starting Date To');?>:</label>
103 <input type="text" class="form-control datepicker" id="group_to_start_date_filter" placeholder="" >
104 </div>
105 <div class=" form-group col-md-2">
106 <label class="" for="group_from_end_date_filter"><?php echo xlt('End Date From');?>:</label>
107 <input type="text" class="form-control datepicker" id="group_from_end_date_filter" placeholder="" >
108 </div>
109 <div class=" form-group col-md-2">
110 <label class="" for="group_to_end_date_filter"><?php echo xlt('End Date To');?>:</label>
111 <input type="text" class="form-control datepicker" id="group_to_end_date_filter" placeholder="" >
112 </div>
114 </div>
115 </div>
116 <!---------- END OF FILTERS SECTION ------------->
118 </br></br>
120 <!---------- TABLE SECTION -------------->
121 <div class="row">
122 <table id="therapy_groups_list" class="dataTable display">
123 <thead>
124 <tr>
125 <th><?php echo xlt('Group Name'); ?></th>
126 <th><?php echo xlt('Group Id'); ?></th>
127 <th><?php echo xlt('Group Type'); ?></th>
128 <th><?php echo xlt('Status'); ?></th>
129 <th><?php echo xlt('Start Date'); ?></th>
130 <th><?php echo xlt('End Date'); ?></th>
131 <th><?php echo xlt('Main Counselors'); ?></th>
132 <th><?php echo xlt('Comment'); ?></th>
133 <th><?php echo xlt('Delete'); ?></th>
134 </tr>
135 </thead>
136 <tbody>
137 <?php foreach ($therapyGroups as $group) : ?>
138 <tr>
139 <td><a href="<?php echo $GLOBALS['rootdir'] . '/therapy_groups/index.php?method=groupDetails&group_id=' . attr($group['group_id']); ?>"><?php echo text($group['group_name']);?></a></td>
140 <td><?php echo text($group['group_id']);?></td>
141 <td><?php echo xlt($group_types[$group['group_type']]);?></td>
142 <td><?php echo xlt($statuses[$group['group_status']]);?></td>
143 <td><?php echo text(oeFormatShortDate($group['group_start_date']));?></td>
144 <td><?php echo ($group['group_end_date'] == '0000-00-00' or $group['group_end_date'] == '00-00-0000' or empty($group['group_end_date'])) ? '' : text(oeFormatShortDate($group['group_end_date'])); ?></td>
145 <td>
146 <?php foreach ($group['counselors'] as $counselor) {
147 echo text($counselor) . " </br> ";
148 } ;?>
149 </td>
150 <td><?php echo text($group['group_notes']);?></td>
151 <td class="delete_btn">
152 <?php
153 //Enable deletion only for groups that weren't yet deleted.
154 if ($group['group_status'] == 10) { ?>
155 <a href="<?php echo $GLOBALS['rootdir'] . '/therapy_groups/index.php?method=listGroups&deleteGroup=1&group_id=' . attr($group['group_id']); ?>"><?php
156 if ($edit) { ?>
157 <button>X</button><?php
158 } ?>
159 </a></td><?php
160 } ?>
162 </td>
163 </tr>
164 <?php endforeach; ?>
165 </tbody>
166 </table>
167 </div>
168 <!---------- END OF TABLE SECTION -------------->
170 </div>
172 <script>
175 /* ========= Initialise Data Table & Filters ========= */
176 $(document).ready(function() {
178 // var lang = '<?php //echo $lang ?>//';//get language support for filters
180 /* Initialise Date Picker */
181 $('.datepicker').datetimepicker({
182 <?php $datetimepicker_timepicker = false; ?>
183 <?php $datetimepicker_showseconds = false; ?>
184 <?php $datetimepicker_formatInput = true; ?>
185 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
186 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
189 /* Initialise Datatable */
190 var table = $('#therapy_groups_list').DataTable({
191 initComplete: function () {
192 $('#therapy_groups_list_filter').hide(); //hide searchbar
194 <?php // Bring in the translations ?>
195 <?php $translationsDatatablesOverride = array('lengthMenu'=>(xla('Display').' _MENU_ '.xla('records per page')),
196 'zeroRecords'=>(xla('Nothing found - sorry')),
197 'info'=>(xla('Showing page') .' _PAGE_ '. xla('of') . ' _PAGES_'),
198 'infoEmpty'=>(xla('No records available')),
199 'infoFiltered'=>('('.xla('filtered from').' _MAX_ '.xla('total records').')'),
200 'infoPostFix'=>(''),
201 'url'=>('')); ?>
202 <?php require($GLOBALS['srcdir'] . '/js/xl/datatables-net.js.php'); ?>
205 /* Order by Start Date column (descending) */
206 table.order( [ 4, 'desc' ] ).draw();
208 /* Hide/Show filters */
209 $("#show_filters").click(function () {
210 $('#filters').show();
211 $("#hide_filters").show();
212 $("#show_filters").hide();
215 $("#hide_filters").click(function () {
216 $('#filters').hide();
217 $("#hide_filters").hide();
218 $("#show_filters").show();
221 /* ------------ Toggle filter functions on keyup/change ----------- */
224 * Note: where there is an explicit extension made for the filter, just table.draw() was used.
225 * Otherwise 'table.columns( ).search( this.value ).draw();' was used.
229 /* ---- Datetimepickers ---- */
230 $('#group_from_start_date_filter').change( function() {
231 table.draw();
232 } );
233 $('#group_to_start_date_filter').change( function() {
234 table.draw();
235 } );
237 $('#group_from_end_date_filter').change( function() {
238 table.draw();
239 } );
240 $('#group_to_end_date_filter').change( function() {
241 table.draw();
242 } );
244 /* --- Text inputs --- */
245 $('#group_name_filter').keyup( function() {
246 table.draw();
247 } );
248 $('#group_id_filter').keyup( function() {
249 table.draw();
250 } );
252 /* ---- Select Boxes ---- */
253 $('#group_type_filter').change(function () {
254 table.columns( 2 ).search( this.value ).draw();
255 } );
257 $('#group_status_filter').change( function() {
258 table.draw();
259 } );
261 $('#counselors_filter').change( function() {
262 table.columns( 6 ).search( this.value ).draw();
263 } );
265 /* ----------------- End of filter toggles -------------------- */
268 /* --------- Reset Filters ------ */
269 $('#clear_filters').click(function(){
270 top.restoreSession();
271 location.reload();
275 /* Bring in the DateToYYYYMMDD_js function */
276 <?php require($GLOBALS['srcdir'] . '/formatting_DateToYYYYMMDD_js.js.php'); ?>
278 /* ========= End Of Data Table & Filters Initialisation ========= */
280 /* ======= DATATABLE FILTER EXTENSIONS ======== */
282 /* Extension for distribution date */
283 $.fn.dataTableExt.afnFiltering.push(
284 function( oSettings, aData, iDataIndex ) {
286 if(document.getElementById('group_from_start_date_filter').value === ""){
287 var iFini = document.getElementById('group_from_start_date_filter').value;
289 else{
290 var iFini = new Date(DateToYYYYMMDD_js(document.getElementById('group_from_start_date_filter').value));
293 if(document.getElementById('group_to_start_date_filter').value === ""){
294 var iFfin = document.getElementById('group_to_start_date_filter').value;
296 else{
297 var iFfin = new Date(DateToYYYYMMDD_js(document.getElementById('group_to_start_date_filter').value));
300 var iStartDateCol = 4;
301 var iEndDateCol = 4;
303 var datofini = new Date(DateToYYYYMMDD_js(aData[iStartDateCol]));
304 var datoffin = new Date(DateToYYYYMMDD_js(aData[iEndDateCol]));
307 if ( iFini === "" && iFfin === "" )
309 return true;
311 else if ( iFini <= datofini && iFfin === "")
313 return true;
315 else if ( iFfin >= datoffin && iFini === "")
317 return true;
319 else if (iFini <= datofini && iFfin >= datoffin)
321 return true;
323 return false;
327 /* Extension for Irregular approval date */
328 $.fn.dataTableExt.afnFiltering.push(
329 function( oSettings, aData, iDataIndex ) {
331 if(document.getElementById('group_from_end_date_filter').value === ""){
332 var iFini = document.getElementById('group_from_end_date_filter').value;
334 else{
335 var iFini = new Date(DateToYYYYMMDD_js(document.getElementById('group_from_end_date_filter').value));
338 if(document.getElementById('group_to_end_date_filter').value === ""){
339 var iFfin = document.getElementById('group_to_end_date_filter').value;
341 else{
342 var iFfin = new Date(DateToYYYYMMDD_js(document.getElementById('group_to_end_date_filter').value));
345 var iStartDateCol = 5;
346 var iEndDateCol = 5;
350 var datofini = new Date(DateToYYYYMMDD_js(aData[iStartDateCol]));
351 var datoffin = new Date(DateToYYYYMMDD_js(aData[iEndDateCol]));
354 if ( iFini === "" && iFfin === "" )
356 return true;
358 else if ( iFini <= datofini && iFfin === "")
360 return true;
362 else if ( iFfin >= datoffin && iFini === "")
364 return true;
366 else if (iFini <= datofini && iFfin >= datoffin)
368 return true;
370 return false;
374 /* Extension for group name */
375 $.fn.dataTableExt.afnFiltering.push(
376 function( oSettings, aData, iDataIndex ) {
377 var iColumn = 0;
378 var iVal = document.getElementById('group_name_filter').value;
379 var iVersion = aData[iColumn] == "-" ? 0 : aData[iColumn];
381 if(iVal === "" || iVal == 0){
382 return true;
384 else if(iVersion.indexOf(iVal) != -1){
385 return true;
387 return false;
391 /* Extension for group id */
392 $.fn.dataTableExt.afnFiltering.push(
393 function( oSettings, aData, iDataIndex ) {
394 var iColumn = 1;
395 var iVal = document.getElementById('group_id_filter').value;
396 var iVersion = aData[iColumn] == "-" ? 0 : aData[iColumn];
398 if(iVal === "" || iVal == 0){
399 return true;
401 else if(iVersion.indexOf(iVal) != -1){
402 return true;
404 return false;
408 /* Extension for group status */
409 $.fn.dataTableExt.afnFiltering.push(
410 function( settings, data, dataIndex ) {
411 var status_selected = $("#group_status_filter").val()||'';
412 var status = data[3] || '';
413 if(status_selected=='' || status_selected == 'all'){
414 return true;
416 if(status==status_selected)
417 return true;
418 return false;
423 /* ========= END OF EXTENSIONS ============= */
426 </script>
428 <?php require 'footer.php'; ?>
429 <?php else :?>
431 <div class="container">
433 <div class="row alert alert-info">
434 <h1 class="col-md-12"><i class="col-md-3 glyphicon glyphicon-alert"></i><span class="col-md-6"><?php echo xlt("access not allowed");?></span></h1>
435 </div>
436 </div>
440 <?php endif;?>