2010-12-02 23:34:41 +00:00
|
|
|
<?php
|
2012-10-25 16:08:30 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
//print_r( $_POST); die;
|
|
|
|
|
/**
|
|
|
|
|
* fields_Save.php
|
|
|
|
|
*
|
|
|
|
|
* ProcessMaker Open Source Edition
|
2011-10-04 16:25:09 -04:00
|
|
|
* Copyright (C) 2004 - 2008 Colosa Inc.
|
2010-12-02 23:34:41 +00:00
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*
|
|
|
|
|
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
|
|
|
|
|
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2011-04-12 11:23:54 -04:00
|
|
|
G::LoadClass('dynaformEditor');
|
|
|
|
|
|
2012-10-25 16:08:30 -04:00
|
|
|
if (($RBAC_Response = $RBAC->userCanAccess("PM_FACTORY")) != 1) {
|
|
|
|
|
return $RBAC_Response;
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-10-25 16:08:30 -04:00
|
|
|
//G::genericForceLogin( 'WF_MYINFO' , 'login/noViewPage', $urlLogin = 'login/login' );
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-10-25 16:08:30 -04:00
|
|
|
G::LoadClass('dynaFormField');
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-10-25 16:08:30 -04:00
|
|
|
$type = strtolower($_POST['form']['PME_TYPE']);
|
|
|
|
|
if (!(isset($_POST['form']['PME_A']) && $_POST['form']['PME_A'] !== '')) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-10-25 16:08:30 -04:00
|
|
|
if (isset($_POST['form']['PME_REQUIRED'])) {
|
2010-12-02 23:34:41 +00:00
|
|
|
if ($_POST['form']['PME_REQUIRED'] == '') {
|
2012-10-25 16:08:30 -04:00
|
|
|
$_POST['form']['PME_REQUIRED'] = 0;
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-25 16:08:30 -04:00
|
|
|
} else {
|
2010-12-02 23:34:41 +00:00
|
|
|
$_POST['form']['PME_REQUIRED'] = 0;
|
2012-10-25 16:08:30 -04:00
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-10-25 16:08:30 -04:00
|
|
|
if (isset($_POST['form']['PME_READONLY'])) {
|
2010-12-02 23:34:41 +00:00
|
|
|
if ($_POST['form']['PME_READONLY'] == '') {
|
2012-10-25 16:08:30 -04:00
|
|
|
$_POST['form']['PME_READONLY'] = 0;
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-25 16:08:30 -04:00
|
|
|
} else {
|
2010-12-02 23:34:41 +00:00
|
|
|
$_POST['form']['PME_READONLY'] = 0;
|
2012-10-25 16:08:30 -04:00
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2015-02-05 13:40:18 -04:00
|
|
|
if (isset($_POST['form']['PME_RESIZABLE'])) {
|
|
|
|
|
if ($_POST['form']['PME_RESIZABLE'] == '') {
|
|
|
|
|
$_POST['form']['PME_RESIZABLE'] = 0;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$_POST['form']['PME_RESIZABLE'] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-27 09:57:22 -04:00
|
|
|
$_POST["form"]["PME_OPTGROUP"] = (isset($_POST["form"]["PME_OPTGROUP"]) && !empty($_POST["form"]["PME_OPTGROUP"]))? intval($_POST["form"]["PME_OPTGROUP"]) : 0;
|
|
|
|
|
|
2012-10-25 16:08:30 -04:00
|
|
|
if (isset($_POST['form']['PME_SAVELABEL'])) {
|
2010-12-02 23:34:41 +00:00
|
|
|
if ($_POST['form']['PME_SAVELABEL'] == '') {
|
2012-10-25 16:08:30 -04:00
|
|
|
$_POST['form']['PME_SAVELABEL'] = 0;
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-25 16:08:30 -04:00
|
|
|
} else {
|
2010-12-02 23:34:41 +00:00
|
|
|
$_POST['form']['PME_SAVELABEL'] = 0;
|
2012-10-25 16:08:30 -04:00
|
|
|
}
|
|
|
|
|
$A = $_POST['form']['PME_A'];
|
|
|
|
|
if (isset($_POST['form']['PME_SAVELABEL'])
|
|
|
|
|
&& isset($_POST['form']['PME_CODE'])
|
|
|
|
|
&& $_POST['form']['PME_TYPE'] === 'javascript') {
|
|
|
|
|
$sType = $_POST['form']['PME_TYPE'];
|
2012-10-25 15:05:26 -04:00
|
|
|
// $A = $_POST['form']['PME_A'];
|
2011-04-12 11:23:54 -04:00
|
|
|
$fieldName = $_POST['form']['PME_XMLNODE_NAME'];
|
2012-10-25 16:08:30 -04:00
|
|
|
$pmeCode = $_POST['form']['PME_CODE'];
|
2011-04-12 11:23:54 -04:00
|
|
|
$_POST['form']['PME_CODE'] = '';
|
2012-10-25 16:08:30 -04:00
|
|
|
// $pmeCode = str_replace("'", "''", $pmeCode);
|
|
|
|
|
// $pmeCode = str_replace('"', '""', $pmeCode);
|
|
|
|
|
// $pmeCode = preg_replace("/\)\s*\n/", ") //\n", $pmeCode);
|
|
|
|
|
// $_POST['form']['PME_CODE'] = $pmeCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$file = G::decrypt($_POST['form']['PME_A'], URL_KEY);
|
|
|
|
|
define('DB_XMLDB_HOST', PATH_DYNAFORM . $file . '.xml');
|
|
|
|
|
define('DB_XMLDB_USER', '');
|
|
|
|
|
define('DB_XMLDB_PASS', '');
|
|
|
|
|
define('DB_XMLDB_NAME', '');
|
|
|
|
|
define('DB_XMLDB_TYPE', 'myxml');
|
|
|
|
|
|
|
|
|
|
// if (isset($_POST['form']['PME_XMLNODE_VALUE'])){
|
|
|
|
|
// $_POST['form']['PME_XMLNODE_VALUE'] = str_replace("'", "''" , $_POST['form']['PME_XMLNODE_VALUE']);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
if (file_exists(PATH_XMLFORM . 'dynaforms/fields/' . $type . '.xml')) {
|
|
|
|
|
$form = new Form('dynaforms/fields/' . $type, PATH_XMLFORM);
|
2010-12-02 23:34:41 +00:00
|
|
|
//TODO: Verify why validatePost removes PME_XMLGRID.
|
2012-10-25 16:08:30 -04:00
|
|
|
$isGrid = isset($_POST['form']['PME_XMLGRID']);
|
|
|
|
|
if ($isGrid) {
|
|
|
|
|
$xmlGrid = $_POST['form']['PME_XMLGRID'];
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
//$form->validatePost();
|
2012-10-25 16:08:30 -04:00
|
|
|
if ($isGrid) {
|
|
|
|
|
$_POST['form']['PME_XMLGRID'] = $xmlGrid;
|
|
|
|
|
}
|
|
|
|
|
if ($type === 'checkbox') {
|
2010-12-02 23:34:41 +00:00
|
|
|
// added by Gustavo Cruz
|
2012-10-25 16:08:30 -04:00
|
|
|
if ($_POST['form']['PME_DEFAULTVALUE'] === "1") {
|
|
|
|
|
$_POST['form']['PME_DEFAULTVALUE'] = $_POST['form']['PME_VALUE'];
|
2010-12-02 23:34:41 +00:00
|
|
|
} else {
|
2012-10-25 16:08:30 -04:00
|
|
|
$_POST['form']['PME_DEFAULTVALUE'] = $_POST['form']['PME_FALSEVALUE'];
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
// end added code
|
2012-10-25 16:08:30 -04:00
|
|
|
// verify why $form->fields['PME_DEFAULTVALUE']->value doesn't capture the value 1
|
|
|
|
|
// if ($_POST['form']['PME_DEFAULTVALUE']===$form->fields['PME_DEFAULTVALUE']->value) {
|
|
|
|
|
// $_POST['form']['PME_DEFAULTVALUE']=$_POST['form']['PME_VALUE'];
|
|
|
|
|
// } else {
|
|
|
|
|
// $_POST['form']['PME_DEFAULTVALUE']=$_POST['form']['PME_FALSEVALUE'];
|
|
|
|
|
// }
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-25 16:08:30 -04:00
|
|
|
if ($type === 'grid') {
|
2012-12-21 10:09:00 -04:00
|
|
|
if (!isset($_POST['form']['PME_ADDROW']) || $_POST['form']['PME_ADDROW'] == '') {
|
2014-02-10 10:55:44 -04:00
|
|
|
$_POST['form']['PME_ADDROW'] = 0;
|
2012-10-25 16:08:30 -04:00
|
|
|
}
|
2012-12-21 10:09:00 -04:00
|
|
|
if (!isset($_POST['form']['PME_DELETEROW']) || $_POST['form']['PME_DELETEROW'] == '') {
|
2014-02-10 10:55:44 -04:00
|
|
|
$_POST['form']['PME_DELETEROW'] = 0;
|
2012-10-25 16:08:30 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($type === 'dropdown' || $type === 'listbox') {
|
2012-12-19 09:21:18 -04:00
|
|
|
if (isset($_POST['form']['PME_OPTIONS'][1]) && count($_POST['form']['PME_OPTIONS']) == 1) {
|
2012-10-25 16:08:30 -04:00
|
|
|
if ($_POST['form']['PME_OPTIONS']['1']['NAME'] === "" &&
|
|
|
|
|
$_POST['form']['PME_OPTIONS']['1']['LABEL'] === "") {
|
|
|
|
|
unset($_POST['form']['PME_OPTIONS']);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2013-08-08 16:46:55 -04:00
|
|
|
if ($type === 'date' && isset($_POST['form']['PME_EDITABLE'])) {
|
|
|
|
|
$_POST['form']['PME_EDITABLE'] = (empty($_POST['form']['PME_EDITABLE'])) ? 0 : $_POST['form']['PME_EDITABLE'];
|
|
|
|
|
}
|
2012-10-25 16:08:30 -04:00
|
|
|
}
|
2013-03-27 09:57:22 -04:00
|
|
|
|
2012-10-25 16:08:30 -04:00
|
|
|
foreach ($_POST['form'] as $key => $value) {
|
|
|
|
|
if (substr($key, 0, 4) === 'PME_') {
|
|
|
|
|
$res[substr($key, 4)] = $value;
|
|
|
|
|
} else {
|
|
|
|
|
$res[$key] = $value;
|
2011-05-09 15:50:03 -04:00
|
|
|
}
|
2012-10-25 16:08:30 -04:00
|
|
|
}
|
2013-03-27 09:57:22 -04:00
|
|
|
|
2012-10-25 16:08:30 -04:00
|
|
|
$_POST['form'] = $res;
|
2011-05-09 15:50:03 -04:00
|
|
|
|
2014-02-10 10:55:44 -04:00
|
|
|
$dbc = new DBConnection(PATH_DYNAFORM . $file . '.xml', '', '', '', 'myxml');
|
2012-10-25 16:08:30 -04:00
|
|
|
$ses = new DBSession($dbc);
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-10-25 16:08:30 -04:00
|
|
|
$fields = new DynaFormField($dbc);
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-10-25 16:08:30 -04:00
|
|
|
if ($_POST['form']['XMLNODE_NAME'] === '') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-10-25 16:08:30 -04:00
|
|
|
$attributes = $_POST['form'];
|
2012-10-25 15:05:26 -04:00
|
|
|
|
2012-10-25 16:08:30 -04:00
|
|
|
if (isset($attributes['HINT'])) {
|
2012-06-28 18:30:08 -04:00
|
|
|
$attributes['HINT'] = addslashes($attributes['HINT']);
|
|
|
|
|
$attributes['HINT'] = htmlspecialchars($attributes['HINT'], ENT_QUOTES, "UTF-8");
|
2012-10-25 16:08:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($attributes['CODE'])) {
|
|
|
|
|
$attributes['XMLNODE_VALUE'] = ($attributes['CODE']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$labels = array();
|
|
|
|
|
if (isset($attributes['LABEL'])) {
|
|
|
|
|
$labels = array(SYS_LANG => $attributes['LABEL']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unset($attributes['A']);
|
|
|
|
|
unset($attributes['ACCEPT']);
|
|
|
|
|
unset($attributes['LABEL']);
|
|
|
|
|
unset($attributes['PRO_UID']);
|
|
|
|
|
|
|
|
|
|
$options = null;
|
|
|
|
|
foreach ($attributes as $key => $value) {
|
2014-02-10 10:55:44 -04:00
|
|
|
if ($key === 'OPTIONS') {
|
2012-10-25 16:08:30 -04:00
|
|
|
if (is_array($value)) {
|
|
|
|
|
if (is_array(reset($value))) {
|
|
|
|
|
$langs = array();
|
|
|
|
|
$options = array();
|
|
|
|
|
$langs[] = SYS_LANG;
|
|
|
|
|
$options[SYS_LANG] = array();
|
|
|
|
|
foreach ($value as $row) {
|
|
|
|
|
foreach ($langs as $lang) {
|
|
|
|
|
$LANG = strtoupper($lang);
|
|
|
|
|
if (isset($row['LABEL'])) {
|
|
|
|
|
$options[$lang][$row['NAME']] = $row['LABEL'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* $first = reset($value);
|
|
|
|
|
foreach( $first as $optKey => $optValue ) {
|
|
|
|
|
if (substr($optKey,0,6)==='LABEL_') {
|
|
|
|
|
$langs[]=strtolower(substr($optKey,6));
|
|
|
|
|
$options[strtolower(substr($optKey,6))]=array();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
foreach( $value as $row ) {
|
|
|
|
|
foreach( $langs as $lang ) {
|
|
|
|
|
$LANG = strtoupper($lang);
|
|
|
|
|
if (isset($row['LABEL_'.$LANG]))
|
|
|
|
|
$options[$lang][$row['NAME']]=$row['LABEL_'.$LANG];
|
|
|
|
|
}
|
|
|
|
|
} */
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
2014-02-10 10:55:44 -04:00
|
|
|
} else {
|
2012-10-25 16:08:30 -04:00
|
|
|
if (is_array($value)) {
|
|
|
|
|
//Is a list:
|
|
|
|
|
if (is_string(reset($value))) {
|
|
|
|
|
$attributes[$key] = implode(',', $value);
|
|
|
|
|
} else {
|
|
|
|
|
//Is a grid.
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-10-25 16:08:30 -04:00
|
|
|
}
|
|
|
|
|
unset($attributes['VALIDATE_NAME']);
|
|
|
|
|
$fields->setFileName(PATH_DYNAFORM . $file . '.xml');
|
|
|
|
|
$FieldAttributes = $attributes;
|
|
|
|
|
$FieldAttrib = array();
|
2014-02-10 10:55:44 -04:00
|
|
|
|
2012-10-25 16:08:30 -04:00
|
|
|
unset($FieldAttributes['XMLNODE_NAME']);
|
|
|
|
|
unset($FieldAttributes['XMLNODE_NAME_OLD']);
|
|
|
|
|
unset($FieldAttributes['XMLNODE_VALUE']);
|
|
|
|
|
unset($FieldAttributes['BTN_CANCEL']);
|
|
|
|
|
unset($FieldAttributes['SAVELABEL']);
|
2014-02-10 10:55:44 -04:00
|
|
|
|
2012-10-25 16:08:30 -04:00
|
|
|
foreach ($FieldAttributes as $key => $value) {
|
2013-08-12 10:56:10 -04:00
|
|
|
switch (gettype($value)) {
|
|
|
|
|
case 'string':
|
2014-05-20 12:19:09 -04:00
|
|
|
if (!empty($value) || $value !== '') {
|
2013-08-12 10:56:10 -04:00
|
|
|
$FieldAttrib[strtolower($key)] = $value;
|
2013-10-22 11:46:03 -04:00
|
|
|
} else {
|
|
|
|
|
if ($_POST["form"]["TYPE"] == "link" && $key == "TARGET_SEL") {
|
|
|
|
|
$FieldAttrib[strtolower($key)] = $value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-12 10:56:10 -04:00
|
|
|
break;
|
|
|
|
|
case 'integer':
|
|
|
|
|
$FieldAttrib[strtolower($key)] = $value;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
//Nothing
|
|
|
|
|
break;
|
2012-10-25 16:08:30 -04:00
|
|
|
}
|
|
|
|
|
}
|
2013-08-12 10:56:10 -04:00
|
|
|
|
2012-10-25 16:08:30 -04:00
|
|
|
$fields->saveField($attributes, $FieldAttrib, $labels);
|
|
|
|
|
|
|
|
|
|
G::LoadClass('xmlDb');
|
|
|
|
|
$i = 0;
|
|
|
|
|
$aFields = array();
|
|
|
|
|
$aFields[] = array('XMLNODE_NAME' => 'char',
|
|
|
|
|
'TYPE' => 'char',
|
|
|
|
|
'UP' => 'char',
|
|
|
|
|
'DOWN' => 'char',
|
|
|
|
|
'row__' => 'integer');
|
|
|
|
|
$oSession = new DBSession(new DBConnection(PATH_DYNAFORM . $file . '.xml', '', '', '', 'myxml'));
|
|
|
|
|
$oDataset = $oSession->Execute('SELECT * FROM dynaForm WHERE NOT( XMLNODE_NAME = "" )');
|
|
|
|
|
$iMaximun = $oDataset->count();
|
|
|
|
|
while ($aRow = $oDataset->Read()) {
|
|
|
|
|
$aFields[] = array('XMLNODE_NAME' => $aRow['XMLNODE_NAME'],
|
2012-12-21 10:00:42 -04:00
|
|
|
'TYPE' => isset($aRow['TYPE']) ? $aRow['TYPE'] : '',
|
2012-10-25 16:08:30 -04:00
|
|
|
'UP' => ($i > 0 ? G::LoadTranslation('ID_UP') : ''),
|
|
|
|
|
'DOWN' => ($i < $iMaximun - 1 ? G::LoadTranslation('ID_DOWN') : ''),
|
|
|
|
|
'row__' => ($i + 1));
|
2010-12-02 23:34:41 +00:00
|
|
|
$i++;
|
2012-10-25 16:08:30 -04:00
|
|
|
}
|
|
|
|
|
global $_DBArray;
|
|
|
|
|
$_DBArray['fields'] = $aFields;
|
|
|
|
|
$_SESSION['_DBArray'] = $_DBArray;
|
|
|
|
|
|
|
|
|
|
// Additions to javascript
|
|
|
|
|
if (isset($sType) && $sType === 'javascript') {
|
|
|
|
|
$sCode = urlencode($pmeCode);
|
2011-04-12 11:23:54 -04:00
|
|
|
$editor = new dynaformEditorAjax($_POST);
|
|
|
|
|
$editor->set_javascript($A, $fieldName, $sCode);
|
2012-10-25 16:08:30 -04:00
|
|
|
}
|
2013-03-27 09:57:22 -04:00
|
|
|
|