minor fix in hover for prior commit
[openemr.git] / library / validation / LBF_Validation.php
blob076ba86d34e69f8d35c53d8bfc68c3bc9dbd0a76
1 <?php
2 /**
3 * LICENSE: This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License
5 * as published by the Free Software Foundation; either version 3
6 * of the License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 * You should have received a copy of the GNU General Public License
12 * along with this program. If not, see
13 * http://www.gnu.org/licenses/licenses.html#GPL .
15 * @package OpenEMR
16 * @license http://www.gnu.org/licenses/licenses.html#GPL GNU GPL V3+
17 * @author Sharon Cohen <sharonco@matrix.co.il>
18 * @author Amiel Elboim <amielel@matrix.co.il>
19 * @link http://www.open-emr.org
22 class LBF_Validation{
24 /*If another library is used the key names can be modified here*/
25 const VJS_KEY_REQUIRED = 'presence';
27 * Function to generate the constraints used in validation.js library
28 * Using the data save in layout options validation
30 public static function generate_validate_constraints($form_id){
31 //to prevent an empty form id error do :
32 if(!$form_id || $form_id==''){
33 return json_encode(array());
36 $fres = sqlStatement(
37 "SELECT layout_options.*,list_options.notes as validation_json
38 FROM layout_options
39 LEFT JOIN list_options ON layout_options.validation = list_options.option_id AND list_options.list_id = 'LBF_Validations' AND list_options.activity = 1
40 WHERE layout_options.form_id = ? AND layout_options.uor > 0 AND layout_options.field_id != ''
41 ORDER BY layout_options.group_name, layout_options.seq ", array($form_id) );
42 $constraints=array();
43 $validation_arr=array();
44 $required=array();
45 while ($frow = sqlFetchArray($fres)) {
46 $id = 'form_'.$frow['field_id'];
47 $validation_arr=array();
48 $required=array();
49 //Keep "required" option from the LBF form
50 if($frow['uor'] == 2 ){
51 $required = array(self::VJS_KEY_REQUIRED=>true);
53 if ($frow['validation_json']){
54 if(json_decode($frow['validation_json'])) {
55 $validation_arr=json_decode($frow['validation_json'],true);
57 }else{
58 trigger_error($frow['validation_json']. " is not a valid json ", E_USER_WARNING);
61 if(!empty($required) || !empty($validation_arr)) {
62 $constraints[$id] = array_merge($required, $validation_arr);
67 return json_encode($constraints);