Various fixes only of interest to athletic teams.
[openemr.git] / sites / default / LBF / LBFfms.plugin.php
blobb3f8f3a93b4c6facfd803e1dc7c39d864db3326d
1 <?php
2 // Copyright (C) 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 provides enhancement functions for the LBFfms visit form,
10 // "Functional Movement Screening". It is invoked by
11 // interface/forms/LBF/new.php.
13 // The purpose of this function is to create JavaScript for the <head>
14 // section of the page. This in turn defines desired javaScript
15 // functions.
17 function LBFfms_javascript() {
18 global $formid;
20 echo "// Array identifying the numeric '0-3' fields.
21 var fms_numeric = [
22 'squat',
23 'hurdle_l',
24 'lunge_l',
25 'sho_l',
26 'actslr_l',
27 'tspu',
28 'spine',
29 'rotary_l'];
32 echo "// A numeric '0-3' field has changed.
33 function fms_numeric_changed(e) {
34 var f = document.forms[0];
35 // Check if the entry is a valid digit.
36 var val = parseInt(e.value);
37 if (isNaN(val) || val < 0 || val > 3) {
38 e.value = '';
39 return;
41 // Propagate values to the read-only second column.
42 var name = e.name;
43 var namepref = name.substring(0, name.length - 2); // removing the '_1'.
44 var namelr = namepref.substring(namepref.length - 2, namepref.length);
45 var name2 = namepref; // this will be the target
46 // If this is a Left or Right field, we propagate the lower of the two
47 // to the Left row in column 2.
48 if (namelr == '_l') {
49 var tmp = parseInt(f[namepref.substring(0,namepref.length-1) + 'r_1'].value);
50 if (!isNaN(tmp) && tmp < val) val = tmp;
52 else if (namelr == '_r') {
53 name2 = namepref.substring(0,namepref.length-1) + 'l';
54 var tmp = parseInt(f[namepref.substring(0,namepref.length-1) + 'l_1'].value);
55 if (!isNaN(tmp) && tmp < val) val = tmp;
57 f[name2 + '_2'].value = val;
58 // Tally up the propagated values.
59 var sum = 0;
60 for (var i = 0; i < fms_numeric.length; ++i) {
61 var val = parseInt(f['form_' + fms_numeric[i] + '_2'].value);
62 if (!isNaN(val)) sum += val;
64 f.form_total.value = sum;
70 // The purpose of this function is to create JavaScript that is run
71 // once when the page is loaded.
73 function LBFfms_javascript_onload() {
75 echo "
76 var f = document.forms[0];
77 for (var i = 0; i < fms_numeric.length; ++i) {
78 var namepref = 'form_' + fms_numeric[i];
79 f[namepref + '_2'].readOnly = true;
80 var ename = namepref + '_1';
81 f[ename].onchange = function () { fms_numeric_changed(this); };
82 var namelr = namepref.substring(namepref.length - 2, namepref.length);
83 if (namelr == '_l') {
84 ename = namepref.substring(0,namepref.length-1) + 'r_1';
85 f[ename].onchange = function () { fms_numeric_changed(this); };
88 f.form_total.readOnly = true;