another minor fix to prior commit
[openemr.git] / library / validation / validate_core.php
blob959b7ff2527848d647ee68e56de4bd6c6a792d0a
1 <?php
3 /**
4 * LICENSE: 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 3
7 * of the License, or (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see
14 * http://www.gnu.org/licenses/licenses.html#GPL .
16 * @package OpenEMR
17 * @license http://www.gnu.org/licenses/licenses.html#GPL GNU GPL V3+
18 * @author Dror Golan <drorgo@matrix.co.il>
19 * @link http://www.open-emr.org
23 /**get all the validation on the page
24 * @param $title
25 * @return array of validation rules and forms names
27 function collectValidationPageRules($title,$active=true){
29 // Note from Rod: Not sure what the purpose is of $active because nothing calls it with a false value.
31 if($active){
32 $sql = sqlStatement("SELECT * " .
33 "FROM `list_options` WHERE list_id=? AND activity=? AND title = ?",array('page_validation',1,$title));
35 else {
36 $sql = sqlStatement("SELECT * " .
37 "FROM `list_options` WHERE list_id=? AND title=?", array('page_validation', $title));
40 $dataArray=array();
41 while($row = sqlFetchArray($sql) ) {
42 $formPageNameArray = explode('#', $row['option_id']);
43 $dataArray[$formPageNameArray[1]]=array('page_name' => $formPageNameArray[0] ,'rules' => $row['notes']);
45 return $dataArray;
49 /**this function creates client side validation rules for each <form> declared in list : Patient Validation - patient_validation
50 * @param $fileNamePath
51 * @output a generated javascript tag with the validation
53 function validateUsingPageRules($fileNamePath)
56 $path='';
58 if($GLOBALS['webroot']!='')
60 $path= str_replace($GLOBALS['webroot'], '',$fileNamePath);
62 else{
63 $path=$fileNamePath;
66 print '<!--Page Form Validations-->';
67 //if we would like to get all the page forms rules we need to call collectValidationPageRules($title) this way there is a
68 $collectThis=collectValidationPageRules($path);
69 if ($collectThis) {
73 print '<!---Start of page form validation-->';
74 print '<!--//include new rules of submitme functionallity-->';
75 echo("\r\n");
76 //Not lbf forms use the new validation, please make sure you have the corresponding values in the list Page validation
77 $use_validate_js = 1;
78 require_once($GLOBALS['srcdir'] . "/validation/validation_script.js.php");
79 echo("\r\n");
80 print '<script type="text/javascript">';
81 echo ("$(document).ready(function(){");
82 echo("\r\n");
83 foreach ($collectThis as $key => $value) {
84 echo("try{");
85 echo("\r\n");
86 echo('if(document.getElementsByName("' . $key . '").length>0)');
87 echo("\r\n");
88 echo('{');
89 echo("\r\n");
90 echo('var form = document.getElementsByName("'.$key.'");');
91 echo("\r\n");
92 echo('form[0].setAttribute("id","'. $key.'");');
93 echo("\r\n");
95 echo('//Use validation script js Validations-');
96 echo("\r\n");
98 echo('$("#'.$key.'").submit(function(event){');
99 echo("\r\n");
101 echo("\r\n");
102 echo ('var submitvalue = submitme(' . $use_validate_js . ',event,"' . $key . '",' . $collectThis[$key]['rules'] . ');');
103 echo("\r\n");
104 echo(' if(submitvalue){');
105 echo("\r\n");
106 echo(" ");
107 echo("\r\n");
108 echo('}');
109 echo("\r\n");
110 echo('else{');
111 echo("\r\n");
112 echo (" event.preventDefault();");
113 echo("\r\n");
114 echo('}');
115 echo("\r\n");
116 echo('});}}');
117 //echo('$("#'.$key.'").prop("onclick", \'return ');
119 echo("\r\n");
120 echo('catch(err)');
121 echo("\r\n");
122 echo('{');
123 echo("\r\n");
124 echo('//log err - console.log(err)');
125 echo("\r\n");
126 echo('}');
129 echo ("});");
130 echo("\r\n");
131 echo('</script>');
132 print '<!---End of page form validation-->';