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

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

View File

@@ -1,4 +1,5 @@
<?php
/**
* class.dynaformhandler.php
* @package gulliver.system
@@ -30,9 +31,9 @@
* @description This class is a Dynaform handler for modify directly into file
* @package gulliver.system
*/
class dynaFormHandler
{
private $xmlfile;
private $dom;
private $root;
@@ -43,30 +44,34 @@ class dynaFormHandler
* @param string $file
* @return void
*/
function __construct($file=null)
public function __construct($file = null)
{
if( !isset($file) )
if (!isset($file)) {
throw new Exception('[Class dynaFormHandler] ERROR: xml file was not set!!');
}
$this->xmlfile = $file;
$this->load();
}
function 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
} 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;
public function reload()
{
$this->dom = null;
$this->load();
}
@@ -75,7 +80,7 @@ class dynaFormHandler
* @access public
* @return void
*/
function __cloneEmpty()
public function __cloneEmpty()
{
$xPath = new DOMXPath($this->dom);
$nodeList = $xPath->query('/dynaForm/*');
@@ -92,11 +97,13 @@ class dynaFormHandler
* @param string $op
* @return void
*/
function toString($op='')
public function toString($op = '')
{
switch ($op) {
case 'html': return htmlentities(file_get_contents($this->xmlfile));
break;
default: return file_get_contents($this->xmlfile);
break;
}
}
@@ -106,7 +113,7 @@ class dynaFormHandler
* @param string $nodename
* @return void
*/
function getNode($nodename)
public function getNode($nodename)
{
return $this->root->getElementsByTagName($nodename)->item(0);
}
@@ -117,7 +124,8 @@ class dynaFormHandler
* @param object $node
* @return object
*/
function setNode($node){
public function setNode($node)
{
$newnode = $this->root->appendChild($node);
$this->save();
return $newnode;
@@ -132,9 +140,15 @@ class dynaFormHandler
* @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)
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);
}
@@ -159,6 +173,35 @@ class dynaFormHandler
$this->save();
}
private function hasChild($p)
{
if ($p->hasChildNodes()) {
foreach ($p->childNodes as $c) {
if ($c->nodeType == XML_ELEMENT_NODE) {
return true;
}
}
}
return false;
}
private function getChildNode($x)
{
$chidNode = array();
foreach ($x->childNodes as $p) {
if ($this->hasChild($p)) {
getChildNode($p);
} else {
if ($p->nodeType == XML_ELEMENT_NODE) {
$chidNode[] = array('node' => $x->nodeName, 'nodeName' => $p->nodeName,
'name' => $p->getAttribute('name'), 'nodeValue' => $p->nodeValue);
}
}
}
return array($x->nodeName => $chidNode);
}
/**
* Function replace
* @access public
@@ -169,32 +212,50 @@ class dynaFormHandler
* @param array $childs_childs
* @return void
*/
function replace($replaced, $name, $attributes, $childs=null, $childs_childs=null)
public function replace($replaced, $name, $attributes, $childs = null, $childs_childs = null)
{
$chidNode = array();
$element = $this->root->getElementsByTagName($replaced)->item(0);
$this->root->replaceChild($this->dom->createElement($name), $element);
$newnode = $element = $this->root->getElementsByTagName($name)->item(0);
// $newnode = $element = $this->root->getElementsByTagName($name)->item(0);
$newnode = $this->root->getElementsByTagName($name)->item(0);
if (isset($attributes['#text'])) {
$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($childs as $child_name => $child_text) {
$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));
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']));
@@ -204,19 +265,35 @@ class dynaFormHandler
}
}
}
} else {
foreach ($chidNode as $valueNode) {
if (array_key_exists($child_name, $valueNode)) {
foreach ($valueNode[$child_name] as $valOption) {
$ccmode = $newnode_child->appendChild($this->dom->createElement($valOption['nodeName']));
$ccmode->appendChild($this->dom->createTextNode($valOption['nodeValue']));
$ccmode->setAttribute('name', $valOption['name']);
}
} else if( isset($childs) ){
}
}
}
$newnode->appendChild($this->dom->createTextNode("\n"));
}
} else {
if (isset($childs)) {
$text_node = $childs;
$newnode->appendChild($this->dom->createTextNode($text_node));
}
}
$this->save();
}
/**
* Function save
* @param string $fname
* @return void
*/
function save($fname=null)
public function save($fname = null)
{
if (!is_writable($this->xmlfile)) {
throw new Exception("The file {$this->xmlfile} is not writeable!");
@@ -234,7 +311,7 @@ class dynaFormHandler
* Function fixXmlFile
* @return void
*/
function fixXmlFile()
public function fixXmlFile()
{
$newxml = '';
$content = file($this->xmlfile);
@@ -252,19 +329,24 @@ class dynaFormHandler
* @param string $att_value
* @return void
*/
function setHeaderAttribute($att_name, $att_value)
public function setHeaderAttribute($att_name, $att_value)
{
$this->root->setAttribute($att_name, $att_value);
$this->save();
}
public 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)
public function modifyHeaderAttribute($att_name, $att_new_value)
{
$this->root->removeAttribute($att_name);
$this->root->setAttribute($att_name, $att_new_value);
@@ -278,7 +360,7 @@ class dynaFormHandler
* @param string $att_new_value
* @return void
*/
function updateAttribute($node_name, $att_name, $att_new_value)
public function updateAttribute($node_name, $att_name, $att_new_value)
{
$xpath = new DOMXPath($this->dom);
$nodeList = $xpath->query("/dynaForm/$node_name");
@@ -293,7 +375,7 @@ class dynaFormHandler
* @param string $v
* @return void
*/
function remove($v)
public function remove($v)
{
if (!is_array($v)) {
$av[0] = $v;
@@ -323,7 +405,7 @@ class dynaFormHandler
* @param string $node_name
* @return boolean
*/
function nodeExists($node_name)
public function nodeExists($node_name)
{
$xpath = new DOMXPath($this->dom);
$nodeList = $xpath->query("/dynaForm/$node_name");
@@ -341,7 +423,7 @@ class dynaFormHandler
* @param string $selected_node
* @return void
*/
function moveUp($selected_node)
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
@@ -374,7 +456,7 @@ class dynaFormHandler
* @param string $selected_node
* @return void
*/
function moveDown($selected_node)
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
@@ -415,7 +497,7 @@ class dynaFormHandler
* @param array $aFilter
* @return array
*/
function getFields( $aFilter = Array() )
public function getFields($aFilter = Array())
{
$xpath = new DOMXPath($this->dom);
$nodeList = $xpath->query("/dynaForm/*");
@@ -452,7 +534,7 @@ class dynaFormHandler
* @param array $aFilter
* @return array
*/
function getFieldNames( $aFilter = Array() )
public function getFieldNames($aFilter = Array())
{
$aList = $this->getFields($aFilter);
$aFieldNames = Array();
@@ -462,10 +544,9 @@ class dynaFormHandler
return $aFieldNames;
}
//
function addChilds($name, $childs, $childs_childs=null)
public function addChilds($name, $childs, $childs_childs = null)
{
//
$xpath = new DOMXPath($this->dom);
$nodeList = @$xpath->query("/dynaForm/$name");
if (!$nodeList) {
@@ -482,16 +563,17 @@ class dynaFormHandler
$nodeList = $xpath->query("/dynaForm/$name/$child_name");
if( $nodeList->length == 0 ){ //the node doesn't exist
if ($nodeList->length == 0) {
//the node doesn't exist
//$newnode_child
$childNode = $element->appendChild($this->dom->createElement($child_name));
$childNode->appendChild($this->dom->createCDATASection($child_text));
} else { // the node already exists
} else {
// the node already exists
//update its value
$childNode = $element->getElementsByTagName($child_name)->item(0);
//
if($child_text !== NULL){
if ($child_text !== null) {
$xnode = $this->dom->createElement($childNode->nodeName);
$xnode->appendChild($this->dom->createCDATASection($child_text));
@@ -517,8 +599,8 @@ class dynaFormHandler
$this->save();
}
function addOrUpdateChild($xnode, $childName, $childValue, $childAttributes){
public function addOrUpdateChild($xnode, $childName, $childValue, $childAttributes)
{
$newNode = $this->dom->createElement($childName);
$newNode->appendChild($this->dom->createCDATASection($childValue));
@@ -533,11 +615,12 @@ class dynaFormHandler
break;
}
}
} else
} else {
$xnode->appendChild($newNode);
}
}
function getArray($node, $attributes = null)
public function getArray($node, $attributes = null)
{
$array = false;
$array['__nodeName__'] = $node->nodeName;
@@ -547,9 +630,10 @@ class dynaFormHandler
if ($node->hasAttributes()) {
if (isset($attributes)) {
foreach ($attributes as $attr) {
if( $node->hasAttribute($attr) )
if ($node->hasAttribute($attr)) {
$array[$attr] = $node->getAttribute($attr);
}
}
} else {
foreach ($node->attributes as $attr) {
$array[$attr->nodeName] = $attr->nodeValue;
@@ -558,9 +642,9 @@ class dynaFormHandler
}
if ($node->hasChildNodes()) {
if ($node->childNodes->length == 0)
if ($node->childNodes->length == 0) {
$return;
else {
} else {
foreach ($node->childNodes as $childNode) {
$childNode->normalize();
//if ($childNode->nodeType == XML_TEXT_NODE || $childNode->nodeType == XML_CDATA_SECTION_NODE) {
@@ -578,3 +662,4 @@ class dynaFormHandler
return $array;
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* class.dynaFormField.php
*
@@ -24,8 +25,8 @@
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
*
*/
G::LoadClass('xmlDb');
G::LoadSystem('dynaformhandler');
/**
* Dynaform Field - DynaformField class
@@ -35,13 +36,25 @@ G::LoadClass( 'xmlDb' );
class DynaFormField extends DBTable
{
private $fileName;
public function getFileName()
{
return $this->fileName;
}
public function setFileName($fileName)
{
$this->fileName = $fileName;
}
/**
* Function SetTo
*
* @param string $objConnection
* @return void
*/
function SetTo ($objConnection)
public function SetTo($objConnection)
{
DBTable::SetTo($objConnection, 'dynaForm', array('XMLNODE_NAME'
));
@@ -53,7 +66,7 @@ class DynaFormField extends DBTable
* @param string $sUID
* @return void
*/
function Load ($sUID)
public function Load($sUID)
{
parent::Load($sUID);
if (is_array($this->Fields)) {
@@ -71,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();
@@ -85,7 +98,7 @@ 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') {
@@ -113,9 +126,10 @@ class DynaFormField extends DBTable
*/
if ($this->is_new) {
foreach ($this->Fields as $key => $value) {
if ($value == "")
if ($value == "") {
unset($this->Fields[$key]);
}
}
} else {
$this->Fields['XMLNODE_NAME'] = $Fields['XMLNODE_NAME_OLD'];
}
@@ -165,16 +179,72 @@ class DynaFormField extends DBTable
}
}
public function saveField($Fields, $attributes = array(), $options = array())
{
$dynaform = new dynaFormHandler($this->getFileName());
if ($Fields['TYPE'] === 'javascript') {
$Fields['XMLNODE_VALUE'] = $Fields['CODE'];
unset($Fields['CODE']);
$attributes = array();
}
if ($Fields['XMLNODE_NAME_OLD'] == '') {
if (($Fields['XMLNODE_NAME'][0] == '1') || ($Fields['XMLNODE_NAME'][0] == '2') || ($Fields['XMLNODE_NAME'][0] == '3') || ($Fields['XMLNODE_NAME'][0] == '4') || ($Fields['XMLNODE_NAME'][0] == '5') || ($Fields['XMLNODE_NAME'][0] == '6') || ($Fields['XMLNODE_NAME'][0] == '7') || ($Fields['XMLNODE_NAME'][0] == '8') || ($Fields['XMLNODE_NAME'][0] == '9') || ($Fields['XMLNODE_NAME'][0] == '10')) {
$Fields['XMLNODE_NAME'] = '_' . $Fields['XMLNODE_NAME'];
}
$res = $this->_dbses->Execute('SELECT * FROM dynaForm WHERE XMLNODE_NAME="' . $Fields['XMLNODE_NAME'] . '"');
} else {
if (($Fields['XMLNODE_NAME_OLD'][0] == '1') || ($Fields['XMLNODE_NAME_OLD'][0] == '2') || ($Fields['XMLNODE_NAME_OLD'][0] == '3') || ($Fields['XMLNODE_NAME_OLD'][0] == '4') || ($Fields['XMLNODE_NAME_OLD'][0] == '5') || ($Fields['XMLNODE_NAME_OLD'][0] == '6') || ($Fields['XMLNODE_NAME_OLD'][0] == '7') || ($Fields['XMLNODE_NAME_OLD'][0] == '8') || ($Fields['XMLNODE_NAME_OLD'][0] == '9') || ($Fields['XMLNODE_NAME_OLD'][0] == '10')) {
$Fields['XMLNODE_NAME_OLD'] = '_' . $Fields['XMLNODE_NAME_OLD'];
}
$res = $this->_dbses->Execute('SELECT * FROM dynaForm WHERE XMLNODE_NAME="' . $Fields['XMLNODE_NAME_OLD'] . '"');
}
$this->is_new = ($res->count() == 0);
$this->Fields = $Fields;
unset($this->Fields['XMLNODE_NAME_OLD']);
/*
* MPD-10 to create fields that do not appear many attributes, only the main ones?
* The show those who are not white
*/
if ($this->is_new) {
foreach ($this->Fields as $key => $value) {
if ($value == "") {
unset($this->Fields[$key]);
}
}
} else {
$this->Fields['XMLNODE_NAME'] = $Fields['XMLNODE_NAME_OLD'];
}
// parent::Save();
if (trim($Fields['XMLNODE_VALUE']) != "") {
$attributes['#cdata'] = $Fields['XMLNODE_VALUE'];
}
$aOptions = array();
if (isset($Fields['OPTIONS']) && is_array($Fields['OPTIONS'])) {
foreach ($Fields['OPTIONS'] as $key => $value) {
$aOptions[] = Array('name' => 'option', 'value' => $value['LABEL'],
'attributes' => array('name' => $value['NAME']));
}
}
if ($this->is_new) {
// Create a new field
$dynaform->add($Fields['XMLNODE_NAME'], $attributes, $options, $aOptions);
} else {
$dynaform->replace($Fields['XMLNODE_NAME_OLD'], $Fields['XMLNODE_NAME'], $attributes, $options, $aOptions);
}
}
/**
* Verify if is New the Field
*
* @return array
*/
function isNew ()
public function isNew()
{
$res = $this->_dbses->Execute('SELECT * FROM dynaForm WHERE XMLNODE_NAME="' . $this->Fields['XMLNODE_NAME'] . '"');
return ($res->count() == 0);
}
}
?>

View File

@@ -1,4 +1,5 @@
<?php
/**
* class.dynaformEditor.php
*
@@ -23,7 +24,6 @@
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
*/
/**
* Created on 21/12/2007
* Dynaform - Dynaform class
@@ -31,27 +31,28 @@
* @copyright 2007 COLOSA
* @author David Callizaya <davidsantos@colosa.com>
*/
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::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,7 +79,7 @@ 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']);
//'title' => G::LoadTranslation('ID_DYNAFORM_EDITOR').' - ['.$this->title.']',
@@ -92,7 +91,7 @@ class dynaformEditor extends WebResource
* @param string $filename
* @return void
*/
function _createDefaultXmlForm ($fileName)
public function _createDefaultXmlForm($fileName)
{
//Create the default Dynaform
$sampleForm = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
@@ -128,7 +127,7 @@ class dynaformEditor extends WebResource
*
* @return void
*/
function _render ()
public function _render()
{
global $G_PUBLISH;
$script = '';
@@ -206,6 +205,7 @@ class dynaformEditor extends WebResource
$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, '', '');
//for showHide tab option @Neyek
@@ -239,7 +239,7 @@ 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;
}
@@ -250,20 +250,22 @@ class dynaformEditor extends WebResource
* @param string $onOff
* @return void
*/
function _setUseTemporalCopy ($onOff)
public function _setUseTemporalCopy($onOff)
{
$file = self::_getFilename($this->file);
if ($onOff) {
$this->file = $file . '_tmp0';
self::_setTmpData( array ('useTmpCopy' => true
) );
if (! file_exists( PATH_DYNAFORM . $file . '.xml' ))
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' ))
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' ))
}
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());
@@ -276,7 +278,7 @@ 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');
@@ -290,12 +292,13 @@ class dynaformEditor extends WebResource
* @param string $filename
* @return array
*/
function _getTmpData ()
public function _getTmpData()
{
$tmpData = array();
$file = PATH_C . 'dynEditor/' . session_id() . '.php';
if (file_exists( $file ))
if (file_exists($file)) {
eval(implode('', file($file)));
}
return $tmpData;
}
@@ -306,7 +309,7 @@ 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");
@@ -325,7 +328,6 @@ interface iDynaformEditorAjax
*
* @package workflow.engine.classes
*/
class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax
{
@@ -335,7 +337,7 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax
* @param var $post
* @return void
*/
function dynaformEditorAjax ($post)
public function dynaformEditorAjax($post)
{
$this->_run($post);
}
@@ -346,7 +348,7 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax
* @param var $post
* @return void
*/
function _run ($post)
public function _run($post)
{
WebResource::WebResource($_SERVER['REQUEST_URI'], $post);
}
@@ -357,7 +359,7 @@ 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);
@@ -375,9 +377,9 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax
$aFields = $aAux;
}
if (is_array($aFields)) {
foreach ($aFields as $key => $val)
$aFields[$key] = array (1 => "",2 => "",3 => "",4 => "",5 => ""
);
foreach ($aFields as $key => $val) {
$aFields[$key] = array(1 => "", 2 => "", 3 => "", 4 => "", 5 => "");
}
}
break;
default:
@@ -397,7 +399,7 @@ 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);
@@ -429,7 +431,7 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax
* @param object $A
* @return code html
*/
function get_htmlcode ($A)
public function get_htmlcode($A)
{
try {
$script = null;
@@ -459,11 +461,12 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax
* Already checked the temporary file dynaforms editor.
*/
$tmp = self::_getTmpData();
if (! isset( $tmp['OLD_FIELDS'] ))
if (!isset($tmp['OLD_FIELDS'])) {
$tmp['OLD_FIELDS'] = array(); //var_dump($html);die;
}
$aAux = explode('</form>', $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)) {
case 'private':
@@ -497,7 +500,7 @@ 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);
@@ -527,7 +530,7 @@ 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);
@@ -548,7 +551,7 @@ 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);
@@ -568,7 +571,7 @@ 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);
@@ -586,7 +589,7 @@ 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);
@@ -597,10 +600,11 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax
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
);
} catch (Exception $e) {
@@ -616,7 +620,7 @@ 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;
@@ -650,7 +654,7 @@ 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);
$tmp = self::_getTmpData();
@@ -667,8 +671,9 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax
} else {
$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,7 +688,7 @@ 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();
@@ -699,30 +704,40 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax
$tmp['Properties'] = $Fields;
self::_setTmpData($tmp);
}
$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['WIDTH'] )) {
$ses2->execute( G::replaceDataField( "UPDATE . SET WIDTH = @@WIDTH WHERE XMLNODE_NAME = 'dynaForm' ", $Fields ) );
}
/* 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 ) );
//$ses2->execute( G::replaceDataField( "UPDATE . SET TYPE = @@DYN_TYPE WHERE XMLNODE_NAME = 'dynaForm' ", $Fields ) );
$dynaform->modifyHeaderAttribute('type', $Fields['DYN_TYPE']);
}
if (isset($Fields['WIDTH'])) {
// $ses2->execute( G::replaceDataField( "UPDATE . SET WIDTH = @@WIDTH WHERE XMLNODE_NAME = 'dynaForm' ", $Fields ) );
$dynaform->modifyHeaderAttribute('width', $Fields['WIDTH']);
//g::pr($dynaform->getHeaderAttribute('width'));
}
if (isset($Fields['MODE'])) {
$ses2->execute( G::replaceDataField( "UPDATE . SET MODE = @@MODE WHERE XMLNODE_NAME = 'dynaForm' ", $Fields ) );
// $ses2->execute( G::replaceDataField( "UPDATE . SET MODE = @@MODE WHERE XMLNODE_NAME = 'dynaForm' ", $Fields ) );
$dynaform->modifyHeaderAttribute('mode', $Fields['MODE']);
}
if (isset($Fields['NEXTSTEPSAVE'])) {
$ses2->execute( G::replaceDataField( "UPDATE . SET NEXTSTEPSAVE = @@NEXTSTEPSAVE WHERE XMLNODE_NAME = 'dynaForm' ", $Fields ) );
//$ses2->execute( G::replaceDataField( "UPDATE . SET NEXTSTEPSAVE = @@NEXTSTEPSAVE WHERE XMLNODE_NAME = 'dynaForm' ", $Fields ) );
$dynaform->modifyHeaderAttribute('nextstepsave', $Fields['NEXTSTEPSAVE']);
}
if (isset($Fields['PRINTDYNAFORM'])) {
$ses2->execute( G::replaceDataField( "UPDATE . SET PRINTDYNAFORM = @@PRINTDYNAFORM WHERE XMLNODE_NAME = 'dynaForm' ", $Fields ) );
//$ses2->execute( G::replaceDataField( "UPDATE . SET PRINTDYNAFORM = @@PRINTDYNAFORM WHERE XMLNODE_NAME = 'dynaForm' ", $Fields ) );
$dynaform->modifyHeaderAttribute('printdynaform', $Fields['PRINTDYNAFORM']);
}
if (isset($Fields['ADJUSTGRIDSWIDTH'])) {
$ses2->execute( G::replaceDataField( "UPDATE . SET ADJUSTGRIDSWIDTH = @@ADJUSTGRIDSWIDTH WHERE XMLNODE_NAME = 'dynaForm' ", $Fields ) );
//$ses2->execute( G::replaceDataField( "UPDATE . SET ADJUSTGRIDSWIDTH = @@ADJUSTGRIDSWIDTH WHERE XMLNODE_NAME = 'dynaForm' ", $Fields ) );
$dynaform->modifyHeaderAttribute('adjustgridswidth', $Fields['ADJUSTGRIDSWIDTH']);
}
return 0;
} catch (Exception $e) {
return (array) $e;
@@ -735,7 +750,7 @@ 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);
@@ -749,13 +764,17 @@ 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);
$value = $value == "1" ? "1" : "0";
$dbc2 = new DBConnection( PATH_DYNAFORM . $file . '.xml', '', '', '', 'myxml' );
$ses2 = new DBSession( $dbc2 );
$ses2->execute( "UPDATE . SET ENABLETEMPLATE = '$value'" );
// $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->modifyHeaderAttribute('enabletemplate', $value);
return $value;
}
@@ -766,13 +785,14 @@ 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);
$tmp = self::_getTmpData();
if (isset( $tmp['useTmpCopy'] )) { /*Save Register*/
if (isset($tmp['useTmpCopy'])) {
/* Save Register */
$dynaform = new dynaform();
$dynaform->update($tmp['Properties']);
/* Save file */
@@ -814,7 +834,7 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax
* @param object $A
* @return array
*/
function close ($A)
public function close($A)
{
try {
/*
@@ -835,10 +855,11 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax
if (file_exists($xmlFile)) {
unlink($xmlFile);
}
if (file_exists( $htmlFile ))
if (file_exists($htmlFile)) {
unlink($htmlFile);
}
}
}
return 0;
} catch (Exception $e) {
return (array) $e;
@@ -852,7 +873,7 @@ 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);
try {
@@ -881,10 +902,11 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax
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']) /*||
$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'])*/;
($sp['MODE']!=$P['MODE']) */
/* Compare copies */
$fileOrigen = dynaformEditor::_getFilename($file);
$copy = implode('', file(PATH_DYNAFORM . $file . '.xml'));
@@ -901,4 +923,4 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax
}
}
}
?>

View File

@@ -1,4 +1,5 @@
<?php
//print_r( $_POST); die;
/**
* fields_Save.php
@@ -25,21 +26,24 @@
*/
G::LoadClass('dynaformEditor');
if (($RBAC_Response=$RBAC->userCanAccess("PM_FACTORY"))!=1) return $RBAC_Response;
if (($RBAC_Response = $RBAC->userCanAccess("PM_FACTORY")) != 1) {
return $RBAC_Response;
}
//G::genericForceLogin( 'WF_MYINFO' , 'login/noViewPage', $urlLogin = 'login/login' );
G::LoadClass('dynaFormField');
$type = strtolower($_POST['form']['PME_TYPE']);
if (!(isset($_POST['form']['PME_A']) && $_POST['form']['PME_A']!=='')) return;
if (!(isset($_POST['form']['PME_A']) && $_POST['form']['PME_A'] !== '')) {
return;
}
if (isset($_POST['form']['PME_REQUIRED'])) {
if ($_POST['form']['PME_REQUIRED'] == '') {
$_POST['form']['PME_REQUIRED'] = 0;
}
}
else {
} else {
$_POST['form']['PME_REQUIRED'] = 0;
}
@@ -47,8 +51,7 @@ if (($RBAC_Response=$RBAC->userCanAccess("PM_FACTORY"))!=1) return $RBAC_Respons
if ($_POST['form']['PME_READONLY'] == '') {
$_POST['form']['PME_READONLY'] = 0;
}
}
else {
} else {
$_POST['form']['PME_READONLY'] = 0;
}
@@ -56,16 +59,15 @@ if (($RBAC_Response=$RBAC->userCanAccess("PM_FACTORY"))!=1) return $RBAC_Respons
if ($_POST['form']['PME_SAVELABEL'] == '') {
$_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'];
// $A = $_POST['form']['PME_A'];
$fieldName = $_POST['form']['PME_XMLNODE_NAME'];
$pmeCode = $_POST['form']['PME_CODE'];
$_POST['form']['PME_CODE'] = '';
@@ -82,17 +84,21 @@ if (($RBAC_Response=$RBAC->userCanAccess("PM_FACTORY"))!=1) return $RBAC_Respons
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);
//TODO: Verify why validatePost removes PME_XMLGRID.
$isGrid = isset($_POST['form']['PME_XMLGRID']);
if ($isGrid) $xmlGrid=$_POST['form']['PME_XMLGRID'];
if ($isGrid) {
$xmlGrid = $_POST['form']['PME_XMLGRID'];
}
//$form->validatePost();
if ($isGrid) $_POST['form']['PME_XMLGRID']=$xmlGrid;
if ($isGrid) {
$_POST['form']['PME_XMLGRID'] = $xmlGrid;
}
if ($type === 'checkbox') {
// added by Gustavo Cruz
if ($_POST['form']['PME_DEFAULTVALUE'] === "1") {
@@ -124,14 +130,14 @@ if (($RBAC_Response=$RBAC->userCanAccess("PM_FACTORY"))!=1) return $RBAC_Respons
}
}
}
}
foreach ($_POST['form'] as $key => $value) {
if (substr($key,0,4)==='PME_')
if (substr($key, 0, 4) === 'PME_') {
$res[substr($key, 4)] = $value;
else
} else {
$res[$key] = $value;
}
}
$_POST['form'] = $res;
$dbc = new DBConnection(PATH_DYNAFORM . $file . '.xml', '', '', '', 'myxml');
@@ -139,7 +145,9 @@ if (($RBAC_Response=$RBAC->userCanAccess("PM_FACTORY"))!=1) return $RBAC_Respons
$fields = new DynaFormField($dbc);
if ($_POST['form']['XMLNODE_NAME']==='') return;
if ($_POST['form']['XMLNODE_NAME'] === '') {
return;
}
$attributes = $_POST['form'];
@@ -148,17 +156,21 @@ if (($RBAC_Response=$RBAC->userCanAccess("PM_FACTORY"))!=1) return $RBAC_Respons
$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'] );
if (isset($attributes['LABEL'])) {
$labels = array(SYS_LANG => $attributes['LABEL']);
}
unset($attributes['A']);
unset($attributes['ACCEPT']);
unset($attributes['LABEL']);
unset($attributes['PRO_UID']);
$options = NULL;
$options = null;
foreach ($attributes as $key => $value) {
if ($key === 'OPTIONS') {
if (is_array($value)) {
@@ -170,10 +182,11 @@ if (($RBAC_Response=$RBAC->userCanAccess("PM_FACTORY"))!=1) return $RBAC_Respons
foreach ($value as $row) {
foreach ($langs as $lang) {
$LANG = strtoupper($lang);
if (isset($row['LABEL']))
if (isset($row['LABEL'])) {
$options[$lang][$row['NAME']] = $row['LABEL'];
}
}
}
/* $first = reset($value);
foreach( $first as $optKey => $optValue ) {
if (substr($optKey,0,6)==='LABEL_') {
@@ -202,7 +215,22 @@ if (($RBAC_Response=$RBAC->userCanAccess("PM_FACTORY"))!=1) return $RBAC_Respons
}
}
unset($attributes['VALIDATE_NAME']);
$fields->Save( $attributes , $labels , $options );
$fields->setFileName(PATH_DYNAFORM . $file . '.xml');
$FieldAttributes = $attributes;
$FieldAttrib = array();
unset($FieldAttributes['XMLNODE_NAME']);
unset($FieldAttributes['XMLNODE_NAME_OLD']);
unset($FieldAttributes['XMLNODE_VALUE']);
unset($FieldAttributes['BTN_CANCEL']);
unset($FieldAttributes['SAVELABEL']);
foreach ($FieldAttributes as $key => $value) {
if ($value != "") {
$FieldAttrib[strtolower($key)] = $value;
}
}
$fields->saveField($attributes, $FieldAttrib, $labels);
G::LoadClass('xmlDb');
$i = 0;
@@ -233,4 +261,4 @@ if (($RBAC_Response=$RBAC->userCanAccess("PM_FACTORY"))!=1) return $RBAC_Respons
$editor = new dynaformEditorAjax($_POST);
$editor->set_javascript($A, $fieldName, $sCode);
}
?>