Merge branch 'master' of git://github.com/openemr/openemr
[openemr.git] / interface / reports / players_report_dialog.php
blob6eda04b03e85122431a250f4c349f1fea090c3c8
1 <?php
2 // Copyright (C) 2009 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 $plid = $_REQUEST['plid'] + 0; // pid
27 $ymd = $_REQUEST['date'];
28 if (empty($ymd)) die("Internal error: date parameter is missing");
29 $date = substr($ymd,0,4) . '-' . substr($ymd,4,2) . '-' . substr($ymd,6,2);
31 $form_fitness = formData('form_fitness');
32 $form_issue = formData('form_issue') + 0;
33 $form_to = formData('form_to');
35 $form_note = empty($_POST['form_note']) ? '' : $_POST['form_note'];
36 if (get_magic_quotes_gpc()) $form_note = stripslashes($form_note);
38 function gen_list_options($list_id, $default='') {
39 $res = sqlStatement("SELECT * FROM list_options WHERE " .
40 "list_id = '$list_id' ORDER BY seq");
41 while ($row = sqlFetchArray($res)) {
42 $key = $row['option_id'];
43 echo " <option value='$key'";
44 if ($key == $default) echo " selected";
45 echo ">" . $row['title'] . "</option>\n";
49 $alertmsg = ''; // anything here pops up in an alert box
51 // Get player info.
52 $patrow = sqlQuery("SELECT " .
53 "fname, mname, lname, pubpid, squad " .
54 "FROM patient_data " .
55 "WHERE pid = '$plid' LIMIT 1");
56 $squad = $patrow['squad'];
58 // Get the daily_fitness row.
59 $dfrow = sqlQuery("SELECT " .
60 "df.*, lf.option_id AS lf_id, lf.title AS lf_title " .
61 "FROM daily_fitness AS df " .
62 "LEFT JOIN list_options AS lf ON lf.list_id = 'fitness' AND lf.option_id = df.fitness " .
63 "WHERE df.pid = '$plid' AND df.date = '$date'");
64 if (empty($dfrow)) {
65 $dfrow = array(
66 'pid' => '0',
67 'date' => '',
68 'fitness' => '1',
69 'lf_title' => 'FF',
70 'issue_id' => '0',
74 // This gets the events for the player's squad for this date,
75 // and the player-specific data (if any) for each such event.
76 $eres = getSquadEvents($date, $squad, $plid);
78 // Get the roster note, if any, for this player and date.
79 $nrow = sqlQuery("SELECT id, body, assigned_to FROM pnotes WHERE " .
80 "pid = '$plid' AND LEFT(date,10) = '$date' AND title LIKE 'Roster' AND " .
81 "deleted = 0 ORDER BY date LIMIT 1");
82 $noteid = empty($nrow) ? '0' : $nrow['id'];
84 // If the Save button was clicked...
85 if ($_POST['form_save']) {
87 // Update daily_fitness.
88 if ($dfrow['pid']) {
89 sqlStatement("UPDATE daily_fitness SET " .
90 "fitness = '$form_fitness', " .
91 // "am = '$form_am', " .
92 // "pm = '$form_pm', " .
93 "issue_id = '$form_issue'" .
94 "WHERE pid = '$plid' AND date = '$date'");
96 else {
97 sqlStatement("INSERT INTO daily_fitness SET " .
98 "pid = '$plid', " .
99 "date = '$date 00:00:00', " .
100 "fitness = '$form_fitness', " .
101 // "am = '$form_am', " .
102 // "pm = '$form_pm', " .
103 "issue_id = '$form_issue'");
106 // Update player_events.
107 while ($erow = sqlFetchArray($eres)) {
108 if (!eventMatchesDay($erow, $date)) continue;
109 $eid = 0 + $erow['pc_eid'];
110 $duration = (int) ($erow['pc_duration'] / 60);
111 $form_mins = formData("form_mins_$eid") + 0;
112 $form_fitrel = empty($_POST["form_fitrel_$eid"]) ? 0 : 1;
113 sqlStatement("DELETE FROM player_event WHERE pid = '$plid' AND " .
114 "date = '$date' AND pc_eid = '$eid'");
115 if ($form_mins < $duration) {
116 sqlStatement("INSERT INTO player_event SET " .
117 "pid = '$plid', " .
118 "date = '$date', " .
119 "pc_eid = '$eid', " .
120 "minutes = '$form_mins', " .
121 "fitness_related = '$form_fitrel'");
125 // Add or append to the roster note.
126 if ($form_note !== '') {
127 if ($noteid) {
128 updatePnote($noteid, $form_note, 'Roster', $form_to);
130 else {
131 addPnote($plid, $form_note, $userauthorized, '1', 'Roster', $form_to,
132 "$date 00:00:00");
136 // Close this window and refresh the roster display.
137 echo "<html>\n<body>\n<script language='JavaScript'>\n";
138 if ($alertmsg) echo " alert('$alertmsg');\n";
139 echo " if (!opener.closed && opener.refreshme) opener.refreshme();\n";
140 echo " window.close();\n";
141 echo "</script>\n</body>\n</html>\n";
142 exit();
145 <html>
146 <head>
147 <?php html_header_show(); ?>
148 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
150 <title><?php xl('Record Payment','e'); ?></title>
152 <style type="text/css">
153 body { font-family:sans-serif; font-size:10pt; font-weight:normal }
154 .dehead { color:#000000; font-family:sans-serif; font-size:10pt; font-weight:bold }
155 .detail { color:#000000; font-family:sans-serif; font-size:10pt; font-weight:normal }
156 </style>
158 <script type="text/javascript" src="../../library/topdialog.js"></script>
159 <script type="text/javascript" src="../../library/dialog.js"></script>
161 <script language="JavaScript">
162 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
163 </script>
165 </head>
167 <body class="body_top" onunload='imclosing()'>
169 <form method='post' action='players_report_dialog.php?<?php echo "plid=$plid" . "&date=$ymd"; ?>'
170 onsubmit='return top.restoreSession()'>
171 <input type='hidden' name='form_pid' value='<?php echo $pid ?>' />
173 <center>
175 <table border='0' cellspacing='8'>
176 <tr>
177 <td>
178 <b><?php xl('Fitness Level','e'); ?></b>
179 </td>
180 <td>
181 <select name='form_fitness'
182 title='<?php xl('Fitness level for this player on this day','e'); ?>'>
183 <?php gen_list_options('fitness', $dfrow['fitness']); ?>
184 </select>
185 </td>
186 </tr>
188 <tr>
189 <td>
190 <b><?php xl('Related Issue','e'); ?></b>
191 </td>
192 <td>
193 <select name='form_issue'
194 title='<?php xl('Select the issue primarily responsible for any missed events on this day','e'); ?>'>
195 <option value='0'>Unassigned</option>
196 <?php
197 $ires = sqlStatement("SELECT id, type, title, begdate FROM lists WHERE " .
198 "pid = $plid AND enddate IS NULL " .
199 "ORDER BY type, begdate");
200 while ($irow = sqlFetchArray($ires)) {
201 $list_id = $irow['id'];
202 $tcode = $irow['type'];
203 if ($ISSUE_TYPES[$tcode]) $tcode = $ISSUE_TYPES[$tcode][2];
204 echo " <option value='$list_id'";
205 if ($list_id == $dfrow['issue_id']) echo " selected";
206 echo ">$tcode: " . $irow['begdate'] . " " .
207 htmlspecialchars(substr($irow['title'], 0, 40)) . "</option>\n";
210 </select>
211 </td>
212 </tr>
214 <?php
215 while ($erow = sqlFetchArray($eres)) {
217 echo "<!--\n";
218 print_r($erow); // debugging
219 echo "-->\n";
221 if (!eventMatchesDay($erow, $date)) continue;
223 echo "<!-- The above matches -->\n"; // debugging
225 $eid = 0 + $erow['pc_eid'];
226 if (empty($erow['pid'])) {
227 // No player_event data so set defaults.
228 $minutes = (int) ($erow['pc_duration'] / 60);
229 $fitness_related = ($dfrow['fitness'] == 1) ? 0 : 1;
231 else {
232 $minutes = 0 + $erow['minutes'];
233 $fitness_related = empty($erow['fitness_related']) ? 0 : 1;
235 echo " <tr>\n";
236 echo " <td><b>" . substr($erow['pc_startTime'], 0, 5) . " " .
237 $erow['pc_hometext'] . "</b></td>\n";
238 echo " <td>" . xl('Minutes') . ": " .
239 "<input type='text' name='form_mins_$eid' size='3' value='$minutes' />" .
240 "&nbsp;<input type='checkbox' name='form_fitrel_$eid'";
241 if ($fitness_related) echo " checked";
242 echo " />" . xl('Injury/illness-related') . "</td>\n";
243 echo " </tr>\n";
247 <tr>
248 <td>
249 <b><?php xl('Note','e'); ?></b>
250 </td>
251 <td>
252 <?php
253 // Get the set of local users.
254 $ures = sqlStatement("SELECT username, fname, lname FROM users " .
255 "WHERE username != '' AND active = 1 AND " .
256 "( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
257 "ORDER BY lname, fname");
258 // Show existing note, if any, and then a textarea for adding more.
259 if ($noteid) {
260 echo " <div class='text' " .
261 "style='background-color:white;color:gray;border:1px solid #999;padding: 5px;'>" .
262 nl2br(htmlentities($nrow['body'])) . "</div>\n";
265 <textarea name='form_note' id='note' rows='4' cols='80'></textarea>
266 <br />
267 <b><?php xl('To','e'); ?>:</b>
268 <select name='form_to'>
269 <option value=''>** <?php xl('Close','e'); ?> **</option>
270 <?php
271 // The "To" list of users.
272 while ($urow = sqlFetchArray($ures)) {
273 echo " <option value='" . $urow['username'] . "'";
274 if ($urow['username'] == $nrow['assigned_to']) echo " selected";
275 echo ">" . $urow['lname'];
276 if ($urow['fname']) echo ", " . $urow['fname'];
277 echo "</option>\n";
280 </select>
281 </td>
282 </tr>
284 </table>
287 <input type='submit' name='form_save' value='<?php xl('Save','e'); ?>' /> &nbsp;
288 <input type='button' value='<?php xl('Cancel','e'); ?>' onclick='window.close()' />
290 </center>
291 </form>
292 </body>
293 </html>