Misc fixes for athletic teams.
[openemr.git] / interface / reports / players_report.php
blobade0dd5b757d5458d3a84a2f5a3bbcdc72dc6ac0
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 lists all players/patients by name within squad.
10 // It is applicable only for sports teams.
12 require_once("../globals.php");
13 require_once("$srcdir/patient.inc");
14 require_once("$srcdir/acl.inc");
15 require_once("$srcdir/calendar_events.inc.php");
17 $squads = acl_get_squads();
18 $auth_notes_a = acl_check('encounters', 'notes_a');
20 $alertmsg = ''; // not used yet but maybe later
22 $form_date = fixDate($_POST['form_date'], date('Y-m-d'));
24 // $now = time();
25 $now = mktime(0, 0, 0, substr($form_date, 5, 2),
26 substr($form_date, 8, 2), substr($form_date, 0, 4));
28 // Get attributes of the default fitless level.
29 $fdefault = sqlQuery("SELECT * FROM list_options WHERE " .
30 "list_id = 'fitness' ORDER BY is_default DESC, seq ASC LIMIT 1");
32 $query = "SELECT pid, squad, fitness, lname, fname FROM patient_data";
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;
51 $ordres = array();
52 if ($res) {
53 while ($row = sqlFetchArray($res)) $ordres[] = $row;
54 usort($ordres, "patient_compare");
57 <html>
58 <head>
59 <?php html_header_show(); ?>
60 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
62 <style type="text/css">
63 </style>
65 <?php if (empty($_GET['embed'])) { ?>
66 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/topdialog.js"></script>
67 <?php } ?>
68 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
69 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script>
70 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/ajtooltip.js"></script>
71 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/textformat.js"></script>
73 <script language="JavaScript">
74 <?php if (empty($_GET['embed'])) require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
76 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
78 function gopid(pid) {
79 <?php
80 $maintop = $_GET['embed'] ? "top" : "opener.top";
81 echo " $maintop.restoreSession();\n";
82 if ($GLOBALS['concurrent_layout']) {
83 echo " $maintop.RTop.location = '../patient_file/summary/demographics.php?set_pid=' + pid;\n";
84 echo " $maintop.left_nav.forceDual();\n";
85 } else {
86 echo " $maintop.location = '../patient_file/patient_file.php?set_pid=' + pid;\n";
88 if (empty($_GET['embed'])) echo " window.close();\n";
92 // Process click to pop up the dialog window.
93 function rosdlgclick(pid, date) {
94 cascwin('players_report_dialog.php?plid=' + pid + '&date=' + date,
95 '_blank', 850, 550, "resizable=1,scrollbars=1");
98 function mov1(elem, plid) {
99 ttMouseOver(elem, "players_report_ajax.php?plid=" + plid);
102 function mov2(elem, plid, date) {
103 ttMouseOver(elem, "players_report_ajax.php?plid=" + plid + "&date=" + date);
106 function refreshme() {
107 // location.reload();
108 document.forms[0].submit();
111 </script>
113 <title><?php xl('Weekly Exposures','e'); ?></title>
114 </head>
116 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
117 <center>
119 <form method='post' action='players_report.php<?php if (!empty($_GET['embed'])) echo "?embed=1"; ?>'>
121 <table border='0' cellpadding='5' cellspacing='0' width='98%'>
123 <tr>
124 <td height="1" colspan="2">
125 </td>
126 </tr>
128 <tr bgcolor='#ddddff'>
129 <td align='left'>
130 <h2><?php xl('Weekly Exposures','e'); ?></h2>
131 </td>
132 <td align='right'>
133 <b><?php echo date('l, F j, Y', $now) ?></b>&nbsp;
134 <input type='text' name='form_date' id='form_date' size='10' value='<?php echo date('Y-m-d', $now) ?>'
135 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
136 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
137 id='img_date' border='0' alt='[?]' style='cursor:pointer'
138 title='<?php xl('Click here to choose a start date','e'); ?>'>
139 &nbsp;
140 <input type='submit' name='form_refresh' value='<?php xl('Refresh','e'); ?>'>
141 </td>
142 </tr>
144 <tr>
145 <td height="1" colspan="2">
146 </td>
147 </tr>
149 </table>
151 <table border='0' cellpadding='1' cellspacing='2' width='98%'>
153 <tr bgcolor="#dddddd">
154 <td class="dehead">
155 &nbsp;<?php xl('Squad','e'); ?>
156 </td>
157 <td class="dehead">
158 &nbsp;<?php xl('Player','e'); ?>
159 </td>
161 <?php
162 $time = $now;
163 for ($day = 0; $day < 8; ++$day) {
164 echo " <td class='dehead' colspan='2' align='center'>";
165 echo date('D', $time);
166 echo "</td>\n";
167 $time += 60 * 60 * 24;
170 </tr>
171 <?php
172 $lastsquad = '';
173 foreach ($ordres as $row) {
174 $squadvalue = $row['squad'];
175 $squadname = $squads[$squadvalue][3];
176 if ($squadname) {
177 if (! acl_check('squads', $squadvalue)) continue;
178 } else {
179 $squadname = "None";
181 $patient_id = $row['pid'];
183 <tr>
184 <td class="detail">
185 &nbsp;<?php echo ($squadname == $lastsquad) ? "" : $squadname ?>
186 </td>
187 <td class="detail">
188 &nbsp;<a href='javascript:gopid(<?php echo $patient_id ?>)' style='color:#000000'><?php echo $row['lname'] . ", " . $row['fname'] ?></a>
189 </td>
190 <?php
191 $time = $now;
192 for ($day = 0; $day < 8; ++$day) {
193 $date = date('Y-m-d', $time);
194 $ymd = date('Ymd', $time);
196 $dfrow = sqlQuery("SELECT df.*, lf.title AS lf_title, lf.mapping AS lf_mapping " .
197 "FROM daily_fitness AS df " .
198 "LEFT JOIN list_options AS lf ON lf.list_id = 'fitness' AND lf.option_id = df.fitness " .
199 "WHERE df.pid = '$patient_id' AND df.date = '$date'");
201 if (empty($dfrow)) {
202 $dfrow = array(
203 'fitness' => $fdefault['option_id'],
204 'lf_title' => $fdefault['title'],
205 'lf_mapping' => $fdefault['mapping'],
206 // 'am' => '',
207 // 'pm' => '',
211 $mapping = explode(':', $dfrow['lf_mapping']);
212 $bgcolor = $mapping[0];
214 // Compute percentage of participation.
215 $eventmins = 0;
216 $partmins = 0;
217 $eres = getSquadEvents($date, $squadvalue, $patient_id);
219 while ($erow = sqlFetchArray($eres)) {
220 if (!eventMatchesDay($erow, $date)) continue;
221 $duration = (int) ($erow['pc_duration'] / 60);
222 $eventmins += $duration;
223 if (empty($erow['pid']) || $erow['minutes'] > $duration) {
224 $partmins += $duration;
226 else {
227 $partmins += $erow['minutes'];
231 echo " <td class='detail' " .
232 "bgcolor='$bgcolor' " .
233 "onclick='rosdlgclick($patient_id,$ymd)' " .
234 "onmouseover='mov1(this,$patient_id)' " .
235 "onmouseout='ttMouseOut()' " .
236 ">\n";
237 echo $mapping[1];
238 echo " </td>\n";
239 echo " <td class='detail' align='right' " .
240 "bgcolor='$bgcolor' " .
241 "style='width:40pt;' " .
242 "onclick='rosdlgclick($patient_id,$ymd)' " .
243 "onmouseover='mov2(this,$patient_id,$ymd)' " .
244 "onmouseout='ttMouseOut()' " .
245 "nowrap>\n";
246 if ($partmins < $eventmins) {
247 echo ((int)($partmins * 100 / $eventmins)) . "%\n";
249 echo " </td>\n";
251 $time += 60 * 60 * 24;
254 </tr>
255 <?php
256 $lastsquad = $squadname;
260 </table>
262 </form>
263 </center>
265 <div id='tooltipdiv'
266 style='position:absolute;width:500px;border:1px solid black;padding:2px;background-color:#ffffaa;visibility:hidden;z-index:1000;font-size:9pt;'
267 ></div>
269 <script>
270 <?php
271 if ($alertmsg) {
272 echo " alert('$alertmsg');\n";
275 </script>
276 <!-- stuff for the popup calendar -->
277 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
278 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
279 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
280 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
281 <script language="Javascript">
282 Calendar.setup({inputField:"form_date", ifFormat:"%Y-%m-%d", button:"img_date"});
283 </script>
284 </body>
285 </html>