2010-12-02 23:34:41 +00:00
|
|
|
<?php
|
2012-10-18 11:53:05 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
/**
|
|
|
|
|
* dynaforms_checkDependentFields.php
|
|
|
|
|
*
|
|
|
|
|
* ProcessMaker Open Source Edition
|
|
|
|
|
* Copyright (C) 2004 - 2010 Colosa Inc.23
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-10-18 11:53:05 -04:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2010-12-02 23:34:41 +00:00
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2012-10-18 11:53:05 -04:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-12-02 23:34:41 +00:00
|
|
|
*
|
|
|
|
|
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
|
|
|
|
|
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
|
|
|
|
|
*/
|
|
|
|
|
|
2012-10-18 11:53:05 -04:00
|
|
|
/**
|
|
|
|
|
* this file is a fix to a dependency bug it was just a minor improvement,
|
|
|
|
|
* also the functionality of dependent fields in grids doesn't depends in this
|
|
|
|
|
* file so this is somewhat expendable.
|
|
|
|
|
*/
|
2017-02-15 16:26:02 +00:00
|
|
|
|
2015-03-19 17:24:54 -04:00
|
|
|
$filter = new InputFilter();
|
|
|
|
|
$_POST = $filter->xssFilterHard($_POST);
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
function subDependencies($k, &$G_FORM, &$aux, $grid = '')
|
2012-10-18 11:53:05 -04:00
|
|
|
{
|
2010-12-02 23:34:41 +00:00
|
|
|
$myDependentFields = '';
|
2017-12-04 13:25:35 +00:00
|
|
|
if (array_search($k, $aux) !== false) {
|
|
|
|
|
return array();
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-18 11:53:05 -04:00
|
|
|
if ($grid == '') {
|
2017-12-04 13:25:35 +00:00
|
|
|
if (!array_key_exists($k, $G_FORM->fields)) {
|
|
|
|
|
return array();
|
2012-10-18 11:53:05 -04:00
|
|
|
}
|
2017-12-04 13:25:35 +00:00
|
|
|
if (!isset($G_FORM->fields[$k]->dependentFields)) {
|
|
|
|
|
return array();
|
2012-10-18 11:53:05 -04:00
|
|
|
}
|
|
|
|
|
$aux[] = $k;
|
|
|
|
|
$mydependentFields = $G_FORM->fields[$k]->dependentFields;
|
|
|
|
|
} else {
|
2017-12-04 13:25:35 +00:00
|
|
|
if (!array_key_exists($k, $G_FORM->fields[$grid]->fields)) {
|
|
|
|
|
return array();
|
2012-10-18 11:53:05 -04:00
|
|
|
}
|
2017-12-04 13:25:35 +00:00
|
|
|
if (!isset($G_FORM->fields[$grid]->fields[$k]->dependentFields)) {
|
|
|
|
|
return array();
|
2012-10-18 11:53:05 -04:00
|
|
|
}
|
|
|
|
|
$myDependentFields = $G_FORM->fields[$grid]->fields[$k]->dependentFields;
|
2017-12-04 13:25:35 +00:00
|
|
|
$myDependentFields = explode(',', $G_FORM->fields[$grid]->fields[$k]->dependentFields);
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
return $myDependentFields;
|
2012-10-18 11:53:05 -04:00
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
if (($RBAC_Response = $RBAC->userCanAccess("PM_FACTORY")) != 1) {
|
2012-10-18 11:53:05 -04:00
|
|
|
return $RBAC_Response;
|
|
|
|
|
}
|
2017-12-04 13:25:35 +00:00
|
|
|
// the script responds an ajax request in order to check the dependent fields,
|
|
|
|
|
// and generate a json output of the values that the dependent field must have.
|
|
|
|
|
$sDynUid = G::getUIDName(urlDecode($_POST['DYN_UID']));
|
2012-11-29 14:25:06 -04:00
|
|
|
//$json = new Services_JSON();
|
2017-12-04 13:25:35 +00:00
|
|
|
$formValues = (Bootstrap::json_decode($_POST['fields']));
|
2012-10-18 11:53:05 -04:00
|
|
|
$sFieldName = $_POST['fieldName'];
|
2010-12-02 23:34:41 +00:00
|
|
|
$sMasterField = '';
|
|
|
|
|
$sPath = PATH_DYNAFORM;
|
2017-12-04 13:25:35 +00:00
|
|
|
$G_FORM = new Form($sDynUid, $sPath);
|
|
|
|
|
$aux = array();
|
|
|
|
|
$newValues = Bootstrap::json_decode(urlDecode(stripslashes($_POST['form'])));
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
if (isset($_POST['grid'])) {
|
|
|
|
|
$_POST['row'] = (int)$_POST['row'];
|
|
|
|
|
$aAux = array();
|
2010-12-02 23:34:41 +00:00
|
|
|
foreach ($newValues as $sKey => $newValue) {
|
2017-12-04 13:25:35 +00:00
|
|
|
$newValue = (array)$newValue;
|
|
|
|
|
$aKeys = array_keys($newValue);
|
|
|
|
|
$aValues = array();
|
|
|
|
|
for ($i = 1; $i <= ($_POST['row'] - 1); $i++) {
|
|
|
|
|
$aValues[$i] = array($aKeys[0] => ''
|
2012-10-18 11:53:05 -04:00
|
|
|
);
|
|
|
|
|
}
|
2017-12-04 13:25:35 +00:00
|
|
|
$aValues[$_POST['row']] = array($aKeys[0] => $newValue[$aKeys[0]]);
|
|
|
|
|
$newValues[$sKey]->{$_POST['grid']} = $aValues;
|
|
|
|
|
unset($newValues[$sKey]->{$aKeys[0]});
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-18 11:53:05 -04:00
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
$dependentFields = array();
|
|
|
|
|
$aux = array();
|
2012-10-18 11:53:05 -04:00
|
|
|
$found = false;
|
2017-12-04 13:25:35 +00:00
|
|
|
for ($r = 0; $r < sizeof($newValues); $r++) {
|
|
|
|
|
$newValues[$r] = (array)$newValues[$r];
|
|
|
|
|
$G_FORM->setValues($newValues[$r]);
|
2012-10-18 11:53:05 -04:00
|
|
|
//Search dependent fields
|
|
|
|
|
foreach ($newValues[$r] as $k => $v) {
|
2017-12-04 13:25:35 +00:00
|
|
|
if (!is_array($v)) {
|
|
|
|
|
$myDependentFields = subDependencies($k, $G_FORM, $aux);
|
|
|
|
|
if (!$found) {
|
|
|
|
|
if (in_array($sFieldName, $myDependentFields)) {
|
2012-10-18 11:53:05 -04:00
|
|
|
$sMasterField = $k;
|
|
|
|
|
$found = true;
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-18 11:53:05 -04:00
|
|
|
$_SESSION[$G_FORM->id][$k] = $v;
|
|
|
|
|
} else {
|
|
|
|
|
foreach ($v[$_POST['row']] as $k1 => $v1) {
|
2017-12-04 13:25:35 +00:00
|
|
|
$myDependentFields = subDependencies($k1, $G_FORM, $aux, $_POST['grid']);
|
|
|
|
|
if (!$found) {
|
|
|
|
|
if (in_array($sFieldName, $myDependentFields)) {
|
2012-10-18 11:53:05 -04:00
|
|
|
$sMasterField = $k1;
|
|
|
|
|
$found = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$_SESSION[$G_FORM->id][$_POST['grid']][$_POST['row']][$k1] = $v1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-04 13:25:35 +00:00
|
|
|
$dependentFields = array_merge($dependentFields, $myDependentFields);
|
2012-10-18 11:53:05 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
switch ($_POST['function']) {
|
2010-12-02 23:34:41 +00:00
|
|
|
case 'showDependentFields':
|
2017-12-04 13:25:35 +00:00
|
|
|
echo $json->encode(array_unique($dependentFields));
|
2012-10-18 11:53:05 -04:00
|
|
|
break;
|
2010-12-02 23:34:41 +00:00
|
|
|
case 'showDependentOf':
|
2012-10-18 11:53:05 -04:00
|
|
|
echo $sMasterField;
|
|
|
|
|
break;
|
|
|
|
|
}
|