Improvements for statements
[openemr.git] / library / validation / validate_core.php
blobe7ea08ff14f535ed8e8e59d4cc79ba0a668c7005
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 if($active){
30 $sql = sqlStatement("SELECT * " .
31 "FROM `list_options` WHERE list_id=? AND activity=? AND title=?",array('page_validation',1,$title));
33 else {
34 $sql = sqlStatement("SELECT * " .
35 "FROM `list_options` WHERE list_id=? AND title=?", array('page_validation', $title));
38 $dataArray=array();
39 while($row = sqlFetchArray($sql) ) {
40 $formPageNameArray = explode('#', $row['option_id']);
41 $dataArray[$formPageNameArray[1]]=array('page_name' => $formPageNameArray[0] ,'rules' => $row['notes']);
43 return $dataArray;
47 /**this function creates client side validation rules for each <form> declared in list : Patient Validation - patient_validation
48 * @param $fileNamePath
49 * @output a generated javascript tag with the validation
51 function validateUsingPageRules($fileNamePath)
54 $path='';
56 if($GLOBALS['webroot']!='')
58 $path= str_replace($GLOBALS['webroot'], '',$fileNamePath);
60 else{
61 $path=$fileNamePath;
64 print '<!--Page Form Validations-->';
65 //if we would like to get all the page forms rules we need to call collectValidationPageRules($title) this way there is a
66 $collectThis=collectValidationPageRules($path);
67 if ($collectThis) {
71 print '<!---Start of page form validation-->';
72 print '<!--//include new rules of submitme functionallity-->';
73 echo("\r\n");
74 require_once($GLOBALS['srcdir'] . "/validation/validation_script.js.php");
75 $new_validate = $GLOBALS['new_validate'] ? 1 : 0;
76 echo("\r\n");
77 print '<script type="text/javascript">';
78 echo ("$(document).ready(function(){");
79 echo("\r\n");
80 foreach ($collectThis as $key => $value) {
81 echo("try{");
82 echo("\r\n");
83 echo('if(document.getElementsByName("' . $key . '").length>0)');
84 echo("\r\n");
85 echo('{');
86 echo("\r\n");
87 echo('var form = document.getElementsByName("'.$key.'");');
88 echo("\r\n");
89 echo('form[0].setAttribute("id","'. $key.'");');
90 echo("\r\n");
92 echo('//Use validation script js Validations-');
93 echo("\r\n");
95 echo('$("#'.$key.'").submit(function(event){');
96 echo("\r\n");
98 echo("\r\n");
99 echo ('var submitvalue = submitme(' . $new_validate . ',event,"' . $key . '",' . $collectThis[$key]['rules'] . ');');
100 echo("\r\n");
101 echo(' if(submitvalue){');
102 echo("\r\n");
103 echo(" ");
104 echo("\r\n");
105 echo('}');
106 echo("\r\n");
107 echo('else{');
108 echo("\r\n");
109 echo (" event.preventDefault();");
110 echo("\r\n");
111 echo('}');
112 echo("\r\n");
113 echo('});}}');
114 //echo('$("#'.$key.'").prop("onclick", \'return ');
116 echo("\r\n");
117 echo('catch(err)');
118 echo("\r\n");
119 echo('{');
120 echo("\r\n");
121 echo('//log err - console.log(err)');
122 echo("\r\n");
123 echo('}');
126 echo ("});");
127 echo("\r\n");
128 echo('</script>');
129 print '<!---End of page form validation-->';