From f62edeec83fad4c4e63a792b289b0d3dd763e759 Mon Sep 17 00:00:00 2001 From: Hector Cortez Date: Thu, 25 Oct 2012 16:08:30 -0400 Subject: [PATCH] BUG 9286 Comments are deleted from the XML code for DynaForms SOLVED - ProcessMaker deletes comments from XML code. - Adjustment in the standarized Code. --- gulliver/system/class.dynaformhandler.php | 1111 +++++++++-------- .../engine/classes/class.dynaFormField.php | 212 ++-- .../engine/classes/class.dynaformEditor.php | 638 +++++----- .../engine/methods/dynaforms/fields_Save.php | 355 +++--- 4 files changed, 1178 insertions(+), 1138 deletions(-) diff --git a/gulliver/system/class.dynaformhandler.php b/gulliver/system/class.dynaformhandler.php index d9dec1a3b..d28fa53b2 100755 --- a/gulliver/system/class.dynaformhandler.php +++ b/gulliver/system/class.dynaformhandler.php @@ -1,4 +1,5 @@ -* @date Aug 26th, 2009 -* @description This class is a Dynaform handler for modify directly into file -* @package gulliver.system -*/ - + * @author Erik Amaru Ortiz + * @date Aug 26th, 2009 + * @description This class is a Dynaform handler for modify directly into file + * @package gulliver.system + */ class dynaFormHandler { - private $xmlfile; - private $dom; - private $root; - /** - * Function constructor - * @access public - * @param string $file - * @return void - */ - function __construct($file=null) - { - if( !isset($file) ) - throw new Exception('[Class dynaFormHandler] ERROR: xml file was not set!!'); - $this->xmlfile = $file; - $this->load(); - } + private $xmlfile; + private $dom; + private $root; - function load(){ - $this->dom = new DOMDocument(); - $this->dom->preserveWhiteSpace = false; - $this->dom->formatOutput = true; - if( is_file($this->xmlfile) ) { - if ( @$this->dom->load($this->xmlfile) === true ) { - $this->root = $this->dom->firstChild; - } else - 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(){ - $this->dom = NULL; - $this->load(); - } - - /** - * Function __cloneEmpty - * @access public - * @return void - */ - function __cloneEmpty() - { - $xPath = new DOMXPath($this->dom); - $nodeList = $xPath->query('/dynaForm/*'); - foreach ($nodeList as $domElement){ - $elements[] = $domElement->nodeName; - } - $this->remove($elements); - //return $cloneObj; - } - - /** - * Function toString - * @access public - * @param string $op - * @return void - */ - function toString($op='') - { - switch($op){ - case 'html': return htmlentities(file_get_contents($this->xmlfile)); - default: return file_get_contents($this->xmlfile); - } - } - - /** - * Function getNode - * @access public - * @param string $nodename - * @return void - */ - function getNode($nodename) - { - return $this->root->getElementsByTagName($nodename)->item(0); - } - - /** - * Function getNode - * @access public - * @param object $node - * @return object - */ - function setNode($node){ - $newnode = $this->root->appendChild($node); - $this->save(); - return $newnode; - } - - /** - * Add Function - * @param string $name - * @param array $attributes - * @param array $childs - * @param array $childs_childs - * @return void - */ - //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) - { - $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) { - $newnode->setAttribute($att_name, $att_value); - } - if(is_array($childs)){ - foreach($childs as $child_name => $child_text) { - $newnode_child = $newnode->appendChild($this->dom->createElement($child_name)); - $newnode_child->appendChild($this->dom->createTextNode($child_text)); - if($childs_childs != null and is_array($childs_childs)){ - foreach($childs_childs as $cc) { - $ccmode = $newnode_child->appendChild($this->dom->createElement($cc['name'])); - $ccmode->appendChild($this->dom->createTextNode($cc['value'])); - foreach($cc['attributes'] as $cc_att_name => $cc_att_value) { - $ccmode->setAttribute($cc_att_name, $cc_att_value); - } - } + /** + * Function constructor + * @access public + * @param string $file + * @return void + */ + public function __construct($file = null) + { + if (!isset($file)) { + throw new Exception('[Class dynaFormHandler] ERROR: xml file was not set!!'); } - } - } else { - $text_node = $childs; - $newnode->appendChild($this->dom->createCDATASection($text_node)); + $this->xmlfile = $file; + $this->load(); + } + + public function load() + { + $this->dom = new DOMDocument(); + $this->dom->preserveWhiteSpace = false; + $this->dom->formatOutput = true; + if (is_file($this->xmlfile)) { + if (@$this->dom->load($this->xmlfile) === true) { + $this->root = $this->dom->firstChild; + } else { + 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!!'); + } + } + + public function reload() + { + $this->dom = null; + $this->load(); + } + + /** + * Function __cloneEmpty + * @access public + * @return void + */ + public function __cloneEmpty() + { + $xPath = new DOMXPath($this->dom); + $nodeList = $xPath->query('/dynaForm/*'); + foreach ($nodeList as $domElement) { + $elements[] = $domElement->nodeName; + } + $this->remove($elements); + //return $cloneObj; + } + + /** + * Function toString + * @access public + * @param string $op + * @return void + */ + public function toString($op = '') + { + switch ($op) { + case 'html': return htmlentities(file_get_contents($this->xmlfile)); + break; + default: return file_get_contents($this->xmlfile); + break; + } + } + + /** + * Function getNode + * @access public + * @param string $nodename + * @return void + */ + public function getNode($nodename) + { + return $this->root->getElementsByTagName($nodename)->item(0); + } + + /** + * Function getNode + * @access public + * @param object $node + * @return object + */ + public function setNode($node) + { + $newnode = $this->root->appendChild($node); + $this->save(); + return $newnode; + } + + /** + * Add Function + * @param string $name + * @param array $attributes + * @param array $childs + * @param array $childs_childs + * @return void + */ + //attributes (String node-name, Array attributes(atribute-name =>attribute-value, ..., ...), Array childs(child-name=>child-content), Array Child-childs()) + public function add($name, $attributes, $childs, $childs_childs = null) + { + $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) { + $newnode->setAttribute($att_name, $att_value); + } + if (is_array($childs)) { + foreach ($childs as $child_name => $child_text) { + $newnode_child = $newnode->appendChild($this->dom->createElement($child_name)); + $newnode_child->appendChild($this->dom->createTextNode($child_text)); + if ($childs_childs != null and is_array($childs_childs)) { + foreach ($childs_childs as $cc) { + $ccmode = $newnode_child->appendChild($this->dom->createElement($cc['name'])); + $ccmode->appendChild($this->dom->createTextNode($cc['value'])); + foreach ($cc['attributes'] as $cc_att_name => $cc_att_value) { + $ccmode->setAttribute($cc_att_name, $cc_att_value); + } + } + } + } + } else { + $text_node = $childs; + $newnode->appendChild($this->dom->createCDATASection($text_node)); + } + $this->save(); } - $this->save(); - } private function hasChild($p) { @@ -187,462 +195,471 @@ class dynaFormHandler if ($p->nodeType == XML_ELEMENT_NODE) { $chidNode[] = array('node' => $x->nodeName, 'nodeName' => $p->nodeName, - 'name' => $p->getAttribute('name'), 'nodeValue' => $p->nodeValue); + 'name' => $p->getAttribute('name'), 'nodeValue' => $p->nodeValue); } } } return array($x->nodeName => $chidNode); } - /** - * Function replace - * @access public - * @param string $replaced - * @param string $name - * @param array $attributes - * @param array $childs - * @param array $childs_childs - * @return void - */ - function replace($replaced, $name, $attributes, $childs=null, $childs_childs=null) - { - $chidNode= array(); - $element = $this->root->getElementsByTagName($replaced)->item(0); - $this->root->replaceChild($this->dom->createElement($name), $element); - // $newnode = $element = $this->root->getElementsByTagName($name)->item(0); - $newnode = $this->root->getElementsByTagName($name)->item(0); + /** + * Function replace + * @access public + * @param string $replaced + * @param string $name + * @param array $attributes + * @param array $childs + * @param array $childs_childs + * @return void + */ + public function replace($replaced, $name, $attributes, $childs = null, $childs_childs = null) + { + $chidNode = array(); + $element = $this->root->getElementsByTagName($replaced)->item(0); + $this->root->replaceChild($this->dom->createElement($name), $element); + // $newnode = $element = $this->root->getElementsByTagName($name)->item(0); + $newnode = $this->root->getElementsByTagName($name)->item(0); - if( isset($attributes['#text']) ) { - $newnode->appendChild($this->dom->createTextNode($attributes['#text'])); - unset($attributes['#text']); - } - 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) { - if (!is_array($att_value)) { - $newnode->setAttribute($att_name, $att_value); - } - - } - 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) { - - $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->appendChild($this->dom->createTextNode($cc['value'])); - foreach($cc['attributes'] as $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']); - } - - } - } + if (isset($attributes['#text'])) { + $newnode->appendChild($this->dom->createTextNode($attributes['#text'])); + unset($attributes['#text']); + } + 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']); } - $newnode->appendChild($this->dom->createTextNode("\n")); - } - } else if( isset($childs) ){ - $text_node = $childs; - $newnode->appendChild($this->dom->createTextNode($text_node)); - } - $this->save(); - } - /** - * Function save - * @param string $fname - * @return void - */ - function save($fname=null) - { - if( ! is_writable($this->xmlfile) ) { - throw new Exception("The file {$this->xmlfile} is not writeable!"); + foreach ($attributes as $att_name => $att_value) { + if (!is_array($att_value)) { + $newnode->setAttribute($att_name, $att_value); + } + } + 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) { + + $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->appendChild($this->dom->createTextNode($cc['value'])); + foreach ($cc['attributes'] as $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)) { + $text_node = $childs; + $newnode->appendChild($this->dom->createTextNode($text_node)); + } + } + $this->save(); } - if( !isset($fname) ){ - $this->dom->save($this->xmlfile); - } else { - $this->xmlfile = $fname; - $this->dom->save($this->xmlfile); + /** + * Function save + * @param string $fname + * @return void + */ + public function save($fname = null) + { + if (!is_writable($this->xmlfile)) { + throw new Exception("The file {$this->xmlfile} is not writeable!"); + } + + if (!isset($fname)) { + $this->dom->save($this->xmlfile); + } else { + $this->xmlfile = $fname; + $this->dom->save($this->xmlfile); + } } - } -/** - * Function fixXmlFile - * @return void - */ - function fixXmlFile() - { - $newxml = ''; - $content = file($this->xmlfile); - foreach($content as $line){ - if( trim($line) != ''){ - $newxml .= $line; - } + /** + * Function fixXmlFile + * @return void + */ + public function fixXmlFile() + { + $newxml = ''; + $content = file($this->xmlfile); + foreach ($content as $line) { + if (trim($line) != '') { + $newxml .= $line; + } + } + file_put_contents($this->xmlfile, $newxml); } - file_put_contents($this->xmlfile, $newxml); - } -/** - * Function setHeaderAttribute - * @param string $att_name - * @param string $att_value - * @return void - */ - function setHeaderAttribute($att_name, $att_value) - { - $this->root->setAttribute($att_name, $att_value); - $this->save(); - } - function getHeaderAttribute($att_name) - { - return $this->root->getAttribute($att_name); - } -/** - * Function modifyHeaderAttribute - * @param string $att_name - * @param string $att_new_value - * @return void - */ - function modifyHeaderAttribute($att_name, $att_new_value) - { - $this->root->removeAttribute($att_name); - $this->root->setAttribute($att_name, $att_new_value); - $this->save(); - } - -/** - * Function updateAttribute - * @param string $node_name - * @param string $att_name - * @param string $att_new_value - * @return void - */ - function updateAttribute($node_name, $att_name, $att_new_value) - { - $xpath = new DOMXPath($this->dom); - $nodeList = $xpath->query("/dynaForm/$node_name"); - $node = $nodeList->item(0); - $node->removeAttribute($att_name); - $node->setAttribute($att_name, $att_new_value); - $this->save(); - } - -/** - * Function remove - * @param string $v - * @return void - */ - function remove($v) - { - if(!is_array($v)){ - $av[0] = $v; - } else{ - $av = $v; + /** + * Function setHeaderAttribute + * @param string $att_name + * @param string $att_value + * @return void + */ + public function setHeaderAttribute($att_name, $att_value) + { + $this->root->setAttribute($att_name, $att_value); + $this->save(); } - foreach($av as $e){ - $xnode = $this->root->getElementsByTagName($e)->item(0); - if ( $xnode->nodeType == XML_ELEMENT_NODE ) { - $dropednode = $this->root->removeChild($xnode); - /*evaluation field aditional routines*/ + + public function getHeaderAttribute($att_name) + { + return $this->root->getAttribute($att_name); + } + + /** + * Function modifyHeaderAttribute + * @param string $att_name + * @param string $att_new_value + * @return void + */ + public function modifyHeaderAttribute($att_name, $att_new_value) + { + $this->root->removeAttribute($att_name); + $this->root->setAttribute($att_name, $att_new_value); + $this->save(); + } + + /** + * Function updateAttribute + * @param string $node_name + * @param string $att_name + * @param string $att_new_value + * @return void + */ + public function updateAttribute($node_name, $att_name, $att_new_value) + { $xpath = new DOMXPath($this->dom); - $nodeList = $xpath->query("/dynaForm/JS_$e"); - if($nodeList->length != 0){ - $tmp_node = $nodeList->item(0); - $this->root->removeChild($tmp_node); - } - } else { - print("[Class dynaFormHandler] ERROR: The \"$e\" element doesn't exist!
"); - } + $nodeList = $xpath->query("/dynaForm/$node_name"); + $node = $nodeList->item(0); + $node->removeAttribute($att_name); + $node->setAttribute($att_name, $att_new_value); + $this->save(); } - $this->save(); - } -/** - * Function nodeExists - * @param string $node_name - * @return boolean - */ - function nodeExists($node_name) - { - $xpath = new DOMXPath($this->dom); - $nodeList = $xpath->query("/dynaForm/$node_name"); - $node = $nodeList->item(0); - if($nodeList->length != 0){ - return true; - } else { - return false; - } - } - - //new features - /** - * Function moveUp - * @param string $selected_node - * @return void - */ - function moveUp($selected_node) - { - /*DOMNode DOMNode::insertBefore ( DOMNode $newnode [, DOMNode $refnode ] ) - 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. */ - $xpath = new DOMXPath($this->dom); - $nodeList = $xpath->query("/dynaForm/*"); - $flag = false; - for($i = 0; $i < $nodeList->length; $i++) { - $xnode = $nodeList->item($i); - if($selected_node == $xnode->nodeName){ - //if is a first node move it to final with a circular logic - if( $flag === false ){ - $removed_node = $this->root->removeChild($xnode); - $this->root->appendChild($removed_node); - break; + /** + * Function remove + * @param string $v + * @return void + */ + public function remove($v) + { + if (!is_array($v)) { + $av[0] = $v; } else { - $removed_node = $this->root->removeChild($xnode); - $predecessor_node = $nodeList->item($i-1); - $this->root->insertBefore($removed_node, $predecessor_node); - break; + $av = $v; } - } - $flag = true; + foreach ($av as $e) { + $xnode = $this->root->getElementsByTagName($e)->item(0); + if ($xnode->nodeType == XML_ELEMENT_NODE) { + $dropednode = $this->root->removeChild($xnode); + /* evaluation field aditional routines */ + $xpath = new DOMXPath($this->dom); + $nodeList = $xpath->query("/dynaForm/JS_$e"); + if ($nodeList->length != 0) { + $tmp_node = $nodeList->item(0); + $this->root->removeChild($tmp_node); + } + } else { + print("[Class dynaFormHandler] ERROR: The \"$e\" element doesn't exist!
"); + } + } + $this->save(); } - $this->save(); - } - /** - * Function moveDown - * @param string $selected_node - * @return void - */ - function moveDown($selected_node) - { - /*DOMNode DOMNode::insertBefore ( DOMNode $newnode [, DOMNode $refnode ] ) - 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. */ - $xpath = new DOMXPath($this->dom); - $nodeList = $xpath->query("/dynaForm/*"); - $real_length = $nodeList->length; - for($i = 0; $i < $nodeList->length; $i++) { - $xnode = $nodeList->item($i); - if($selected_node == $xnode->nodeName){ - //if is a last node move it to final with a circular logic - if( ($i+1) == $real_length){ - if($real_length != 1){ - $first_node = $nodeList->item(0); - $removed_node = $this->root->removeChild($xnode); - $this->root->insertBefore($removed_node, $first_node); - } - break; + /** + * Function nodeExists + * @param string $node_name + * @return boolean + */ + public function nodeExists($node_name) + { + $xpath = new DOMXPath($this->dom); + $nodeList = $xpath->query("/dynaForm/$node_name"); + $node = $nodeList->item(0); + if ($nodeList->length != 0) { + return true; } else { - if( ($i+3) <= $real_length ){ - $removed_node = $this->root->removeChild($xnode); - $predecessor_node = $nodeList->item($i+2); - $this->root->insertBefore($removed_node, $predecessor_node); - break; - } else { - $removed_node = $this->root->removeChild($xnode); - $this->root->appendChild($removed_node); - break; - } + return false; } - } } - $this->save(); - } - /** - * Function getFields - * @param array $aFilter - * @return array - */ - function getFields( $aFilter = Array() ) - { - $xpath = new DOMXPath($this->dom); - $nodeList = $xpath->query("/dynaForm/*"); - $aList = Array(); - for($i = 0; $i < $nodeList->length; $i++) { - $xnode = $nodeList->item($i); - if( is_array($aFilter) && sizeof($aFilter) > 0 ){ - if( isset($aFilter['IN']) ){ - if( isset($aFilter['NOT_IN']) ){ - if( in_array($xnode->nodeName, $aFilter['IN']) && !in_array($xnode->nodeName, $aFilter['NOT_IN']) ){ - array_push($aList, $xnode); + //new features + /** + * Function moveUp + * @param string $selected_node + * @return void + */ + public function moveUp($selected_node) + { + /* DOMNode DOMNode::insertBefore ( DOMNode $newnode [, DOMNode $refnode ] ) + 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. */ + $xpath = new DOMXPath($this->dom); + $nodeList = $xpath->query("/dynaForm/*"); + $flag = false; + for ($i = 0; $i < $nodeList->length; $i++) { + $xnode = $nodeList->item($i); + if ($selected_node == $xnode->nodeName) { + //if is a first node move it to final with a circular logic + if ($flag === false) { + $removed_node = $this->root->removeChild($xnode); + $this->root->appendChild($removed_node); + break; + } else { + $removed_node = $this->root->removeChild($xnode); + $predecessor_node = $nodeList->item($i - 1); + $this->root->insertBefore($removed_node, $predecessor_node); + break; + } } - } else { - if( in_array($xnode->nodeName, $aFilter['IN']) ){ - array_push($aList, $xnode); + $flag = true; + } + $this->save(); + } + + /** + * Function moveDown + * @param string $selected_node + * @return void + */ + public function moveDown($selected_node) + { + /* DOMNode DOMNode::insertBefore ( DOMNode $newnode [, DOMNode $refnode ] ) + 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. */ + $xpath = new DOMXPath($this->dom); + $nodeList = $xpath->query("/dynaForm/*"); + $real_length = $nodeList->length; + for ($i = 0; $i < $nodeList->length; $i++) { + $xnode = $nodeList->item($i); + if ($selected_node == $xnode->nodeName) { + //if is a last node move it to final with a circular logic + if (($i + 1) == $real_length) { + if ($real_length != 1) { + $first_node = $nodeList->item(0); + $removed_node = $this->root->removeChild($xnode); + $this->root->insertBefore($removed_node, $first_node); + } + break; + } else { + if (($i + 3) <= $real_length) { + $removed_node = $this->root->removeChild($xnode); + $predecessor_node = $nodeList->item($i + 2); + $this->root->insertBefore($removed_node, $predecessor_node); + break; + } else { + $removed_node = $this->root->removeChild($xnode); + $this->root->appendChild($removed_node); + break; + } + } + } + } + $this->save(); + } + + /** + * Function getFields + * @param array $aFilter + * @return array + */ + public function getFields($aFilter = Array()) + { + $xpath = new DOMXPath($this->dom); + $nodeList = $xpath->query("/dynaForm/*"); + $aList = Array(); + for ($i = 0; $i < $nodeList->length; $i++) { + $xnode = $nodeList->item($i); + if (is_array($aFilter) && sizeof($aFilter) > 0) { + if (isset($aFilter['IN'])) { + if (isset($aFilter['NOT_IN'])) { + if (in_array($xnode->nodeName, $aFilter['IN']) && !in_array($xnode->nodeName, $aFilter['NOT_IN'])) { + array_push($aList, $xnode); + } + } else { + if (in_array($xnode->nodeName, $aFilter['IN'])) { + array_push($aList, $xnode); + } + } + } else if (isset($aFilter['NOT_IN'])) { + if (!in_array($xnode->nodeName, $aFilter['NOT_IN'])) { + array_push($aList, $xnode); + } + } else { + array_push($aList, $xnode); + } + } else { + array_push($aList, $xnode); + } + } + return $aList; + } + + /** + * Function getFieldNames + * @param array $aFilter + * @return array + */ + public function getFieldNames($aFilter = Array()) + { + $aList = $this->getFields($aFilter); + $aFieldNames = Array(); + foreach ($aList as $item) { + array_push($aFieldNames, $item->nodeName); + } + return $aFieldNames; + } + + + public function addChilds($name, $childs, $childs_childs = null) + { + $xpath = new DOMXPath($this->dom); + $nodeList = @$xpath->query("/dynaForm/$name"); + if (!$nodeList) { + throw new Exception("Error trying get the field dynaform $name, maybe it doesn't exist in {$this->xmlfile}"); + } + + if ($nodeList->length == 0) { + $element = $this->root->appendChild($this->dom->createElement($name)); + } else + $element = $this->root->getElementsByTagName($name)->item(0); + + if (is_array($childs)) { + foreach ($childs as $child_name => $child_text) { + + $nodeList = $xpath->query("/dynaForm/$name/$child_name"); + + if ($nodeList->length == 0) { + //the node doesn't exist + //$newnode_child + $childNode = $element->appendChild($this->dom->createElement($child_name)); + $childNode->appendChild($this->dom->createCDATASection($child_text)); + } else { + // the node already exists + //update its value + $childNode = $element->getElementsByTagName($child_name)->item(0); + + if ($child_text !== null) { + $xnode = $this->dom->createElement($childNode->nodeName); + $xnode->appendChild($this->dom->createCDATASection($child_text)); + + $element->replaceChild($xnode, $childNode); + $childNode = $element->getElementsByTagName($child_name)->item(0); + } + } + + if ($childs_childs != null and is_array($childs_childs)) { + foreach ($childs_childs as $cc) { + $ccnode = $childNode->appendChild($this->dom->createElement($cc['name'])); + $ccnode->appendChild($this->dom->createCDATASection($cc['value'])); + foreach ($cc['attributes'] as $cc_att_name => $cc_att_value) { + $ccnode->setAttribute($cc_att_name, $cc_att_value); + } + } + } } - } - } else if( isset($aFilter['NOT_IN']) ){ - if( !in_array($xnode->nodeName, $aFilter['NOT_IN']) ){ - array_push($aList, $xnode); - } } else { - array_push($aList, $xnode); + $text_node = $childs; + $newnode->appendChild($this->dom->createTextNode($text_node)); } - } else { - array_push($aList, $xnode); - } - } - return $aList; - } - - /** - * Function getFieldNames - * @param array $aFilter - * @return array - */ - function getFieldNames( $aFilter = Array() ) - { - $aList = $this->getFields($aFilter); - $aFieldNames = Array(); - foreach( $aList as $item ){ - array_push($aFieldNames, $item->nodeName); - } - return $aFieldNames; - } - - // - function addChilds($name, $childs, $childs_childs=null) - { - // - $xpath = new DOMXPath($this->dom); - $nodeList = @$xpath->query("/dynaForm/$name"); - if( ! $nodeList ){ - throw new Exception("Error trying get the field dynaform $name, maybe it doesn't exist in {$this->xmlfile}"); + $this->save(); } - if( $nodeList->length == 0 ) { - $element = $this->root->appendChild($this->dom->createElement($name)); - } else - $element = $this->root->getElementsByTagName($name)->item(0); + public function addOrUpdateChild($xnode, $childName, $childValue, $childAttributes) + { + $newNode = $this->dom->createElement($childName); + $newNode->appendChild($this->dom->createCDATASection($childValue)); - if( is_array($childs) ) { - foreach( $childs as $child_name => $child_text ) { - - $nodeList = $xpath->query("/dynaForm/$name/$child_name"); - - if( $nodeList->length == 0 ){ //the node doesn't exist - //$newnode_child - $childNode = $element->appendChild($this->dom->createElement($child_name)); - $childNode->appendChild($this->dom->createCDATASection($child_text)); - } else { // the node already exists - //update its value - $childNode = $element->getElementsByTagName($child_name)->item(0); - - // - if($child_text !== NULL){ - $xnode = $this->dom->createElement($childNode->nodeName); - $xnode->appendChild($this->dom->createCDATASection($child_text)); - - $element->replaceChild($xnode, $childNode); - $childNode = $element->getElementsByTagName($child_name)->item(0); - } + foreach ($childAttributes as $attName => $attValue) { + $newNode->setAttribute($attName, $attValue); } - if($childs_childs != null and is_array($childs_childs)){ - foreach($childs_childs as $cc) { - $ccnode = $childNode->appendChild($this->dom->createElement($cc['name'])); - $ccnode->appendChild($this->dom->createCDATASection($cc['value'])); - foreach($cc['attributes'] as $cc_att_name => $cc_att_value) { - $ccnode->setAttribute($cc_att_name, $cc_att_value); + if ($xnode->hasChildNodes()) { + foreach ($xnode->childNodes as $cnode) { + if ($cnode->nodeName == $childName) { + $xnode->replaceChild($newNode, $cnode); + break; + } } - } + } else { + $xnode->appendChild($newNode); } - } - } else { - $text_node = $childs; - $newnode->appendChild($this->dom->createTextNode($text_node)); - } - $this->save(); - } - - - function addOrUpdateChild($xnode, $childName, $childValue, $childAttributes){ - $newNode = $this->dom->createElement($childName); - $newNode->appendChild($this->dom->createCDATASection($childValue)); - - foreach($childAttributes as $attName => $attValue) { - $newNode->setAttribute($attName, $attValue); } - if( $xnode->hasChildNodes() ) { - foreach($xnode->childNodes as $cnode) { - if( $cnode->nodeName == $childName ) { - $xnode->replaceChild($newNode, $cnode); - break; - } - } - } else - $xnode->appendChild($newNode); - } + public function getArray($node, $attributes = null) + { + $array = false; + $array['__nodeName__'] = $node->nodeName; + $text = simplexml_import_dom($node); + $array['__nodeText__'] = trim((string) $text); - function getArray($node, $attributes = null) - { - $array = false; - $array['__nodeName__'] = $node->nodeName; - $text = simplexml_import_dom($node); - $array['__nodeText__'] = trim((string) $text); + if ($node->hasAttributes()) { + if (isset($attributes)) { + foreach ($attributes as $attr) { + if ($node->hasAttribute($attr)) { + $array[$attr] = $node->getAttribute($attr); + } + } + } else { + foreach ($node->attributes as $attr) { + $array[$attr->nodeName] = $attr->nodeValue; + } + } + } - if ($node->hasAttributes()) { - if( isset($attributes) ) { - foreach ($attributes as $attr) { - if( $node->hasAttribute($attr) ) - $array[$attr] = $node->getAttribute($attr); + if ($node->hasChildNodes()) { + if ($node->childNodes->length == 0) { + $return; + } else { + foreach ($node->childNodes as $childNode) { + $childNode->normalize(); + //if ($childNode->nodeType == XML_TEXT_NODE || $childNode->nodeType == XML_CDATA_SECTION_NODE) { + if ($childNode->nodeType == XML_ELEMENT_NODE) { + $array[$childNode->nodeName][] = $this->getArray($childNode); + } else if ($childNode->nodeType == XML_TEXT_NODE || $childNode->nodeType == XML_CDATA_SECTION_NODE) { + //$array[$childNode->nodeName] = $childNode->textContent; + $text = simplexml_import_dom($childNode->parentNode); + $array['__nodeText__'] = trim((string) $text); + } + } + } } - } else { - foreach ($node->attributes as $attr) { - $array[$attr->nodeName] = $attr->nodeValue; - } - } + + return $array; } - - if ($node->hasChildNodes()) { - if ($node->childNodes->length == 0) - $return; - else { - foreach ($node->childNodes as $childNode) { - $childNode->normalize(); - //if ($childNode->nodeType == XML_TEXT_NODE || $childNode->nodeType == XML_CDATA_SECTION_NODE) { - if ($childNode->nodeType == XML_ELEMENT_NODE) { - $array[$childNode->nodeName][] = $this->getArray($childNode); - } else if ($childNode->nodeType == XML_TEXT_NODE || $childNode->nodeType == XML_CDATA_SECTION_NODE) { - //$array[$childNode->nodeName] = $childNode->textContent; - $text = simplexml_import_dom($childNode->parentNode); - $array['__nodeText__'] = trim((string) $text); - } - } - } - } - - return $array; - } } + diff --git a/workflow/engine/classes/class.dynaFormField.php b/workflow/engine/classes/class.dynaFormField.php index ec71cbe2c..4f490f97d 100755 --- a/workflow/engine/classes/class.dynaFormField.php +++ b/workflow/engine/classes/class.dynaFormField.php @@ -1,4 +1,5 @@ fileName; @@ -52,10 +54,10 @@ class DynaFormField extends DBTable * @param string $objConnection * @return void */ - function SetTo ($objConnection) + public function SetTo($objConnection) { - DBTable::SetTo( $objConnection, 'dynaForm', array ('XMLNODE_NAME' - ) ); + DBTable::SetTo($objConnection, 'dynaForm', array('XMLNODE_NAME' + )); } /** @@ -64,13 +66,13 @@ class DynaFormField extends DBTable * @param string $sUID * @return void */ - function Load ($sUID) + public function Load($sUID) { - parent::Load( $sUID ); - if (is_array( $this->Fields )) { + parent::Load($sUID); + if (is_array($this->Fields)) { foreach ($this->Fields as $name => $value) { - if (strcasecmp( $name, 'dependentfields' ) == 0) { - $this->Fields[$name] = explode( ',', $value ); + if (strcasecmp($name, 'dependentfields') == 0) { + $this->Fields[$name] = explode(',', $value); } } } @@ -82,7 +84,7 @@ class DynaFormField extends DBTable * @param string $uid * @return void */ - function Delete ($uid) + public function Delete($uid) { $this->Fields['XMLNODE_NAME'] = $uid; parent::Delete(); @@ -96,108 +98,28 @@ class DynaFormField extends DBTable * @param array $options * @return void */ - function Save ($Fields, $labels = array(), $options = array()) + public function Save($Fields, $labels = array(), $options = array()) { if ($Fields['TYPE'] === 'javascript') { $Fields['XMLNODE_VALUE'] = $Fields['CODE']; - unset( $Fields['CODE'] ); - $labels = array (); + unset($Fields['CODE']); + $labels = 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'] . '"' ); + $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'] . '"' ); + $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']; - } - /*$res = $this->_dbses->Execute('INSERT INTO dynaForm'. - ' (XMLNODE_TYPE,XMLNODE_VALUE)'. - ' VALUES ("cdata", "'."\n".'")');*/ - parent::Save(); - if ($this->is_new) { - /* - * Create a new field. - */ - foreach ($labels as $lang => $value) { - /*$res = $this->_dbses->Execute('INSERT INTO dynaForm'. - ' (XMLNODE_TYPE,XMLNODE_VALUE)'. - ' 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) ' . 'VALUES ("' . $lang . '","' . str_replace( '"', '""', $value )/*."\n "*/.'")' ); - if (isset( $options[$lang] )) { - 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,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'] . ' (XMLNODE_NAME,XMLNODE_VALUE,XMLNODE_TYPE) ' . 'VALUES ("","' . "\n" . '","cdata")' ); - } - $res = $this->_dbses->Execute( 'INSERT INTO dynaForm' . ' (XMLNODE_TYPE,XMLNODE_VALUE)' . ' VALUES ("cdata", "' . "\n" . '")' ); - } else { - /* - * Update an existing field. - */ - $this->_dbses->Execute( 'UPDATE dynaForm SET XMLNODE_NAME = "' . $Fields['XMLNODE_NAME'] . '" WHERE XMLNODE_NAME = "' . $Fields['XMLNODE_NAME_OLD'] . '"' ); - foreach ($labels as $lang => $value) { - $res = $this->_dbses->Execute( 'SELECT * FROM dynaForm.' . $Fields['XMLNODE_NAME'] . ' WHERE XMLNODE_NAME ="' . $lang . '"' ); - if ($res->count() > 0) { - $res = $this->_dbses->Execute( 'UPDATE dynaForm.' . $Fields['XMLNODE_NAME'] . ' SET XMLNODE_VALUE = ' . '"' . str_replace( '"', '""', $value ) . '" WHERE XMLNODE_NAME ="' . $lang . '"' ); - } else { - $res = $this->_dbses->Execute( 'INSERT INTO dynaForm.' . $Fields['XMLNODE_NAME'] . ' (XMLNODE_NAME,XMLNODE_VALUE) ' . 'VALUES ("' . $lang . '","' . str_replace( '"', '""', $value ) . '")' ); - } - if (isset( $options[$lang] )) { - $res = $this->_dbses->Execute( 'DELETE FROM dynaForm.' . $Fields['XMLNODE_NAME'] . '.' . $lang . ' WHERE 1' ); - 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 ) . '")' ); - } - } - } - } - } - - 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'] ); + 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 @@ -205,7 +127,88 @@ class DynaFormField extends DBTable if ($this->is_new) { foreach ($this->Fields as $key => $value) { if ($value == "") { - unset( $this->Fields[$key] ); + unset($this->Fields[$key]); + } + } + } else { + $this->Fields['XMLNODE_NAME'] = $Fields['XMLNODE_NAME_OLD']; + } + /* $res = $this->_dbses->Execute('INSERT INTO dynaForm'. + ' (XMLNODE_TYPE,XMLNODE_VALUE)'. + ' VALUES ("cdata", "'."\n".'")'); */ + parent::Save(); + if ($this->is_new) { + /* + * Create a new field. + */ + foreach ($labels as $lang => $value) { + /* $res = $this->_dbses->Execute('INSERT INTO dynaForm'. + ' (XMLNODE_TYPE,XMLNODE_VALUE)'. + ' 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) ' . 'VALUES ("' . $lang . '","' . str_replace('"', '""', $value)/* ."\n " */ . '")'); + if (isset($options[$lang])) { + 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,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'] . ' (XMLNODE_NAME,XMLNODE_VALUE,XMLNODE_TYPE) ' . 'VALUES ("","' . "\n" . '","cdata")'); + } + $res = $this->_dbses->Execute('INSERT INTO dynaForm' . ' (XMLNODE_TYPE,XMLNODE_VALUE)' . ' VALUES ("cdata", "' . "\n" . '")'); + } else { + /* + * Update an existing field. + */ + $this->_dbses->Execute('UPDATE dynaForm SET XMLNODE_NAME = "' . $Fields['XMLNODE_NAME'] . '" WHERE XMLNODE_NAME = "' . $Fields['XMLNODE_NAME_OLD'] . '"'); + foreach ($labels as $lang => $value) { + $res = $this->_dbses->Execute('SELECT * FROM dynaForm.' . $Fields['XMLNODE_NAME'] . ' WHERE XMLNODE_NAME ="' . $lang . '"'); + if ($res->count() > 0) { + $res = $this->_dbses->Execute('UPDATE dynaForm.' . $Fields['XMLNODE_NAME'] . ' SET XMLNODE_VALUE = ' . '"' . str_replace('"', '""', $value) . '" WHERE XMLNODE_NAME ="' . $lang . '"'); + } else { + $res = $this->_dbses->Execute('INSERT INTO dynaForm.' . $Fields['XMLNODE_NAME'] . ' (XMLNODE_NAME,XMLNODE_VALUE) ' . 'VALUES ("' . $lang . '","' . str_replace('"', '""', $value) . '")'); + } + if (isset($options[$lang])) { + $res = $this->_dbses->Execute('DELETE FROM dynaForm.' . $Fields['XMLNODE_NAME'] . '.' . $lang . ' WHERE 1'); + 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) . '")'); + } + } + } + } + } + + 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 { @@ -218,10 +221,10 @@ class DynaFormField extends DBTable } $aOptions = array(); - if(isset($Fields['OPTIONS']) && is_array($Fields['OPTIONS']) ) { + 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']) ); + $aOptions[] = Array('name' => 'option', 'value' => $value['LABEL'], + 'attributes' => array('name' => $value['NAME'])); } } @@ -238,11 +241,10 @@ class DynaFormField extends DBTable * * @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); } } - -?> \ No newline at end of file + \ No newline at end of file diff --git a/workflow/engine/classes/class.dynaformEditor.php b/workflow/engine/classes/class.dynaformEditor.php index df3c42557..ee71840b7 100755 --- a/workflow/engine/classes/class.dynaformEditor.php +++ b/workflow/engine/classes/class.dynaformEditor.php @@ -1,4 +1,5 @@ */ - -G::LoadSystem( "webResource" ); -G::LoadClass( 'toolBar' ); -G::LoadClass( 'dynaFormField' ); +G::LoadSystem("webResource"); +G::LoadClass('toolBar'); +G::LoadClass('dynaFormField'); require_once ('classes/model/Process.php'); require_once ('classes/model/Dynaform.php'); -G::LoadClass( 'xmlDb' ); +G::LoadClass('xmlDb'); G::LoadSystem('dynaformhandler'); + /** * * @package workflow.engine.classes */ - class dynaformEditor extends WebResource { + private $isOldCopy = false; - var $file = ''; - var $title = 'New Dynaform'; - var $dyn_uid = ''; - var $dyn_type = ''; - var $home = ''; + public $file = ''; + public $title = 'New Dynaform'; + public $dyn_uid = ''; + public $dyn_type = ''; + public $home = ''; + /** * Other Options for Editor: * left: 'getAbsoluteLeft(document.getElementById("dynaformEditor[0]"))', @@ -64,14 +65,12 @@ class dynaformEditor extends WebResource * left: 'getAbsoluteLeft(document.getElementById("dynaformEditor[0]"))', * top: 'getAbsoluteTop(document.getElementById("dynaformEditor[0]"))', */ - var $defaultConfig = array ('Editor' => array ('left' => '0','top' => '0','width' => 'document.body.clientWidth-4','height' => 'document.body.clientHeight-4' - ),'Toolbar' => array ('left' => 'document.body.clientWidth-2-toolbar.clientWidth-24-3+7','top' => '52' - ),'FieldsList' => array ('left' => '4+toolbar.clientWidth+24','top' => 'getAbsoluteTop(document.getElementById("dynaformEditor[0]"))','width' => 244,'height' => 400 - ) + public $defaultConfig = array('Editor' => array('left' => '0', 'top' => '0', 'width' => 'document.body.clientWidth-4', 'height' => 'document.body.clientHeight-4'), + 'Toolbar' => array('left' => 'document.body.clientWidth-2-toolbar.clientWidth-24-3+7', 'top' => '52'), + 'FieldsList' => array('left' => '4+toolbar.clientWidth+24', 'top' => 'getAbsoluteTop(document.getElementById("dynaformEditor[0]"))', 'width' => 244, 'height' => 400) ); - var $panelConf = array ('style' => array ('title' => array ('textAlign' => 'center' - ) - ),'width' => 700,'height' => 600,'tabWidth' => 120,'modal' => true,'drag' => false,'resize' => false,'blinkToFront' => false + public $panelConf = array('style' => array('title' => array('textAlign' => 'center')), + 'width' => 700, 'height' => 600, 'tabWidth' => 120, 'modal' => true, 'drag' => false, 'resize' => false, 'blinkToFront' => false ); /** @@ -80,9 +79,9 @@ class dynaformEditor extends WebResource * @param string $get * @return void */ - function dynaformEditor ($get) + public function dynaformEditor($get) { - $this->panelConf = array_merge( $this->panelConf, $this->defaultConfig['Editor'] ); + $this->panelConf = array_merge($this->panelConf, $this->defaultConfig['Editor']); //'title' => G::LoadTranslation('ID_DYNAFORM_EDITOR').' - ['.$this->title.']', } @@ -92,35 +91,35 @@ class dynaformEditor extends WebResource * @param string $filename * @return void */ - function _createDefaultXmlForm ($fileName) + public function _createDefaultXmlForm($fileName) { //Create the default Dynaform $sampleForm = '' . "\n"; $sampleForm .= '' . "\n"; switch ($this->dyn_type) { case "xmlform": - /*$sampleForm.='' . "\n" . - ' <en>Sample form</en>' . "\n" . - ''."\n"; - $sampleForm.='' . "\n" . - ' Submit' . "\n" . - ''."\n";*/ - break; + /* $sampleForm.='' . "\n" . + ' <en>Sample form</en>' . "\n" . + ''."\n"; + $sampleForm.='' . "\n" . + ' Submit' . "\n" . + ''."\n"; */ + break; case "grid": - /*$sampleForm.='' . "\n" . - 'A' . "\n" . - ''."\n"; - $sampleForm.='' . "\n" . - 'B' . "\n" . - ''."\n";*/ - break; + /* $sampleForm.='' . "\n" . + 'A' . "\n" . + ''."\n"; + $sampleForm.='' . "\n" . + 'B' . "\n" . + ''."\n"; */ + break; } $sampleForm .= ''; - G::verifyPath( dirname( $fileName ), true ); - $fp = fopen( $fileName, 'w' ); - $sampleForm = str_replace( 'name=""', 'name="' . $this->_getFilename( $this->file ) . '"', $sampleForm ); - fwrite( $fp, $sampleForm ); - fclose( $fp ); + G::verifyPath(dirname($fileName), true); + $fp = fopen($fileName, 'w'); + $sampleForm = str_replace('name=""', 'name="' . $this->_getFilename($this->file) . '"', $sampleForm); + fwrite($fp, $sampleForm); + fclose($fp); } /** @@ -128,109 +127,110 @@ class dynaformEditor extends WebResource * * @return void */ - function _render () + public function _render() { global $G_PUBLISH; $script = ''; /* Start Block: Load (Create if doesn't exist) the xmlform */ - $Parameters = array ('SYS_LANG' => SYS_LANG,'URL' => G::encrypt( $this->file, URL_KEY ),'DYN_UID' => $this->dyn_uid,'PRO_UID' => $this->pro_uid,'DYNAFORM_NAME' => $this->dyn_title,'FILE' => $this->file,'DYN_EDITOR' => $this->dyn_editor + $Parameters = array('SYS_LANG' => SYS_LANG, 'URL' => G::encrypt($this->file, URL_KEY), 'DYN_UID' => $this->dyn_uid, 'PRO_UID' => $this->pro_uid, 'DYNAFORM_NAME' => $this->dyn_title, 'FILE' => $this->file, 'DYN_EDITOR' => $this->dyn_editor ); $_SESSION['Current_Dynafom']['Parameters'] = $Parameters; - $XmlEditor = array ('URL' => G::encrypt( $this->file, URL_KEY ),'XML' => '' //$openDoc->getXml() + $XmlEditor = array('URL' => G::encrypt($this->file, URL_KEY), 'XML' => '' //$openDoc->getXml() ); - $JSEditor = array ('URL' => G::encrypt( $this->file, URL_KEY ) + $JSEditor = array('URL' => G::encrypt($this->file, URL_KEY) ); - $A = G::encrypt( $this->file, URL_KEY ); + $A = G::encrypt($this->file, URL_KEY); try { $openDoc = new Xml_Document(); $fileName = $this->home . $this->file . '.xml'; - if (file_exists( $fileName )) { - $openDoc->parseXmlFile( $fileName ); + if (file_exists($fileName)) { + $openDoc->parseXmlFile($fileName); } else { - $this->_createDefaultXmlForm( $fileName ); - $openDoc->parseXmlFile( $fileName ); + $this->_createDefaultXmlForm($fileName); + $openDoc->parseXmlFile($fileName); } //$form = new Form( $this->file , $this->home, SYS_LANG, true ); - $Properties = dynaformEditorAjax::get_properties( $A, $this->dyn_uid ); + $Properties = dynaformEditorAjax::get_properties($A, $this->dyn_uid); /* Start Block: Prepare the XMLDB connection */ - define( 'DB_XMLDB_HOST', PATH_DYNAFORM . $this->file . '.xml' ); - define( 'DB_XMLDB_USER', '' ); - define( 'DB_XMLDB_PASS', '' ); - define( 'DB_XMLDB_NAME', '' ); - define( 'DB_XMLDB_TYPE', 'myxml' ); + define('DB_XMLDB_HOST', PATH_DYNAFORM . $this->file . '.xml'); + define('DB_XMLDB_USER', ''); + define('DB_XMLDB_PASS', ''); + define('DB_XMLDB_NAME', ''); + define('DB_XMLDB_TYPE', 'myxml'); /* Start Block: Prepare the dynaformEditor */ $G_PUBLISH = new Publisher(); $sName = 'dynaformEditor'; $G_PUBLISH->publisherId = $sName; $oHeadPublisher = & headPublisher::getSingleton(); - $labesTrans = G::getTranslations( Array ('ID_FIELD_DYNAFORM_TEXT','ID_FIELD_DYNAFORM_CURRENCY','ID_FIELD_DYNAFORM_PERCENTAGE','ID_FIELD_DYNAFORM_PASSWORD','ID_FIELD_DYNAFORM_SUGGEST','ID_FIELD_DYNAFORM_TEXTAREA','ID_FIELD_DYNAFORM_TITLE','ID_FIELD_DYNAFORM_SUBTITLE','ID_FIELD_DYNAFORM_BUTTON','ID_FIELD_DYNAFORM_SUBMIT','ID_FIELD_DYNAFORM_RESET','ID_FIELD_DYNAFORM_DROPDOWN','ID_FIELD_DYNAFORM_YESNO','ID_FIELD_DYNAFORM_LISTBOX','ID_FIELD_DYNAFORM_CHECKBOX','ID_FIELD_DYNAFORM_CHECKGROUP','ID_FIELD_DYNAFORM_RADIOGROUP','DATE_LABEL','ID_FIELD_DYNAFORM_HIDDEN','ID_FIELD_DYNAFORM_LINK','ID_FIELD_DYNAFORM_LINK','ID_FIELD_DYNAFORM_FILE','ID_FIELD_DYNAFORM_JAVASCRIPT','ID_FIELD_DYNAFORM_GRID','ID_INDEX' - ) ); - $oHeadPublisher->addScriptCode( "var TRANSLATIONS = " . G::json_encode( $labesTrans ) . ";" ); - $oHeadPublisher->setTitle( G::LoadTranslation( 'ID_DYNAFORM_EDITOR' ) . ' - ' . $Properties['DYN_TITLE'] ); - $G_PUBLISH->AddContent( 'blank' ); + $labesTrans = G::getTranslations(Array('ID_FIELD_DYNAFORM_TEXT', 'ID_FIELD_DYNAFORM_CURRENCY', 'ID_FIELD_DYNAFORM_PERCENTAGE', 'ID_FIELD_DYNAFORM_PASSWORD', 'ID_FIELD_DYNAFORM_SUGGEST', 'ID_FIELD_DYNAFORM_TEXTAREA', 'ID_FIELD_DYNAFORM_TITLE', 'ID_FIELD_DYNAFORM_SUBTITLE', 'ID_FIELD_DYNAFORM_BUTTON', 'ID_FIELD_DYNAFORM_SUBMIT', 'ID_FIELD_DYNAFORM_RESET', 'ID_FIELD_DYNAFORM_DROPDOWN', 'ID_FIELD_DYNAFORM_YESNO', 'ID_FIELD_DYNAFORM_LISTBOX', 'ID_FIELD_DYNAFORM_CHECKBOX', 'ID_FIELD_DYNAFORM_CHECKGROUP', 'ID_FIELD_DYNAFORM_RADIOGROUP', 'DATE_LABEL', 'ID_FIELD_DYNAFORM_HIDDEN', 'ID_FIELD_DYNAFORM_LINK', 'ID_FIELD_DYNAFORM_LINK', 'ID_FIELD_DYNAFORM_FILE', 'ID_FIELD_DYNAFORM_JAVASCRIPT', 'ID_FIELD_DYNAFORM_GRID', 'ID_INDEX' + )); + $oHeadPublisher->addScriptCode("var TRANSLATIONS = " . G::json_encode($labesTrans) . ";"); + $oHeadPublisher->setTitle(G::LoadTranslation('ID_DYNAFORM_EDITOR') . ' - ' . $Properties['DYN_TITLE']); + $G_PUBLISH->AddContent('blank'); $this->panelConf['title'] = $this->title; - $G_PUBLISH->AddContent( 'panel-init', 'mainPanel', $this->panelConf ); + $G_PUBLISH->AddContent('panel-init', 'mainPanel', $this->panelConf); if ($Properties['DYN_TYPE'] == 'xmlform') { - $G_PUBLISH->AddContent( 'xmlform', 'toolbar', 'dynaforms/fields_Toolbar', 'display:none', $Parameters, '', '' ); + $G_PUBLISH->AddContent('xmlform', 'toolbar', 'dynaforms/fields_Toolbar', 'display:none', $Parameters, '', ''); } else { - $G_PUBLISH->AddContent( 'xmlform', 'toolbar', 'dynaforms/fields_ToolbarGrid', 'display:none', $Parameters, '', '' ); + $G_PUBLISH->AddContent('xmlform', 'toolbar', 'dynaforms/fields_ToolbarGrid', 'display:none', $Parameters, '', ''); } - $G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'dynaforms/dynaforms_Editor', 'display:none', $Parameters, '', '' ); - $G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'dynaforms/dynaforms_XmlEditor', 'display:none', $XmlEditor, '', '' ); - $G_PUBLISH->AddContent( 'blank' ); + $G_PUBLISH->AddContent('xmlform', 'xmlform', 'dynaforms/dynaforms_Editor', 'display:none', $Parameters, '', ''); + $G_PUBLISH->AddContent('xmlform', 'xmlform', 'dynaforms/dynaforms_XmlEditor', 'display:none', $XmlEditor, '', ''); + $G_PUBLISH->AddContent('blank'); $i = 0; - $aFields = array (); - $aFields[] = array ('XMLNODE_NAME' => 'char','TYPE' => 'char','UP' => 'char','DOWN' => 'char' + $aFields = array(); + $aFields[] = array('XMLNODE_NAME' => 'char', 'TYPE' => 'char', 'UP' => 'char', 'DOWN' => 'char' ); - $oSession = new DBSession( new DBConnection( PATH_DYNAFORM . $this->file . '.xml', '', '', '', 'myxml' ) ); - $oDataset = $oSession->Execute( 'SELECT * FROM dynaForm WHERE NOT( XMLNODE_NAME = "" ) AND TYPE <> "pmconnection"' ); + $oSession = new DBSession(new DBConnection(PATH_DYNAFORM . $this->file . '.xml', '', '', '', 'myxml')); + $oDataset = $oSession->Execute('SELECT * FROM dynaForm WHERE NOT( XMLNODE_NAME = "" ) AND TYPE <> "pmconnection"'); $iMaximun = $oDataset->count(); while ($aRow = $oDataset->Read()) { - $aFields[] = array ('XMLNODE_NAME' => $aRow['XMLNODE_NAME'],'TYPE' => $aRow['TYPE'],'UP' => ($i > 0 ? G::LoadTranslation( 'ID_UP' ) : ''),'DOWN' => ($i < $iMaximun - 1 ? G::LoadTranslation( 'ID_DOWN' ) : ''),'row__' => ($i + 1) + $aFields[] = array('XMLNODE_NAME' => $aRow['XMLNODE_NAME'], 'TYPE' => $aRow['TYPE'], 'UP' => ($i > 0 ? G::LoadTranslation('ID_UP') : ''), 'DOWN' => ($i < $iMaximun - 1 ? G::LoadTranslation('ID_DOWN') : ''), 'row__' => ($i + 1) ); - $i ++; + $i++; break; } global $_DBArray; $_DBArray['fields'] = $aFields; $_SESSION['_DBArray'] = $_DBArray; - G::LoadClass( 'ArrayPeer' ); - $oCriteria = new Criteria( 'dbarray' ); - $oCriteria->setDBArrayTable( 'fields' ); + G::LoadClass('ArrayPeer'); + $oCriteria = new Criteria('dbarray'); + $oCriteria->setDBArrayTable('fields'); /** * *@Erik-> this is deprecated,. * (unuseful) $G_PUBLISH->AddContent('propeltable', 'paged-table', 'dynaforms/fields_List', $oCriteria, $Parameters, '', SYS_URI.'dynaforms/dynaforms_PagedTableAjax');** */ - $G_PUBLISH->AddContent( 'blank' ); - $G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'dynaforms/dynaforms_JSEditor', 'display:none', $JSEditor, '', '' ); + $G_PUBLISH->AddContent('blank'); + $G_PUBLISH->AddContent('xmlform', 'xmlform', 'dynaforms/dynaforms_JSEditor', 'display:none', $JSEditor, '', ''); } catch (Exception $e) { + } - $G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'dynaforms/dynaforms_Properties', 'display:none', $Properties, '', '' ); + $G_PUBLISH->AddContent('xmlform', 'xmlform', 'dynaforms/dynaforms_Properties', 'display:none', $Properties, '', ''); //for showHide tab option @Neyek - $G_PUBLISH->AddContent( 'blank' ); - $G_PUBLISH->AddContent( 'panel-tab', G::LoadTranslation( "ID_PREVIEW" ), $sName . '[3]', 'dynaformEditor.changeToPreview', 'dynaformEditor.saveCurrentView' ); - $G_PUBLISH->AddContent( 'panel-tab', G::LoadTranslation( "ID_XML" ), $sName . '[4]', 'dynaformEditor.changeToXmlCode', 'dynaformEditor.saveCurrentView' ); - $G_PUBLISH->AddContent( 'panel-tab', G::LoadTranslation( "ID_HTML" ), $sName . '[5]', 'dynaformEditor.changeToHtmlCode', 'dynaformEditor.saveCurrentView' ); - $G_PUBLISH->AddContent( 'panel-tab', G::LoadTranslation( "ID_FIELDS_LIST" ), $sName . '[6]', 'dynaformEditor.changeToFieldsList', 'dynaformEditor.saveCurrentView' ); - $G_PUBLISH->AddContent( 'panel-tab', G::LoadTranslation( "ID_JAVASCRIPTS" ), $sName . '[7]', 'dynaformEditor.changeToJavascripts', 'dynaformEditor.saveCurrentView' ); - $G_PUBLISH->AddContent( 'panel-tab', G::LoadTranslation( "ID_PROPERTIES" ), $sName . '[8]', 'dynaformEditor.changeToProperties', 'dynaformEditor.saveCurrentView' ); + $G_PUBLISH->AddContent('blank'); + $G_PUBLISH->AddContent('panel-tab', G::LoadTranslation("ID_PREVIEW"), $sName . '[3]', 'dynaformEditor.changeToPreview', 'dynaformEditor.saveCurrentView'); + $G_PUBLISH->AddContent('panel-tab', G::LoadTranslation("ID_XML"), $sName . '[4]', 'dynaformEditor.changeToXmlCode', 'dynaformEditor.saveCurrentView'); + $G_PUBLISH->AddContent('panel-tab', G::LoadTranslation("ID_HTML"), $sName . '[5]', 'dynaformEditor.changeToHtmlCode', 'dynaformEditor.saveCurrentView'); + $G_PUBLISH->AddContent('panel-tab', G::LoadTranslation("ID_FIELDS_LIST"), $sName . '[6]', 'dynaformEditor.changeToFieldsList', 'dynaformEditor.saveCurrentView'); + $G_PUBLISH->AddContent('panel-tab', G::LoadTranslation("ID_JAVASCRIPTS"), $sName . '[7]', 'dynaformEditor.changeToJavascripts', 'dynaformEditor.saveCurrentView'); + $G_PUBLISH->AddContent('panel-tab', G::LoadTranslation("ID_PROPERTIES"), $sName . '[8]', 'dynaformEditor.changeToProperties', 'dynaformEditor.saveCurrentView'); //for showHide tab option @Neyek - $G_PUBLISH->AddContent( 'panel-tab', G::LoadTranslation( "ID_CONDITIONS_EDITOR" ), $sName . '[9]', 'dynaformEditor.changeToShowHide', 'dynaformEditor.saveShowHide' ); - $G_PUBLISH->AddContent( 'panel-close' ); - $oHeadPublisher->addScriptFile( '/jscore/dynaformEditor/core/dynaformEditor.js' ); + $G_PUBLISH->AddContent('panel-tab', G::LoadTranslation("ID_CONDITIONS_EDITOR"), $sName . '[9]', 'dynaformEditor.changeToShowHide', 'dynaformEditor.saveShowHide'); + $G_PUBLISH->AddContent('panel-close'); + $oHeadPublisher->addScriptFile('/jscore/dynaformEditor/core/dynaformEditor.js'); //$oHeadPublisher->addScriptFile('/js/dveditor/core/dveditor.js'); //$oHeadPublisher->addScriptFile('/codepress/codepress.js',1); - $oHeadPublisher->addScriptFile( '/js/codemirror/js/codemirror.js', 1 ); + $oHeadPublisher->addScriptFile('/js/codemirror/js/codemirror.js', 1); - $oHeadPublisher->addScriptFile( '/js/grid/core/grid.js' ); - $oHeadPublisher->addScriptCode( ' + $oHeadPublisher->addScriptFile('/js/grid/core/grid.js'); + $oHeadPublisher->addScriptCode(' var DYNAFORM_URL="' . $Parameters['URL'] . '"; leimnud.event.add(window,"load",function(){ loadEditor(); }); - ' ); - $oHeadPublisher->addScriptCode( ' var jsMeta;' ); - G::RenderPage( "publish", 'blank' ); + '); + $oHeadPublisher->addScriptCode(' var jsMeta;'); + G::RenderPage("publish", 'blank'); } /** @@ -239,9 +239,9 @@ class dynaformEditor extends WebResource * @param string $file * @return string */ - function _getFilename ($file) + public function _getFilename($file) { - return (strcasecmp( substr( $file, - 5 ), '_tmp0' ) == 0) ? substr( $file, 0, strlen( $file ) - 5 ) : $file; + return (strcasecmp(substr($file, - 5), '_tmp0') == 0) ? substr($file, 0, strlen($file) - 5) : $file; } /** @@ -250,23 +250,25 @@ class dynaformEditor extends WebResource * @param string $onOff * @return void */ - function _setUseTemporalCopy ($onOff) + public function _setUseTemporalCopy($onOff) { - $file = self::_getFilename( $this->file ); + $file = self::_getFilename($this->file); if ($onOff) { $this->file = $file . '_tmp0'; - self::_setTmpData( array ('useTmpCopy' => true - ) ); - if (! file_exists( PATH_DYNAFORM . $file . '.xml' )) - $this->_createDefaultXmlForm( PATH_DYNAFORM . $file . '.xml' ); - //Creates a copy if it doesn't exist, else, use the old copy - if (! file_exists( PATH_DYNAFORM . $this->file . '.xml' )) - self::_copyFile( PATH_DYNAFORM . $file . '.xml', PATH_DYNAFORM . $this->file . '.xml' ); - if (! file_exists( PATH_DYNAFORM . $this->file . '.html' ) && file_exists( PATH_DYNAFORM . $file . '.html' )) - self::_copyFile( PATH_DYNAFORM . $file . '.html', PATH_DYNAFORM . $this->file . '.html' ); + self::_setTmpData(array('useTmpCopy' => true )); + if (!file_exists(PATH_DYNAFORM . $file . '.xml')) { + $this->_createDefaultXmlForm(PATH_DYNAFORM . $file . '.xml'); + } + //Creates a copy if it doesn't exist, else, use the old copy + if (!file_exists(PATH_DYNAFORM . $this->file . '.xml')) { + self::_copyFile(PATH_DYNAFORM . $file . '.xml', PATH_DYNAFORM . $this->file . '.xml'); + } + if (!file_exists(PATH_DYNAFORM . $this->file . '.html') && file_exists(PATH_DYNAFORM . $file . '.html')) { + self::_copyFile(PATH_DYNAFORM . $file . '.html', PATH_DYNAFORM . $this->file . '.html'); + } } else { $this->file = $file; - self::_setTmpData( array () ); + self::_setTmpData(array()); } } @@ -276,12 +278,12 @@ class dynaformEditor extends WebResource * @param $data * @return void */ - function _setTmpData ($data) + public function _setTmpData($data) { - G::verifyPath( PATH_C . 'dynEditor/', true ); - $fp = fopen( PATH_C . 'dynEditor/' . session_id() . '.php', 'w' ); - fwrite( $fp, '$tmpData=unserialize(\'' . addcslashes( serialize( $data ), '\\\'' ) . '\');' ); - fclose( $fp ); + G::verifyPath(PATH_C . 'dynEditor/', true); + $fp = fopen(PATH_C . 'dynEditor/' . session_id() . '.php', 'w'); + fwrite($fp, '$tmpData=unserialize(\'' . addcslashes(serialize($data), '\\\'') . '\');'); + fclose($fp); } /** @@ -290,12 +292,13 @@ class dynaformEditor extends WebResource * @param string $filename * @return array */ - function _getTmpData () + public function _getTmpData() { - $tmpData = array (); + $tmpData = array(); $file = PATH_C . 'dynEditor/' . session_id() . '.php'; - if (file_exists( $file )) - eval( implode( '', file( $file ) ) ); + if (file_exists($file)) { + eval(implode('', file($file))); + } return $tmpData; } @@ -306,12 +309,12 @@ class dynaformEditor extends WebResource * @param file $to * @return void */ - function _copyFile ($from, $to) + public function _copyFile($from, $to) { - $copy = implode( '', file( $from ) ); - $fcopy = fopen( $to, "w" ); - fwrite( $fcopy, $copy ); - fclose( $fcopy ); + $copy = implode('', file($from)); + $fcopy = fopen($to, "w"); + fwrite($fcopy, $copy); + fclose($fcopy); } } @@ -325,7 +328,6 @@ interface iDynaformEditorAjax * * @package workflow.engine.classes */ - class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax { @@ -335,9 +337,9 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax * @param var $post * @return void */ - function dynaformEditorAjax ($post) + public function dynaformEditorAjax($post) { - $this->_run( $post ); + $this->_run($post); } /** @@ -346,9 +348,9 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax * @param var $post * @return void */ - function _run ($post) + public function _run($post) { - WebResource::WebResource( $_SERVER['REQUEST_URI'], $post ); + WebResource::WebResource($_SERVER['REQUEST_URI'], $post); } /** @@ -357,37 +359,37 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax * @param object $A * @return ob_get_clean */ - function render_preview ($A) + public function render_preview($A) { ob_start(); - $file = G::decrypt( $A, URL_KEY ); + $file = G::decrypt($A, URL_KEY); global $G_PUBLISH; $G_PUBLISH = new Publisher(); $G_PUBLISH->publisherId = 'preview'; - $form = new Form( $file, PATH_DYNAFORM, SYS_LANG, true, $G_PUBLISH->publisherId ); - switch (basename( $form->template, '.html' )) { + $form = new Form($file, PATH_DYNAFORM, SYS_LANG, true, $G_PUBLISH->publisherId); + switch (basename($form->template, '.html')) { case 'grid': $template = 'grid'; - $aAux = array_keys( $form->fields ); - if (count( $aAux ) > 0) { - $aFields = (array_combine( $aAux, $aAux )); + $aAux = array_keys($form->fields); + if (count($aAux) > 0) { + $aFields = (array_combine($aAux, $aAux)); } else { $aFields = $aAux; } - if (is_array( $aFields )) { - foreach ($aFields as $key => $val) - $aFields[$key] = array (1 => "",2 => "",3 => "",4 => "",5 => "" - ); + if (is_array($aFields)) { + foreach ($aFields as $key => $val) { + $aFields[$key] = array(1 => "", 2 => "", 3 => "", 4 => "", 5 => ""); + } } break; default: $template = 'xmlform_' . $G_PUBLISH->publisherId; - $aFields = array ('__DYNAFORM_OPTIONS' => array ('PREVIOUS_STEP' => '#','NEXT_STEP' => '#','NEXT_STEP_LABEL' => G::loadTranslation( 'ID_NEXT_STEP' ),'PREVIOUS_ACTION' => 'return false;','NEXT_ACTION' => 'return false;' - ) + $aFields = array('__DYNAFORM_OPTIONS' => array('PREVIOUS_STEP' => '#', 'NEXT_STEP' => '#', 'NEXT_STEP_LABEL' => G::loadTranslation('ID_NEXT_STEP'), 'PREVIOUS_ACTION' => 'return false;', 'NEXT_ACTION' => 'return false;' + ) ); } - $G_PUBLISH->AddContent( 'dynaform', $template, $file, '', $aFields, '' ); - G::RenderPage( 'publish', 'raw' ); + $G_PUBLISH->AddContent('dynaform', $template, $file, '', $aFields, ''); + G::RenderPage('publish', 'raw'); return ob_get_clean(); } @@ -397,27 +399,27 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax * @param object $A * @return array */ - function render_htmledit ($A) + public function render_htmledit($A) { $script = ''; - $file = G::decrypt( $A, URL_KEY ); + $file = G::decrypt($A, URL_KEY); ob_start(); global $G_PUBLISH; - $form = new Form( $file, PATH_DYNAFORM, SYS_LANG, true ); + $form = new Form($file, PATH_DYNAFORM, SYS_LANG, true); $G_PUBLISH = new Publisher(); $G_PUBLISH->publisherId = ''; - $html = $this->get_htmlcode( $A ); - if (! is_string( $html )) { + $html = $this->get_htmlcode($A); + if (!is_string($html)) { $error = $html; $html = ''; } else { $error = 0; } - $HtmlEditor = array ('URL' => $A,'HTML' => $html + $HtmlEditor = array('URL' => $A, 'HTML' => $html ); - $G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'dynaforms/dynaforms_HtmlEditor', '', $HtmlEditor, '', '' ); - G::RenderPage( "publish", 'raw' ); - return array ('error' => $error,'html' => ob_get_clean() + $G_PUBLISH->AddContent('xmlform', 'xmlform', 'dynaforms/dynaforms_HtmlEditor', '', $HtmlEditor, '', ''); + G::RenderPage("publish", 'raw'); + return array('error' => $error, 'html' => ob_get_clean() ); } @@ -429,48 +431,49 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax * @param object $A * @return code html */ - function get_htmlcode ($A) + public function get_htmlcode($A) { try { $script = null; - $fileTmp = G::decrypt( $A, URL_KEY ); - $form = new Form( $fileTmp, PATH_DYNAFORM, SYS_LANG, true ); + $fileTmp = G::decrypt($A, URL_KEY); + $form = new Form($fileTmp, PATH_DYNAFORM, SYS_LANG, true); //Navigation Bar - $form->fields = G::array_merges( array ("__DYNAFORM_OPTIONS" => new XmlForm_Field_XmlMenu( new Xml_Node( "__DYNAFORM_OPTIONS", "complete", "", array ("type" => "xmlmenu","xmlfile" => "gulliver/dynaforms_Options" - ) ), SYS_LANG, PATH_XMLFORM, $form ) - ), $form->fields ); + $form->fields = G::array_merges(array("__DYNAFORM_OPTIONS" => new XmlForm_Field_XmlMenu(new Xml_Node("__DYNAFORM_OPTIONS", "complete", "", array("type" => "xmlmenu", "xmlfile" => "gulliver/dynaforms_Options" + )), SYS_LANG, PATH_XMLFORM, $form) + ), $form->fields); //Loads the stored HTML or the default Template if //it doesn't exist. - $filename = substr( $form->fileName, 0, - 3 ) . ($form->type === "xmlform" ? "" : "." . $form->type) . "html"; + $filename = substr($form->fileName, 0, - 3) . ($form->type === "xmlform" ? "" : "." . $form->type) . "html"; - if (! file_exists( $filename )) { - $html = $form->printTemplate( $form->template, $script ); + if (!file_exists($filename)) { + $html = $form->printTemplate($form->template, $script); } else { - $html = implode( "", file( $filename ) ); + $html = implode("", file($filename)); } /* - * It adds the new fields automatically at the bottom of the form. - * TODO: �TOP OR BOTTOM? - * Improving detection algorithm of new fields. - * Current: Do not check the fields that have already been reviewed (saving) - * Already checked the temporary file dynaforms editor. - */ + * It adds the new fields automatically at the bottom of the form. + * TODO: �TOP OR BOTTOM? + * Improving detection algorithm of new fields. + * Current: Do not check the fields that have already been reviewed (saving) + * Already checked the temporary file dynaforms editor. + */ $tmp = self::_getTmpData(); - if (! isset( $tmp['OLD_FIELDS'] )) - $tmp['OLD_FIELDS'] = array (); //var_dump($html);die; - $aAux = explode( '', $html ); + if (!isset($tmp['OLD_FIELDS'])) { + $tmp['OLD_FIELDS'] = array(); //var_dump($html);die; + } + $aAux = explode('', $html); foreach ($form->fields as $field) { - if ((strpos( $html, '{$form.' . $field->name . '}' ) === FALSE) && (strpos( $html, '{$' . $field->name . '}' ) === FALSE)) { + if ((strpos($html, '{$form.' . $field->name . '}') === false) && (strpos($html, '{$' . $field->name . '}') === false)) { //Aparantly is new (but could be a deleted or non visible like private type fields) - switch (strtolower( $field->type )) { + switch (strtolower($field->type)) { case 'private': case 'phpvariable': break; default: - if (array_search( $field->name, $tmp['OLD_FIELDS'] ) === false) { + if (array_search($field->name, $tmp['OLD_FIELDS']) === false) { //TOP $aAux[0] .= '
{$' . $field->name . '}' . '{$form.' . $field->name . '}'; //$html.='
{$'.$field->name.'}'.'{$form.'.$field->name.'}'; @@ -481,9 +484,9 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax } } } - self::_setTmpData( $tmp ); + self::_setTmpData($tmp); //$html=str_replace('{$form_className}','formDefault', $html ); - $html = str_replace( '{$form_className}', 'formDefault', $aAux[0] . '' ); + $html = str_replace('{$form_className}', 'formDefault', $aAux[0] . ''); return $html; } catch (Exception $e) { @@ -497,26 +500,26 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax * @param object $A * @return code html */ - function restore_html ($A) + public function restore_html($A) { $script = null; - $fileTmp = G::decrypt( $A, URL_KEY ); - $form = new Form( $fileTmp, PATH_DYNAFORM, SYS_LANG, true ); + $fileTmp = G::decrypt($A, URL_KEY); + $form = new Form($fileTmp, PATH_DYNAFORM, SYS_LANG, true); //Navigation Bar - $form->fields = G::array_merges( array ("__DYNAFORM_OPTIONS" => new XmlForm_Field_XmlMenu( new Xml_Node( "__DYNAFORM_OPTIONS", "complete", "", array ("type" => "xmlmenu","xmlfile" => "gulliver/dynaforms_Options" - ) ), SYS_LANG, PATH_XMLFORM, $form ) - ), $form->fields ); + $form->fields = G::array_merges(array("__DYNAFORM_OPTIONS" => new XmlForm_Field_XmlMenu(new Xml_Node("__DYNAFORM_OPTIONS", "complete", "", array("type" => "xmlmenu", "xmlfile" => "gulliver/dynaforms_Options" + )), SYS_LANG, PATH_XMLFORM, $form) + ), $form->fields); $form->enableTemplate = false; - $html = $form->printTemplate( $form->template, $script ); - $html = str_replace( '{$form_className}', 'formDefault', $html ); - if (file_exists( PATH_DYNAFORM . $fileTmp . '.html' )) { - unlink( PATH_DYNAFORM . $fileTmp . '.html' ); + $html = $form->printTemplate($form->template, $script); + $html = str_replace('{$form_className}', 'formDefault', $html); + if (file_exists(PATH_DYNAFORM . $fileTmp . '.html')) { + unlink(PATH_DYNAFORM . $fileTmp . '.html'); } - $fp = fopen( PATH_DYNAFORM . $fileTmp . '.html', 'w' ); - fwrite( $fp, $html ); - fclose( $fp ); + $fp = fopen(PATH_DYNAFORM . $fileTmp . '.html', 'w'); + fwrite($fp, $html); + fclose($fp); return $html; } @@ -527,15 +530,15 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax * @param object $A * @return array */ - function set_htmlcode ($A, $htmlcode) + public function set_htmlcode($A, $htmlcode) { try { - $file = G::decrypt( $A, URL_KEY ); - $form = new Form( $file, PATH_DYNAFORM, SYS_LANG, true ); - $filename = substr( $form->fileName, 0, - 3 ) . ($form->type === 'xmlform' ? '' : '.' . $form->type) . 'html'; - $fp = fopen( $filename, 'w' ); - fwrite( $fp, $htmlcode ); - fclose( $fp ); + $file = G::decrypt($A, URL_KEY); + $form = new Form($file, PATH_DYNAFORM, SYS_LANG, true); + $filename = substr($form->fileName, 0, - 3) . ($form->type === 'xmlform' ? '' : '.' . $form->type) . 'html'; + $fp = fopen($filename, 'w'); + fwrite($fp, $htmlcode); + fclose($fp); return 0; } catch (Exception $e) { return (array) $e; @@ -548,15 +551,15 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax * @param object $A * @return array */ - function get_xmlcode ($A) + public function get_xmlcode($A) { try { - $file = G::decrypt( $A, URL_KEY ); - $xmlcode = implode( '', file( PATH_DYNAFORM . $file . '.xml' ) ); - return array ("xmlcode" => $xmlcode,"error" => 0 + $file = G::decrypt($A, URL_KEY); + $xmlcode = implode('', file(PATH_DYNAFORM . $file . '.xml')); + return array("xmlcode" => $xmlcode, "error" => 0 ); } catch (Exception $e) { - return array ("xmlcode" => "","error" => (array) $e + return array("xmlcode" => "", "error" => (array) $e ); } } @@ -568,14 +571,14 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax * @param array $xmlcode * @return string */ - function set_xmlcode ($A, $xmlcode) + public function set_xmlcode($A, $xmlcode) { - $xmlcode = urldecode( $xmlcode ); - $file = G::decrypt( $A, URL_KEY ); - $xmlcode = str_replace( ' ', ' ', trim( $xmlcode ) ); - $fp = fopen( PATH_DYNAFORM . $file . '.xml', 'w' ); - fwrite( $fp, $xmlcode ); - fclose( $fp ); + $xmlcode = urldecode($xmlcode); + $file = G::decrypt($A, URL_KEY); + $xmlcode = str_replace(' ', ' ', trim($xmlcode)); + $fp = fopen(PATH_DYNAFORM . $file . '.xml', 'w'); + fwrite($fp, $xmlcode); + fclose($fp); return ""; } @@ -586,22 +589,23 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax * @param string $fieldName * @return array */ - function get_javascripts ($A, $fieldName) + public function get_javascripts($A, $fieldName) { try { - $file = G::decrypt( $A, URL_KEY ); - $form = new Form( $file, PATH_DYNAFORM, SYS_LANG, true ); - $aOptions = array (); + $file = G::decrypt($A, URL_KEY); + $form = new Form($file, PATH_DYNAFORM, SYS_LANG, true); + $aOptions = array(); $sCode = ''; foreach ($form->fields as $name => $value) { - if (strcasecmp( $value->type, "javascript" ) == 0) { - $aOptions[] = array ('key' => $name,'value' => $name + if (strcasecmp($value->type, "javascript") == 0) { + $aOptions[] = array('key' => $name, 'value' => $name ); - if ($name == $fieldName) + if ($name == $fieldName) { $sCode = $value->code; + } } } - return array ('aOptions' => $aOptions,'sCode' => $sCode + return array('aOptions' => $aOptions, 'sCode' => $sCode ); } catch (Exception $e) { return (array) $e; @@ -616,26 +620,26 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax * @param string $sCode * @return array */ - function set_javascript ($A, $fieldName, $sCode, $meta = '') + public function set_javascript($A, $fieldName, $sCode, $meta = '') { if ($fieldName == '___pm_boot_strap___') { return 0; } - $sCode = urldecode( $sCode ); + $sCode = urldecode($sCode); try { - $sCode = rtrim( $sCode ); - $file = G::decrypt( $A, URL_KEY ); - /*$dbc2 = new DBConnection( PATH_DYNAFORM . $file . '.xml' ,'','','','myxml' ); - $ses2 = new DBSession($dbc2); - $ses2->execute(G::replaceDataField("UPDATE dynaForm SET XMLNODE_VALUE = @@CODE WHERE XMLNODE_NAME = @@FIELDNAME ", array('FIELDNAME'=>$fieldName,'CODE'=>$sCode), "myxml" )); - */ + $sCode = rtrim($sCode); + $file = G::decrypt($A, URL_KEY); + /* $dbc2 = new DBConnection( PATH_DYNAFORM . $file . '.xml' ,'','','','myxml' ); + $ses2 = new DBSession($dbc2); + $ses2->execute(G::replaceDataField("UPDATE dynaForm SET XMLNODE_VALUE = @@CODE WHERE XMLNODE_NAME = @@FIELDNAME ", array('FIELDNAME'=>$fieldName,'CODE'=>$sCode), "myxml" )); + */ - G::LoadSystem( 'dynaformhandler' ); + G::LoadSystem('dynaformhandler'); - $dynaform = new dynaFormHandler( PATH_DYNAFORM . "{$file}.xml" ); - $dynaform->replace( $fieldName, $fieldName, Array ('type' => 'javascript','meta' => $meta,'#cdata' => $sCode - ) ); + $dynaform = new dynaFormHandler(PATH_DYNAFORM . "{$file}.xml"); + $dynaform->replace($fieldName, $fieldName, Array('type' => 'javascript', 'meta' => $meta, '#cdata' => $sCode + )); return 0; } catch (Exception $e) { @@ -650,25 +654,26 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax * @param string $DYN_UID * @return array */ - function get_properties ($A, $DYN_UID) + public function get_properties($A, $DYN_UID) { - $file = G::decrypt( $A, URL_KEY ); + $file = G::decrypt($A, URL_KEY); $tmp = self::_getTmpData(); - if (! (isset( $tmp['Properties'] ) && isset( $tmp['useTmpCopy'] ))) { + if (!(isset($tmp['Properties']) && isset($tmp['useTmpCopy']))) { $dynaform = new dynaform(); - $dynaform->load( $DYN_UID ); - $form = new Form( $file, PATH_DYNAFORM, SYS_LANG, true ); - $Properties = array ('A' => $A,'DYN_UID' => $dynaform->getDynUid(),'PRO_UID' => $dynaform->getProUid(),'DYN_TITLE' => $dynaform->getDynTitle(),'DYN_TYPE' => $dynaform->getDynType(),'DYN_DESCRIPTION' => $dynaform->getDynDescription(),'WIDTH' => $form->width, - //'ENABLETEMPLATE'=> $form->enableTemplate, - 'MODE' => $form->mode,'PRINTDYNAFORM' => $form->printdynaform,'ADJUSTGRIDSWIDTH' => $form->adjustgridswidth,'NEXTSTEPSAVE' => $form->nextstepsave + $dynaform->load($DYN_UID); + $form = new Form($file, PATH_DYNAFORM, SYS_LANG, true); + $Properties = array('A' => $A, 'DYN_UID' => $dynaform->getDynUid(), 'PRO_UID' => $dynaform->getProUid(), 'DYN_TITLE' => $dynaform->getDynTitle(), 'DYN_TYPE' => $dynaform->getDynType(), 'DYN_DESCRIPTION' => $dynaform->getDynDescription(), 'WIDTH' => $form->width, + //'ENABLETEMPLATE'=> $form->enableTemplate, + 'MODE' => $form->mode, 'PRINTDYNAFORM' => $form->printdynaform, 'ADJUSTGRIDSWIDTH' => $form->adjustgridswidth, 'NEXTSTEPSAVE' => $form->nextstepsave ); $tmp['Properties'] = $Properties; - self::_setTmpData( $tmp ); + self::_setTmpData($tmp); } else { - $form = new Form( $file, PATH_DYNAFORM, SYS_LANG, true ); + $form = new Form($file, PATH_DYNAFORM, SYS_LANG, true); $Properties = $tmp['Properties']; - if (! isset( $Properties['ENABLETEMPLATE'] )) + if (!isset($Properties['ENABLETEMPLATE'])) { $Properties['ENABLETEMPLATE'] = "0"; + } $Properties['WIDTH'] = $form->width; $Properties['MODE'] = $form->mode; } @@ -683,52 +688,52 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax * @param array $getFields * @return array */ - function set_properties ($A, $DYN_UID, $getFields) + public function set_properties($A, $DYN_UID, $getFields) { try { - $post = array (); - parse_str( $getFields, $post ); + $post = array(); + parse_str($getFields, $post); $Fields = $post['form']; //if (!isset($Fields['ENABLETEMPLATE'])) $Fields['ENABLETEMPLATE'] ="0"; - $file = G::decrypt( $A, URL_KEY ); + $file = G::decrypt($A, URL_KEY); $tmp = self::_getTmpData(); - if (! isset( $tmp['useTmpCopy'] )) { + if (!isset($tmp['useTmpCopy'])) { $dynaform = new dynaform(); - $dynaform->update( $Fields ); + $dynaform->update($Fields); } else { $tmp['Properties'] = $Fields; - self::_setTmpData( $tmp ); + self::_setTmpData($tmp); } - $dynaform = new dynaFormHandler( PATH_DYNAFORM . "{$file}.xml" ); - $dbc2 = new DBConnection( PATH_DYNAFORM . $file . '.xml', '', '', '', 'myxml' ); - $ses2 = new DBSession( $dbc2 ); + $dynaform = new dynaFormHandler(PATH_DYNAFORM . "{$file}.xml"); + $dbc2 = new DBConnection(PATH_DYNAFORM . $file . '.xml', '', '', '', 'myxml'); + $ses2 = new DBSession($dbc2); //if (!isset($Fields['ENABLETEMPLATE'])) $Fields['ENABLETEMPLATE'] ="0"; - /*if (isset($Fields['ENABLETEMPLATE'])) { - $ses2->execute(G::replaceDataField("UPDATE . SET ENABLETEMPLATE = @@ENABLETEMPLATE WHERE XMLNODE_NAME = 'dynaForm' ", $Fields)); - }*/ - if (isset( $Fields['DYN_TYPE'] )) { + /* if (isset($Fields['ENABLETEMPLATE'])) { + $ses2->execute(G::replaceDataField("UPDATE . SET ENABLETEMPLATE = @@ENABLETEMPLATE WHERE XMLNODE_NAME = 'dynaForm' ", $Fields)); + } */ + if (isset($Fields['DYN_TYPE'])) { //$ses2->execute( G::replaceDataField( "UPDATE . SET TYPE = @@DYN_TYPE WHERE XMLNODE_NAME = 'dynaForm' ", $Fields ) ); $dynaform->modifyHeaderAttribute('type', $Fields['DYN_TYPE']); } - if (isset( $Fields['WIDTH'] )) { + 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 ) ); $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 ) ); $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 ) ); $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 ) ); $dynaform->modifyHeaderAttribute('adjustgridswidth', $Fields['ADJUSTGRIDSWIDTH']); } @@ -745,10 +750,10 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax * @param object $A * @return string */ - function get_enabletemplate ($A) + public function get_enabletemplate($A) { - $file = G::decrypt( $A, URL_KEY ); - $form = new Form( $file, PATH_DYNAFORM, SYS_LANG, true ); + $file = G::decrypt($A, URL_KEY); + $form = new Form($file, PATH_DYNAFORM, SYS_LANG, true); return $form->enableTemplate; } @@ -759,15 +764,15 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax * @param string $value * @return string */ - function set_enabletemplate ($A, $value) + public function set_enabletemplate($A, $value) { - $file = G::decrypt( $A, URL_KEY ); + $file = G::decrypt($A, URL_KEY); $value = $value == "1" ? "1" : "0"; // $dbc2 = new DBConnection( PATH_DYNAFORM . $file . '.xml', '', '', '', 'myxml' ); // $ses2 = new DBSession( $dbc2 ); // $ses2->execute( "UPDATE . SET ENABLETEMPLATE = '$value'" ); - $dynaform = new dynaFormHandler( PATH_DYNAFORM . "{$file}.xml" ); + $dynaform = new dynaFormHandler(PATH_DYNAFORM . "{$file}.xml"); $dynaform->modifyHeaderAttribute('enabletemplate', $value); return $value; @@ -780,38 +785,39 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax * @param string $DYN_UID * @return array */ - function save ($A, $DYN_UID) + public function save($A, $DYN_UID) { try { $answer = 0; - $file = G::decrypt( $A, URL_KEY ); + $file = G::decrypt($A, URL_KEY); $tmp = self::_getTmpData(); - if (isset( $tmp['useTmpCopy'] )) { /*Save Register*/ + if (isset($tmp['useTmpCopy'])) { + /* Save Register */ $dynaform = new dynaform(); - $dynaform->update( $tmp['Properties'] ); - /*Save file*/ - $copy = implode( '', file( PATH_DYNAFORM . $file . '.xml' ) ); + $dynaform->update($tmp['Properties']); + /* Save file */ + $copy = implode('', file(PATH_DYNAFORM . $file . '.xml')); /* - * added by krlos carlos/a/colosa.com - * in here we are validation if a xmlform has a submit action - */ + * added by krlos carlos/a/colosa.com + * in here we are validation if a xmlform has a submit action + */ // if (!preg_match("/type=\"submit\"/",$copy) && !preg_match("/type=\"grid\"/",$copy) && !isset($_SESSION['submitAction']) ){ - if (! preg_match( "/type=\"submit\"/", $copy ) && ! preg_match( "/type=\"grid\"/", $copy )) { + if (!preg_match("/type=\"submit\"/", $copy) && !preg_match("/type=\"grid\"/", $copy)) { // $_SESSION['submitAction'] = 1; $answer = 'noSub'; } $copyHtml = false; - if (file_exists( PATH_DYNAFORM . $file . '.html' )) { - $copyHtml = implode( '', file( PATH_DYNAFORM . $file . '.html' ) ); + if (file_exists(PATH_DYNAFORM . $file . '.html')) { + $copyHtml = implode('', file(PATH_DYNAFORM . $file . '.html')); } - $file = dynaformEditor::_getFilename( $file ); - $fcopy = fopen( PATH_DYNAFORM . $file . '.xml', "w" ); - fwrite( $fcopy, $copy ); - fclose( $fcopy ); + $file = dynaformEditor::_getFilename($file); + $fcopy = fopen(PATH_DYNAFORM . $file . '.xml', "w"); + fwrite($fcopy, $copy); + fclose($fcopy); if ($copyHtml) { - $fcopy = fopen( PATH_DYNAFORM . $file . '.html', "w" ); - fwrite( $fcopy, $copyHtml ); - fclose( $fcopy ); + $fcopy = fopen(PATH_DYNAFORM . $file . '.html', "w"); + fwrite($fcopy, $copyHtml); + fclose($fcopy); } } else { //throw new Exception("It should not come here unless you have disabled the temporary copy."); @@ -828,29 +834,30 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax * @param object $A * @return array */ - function close ($A) + public function close($A) { try { /* - * we are unseting this variable. It's our control about to save the xmlfrom - */ + * we are unseting this variable. It's our control about to save the xmlfrom + */ // unset($_SESSION['submitAction']); - $file = G::decrypt( $A, URL_KEY ); + $file = G::decrypt($A, URL_KEY); //return(array('response'=>PATH_DYNAFORM . $file . '.xml')); /* Delete the temporal copy */ $tmp = self::_getTmpData(); $xmlFile = PATH_DYNAFORM . $file . '.xml'; $htmlFile = PATH_DYNAFORM . $file . '.html'; //return(array('response'=>$tmp['useTmpCopy'])); - if (isset( $tmp['useTmpCopy'] )) { + if (isset($tmp['useTmpCopy'])) { //return(array('response'=>PATH_DYNAFORM . $file . '.xml')); - if ($file !== dynaformEditor::_getFilename( $file )) { + if ($file !== dynaformEditor::_getFilename($file)) { // return(array('response'=>PATH_DYNAFORM . $file . '.xml')); - if (file_exists( $xmlFile )) { - unlink( $xmlFile ); + if (file_exists($xmlFile)) { + unlink($xmlFile); + } + if (file_exists($htmlFile)) { + unlink($htmlFile); } - if (file_exists( $htmlFile )) - unlink( $htmlFile ); } } return 0; @@ -866,45 +873,46 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax * @param string $DYN_UID * @return array */ - function is_modified ($A, $DYN_UID) + public function is_modified($A, $DYN_UID) { - $file = G::decrypt( $A, URL_KEY ); + $file = G::decrypt($A, URL_KEY); try { /* Compare Properties */ $dynaform = new dynaform(); - $dynaform->load( $DYN_UID ); - $form = new Form( $file, PATH_DYNAFORM, SYS_LANG, true ); - $sp = array ('A' => $A,'DYN_UID' => $dynaform->getDynUid(),'PRO_UID' => $dynaform->getProUid(),'DYN_TITLE' => $dynaform->getDynTitle(),'DYN_TYPE' => $dynaform->getDynType(),'DYN_DESCRIPTION' => $dynaform->getDynDescription(),'WIDTH' => $form->width,'ENABLETEMPLATE' => $form->enableTemplate,'MODE' => $form->mode + $dynaform->load($DYN_UID); + $form = new Form($file, PATH_DYNAFORM, SYS_LANG, true); + $sp = array('A' => $A, 'DYN_UID' => $dynaform->getDynUid(), 'PRO_UID' => $dynaform->getProUid(), 'DYN_TITLE' => $dynaform->getDynTitle(), 'DYN_TYPE' => $dynaform->getDynType(), 'DYN_DESCRIPTION' => $dynaform->getDynDescription(), 'WIDTH' => $form->width, 'ENABLETEMPLATE' => $form->enableTemplate, 'MODE' => $form->mode ); - $P = self::get_properties( $A, $DYN_UID ); - if (! isset( $P['DYN_TITLE'] )) { + $P = self::get_properties($A, $DYN_UID); + if (!isset($P['DYN_TITLE'])) { $P['DYN_TITLE'] = $sp['DYN_TITLE']; } - if (! isset( $P['DYN_TYPE'] )) { + if (!isset($P['DYN_TYPE'])) { $P['DYN_TYPE'] = $sp['DYN_TYPE']; } - if (! isset( $P['DYN_DESCRIPTION'] )) { + if (!isset($P['DYN_DESCRIPTION'])) { $P['DYN_DESCRIPTION'] = $sp['DYN_DESCRIPTION']; } - if (! isset( $P['WIDTH'] )) { + if (!isset($P['WIDTH'])) { $P['WIDTH'] = $sp['WIDTH']; } - if (! isset( $P['ENABLETEMPLATE'] )) { + if (!isset($P['ENABLETEMPLATE'])) { $P['ENABLETEMPLATE'] = $sp['ENABLETEMPLATE']; } - if (! isset( $P['MODE'] )) { + if (!isset($P['MODE'])) { $P['MODE'] = $sp['MODE']; } - $modPro = ($sp['DYN_TITLE'] != $P['DYN_TITLE']) || ($sp['DYN_TYPE'] != $P['DYN_TYPE']) || ($sp['DYN_DESCRIPTION'] != $P['DYN_DESCRIPTION']) /*|| - ($sp['WIDTH']!=$P['WIDTH']) || - ($sp['ENABLETEMPLATE']!=$P['ENABLETEMPLATE']) || - ($sp['MODE']!=$P['MODE'])*/; + $modPro = ($sp['DYN_TITLE'] != $P['DYN_TITLE']) || ($sp['DYN_TYPE'] != $P['DYN_TYPE']) || ($sp['DYN_DESCRIPTION'] != $P['DYN_DESCRIPTION']); + /* || + ($sp['WIDTH']!=$P['WIDTH']) || + ($sp['ENABLETEMPLATE']!=$P['ENABLETEMPLATE']) || + ($sp['MODE']!=$P['MODE']) */ /* Compare copies */ - $fileOrigen = dynaformEditor::_getFilename( $file ); - $copy = implode( '', file( PATH_DYNAFORM . $file . '.xml' ) ); - $origen = implode( '', file( PATH_DYNAFORM . $fileOrigen . '.xml' ) ); - $copyHTML = file_exists( PATH_DYNAFORM . $file . '.html' ) ? implode( '', file( PATH_DYNAFORM . $file . '.html' ) ) : false; - $origenHTML = file_exists( PATH_DYNAFORM . $fileOrigen . '.html' ) ? implode( '', file( PATH_DYNAFORM . $fileOrigen . '.html' ) ) : false; + $fileOrigen = dynaformEditor::_getFilename($file); + $copy = implode('', file(PATH_DYNAFORM . $file . '.xml')); + $origen = implode('', file(PATH_DYNAFORM . $fileOrigen . '.xml')); + $copyHTML = file_exists(PATH_DYNAFORM . $file . '.html') ? implode('', file(PATH_DYNAFORM . $file . '.html')) : false; + $origenHTML = file_exists(PATH_DYNAFORM . $fileOrigen . '.html') ? implode('', file(PATH_DYNAFORM . $fileOrigen . '.html')) : false; $modFile = ($copy !== $origen) || ($origenHTML && ($copyHTML !== $origenHTML)); //Return //return array("*message"=>sprintf("%s, (%s= %s %s):", $modPro?"1":"0" , $modFile?"1":"0", ($copy!==$origen)?"1":"0" , ($origenHTML && ($copyHTML!==$origenHTML))?"1":"0" )); @@ -915,4 +923,4 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax } } } -?> + \ No newline at end of file diff --git a/workflow/engine/methods/dynaforms/fields_Save.php b/workflow/engine/methods/dynaforms/fields_Save.php index eeb379965..cd011bac8 100755 --- a/workflow/engine/methods/dynaforms/fields_Save.php +++ b/workflow/engine/methods/dynaforms/fields_Save.php @@ -1,4 +1,5 @@ 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']); - if (!(isset($_POST['form']['PME_A']) && $_POST['form']['PME_A']!=='')) return; +$type = strtolower($_POST['form']['PME_TYPE']); +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'] == '') { - $_POST['form']['PME_REQUIRED'] = 0; + $_POST['form']['PME_REQUIRED'] = 0; } - } - else { +} else { $_POST['form']['PME_REQUIRED'] = 0; - } +} - if (isset($_POST['form']['PME_READONLY'])) { +if (isset($_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; - } +} - if (isset($_POST['form']['PME_SAVELABEL'])) { +if (isset($_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; - } - $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']; +} +$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']; // $A = $_POST['form']['PME_A']; $fieldName = $_POST['form']['PME_XMLNODE_NAME']; - $pmeCode = $_POST['form']['PME_CODE']; + $pmeCode = $_POST['form']['PME_CODE']; $_POST['form']['PME_CODE'] = ''; -// $pmeCode = str_replace("'", "''", $pmeCode); -// $pmeCode = str_replace('"', '""', $pmeCode); -// $pmeCode = preg_replace("/\)\s*\n/", ") //\n", $pmeCode); -// $_POST['form']['PME_CODE'] = $pmeCode; - } + // $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'); +$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 (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); +if (file_exists(PATH_XMLFORM . 'dynaforms/fields/' . $type . '.xml')) { + $form = new Form('dynaforms/fields/' . $type, PATH_XMLFORM); //TODO: Verify why validatePost removes PME_XMLGRID. - $isGrid=isset($_POST['form']['PME_XMLGRID']); - if ($isGrid) $xmlGrid=$_POST['form']['PME_XMLGRID']; + $isGrid = isset($_POST['form']['PME_XMLGRID']); + if ($isGrid) { + $xmlGrid = $_POST['form']['PME_XMLGRID']; + } //$form->validatePost(); - if ($isGrid) $_POST['form']['PME_XMLGRID']=$xmlGrid; - if ($type==='checkbox') { + if ($isGrid) { + $_POST['form']['PME_XMLGRID'] = $xmlGrid; + } + if ($type === 'checkbox') { // added by Gustavo Cruz - if ($_POST['form']['PME_DEFAULTVALUE']==="1") { - $_POST['form']['PME_DEFAULTVALUE']=$_POST['form']['PME_VALUE']; + if ($_POST['form']['PME_DEFAULTVALUE'] === "1") { + $_POST['form']['PME_DEFAULTVALUE'] = $_POST['form']['PME_VALUE']; } else { - $_POST['form']['PME_DEFAULTVALUE']=$_POST['form']['PME_FALSEVALUE']; + $_POST['form']['PME_DEFAULTVALUE'] = $_POST['form']['PME_FALSEVALUE']; } // end added code -// 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']; -// } + // 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']; + // } } - if ($type==='grid') { - if (!isset($_POST['form']['PME_ADDROW'])) { - $_POST['form']['PME_ADDROW'] = '0'; - } - if (!isset($_POST['form']['PME_DELETEROW'])) { - $_POST['form']['PME_DELETEROW'] = '0'; - } + if ($type === 'grid') { + if (!isset($_POST['form']['PME_ADDROW'])) { + $_POST['form']['PME_ADDROW'] = '0'; + } + if (!isset($_POST['form']['PME_DELETEROW'])) { + $_POST['form']['PME_DELETEROW'] = '0'; + } } - if ($type==='dropdown' || $type==='listbox' ) { - if(isset($_POST['form']['PME_OPTIONS'][1])){ - if($_POST['form']['PME_OPTIONS']['1']['NAME'] === "" && - $_POST['form']['PME_OPTIONS']['1']['LABEL'] === ""){ - unset($_POST['form']['PME_OPTIONS']); - } - } + if ($type === 'dropdown' || $type === 'listbox') { + if (isset($_POST['form']['PME_OPTIONS'][1])) { + if ($_POST['form']['PME_OPTIONS']['1']['NAME'] === "" && + $_POST['form']['PME_OPTIONS']['1']['LABEL'] === "") { + 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; + } +} +$_POST['form'] = $res; - } - foreach($_POST['form'] as $key => $value){ - if (substr($key,0,4)==='PME_') - $res[substr($key,4)]=$value; - else - $res[$key]=$value; - } - $_POST['form']=$res; +$dbc = new DBConnection(PATH_DYNAFORM . $file . '.xml', '', '', '', 'myxml'); +$ses = new DBSession($dbc); - $dbc = new DBConnection( PATH_DYNAFORM . $file . '.xml' ,'','','','myxml' ); - $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'] = 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(); - if (isset($attributes['LABEL'])) $labels = array ( SYS_LANG => $attributes['LABEL'] ); +$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']); +unset($attributes['A']); +unset($attributes['ACCEPT']); +unset($attributes['LABEL']); +unset($attributes['PRO_UID']); - $options = NULL; - foreach($attributes as $key => $value ) { - if ($key==='OPTIONS') { - 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']; +$options = null; +foreach ($attributes as $key => $value) { + if ($key === 'OPTIONS') { + 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]; + } + } */ } - } - /*$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]; - } - }*/ } - } } else { - if (is_array($value)){ - //Is a list: - if (is_string(reset($value))) { - $attributes[$key] = implode(',',$value); - } else { - //Is a grid. + if (is_array($value)) { + //Is a list: + if (is_string(reset($value))) { + $attributes[$key] = implode(',', $value); + } else { + //Is a grid. + } } - } } - } - unset($attributes['VALIDATE_NAME']); - $fields->setFileName(PATH_DYNAFORM . $file . '.xml' ); +} +unset($attributes['VALIDATE_NAME']); +$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; - } - } +$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 ); +$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'], - 'TYPE' => $aRow['TYPE'], - 'UP' => ($i > 0 ? G::LoadTranslation('ID_UP') : ''), - 'DOWN' => ($i < $iMaximun-1 ? G::LoadTranslation('ID_DOWN') : ''), - 'row__' => ($i + 1)); +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'], + 'TYPE' => $aRow['TYPE'], + 'UP' => ($i > 0 ? G::LoadTranslation('ID_UP') : ''), + 'DOWN' => ($i < $iMaximun - 1 ? G::LoadTranslation('ID_DOWN') : ''), + 'row__' => ($i + 1)); $i++; - } - global $_DBArray; - $_DBArray['fields'] = $aFields; - $_SESSION['_DBArray'] = $_DBArray; +} +global $_DBArray; +$_DBArray['fields'] = $aFields; +$_SESSION['_DBArray'] = $_DBArray; - // Additions to javascript - if(isset($sType) && $sType === 'javascript'){ - $sCode = urlencode($pmeCode); +// Additions to javascript +if (isset($sType) && $sType === 'javascript') { + $sCode = urlencode($pmeCode); $editor = new dynaformEditorAjax($_POST); $editor->set_javascript($A, $fieldName, $sCode); - } -?> +} + \ No newline at end of file