Various fixes only of interest to athletic teams.
[openemr.git] / interface / reports / players_report.php
blobedf9f71d11a2bc55440640e8219aa7674ddcf6cc
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 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 // Temporary variable while new logic is being tested.
18 // True means that missing days in the daily_fitness table default to
19 // the previous entry's values, if there is one.
20 // Otherwise the default fitness level (Fully Fit) is used.
21 $PROPLOGIC = true;
23 $squads = acl_get_squads();
24 $auth_notes_a = acl_check('encounters', 'notes_a');
26 $alertmsg = ''; // not used yet but maybe later
28 $form_date = fixDate($_POST['form_date'], date('Y-m-d'));
30 // $now = time();
31 $now = mktime(0, 0, 0, substr($form_date, 5, 2),
32 substr($form_date, 8, 2), substr($form_date, 0, 4));
34 // Get attributes of the default fitless level.
35 $fdefault = sqlQuery("SELECT * FROM list_options WHERE " .
36 "list_id = 'fitness' ORDER BY is_default DESC, seq ASC LIMIT 1");
38 $query = "SELECT pid, squad, fitness, lname, fname FROM patient_data";
39 $res = sqlStatement($query);
41 // Sort the patients in squad priority order.
42 function patient_compare($a, $b) {
43 global $squads;
44 if ($squads[$a['squad']][3] == $squads[$b['squad']][3]) {
45 if ($a['lname'] == $b['lname']) {
46 return ($a['fname'] < $b['fname']) ? -1 : 1;
48 return ($a['lname'] < $b['lname']) ? -1 : 1;
50 // The squads are different so compare their order attributes,
51 // or unassigned squads sort last.
52 if (! $squads[$a['squad']][3]) return 1;
53 if (! $squads[$b['squad']][3]) return -1;
54 return ($squads[$a['squad']][2] < $squads[$b['squad']][2]) ? -1 : 1;
57 $ordres = array();
58 if ($res) {
59 while ($row = sqlFetchArray($res)) $ordres[] = $row;
60 usort($ordres, "patient_compare");
63 <html>
64 <head>
65 <?php html_header_show(); ?>
66 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
68 <style type="text/css">
69 </style>
71 <?php if (empty($_GET['embed'])) { ?>
72 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/topdialog.js"></script>
73 <?php } ?>
74 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
75 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script>
76 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/ajtooltip.js"></script>
77 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/textformat.js"></script>
79 <script language="JavaScript">
80 <?php if (empty($_GET['embed'])) require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
82 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
84 function gopid(pid) {
85 <?php
86 $maintop = $_GET['embed'] ? "top" : "opener.top";
87 echo " $maintop.restoreSession();\n";
88 if ($GLOBALS['concurrent_layout']) {
89 echo " $maintop.RTop.location = '../patient_file/summary/demographics.php?set_pid=' + pid;\n";
90 // echo " $maintop.left_nav.forceDual();\n"; // Decided not to do this.
91 } else {
92 echo " $maintop.location = '../patient_file/patient_file.php?set_pid=' + pid;\n";
94 if (empty($_GET['embed'])) echo " window.close();\n";
98 // Process click to pop up the dialog window.
99 function rosdlgclick(pid, date) {
100 cascwin('players_report_dialog.php?plid=' + pid + '&date=' + date,
101 '_blank', 850, 550, "resizable=1,scrollbars=1");
104 function mov1(elem, plid) {
105 ttMouseOver(elem, "players_report_ajax.php?plid=" + plid);
108 function mov2(elem, plid, date) {
109 ttMouseOver(elem, "players_report_ajax.php?plid=" + plid + "&date=" + date);
112 function refreshme() {
113 // location.reload();
114 document.forms[0].submit();
117 </script>
119 <title><?php xl('Weekly Exposures','e'); ?></title>
120 </head>
122 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
123 <center>
125 <form method='post' action='players_report.php<?php if (!empty($_GET['embed'])) echo "?embed=1"; ?>'>
127 <table border='0' cellpadding='5' cellspacing='0' width='98%'>
129 <tr>
130 <td height="1" colspan="2">
131 </td>
132 </tr>
134 <tr bgcolor='#ddddff'>
135 <td align='left'>
136 <h2><?php xl('Weekly Exposures','e'); ?></h2>
137 </td>
138 <td align='right'>
139 <b><?php echo date('l, F j, Y', $now) ?></b>&nbsp;
140 <input type='text' name='form_date' id='form_date' size='10' value='<?php echo date('Y-m-d', $now) ?>'
141 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
142 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
143 id='img_date' border='0' alt='[?]' style='cursor:pointer'
144 title='<?php xl('Click here to choose a start date','e'); ?>'>
145 &nbsp;
146 <input type='submit' name='form_refresh' value='<?php xl('Refresh','e'); ?>'>
147 </td>
148 </tr>
150 <tr>
151 <td height="1" colspan="2">
152 </td>
153 </tr>
155 </table>
157 <table border='0' cellpadding='1' cellspacing='2' width='98%'>
159 <tr bgcolor="#dddddd">
160 <td class="dehead">
161 &nbsp;<?php xl('Squad','e'); ?>
162 </td>
163 <td class="dehead">
164 &nbsp;<?php xl('Player','e'); ?>
165 </td>
167 <?php
168 $time = $now;
169 for ($day = 0; $day < 8; ++$day) {
170 echo " <td class='dehead' colspan='2' align='center'>";
171 echo date('D', $time);
172 echo "</td>\n";
173 $time += 60 * 60 * 24;
176 </tr>
177 <?php
178 $lastsquad = '';
179 foreach ($ordres as $row) {
180 $squadvalue = $row['squad'];
181 $squadname = $squads[$squadvalue][3];
182 if ($squadname) {
183 if (! acl_check('squads', $squadvalue)) continue;
184 } else {
185 $squadname = "None";
187 $patient_id = $row['pid'];
189 <tr>
190 <td class="detail">
191 &nbsp;<?php echo ($squadname == $lastsquad) ? "" : $squadname ?>
192 </td>
193 <td class="detail">
194 &nbsp;<a href='javascript:gopid(<?php echo $patient_id ?>)' style='color:#000000'><?php echo $row['lname'] . ", " . $row['fname'] ?></a>
195 </td>
196 <?php
197 $time = $now;
198 for ($day = 0; $day < 8; ++$day) {
199 $date = date('Y-m-d', $time);
200 $ymd = date('Ymd', $time);
202 if ($PROPLOGIC) {
203 // For a given date, fitness info is the last on or before that date,
204 // or if there is none then the defaults apply.
205 $dfrow = sqlQuery("SELECT df.*, lf.title AS lf_title, lf.mapping AS lf_mapping " .
206 "FROM daily_fitness AS df " .
207 "LEFT JOIN list_options AS lf ON lf.list_id = 'fitness' AND lf.option_id = df.fitness " .
208 "WHERE df.pid = '$patient_id' AND df.date <= '$date' " .
209 "ORDER BY df.date DESC LIMIT 1");
211 else {
212 $dfrow = sqlQuery("SELECT df.*, lf.title AS lf_title, lf.mapping AS lf_mapping " .
213 "FROM daily_fitness AS df " .
214 "LEFT JOIN list_options AS lf ON lf.list_id = 'fitness' AND lf.option_id = df.fitness " .
215 "WHERE df.pid = '$patient_id' AND df.date = '$date'");
218 if (empty($dfrow)) {
219 $dfrow = array(
220 'fitness' => $fdefault['option_id'],
221 'lf_title' => $fdefault['title'],
222 'lf_mapping' => $fdefault['mapping'],
223 // 'am' => '',
224 // 'pm' => '',
228 $mapping = explode(':', $dfrow['lf_mapping']);
229 $bgcolor = $mapping[0];
231 // Compute percentage of participation.
232 $eventmins = 0;
233 $partmins = 0;
234 $eres = getSquadEvents($date, $squadvalue, $patient_id);
236 while ($erow = sqlFetchArray($eres)) {
237 if (!eventMatchesDay($erow, $date)) continue;
238 $duration = (int) ($erow['pc_duration'] / 60);
239 $eventmins += $duration;
240 if (empty($erow['pid']) || $erow['minutes'] > $duration) {
241 $partmins += $duration;
243 else {
244 $partmins += $erow['minutes'];
248 echo " <td class='detail' " .
249 "bgcolor='$bgcolor' " .
250 "onclick='rosdlgclick($patient_id,$ymd)' " .
251 "onmouseover='mov1(this,$patient_id)' " .
252 "onmouseout='ttMouseOut()' " .
253 ">\n";
254 if ($PROPLOGIC && (empty($dfrow['date']) || $dfrow['date'] != $date))
255 echo '<i>' . $mapping[1] . '</i>';
256 else
257 echo $mapping[1];
258 echo " </td>\n";
259 echo " <td class='detail' align='right' " .
260 "bgcolor='$bgcolor' " .
261 "style='width:40pt;' " .
262 "onclick='rosdlgclick($patient_id,$ymd)' " .
263 "onmouseover='mov2(this,$patient_id,$ymd)' " .
264 "onmouseout='ttMouseOut()' " .
265 "nowrap>\n";
266 if ($partmins < $eventmins) {
267 echo ((int)($partmins * 100 / $eventmins)) . "%\n";
269 echo " </td>\n";
271 $time += 60 * 60 * 24;
274 </tr>
275 <?php
276 $lastsquad = $squadname;
280 </table>
282 </form>
283 </center>
285 <div id='tooltipdiv'
286 style='position:absolute;width:500px;border:1px solid black;padding:2px;background-color:#ffffaa;visibility:hidden;z-index:1000;font-size:9pt;'
287 ></div>
289 <script>
290 <?php
291 if ($alertmsg) {
292 echo " alert('$alertmsg');\n";
295 </script>
296 <!-- stuff for the popup calendar -->
297 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
298 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
299 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
300 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
301 <script language="Javascript">
302 Calendar.setup({inputField:"form_date", ifFormat:"%Y-%m-%d", button:"img_date"});
303 </script>
304 </body>
305 </html>