Highway to PSR2
[openemr.git] / sites / default / LBF / LBFfms.plugin.php
blobc1240fd41684dca171e75ad0a18b8bf4620311f4
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()
19 global $formid;
21 echo "// Array identifying the numeric '0-3' fields.
22 var fms_numeric = [
23 'squat',
24 'hurdle_l',
25 'lunge_l',
26 'sho_l',
27 'actslr_l',
28 'tspu',
29 'spine',
30 'rotary_l'];
33 echo "// A numeric '0-3' field has changed.
34 function fms_numeric_changed(e) {
35 var f = document.forms[0];
36 // Check if the entry is a valid digit.
37 var val = parseInt(e.value);
38 if (isNaN(val) || val < 0 || val > 3) {
39 e.value = '';
40 return;
42 // Propagate values to the read-only second column.
43 var name = e.name;
44 var namepref = name.substring(0, name.length - 2); // removing the '_1'.
45 var namelr = namepref.substring(namepref.length - 2, namepref.length);
46 var name2 = namepref; // this will be the target
47 // If this is a Left or Right field, we propagate the lower of the two
48 // to the Left row in column 2.
49 if (namelr == '_l') {
50 var tmp = parseInt(f[namepref.substring(0,namepref.length-1) + 'r_1'].value);
51 if (!isNaN(tmp) && tmp < val) val = tmp;
53 else if (namelr == '_r') {
54 name2 = namepref.substring(0,namepref.length-1) + 'l';
55 var tmp = parseInt(f[namepref.substring(0,namepref.length-1) + 'l_1'].value);
56 if (!isNaN(tmp) && tmp < val) val = tmp;
58 f[name2 + '_2'].value = val;
59 // Tally up the propagated values.
60 var sum = 0;
61 for (var i = 0; i < fms_numeric.length; ++i) {
62 var val = parseInt(f['form_' + fms_numeric[i] + '_2'].value);
63 if (!isNaN(val)) sum += val;
65 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;