Focus the search term on load
[openemr.git] / interface / reports / old_players_report.php
blob4ee62482129562b911214b5d52e64bad8e73e779
1 <?php
2 // Copyright (C) 2005-2011 Rod Roark <rod@sunsetsystems.com>
3 //
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.
20 $PROPLOGIC = true;
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) {
37 global $squads;
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;
50 $ordres = array();
51 if ($res) {
52 while ($row = sqlFetchArray($res)) $ordres[] = $row;
53 usort($ordres, "patient_compare");
56 <html>
57 <head>
58 <?php html_header_show();?>
59 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
61 <script language="JavaScript">
63 function gopid(pid) {
64 <?php
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.
70 } else {
71 echo " $maintop.location = '../patient_file/patient_file.php?set_pid=' + pid;\n";
73 if (empty($_GET['embed'])) echo " window.close();\n";
77 </script>
79 <title><?php xl('Team Roster','e'); ?></title>
80 </head>
82 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
83 <center>
85 <form method='post' action='old_players_report.php'>
87 <table border='0' cellpadding='5' cellspacing='0' width='98%'>
89 <tr>
90 <td height="1" colspan="2">
91 </td>
92 </tr>
94 <tr bgcolor='#ddddff'>
95 <td align='left'>
96 <h2><?php xl('Team Roster','e'); ?></h2>
97 </td>
98 <td align='right'>
99 <b><?php echo date('l, F j, Y') ?></b>
100 </td>
101 </tr>
103 <tr>
104 <td height="1" colspan="2">
105 </td>
106 </tr>
108 </table>
110 <table border='0' cellpadding='1' cellspacing='2' width='98%'>
112 <tr bgcolor="#dddddd">
113 <td class="dehead">
114 &nbsp;<?php xl('Squad','e'); ?>
115 </td>
116 <td class="dehead">
117 &nbsp;<?php xl('Player','e'); ?>
118 </td>
119 <td class="dehead">
120 &nbsp;<?php xl('Fitness','e'); ?>
121 </td>
122 <td class="dehead">
123 &nbsp;<?php xl('Last Encounter','e'); ?>
124 </td>
125 </tr>
126 <?php
127 // if ($res) {
128 $lastsquad = '';
129 foreach ($ordres as $row) {
130 $squadvalue = $row['squad'];
131 $squadname = $squads[$squadvalue][3];
132 if ($squadname) {
133 if (! acl_check('squads', $squadvalue)) continue;
134 } else {
135 $squadname = "None";
137 $patient_id = $row['pid'];
139 $date = date('Y-m-d');
141 if ($PROPLOGIC) {
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");
150 else {
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'");
157 if (empty($dfrow)) {
158 $dfrow = array(
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);
173 <tr>
174 <td class="detail">
175 &nbsp;<?php echo ($squadname == $lastsquad) ? "" : $squadname ?>
176 </td>
177 <td class="detail" bgcolor="<?php echo $bgcolor ?>">
178 &nbsp;<a href='javascript:gopid(<?php echo $patient_id ?>)' style='color:#000000'><?php echo $row['lname'] . ", " . $row['fname'] ?></a>
179 </td>
180 <td class="detail" bgcolor="<?php echo $bgcolor ?>">
181 <?php echo $dfrow['lf_title'] ?>&nbsp;
182 </td>
183 <td class="detail" bgcolor="<?php echo $bgcolor ?>">
184 &nbsp;<?php
185 if ($auth_notes_a) {
186 echo substr($erow['date'], 0, 10) . ' ' . $erow['reason'];
187 } else {
188 echo '(No access)';
190 ?>&nbsp;
191 </td>
192 </tr>
193 <?php
194 $lastsquad = $squadname;
196 // }
199 </table>
201 </form>
202 </center>
203 <script>
204 <?php
205 if ($alertmsg) {
206 echo " alert('$alertmsg');\n";
209 </script>
210 </body>
211 </html>