use squad ordering from phpgacl in the team roster
[openemr.git] / interface / reports / players_report.php
blob62365be62e61c29115217f6448185a6bb45f65c2
1 <?
2 // Copyright (C) 2005 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();
18 $fitnesses = array(
19 'Full Play',
20 'Full Training',
21 'Restricted Training',
22 'Injured Out',
23 'Rehabilitation'
26 $fitcolors = array('#6677ff', '#00cc00', '#ffff00', '#ff3333', '#ff8800');
28 $alertmsg = ''; // not used yet but maybe later
30 $query = "SELECT pid, squad, fitness, lname, fname FROM " .
31 "patient_data"; // ORDER BY squad, lname, fname
32 $res = sqlStatement($query);
34 // Sort the patients in squad priority order.
35 function patient_compare($a, $b) {
36 global $squads;
37 if ($squads[$a['squad']][3] == $squads[$b['squad']][3]) {
38 if ($a['lname'] == $b['lname']) {
39 return ($a['fname'] < $b['fname']) ? -1 : 1;
41 return ($a['lname'] < $b['lname']) ? -1 : 1;
43 // The squads are different so compare their order attributes,
44 // or unassigned squads sort last.
45 if (! $squads[$a['squad']][3]) return 1;
46 if (! $squads[$b['squad']][3]) return -1;
47 return ($squads[$a['squad']][2] < $squads[$b['squad']][2]) ? -1 : 1;
49 $ordres = array();
50 if ($res) {
51 while ($row = sqlFetchArray($res)) $ordres[] = $row;
52 usort($ordres, "patient_compare");
55 <html>
56 <head>
57 <link rel=stylesheet href="<?echo $css_header;?>" type="text/css">
59 <script language="JavaScript">
61 function gopid(pid) {
62 <? if ($_GET['embed']) { ?>
63 top.location = '../patient_file/patient_file.php?set_pid=' + pid;
64 <? } else { ?>
65 opener.top.location = '../patient_file/patient_file.php?set_pid=' + pid;
66 window.close();
67 <? } ?>
70 </script>
72 <title>Team Roster</title>
73 </head>
75 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
76 <center>
78 <form method='post' action='players_report.php'>
80 <table border='0' cellpadding='5' cellspacing='0' width='98%'>
82 <tr>
83 <td height="1" colspan="2">
84 </td>
85 </tr>
87 <tr bgcolor='#ddddff'>
88 <td align='left'>
89 <h2>Team Roster</h2>
90 </td>
91 <td align='right'>
92 <b><? echo date('l, F j, Y') ?></b>
93 </td>
94 </tr>
96 <tr>
97 <td height="1" colspan="2">
98 </td>
99 </tr>
101 </table>
103 <table border='0' cellpadding='1' cellspacing='2' width='98%'>
105 <tr bgcolor="#dddddd">
106 <td class="dehead">
107 &nbsp;Squad
108 </td>
109 <td class="dehead">
110 &nbsp;Player
111 </td>
112 <td class="dehead">
113 &nbsp;Fitness
114 </td>
115 <td class="dehead">
116 &nbsp;Last Encounter
117 </td>
118 </tr>
120 // if ($res) {
121 $lastsquad = '';
122 foreach ($ordres as $row) {
123 $squadvalue = $row['squad'];
124 $squadname = $squads[$squadvalue][3];
125 if ($squadname) {
126 if (! acl_check('squads', $squadvalue)) continue;
127 } else {
128 $squadname = "None";
130 $patient_id = $row['pid'];
131 $fitness = $row['fitness'];
132 if (! $fitness) $fitness = 1;
133 $query = "SELECT date, reason " .
134 "FROM form_encounter WHERE " .
135 "pid = '$patient_id' " .
136 "ORDER BY date DESC LIMIT 1";
137 $erow = sqlQuery($query);
139 <tr>
140 <td class="detail">
141 &nbsp;<? echo ($squadname == $lastsquad) ? "" : $squadname ?>
142 </td>
143 <td class="detail" bgcolor="<? echo $fitcolors[$fitness-1] ?>">
144 &nbsp;<a href='javascript:gopid(<? echo $patient_id ?>)' style='color:#000000'><? echo $row['lname'] . ", " . $row['fname'] ?></a>
145 </td>
146 <td class="detail" bgcolor="<? echo $fitcolors[$fitness-1] ?>">
147 <? echo $fitnesses[$fitness-1] ?>&nbsp;
148 </td>
149 <td class="detail" bgcolor="<? echo $fitcolors[$fitness-1] ?>">
150 &nbsp;<? echo substr($erow['date'], 0, 10) . ' ' . $erow['reason'] ?>&nbsp;
151 </td>
152 </tr>
154 $lastsquad = $squadname;
156 // }
159 </table>
161 </form>
162 </center>
163 <script>
165 if ($alertmsg) {
166 echo " alert('$alertmsg');\n";
169 </script>
170 </body>
171 </html>