2 // Copyright (C) 2005-2011 Rod Roark <rod@sunsetsystems.com>
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 // This report simply lists all players/patients by name within
10 // squad. It is applicable only for sports teams.
12 require_once("../globals.php");
13 require_once("$srcdir/patient.inc");
14 require_once("$srcdir/acl.inc");
16 // Temporary variable while new logic is being tested.
17 // True means that missing days in the daily_fitness table default to
18 // the previous entry's values, if there is one.
19 // Otherwise the default fitness level (Fully Fit) is used.
22 $squads = acl_get_squads();
23 $auth_notes_a = acl_check('encounters', 'notes_a');
25 $alertmsg = ''; // not used yet but maybe later
27 // Get attributes of the default fitless level.
28 $fdefault = sqlQuery("SELECT * FROM list_options WHERE " .
29 "list_id = 'fitness' ORDER BY is_default DESC, seq ASC LIMIT 1");
31 $query = "SELECT pid, squad, lname, fname FROM " .
32 "patient_data"; // ORDER BY squad, lname, fname
33 $res = sqlStatement($query);
35 // Sort the patients in squad priority order.
36 function patient_compare($a, $b) {
38 if ($squads[$a['squad']][3] == $squads[$b['squad']][3]) {
39 if ($a['lname'] == $b['lname']) {
40 return ($a['fname'] < $b['fname']) ?
-1 : 1;
42 return ($a['lname'] < $b['lname']) ?
-1 : 1;
44 // The squads are different so compare their order attributes,
45 // or unassigned squads sort last.
46 if (! $squads[$a['squad']][3]) return 1;
47 if (! $squads[$b['squad']][3]) return -1;
48 return ($squads[$a['squad']][2] < $squads[$b['squad']][2]) ?
-1 : 1;
52 while ($row = sqlFetchArray($res)) $ordres[] = $row;
53 usort($ordres, "patient_compare");
58 <?php
html_header_show();?
>
59 <link rel
=stylesheet href
="<?php echo $css_header;?>" type
="text/css">
61 <script language
="JavaScript">
65 $maintop = $_GET['embed'] ?
"top" : "opener.top";
66 echo " $maintop.restoreSession();\n";
67 if ($GLOBALS['concurrent_layout']) {
68 echo " $maintop.RTop.location = '../patient_file/summary/demographics.php?set_pid=' + pid;\n";
69 // echo " $maintop.left_nav.forceDual();\n"; // Decided not to do this.
71 echo " $maintop.location = '../patient_file/patient_file.php?set_pid=' + pid;\n";
73 if (empty($_GET['embed'])) echo " window.close();\n";
79 <title
><?php
xl('Team Roster','e'); ?
></title
>
82 <body leftmargin
='0' topmargin
='0' marginwidth
='0' marginheight
='0'>
85 <form method
='post' action
='old_players_report.php'>
87 <table border
='0' cellpadding
='5' cellspacing
='0' width
='98%'>
90 <td height
="1" colspan
="2">
94 <tr bgcolor
='#ddddff'>
96 <h2
><?php
xl('Team Roster','e'); ?
></h2
>
99 <b
><?php
echo date('l, F j, Y') ?
></b
>
104 <td height
="1" colspan
="2">
110 <table border
='0' cellpadding
='1' cellspacing
='2' width
='98%'>
112 <tr bgcolor
="#dddddd">
114  
;<?php
xl('Squad','e'); ?
>
117  
;<?php
xl('Player','e'); ?
>
120  
;<?php
xl('Fitness','e'); ?
>
123  
;<?php
xl('Last Encounter','e'); ?
>
129 foreach ($ordres as $row) {
130 $squadvalue = $row['squad'];
131 $squadname = $squads[$squadvalue][3];
133 if (! acl_check('squads', $squadvalue)) continue;
137 $patient_id = $row['pid'];
139 $date = date('Y-m-d');
142 // For a given date, fitness info is the last on or before that date,
143 // or if there is none then the defaults apply.
144 $dfrow = sqlQuery("SELECT df.*, lf.title AS lf_title, lf.mapping AS lf_mapping " .
145 "FROM daily_fitness AS df " .
146 "LEFT JOIN list_options AS lf ON lf.list_id = 'fitness' AND lf.option_id = df.fitness " .
147 "WHERE df.pid = '$patient_id' AND df.date <= '$date' " .
148 "ORDER BY df.date DESC LIMIT 1");
151 $dfrow = sqlQuery("SELECT df.*, lf.title AS lf_title, lf.mapping AS lf_mapping " .
152 "FROM daily_fitness AS df " .
153 "LEFT JOIN list_options AS lf ON lf.list_id = 'fitness' AND lf.option_id = df.fitness " .
154 "WHERE df.pid = '$patient_id' AND df.date = '$date'");
159 'fitness' => $fdefault['option_id'],
160 'lf_title' => $fdefault['title'],
161 'lf_mapping' => $fdefault['mapping'],
164 $mapping = explode(':', $dfrow['lf_mapping']);
165 $bgcolor = $mapping[0];
167 $query = "SELECT date, reason " .
168 "FROM form_encounter WHERE " .
169 "pid = '$patient_id' " .
170 "ORDER BY date DESC LIMIT 1";
171 $erow = sqlQuery($query);
175  
;<?php
echo ($squadname == $lastsquad) ?
"" : $squadname ?
>
177 <td
class="detail" bgcolor
="<?php echo $bgcolor ?>">
178  
;<a href
='javascript:gopid(<?php echo $patient_id ?>)' style
='color:#000000'><?php
echo $row['lname'] . ", " . $row['fname'] ?
></a
>
180 <td
class="detail" bgcolor
="<?php echo $bgcolor ?>">
181 <?php
echo $dfrow['lf_title'] ?
> 
;
183 <td
class="detail" bgcolor
="<?php echo $bgcolor ?>">
186 echo substr($erow['date'], 0, 10) . ' ' . $erow['reason'];
194 $lastsquad = $squadname;
206 echo " alert('$alertmsg');\n";