Merge branch 'master' of git://github.com/openemr/openemr
[openemr.git] / interface / reports / players_report.php
blobec8c7b72c619037f6bfc1eefd06d138daa9e5aa7
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 } else {
85 echo " $maintop.location = '../patient_file/patient_file.php?set_pid=' + pid;\n";
87 if (empty($_GET['embed'])) echo " window.close();\n";
91 // Process click to pop up the dialog window.
92 function rosdlgclick(pid, date) {
93 cascwin('players_report_dialog.php?plid=' + pid + '&date=' + date,
94 '_blank', 850, 550, "resizable=1,scrollbars=1");
97 function mov1(elem, plid) {
98 ttMouseOver(elem, "players_report_ajax.php?plid=" + plid);
101 function mov2(elem, plid, date) {
102 ttMouseOver(elem, "players_report_ajax.php?plid=" + plid + "&date=" + date);
105 function refreshme() {
106 // location.reload();
107 document.forms[0].submit();
110 </script>
112 <title><?php xl('Weekly Exposures','e'); ?></title>
113 </head>
115 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
116 <center>
118 <form method='post' action='players_report.php<?php if (!empty($_GET['embed'])) echo "?embed=1"; ?>'>
120 <table border='0' cellpadding='5' cellspacing='0' width='98%'>
122 <tr>
123 <td height="1" colspan="2">
124 </td>
125 </tr>
127 <tr bgcolor='#ddddff'>
128 <td align='left'>
129 <h2><?php xl('Weekly Exposures','e'); ?></h2>
130 </td>
131 <td align='right'>
132 <b><?php echo date('l, F j, Y', $now) ?></b>&nbsp;
133 <input type='text' name='form_date' id='form_date' size='10' value='<?php echo date('Y-m-d', $now) ?>'
134 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
135 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
136 id='img_date' border='0' alt='[?]' style='cursor:pointer'
137 title='<?php xl('Click here to choose a start date','e'); ?>'>
138 &nbsp;
139 <input type='submit' name='form_refresh' value='<?php xl('Refresh','e'); ?>'>
140 </td>
141 </tr>
143 <tr>
144 <td height="1" colspan="2">
145 </td>
146 </tr>
148 </table>
150 <table border='0' cellpadding='1' cellspacing='2' width='98%'>
152 <tr bgcolor="#dddddd">
153 <td class="dehead">
154 &nbsp;<?php xl('Squad','e'); ?>
155 </td>
156 <td class="dehead">
157 &nbsp;<?php xl('Player','e'); ?>
158 </td>
160 <?php
161 $time = $now;
162 for ($day = 0; $day < 8; ++$day) {
163 echo " <td class='dehead' colspan='2' align='center'>";
164 echo date('D', $time);
165 echo "</td>\n";
166 $time += 60 * 60 * 24;
169 </tr>
170 <?php
171 $lastsquad = '';
172 foreach ($ordres as $row) {
173 $squadvalue = $row['squad'];
174 $squadname = $squads[$squadvalue][3];
175 if ($squadname) {
176 if (! acl_check('squads', $squadvalue)) continue;
177 } else {
178 $squadname = "None";
180 $patient_id = $row['pid'];
182 <tr>
183 <td class="detail">
184 &nbsp;<?php echo ($squadname == $lastsquad) ? "" : $squadname ?>
185 </td>
186 <td class="detail">
187 &nbsp;<a href='javascript:gopid(<?php echo $patient_id ?>)' style='color:#000000'><?php echo $row['lname'] . ", " . $row['fname'] ?></a>
188 </td>
189 <?php
190 $time = $now;
191 for ($day = 0; $day < 8; ++$day) {
192 $date = date('Y-m-d', $time);
193 $ymd = date('Ymd', $time);
195 $dfrow = sqlQuery("SELECT df.*, lf.title AS lf_title, lf.mapping AS lf_mapping " .
196 "FROM daily_fitness AS df " .
197 "LEFT JOIN list_options AS lf ON lf.list_id = 'fitness' AND lf.option_id = df.fitness " .
198 "WHERE df.pid = '$patient_id' AND df.date = '$date'");
200 if (empty($dfrow)) {
201 $dfrow = array(
202 'fitness' => $fdefault['option_id'],
203 'lf_title' => $fdefault['title'],
204 'lf_mapping' => $fdefault['mapping'],
205 // 'am' => '',
206 // 'pm' => '',
210 $mapping = explode(':', $dfrow['lf_mapping']);
211 $bgcolor = $mapping[0];
213 // Compute percentage of participation.
214 $eventmins = 0;
215 $partmins = 0;
216 $eres = getSquadEvents($date, $squadvalue, $patient_id);
218 while ($erow = sqlFetchArray($eres)) {
219 if (!eventMatchesDay($erow, $date)) continue;
220 $duration = (int) ($erow['pc_duration'] / 60);
221 $eventmins += $duration;
222 if (empty($erow['pid']) || $erow['minutes'] > $duration) {
223 $partmins += $duration;
225 else {
226 $partmins += $erow['minutes'];
230 echo " <td class='detail' " .
231 "bgcolor='$bgcolor' " .
232 "onclick='rosdlgclick($patient_id,$ymd)' " .
233 "onmouseover='mov1(this,$patient_id)' " .
234 "onmouseout='ttMouseOut()' " .
235 ">\n";
236 echo $mapping[1];
237 echo " </td>\n";
238 echo " <td class='detail' align='right' " .
239 "bgcolor='$bgcolor' " .
240 "style='width:40pt;' " .
241 "onclick='rosdlgclick($patient_id,$ymd)' " .
242 "onmouseover='mov2(this,$patient_id,$ymd)' " .
243 "onmouseout='ttMouseOut()' " .
244 "nowrap>\n";
245 if ($partmins < $eventmins) {
246 echo ((int)($partmins * 100 / $eventmins)) . "%\n";
248 echo " </td>\n";
250 $time += 60 * 60 * 24;
253 </tr>
254 <?php
255 $lastsquad = $squadname;
259 </table>
261 </form>
262 </center>
264 <div id='tooltipdiv'
265 style='position:absolute;width:500px;border:1px solid black;padding:2px;background-color:#ffffaa;visibility:hidden;z-index:1000;font-size:9pt;'
266 ></div>
268 <script>
269 <?php
270 if ($alertmsg) {
271 echo " alert('$alertmsg');\n";
274 </script>
275 <!-- stuff for the popup calendar -->
276 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
277 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
278 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
279 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
280 <script language="Javascript">
281 Calendar.setup({inputField:"form_date", ifFormat:"%Y-%m-%d", button:"img_date"});
282 </script>
283 </body>
284 </html>