2 // Copyright (C) 2005-2011 Rod Roark <rod@sunsetsystems.com>
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 //SANITIZE ALL ESCAPES
13 $sanitize_all_escapes=true;
16 //STOP FAKE REGISTER GLOBALS
17 $fake_register_globals=false;
20 require_once("../globals.php");
21 require_once("$srcdir/patient.inc");
22 require_once("$srcdir/acl.inc");
23 require_once("$srcdir/lists.inc");
24 require_once("$srcdir/calendar_events.inc.php");
26 // Temporary variable while new "propagation" logic is being tested.
27 // True means that missing days in the daily_fitness table default to
28 // the previous entry's values, if there is one.
29 // Otherwise the default fitness level (Fully Fit) is used (old logic).
32 $squads = acl_get_squads();
33 $auth_notes_a = acl_check('encounters', 'notes_a');
35 $alertmsg = ''; // not used yet but maybe later
37 $form_date = fixDate($_POST['form_date'], date('Y-m-d'));
39 // Figure out the desired or default squad to select.
40 if (!empty($_POST['form_squad'])) {
41 $form_squad = $_POST['form_squad'];
42 $_SESSION['roster_squad'] = $form_squad;
44 else if (!empty($_SESSION['roster_squad'])) {
45 $form_squad = $_SESSION['roster_squad'];
48 $form_squad = array_shift(array_keys($squads));
52 $now = mktime(0, 0, 0, substr($form_date, 5, 2),
53 substr($form_date, 8, 2), substr($form_date, 0, 4));
55 // Get attributes of the default fitless level.
56 $fdefault = sqlQuery("SELECT * FROM list_options WHERE " .
57 "list_id = 'fitness' ORDER BY is_default DESC, seq ASC LIMIT 1");
59 $query = "SELECT pid, squad, fitness, lname, fname FROM patient_data";
60 if (!empty($form_squad)) {
61 $query .= " WHERE squad LIKE '$form_squad'";
63 $res = sqlStatement($query);
65 // Sort the patients in squad priority order.
66 function patient_compare($a, $b) {
68 if ($squads[$a['squad']][3] == $squads[$b['squad']][3]) {
69 if ($a['lname'] == $b['lname']) {
70 return ($a['fname'] < $b['fname']) ?
-1 : 1;
72 return ($a['lname'] < $b['lname']) ?
-1 : 1;
74 // The squads are different so compare their order attributes,
75 // or unassigned squads sort last.
76 if (! $squads[$a['squad']][3]) return 1;
77 if (! $squads[$b['squad']][3]) return -1;
78 return ($squads[$a['squad']][2] < $squads[$b['squad']][2]) ?
-1 : 1;
83 while ($row = sqlFetchArray($res)) $ordres[] = $row;
84 usort($ordres, "patient_compare");
89 <?php
html_header_show(); ?
>
90 <link rel
=stylesheet href
="<?php echo $css_header;?>" type
="text/css">
92 <style type
="text/css">
95 <?php
if (empty($_GET['embed'])) { ?
>
96 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/topdialog.js"></script
>
98 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script
>
99 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script
>
100 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/ajtooltip.js"></script
>
101 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/textformat.js"></script
>
103 <script language
="JavaScript">
104 <?php
if (empty($_GET['embed'])) require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
106 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
108 function gopid(pid
) {
110 $maintop = $_GET['embed'] ?
"top" : "opener.top";
111 echo " $maintop.restoreSession();\n";
112 if ($GLOBALS['concurrent_layout']) {
113 echo " $maintop.RTop.location = '../patient_file/summary/demographics.php?set_pid=' + pid;\n";
114 // echo " $maintop.left_nav.forceDual();\n"; // Decided not to do this.
116 echo " $maintop.location = '../patient_file/patient_file.php?set_pid=' + pid;\n";
118 if (empty($_GET['embed'])) echo " window.close();\n";
122 // Process click to pop up the dialog window.
123 function rosdlgclick(pid
, date
) {
124 cascwin('players_report_dialog.php?plid=' + pid +
'&date=' + date
,
125 '_blank', 850, 550, "resizable=1,scrollbars=1");
128 function mov1(elem
, plid
) {
129 ttMouseOver(elem
, "players_report_ajax.php?plid=" + plid
);
132 function mov2(elem
, plid
, date
) {
133 ttMouseOver(elem
, "players_report_ajax.php?plid=" + plid +
"&date=" + date
);
136 function refreshme() {
137 top
.restoreSession();
138 // location.reload();
139 document
.forms
[0].submit();
142 // Process click on issue title or [Add Issue].
143 function openissue(pid
, issue
) {
144 dlgopen('../patient_file/summary/add_edit_issue.php?thispid=' + pid +
'&issue=' + issue
, '_blank', 800, 600);
148 // callback from add_edit_issue.php:
149 function refreshIssue(issue
, title
) {
153 // Process click on Treatment Protocols form title.
154 function opentpform(id
) {
155 dlgopen('../forms/treatment_protocols/new.php?popup=1&id=' + id
, '_blank', 800, 600);
159 // This is called from left_nav_encounter_ajax.php to create the new TP form.
160 function createtpform(encounter
) {
161 dlgopen('../forms/treatment_protocols/new.php?popup=1&id=0&thisenc=' + encounter
, '_blank', 800, 600);
165 // Process click on [Add Rehab Form] to add a new encounter and TP form.
166 function newtpform(issue
) {
167 top
.restoreSession();
168 $
.getScript('../../library/ajax/left_nav_encounter_ajax.php?issue=' + issue +
'&followup=createtpform');
172 // Process click on issue title to add a new encounter and switch to it and its patient.
173 function newvisit(issue
) {
174 top
.restoreSession();
175 $
.getScript('../../library/ajax/left_nav_encounter_ajax.php?issue=' + issue
);
181 <title
><?php
xl('Weekly Exposures','e'); ?
></title
>
184 <body leftmargin
='0' topmargin
='0' marginwidth
='0' marginheight
='0'>
187 <form method
='post' action
='players_report.php<?php if (!empty($_GET['embed
'])) echo "?embed=1"; ?>'>
189 <table border
='0' cellpadding
='5' cellspacing
='0' width
='98%'>
192 <td height
="1" colspan
="2">
196 <tr bgcolor
='#ddddff'>
198 <h2
><?php
xl('Weekly Exposures','e'); ?
></h2
>
201 <b
><?php
echo date('l, F j, Y', $now) ?
></b
> 
;
202 <input type
='text' name
='form_date' id
='form_date' size
='10' value
='<?php echo date('Y
-m
-d
', $now) ?>'
203 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
204 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
205 id
='img_date' border
='0' alt
='[?]' style
='cursor:pointer'
206 title
='<?php xl('Click here to choose a start date
','e
'); ?>'>
211 <select name
='form_squad' title
='<?php xl('Select desired squad
','e
'); ?>'>
214 foreach ($squads as $key => $value) {
215 echo " <option value='$key'";
216 if (!empty($form_squad) && $form_squad == $key) echo " selected";
217 echo ">" . $value[3] . "</option>\n";
226 <input type
='submit' name
='form_refresh' value
='<?php xl('Refresh
','e
'); ?>'>
231 <td height
="1" colspan
="2">
237 <table border
='0' cellpadding
='1' cellspacing
='2' width
='98%'>
239 <tr bgcolor
="#dddddd">
242  
;<?php
xl('Squad','e'); ?
>
246  
;<?php
xl('Player','e'); ?
>
251 for ($day = 0; $day < 8; ++
$day) {
252 echo " <td class='dehead' colspan='2' align='center'>";
253 echo date('D', $time);
255 $time +
= 60 * 60 * 24;
261 foreach ($ordres as $row) {
262 $squadvalue = $row['squad'];
263 $squadname = $squads[$squadvalue][3];
265 if (! acl_check('squads', $squadvalue)) continue;
269 $patient_id = $row['pid'];
274  
;<?php
echo ($squadname == $lastsquad) ?
"" : $squadname ?
>
278  
;<a href
='javascript:gopid(<?php echo $patient_id ?>)' style
='color:#000000'><?php
echo $row['lname'] . ", " . $row['fname'] ?
></a
>
282 for ($day = 0; $day < 8; ++
$day) {
283 $date = date('Y-m-d', $time);
284 $ymd = date('Ymd', $time);
287 // For a given date, fitness info is the last on or before that date,
288 // or if there is none then the defaults apply.
289 $dfrow = sqlQuery("SELECT df.*, lf.title AS lf_title, lf.mapping AS lf_mapping " .
290 "FROM daily_fitness AS df " .
291 "LEFT JOIN list_options AS lf ON lf.list_id = 'fitness' AND lf.option_id = df.fitness " .
292 "WHERE df.pid = '$patient_id' AND df.date <= '$date' " .
293 "ORDER BY df.date DESC LIMIT 1");
297 $dfrow = sqlQuery("SELECT df.*, lf.title AS lf_title, lf.mapping AS lf_mapping " .
298 "FROM daily_fitness AS df " .
299 "LEFT JOIN list_options AS lf ON lf.list_id = 'fitness' AND lf.option_id = df.fitness " .
300 "WHERE df.pid = '$patient_id' AND df.date = '$date'");
305 'fitness' => $fdefault['option_id'],
306 'lf_title' => $fdefault['title'],
307 'lf_mapping' => $fdefault['mapping'],
313 $mapping = explode(':', $dfrow['lf_mapping']);
314 $bgcolor = $mapping[0];
316 // Compute percentage of participation.
319 $eres = getSquadEvents($date, $squadvalue, $patient_id);
321 while ($erow = sqlFetchArray($eres)) {
322 if (!eventMatchesDay($erow, $date)) continue;
323 $duration = (int) ($erow['pc_duration'] / 60);
324 $eventmins +
= $duration;
325 if (empty($erow['pid']) ||
$erow['minutes'] > $duration) {
326 $partmins +
= $duration;
329 $partmins +
= $erow['minutes'];
333 echo " <td class='detail' " .
334 "bgcolor='$bgcolor' " .
335 // "onclick='rosdlgclick($patient_id,$ymd)' " .
336 // "onmouseover='mov1(this,$patient_id)' " .
337 // "onmouseout='ttMouseOut()' " .
341 if ($PROPLOGIC && (empty($dfrow['date']) ||
$dfrow['date'] != $date))
342 echo '<i>' . $mapping[1] . '</i>';
344 echo $mapping[1]; // this is obsolete
345 // Append % fitness to this line.
346 if ($partmins < $eventmins) {
347 echo sprintf(" %d", $partmins * 100 / $eventmins) . '%';
350 // Write a line for each active issue, and below it enumerate the forms.
351 // Each form can be clicked to pop it up for editing, or the issue can be
352 // clicked to add a form.
353 // At end of forms for each issue, a line to add a new form.
354 // At end of issues, a line to add a new issue.
356 $ires = sqlStatement("SELECT id, type, title, begdate " .
357 "FROM lists WHERE pid = ? AND activity = 1 AND " .
358 "( type = 'football_injury' OR type = 'medical_problem' ) AND " .
359 "begdate <= ? AND ( enddate IS NULL OR enddate >= ? ) " .
360 "ORDER BY begdate, id", array($patient_id, $date, $date));
361 while ($irow = sqlFetchArray($ires)) {
362 $issue_id = 0 +
$irow['id'];
363 $tcode = $irow['type'];
364 if ($ISSUE_TYPES[$tcode]) $tcode = $ISSUE_TYPES[$tcode][2];
366 // echo "<a href='javascript:;' class='link' onclick='return openissue($patient_id,$issue_id)'>";
367 echo "<a href='javascript:;' class='link' onclick='return newvisit($issue_id)'>";
368 echo "<b>$tcode</b>: " . htmlspecialchars($irow['title'], ENT_NOQUOTES
);
370 $fres = sqlStatement("SELECT f.date, f.encounter, f.form_id, tp.value FROM " .
371 "issue_encounter AS ie, forms AS f , form_treatment_protocols AS tp WHERE " .
372 "ie.pid = ? AND ie.list_id = ? AND " .
373 "f.pid = ie.pid AND f.encounter = ie.encounter AND " .
374 "f.formdir = 'treatment_protocols' AND f.deleted = 0 AND " .
375 "tp.id = f.form_id AND tp.rownbr = -1 AND tp.colnbr = -1 AND " .
376 "SUBSTR(tp.value,3,10) <= ? " . // TBD: implement form end date also
377 "ORDER BY f.encounter DESC, f.id DESC",
378 array($patient_id, $irow['id'], $date));
380 while ($frow = sqlFetchArray($fres)) {
381 $form_id = 0 +
$frow['form_id'];
382 list($form_completed, $start_date, $template_name) = explode('|', $frow['value'], 3);
384 echo "<a href='javascript:;' class='link' onclick='return opentpform($form_id)'>";
387 echo htmlspecialchars($template_name, ENT_NOQUOTES
);
390 // If there were no rehab forms, insert a link for adding one. In this case the link will
391 // create a new encounter but will not switch to it.
393 echo "<br /><a href='javascript:;' class='link' onclick='return newtpform($issue_id)'>";
395 echo htmlspecialchars('[' . xl('Add') . ']', ENT_NOQUOTES
);
399 // echo "<br /><a href='javascript:;' class='link' onclick='return openissue($patient_id,0)'>";
400 // echo htmlspecialchars('[' . xl('Add Issue') . ']', ENT_NOQUOTES);
405 // "class='detail' " .
406 // "class='small' " .
407 // "align='right' " .
408 "bgcolor='$bgcolor' " .
409 // "style='width:20pt;font-size:70%;' " .
410 "style='font-size:70%;' " .
411 "onclick='rosdlgclick($patient_id,$ymd)' " .
412 "onmouseover='mov2(this,$patient_id,$ymd)' " .
413 "onmouseout='ttMouseOut()' " .
417 // echo "<a href='javascript:;' class='link' onclick='return openissue($patient_id,0)'>";
418 // echo htmlspecialchars('[' . xl('New')) . ' ' . htmlspecialchars(xl('Inj/Rehab') . ']', ENT_NOQUOTES);
420 // echo "<a href='javascript:;' class='link' " .
421 // "onclick='return rosdlgclick($patient_id,$ymd)'>";
422 if (!empty($dfrow['am'])) {
424 echo '<b>' . htmlspecialchars(xl('AM'), ENT_NOQUOTES
) . '</b>: ';
425 echo htmlspecialchars($dfrow['am'], ENT_NOQUOTES
);
427 if (!empty($dfrow['pm'])) {
428 if (!empty($dfrow['am'])) echo "<br />";
429 echo '<b>' . htmlspecialchars(xl('PM'), ENT_NOQUOTES
) . '</b>: ';
430 echo htmlspecialchars($dfrow['pm'], ENT_NOQUOTES
);
432 if (empty($dfrow['am']) && empty($dfrow['pm'])) {
434 echo htmlspecialchars('[' . xl('New Inj/Status') . ']', ENT_NOQUOTES
);
439 $time +
= 60 * 60 * 24;
444 $lastsquad = $squadname;
454 style
='position:absolute;width:500px;border:1px solid black;padding:2px;background-color:#ffffaa;visibility:hidden;z-index:1000;font-size:9pt;'
460 echo " alert('$alertmsg');\n";
464 <!-- stuff
for the popup calendar
-->
465 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
466 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
467 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
468 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
469 <script language
="Javascript">
470 Calendar
.setup({inputField
:"form_date", ifFormat
:"%Y-%m-%d", button
:"img_date"});