Merge pull request #868 from hector-cortez/BUG-9286

BUG 9286 Comments are deleted from the XML code for DynaForms SOLVED
This commit is contained in:
julceslauhub
2012-10-26 07:45:05 -07:00
4 changed files with 1260 additions and 1055 deletions

View File

@@ -1,4 +1,5 @@
<?php <?php
/** /**
* class.dynaformhandler.php * class.dynaformhandler.php
* @package gulliver.system * @package gulliver.system
@@ -25,14 +26,14 @@
*/ */
/** /**
* @author Erik Amaru Ortiz <erik@colosa.com> * @author Erik Amaru Ortiz <erik@colosa.com>
* @date Aug 26th, 2009 * @date Aug 26th, 2009
* @description This class is a Dynaform handler for modify directly into file * @description This class is a Dynaform handler for modify directly into file
* @package gulliver.system * @package gulliver.system
*/ */
class dynaFormHandler class dynaFormHandler
{ {
private $xmlfile; private $xmlfile;
private $dom; private $dom;
private $root; private $root;
@@ -43,30 +44,34 @@ class dynaFormHandler
* @param string $file * @param string $file
* @return void * @return void
*/ */
function __construct($file=null) public function __construct($file = null)
{ {
if( !isset($file) ) if (!isset($file)) {
throw new Exception('[Class dynaFormHandler] ERROR: xml file was not set!!'); throw new Exception('[Class dynaFormHandler] ERROR: xml file was not set!!');
}
$this->xmlfile = $file; $this->xmlfile = $file;
$this->load(); $this->load();
} }
function load(){ public function load()
{
$this->dom = new DOMDocument(); $this->dom = new DOMDocument();
$this->dom->preserveWhiteSpace = false; $this->dom->preserveWhiteSpace = false;
$this->dom->formatOutput = true; $this->dom->formatOutput = true;
if( is_file($this->xmlfile) ) { if (is_file($this->xmlfile)) {
if ( @$this->dom->load($this->xmlfile) === true ) { if (@$this->dom->load($this->xmlfile) === true) {
$this->root = $this->dom->firstChild; $this->root = $this->dom->firstChild;
} else
throw new Exception('Error: '.$this->xmlfile.' is a invalid xml file!');
} else { } else {
throw new Exception('[Class dynaFormHandler] ERROR: the ('.$this->xmlfile.') file doesn\'t exits!!'); throw new Exception('Error: ' . $this->xmlfile . ' is a invalid xml file!');
}
} else {
throw new Exception('[Class dynaFormHandler] ERROR: the (' . $this->xmlfile . ') file doesn\'t exits!!');
} }
} }
function reload(){ public function reload()
$this->dom = NULL; {
$this->dom = null;
$this->load(); $this->load();
} }
@@ -75,11 +80,11 @@ class dynaFormHandler
* @access public * @access public
* @return void * @return void
*/ */
function __cloneEmpty() public function __cloneEmpty()
{ {
$xPath = new DOMXPath($this->dom); $xPath = new DOMXPath($this->dom);
$nodeList = $xPath->query('/dynaForm/*'); $nodeList = $xPath->query('/dynaForm/*');
foreach ($nodeList as $domElement){ foreach ($nodeList as $domElement) {
$elements[] = $domElement->nodeName; $elements[] = $domElement->nodeName;
} }
$this->remove($elements); $this->remove($elements);
@@ -92,11 +97,13 @@ class dynaFormHandler
* @param string $op * @param string $op
* @return void * @return void
*/ */
function toString($op='') public function toString($op = '')
{ {
switch($op){ switch ($op) {
case 'html': return htmlentities(file_get_contents($this->xmlfile)); case 'html': return htmlentities(file_get_contents($this->xmlfile));
break;
default: return file_get_contents($this->xmlfile); default: return file_get_contents($this->xmlfile);
break;
} }
} }
@@ -106,7 +113,7 @@ class dynaFormHandler
* @param string $nodename * @param string $nodename
* @return void * @return void
*/ */
function getNode($nodename) public function getNode($nodename)
{ {
return $this->root->getElementsByTagName($nodename)->item(0); return $this->root->getElementsByTagName($nodename)->item(0);
} }
@@ -117,7 +124,8 @@ class dynaFormHandler
* @param object $node * @param object $node
* @return object * @return object
*/ */
function setNode($node){ public function setNode($node)
{
$newnode = $this->root->appendChild($node); $newnode = $this->root->appendChild($node);
$this->save(); $this->save();
return $newnode; return $newnode;
@@ -132,21 +140,27 @@ class dynaFormHandler
* @return void * @return void
*/ */
//attributes (String node-name, Array attributes(atribute-name =>attribute-value, ..., ...), Array childs(child-name=>child-content), Array Child-childs()) //attributes (String node-name, Array attributes(atribute-name =>attribute-value, ..., ...), Array childs(child-name=>child-content), Array Child-childs())
function add($name, $attributes, $childs, $childs_childs=null) public function add($name, $attributes, $childs, $childs_childs = null)
{ {
$newnode = $this->root->appendChild($this->dom->createElement($name)); $newnode = $this->root->appendChild($this->dom->createElement($name));
foreach($attributes as $att_name => $att_value) { 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) {
$newnode->setAttribute($att_name, $att_value); $newnode->setAttribute($att_name, $att_value);
} }
if(is_array($childs)){ if (is_array($childs)) {
foreach($childs as $child_name => $child_text) { foreach ($childs as $child_name => $child_text) {
$newnode_child = $newnode->appendChild($this->dom->createElement($child_name)); $newnode_child = $newnode->appendChild($this->dom->createElement($child_name));
$newnode_child->appendChild($this->dom->createTextNode($child_text)); $newnode_child->appendChild($this->dom->createTextNode($child_text));
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);
} }
} }
@@ -159,6 +173,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
@@ -169,60 +212,94 @@ class dynaFormHandler
* @param array $childs_childs * @param array $childs_childs
* @return void * @return void
*/ */
function replace($replaced, $name, $attributes, $childs=null, $childs_childs=null) public 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) {
if (!is_array($att_value)) {
$newnode->setAttribute($att_name, $att_value); $newnode->setAttribute($att_name, $att_value);
} }
if(is_array($childs)){ }
foreach($childs as $child_name => $child_text) { if (is_array($childs)) {
$newnode_child = $newnode->appendChild($this->dom->createElement($child_name)); foreach ($element->childNodes as $pNode) {
if( is_string($child_text) ) if ($pNode->nodeName != SYS_LANG && $pNode->nodeName != '#cdata-section' && $pNode->nodeName != '#text') {
$newnode_child->appendChild($this->dom->createTextNode($child_text)); $chidNode[] = $this->getChildNode($pNode);
else if( is_array($child_text) && isset($child_text['cdata']) ) $childs[$pNode->nodeName] = $pNode->firstChild->nodeValue;
$newnode_child->appendChild($this->dom->createCDATASection($child_text)); }
}
if($childs_childs != null and is_array($childs_childs)){ foreach ($childs as $child_name => $child_text) {
foreach($childs_childs as $cc) {
$newnode->appendChild($this->dom->createTextNode(" "));
$newnode_child = $newnode->appendChild($this->dom->createElement($child_name));
if (is_string($child_text)) {
$newnode_child->appendChild($this->dom->createTextNode($child_text));
} else {
if (is_array($child_text) && isset($child_text['cdata'])) {
$newnode_child->appendChild($this->dom->createCDATASection($child_text));
}
}
if ($child_name == SYS_LANG) {
if ($childs_childs != null and is_array($childs_childs)) {
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']);
} }
} else if( isset($childs) ){ }
}
}
$newnode->appendChild($this->dom->createTextNode("\n"));
}
} else {
if (isset($childs)) {
$text_node = $childs; $text_node = $childs;
$newnode->appendChild($this->dom->createTextNode($text_node)); $newnode->appendChild($this->dom->createTextNode($text_node));
} }
}
$this->save(); $this->save();
} }
/** /**
* Function save * Function save
* @param string $fname * @param string $fname
* @return void * @return void
*/ */
function save($fname=null) public function save($fname = null)
{ {
if( ! is_writable($this->xmlfile) ) { if (!is_writable($this->xmlfile)) {
throw new Exception("The file {$this->xmlfile} is not writeable!"); throw new Exception("The file {$this->xmlfile} is not writeable!");
} }
if( !isset($fname) ){ if (!isset($fname)) {
$this->dom->save($this->xmlfile); $this->dom->save($this->xmlfile);
} else { } else {
$this->xmlfile = $fname; $this->xmlfile = $fname;
@@ -230,55 +307,60 @@ class dynaFormHandler
} }
} }
/** /**
* Function fixXmlFile * Function fixXmlFile
* @return void * @return void
*/ */
function fixXmlFile() public function fixXmlFile()
{ {
$newxml = ''; $newxml = '';
$content = file($this->xmlfile); $content = file($this->xmlfile);
foreach($content as $line){ foreach ($content as $line) {
if( trim($line) != ''){ if (trim($line) != '') {
$newxml .= $line; $newxml .= $line;
} }
} }
file_put_contents($this->xmlfile, $newxml); file_put_contents($this->xmlfile, $newxml);
} }
/** /**
* Function setHeaderAttribute * Function setHeaderAttribute
* @param string $att_name * @param string $att_name
* @param string $att_value * @param string $att_value
* @return void * @return void
*/ */
function setHeaderAttribute($att_name, $att_value) public function setHeaderAttribute($att_name, $att_value)
{ {
$this->root->setAttribute($att_name, $att_value); $this->root->setAttribute($att_name, $att_value);
$this->save(); $this->save();
} }
/** public function getHeaderAttribute($att_name)
{
return $this->root->getAttribute($att_name);
}
/**
* Function modifyHeaderAttribute * Function modifyHeaderAttribute
* @param string $att_name * @param string $att_name
* @param string $att_new_value * @param string $att_new_value
* @return void * @return void
*/ */
function modifyHeaderAttribute($att_name, $att_new_value) public function modifyHeaderAttribute($att_name, $att_new_value)
{ {
$this->root->removeAttribute($att_name); $this->root->removeAttribute($att_name);
$this->root->setAttribute($att_name, $att_new_value); $this->root->setAttribute($att_name, $att_new_value);
$this->save(); $this->save();
} }
/** /**
* Function updateAttribute * Function updateAttribute
* @param string $node_name * @param string $node_name
* @param string $att_name * @param string $att_name
* @param string $att_new_value * @param string $att_new_value
* @return void * @return void
*/ */
function updateAttribute($node_name, $att_name, $att_new_value) public function updateAttribute($node_name, $att_name, $att_new_value)
{ {
$xpath = new DOMXPath($this->dom); $xpath = new DOMXPath($this->dom);
$nodeList = $xpath->query("/dynaForm/$node_name"); $nodeList = $xpath->query("/dynaForm/$node_name");
@@ -288,26 +370,26 @@ class dynaFormHandler
$this->save(); $this->save();
} }
/** /**
* Function remove * Function remove
* @param string $v * @param string $v
* @return void * @return void
*/ */
function remove($v) public function remove($v)
{ {
if(!is_array($v)){ if (!is_array($v)) {
$av[0] = $v; $av[0] = $v;
} else{ } else {
$av = $v; $av = $v;
} }
foreach($av as $e){ foreach ($av as $e) {
$xnode = $this->root->getElementsByTagName($e)->item(0); $xnode = $this->root->getElementsByTagName($e)->item(0);
if ( $xnode->nodeType == XML_ELEMENT_NODE ) { if ($xnode->nodeType == XML_ELEMENT_NODE) {
$dropednode = $this->root->removeChild($xnode); $dropednode = $this->root->removeChild($xnode);
/*evaluation field aditional routines*/ /* evaluation field aditional routines */
$xpath = new DOMXPath($this->dom); $xpath = new DOMXPath($this->dom);
$nodeList = $xpath->query("/dynaForm/JS_$e"); $nodeList = $xpath->query("/dynaForm/JS_$e");
if($nodeList->length != 0){ if ($nodeList->length != 0) {
$tmp_node = $nodeList->item(0); $tmp_node = $nodeList->item(0);
$this->root->removeChild($tmp_node); $this->root->removeChild($tmp_node);
} }
@@ -318,17 +400,17 @@ class dynaFormHandler
$this->save(); $this->save();
} }
/** /**
* Function nodeExists * Function nodeExists
* @param string $node_name * @param string $node_name
* @return boolean * @return boolean
*/ */
function nodeExists($node_name) public function nodeExists($node_name)
{ {
$xpath = new DOMXPath($this->dom); $xpath = new DOMXPath($this->dom);
$nodeList = $xpath->query("/dynaForm/$node_name"); $nodeList = $xpath->query("/dynaForm/$node_name");
$node = $nodeList->item(0); $node = $nodeList->item(0);
if($nodeList->length != 0){ if ($nodeList->length != 0) {
return true; return true;
} else { } else {
return false; return false;
@@ -341,25 +423,25 @@ class dynaFormHandler
* @param string $selected_node * @param string $selected_node
* @return void * @return void
*/ */
function moveUp($selected_node) public function moveUp($selected_node)
{ {
/*DOMNode DOMNode::insertBefore ( DOMNode $newnode [, DOMNode $refnode ] ) /* DOMNode DOMNode::insertBefore ( DOMNode $newnode [, DOMNode $refnode ] )
This function inserts a new node right before the reference node. If you plan This function inserts a new node right before the reference node. If you plan
to do further modifications on the appended child you must use the returned node. */ to do further modifications on the appended child you must use the returned node. */
$xpath = new DOMXPath($this->dom); $xpath = new DOMXPath($this->dom);
$nodeList = $xpath->query("/dynaForm/*"); $nodeList = $xpath->query("/dynaForm/*");
$flag = false; $flag = false;
for($i = 0; $i < $nodeList->length; $i++) { for ($i = 0; $i < $nodeList->length; $i++) {
$xnode = $nodeList->item($i); $xnode = $nodeList->item($i);
if($selected_node == $xnode->nodeName){ if ($selected_node == $xnode->nodeName) {
//if is a first node move it to final with a circular logic //if is a first node move it to final with a circular logic
if( $flag === false ){ if ($flag === false) {
$removed_node = $this->root->removeChild($xnode); $removed_node = $this->root->removeChild($xnode);
$this->root->appendChild($removed_node); $this->root->appendChild($removed_node);
break; break;
} else { } else {
$removed_node = $this->root->removeChild($xnode); $removed_node = $this->root->removeChild($xnode);
$predecessor_node = $nodeList->item($i-1); $predecessor_node = $nodeList->item($i - 1);
$this->root->insertBefore($removed_node, $predecessor_node); $this->root->insertBefore($removed_node, $predecessor_node);
break; break;
} }
@@ -374,29 +456,29 @@ class dynaFormHandler
* @param string $selected_node * @param string $selected_node
* @return void * @return void
*/ */
function moveDown($selected_node) public function moveDown($selected_node)
{ {
/*DOMNode DOMNode::insertBefore ( DOMNode $newnode [, DOMNode $refnode ] ) /* DOMNode DOMNode::insertBefore ( DOMNode $newnode [, DOMNode $refnode ] )
This function inserts a new node right before the reference node. If you plan This function inserts a new node right before the reference node. If you plan
to do further modifications on the appended child you must use the returned node. */ to do further modifications on the appended child you must use the returned node. */
$xpath = new DOMXPath($this->dom); $xpath = new DOMXPath($this->dom);
$nodeList = $xpath->query("/dynaForm/*"); $nodeList = $xpath->query("/dynaForm/*");
$real_length = $nodeList->length; $real_length = $nodeList->length;
for($i = 0; $i < $nodeList->length; $i++) { for ($i = 0; $i < $nodeList->length; $i++) {
$xnode = $nodeList->item($i); $xnode = $nodeList->item($i);
if($selected_node == $xnode->nodeName){ if ($selected_node == $xnode->nodeName) {
//if is a last node move it to final with a circular logic //if is a last node move it to final with a circular logic
if( ($i+1) == $real_length){ if (($i + 1) == $real_length) {
if($real_length != 1){ if ($real_length != 1) {
$first_node = $nodeList->item(0); $first_node = $nodeList->item(0);
$removed_node = $this->root->removeChild($xnode); $removed_node = $this->root->removeChild($xnode);
$this->root->insertBefore($removed_node, $first_node); $this->root->insertBefore($removed_node, $first_node);
} }
break; break;
} else { } else {
if( ($i+3) <= $real_length ){ if (($i + 3) <= $real_length) {
$removed_node = $this->root->removeChild($xnode); $removed_node = $this->root->removeChild($xnode);
$predecessor_node = $nodeList->item($i+2); $predecessor_node = $nodeList->item($i + 2);
$this->root->insertBefore($removed_node, $predecessor_node); $this->root->insertBefore($removed_node, $predecessor_node);
break; break;
} else { } else {
@@ -415,26 +497,26 @@ class dynaFormHandler
* @param array $aFilter * @param array $aFilter
* @return array * @return array
*/ */
function getFields( $aFilter = Array() ) public function getFields($aFilter = Array())
{ {
$xpath = new DOMXPath($this->dom); $xpath = new DOMXPath($this->dom);
$nodeList = $xpath->query("/dynaForm/*"); $nodeList = $xpath->query("/dynaForm/*");
$aList = Array(); $aList = Array();
for($i = 0; $i < $nodeList->length; $i++) { for ($i = 0; $i < $nodeList->length; $i++) {
$xnode = $nodeList->item($i); $xnode = $nodeList->item($i);
if( is_array($aFilter) && sizeof($aFilter) > 0 ){ if (is_array($aFilter) && sizeof($aFilter) > 0) {
if( isset($aFilter['IN']) ){ if (isset($aFilter['IN'])) {
if( isset($aFilter['NOT_IN']) ){ if (isset($aFilter['NOT_IN'])) {
if( in_array($xnode->nodeName, $aFilter['IN']) && !in_array($xnode->nodeName, $aFilter['NOT_IN']) ){ if (in_array($xnode->nodeName, $aFilter['IN']) && !in_array($xnode->nodeName, $aFilter['NOT_IN'])) {
array_push($aList, $xnode); array_push($aList, $xnode);
} }
} else { } else {
if( in_array($xnode->nodeName, $aFilter['IN']) ){ if (in_array($xnode->nodeName, $aFilter['IN'])) {
array_push($aList, $xnode); array_push($aList, $xnode);
} }
} }
} else if( isset($aFilter['NOT_IN']) ){ } else if (isset($aFilter['NOT_IN'])) {
if( !in_array($xnode->nodeName, $aFilter['NOT_IN']) ){ if (!in_array($xnode->nodeName, $aFilter['NOT_IN'])) {
array_push($aList, $xnode); array_push($aList, $xnode);
} }
} else { } else {
@@ -452,46 +534,46 @@ class dynaFormHandler
* @param array $aFilter * @param array $aFilter
* @return array * @return array
*/ */
function getFieldNames( $aFilter = Array() ) public function getFieldNames($aFilter = Array())
{ {
$aList = $this->getFields($aFilter); $aList = $this->getFields($aFilter);
$aFieldNames = Array(); $aFieldNames = Array();
foreach( $aList as $item ){ foreach ($aList as $item) {
array_push($aFieldNames, $item->nodeName); array_push($aFieldNames, $item->nodeName);
} }
return $aFieldNames; return $aFieldNames;
} }
//
function addChilds($name, $childs, $childs_childs=null) public function addChilds($name, $childs, $childs_childs = null)
{ {
//
$xpath = new DOMXPath($this->dom); $xpath = new DOMXPath($this->dom);
$nodeList = @$xpath->query("/dynaForm/$name"); $nodeList = @$xpath->query("/dynaForm/$name");
if( ! $nodeList ){ if (!$nodeList) {
throw new Exception("Error trying get the field dynaform $name, maybe it doesn't exist in {$this->xmlfile}"); throw new Exception("Error trying get the field dynaform $name, maybe it doesn't exist in {$this->xmlfile}");
} }
if( $nodeList->length == 0 ) { if ($nodeList->length == 0) {
$element = $this->root->appendChild($this->dom->createElement($name)); $element = $this->root->appendChild($this->dom->createElement($name));
} else } else
$element = $this->root->getElementsByTagName($name)->item(0); $element = $this->root->getElementsByTagName($name)->item(0);
if( is_array($childs) ) { if (is_array($childs)) {
foreach( $childs as $child_name => $child_text ) { foreach ($childs as $child_name => $child_text) {
$nodeList = $xpath->query("/dynaForm/$name/$child_name"); $nodeList = $xpath->query("/dynaForm/$name/$child_name");
if( $nodeList->length == 0 ){ //the node doesn't exist if ($nodeList->length == 0) {
//the node doesn't exist
//$newnode_child //$newnode_child
$childNode = $element->appendChild($this->dom->createElement($child_name)); $childNode = $element->appendChild($this->dom->createElement($child_name));
$childNode->appendChild($this->dom->createCDATASection($child_text)); $childNode->appendChild($this->dom->createCDATASection($child_text));
} else { // the node already exists } else {
// the node already exists
//update its value //update its value
$childNode = $element->getElementsByTagName($child_name)->item(0); $childNode = $element->getElementsByTagName($child_name)->item(0);
// if ($child_text !== null) {
if($child_text !== NULL){
$xnode = $this->dom->createElement($childNode->nodeName); $xnode = $this->dom->createElement($childNode->nodeName);
$xnode->appendChild($this->dom->createCDATASection($child_text)); $xnode->appendChild($this->dom->createCDATASection($child_text));
@@ -500,11 +582,11 @@ class dynaFormHandler
} }
} }
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) {
$ccnode = $childNode->appendChild($this->dom->createElement($cc['name'])); $ccnode = $childNode->appendChild($this->dom->createElement($cc['name']));
$ccnode->appendChild($this->dom->createCDATASection($cc['value'])); $ccnode->appendChild($this->dom->createCDATASection($cc['value']));
foreach($cc['attributes'] as $cc_att_name => $cc_att_value) { foreach ($cc['attributes'] as $cc_att_name => $cc_att_value) {
$ccnode->setAttribute($cc_att_name, $cc_att_value); $ccnode->setAttribute($cc_att_name, $cc_att_value);
} }
} }
@@ -517,27 +599,28 @@ class dynaFormHandler
$this->save(); $this->save();
} }
public function addOrUpdateChild($xnode, $childName, $childValue, $childAttributes)
function addOrUpdateChild($xnode, $childName, $childValue, $childAttributes){ {
$newNode = $this->dom->createElement($childName); $newNode = $this->dom->createElement($childName);
$newNode->appendChild($this->dom->createCDATASection($childValue)); $newNode->appendChild($this->dom->createCDATASection($childValue));
foreach($childAttributes as $attName => $attValue) { foreach ($childAttributes as $attName => $attValue) {
$newNode->setAttribute($attName, $attValue); $newNode->setAttribute($attName, $attValue);
} }
if( $xnode->hasChildNodes() ) { if ($xnode->hasChildNodes()) {
foreach($xnode->childNodes as $cnode) { foreach ($xnode->childNodes as $cnode) {
if( $cnode->nodeName == $childName ) { if ($cnode->nodeName == $childName) {
$xnode->replaceChild($newNode, $cnode); $xnode->replaceChild($newNode, $cnode);
break; break;
} }
} }
} else } else {
$xnode->appendChild($newNode); $xnode->appendChild($newNode);
} }
}
function getArray($node, $attributes = null) public function getArray($node, $attributes = null)
{ {
$array = false; $array = false;
$array['__nodeName__'] = $node->nodeName; $array['__nodeName__'] = $node->nodeName;
@@ -545,11 +628,12 @@ class dynaFormHandler
$array['__nodeText__'] = trim((string) $text); $array['__nodeText__'] = trim((string) $text);
if ($node->hasAttributes()) { if ($node->hasAttributes()) {
if( isset($attributes) ) { if (isset($attributes)) {
foreach ($attributes as $attr) { foreach ($attributes as $attr) {
if( $node->hasAttribute($attr) ) if ($node->hasAttribute($attr)) {
$array[$attr] = $node->getAttribute($attr); $array[$attr] = $node->getAttribute($attr);
} }
}
} else { } else {
foreach ($node->attributes as $attr) { foreach ($node->attributes as $attr) {
$array[$attr->nodeName] = $attr->nodeValue; $array[$attr->nodeName] = $attr->nodeValue;
@@ -558,9 +642,9 @@ class dynaFormHandler
} }
if ($node->hasChildNodes()) { if ($node->hasChildNodes()) {
if ($node->childNodes->length == 0) if ($node->childNodes->length == 0) {
$return; $return;
else { } else {
foreach ($node->childNodes as $childNode) { foreach ($node->childNodes as $childNode) {
$childNode->normalize(); $childNode->normalize();
//if ($childNode->nodeType == XML_TEXT_NODE || $childNode->nodeType == XML_CDATA_SECTION_NODE) { //if ($childNode->nodeType == XML_TEXT_NODE || $childNode->nodeType == XML_CDATA_SECTION_NODE) {
@@ -578,3 +662,4 @@ class dynaFormHandler
return $array; return $array;
} }
} }

View File

@@ -1,4 +1,5 @@
<?php <?php
/** /**
* class.dynaFormField.php * class.dynaFormField.php
* *
@@ -24,8 +25,8 @@
* Coral Gables, FL, 33134, USA, or email info@colosa.com. * Coral Gables, FL, 33134, USA, or email info@colosa.com.
* *
*/ */
G::LoadClass('xmlDb');
G::LoadClass( 'xmlDb' ); G::LoadSystem('dynaformhandler');
/** /**
* Dynaform Field - DynaformField class * Dynaform Field - DynaformField class
@@ -35,16 +36,28 @@ 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
* *
* @param string $objConnection * @param string $objConnection
* @return void * @return void
*/ */
function SetTo ($objConnection) public function SetTo($objConnection)
{ {
DBTable::SetTo( $objConnection, 'dynaForm', array ('XMLNODE_NAME' DBTable::SetTo($objConnection, 'dynaForm', array('XMLNODE_NAME'
) ); ));
} }
/** /**
@@ -53,13 +66,13 @@ class DynaFormField extends DBTable
* @param string $sUID * @param string $sUID
* @return void * @return void
*/ */
function Load ($sUID) public function Load($sUID)
{ {
parent::Load( $sUID ); parent::Load($sUID);
if (is_array( $this->Fields )) { if (is_array($this->Fields)) {
foreach ($this->Fields as $name => $value) { foreach ($this->Fields as $name => $value) {
if (strcasecmp( $name, 'dependentfields' ) == 0) { if (strcasecmp($name, 'dependentfields') == 0) {
$this->Fields[$name] = explode( ',', $value ); $this->Fields[$name] = explode(',', $value);
} }
} }
} }
@@ -71,7 +84,7 @@ class DynaFormField extends DBTable
* @param string $uid * @param string $uid
* @return void * @return void
*/ */
function Delete ($uid) public function Delete($uid)
{ {
$this->Fields['XMLNODE_NAME'] = $uid; $this->Fields['XMLNODE_NAME'] = $uid;
parent::Delete(); parent::Delete();
@@ -85,96 +98,153 @@ class DynaFormField extends DBTable
* @param array $options * @param array $options
* @return void * @return void
*/ */
function Save ($Fields, $labels = array(), $options = array()) public function Save($Fields, $labels = array(), $options = array())
{ {
if ($Fields['TYPE'] === 'javascript') { if ($Fields['TYPE'] === 'javascript') {
$Fields['XMLNODE_VALUE'] = $Fields['CODE']; $Fields['XMLNODE_VALUE'] = $Fields['CODE'];
unset( $Fields['CODE'] ); unset($Fields['CODE']);
$labels = array (); $labels = array();
} }
if ($Fields['XMLNODE_NAME_OLD'] == '') { 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')) { 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']; $Fields['XMLNODE_NAME'] = '_' . $Fields['XMLNODE_NAME'];
} }
$res = $this->_dbses->Execute( 'SELECT * FROM dynaForm WHERE XMLNODE_NAME="' . $Fields['XMLNODE_NAME'] . '"' ); $res = $this->_dbses->Execute('SELECT * FROM dynaForm WHERE XMLNODE_NAME="' . $Fields['XMLNODE_NAME'] . '"');
} else { } 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')) { 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']; $Fields['XMLNODE_NAME_OLD'] = '_' . $Fields['XMLNODE_NAME_OLD'];
} }
$res = $this->_dbses->Execute( 'SELECT * FROM dynaForm WHERE XMLNODE_NAME="' . $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->is_new = ($res->count() == 0);
$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 == "") {
unset( $this->Fields[$key] ); unset($this->Fields[$key]);
}
} }
} else { } else {
$this->Fields['XMLNODE_NAME'] = $Fields['XMLNODE_NAME_OLD']; $this->Fields['XMLNODE_NAME'] = $Fields['XMLNODE_NAME_OLD'];
} }
/*$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".'")'); */
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])) {
foreach ($options[$lang] as $option => $text) { foreach ($options[$lang] as $option => $text) {
$res = $this->_dbses->Execute( 'INSERT INTO dynaForm.' . $Fields['XMLNODE_NAME'] . '.' . $lang . ' (XMLNODE_NAME,XMLNODE_VALUE,XMLNODE_TYPE) ' . 'VALUES ("","' . " " . '","cdata")' ); $res = $this->_dbses->Execute('INSERT INTO dynaForm.' . $Fields['XMLNODE_NAME'] . '.' . $lang . ' (XMLNODE_NAME,XMLNODE_VALUE,XMLNODE_TYPE) ' . 'VALUES ("","' . " " . '","cdata")');
$res = $this->_dbses->Execute( 'INSERT INTO dynaForm.' . $Fields['XMLNODE_NAME'] . '.' . $lang . ' (XMLNODE_NAME,XMLNODE_VALUE,name) ' . 'VALUES ("option","' . str_replace( '"', '""', $text ) . '","' . str_replace( '"', '""', $option ) . '")' ); $res = $this->_dbses->Execute('INSERT INTO dynaForm.' . $Fields['XMLNODE_NAME'] . '.' . $lang . ' (XMLNODE_NAME,XMLNODE_VALUE,name) ' . 'VALUES ("option","' . str_replace('"', '""', $text) . '","' . str_replace('"', '""', $option) . '")');
$res = $this->_dbses->Execute( 'INSERT INTO dynaForm.' . $Fields['XMLNODE_NAME'] . '.' . $lang . ' (XMLNODE_NAME,XMLNODE_VALUE,XMLNODE_TYPE) ' . 'VALUES ("","' . "\n " . '","cdata")' ); $res = $this->_dbses->Execute('INSERT INTO dynaForm.' . $Fields['XMLNODE_NAME'] . '.' . $lang . ' (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,XMLNODE_TYPE) ' . 'VALUES ("","' . "\n" . '","cdata")');
} }
$res = $this->_dbses->Execute( 'INSERT INTO dynaForm' . ' (XMLNODE_TYPE,XMLNODE_VALUE)' . ' VALUES ("cdata", "' . "\n" . '")' ); $res = $this->_dbses->Execute('INSERT INTO dynaForm' . ' (XMLNODE_TYPE,XMLNODE_VALUE)' . ' VALUES ("cdata", "' . "\n" . '")');
} else { } else {
/* /*
* Update an existing field. * Update an existing field.
*/ */
$this->_dbses->Execute( 'UPDATE dynaForm SET XMLNODE_NAME = "' . $Fields['XMLNODE_NAME'] . '" WHERE XMLNODE_NAME = "' . $Fields['XMLNODE_NAME_OLD'] . '"' ); $this->_dbses->Execute('UPDATE dynaForm SET XMLNODE_NAME = "' . $Fields['XMLNODE_NAME'] . '" WHERE XMLNODE_NAME = "' . $Fields['XMLNODE_NAME_OLD'] . '"');
foreach ($labels as $lang => $value) { foreach ($labels as $lang => $value) {
$res = $this->_dbses->Execute( 'SELECT * FROM dynaForm.' . $Fields['XMLNODE_NAME'] . ' WHERE XMLNODE_NAME ="' . $lang . '"' ); $res = $this->_dbses->Execute('SELECT * FROM dynaForm.' . $Fields['XMLNODE_NAME'] . ' WHERE XMLNODE_NAME ="' . $lang . '"');
if ($res->count() > 0) { if ($res->count() > 0) {
$res = $this->_dbses->Execute( 'UPDATE dynaForm.' . $Fields['XMLNODE_NAME'] . ' SET XMLNODE_VALUE = ' . '"' . str_replace( '"', '""', $value ) . '" WHERE XMLNODE_NAME ="' . $lang . '"' ); $res = $this->_dbses->Execute('UPDATE dynaForm.' . $Fields['XMLNODE_NAME'] . ' SET XMLNODE_VALUE = ' . '"' . str_replace('"', '""', $value) . '" WHERE XMLNODE_NAME ="' . $lang . '"');
} else { } else {
$res = $this->_dbses->Execute( 'INSERT INTO dynaForm.' . $Fields['XMLNODE_NAME'] . ' (XMLNODE_NAME,XMLNODE_VALUE) ' . 'VALUES ("' . $lang . '","' . str_replace( '"', '""', $value ) . '")' ); $res = $this->_dbses->Execute('INSERT INTO dynaForm.' . $Fields['XMLNODE_NAME'] . ' (XMLNODE_NAME,XMLNODE_VALUE) ' . 'VALUES ("' . $lang . '","' . str_replace('"', '""', $value) . '")');
} }
if (isset( $options[$lang] )) { if (isset($options[$lang])) {
$res = $this->_dbses->Execute( 'DELETE FROM dynaForm.' . $Fields['XMLNODE_NAME'] . '.' . $lang . ' WHERE 1' ); $res = $this->_dbses->Execute('DELETE FROM dynaForm.' . $Fields['XMLNODE_NAME'] . '.' . $lang . ' WHERE 1');
foreach ($options[$lang] as $option => $text) { foreach ($options[$lang] as $option => $text) {
$res = $this->_dbses->Execute( 'INSERT INTO dynaForm.' . $Fields['XMLNODE_NAME'] . '.' . $lang . ' (XMLNODE_NAME,XMLNODE_VALUE,name) ' . 'VALUES ("option","' . str_replace( '"', '""', $text ) . '","' . str_replace( '"', '""', $option ) . '")' ); $res = $this->_dbses->Execute('INSERT INTO dynaForm.' . $Fields['XMLNODE_NAME'] . '.' . $lang . ' (XMLNODE_NAME,XMLNODE_VALUE,name) ' . 'VALUES ("option","' . str_replace('"', '""', $text) . '","' . str_replace('"', '""', $option) . '")');
} }
} }
} }
} }
} }
public 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
* *
* @return array * @return array
*/ */
function isNew () public function isNew()
{ {
$res = $this->_dbses->Execute( 'SELECT * FROM dynaForm WHERE XMLNODE_NAME="' . $this->Fields['XMLNODE_NAME'] . '"' ); $res = $this->_dbses->Execute('SELECT * FROM dynaForm WHERE XMLNODE_NAME="' . $this->Fields['XMLNODE_NAME'] . '"');
return ($res->count() == 0); return ($res->count() == 0);
} }
} }
?>

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,5 @@
<?php <?php
//print_r( $_POST); die; //print_r( $_POST); die;
/** /**
* fields_Save.php * fields_Save.php
@@ -25,90 +26,95 @@
*/ */
G::LoadClass('dynaformEditor'); G::LoadClass('dynaformEditor');
if (($RBAC_Response=$RBAC->userCanAccess("PM_FACTORY"))!=1) return $RBAC_Response; if (($RBAC_Response = $RBAC->userCanAccess("PM_FACTORY")) != 1) {
return $RBAC_Response;
}
//G::genericForceLogin( 'WF_MYINFO' , 'login/noViewPage', $urlLogin = 'login/login' ); //G::genericForceLogin( 'WF_MYINFO' , 'login/noViewPage', $urlLogin = 'login/login' );
G::LoadClass('dynaFormField'); G::LoadClass('dynaFormField');
$type=strtolower($_POST['form']['PME_TYPE']); $type = strtolower($_POST['form']['PME_TYPE']);
if (!(isset($_POST['form']['PME_A']) && $_POST['form']['PME_A']!=='')) return; if (!(isset($_POST['form']['PME_A']) && $_POST['form']['PME_A'] !== '')) {
return;
}
if (isset($_POST['form']['PME_REQUIRED'])) { if (isset($_POST['form']['PME_REQUIRED'])) {
if ($_POST['form']['PME_REQUIRED'] == '') { if ($_POST['form']['PME_REQUIRED'] == '') {
$_POST['form']['PME_REQUIRED'] = 0; $_POST['form']['PME_REQUIRED'] = 0;
} }
} } else {
else {
$_POST['form']['PME_REQUIRED'] = 0; $_POST['form']['PME_REQUIRED'] = 0;
} }
if (isset($_POST['form']['PME_READONLY'])) { if (isset($_POST['form']['PME_READONLY'])) {
if ($_POST['form']['PME_READONLY'] == '') { if ($_POST['form']['PME_READONLY'] == '') {
$_POST['form']['PME_READONLY'] = 0; $_POST['form']['PME_READONLY'] = 0;
} }
} } else {
else {
$_POST['form']['PME_READONLY'] = 0; $_POST['form']['PME_READONLY'] = 0;
} }
if (isset($_POST['form']['PME_SAVELABEL'])) { if (isset($_POST['form']['PME_SAVELABEL'])) {
if ($_POST['form']['PME_SAVELABEL'] == '') { if ($_POST['form']['PME_SAVELABEL'] == '') {
$_POST['form']['PME_SAVELABEL'] = 0; $_POST['form']['PME_SAVELABEL'] = 0;
} }
} } 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'] = '';
// $pmeCode = str_replace("'", "''", $pmeCode); // $pmeCode = str_replace("'", "''", $pmeCode);
// $pmeCode = str_replace('"', '""', $pmeCode); // $pmeCode = str_replace('"', '""', $pmeCode);
// $pmeCode = preg_replace("/\)\s*\n/", ") //\n", $pmeCode); // $pmeCode = preg_replace("/\)\s*\n/", ") //\n", $pmeCode);
// $_POST['form']['PME_CODE'] = $pmeCode; // $_POST['form']['PME_CODE'] = $pmeCode;
} }
$file = G::decrypt( $_POST['form']['PME_A'] , URL_KEY ); $file = G::decrypt($_POST['form']['PME_A'], URL_KEY);
define('DB_XMLDB_HOST', PATH_DYNAFORM . $file . '.xml' ); define('DB_XMLDB_HOST', PATH_DYNAFORM . $file . '.xml');
define('DB_XMLDB_USER',''); define('DB_XMLDB_USER', '');
define('DB_XMLDB_PASS',''); define('DB_XMLDB_PASS', '');
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);
//TODO: Verify why validatePost removes PME_XMLGRID. //TODO: Verify why validatePost removes PME_XMLGRID.
$isGrid=isset($_POST['form']['PME_XMLGRID']); $isGrid = isset($_POST['form']['PME_XMLGRID']);
if ($isGrid) $xmlGrid=$_POST['form']['PME_XMLGRID']; if ($isGrid) {
$xmlGrid = $_POST['form']['PME_XMLGRID'];
}
//$form->validatePost(); //$form->validatePost();
if ($isGrid) $_POST['form']['PME_XMLGRID']=$xmlGrid; if ($isGrid) {
if ($type==='checkbox') { $_POST['form']['PME_XMLGRID'] = $xmlGrid;
}
if ($type === 'checkbox') {
// added by Gustavo Cruz // added by Gustavo Cruz
if ($_POST['form']['PME_DEFAULTVALUE']==="1") { if ($_POST['form']['PME_DEFAULTVALUE'] === "1") {
$_POST['form']['PME_DEFAULTVALUE']=$_POST['form']['PME_VALUE']; $_POST['form']['PME_DEFAULTVALUE'] = $_POST['form']['PME_VALUE'];
} else { } else {
$_POST['form']['PME_DEFAULTVALUE']=$_POST['form']['PME_FALSEVALUE']; $_POST['form']['PME_DEFAULTVALUE'] = $_POST['form']['PME_FALSEVALUE'];
} }
// end added code // end added code
// verify why $form->fields['PME_DEFAULTVALUE']->value doesn't capture the value 1 // verify why $form->fields['PME_DEFAULTVALUE']->value doesn't capture the value 1
// if ($_POST['form']['PME_DEFAULTVALUE']===$form->fields['PME_DEFAULTVALUE']->value) { // if ($_POST['form']['PME_DEFAULTVALUE']===$form->fields['PME_DEFAULTVALUE']->value) {
// $_POST['form']['PME_DEFAULTVALUE']=$_POST['form']['PME_VALUE']; // $_POST['form']['PME_DEFAULTVALUE']=$_POST['form']['PME_VALUE'];
// } else { // } else {
// $_POST['form']['PME_DEFAULTVALUE']=$_POST['form']['PME_FALSEVALUE']; // $_POST['form']['PME_DEFAULTVALUE']=$_POST['form']['PME_FALSEVALUE'];
// } // }
} }
if ($type==='grid') { if ($type === 'grid') {
if (!isset($_POST['form']['PME_ADDROW'])) { if (!isset($_POST['form']['PME_ADDROW'])) {
$_POST['form']['PME_ADDROW'] = '0'; $_POST['form']['PME_ADDROW'] = '0';
} }
@@ -116,65 +122,72 @@ if (($RBAC_Response=$RBAC->userCanAccess("PM_FACTORY"))!=1) return $RBAC_Respons
$_POST['form']['PME_DELETEROW'] = '0'; $_POST['form']['PME_DELETEROW'] = '0';
} }
} }
if ($type==='dropdown' || $type==='listbox' ) { if ($type === 'dropdown' || $type === 'listbox') {
if(isset($_POST['form']['PME_OPTIONS'][1])){ if (isset($_POST['form']['PME_OPTIONS'][1])) {
if($_POST['form']['PME_OPTIONS']['1']['NAME'] === "" && if ($_POST['form']['PME_OPTIONS']['1']['NAME'] === "" &&
$_POST['form']['PME_OPTIONS']['1']['LABEL'] === ""){ $_POST['form']['PME_OPTIONS']['1']['LABEL'] === "") {
unset($_POST['form']['PME_OPTIONS']); unset($_POST['form']['PME_OPTIONS']);
} }
} }
} }
}
foreach ($_POST['form'] as $key => $value) {
if (substr($key, 0, 4) === 'PME_') {
$res[substr($key, 4)] = $value;
} else {
$res[$key] = $value;
} }
foreach($_POST['form'] as $key => $value){ }
if (substr($key,0,4)==='PME_') $_POST['form'] = $res;
$res[substr($key,4)]=$value;
else
$res[$key]=$value;
}
$_POST['form']=$res;
$dbc = new DBConnection( PATH_DYNAFORM . $file . '.xml' ,'','','','myxml' ); $dbc = new DBConnection(PATH_DYNAFORM . $file . '.xml', '', '', '', 'myxml');
$ses = new DBSession($dbc); $ses = new DBSession($dbc);
$fields = new DynaFormField( $dbc ); $fields = new DynaFormField($dbc);
if ($_POST['form']['XMLNODE_NAME']==='') return; if ($_POST['form']['XMLNODE_NAME'] === '') {
return;
}
$attributes = $_POST['form']; $attributes = $_POST['form'];
if (isset($attributes['HINT'])) { if (isset($attributes['HINT'])) {
$attributes['HINT'] = addslashes($attributes['HINT']); $attributes['HINT'] = addslashes($attributes['HINT']);
$attributes['HINT'] = htmlspecialchars($attributes['HINT'], ENT_QUOTES, "UTF-8"); $attributes['HINT'] = htmlspecialchars($attributes['HINT'], ENT_QUOTES, "UTF-8");
} }
if (isset($attributes['CODE'])) $attributes['XMLNODE_VALUE'] = ($attributes['CODE']); if (isset($attributes['CODE'])) {
$attributes['XMLNODE_VALUE'] = ($attributes['CODE']);
}
$labels = array(); $labels = array();
if (isset($attributes['LABEL'])) $labels = array ( SYS_LANG => $attributes['LABEL'] ); if (isset($attributes['LABEL'])) {
$labels = array(SYS_LANG => $attributes['LABEL']);
}
unset($attributes['A']); unset($attributes['A']);
unset($attributes['ACCEPT']); unset($attributes['ACCEPT']);
unset($attributes['LABEL']); unset($attributes['LABEL']);
unset($attributes['PRO_UID']); unset($attributes['PRO_UID']);
$options = NULL; $options = null;
foreach($attributes as $key => $value ) { foreach ($attributes as $key => $value) {
if ($key==='OPTIONS') { if ($key === 'OPTIONS') {
if (is_array($value)){ if (is_array($value)) {
if (is_array(reset($value))) { if (is_array(reset($value))) {
$langs = array(); $langs = array();
$options = array(); $options = array();
$langs[] = SYS_LANG; $langs[] = SYS_LANG;
$options[SYS_LANG]=array(); $options[SYS_LANG] = array();
foreach( $value as $row ) { foreach ($value as $row) {
foreach( $langs as $lang ) { foreach ($langs as $lang) {
$LANG = strtoupper($lang); $LANG = strtoupper($lang);
if (isset($row['LABEL'])) if (isset($row['LABEL'])) {
$options[$lang][$row['NAME']]=$row['LABEL']; $options[$lang][$row['NAME']] = $row['LABEL'];
} }
} }
/*$first = reset($value); }
/* $first = reset($value);
foreach( $first as $optKey => $optValue ) { foreach( $first as $optKey => $optValue ) {
if (substr($optKey,0,6)==='LABEL_') { if (substr($optKey,0,6)==='LABEL_') {
$langs[]=strtolower(substr($optKey,6)); $langs[]=strtolower(substr($optKey,6));
@@ -187,50 +200,65 @@ if (($RBAC_Response=$RBAC->userCanAccess("PM_FACTORY"))!=1) return $RBAC_Respons
if (isset($row['LABEL_'.$LANG])) if (isset($row['LABEL_'.$LANG]))
$options[$lang][$row['NAME']]=$row['LABEL_'.$LANG]; $options[$lang][$row['NAME']]=$row['LABEL_'.$LANG];
} }
}*/ } */
} }
} }
} else { } else {
if (is_array($value)){ if (is_array($value)) {
//Is a list: //Is a list:
if (is_string(reset($value))) { if (is_string(reset($value))) {
$attributes[$key] = implode(',',$value); $attributes[$key] = implode(',', $value);
} else { } else {
//Is a grid. //Is a grid.
} }
} }
} }
} }
unset($attributes['VALIDATE_NAME']); unset($attributes['VALIDATE_NAME']);
$fields->Save( $attributes , $labels , $options ); $fields->setFileName(PATH_DYNAFORM . $file . '.xml');
G::LoadClass('xmlDb'); $FieldAttributes = $attributes;
$i = 0; $FieldAttrib = array();
$aFields = array(); unset($FieldAttributes['XMLNODE_NAME']);
$aFields[] = array('XMLNODE_NAME' => 'char', 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');
$i = 0;
$aFields = array();
$aFields[] = array('XMLNODE_NAME' => 'char',
'TYPE' => 'char', 'TYPE' => 'char',
'UP' => 'char', 'UP' => 'char',
'DOWN' => 'char', 'DOWN' => 'char',
'row__' => 'integer'); 'row__' => 'integer');
$oSession = new DBSession(new DBConnection(PATH_DYNAFORM . $file . '.xml', '', '', '', 'myxml')); $oSession = new DBSession(new DBConnection(PATH_DYNAFORM . $file . '.xml', '', '', '', 'myxml'));
$oDataset = $oSession->Execute('SELECT * FROM dynaForm WHERE NOT( XMLNODE_NAME = "" )'); $oDataset = $oSession->Execute('SELECT * FROM dynaForm WHERE NOT( XMLNODE_NAME = "" )');
$iMaximun = $oDataset->count(); $iMaximun = $oDataset->count();
while ($aRow = $oDataset->Read()) { while ($aRow = $oDataset->Read()) {
$aFields[] = array('XMLNODE_NAME' => $aRow['XMLNODE_NAME'], $aFields[] = array('XMLNODE_NAME' => $aRow['XMLNODE_NAME'],
'TYPE' => $aRow['TYPE'], 'TYPE' => $aRow['TYPE'],
'UP' => ($i > 0 ? G::LoadTranslation('ID_UP') : ''), 'UP' => ($i > 0 ? G::LoadTranslation('ID_UP') : ''),
'DOWN' => ($i < $iMaximun-1 ? G::LoadTranslation('ID_DOWN') : ''), 'DOWN' => ($i < $iMaximun - 1 ? G::LoadTranslation('ID_DOWN') : ''),
'row__' => ($i + 1)); 'row__' => ($i + 1));
$i++; $i++;
} }
global $_DBArray; global $_DBArray;
$_DBArray['fields'] = $aFields; $_DBArray['fields'] = $aFields;
$_SESSION['_DBArray'] = $_DBArray; $_SESSION['_DBArray'] = $_DBArray;
// Additions to javascript // Additions to javascript
if(isset($sType) && $sType === 'javascript'){ if (isset($sType) && $sType === 'javascript') {
$sCode = urlencode($pmeCode); $sCode = urlencode($pmeCode);
$editor = new dynaformEditorAjax($_POST); $editor = new dynaformEditorAjax($_POST);
$editor->set_javascript($A, $fieldName, $sCode); $editor->set_javascript($A, $fieldName, $sCode);
} }
?>