PHPSECLIB 0.3.1 added to the project to support SFTP transfers of lab orders and...
[openemr.git] / interface / reports / players_report_dialog.php
blob6ea8b8665028bab7fa93db7dbcd3c6c6251cf741
1 <?php
2 // Copyright (C) 2009-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 //////////////////////////////////////////////////////////////////////
10 // This dialog works with a specified player on a specified date,
11 // and is used to:
13 // o change fitness level
14 // o change per-event minutes of participation and absence reason
15 // o add/modify the associated pt note
16 // o link an issue to the player's fitness for that day
17 //////////////////////////////////////////////////////////////////////
19 require_once("../globals.php");
20 require_once("$srcdir/acl.inc");
21 require_once("$srcdir/lists.inc");
22 require_once("$srcdir/pnotes.inc");
23 require_once("$srcdir/formdata.inc.php");
24 require_once("$srcdir/calendar_events.inc.php");
26 // Temporary variable while new 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.
30 $PROPLOGIC = true;
32 $plid = $_REQUEST['plid'] + 0; // pid
33 $ymd = $_REQUEST['date'];
34 if (empty($ymd)) die("Internal error: date parameter is missing");
35 $date = substr($ymd,0,4) . '-' . substr($ymd,4,2) . '-' . substr($ymd,6,2);
37 $form_fitness = formData('form_fitness');
38 $form_issue = formData('form_issue') + 0;
39 $form_to = formData('form_to');
41 $form_note = empty($_POST['form_note']) ? '' : $_POST['form_note'];
42 if (get_magic_quotes_gpc()) $form_note = stripslashes($form_note);
44 $form_am = empty($_POST['form_am']) ? '' : $_POST['form_am'];
45 if (get_magic_quotes_gpc()) $form_am = stripslashes($form_am);
47 $form_pm = empty($_POST['form_pm']) ? '' : $_POST['form_pm'];
48 if (get_magic_quotes_gpc()) $form_pm = stripslashes($form_pm);
50 function gen_list_options($list_id, $default='') {
51 $res = sqlStatement("SELECT * FROM list_options WHERE " .
52 "list_id = '$list_id' ORDER BY seq");
53 while ($row = sqlFetchArray($res)) {
54 $key = $row['option_id'];
55 echo " <option value='$key'";
56 if ($key == $default) echo " selected";
57 echo ">" . $row['title'] . "</option>\n";
61 $alertmsg = ''; // anything here pops up in an alert box
63 // Get player info.
64 $patrow = sqlQuery("SELECT " .
65 "fname, mname, lname, pubpid, squad " .
66 "FROM patient_data " .
67 "WHERE pid = '$plid' LIMIT 1");
68 $squad = $patrow['squad'];
70 if ($PROPLOGIC) {
71 // For a given date, fitness info is the last on or before that date,
72 // or if there is none then the defaults apply.
73 $dfrow = sqlQuery("SELECT " .
74 "df.*, lf.option_id AS lf_id, lf.title AS lf_title " .
75 "FROM daily_fitness AS df " .
76 "LEFT JOIN list_options AS lf ON lf.list_id = 'fitness' AND lf.option_id = df.fitness " .
77 "WHERE df.pid = '$plid' AND df.date <= '$date' " .
78 "ORDER BY df.date DESC LIMIT 1");
80 else {
81 $dfrow = sqlQuery("SELECT " .
82 "df.*, lf.option_id AS lf_id, lf.title AS lf_title " .
83 "FROM daily_fitness AS df " .
84 "LEFT JOIN list_options AS lf ON lf.list_id = 'fitness' AND lf.option_id = df.fitness " .
85 "WHERE df.pid = '$plid' AND df.date = '$date'");
88 if (empty($dfrow)) {
89 $dfrow = array(
90 'pid' => '0',
91 'date' => '',
92 'fitness' => '1',
93 'lf_title' => 'FF',
94 'issue_id' => '0',
98 // This gets the events for the player's squad for this date,
99 // and the player-specific data (if any) for each such event.
100 $eres = getSquadEvents($date, $squad, $plid);
102 // Get the roster note, if any, for this player and date.
103 $nrow = sqlQuery("SELECT id, body, assigned_to FROM pnotes WHERE " .
104 "pid = '$plid' AND LEFT(date,10) = '$date' AND title LIKE 'Roster' AND " .
105 "deleted = 0 ORDER BY date LIMIT 1");
106 $noteid = empty($nrow) ? '0' : $nrow['id'];
108 // If the Save button was clicked...
109 if ($_POST['form_save']) {
111 // Update daily_fitness.
112 if ($dfrow['date'] == $date) {
113 sqlStatement("UPDATE daily_fitness SET " .
114 "fitness = '$form_fitness', " .
115 "am = '$form_am', " .
116 "pm = '$form_pm', " .
117 "issue_id = '$form_issue'" .
118 "WHERE pid = '$plid' AND date = '$date'");
120 else {
121 sqlStatement("INSERT INTO daily_fitness SET " .
122 "pid = '$plid', " .
123 "date = '$date', " .
124 "fitness = '$form_fitness', " .
125 "am = '$form_am', " .
126 "pm = '$form_pm', " .
127 "issue_id = '$form_issue'");
130 // Update player_events.
131 while ($erow = sqlFetchArray($eres)) {
132 if (!eventMatchesDay($erow, $date)) continue;
133 $eid = 0 + $erow['pc_eid'];
134 $duration = (int) ($erow['pc_duration'] / 60);
135 $form_mins = formData("form_mins_$eid") + 0;
136 $form_fitrel = empty($_POST["form_fitrel_$eid"]) ? 0 : 1;
137 sqlStatement("DELETE FROM player_event WHERE pid = '$plid' AND " .
138 "date = '$date' AND pc_eid = '$eid'");
139 if ($form_mins < $duration) {
140 sqlStatement("INSERT INTO player_event SET " .
141 "pid = '$plid', " .
142 "date = '$date', " .
143 "pc_eid = '$eid', " .
144 "minutes = '$form_mins', " .
145 "fitness_related = '$form_fitrel'");
149 // Add or append to the roster note.
150 if ($form_note !== '') {
151 if ($noteid) {
152 updatePnote($noteid, $form_note, 'Roster', $form_to);
154 else {
155 addPnote($plid, $form_note, $userauthorized, '1', 'Roster', $form_to,
156 "$date 00:00:00");
160 // Close this window and refresh the roster display.
161 echo "<html>\n<body>\n<script language='JavaScript'>\n";
162 if ($alertmsg) echo " alert('$alertmsg');\n";
163 echo " if (!opener.closed && opener.refreshme) opener.refreshme();\n";
164 echo " window.close();\n";
165 echo "</script>\n</body>\n</html>\n";
166 exit();
169 <html>
170 <head>
171 <?php html_header_show(); ?>
172 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
174 <title><?php echo htmlspecialchars(xl('Record of Fitness')); ?></title>
176 <style type="text/css">
177 body { font-family:sans-serif; font-size:10pt; font-weight:normal }
178 .dehead { color:#000000; font-family:sans-serif; font-size:10pt; font-weight:bold }
179 .detail { color:#000000; font-family:sans-serif; font-size:10pt; font-weight:normal }
180 </style>
182 <script type="text/javascript" src="../../library/topdialog.js"></script>
183 <script type="text/javascript" src="../../library/dialog.js"></script>
185 <script language="JavaScript">
186 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
188 // Process click on issue title.
189 function newissue() {
190 dlgopen('../patient_file/summary/add_edit_issue.php?thispid=<?php echo $plid; ?>', '_blank', 800, 600);
191 return false;
194 // callback from add_edit_issue.php:
195 function refreshIssue(issue, title) {
196 var s = document.forms[0].form_issue;
197 s.options[s.options.length] = new Option(title, issue, true, true);
200 </script>
202 </head>
204 <body class="body_top" onunload='imclosing()'>
206 <form method='post' action='players_report_dialog.php?<?php echo "plid=$plid" . "&date=$ymd"; ?>'
207 onsubmit='return top.restoreSession()'>
208 <input type='hidden' name='form_pid' value='<?php echo $pid ?>' />
210 <center>
212 <table border='0' cellspacing='8'>
213 <tr>
214 <td>
215 <b><?php xl('Fitness Level','e'); ?></b>
216 </td>
217 <td>
218 <select name='form_fitness'
219 title='<?php xl('Fitness level for this player on this day','e'); ?>'>
220 <?php gen_list_options('fitness', $dfrow['fitness']); ?>
221 </select>
222 </td>
223 </tr>
225 <tr>
226 <td>
227 <b><?php xl('Related Issue','e'); ?></b>
228 </td>
229 <td>
230 <select name='form_issue'
231 title='<?php xl('Select the issue primarily responsible for any missed events on this day','e'); ?>'>
232 <option value='0'>Unassigned</option>
233 <?php
234 $ires = sqlStatement("SELECT id, type, title, begdate FROM lists WHERE " .
235 "pid = $plid AND enddate IS NULL " .
236 "ORDER BY type, begdate");
237 while ($irow = sqlFetchArray($ires)) {
238 $list_id = $irow['id'];
239 $tcode = $irow['type'];
240 if ($ISSUE_TYPES[$tcode]) $tcode = $ISSUE_TYPES[$tcode][2];
241 echo " <option value='$list_id'";
242 if ($list_id == $dfrow['issue_id']) echo " selected";
243 echo ">$tcode: " . $irow['begdate'] . " " .
244 htmlspecialchars(substr($irow['title'], 0, 40)) . "</option>\n";
247 </select>
248 &nbsp;
249 <input type='button' value='<?php echo htmlspecialchars(xl('Add Issue')); ?>'
250 onclick='newissue()' /> &nbsp;
251 </td>
252 </tr>
254 <?php
255 while ($erow = sqlFetchArray($eres)) {
257 echo "<!--\n";
258 print_r($erow); // debugging
259 echo "-->\n";
261 if (!eventMatchesDay($erow, $date)) continue;
263 echo "<!-- The above matches -->\n"; // debugging
265 $eid = 0 + $erow['pc_eid'];
266 if (empty($erow['pid'])) {
267 // No player_event data so set defaults.
268 $minutes = (int) ($erow['pc_duration'] / 60);
269 $fitness_related = ($dfrow['fitness'] == 1) ? 0 : 1;
271 else {
272 $minutes = 0 + $erow['minutes'];
273 $fitness_related = empty($erow['fitness_related']) ? 0 : 1;
275 echo " <tr>\n";
276 echo " <td><b>" . substr($erow['pc_startTime'], 0, 5) . " " .
277 $erow['pc_hometext'] . "</b></td>\n";
278 echo " <td>" . xl('Minutes') . ": " .
279 "<input type='text' name='form_mins_$eid' size='3' value='$minutes' />" .
280 "&nbsp;<input type='checkbox' name='form_fitrel_$eid'";
281 if ($fitness_related) echo " checked";
282 echo " />" . xl('Injury/illness-related') . "</td>\n";
283 echo " </tr>\n";
287 <tr>
288 <td>
289 <b><?php xl('Note','e'); ?></b>
290 </td>
291 <td>
292 <?php
293 // Get the set of local users.
294 $ures = sqlStatement("SELECT username, fname, lname FROM users " .
295 "WHERE username != '' AND active = 1 AND " .
296 "( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
297 "ORDER BY lname, fname");
298 // Show existing note, if any, and then a textarea for adding more.
299 if ($noteid) {
300 echo " <div class='text' " .
301 "style='background-color:white;color:gray;border:1px solid #999;padding: 5px;'>" .
302 nl2br(htmlentities($nrow['body'])) . "</div>\n";
305 <textarea name='form_note' id='note' rows='4' cols='80'></textarea>
306 <br />
307 <b><?php xl('To','e'); ?>:</b>
308 <select name='form_to'>
309 <option value=''>** <?php xl('Close','e'); ?> **</option>
310 <?php
311 // The "To" list of users.
312 while ($urow = sqlFetchArray($ures)) {
313 echo " <option value='" . $urow['username'] . "'";
314 if ($urow['username'] == $nrow['assigned_to']) echo " selected";
315 echo ">" . $urow['lname'];
316 if ($urow['fname']) echo ", " . $urow['fname'];
317 echo "</option>\n";
320 </select>
321 </td>
322 </tr>
324 <tr>
325 <td>
326 <b><?php xl('AM Program','e'); ?></b>
327 </td>
328 <td>
329 <textarea name='form_am' rows='3' cols='80'><?php echo $dfrow['am']; ?></textarea>
330 </td>
331 </tr>
333 <tr>
334 <td>
335 <b><?php xl('PM Program','e'); ?></b>
336 </td>
337 <td>
338 <textarea name='form_pm' rows='3' cols='80'><?php echo $dfrow['pm']; ?></textarea>
339 </td>
340 </tr>
342 </table>
345 <input type='submit' name='form_save' value='<?php xl('Save','e'); ?>' /> &nbsp;
346 <input type='button' value='<?php xl('Cancel','e'); ?>' onclick='window.close()' />
348 </center>
349 </form>
350 </body>
351 </html>