2010-12-02 23:34:41 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Dynaform.php
|
2012-10-19 10:24:29 -04:00
|
|
|
*
|
|
|
|
|
* @package workflow.engine.classes.model
|
2012-08-16 12:27:59 -04:00
|
|
|
*
|
2010-12-02 23:34:41 +00:00
|
|
|
* ProcessMaker Open Source Edition
|
2011-01-31 14:14:55 +00:00
|
|
|
* Copyright (C) 2004 - 2011 Colosa Inc.
|
2010-12-02 23:34:41 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-10-19 10:24:29 -04:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2010-12-02 23:34:41 +00:00
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2012-10-19 10:24:29 -04:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-12-02 23:34:41 +00:00
|
|
|
*
|
|
|
|
|
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
|
|
|
|
|
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2012-11-16 17:13:48 -04:00
|
|
|
//require_once 'classes/model/om/BaseDynaform.php';
|
|
|
|
|
//require_once 'classes/model/Content.php';
|
|
|
|
|
//require_once ('classes/model/AdditionalTables.php');
|
|
|
|
|
//G::LoadClass( 'dynaFormField' );
|
2010-12-02 23:34:41 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Skeleton subclass for representing a row from the 'DYNAFORM' table.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* You should add additional methods to this class to meet the
|
2012-10-19 10:24:29 -04:00
|
|
|
* application requirements. This class will only be generated as
|
2010-12-02 23:34:41 +00:00
|
|
|
* long as it does not already exist in the output directory.
|
|
|
|
|
*
|
2012-10-19 10:24:29 -04:00
|
|
|
* @package workflow.engine.classes.model
|
2010-12-02 23:34:41 +00:00
|
|
|
*/
|
2012-10-19 10:24:29 -04:00
|
|
|
class Dynaform extends BaseDynaform
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* This value goes in the content table
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2016-12-22 17:16:01 -04:00
|
|
|
protected $dyn_title_content = '';
|
2012-10-19 10:24:29 -04:00
|
|
|
|
|
|
|
|
/**
|
2016-12-22 17:16:01 -04:00
|
|
|
* Get the [Dyn_title_content] column value.
|
2012-10-19 10:24:29 -04:00
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2016-12-01 09:32:35 -05:00
|
|
|
public function getDynTitleContent ()
|
2012-10-19 10:24:29 -04:00
|
|
|
{
|
|
|
|
|
if ($this->getDynUid() == '') {
|
|
|
|
|
throw (new Exception( "Error in getDynTitle, the DYN_UID can't be blank" ));
|
|
|
|
|
}
|
|
|
|
|
$lang = defined( 'SYS_LANG' ) ? SYS_LANG : 'en';
|
2016-12-22 17:16:01 -04:00
|
|
|
$this->dyn_title_content = Content::load( 'DYN_TITLE', '', $this->getDynUid(), $lang );
|
|
|
|
|
return $this->dyn_title_content;
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
/**
|
|
|
|
|
* Set the [Dyn_title] column value.
|
|
|
|
|
*
|
|
|
|
|
* @param string $v new value
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2016-12-01 09:32:35 -05:00
|
|
|
public function setDynTitleContent ($v)
|
2012-10-19 10:24:29 -04:00
|
|
|
{
|
|
|
|
|
if ($this->getDynUid() == '') {
|
|
|
|
|
throw (new Exception( "Error in setDynTitle, the DYN_UID can't be blank" ));
|
|
|
|
|
}
|
|
|
|
|
// Since the native PHP type for this column is string,
|
|
|
|
|
// we will cast the input to a string (if it is not).
|
|
|
|
|
if ($v !== null && ! is_string( $v )) {
|
|
|
|
|
$v = (string) $v;
|
|
|
|
|
}
|
2012-08-16 12:27:59 -04:00
|
|
|
|
2017-04-06 10:04:29 -04:00
|
|
|
if (in_array(DynaformPeer::DYN_TITLE, $this->modifiedColumns) || $v === '') {
|
2016-12-22 17:16:01 -04:00
|
|
|
$this->dyn_title_content = $v;
|
2012-10-19 10:24:29 -04:00
|
|
|
$lang = defined( 'SYS_LANG' ) ? SYS_LANG : 'en';
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2016-12-22 17:16:01 -04:00
|
|
|
$res = Content::addContent( 'DYN_TITLE', '', $this->getDynUid(), $lang, $this->dyn_title_content );
|
2012-10-19 10:24:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // set()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This value goes in the content table
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $dyn_description = '';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the [Dyn_description] column value.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2016-12-01 09:32:35 -05:00
|
|
|
public function getDynDescriptionContent ()
|
2012-10-19 10:24:29 -04:00
|
|
|
{
|
|
|
|
|
if ($this->getDynUid() == '') {
|
|
|
|
|
throw (new Exception( "Error in getDynDescription, the DYN_UID can't be blank" ));
|
|
|
|
|
}
|
|
|
|
|
$lang = defined( 'SYS_LANG' ) ? SYS_LANG : 'en';
|
|
|
|
|
$this->dyn_description = Content::load( 'DYN_DESCRIPTION', '', $this->getDynUid(), $lang );
|
|
|
|
|
return $this->dyn_description;
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
/**
|
|
|
|
|
* Set the [Dyn_description] column value.
|
|
|
|
|
*
|
|
|
|
|
* @param string $v new value
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2016-12-01 09:32:35 -05:00
|
|
|
public function setDynDescriptionContent ($v)
|
2012-10-19 10:24:29 -04:00
|
|
|
{
|
|
|
|
|
if ($this->getDynUid() == '') {
|
|
|
|
|
throw (new Exception( "Error in setDynDescription, the DYN_UID can't be blank" ));
|
|
|
|
|
}
|
|
|
|
|
// Since the native PHP type for this column is string,
|
|
|
|
|
// we will cast the input to a string (if it is not).
|
|
|
|
|
if ($v !== null && ! is_string( $v )) {
|
|
|
|
|
$v = (string) $v;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-06 10:04:29 -04:00
|
|
|
if (in_array(DynaformPeer::DYN_DESCRIPTION, $this->modifiedColumns) || $v === '') {
|
2012-10-19 10:24:29 -04:00
|
|
|
$this->dyn_description = $v;
|
|
|
|
|
$lang = defined( 'SYS_LANG' ) ? SYS_LANG : 'en';
|
2012-08-16 12:27:59 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
$res = Content::addContent( 'DYN_DESCRIPTION', '', $this->getDynUid(), $lang, $this->dyn_description );
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
} // set()
|
2010-12-02 23:34:41 +00:00
|
|
|
|
|
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
/**
|
|
|
|
|
* Creates the Dynaform
|
|
|
|
|
*
|
|
|
|
|
* @param array $aData Fields with :
|
|
|
|
|
* $aData['DYN_UID'] the dynaform id
|
|
|
|
|
* $aData['USR_UID'] the userid
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2015-02-12 15:56:30 -04:00
|
|
|
public function create ($aData, $pmTableUid='')
|
2012-10-19 10:24:29 -04:00
|
|
|
{
|
|
|
|
|
if (! isset( $aData['PRO_UID'] )) {
|
|
|
|
|
throw (new PropelException( 'The dynaform cannot be created. The PRO_UID is empty.' ));
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-19 10:24:29 -04:00
|
|
|
$con = Propel::getConnection( DynaformPeer::DATABASE_NAME );
|
|
|
|
|
try {
|
|
|
|
|
if (isset( $aData['DYN_UID'] ) && $aData['DYN_UID'] == '') {
|
|
|
|
|
unset( $aData['DYN_UID'] );
|
|
|
|
|
}
|
|
|
|
|
if (! isset( $aData['DYN_UID'] )) {
|
|
|
|
|
$dynUid = (G::generateUniqueID());
|
|
|
|
|
} else {
|
|
|
|
|
$dynUid = $aData['DYN_UID'];
|
|
|
|
|
}
|
|
|
|
|
$this->setDynUid( $dynUid );
|
2016-12-01 09:32:35 -05:00
|
|
|
$dynTitle = isset($aData['DYN_TITLE']) ? $aData['DYN_TITLE'] : 'Default Dynaform Title';
|
|
|
|
|
$this->setDynTitle($dynTitle);
|
|
|
|
|
$dynDescription = isset($aData['DYN_DESCRIPTION']) ? $aData['DYN_DESCRIPTION'] : 'Default Dynaform Description';
|
|
|
|
|
$this->setDynDescription($dynDescription);
|
2012-10-19 10:24:29 -04:00
|
|
|
$this->setProUid( $aData['PRO_UID'] );
|
|
|
|
|
$this->setDynType( isset( $aData['DYN_TYPE'] ) ? $aData['DYN_TYPE'] : 'xmlform' );
|
|
|
|
|
$this->setDynFilename( $aData['PRO_UID'] . PATH_SEP . $dynUid );
|
2015-07-06 17:23:25 -04:00
|
|
|
$this->setDynUpdateDate( date("Y-m-d H:i:s"));
|
2012-10-19 10:24:29 -04:00
|
|
|
|
2014-06-27 14:48:00 -04:00
|
|
|
if (isset($aData["DYN_CONTENT"])) {
|
|
|
|
|
$this->setDynContent($aData["DYN_CONTENT"]);
|
2016-03-10 15:14:18 -04:00
|
|
|
} else {
|
|
|
|
|
$this->setDynContent(G::json_encode(array(
|
|
|
|
|
"name" => $aData["DYN_TITLE"],
|
|
|
|
|
"description" => $aData["DYN_DESCRIPTION"],
|
|
|
|
|
"items" => array(array(
|
|
|
|
|
"type" => "form",
|
|
|
|
|
"variable" => "",
|
|
|
|
|
"var_uid" => "",
|
|
|
|
|
"dataType" => "",
|
|
|
|
|
"id" => $this->getDynUid(),
|
|
|
|
|
"name" => $aData["DYN_TITLE"],
|
|
|
|
|
"description" => $aData["DYN_DESCRIPTION"],
|
|
|
|
|
"mode" => "edit",
|
|
|
|
|
"script" => "",
|
|
|
|
|
"language" => "en",
|
|
|
|
|
"externalLibs" => "",
|
|
|
|
|
"printable" => false,
|
|
|
|
|
"items" => array(),
|
|
|
|
|
"variables" => array()
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
)));
|
2014-06-27 14:48:00 -04:00
|
|
|
}
|
2015-03-25 15:57:53 -04:00
|
|
|
if (isset($aData["DYN_LABEL"])) {
|
|
|
|
|
$this->setDynLabel($aData["DYN_LABEL"]);
|
|
|
|
|
}
|
2014-07-03 12:57:45 -04:00
|
|
|
if (!isset($aData['DYN_VERSION'])) {
|
|
|
|
|
$aData['DYN_VERSION'] = 0;
|
2014-07-01 09:36:57 -04:00
|
|
|
}
|
2014-07-03 12:57:45 -04:00
|
|
|
$this->setDynVersion( $aData['DYN_VERSION'] );
|
2012-10-19 10:24:29 -04:00
|
|
|
if ($this->validate()) {
|
|
|
|
|
$con->begin();
|
2016-12-01 09:32:35 -05:00
|
|
|
$this->setDynTitleContent( $dynTitle );
|
|
|
|
|
$this->setDynDescriptionContent( $dynDescription );
|
2017-04-07 16:28:20 -04:00
|
|
|
$res = $this->save();
|
2012-10-19 10:24:29 -04:00
|
|
|
$con->commit();
|
2015-02-12 15:56:30 -04:00
|
|
|
|
|
|
|
|
//Add Audit Log
|
|
|
|
|
$mode = isset($aData['MODE'])? $aData['MODE'] : 'Determined by Fields';
|
|
|
|
|
$description = "";
|
|
|
|
|
if($pmTableUid!=''){
|
|
|
|
|
$pmTable = AdditionalTablesPeer::retrieveByPK( $pmTableUid );
|
|
|
|
|
$addTabName = $pmTable->getAddTabName();
|
|
|
|
|
$description = "Create from a PM Table: ".$addTabName.", ";
|
|
|
|
|
}
|
|
|
|
|
G::auditLog("CreateDynaform", $description."Dynaform Title: ".$aData['DYN_TITLE'].", Type: ".$aData['DYN_TYPE'].", Description: ".$aData['DYN_DESCRIPTION'].", Mode: ".$mode);
|
|
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
$sXml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
|
|
|
|
|
$sXml .= '<dynaForm type="' . $this->getDynType() . '" name="' . $this->getProUid() . '/' . $this->getDynUid() . '" width="500" enabletemplate="0" mode="" nextstepsave="prompt">' . "\n";
|
|
|
|
|
$sXml .= '</dynaForm>';
|
|
|
|
|
G::verifyPath( PATH_DYNAFORM . $this->getProUid(), true );
|
|
|
|
|
$oFile = fopen( PATH_DYNAFORM . $this->getProUid() . '/' . $this->getDynUid() . '.xml', 'w' );
|
|
|
|
|
fwrite( $oFile, $sXml );
|
|
|
|
|
fclose( $oFile );
|
|
|
|
|
return $this->getDynUid();
|
|
|
|
|
} else {
|
|
|
|
|
$msg = '';
|
|
|
|
|
foreach ($this->getValidationFailures() as $objValidationFailure) {
|
|
|
|
|
$msg .= $objValidationFailure->getMessage() . "<br/>";
|
|
|
|
|
}
|
|
|
|
|
throw (new PropelException( 'The row cannot be created!', new PropelException( $msg ) ));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
$con->rollback();
|
|
|
|
|
throw ($e);
|
2012-07-19 18:53:48 -04:00
|
|
|
}
|
2012-10-19 10:24:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Creates a Dynaform based on a PMTable
|
|
|
|
|
*
|
|
|
|
|
* @name createFromPMTable
|
|
|
|
|
* @author gustavo cruz gustavo[at]colosa[dot]com
|
|
|
|
|
* @param array $aData Fields with :
|
|
|
|
|
* $aData['DYN_UID'] the dynaform id
|
|
|
|
|
* $aData['USR_UID'] the userid
|
|
|
|
|
* string $pmTableUid uid of the PMTable
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2012-10-20 17:19:10 -04:00
|
|
|
public function createFromPMTable ($aData, $pmTableUid)
|
2012-10-19 10:24:29 -04:00
|
|
|
{
|
2015-02-12 15:56:30 -04:00
|
|
|
$this->create( $aData , $pmTableUid);
|
2012-10-19 10:24:29 -04:00
|
|
|
$aData['DYN_UID'] = $this->getDynUid();
|
|
|
|
|
$pmTable = AdditionalTablesPeer::retrieveByPK( $pmTableUid );
|
|
|
|
|
$addTabName = $pmTable->getAddTabName();
|
|
|
|
|
$keys = '';
|
|
|
|
|
if (isset( $aData['FIELDS'] )) {
|
|
|
|
|
foreach ($aData['FIELDS'] as $iRow => $row) {
|
|
|
|
|
if ($keys != '') {
|
|
|
|
|
$keys = $keys . '|' . $row['PRO_VARIABLE'];
|
|
|
|
|
} else {
|
|
|
|
|
$keys = $row['PRO_VARIABLE'];
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
} else {
|
2012-10-19 10:24:29 -04:00
|
|
|
$keys = ' ';
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-19 10:24:29 -04:00
|
|
|
|
|
|
|
|
// Determines the engine to use
|
|
|
|
|
// For a description of a table
|
|
|
|
|
$sDataBase = 'database_' . strtolower( DB_ADAPTER );
|
|
|
|
|
if (G::LoadSystemExist( $sDataBase )) {
|
|
|
|
|
G::LoadSystem( $sDataBase );
|
|
|
|
|
$oDataBase = new database();
|
|
|
|
|
$sql = $oDataBase->getTableDescription( $addTabName );
|
2010-12-02 23:34:41 +00:00
|
|
|
} else {
|
2012-10-19 10:24:29 -04:00
|
|
|
$sql = 'DESC ' . $addTabName;
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-19 10:24:29 -04:00
|
|
|
|
|
|
|
|
$dbh = Propel::getConnection( AdditionalTablesPeer::DATABASE_NAME );
|
|
|
|
|
$sth = $dbh->createStatement();
|
|
|
|
|
$res = $sth->executeQuery( $sql, ResultSet::FETCHMODE_ASSOC );
|
|
|
|
|
|
|
|
|
|
$file = $aData['PRO_UID'] . '/' . $aData['DYN_UID'];
|
|
|
|
|
$dbc = new DBConnection( PATH_DYNAFORM . $file . '.xml', '', '', '', 'myxml' );
|
|
|
|
|
$fieldXML = new DynaFormField( $dbc );
|
|
|
|
|
|
|
|
|
|
$pmConnectionName = $addTabName . '_CONNECTION';
|
|
|
|
|
|
|
|
|
|
if ($aData['DYN_TYPE'] == 'xmlform') {
|
|
|
|
|
$labels = array ();
|
|
|
|
|
$options = array ();
|
|
|
|
|
$attributes = array ('XMLNODE_NAME_OLD' => '','XMLNODE_NAME' => $pmConnectionName,'TYPE' => 'pmconnection','PMTABLE' => $pmTableUid,'KEYS' => $keys
|
|
|
|
|
);
|
|
|
|
|
$fieldXML->Save( $attributes, $labels, $options );
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-19 10:24:29 -04:00
|
|
|
|
|
|
|
|
$keyRequered = '';
|
|
|
|
|
$countKeys = 0;
|
|
|
|
|
while ($res->next()) {
|
|
|
|
|
if ($res->get( 'Key' ) != '') {
|
|
|
|
|
$countKeys ++;
|
|
|
|
|
}
|
|
|
|
|
if ($res->get( 'Extra' ) == 'auto_increment') {
|
|
|
|
|
$keyRequered .= $res->get( 'Field' );
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-19 10:24:29 -04:00
|
|
|
|
|
|
|
|
$dbh = Propel::getConnection( AdditionalTablesPeer::DATABASE_NAME );
|
|
|
|
|
$sth = $dbh->createStatement();
|
|
|
|
|
$res = $sth->executeQuery( $sql, ResultSet::FETCHMODE_ASSOC );
|
|
|
|
|
|
|
|
|
|
while ($res->next()) {
|
|
|
|
|
if (strtoupper( $res->get( $oDataBase->getFieldNull() ) ) == 'NO') {
|
|
|
|
|
if ($countKeys == 1 && $res->get( 'Field' ) == $keyRequered) {
|
|
|
|
|
$required = '0';
|
|
|
|
|
} else {
|
|
|
|
|
$required = '1';
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$required = '0';
|
|
|
|
|
}
|
|
|
|
|
$fieldName = $res->get( 'Field' );
|
|
|
|
|
$defaultValue = $res->get( 'Default' );
|
|
|
|
|
$labels = array (SYS_LANG => $fieldName
|
|
|
|
|
);
|
|
|
|
|
$options = array ();
|
|
|
|
|
$type = explode( '(', $res->get( 'Type' ) );
|
|
|
|
|
|
|
|
|
|
switch ($type[0]) {
|
|
|
|
|
case 'text':
|
|
|
|
|
$type = 'textarea';
|
|
|
|
|
break;
|
|
|
|
|
case 'date':
|
|
|
|
|
$type = 'date';
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
$type = 'text';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if ($aData['DYN_TYPE'] == 'xmlform') {
|
|
|
|
|
$attributes = array ('XMLNODE_NAME_OLD' => '','XMLNODE_NAME' => $fieldName,'TYPE' => $type,'PMCONNECTION' => $pmConnectionName,'PMFIELD' => $fieldName,'REQUIRED' => $required,'DEFAULTVALUE' => $defaultValue
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$attributes = array ('XMLNODE_NAME_OLD' => '','XMLNODE_NAME' => $fieldName,'TYPE' => $type,'REQUIRED' => $required,'DEFAULTVALUE' => $defaultValue
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
$fieldXML->Save( $attributes, $labels, $options );
|
|
|
|
|
}
|
|
|
|
|
$labels = array (SYS_LANG => 'Submit'
|
|
|
|
|
);
|
|
|
|
|
$attributes = array ('XMLNODE_NAME_OLD' => '','XMLNODE_NAME' => 'SUBMIT','TYPE' => 'submit'
|
|
|
|
|
);
|
|
|
|
|
$fieldXML->Save( $attributes, $labels, $options );
|
2015-01-19 11:29:15 -04:00
|
|
|
|
|
|
|
|
//update content if version is 2
|
|
|
|
|
if ($this->getDynVersion() === 2) {
|
|
|
|
|
$items = array();
|
|
|
|
|
$variables = array();
|
|
|
|
|
$res = $sth->executeQuery($sql, ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
while ($res->next()) {
|
|
|
|
|
//data type
|
|
|
|
|
$type = "text";
|
|
|
|
|
$dataType = explode('(', $res->get('Type'));
|
|
|
|
|
error_log(print_r($dataType, true));
|
|
|
|
|
switch ($dataType[0]) {
|
|
|
|
|
case 'bigint':
|
|
|
|
|
$type = 'text';
|
|
|
|
|
$dataType = 'integer';
|
|
|
|
|
break;
|
|
|
|
|
case 'int':
|
|
|
|
|
$type = 'text';
|
|
|
|
|
$dataType = 'integer';
|
|
|
|
|
break;
|
|
|
|
|
case 'smallint':
|
|
|
|
|
$type = 'text';
|
|
|
|
|
$dataType = 'integer';
|
|
|
|
|
break;
|
|
|
|
|
case 'tinyint':
|
|
|
|
|
$type = 'text';
|
|
|
|
|
$dataType = 'integer';
|
|
|
|
|
break;
|
|
|
|
|
case 'decimal':
|
|
|
|
|
$type = 'text';
|
|
|
|
|
$dataType = 'float';
|
|
|
|
|
break;
|
|
|
|
|
case 'double':
|
|
|
|
|
$type = 'text';
|
|
|
|
|
$dataType = 'float';
|
|
|
|
|
break;
|
|
|
|
|
case 'float':
|
|
|
|
|
$type = 'text';
|
|
|
|
|
$dataType = 'float';
|
|
|
|
|
break;
|
|
|
|
|
case 'datetime':
|
|
|
|
|
$type = 'datetime';
|
|
|
|
|
$dataType = 'datetime';
|
|
|
|
|
break;
|
|
|
|
|
case 'date':
|
|
|
|
|
$type = 'datetime';
|
|
|
|
|
$dataType = 'datetime';
|
|
|
|
|
break;
|
|
|
|
|
case 'time':
|
|
|
|
|
$type = 'datetime';
|
|
|
|
|
$dataType = 'datetime';
|
|
|
|
|
break;
|
|
|
|
|
case 'char':
|
|
|
|
|
$type = 'text';
|
|
|
|
|
$dataType = 'string';
|
|
|
|
|
break;
|
|
|
|
|
case 'varchar':
|
|
|
|
|
$type = 'text';
|
|
|
|
|
$dataType = 'string';
|
|
|
|
|
break;
|
|
|
|
|
case 'mediumtext':
|
|
|
|
|
$type = 'textarea';
|
|
|
|
|
$dataType = 'string';
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
$type = "text";
|
|
|
|
|
$dataType = 'string';
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-01-19 14:59:07 -04:00
|
|
|
|
|
|
|
|
//variables
|
|
|
|
|
$arrayData = array(
|
|
|
|
|
"var_name" => $res->get('Field'),
|
|
|
|
|
"var_label" => $res->get('Field'),
|
|
|
|
|
"var_field_type" => $dataType,
|
|
|
|
|
"var_field_size" => 10,
|
|
|
|
|
"var_null" => 1,
|
|
|
|
|
"var_dbconnection" => "none",
|
|
|
|
|
"var_sql" => "",
|
|
|
|
|
"var_options_control" => "",
|
|
|
|
|
"var_default" => "",
|
|
|
|
|
"var_accepted_values" => Array()
|
|
|
|
|
);
|
|
|
|
|
$objVariable = new \ProcessMaker\BusinessModel\Variable();
|
|
|
|
|
try {
|
|
|
|
|
$objVariable->existsName($this->getProUid(), $res->get('Field'));
|
|
|
|
|
$variable = $objVariable->create($this->getProUid(), $arrayData);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
$data = $objVariable->getVariables($this->getProUid());
|
|
|
|
|
foreach ($data as $datavariable) {
|
|
|
|
|
if ($datavariable["var_name"] === $res->get('Field')) {
|
|
|
|
|
$variable = $datavariable;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
array_push($variables, $variable);
|
2015-01-19 11:29:15 -04:00
|
|
|
|
|
|
|
|
array_push($items, array(
|
|
|
|
|
array(
|
|
|
|
|
"type" => $type,
|
|
|
|
|
"dataType" => $dataType, //$res->get('Type'),
|
|
|
|
|
"id" => $res->get('Field'),
|
|
|
|
|
"name" => $res->get('Field'),
|
|
|
|
|
"label" => $res->get('Field'),
|
|
|
|
|
"hint" => "",
|
|
|
|
|
"required" => false,
|
|
|
|
|
"defaultValue" => "",
|
|
|
|
|
"dependentFields" => array(),
|
|
|
|
|
"textTransform" => "none",
|
|
|
|
|
"validate" => "any",
|
|
|
|
|
"mask" => "",
|
|
|
|
|
"maxLength" => 1000,
|
|
|
|
|
"formula" => "",
|
|
|
|
|
"mode" => "parent",
|
|
|
|
|
"var_uid" => $variable["var_uid"],
|
|
|
|
|
"var_name" => $variable["var_name"],
|
|
|
|
|
"colSpan" => 12
|
|
|
|
|
)
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
//submit button
|
|
|
|
|
array_push($items, array(
|
|
|
|
|
array(
|
|
|
|
|
"type" => "submit",
|
|
|
|
|
"id" => "FormDesigner-" . \ProcessMaker\Util\Common::generateUID(),
|
|
|
|
|
"name" => "submit",
|
|
|
|
|
"label" => "submit",
|
|
|
|
|
"colSpan" => 12
|
|
|
|
|
)
|
|
|
|
|
));
|
|
|
|
|
$json = array(
|
|
|
|
|
"name" => $this->getDynTitle(),
|
|
|
|
|
"description" => $this->getDynDescription(),
|
|
|
|
|
"items" => array(
|
|
|
|
|
array(
|
|
|
|
|
"type" => "form",
|
|
|
|
|
"id" => $this->getDynUid(),
|
|
|
|
|
"name" => $this->getDynTitle(),
|
|
|
|
|
"description" => $this->getDynDescription(),
|
|
|
|
|
"mode" => "edit",
|
|
|
|
|
"script" => "",
|
|
|
|
|
"items" => $items,
|
|
|
|
|
"variables" => $variables
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$aData = $this->Load($this->getDynUid());
|
|
|
|
|
$aData["DYN_CONTENT"] = G::json_encode($json);
|
|
|
|
|
$this->update($aData);
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-19 10:24:29 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load the Dynaform row specified in [dyn_id] column value.
|
|
|
|
|
*
|
|
|
|
|
* @param string $ProUid the uid of the Prolication
|
|
|
|
|
* @return array $Fields the fields
|
|
|
|
|
*/
|
|
|
|
|
|
2012-10-20 17:19:10 -04:00
|
|
|
public function Load ($ProUid)
|
2012-10-19 10:24:29 -04:00
|
|
|
{
|
|
|
|
|
$con = Propel::getConnection( DynaformPeer::DATABASE_NAME );
|
|
|
|
|
try {
|
|
|
|
|
$oPro = DynaformPeer::retrieveByPk( $ProUid );
|
|
|
|
|
if (is_object( $oPro ) && get_class( $oPro ) == 'Dynaform') {
|
|
|
|
|
$aFields = $oPro->toArray( BasePeer::TYPE_FIELDNAME );
|
|
|
|
|
$this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME );
|
|
|
|
|
return $aFields;
|
|
|
|
|
} else {
|
|
|
|
|
throw (new Exception( "The row '$ProUid' in table Dynaform doesn't exist!" ));
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $oError) {
|
|
|
|
|
throw ($oError);
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-19 10:24:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update the Prolication row
|
|
|
|
|
*
|
|
|
|
|
* @param array $aData
|
|
|
|
|
* @return variant
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public function update ($aData)
|
|
|
|
|
{
|
|
|
|
|
$con = Propel::getConnection( DynaformPeer::DATABASE_NAME );
|
|
|
|
|
try {
|
|
|
|
|
$con->begin();
|
|
|
|
|
$oPro = DynaformPeer::retrieveByPK( $aData['DYN_UID'] );
|
|
|
|
|
if (is_object( $oPro ) && get_class( $oPro ) == 'Dynaform') {
|
|
|
|
|
$oPro->fromArray( $aData, BasePeer::TYPE_FIELDNAME );
|
2015-07-06 17:23:25 -04:00
|
|
|
$oPro->setDynUpdateDate(date("Y-m-d H:i:s"));
|
2012-10-19 10:24:29 -04:00
|
|
|
if ($oPro->validate()) {
|
|
|
|
|
if (isset( $aData['DYN_TITLE'] )) {
|
2016-12-01 09:32:35 -05:00
|
|
|
$oPro->setDynTitleContent( $aData['DYN_TITLE'] );
|
2012-10-19 10:24:29 -04:00
|
|
|
}
|
|
|
|
|
if (isset( $aData['DYN_DESCRIPTION'] )) {
|
2016-12-01 09:32:35 -05:00
|
|
|
$oPro->setDynDescriptionContent( $aData['DYN_DESCRIPTION'] );
|
2012-10-19 10:24:29 -04:00
|
|
|
}
|
|
|
|
|
$res = $oPro->save();
|
|
|
|
|
$con->commit();
|
|
|
|
|
return $res;
|
|
|
|
|
} else {
|
|
|
|
|
foreach ($this->getValidationFailures() as $objValidationFailure) {
|
|
|
|
|
$msg .= $objValidationFailure->getMessage() . "<br/>";
|
|
|
|
|
}
|
|
|
|
|
throw (new PropelException( 'The row cannot be created!', new PropelException( $msg ) ));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$con->rollback();
|
|
|
|
|
throw (new Exception( "The row '" . $aData['DYN_UID'] . "' in table Dynaform doesn't exist!" ));
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $oError) {
|
|
|
|
|
throw ($oError);
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-19 10:24:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove the Prolication document registry
|
|
|
|
|
*
|
|
|
|
|
* @param array $aData or string $ProUid
|
|
|
|
|
* @return string
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function remove ($ProUid)
|
|
|
|
|
{
|
|
|
|
|
if (is_array( $ProUid )) {
|
|
|
|
|
$ProUid = (isset( $ProUid['DYN_UID'] ) ? $ProUid['DYN_UID'] : '');
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-19 10:24:29 -04:00
|
|
|
try {
|
|
|
|
|
$oPro = DynaformPeer::retrieveByPK( $ProUid );
|
|
|
|
|
if (! is_null( $oPro )) {
|
2015-02-12 15:56:30 -04:00
|
|
|
$title = $oPro->getDynTitle();
|
|
|
|
|
$type = $oPro->getDynType();
|
|
|
|
|
$description = $oPro->getDynDescription();
|
|
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
Content::removeContent( 'DYN_TITLE', '', $oPro->getDynUid() );
|
|
|
|
|
Content::removeContent( 'DYN_DESCRIPTION', '', $oPro->getDynUid() );
|
|
|
|
|
$iResult = $oPro->delete();
|
2015-02-12 15:56:30 -04:00
|
|
|
|
|
|
|
|
//Add Audit Log
|
|
|
|
|
G::auditLog("DeleteDynaform", "Dynaform Title: ".$title.", Type: ".$type.", Description: ".$description);
|
|
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
if (file_exists( PATH_DYNAFORM . $oPro->getProUid() . PATH_SEP . $oPro->getDynUid() . '.xml' )) {
|
|
|
|
|
unlink( PATH_DYNAFORM . $oPro->getProUid() . PATH_SEP . $oPro->getDynUid() . '.xml' );
|
|
|
|
|
}
|
|
|
|
|
if (file_exists( PATH_DYNAFORM . $oPro->getProUid() . PATH_SEP . $oPro->getDynUid() . '_tmp0.xml' )) {
|
|
|
|
|
unlink( PATH_DYNAFORM . $oPro->getProUid() . PATH_SEP . $oPro->getDynUid() . '_tmp0.xml' );
|
|
|
|
|
}
|
|
|
|
|
if (file_exists( PATH_DYNAFORM . $oPro->getProUid() . PATH_SEP . $oPro->getDynUid() . '.html' )) {
|
|
|
|
|
unlink( PATH_DYNAFORM . $oPro->getProUid() . PATH_SEP . $oPro->getDynUid() . '.html' );
|
|
|
|
|
}
|
|
|
|
|
if (file_exists( PATH_DYNAFORM . $oPro->getProUid() . PATH_SEP . $oPro->getDynUid() . '_tmp0.html' )) {
|
|
|
|
|
unlink( PATH_DYNAFORM . $oPro->getProUid() . PATH_SEP . $oPro->getDynUid() . '_tmp0.html' );
|
|
|
|
|
}
|
|
|
|
|
return $iResult;
|
|
|
|
|
} else {
|
|
|
|
|
throw (new Exception( "The row '$ProUid' in table Dynaform doesn't exist!" ));
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $oError) {
|
|
|
|
|
throw ($oError);
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-10-19 10:24:29 -04:00
|
|
|
|
|
|
|
|
public function exists ($DynUid)
|
|
|
|
|
{
|
|
|
|
|
$oPro = DynaformPeer::retrieveByPk( $DynUid );
|
|
|
|
|
return (is_object( $oPro ) && get_class( $oPro ) == 'Dynaform');
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-19 10:24:29 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* verify if Dynaform row specified in [DynUid] exists.
|
|
|
|
|
*
|
|
|
|
|
* @param string $sProUid the uid of the Prolication
|
|
|
|
|
*/
|
|
|
|
|
|
2012-10-20 17:19:10 -04:00
|
|
|
public function dynaformExists ($DynUid)
|
2012-10-19 10:24:29 -04:00
|
|
|
{
|
|
|
|
|
$con = Propel::getConnection( TaskPeer::DATABASE_NAME );
|
|
|
|
|
try {
|
|
|
|
|
$oDyn = DynaformPeer::retrieveByPk( $DynUid );
|
|
|
|
|
if (is_object( $oDyn ) && get_class( $oDyn ) == 'Dynaform') {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $oError) {
|
|
|
|
|
throw ($oError);
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-19 10:24:29 -04:00
|
|
|
|
2012-10-20 17:19:10 -04:00
|
|
|
public function getDynaformContent ($dynaformUid)
|
2012-10-19 10:24:29 -04:00
|
|
|
{
|
|
|
|
|
$content = '';
|
|
|
|
|
$fields = $this->Load( $dynaformUid );
|
|
|
|
|
$filename = PATH_DYNAFORM . $fields['PRO_UID'] . PATH_SEP . $fields['DYN_UID'] . '.xml';
|
|
|
|
|
if (file_exists( $filename )) {
|
|
|
|
|
$content = file_get_contents( $filename );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $content;
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-08-16 12:27:59 -04:00
|
|
|
|
2012-10-20 17:19:10 -04:00
|
|
|
public function getDynaformFields ($dynaformUid)
|
2012-10-19 10:24:29 -04:00
|
|
|
{
|
|
|
|
|
$content = '';
|
|
|
|
|
$fields = $this->Load( $dynaformUid );
|
|
|
|
|
$filename = PATH_DYNAFORM . $fields['PRO_UID'] . PATH_SEP . $fields['DYN_UID'] . '.xml';
|
|
|
|
|
if (file_exists( $filename )) {
|
|
|
|
|
$content = file_get_contents( $filename );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$G_FORM = new xmlform( $fields['DYN_FILENAME'], PATH_DYNAFORM );
|
|
|
|
|
$G_FORM->parseFile( $filename, SYS_LANG, true );
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
return $G_FORM->fields;
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-08-16 12:27:59 -04:00
|
|
|
|
2016-12-01 09:32:35 -05:00
|
|
|
public function verifyExistingName ($sName, $sProUid, $sDynUid = null)
|
2012-10-19 10:24:29 -04:00
|
|
|
{
|
|
|
|
|
$sNameDyanform = urldecode( $sName );
|
|
|
|
|
$sProUid = urldecode( $sProUid );
|
|
|
|
|
$oCriteria = new Criteria( 'workflow' );
|
|
|
|
|
$oCriteria->addSelectColumn( DynaformPeer::DYN_UID );
|
|
|
|
|
$oCriteria->add( DynaformPeer::PRO_UID, $sProUid );
|
2016-12-01 09:32:35 -05:00
|
|
|
if (!is_null($sDynUid)) {
|
|
|
|
|
$oCriteria->add(DynaformPeer::DYN_UID, $sDynUid);
|
|
|
|
|
}
|
|
|
|
|
$oCriteria->add( DynaformPeer::DYN_TITLE, $sNameDyanform );
|
2012-10-19 10:24:29 -04:00
|
|
|
$oDataset = DynaformPeer::doSelectRS( $oCriteria );
|
|
|
|
|
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
|
2016-12-01 09:32:35 -05:00
|
|
|
$oDataset->next();
|
|
|
|
|
$aRow = $oDataset->getRow();
|
|
|
|
|
return (!$aRow) ? true : false;
|
2010-12-15 16:59:26 +00:00
|
|
|
}
|
2015-11-06 18:05:20 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* verify if a dynaform is assigned some dynaform
|
|
|
|
|
*
|
|
|
|
|
* @param string $proUid the uid of the process
|
|
|
|
|
* @param string $dynUid the uid of the dynaform
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function verifyDynaformAssignDynaform ($dynUid, $proUid)
|
|
|
|
|
{
|
|
|
|
|
$res = array();
|
|
|
|
|
$oCriteria = new Criteria();
|
|
|
|
|
$oCriteria->addSelectColumn(DynaformPeer::DYN_UID);
|
|
|
|
|
$oCriteria->add(DynaformPeer::PRO_UID, $proUid);
|
|
|
|
|
$oCriteria->add(DynaformPeer::DYN_UID, $dynUid, Criteria::NOT_EQUAL);
|
|
|
|
|
$oCriteria->add(DynaformPeer::DYN_CONTENT, "%" . $dynUid . "%", Criteria::LIKE);
|
|
|
|
|
$oDataset = DynaformPeer::doSelectRS($oCriteria);
|
|
|
|
|
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
while ($oDataset->next()) {
|
|
|
|
|
$res[] = $oDataset->getRow();
|
|
|
|
|
}
|
|
|
|
|
return $res;
|
|
|
|
|
}
|
2012-10-19 10:24:29 -04:00
|
|
|
}
|