BUG 9286 Comments are deleted from the XML code for DynaForms SOLVED

- ProcessMaker deletes comments from XML code. For example if I have:
- Change in the way of creating XML files in DynaForms.
This commit is contained in:
Hector Cortez
2012-10-25 15:05:26 -04:00
parent 05de793839
commit 8e4229f53e
4 changed files with 240 additions and 75 deletions

View File

@@ -135,6 +135,12 @@ class dynaFormHandler
function add($name, $attributes, $childs, $childs_childs=null) function add($name, $attributes, $childs, $childs_childs=null)
{ {
$newnode = $this->root->appendChild($this->dom->createElement($name)); $newnode = $this->root->appendChild($this->dom->createElement($name));
if( isset($attributes['#cdata']) ) {
$newnode->appendChild($this->dom->createTextNode("\n"));
$newnode->appendChild($this->dom->createCDATASection($attributes['#cdata']));
$newnode->appendChild($this->dom->createTextNode("\n"));
unset($attributes['#cdata']);
}
foreach($attributes as $att_name => $att_value) { foreach($attributes as $att_name => $att_value) {
$newnode->setAttribute($att_name, $att_value); $newnode->setAttribute($att_name, $att_value);
} }
@@ -159,6 +165,35 @@ class dynaFormHandler
$this->save(); $this->save();
} }
private function hasChild($p)
{
if ($p->hasChildNodes()) {
foreach ($p->childNodes as $c) {
if ($c->nodeType == XML_ELEMENT_NODE) {
return true;
}
}
}
return false;
}
private function getChildNode($x)
{
$chidNode = array();
foreach ($x->childNodes as $p) {
if ($this->hasChild($p)) {
getChildNode($p);
} else {
if ($p->nodeType == XML_ELEMENT_NODE) {
$chidNode[] = array('node' => $x->nodeName, 'nodeName' => $p->nodeName,
'name' => $p->getAttribute('name'), 'nodeValue' => $p->nodeValue);
}
}
}
return array($x->nodeName => $chidNode);
}
/** /**
* Function replace * Function replace
* @access public * @access public
@@ -171,39 +206,69 @@ class dynaFormHandler
*/ */
function replace($replaced, $name, $attributes, $childs=null, $childs_childs=null) function replace($replaced, $name, $attributes, $childs=null, $childs_childs=null)
{ {
$chidNode= array();
$element = $this->root->getElementsByTagName($replaced)->item(0); $element = $this->root->getElementsByTagName($replaced)->item(0);
$this->root->replaceChild($this->dom->createElement($name), $element); $this->root->replaceChild($this->dom->createElement($name), $element);
$newnode = $element = $this->root->getElementsByTagName($name)->item(0); // $newnode = $element = $this->root->getElementsByTagName($name)->item(0);
$newnode = $this->root->getElementsByTagName($name)->item(0);
if( isset($attributes['#text']) ) { if( isset($attributes['#text']) ) {
$newnode->appendChild($this->dom->createTextNode($attributes['#text'])); $newnode->appendChild($this->dom->createTextNode($attributes['#text']));
unset($attributes['#text']); unset($attributes['#text']);
} }
if( isset($attributes['#cdata']) ) { if( isset($attributes['#cdata']) ) {
$newnode->appendChild($this->dom->createTextNode("\n"));
$newnode->appendChild($this->dom->createCDATASection($attributes['#cdata'])); $newnode->appendChild($this->dom->createCDATASection($attributes['#cdata']));
$newnode->appendChild($this->dom->createTextNode("\n"));
unset($attributes['#cdata']); unset($attributes['#cdata']);
} }
foreach($attributes as $att_name => $att_value) { foreach($attributes as $att_name => $att_value) {
$newnode->setAttribute($att_name, $att_value); if (!is_array($att_value)) {
$newnode->setAttribute($att_name, $att_value);
}
} }
if(is_array($childs)){ if(is_array($childs)){
foreach ($element->childNodes as $pNode) {
if( $pNode->nodeName != SYS_LANG && $pNode->nodeName != '#cdata-section' && $pNode->nodeName != '#text') {
$chidNode[] = $this->getChildNode($pNode);
$childs[$pNode->nodeName] = $pNode->firstChild->nodeValue;
}
}
foreach($childs as $child_name => $child_text) { foreach($childs as $child_name => $child_text) {
$newnode->appendChild($this->dom->createTextNode(" "));
$newnode_child = $newnode->appendChild($this->dom->createElement($child_name)); $newnode_child = $newnode->appendChild($this->dom->createElement($child_name));
if( is_string($child_text) ) if( is_string($child_text) )
$newnode_child->appendChild($this->dom->createTextNode($child_text)); $newnode_child->appendChild($this->dom->createTextNode($child_text));
else if( is_array($child_text) && isset($child_text['cdata']) ) else if( is_array($child_text) && isset($child_text['cdata']) )
$newnode_child->appendChild($this->dom->createCDATASection($child_text)); $newnode_child->appendChild($this->dom->createCDATASection($child_text));
if ($child_name == SYS_LANG ) {
if($childs_childs != null and is_array($childs_childs)){ if($childs_childs != null and is_array($childs_childs)){
foreach($childs_childs as $cc) { foreach($childs_childs as $cc) {
$ccmode = $newnode_child->appendChild($this->dom->createElement($cc['name'])); $ccmode = $newnode_child->appendChild($this->dom->createElement($cc['name']));
$ccmode->appendChild($this->dom->createTextNode($cc['value'])); $ccmode->appendChild($this->dom->createTextNode($cc['value']));
foreach($cc['attributes'] as $cc_att_name => $cc_att_value) { foreach($cc['attributes'] as $cc_att_name => $cc_att_value) {
$ccmode->setAttribute($cc_att_name, $cc_att_value); $ccmode->setAttribute($cc_att_name, $cc_att_value);
}
}
}
} else {
foreach ($chidNode as $valueNode) {
if ( array_key_exists($child_name, $valueNode) ) {
foreach($valueNode[$child_name] as $valOption) {
$ccmode = $newnode_child->appendChild($this->dom->createElement($valOption['nodeName']));
$ccmode->appendChild($this->dom->createTextNode($valOption['nodeValue']));
$ccmode->setAttribute('name', $valOption['name']);
}
}
} }
}
} }
$newnode->appendChild($this->dom->createTextNode("\n"));
} }
} else if( isset($childs) ){ } else if( isset($childs) ){
$text_node = $childs; $text_node = $childs;
@@ -257,7 +322,10 @@ class dynaFormHandler
$this->root->setAttribute($att_name, $att_value); $this->root->setAttribute($att_name, $att_value);
$this->save(); $this->save();
} }
function getHeaderAttribute($att_name)
{
return $this->root->getAttribute($att_name);
}
/** /**
* Function modifyHeaderAttribute * Function modifyHeaderAttribute
* @param string $att_name * @param string $att_name

View File

@@ -26,6 +26,7 @@
*/ */
G::LoadClass( 'xmlDb' ); G::LoadClass( 'xmlDb' );
G::LoadSystem('dynaformhandler');
/** /**
* Dynaform Field - DynaformField class * Dynaform Field - DynaformField class
@@ -34,6 +35,16 @@ G::LoadClass( 'xmlDb' );
*/ */
class DynaFormField extends DBTable class DynaFormField extends DBTable
{ {
private $fileName;
public function getFileName()
{
return $this->fileName;
}
public function setFileName($fileName)
{
$this->fileName = $fileName;
}
/** /**
* Function SetTo * Function SetTo
@@ -108,9 +119,9 @@ class DynaFormField extends DBTable
$this->Fields = $Fields; $this->Fields = $Fields;
unset( $this->Fields['XMLNODE_NAME_OLD'] ); unset( $this->Fields['XMLNODE_NAME_OLD'] );
/* /*
* MPD-10 to create fields that do not appear many attributes, only the main ones? * MPD-10 to create fields that do not appear many attributes, only the main ones?
* The show those who are not white * The show those who are not white
*/ */
if ($this->is_new) { if ($this->is_new) {
foreach ($this->Fields as $key => $value) { foreach ($this->Fields as $key => $value) {
if ($value == "") if ($value == "")
@@ -125,12 +136,12 @@ class DynaFormField extends DBTable
parent::Save(); parent::Save();
if ($this->is_new) { if ($this->is_new) {
/* /*
* Create a new field. * Create a new field.
*/ */
foreach ($labels as $lang => $value) { foreach ($labels as $lang => $value) {
/*$res = $this->_dbses->Execute('INSERT INTO dynaForm'. /*$res = $this->_dbses->Execute('INSERT INTO dynaForm'.
' (XMLNODE_TYPE,XMLNODE_VALUE)'. ' (XMLNODE_TYPE,XMLNODE_VALUE)'.
' VALUES ("cdata", "'."\n".'")');*/ ' VALUES ("cdata", "'."\n".'")');*/
$res = $this->_dbses->Execute( 'INSERT INTO dynaForm.' . $Fields['XMLNODE_NAME'] . ' (XMLNODE_NAME,XMLNODE_VALUE,XMLNODE_TYPE) ' . 'VALUES ("","' . "\n " . '","cdata")' ); $res = $this->_dbses->Execute( 'INSERT INTO dynaForm.' . $Fields['XMLNODE_NAME'] . ' (XMLNODE_NAME,XMLNODE_VALUE,XMLNODE_TYPE) ' . 'VALUES ("","' . "\n " . '","cdata")' );
$res = $this->_dbses->Execute( 'INSERT INTO dynaForm.' . $Fields['XMLNODE_NAME'] . ' (XMLNODE_NAME,XMLNODE_VALUE) ' . 'VALUES ("' . $lang . '","' . str_replace( '"', '""', $value )/*."\n "*/.'")' ); $res = $this->_dbses->Execute( 'INSERT INTO dynaForm.' . $Fields['XMLNODE_NAME'] . ' (XMLNODE_NAME,XMLNODE_VALUE) ' . 'VALUES ("' . $lang . '","' . str_replace( '"', '""', $value )/*."\n "*/.'")' );
if (isset( $options[$lang] )) { if (isset( $options[$lang] )) {
@@ -165,6 +176,63 @@ class DynaFormField extends DBTable
} }
} }
function saveField ($Fields, $attributes = array(), $options = array())
{
$dynaform = new dynaFormHandler( $this->getFileName());
if ($Fields['TYPE'] === 'javascript') {
$Fields['XMLNODE_VALUE'] = $Fields['CODE'];
unset( $Fields['CODE'] );
$attributes = array ();
}
if ($Fields['XMLNODE_NAME_OLD'] == '') {
if (($Fields['XMLNODE_NAME'][0] == '1') || ($Fields['XMLNODE_NAME'][0] == '2') || ($Fields['XMLNODE_NAME'][0] == '3') || ($Fields['XMLNODE_NAME'][0] == '4') || ($Fields['XMLNODE_NAME'][0] == '5') || ($Fields['XMLNODE_NAME'][0] == '6') || ($Fields['XMLNODE_NAME'][0] == '7') || ($Fields['XMLNODE_NAME'][0] == '8') || ($Fields['XMLNODE_NAME'][0] == '9') || ($Fields['XMLNODE_NAME'][0] == '10')) {
$Fields['XMLNODE_NAME'] = '_' . $Fields['XMLNODE_NAME'];
}
$res = $this->_dbses->Execute( 'SELECT * FROM dynaForm WHERE XMLNODE_NAME="' . $Fields['XMLNODE_NAME'] . '"' );
} else {
if (($Fields['XMLNODE_NAME_OLD'][0] == '1') || ($Fields['XMLNODE_NAME_OLD'][0] == '2') || ($Fields['XMLNODE_NAME_OLD'][0] == '3') || ($Fields['XMLNODE_NAME_OLD'][0] == '4') || ($Fields['XMLNODE_NAME_OLD'][0] == '5') || ($Fields['XMLNODE_NAME_OLD'][0] == '6') || ($Fields['XMLNODE_NAME_OLD'][0] == '7') || ($Fields['XMLNODE_NAME_OLD'][0] == '8') || ($Fields['XMLNODE_NAME_OLD'][0] == '9') || ($Fields['XMLNODE_NAME_OLD'][0] == '10')) {
$Fields['XMLNODE_NAME_OLD'] = '_' . $Fields['XMLNODE_NAME_OLD'];
}
$res = $this->_dbses->Execute( 'SELECT * FROM dynaForm WHERE XMLNODE_NAME="' . $Fields['XMLNODE_NAME_OLD'] . '"' );
}
$this->is_new = ($res->count() == 0);
$this->Fields = $Fields;
unset( $this->Fields['XMLNODE_NAME_OLD'] );
/*
* MPD-10 to create fields that do not appear many attributes, only the main ones?
* The show those who are not white
*/
if ($this->is_new) {
foreach ($this->Fields as $key => $value) {
if ($value == "") {
unset( $this->Fields[$key] );
}
}
} else {
$this->Fields['XMLNODE_NAME'] = $Fields['XMLNODE_NAME_OLD'];
}
// parent::Save();
if (trim($Fields['XMLNODE_VALUE']) != "") {
$attributes['#cdata'] = $Fields['XMLNODE_VALUE'];
}
$aOptions = array();
if(isset($Fields['OPTIONS']) && is_array($Fields['OPTIONS']) ) {
foreach ($Fields['OPTIONS'] as $key => $value) {
$aOptions[] = Array( 'name' => 'option', 'value' => $value['LABEL'],
'attributes' => array('name'=>$value['NAME']) );
}
}
if ($this->is_new) {
// Create a new field
$dynaform->add($Fields['XMLNODE_NAME'], $attributes, $options, $aOptions);
} else {
$dynaform->replace($Fields['XMLNODE_NAME_OLD'], $Fields['XMLNODE_NAME'], $attributes, $options, $aOptions);
}
}
/** /**
* Verify if is New the Field * Verify if is New the Field
* *

View File

@@ -38,7 +38,7 @@ G::LoadClass( 'dynaFormField' );
require_once ('classes/model/Process.php'); require_once ('classes/model/Process.php');
require_once ('classes/model/Dynaform.php'); require_once ('classes/model/Dynaform.php');
G::LoadClass( 'xmlDb' ); G::LoadClass( 'xmlDb' );
G::LoadSystem('dynaformhandler');
/** /**
* *
* @package workflow.engine.classes * @package workflow.engine.classes
@@ -699,30 +699,40 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax
$tmp['Properties'] = $Fields; $tmp['Properties'] = $Fields;
self::_setTmpData( $tmp ); self::_setTmpData( $tmp );
} }
$dynaform = new dynaFormHandler( PATH_DYNAFORM . "{$file}.xml" );
$dbc2 = new DBConnection( PATH_DYNAFORM . $file . '.xml', '', '', '', 'myxml' ); $dbc2 = new DBConnection( PATH_DYNAFORM . $file . '.xml', '', '', '', 'myxml' );
$ses2 = new DBSession( $dbc2 ); $ses2 = new DBSession( $dbc2 );
//if (!isset($Fields['ENABLETEMPLATE'])) $Fields['ENABLETEMPLATE'] ="0"; //if (!isset($Fields['ENABLETEMPLATE'])) $Fields['ENABLETEMPLATE'] ="0";
if (isset( $Fields['WIDTH'] )) {
$ses2->execute( G::replaceDataField( "UPDATE . SET WIDTH = @@WIDTH WHERE XMLNODE_NAME = 'dynaForm' ", $Fields ) );
}
/*if (isset($Fields['ENABLETEMPLATE'])) { /*if (isset($Fields['ENABLETEMPLATE'])) {
$ses2->execute(G::replaceDataField("UPDATE . SET ENABLETEMPLATE = @@ENABLETEMPLATE WHERE XMLNODE_NAME = 'dynaForm' ", $Fields)); $ses2->execute(G::replaceDataField("UPDATE . SET ENABLETEMPLATE = @@ENABLETEMPLATE WHERE XMLNODE_NAME = 'dynaForm' ", $Fields));
}*/ }*/
if (isset( $Fields['DYN_TYPE'] )) { if (isset( $Fields['DYN_TYPE'] )) {
$ses2->execute( G::replaceDataField( "UPDATE . SET TYPE = @@DYN_TYPE WHERE XMLNODE_NAME = 'dynaForm' ", $Fields ) ); //$ses2->execute( G::replaceDataField( "UPDATE . SET TYPE = @@DYN_TYPE WHERE XMLNODE_NAME = 'dynaForm' ", $Fields ) );
$dynaform->modifyHeaderAttribute('type', $Fields['DYN_TYPE']);
}
if (isset( $Fields['WIDTH'] )) {
// $ses2->execute( G::replaceDataField( "UPDATE . SET WIDTH = @@WIDTH WHERE XMLNODE_NAME = 'dynaForm' ", $Fields ) );
$dynaform->modifyHeaderAttribute('width', $Fields['WIDTH']);
//g::pr($dynaform->getHeaderAttribute('width'));
} }
if (isset( $Fields['MODE'] )) { if (isset( $Fields['MODE'] )) {
$ses2->execute( G::replaceDataField( "UPDATE . SET MODE = @@MODE WHERE XMLNODE_NAME = 'dynaForm' ", $Fields ) ); // $ses2->execute( G::replaceDataField( "UPDATE . SET MODE = @@MODE WHERE XMLNODE_NAME = 'dynaForm' ", $Fields ) );
$dynaform->modifyHeaderAttribute('mode', $Fields['MODE']);
} }
if (isset( $Fields['NEXTSTEPSAVE'] )) { if (isset( $Fields['NEXTSTEPSAVE'] )) {
$ses2->execute( G::replaceDataField( "UPDATE . SET NEXTSTEPSAVE = @@NEXTSTEPSAVE WHERE XMLNODE_NAME = 'dynaForm' ", $Fields ) ); //$ses2->execute( G::replaceDataField( "UPDATE . SET NEXTSTEPSAVE = @@NEXTSTEPSAVE WHERE XMLNODE_NAME = 'dynaForm' ", $Fields ) );
$dynaform->modifyHeaderAttribute('nextstepsave', $Fields['NEXTSTEPSAVE']);
} }
if (isset( $Fields['PRINTDYNAFORM'] )) { if (isset( $Fields['PRINTDYNAFORM'] )) {
$ses2->execute( G::replaceDataField( "UPDATE . SET PRINTDYNAFORM = @@PRINTDYNAFORM WHERE XMLNODE_NAME = 'dynaForm' ", $Fields ) ); //$ses2->execute( G::replaceDataField( "UPDATE . SET PRINTDYNAFORM = @@PRINTDYNAFORM WHERE XMLNODE_NAME = 'dynaForm' ", $Fields ) );
$dynaform->modifyHeaderAttribute('printdynaform', $Fields['PRINTDYNAFORM']);
} }
if (isset( $Fields['ADJUSTGRIDSWIDTH'] )) { if (isset( $Fields['ADJUSTGRIDSWIDTH'] )) {
$ses2->execute( G::replaceDataField( "UPDATE . SET ADJUSTGRIDSWIDTH = @@ADJUSTGRIDSWIDTH WHERE XMLNODE_NAME = 'dynaForm' ", $Fields ) ); //$ses2->execute( G::replaceDataField( "UPDATE . SET ADJUSTGRIDSWIDTH = @@ADJUSTGRIDSWIDTH WHERE XMLNODE_NAME = 'dynaForm' ", $Fields ) );
$dynaform->modifyHeaderAttribute('adjustgridswidth', $Fields['ADJUSTGRIDSWIDTH']);
} }
return 0; return 0;
} catch (Exception $e) { } catch (Exception $e) {
return (array) $e; return (array) $e;
@@ -753,9 +763,13 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax
{ {
$file = G::decrypt( $A, URL_KEY ); $file = G::decrypt( $A, URL_KEY );
$value = $value == "1" ? "1" : "0"; $value = $value == "1" ? "1" : "0";
$dbc2 = new DBConnection( PATH_DYNAFORM . $file . '.xml', '', '', '', 'myxml' ); // $dbc2 = new DBConnection( PATH_DYNAFORM . $file . '.xml', '', '', '', 'myxml' );
$ses2 = new DBSession( $dbc2 ); // $ses2 = new DBSession( $dbc2 );
$ses2->execute( "UPDATE . SET ENABLETEMPLATE = '$value'" ); // $ses2->execute( "UPDATE . SET ENABLETEMPLATE = '$value'" );
$dynaform = new dynaFormHandler( PATH_DYNAFORM . "{$file}.xml" );
$dynaform->modifyHeaderAttribute('enabletemplate', $value);
return $value; return $value;
} }

View File

@@ -60,12 +60,12 @@ if (($RBAC_Response=$RBAC->userCanAccess("PM_FACTORY"))!=1) return $RBAC_Respons
else { else {
$_POST['form']['PME_SAVELABEL'] = 0; $_POST['form']['PME_SAVELABEL'] = 0;
} }
$A = $_POST['form']['PME_A'];
if (isset($_POST['form']['PME_SAVELABEL']) if (isset($_POST['form']['PME_SAVELABEL'])
&& isset($_POST['form']['PME_CODE']) && isset($_POST['form']['PME_CODE'])
&& $_POST['form']['PME_TYPE'] === 'javascript'){ && $_POST['form']['PME_TYPE'] === 'javascript'){
$sType = $_POST['form']['PME_TYPE']; $sType = $_POST['form']['PME_TYPE'];
$A = $_POST['form']['PME_A']; // $A = $_POST['form']['PME_A'];
$fieldName = $_POST['form']['PME_XMLNODE_NAME']; $fieldName = $_POST['form']['PME_XMLNODE_NAME'];
$pmeCode = $_POST['form']['PME_CODE']; $pmeCode = $_POST['form']['PME_CODE'];
$_POST['form']['PME_CODE'] = ''; $_POST['form']['PME_CODE'] = '';
@@ -82,9 +82,9 @@ if (($RBAC_Response=$RBAC->userCanAccess("PM_FACTORY"))!=1) return $RBAC_Respons
define('DB_XMLDB_NAME',''); define('DB_XMLDB_NAME','');
define('DB_XMLDB_TYPE','myxml'); define('DB_XMLDB_TYPE','myxml');
if (isset($_POST['form']['PME_XMLNODE_VALUE'])){ // if (isset($_POST['form']['PME_XMLNODE_VALUE'])){
$_POST['form']['PME_XMLNODE_VALUE'] = str_replace("'", "''" , $_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')) { if (file_exists( PATH_XMLFORM . 'dynaforms/fields/' . $type . '.xml')) {
$form=new Form('dynaforms/fields/' . $type , PATH_XMLFORM); $form=new Form('dynaforms/fields/' . $type , PATH_XMLFORM);
@@ -202,7 +202,22 @@ if (($RBAC_Response=$RBAC->userCanAccess("PM_FACTORY"))!=1) return $RBAC_Respons
} }
} }
unset($attributes['VALIDATE_NAME']); unset($attributes['VALIDATE_NAME']);
$fields->Save( $attributes , $labels , $options ); $fields->setFileName(PATH_DYNAFORM . $file . '.xml' );
$FieldAttributes = $attributes;
$FieldAttrib = array();
unset($FieldAttributes['XMLNODE_NAME']);
unset($FieldAttributes['XMLNODE_NAME_OLD']);
unset($FieldAttributes['XMLNODE_VALUE']);
unset($FieldAttributes['BTN_CANCEL']);
unset($FieldAttributes['SAVELABEL']);
foreach ($FieldAttributes as $key => $value) {
if ($value != "") {
$FieldAttrib[strtolower($key)] = $value;
}
}
$fields->saveField($attributes, $FieldAttrib, $labels );
G::LoadClass('xmlDb'); G::LoadClass('xmlDb');
$i = 0; $i = 0;