some portal work
[openemr.git] / library / validation / LBF_Validation.php
bloba9177be3cbc0771d591ca413ee8e44ad4bd17002
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
25 /*If another library is used the key names can be modified here*/
26 const VJS_KEY_REQUIRED = 'presence';
28 * Function to generate the constraints used in validation.js library
29 * Using the data save in layout options validation
31 public static function generate_validate_constraints($form_id)
33 //to prevent an empty form id error do :
34 if (!$form_id || $form_id=='') {
35 return json_encode(array());
38 $fres = sqlStatement(
39 "SELECT layout_options.*,list_options.notes as validation_json
40 FROM layout_options
41 LEFT JOIN list_options ON layout_options.validation = list_options.option_id AND list_options.list_id = 'LBF_Validations' AND list_options.activity = 1
42 WHERE layout_options.form_id = ? AND layout_options.uor > 0 AND layout_options.field_id != ''
43 ORDER BY layout_options.group_id, layout_options.seq ",
44 array($form_id)
46 $constraints=array();
47 $validation_arr=array();
48 $required=array();
49 while ($frow = sqlFetchArray($fres)) {
50 $id = 'form_'.$frow['field_id'];
51 $validation_arr=array();
52 $required=array();
53 //Keep "required" option from the LBF form
54 if ($frow['uor'] == 2) {
55 $required = array(self::VJS_KEY_REQUIRED=>true);
58 if ($frow['validation_json']) {
59 if (json_decode($frow['validation_json'])) {
60 $validation_arr=json_decode($frow['validation_json'], true);
61 } else {
62 trigger_error($frow['validation_json']. " is not a valid json ", E_USER_WARNING);
66 if (!empty($required) || !empty($validation_arr)) {
67 $constraints[$id] = array_merge($required, $validation_arr);
71 return json_encode($constraints);