Merge branch 'master' of git://github.com/openemr/openemr
[openemr.git] / interface / reports / old_players_report.php
blob7d8a60d31a61171fee3ac47f3621f9ee998207aa
1 <?php
2 // Copyright (C) 2005-2010 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 include_once("../globals.php");
13 include_once("$srcdir/patient.inc");
14 include_once("$srcdir/acl.inc");
16 $squads = acl_get_squads();
17 $auth_notes_a = acl_check('encounters', 'notes_a');
19 $alertmsg = ''; // not used yet but maybe later
21 /*********************************************************************
22 // Get fitness level names and colors.
23 $PLAYER_FITNESSES = array();
24 $fres = sqlStatement("SELECT * FROM list_options WHERE " .
25 "list_id = 'fitness' ORDER BY seq");
26 while ($frow = sqlFetchArray($fres)) $PLAYER_FITNESSES[] = $frow['title'];
27 if (!empty($GLOBALS['fitness_colors'])) $PLAYER_FITCOLORS = $GLOBALS['fitness_colors'];
28 *********************************************************************/
29 // Get attributes of the default fitless level.
30 $fdefault = sqlQuery("SELECT * FROM list_options WHERE " .
31 "list_id = 'fitness' ORDER BY is_default DESC, seq ASC LIMIT 1");
32 /********************************************************************/
34 $query = "SELECT pid, squad, lname, fname FROM " .
35 "patient_data"; // ORDER BY squad, lname, fname
36 $res = sqlStatement($query);
38 // Sort the patients in squad priority order.
39 function patient_compare($a, $b) {
40 global $squads;
41 if ($squads[$a['squad']][3] == $squads[$b['squad']][3]) {
42 if ($a['lname'] == $b['lname']) {
43 return ($a['fname'] < $b['fname']) ? -1 : 1;
45 return ($a['lname'] < $b['lname']) ? -1 : 1;
47 // The squads are different so compare their order attributes,
48 // or unassigned squads sort last.
49 if (! $squads[$a['squad']][3]) return 1;
50 if (! $squads[$b['squad']][3]) return -1;
51 return ($squads[$a['squad']][2] < $squads[$b['squad']][2]) ? -1 : 1;
53 $ordres = array();
54 if ($res) {
55 while ($row = sqlFetchArray($res)) $ordres[] = $row;
56 usort($ordres, "patient_compare");
59 <html>
60 <head>
61 <? html_header_show();?>
62 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
64 <script language="JavaScript">
66 function gopid(pid) {
67 <?php
68 $maintop = $_GET['embed'] ? "top" : "opener.top";
69 echo " $maintop.restoreSession();\n";
70 if ($GLOBALS['concurrent_layout']) {
72 echo " $maintop.RTop.location = '../patient_file/summary/demographics.php?set_pid=' + pid;\n";
74 } else {
75 echo " $maintop.location = '../patient_file/patient_file.php?set_pid=' + pid;\n";
77 if (empty($_GET['embed'])) echo " window.close();\n";
81 </script>
83 <title><?php xl('Team Roster','e'); ?></title>
84 </head>
86 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
87 <center>
89 <form method='post' action='old_players_report.php'>
91 <table border='0' cellpadding='5' cellspacing='0' width='98%'>
93 <tr>
94 <td height="1" colspan="2">
95 </td>
96 </tr>
98 <tr bgcolor='#ddddff'>
99 <td align='left'>
100 <h2><?php xl('Team Roster','e'); ?></h2>
101 </td>
102 <td align='right'>
103 <b><?php echo date('l, F j, Y') ?></b>
104 </td>
105 </tr>
107 <tr>
108 <td height="1" colspan="2">
109 </td>
110 </tr>
112 </table>
114 <table border='0' cellpadding='1' cellspacing='2' width='98%'>
116 <tr bgcolor="#dddddd">
117 <td class="dehead">
118 &nbsp;<?php xl('Squad','e'); ?>
119 </td>
120 <td class="dehead">
121 &nbsp;<?php xl('Player','e'); ?>
122 </td>
123 <td class="dehead">
124 &nbsp;<?php xl('Fitness','e'); ?>
125 </td>
126 <td class="dehead">
127 &nbsp;<?php xl('Last Encounter','e'); ?>
128 </td>
129 </tr>
130 <?php
131 // if ($res) {
132 $lastsquad = '';
133 foreach ($ordres as $row) {
134 $squadvalue = $row['squad'];
135 $squadname = $squads[$squadvalue][3];
136 if ($squadname) {
137 if (! acl_check('squads', $squadvalue)) continue;
138 } else {
139 $squadname = "None";
141 $patient_id = $row['pid'];
143 /******************************************************************
144 $fitness = $row['fitness'];
145 if (! $fitness) $fitness = 1;
146 ******************************************************************/
147 $date = date('Y-m-d');
148 $dfrow = sqlQuery("SELECT df.*, lf.title AS lf_title, lf.mapping AS lf_mapping " .
149 "FROM daily_fitness AS df " .
150 "LEFT JOIN list_options AS lf ON lf.list_id = 'fitness' AND lf.option_id = df.fitness " .
151 "WHERE df.pid = '$patient_id' AND df.date = '$date'");
152 if (empty($dfrow)) {
153 $dfrow = array(
154 'fitness' => $fdefault['option_id'],
155 'lf_title' => $fdefault['title'],
156 'lf_mapping' => $fdefault['mapping'],
159 $mapping = explode(':', $dfrow['lf_mapping']);
160 $bgcolor = $mapping[0];
161 /*****************************************************************/
163 $query = "SELECT date, reason " .
164 "FROM form_encounter WHERE " .
165 "pid = '$patient_id' " .
166 "ORDER BY date DESC LIMIT 1";
167 $erow = sqlQuery($query);
169 <tr>
170 <td class="detail">
171 &nbsp;<?php echo ($squadname == $lastsquad) ? "" : $squadname ?>
172 </td>
173 <td class="detail" bgcolor="<?php echo $bgcolor ?>">
174 &nbsp;<a href='javascript:gopid(<?php echo $patient_id ?>)' style='color:#000000'><?php echo $row['lname'] . ", " . $row['fname'] ?></a>
175 </td>
176 <td class="detail" bgcolor="<?php echo $bgcolor ?>">
177 <?php echo $dfrow['lf_title'] ?>&nbsp;
178 </td>
179 <td class="detail" bgcolor="<?php echo $bgcolor ?>">
180 &nbsp;<?php
181 if ($auth_notes_a) {
182 echo substr($erow['date'], 0, 10) . ' ' . $erow['reason'];
183 } else {
184 echo '(No access)';
186 ?>&nbsp;
187 </td>
188 </tr>
189 <?php
190 $lastsquad = $squadname;
192 // }
195 </table>
197 </form>
198 </center>
199 <script>
200 <?php
201 if ($alertmsg) {
202 echo " alert('$alertmsg');\n";
205 </script>
206 </body>
207 </html>