2 // Copyright (C) 2009 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 //////////////////////////////////////////////////////////////////////
10 // This dialog works with a specified player on a specified date,
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
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'");
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.
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'");
97 sqlStatement("INSERT INTO daily_fitness SET " .
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 " .
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 !== '') {
128 updatePnote($noteid, $form_note, 'Roster', $form_to);
131 addPnote($plid, $form_note, $userauthorized, '1', 'Roster', $form_to,
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";
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 }
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"); ?
>
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 ?>' />
175 <table border
='0' cellspacing
='8'>
178 <b
><?php
xl('Fitness Level','e'); ?
></b
>
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']); ?
>
190 <b
><?php
xl('Related Issue','e'); ?
></b
>
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
>
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";
215 while ($erow = sqlFetchArray($eres)) {
218 print_r($erow); // debugging
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;
232 $minutes = 0 +
$erow['minutes'];
233 $fitness_related = empty($erow['fitness_related']) ?
0 : 1;
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 " <input type='checkbox' name='form_fitrel_$eid'";
241 if ($fitness_related) echo " checked";
242 echo " />" . xl('Injury/illness-related') . "</td>\n";
249 <b
><?php
xl('Note','e'); ?
></b
>
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.
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
>
267 <b
><?php
xl('To','e'); ?
>:</b
>
268 <select name
='form_to'>
269 <option value
=''>** <?php
xl('Close','e'); ?
> **</option
>
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'];
287 <input type
='submit' name
='form_save' value
='<?php xl('Save
','e
'); ?>' />  
;
288 <input type
='button' value
='<?php xl('Cancel
','e
'); ?>' onclick
='window.close()' />