Fix to solve class Smarty not found on api request POST to create web-entry HTML based.
This commit is contained in:
@@ -344,8 +344,8 @@ class WebApplication
|
|||||||
set_include_path(get_include_path() . PATH_SEPARATOR . PATH_WORKSPACE);
|
set_include_path(get_include_path() . PATH_SEPARATOR . PATH_WORKSPACE);
|
||||||
|
|
||||||
// smarty constants
|
// smarty constants
|
||||||
// define( "PATH_SMARTY_C", PATH_C . "smarty" . PATH_SEP . "c" );
|
define( "PATH_SMARTY_C", PATH_C . "smarty" . PATH_SEP . "c" );
|
||||||
// define( "PATH_SMARTY_CACHE", PATH_C . "smarty" . PATH_SEP . "cache" );
|
define( "PATH_SMARTY_CACHE", PATH_C . "smarty" . PATH_SEP . "cache" );
|
||||||
|
|
||||||
define("PATH_DATA_SITE", PATH_DATA . "sites/" . SYS_SYS . "/");
|
define("PATH_DATA_SITE", PATH_DATA . "sites/" . SYS_SYS . "/");
|
||||||
define("PATH_DOCUMENT", PATH_DATA_SITE . "files/");
|
define("PATH_DOCUMENT", PATH_DATA_SITE . "files/");
|
||||||
@@ -366,6 +366,33 @@ class WebApplication
|
|||||||
echo "WARNING! No server info found!";
|
echo "WARNING! No server info found!";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Global definitions, before it was the defines.php file
|
||||||
|
*/
|
||||||
|
|
||||||
|
// URL Key
|
||||||
|
define( "URL_KEY", 'c0l0s40pt1mu59r1m3' );
|
||||||
|
|
||||||
|
// Other definitions
|
||||||
|
define( 'TIMEOUT_RESPONSE', 100 ); //web service timeout
|
||||||
|
define( 'APPLICATION_CODE', 'ProcessMaker' ); //to login like workflow system
|
||||||
|
define( 'MAIN_POFILE', 'processmaker' );
|
||||||
|
define( 'PO_SYSTEM_VERSION', 'PM 4.0.1' );
|
||||||
|
|
||||||
|
// Environment definitions
|
||||||
|
define( 'G_PRO_ENV', 'PRODUCTION' );
|
||||||
|
define( 'G_DEV_ENV', 'DEVELOPMENT' );
|
||||||
|
define( 'G_TEST_ENV', 'TEST' );
|
||||||
|
|
||||||
|
// Number of files per folder at PATH_UPLOAD (cases documents)
|
||||||
|
define( 'APPLICATION_DOCUMENTS_PER_FOLDER', 1000 );
|
||||||
|
|
||||||
|
// Server of ProcessMaker Library
|
||||||
|
define( 'PML_SERVER', 'http://library.processmaker.com' );
|
||||||
|
define( 'PML_WSDL_URL', PML_SERVER . '/syspmLibrary/en/green/services/wsdl' );
|
||||||
|
define( 'PML_UPLOAD_URL', PML_SERVER . '/syspmLibrary/en/green/services/uploadProcess' );
|
||||||
|
define( 'PML_DOWNLOAD_URL', PML_SERVER . '/syspmLibrary/en/green/services/download' );
|
||||||
|
|
||||||
// create memcached singleton
|
// create memcached singleton
|
||||||
//\Bootstrap::LoadClass("memcached");
|
//\Bootstrap::LoadClass("memcached");
|
||||||
//$memcache = PMmemcached::getSingleton( SYS_SYS );
|
//$memcache = PMmemcached::getSingleton( SYS_SYS );
|
||||||
|
|||||||
@@ -159,6 +159,7 @@ class Bootstrap
|
|||||||
self::registerClass("XmlForm_Field_cellMark", PATH_GULLIVER . "class.xmlformExtension.php");
|
self::registerClass("XmlForm_Field_cellMark", PATH_GULLIVER . "class.xmlformExtension.php");
|
||||||
self::registerClass("XmlForm_Field_DVEditor", PATH_GULLIVER . "class.xmlformExtension.php");
|
self::registerClass("XmlForm_Field_DVEditor", PATH_GULLIVER . "class.xmlformExtension.php");
|
||||||
self::registerClass("XmlForm_Field_FastSearch", PATH_GULLIVER . "class.xmlformExtension.php");
|
self::registerClass("XmlForm_Field_FastSearch", PATH_GULLIVER . "class.xmlformExtension.php");
|
||||||
|
self::registerClass("xmlformTemplate", PATH_GULLIVER . "class.xmlformTemplate.php");
|
||||||
self::registerClass("ymlDomain", PATH_GULLIVER . "class.ymlDomain.php");
|
self::registerClass("ymlDomain", PATH_GULLIVER . "class.ymlDomain.php");
|
||||||
self::registerClass("ymlTestCases", PATH_GULLIVER . "class.ymlTestCases.php");
|
self::registerClass("ymlTestCases", PATH_GULLIVER . "class.ymlTestCases.php");
|
||||||
|
|
||||||
|
|||||||
@@ -5463,417 +5463,7 @@ class XmlForm
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Class xmlformTemplate
|
|
||||||
*
|
|
||||||
* @author David S. Callizaya S. <davidsantos@colosa.com>
|
|
||||||
* @package gulliver.system
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
class xmlformTemplate extends Smarty
|
|
||||||
{
|
|
||||||
public $template;
|
|
||||||
public $templateFile;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function xmlformTemplate
|
|
||||||
*
|
|
||||||
* @author David S. Callizaya S. <davidsantos@colosa.com>
|
|
||||||
* @access public
|
|
||||||
* @param string form
|
|
||||||
* @param string templateFile
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function xmlformTemplate (&$form, $templateFile)
|
|
||||||
{
|
|
||||||
$this->template_dir = PATH_XMLFORM;
|
|
||||||
$this->compile_dir = PATH_SMARTY_C;
|
|
||||||
$this->cache_dir = PATH_SMARTY_CACHE;
|
|
||||||
$this->config_dir = PATH_THIRDPARTY . 'smarty/configs';
|
|
||||||
$this->caching = false;
|
|
||||||
|
|
||||||
// register the resource name "db"
|
|
||||||
$this->templateFile = $templateFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function printTemplate
|
|
||||||
*
|
|
||||||
* @author David S. Callizaya S. <davidsantos@colosa.com>
|
|
||||||
* @access public
|
|
||||||
* @param string form
|
|
||||||
* @param string target
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function printTemplate (&$form, $target = 'smarty')
|
|
||||||
{
|
|
||||||
if (strcasecmp( $target, 'smarty' ) === 0) {
|
|
||||||
$varPrefix = '$';
|
|
||||||
}
|
|
||||||
if (strcasecmp( $target, 'templatePower' ) === 0) {
|
|
||||||
$varPrefix = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
$ft = new StdClass();
|
|
||||||
foreach ($form as $name => $value) {
|
|
||||||
if (($name !== 'fields') && ($value !== '')) {
|
|
||||||
$ft->{$name} = '{$form_' . $name . '}';
|
|
||||||
}
|
|
||||||
if ($name === 'cols') {
|
|
||||||
$ft->{$name} = $value;
|
|
||||||
}
|
|
||||||
if ($name === 'owner') {
|
|
||||||
$ft->owner = & $form->owner;
|
|
||||||
}
|
|
||||||
if ($name === 'deleteRow') {
|
|
||||||
$ft->deleteRow = $form->deleteRow;
|
|
||||||
}
|
|
||||||
if ($name === 'addRow') {
|
|
||||||
$ft->addRow = $form->addRow;
|
|
||||||
}
|
|
||||||
if ($name === 'editRow') {
|
|
||||||
$ft->editRow = $form->editRow;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (! isset( $ft->action )) {
|
|
||||||
$ft->action = '{$form_action}';
|
|
||||||
}
|
|
||||||
$hasRequiredFields = false;
|
|
||||||
|
|
||||||
foreach ($form->fields as $k => $v) {
|
|
||||||
$ft->fields[$k] = $v->cloneObject();
|
|
||||||
$ft->fields[$k]->label = '{' . $varPrefix . $k . '}';
|
|
||||||
|
|
||||||
if ($form->type === 'grid') {
|
|
||||||
if (strcasecmp( $target, 'smarty' ) === 0) {
|
|
||||||
$ft->fields[$k]->field = '{' . $varPrefix . 'form.' . $k . '[row]}';
|
|
||||||
}
|
|
||||||
if (strcasecmp( $target, 'templatePower' ) === 0) {
|
|
||||||
$ft->fields[$k]->field = '{' . $varPrefix . 'form[' . $k . '][row]}';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (strcasecmp( $target, 'smarty' ) === 0) {
|
|
||||||
$ft->fields[$k]->field = '{' . $varPrefix . 'form.' . $k . '}';
|
|
||||||
}
|
|
||||||
if (strcasecmp( $target, 'templatePower' ) === 0) {
|
|
||||||
$ft->fields[$k]->field = '{' . $varPrefix . 'form[' . $k . ']}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$hasRequiredFields = $hasRequiredFields | (isset( $v->required ) && ($v->required == '1') && ($v->mode == 'edit'));
|
|
||||||
|
|
||||||
if ($v->type == 'xmlmenu') {
|
|
||||||
$menu = $v;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset( $menu )) {
|
|
||||||
if (isset( $menu->owner->values['__DYNAFORM_OPTIONS']['PREVIOUS_STEP'] )) {
|
|
||||||
$prevStep_url = $menu->owner->values['__DYNAFORM_OPTIONS']['PREVIOUS_STEP'];
|
|
||||||
|
|
||||||
$this->assign( 'prevStep_url', $prevStep_url );
|
|
||||||
$this->assign( 'prevStep_label', G::loadTranslation( 'ID_BACK' ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->assign( 'hasRequiredFields', $hasRequiredFields );
|
|
||||||
$this->assign( 'form', $ft );
|
|
||||||
$this->assign( 'printTemplate', true );
|
|
||||||
$this->assign( 'printJSFile', false );
|
|
||||||
$this->assign( 'printJavaScript', false );
|
|
||||||
//$this->assign ( 'dynaformSetFocus', "try {literal}{{/literal} dynaformSetFocus();}catch(e){literal}{{/literal}}" );
|
|
||||||
return $this->fetch( $this->templateFile );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function printJavaScript
|
|
||||||
*
|
|
||||||
* @author David S. Callizaya S. <davidsantos@colosa.com>
|
|
||||||
* @access public
|
|
||||||
* @param string form
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function printJavaScript (&$form)
|
|
||||||
{
|
|
||||||
$this->assign( 'form', $form );
|
|
||||||
$this->assign( 'printTemplate', false );
|
|
||||||
$this->assign( 'printJSFile', false );
|
|
||||||
$this->assign( 'printJavaScript', true );
|
|
||||||
return $this->fetch( $this->templateFile );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function printJSFile
|
|
||||||
*
|
|
||||||
* @author David S. Callizaya S. <davidsantos@colosa.com>
|
|
||||||
* @access public
|
|
||||||
* @param string form
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function printJSFile (&$form)
|
|
||||||
{
|
|
||||||
//JS designer>preview
|
|
||||||
if (isset($_SERVER["HTTP_REFERER"]) && !empty($_SERVER["HTTP_REFERER"]) && preg_match("/^.*dynaforms_Editor\?.*PRO_UID=.*DYN_UID=.*$/", $_SERVER["HTTP_REFERER"]) && preg_match("/^.*dynaforms\/dynaforms_Ajax.*$/", $_SERVER["REQUEST_URI"])) {
|
|
||||||
$js = null;
|
|
||||||
|
|
||||||
foreach ($form->fields as $index => $value) {
|
|
||||||
$field = $value;
|
|
||||||
|
|
||||||
if ($field->type == "javascript" && !empty($field->code)) {
|
|
||||||
$js = $js . " " . $field->code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($js != null) {
|
|
||||||
$form->jsDesignerPreview = "
|
|
||||||
//JS designer>preview
|
|
||||||
$js
|
|
||||||
|
|
||||||
loadForm_" . $form->id . "(\"../gulliver/defaultAjaxDynaform\");
|
|
||||||
|
|
||||||
if (typeof(dynaformOnload) != \"undefined\") {
|
|
||||||
dynaformOnload();
|
|
||||||
}
|
|
||||||
";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->assign( 'form', $form );
|
|
||||||
$this->assign( 'printTemplate', false );
|
|
||||||
$this->assign( 'printJSFile', true );
|
|
||||||
$this->assign( 'printJavaScript', false );
|
|
||||||
return $this->fetch( $this->templateFile );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function getFields
|
|
||||||
*
|
|
||||||
* @author David S. Callizaya S. <davidsantos@colosa.com>
|
|
||||||
* @access public
|
|
||||||
* @param string form
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getFields (&$form, $therow = -1)
|
|
||||||
{
|
|
||||||
$result = array ();
|
|
||||||
|
|
||||||
foreach ($form->fields as $k => $v) {
|
|
||||||
$field = $v;
|
|
||||||
|
|
||||||
if ($form->mode != '') {
|
|
||||||
#@ last modification: erik
|
|
||||||
$field->mode = $form->mode; #@
|
|
||||||
} #@
|
|
||||||
|
|
||||||
//if (isset($form->fields[$k]->sql)) $form->fields[$k]->executeSQL( $form );
|
|
||||||
$value = (isset( $form->values[$k] )) ? $form->values[$k] : null;
|
|
||||||
$result[$k] = G::replaceDataField( $form->fields[$k]->label, $form->values );
|
|
||||||
|
|
||||||
if ($form->type == 'xmlform') {
|
|
||||||
if (in_array($field->type, array("text", "currency", "percentage", "password", "suggest", "textarea", "dropdown", "yesno", "listbox", "checkbox", "date", "link", "file"))) {
|
|
||||||
$result[$k] = '<label for="form[' . $k . ']">' . $result[$k] . '</label>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! is_array( $value )) {
|
|
||||||
if ($form->type == 'grid') {
|
|
||||||
$aAux = array ();
|
|
||||||
if (!isset($form->values[$form->name])) {
|
|
||||||
$form->values[$form->name] = array();
|
|
||||||
}
|
|
||||||
if ($therow == - 1) {
|
|
||||||
for ($i = 0; $i < count( $form->values[$form->name] ); $i ++) {
|
|
||||||
$aAux[] = '';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for ($i = 0; $i < $therow; $i ++) {
|
|
||||||
$aAux[] = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ($field->type) {
|
|
||||||
case "link":
|
|
||||||
$result["form"][$k] = $form->fields[$k]->renderGrid($aAux, array(), $form);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$result["form"][$k] = $form->fields[$k]->renderGrid($aAux, $form);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
switch ($field->type) {
|
|
||||||
case "link":
|
|
||||||
$result["form"][$k] = $form->fields[$k]->render(
|
|
||||||
$value,
|
|
||||||
(isset($form->values[$k . "_label"]))? $form->values[$k . "_label"] : null,
|
|
||||||
$form
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$result["form"][$k] = $form->fields[$k]->render($value, $form);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/*if (isset ( $form->owner )) {
|
|
||||||
if (count ( $value ) < count ( $form->owner->values [$form->name] )) {
|
|
||||||
$i = count ( $value );
|
|
||||||
$j = count ( $form->owner->values [$form->name] );
|
|
||||||
|
|
||||||
for($i; $i < $j; $i ++) {
|
|
||||||
$value [] = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if ($field->type == "grid") {
|
|
||||||
// Fix data for grids
|
|
||||||
if (is_array($form->fields[$k]->fields)) {
|
|
||||||
foreach ($form->fields[$k]->fields as $gridFieldName => $gridField) {
|
|
||||||
$valueLength = count($value);
|
|
||||||
for ($i = 1; $i <= $valueLength; $i++) {
|
|
||||||
if (!isset($value[$i][$gridFieldName])) {
|
|
||||||
switch ($gridField->type) {
|
|
||||||
case 'checkbox':
|
|
||||||
$defaultAttribute = 'falseValue';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$defaultAttribute = 'defaultValue';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$value[$i][$gridFieldName] = isset($gridField->$defaultAttribute) ? $gridField->$defaultAttribute : '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$form->fields[$k]->setScrollStyle( $form );
|
|
||||||
$result["form"][$k] = $form->fields[$k]->renderGrid( $value, $form, $therow );
|
|
||||||
} else {
|
|
||||||
switch ($field->type) {
|
|
||||||
case "dropdown":
|
|
||||||
$result["form"][$k] = $form->fields[$k]->renderGrid( $value, $form, false, $therow );
|
|
||||||
break;
|
|
||||||
case "file":
|
|
||||||
$result["form"][$k] = $form->fields[$k]->renderGrid( $value, $form, $therow );
|
|
||||||
break;
|
|
||||||
case "link":
|
|
||||||
$result["form"][$k] = $form->fields[$k]->renderGrid(
|
|
||||||
$value,
|
|
||||||
(isset($form->values[$k . "_label"]))? $form->values[$k . "_label"] : array(),
|
|
||||||
$form
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$result["form"][$k] = $form->fields[$k]->renderGrid( $value, $form );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($form as $name => $value) {
|
|
||||||
if ($name !== 'fields') {
|
|
||||||
$result['form_' . $name] = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function printObject
|
|
||||||
* @author David S. Callizaya S. <davidsantos@colosa.com>
|
|
||||||
* @access public
|
|
||||||
* @param string form
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function printObject(&$form, $therow = -1)
|
|
||||||
{
|
|
||||||
//to do: generate the template for templatePower.
|
|
||||||
//DONE: The template was generated in printTemplate, to use it
|
|
||||||
// is necesary to load the file with templatePower and send the array
|
|
||||||
//result
|
|
||||||
$this->register_resource ( 'mem', array (array (&$this, '_get_template' ), array ($this, '_get_timestamp' ), array ($this, '_get_secure' ), array ($this, '_get_trusted' ) ) );
|
|
||||||
$result = $this->getFields ( $form, $therow );
|
|
||||||
|
|
||||||
$this->assign ( array ('PATH_TPL' => PATH_TPL ) );
|
|
||||||
$this->assign ( $result );
|
|
||||||
if ( defined('SYS_LANG_DIRECTION') && SYS_LANG_DIRECTION == 'R' ) {
|
|
||||||
switch( $form->type ){
|
|
||||||
case 'toolbar':
|
|
||||||
$form->align = 'right';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->assign ( array ('_form' => $form ) );
|
|
||||||
//'mem:defaultTemplate'.$form->name obtains the template generated for the
|
|
||||||
//current "form" object, then this resource y saved by Smarty in the
|
|
||||||
//cache_dir. To avoiding troubles when two forms with the same id are being
|
|
||||||
//drawed in a same page with different templates, add an . rand(1,1000)
|
|
||||||
//to the resource name. This is because the process of creating templates
|
|
||||||
//(with the method "printTemplate") and painting takes less than 1 second
|
|
||||||
//so the new template resource generally will had the same timestamp.
|
|
||||||
$output = $this->fetch ( 'mem:defaultTemplate' . $form->name );
|
|
||||||
return $output;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Smarty plugin
|
|
||||||
* -------------------------------------------------------------
|
|
||||||
* Type: resource
|
|
||||||
* Name: mem
|
|
||||||
* Purpose: Fetches templates from this object
|
|
||||||
* -------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
public function _get_template($tpl_name, &$tpl_source, &$smarty_obj)
|
|
||||||
{
|
|
||||||
$tpl_source = $this->template;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function _get_timestamp
|
|
||||||
* @author David S. Callizaya S. <davidsantos@colosa.com>
|
|
||||||
* @access public
|
|
||||||
* @param string tpl_name
|
|
||||||
* @param string tpl_timestamp
|
|
||||||
* @param string smarty_obj
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function _get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
|
|
||||||
{
|
|
||||||
//NOTE: +1 prevents to load the smarty cache instead of this resource
|
|
||||||
$tpl_timestamp = time () + 1;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function _get_secure
|
|
||||||
* @author David S. Callizaya S. <davidsantos@colosa.com>
|
|
||||||
* @access public
|
|
||||||
* @param string tpl_name
|
|
||||||
* @param string smarty_obj
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function _get_secure($tpl_name, &$smarty_obj)
|
|
||||||
{
|
|
||||||
// assume all templates are secure
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function _get_trusted
|
|
||||||
* @author David S. Callizaya S. <davidsantos@colosa.com>
|
|
||||||
* @access public
|
|
||||||
* @param string tpl_name
|
|
||||||
* @param string smarty_obj
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function _get_trusted($tpl_name, &$smarty_obj)
|
|
||||||
{
|
|
||||||
// not used for templates
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @package gulliver.system
|
* @package gulliver.system
|
||||||
|
|||||||
412
gulliver/system/class.xmlformTemplate.php
Normal file
412
gulliver/system/class.xmlformTemplate.php
Normal file
@@ -0,0 +1,412 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Class xmlformTemplate
|
||||||
|
*
|
||||||
|
* @author David S. Callizaya S. <davidsantos@colosa.com>
|
||||||
|
* @package gulliver.system
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
class xmlformTemplate extends Smarty
|
||||||
|
{
|
||||||
|
public $template;
|
||||||
|
public $templateFile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function xmlformTemplate
|
||||||
|
*
|
||||||
|
* @author David S. Callizaya S. <davidsantos@colosa.com>
|
||||||
|
* @access public
|
||||||
|
* @param string form
|
||||||
|
* @param string templateFile
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function xmlformTemplate (&$form, $templateFile)
|
||||||
|
{
|
||||||
|
$this->template_dir = PATH_XMLFORM;
|
||||||
|
$this->compile_dir = PATH_SMARTY_C;
|
||||||
|
$this->cache_dir = PATH_SMARTY_CACHE;
|
||||||
|
$this->config_dir = PATH_THIRDPARTY . 'smarty/configs';
|
||||||
|
$this->caching = false;
|
||||||
|
|
||||||
|
// register the resource name "db"
|
||||||
|
$this->templateFile = $templateFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function printTemplate
|
||||||
|
*
|
||||||
|
* @author David S. Callizaya S. <davidsantos@colosa.com>
|
||||||
|
* @access public
|
||||||
|
* @param string form
|
||||||
|
* @param string target
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function printTemplate (&$form, $target = 'smarty')
|
||||||
|
{
|
||||||
|
if (strcasecmp( $target, 'smarty' ) === 0) {
|
||||||
|
$varPrefix = '$';
|
||||||
|
}
|
||||||
|
if (strcasecmp( $target, 'templatePower' ) === 0) {
|
||||||
|
$varPrefix = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$ft = new StdClass();
|
||||||
|
foreach ($form as $name => $value) {
|
||||||
|
if (($name !== 'fields') && ($value !== '')) {
|
||||||
|
$ft->{$name} = '{$form_' . $name . '}';
|
||||||
|
}
|
||||||
|
if ($name === 'cols') {
|
||||||
|
$ft->{$name} = $value;
|
||||||
|
}
|
||||||
|
if ($name === 'owner') {
|
||||||
|
$ft->owner = & $form->owner;
|
||||||
|
}
|
||||||
|
if ($name === 'deleteRow') {
|
||||||
|
$ft->deleteRow = $form->deleteRow;
|
||||||
|
}
|
||||||
|
if ($name === 'addRow') {
|
||||||
|
$ft->addRow = $form->addRow;
|
||||||
|
}
|
||||||
|
if ($name === 'editRow') {
|
||||||
|
$ft->editRow = $form->editRow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (! isset( $ft->action )) {
|
||||||
|
$ft->action = '{$form_action}';
|
||||||
|
}
|
||||||
|
$hasRequiredFields = false;
|
||||||
|
|
||||||
|
foreach ($form->fields as $k => $v) {
|
||||||
|
$ft->fields[$k] = $v->cloneObject();
|
||||||
|
$ft->fields[$k]->label = '{' . $varPrefix . $k . '}';
|
||||||
|
|
||||||
|
if ($form->type === 'grid') {
|
||||||
|
if (strcasecmp( $target, 'smarty' ) === 0) {
|
||||||
|
$ft->fields[$k]->field = '{' . $varPrefix . 'form.' . $k . '[row]}';
|
||||||
|
}
|
||||||
|
if (strcasecmp( $target, 'templatePower' ) === 0) {
|
||||||
|
$ft->fields[$k]->field = '{' . $varPrefix . 'form[' . $k . '][row]}';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (strcasecmp( $target, 'smarty' ) === 0) {
|
||||||
|
$ft->fields[$k]->field = '{' . $varPrefix . 'form.' . $k . '}';
|
||||||
|
}
|
||||||
|
if (strcasecmp( $target, 'templatePower' ) === 0) {
|
||||||
|
$ft->fields[$k]->field = '{' . $varPrefix . 'form[' . $k . ']}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$hasRequiredFields = $hasRequiredFields | (isset( $v->required ) && ($v->required == '1') && ($v->mode == 'edit'));
|
||||||
|
|
||||||
|
if ($v->type == 'xmlmenu') {
|
||||||
|
$menu = $v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset( $menu )) {
|
||||||
|
if (isset( $menu->owner->values['__DYNAFORM_OPTIONS']['PREVIOUS_STEP'] )) {
|
||||||
|
$prevStep_url = $menu->owner->values['__DYNAFORM_OPTIONS']['PREVIOUS_STEP'];
|
||||||
|
|
||||||
|
$this->assign( 'prevStep_url', $prevStep_url );
|
||||||
|
$this->assign( 'prevStep_label', G::loadTranslation( 'ID_BACK' ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assign( 'hasRequiredFields', $hasRequiredFields );
|
||||||
|
$this->assign( 'form', $ft );
|
||||||
|
$this->assign( 'printTemplate', true );
|
||||||
|
$this->assign( 'printJSFile', false );
|
||||||
|
$this->assign( 'printJavaScript', false );
|
||||||
|
//$this->assign ( 'dynaformSetFocus', "try {literal}{{/literal} dynaformSetFocus();}catch(e){literal}{{/literal}}" );
|
||||||
|
return $this->fetch( $this->templateFile );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function printJavaScript
|
||||||
|
*
|
||||||
|
* @author David S. Callizaya S. <davidsantos@colosa.com>
|
||||||
|
* @access public
|
||||||
|
* @param string form
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function printJavaScript (&$form)
|
||||||
|
{
|
||||||
|
$this->assign( 'form', $form );
|
||||||
|
$this->assign( 'printTemplate', false );
|
||||||
|
$this->assign( 'printJSFile', false );
|
||||||
|
$this->assign( 'printJavaScript', true );
|
||||||
|
return $this->fetch( $this->templateFile );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function printJSFile
|
||||||
|
*
|
||||||
|
* @author David S. Callizaya S. <davidsantos@colosa.com>
|
||||||
|
* @access public
|
||||||
|
* @param string form
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function printJSFile (&$form)
|
||||||
|
{
|
||||||
|
//JS designer>preview
|
||||||
|
if (isset($_SERVER["HTTP_REFERER"]) && !empty($_SERVER["HTTP_REFERER"]) && preg_match("/^.*dynaforms_Editor\?.*PRO_UID=.*DYN_UID=.*$/", $_SERVER["HTTP_REFERER"]) && preg_match("/^.*dynaforms\/dynaforms_Ajax.*$/", $_SERVER["REQUEST_URI"])) {
|
||||||
|
$js = null;
|
||||||
|
|
||||||
|
foreach ($form->fields as $index => $value) {
|
||||||
|
$field = $value;
|
||||||
|
|
||||||
|
if ($field->type == "javascript" && !empty($field->code)) {
|
||||||
|
$js = $js . " " . $field->code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($js != null) {
|
||||||
|
$form->jsDesignerPreview = "
|
||||||
|
//JS designer>preview
|
||||||
|
$js
|
||||||
|
|
||||||
|
loadForm_" . $form->id . "(\"../gulliver/defaultAjaxDynaform\");
|
||||||
|
|
||||||
|
if (typeof(dynaformOnload) != \"undefined\") {
|
||||||
|
dynaformOnload();
|
||||||
|
}
|
||||||
|
";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assign( 'form', $form );
|
||||||
|
$this->assign( 'printTemplate', false );
|
||||||
|
$this->assign( 'printJSFile', true );
|
||||||
|
$this->assign( 'printJavaScript', false );
|
||||||
|
return $this->fetch( $this->templateFile );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function getFields
|
||||||
|
*
|
||||||
|
* @author David S. Callizaya S. <davidsantos@colosa.com>
|
||||||
|
* @access public
|
||||||
|
* @param string form
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getFields (&$form, $therow = -1)
|
||||||
|
{
|
||||||
|
$result = array ();
|
||||||
|
|
||||||
|
foreach ($form->fields as $k => $v) {
|
||||||
|
$field = $v;
|
||||||
|
|
||||||
|
if ($form->mode != '') {
|
||||||
|
#@ last modification: erik
|
||||||
|
$field->mode = $form->mode; #@
|
||||||
|
} #@
|
||||||
|
|
||||||
|
//if (isset($form->fields[$k]->sql)) $form->fields[$k]->executeSQL( $form );
|
||||||
|
$value = (isset( $form->values[$k] )) ? $form->values[$k] : null;
|
||||||
|
$result[$k] = G::replaceDataField( $form->fields[$k]->label, $form->values );
|
||||||
|
|
||||||
|
if ($form->type == 'xmlform') {
|
||||||
|
if (in_array($field->type, array("text", "currency", "percentage", "password", "suggest", "textarea", "dropdown", "yesno", "listbox", "checkbox", "date", "link", "file"))) {
|
||||||
|
$result[$k] = '<label for="form[' . $k . ']">' . $result[$k] . '</label>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! is_array( $value )) {
|
||||||
|
if ($form->type == 'grid') {
|
||||||
|
$aAux = array ();
|
||||||
|
if (!isset($form->values[$form->name])) {
|
||||||
|
$form->values[$form->name] = array();
|
||||||
|
}
|
||||||
|
if ($therow == - 1) {
|
||||||
|
for ($i = 0; $i < count( $form->values[$form->name] ); $i ++) {
|
||||||
|
$aAux[] = '';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for ($i = 0; $i < $therow; $i ++) {
|
||||||
|
$aAux[] = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($field->type) {
|
||||||
|
case "link":
|
||||||
|
$result["form"][$k] = $form->fields[$k]->renderGrid($aAux, array(), $form);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$result["form"][$k] = $form->fields[$k]->renderGrid($aAux, $form);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch ($field->type) {
|
||||||
|
case "link":
|
||||||
|
$result["form"][$k] = $form->fields[$k]->render(
|
||||||
|
$value,
|
||||||
|
(isset($form->values[$k . "_label"]))? $form->values[$k . "_label"] : null,
|
||||||
|
$form
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$result["form"][$k] = $form->fields[$k]->render($value, $form);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/*if (isset ( $form->owner )) {
|
||||||
|
if (count ( $value ) < count ( $form->owner->values [$form->name] )) {
|
||||||
|
$i = count ( $value );
|
||||||
|
$j = count ( $form->owner->values [$form->name] );
|
||||||
|
|
||||||
|
for($i; $i < $j; $i ++) {
|
||||||
|
$value [] = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
if ($field->type == "grid") {
|
||||||
|
// Fix data for grids
|
||||||
|
if (is_array($form->fields[$k]->fields)) {
|
||||||
|
foreach ($form->fields[$k]->fields as $gridFieldName => $gridField) {
|
||||||
|
$valueLength = count($value);
|
||||||
|
for ($i = 1; $i <= $valueLength; $i++) {
|
||||||
|
if (!isset($value[$i][$gridFieldName])) {
|
||||||
|
switch ($gridField->type) {
|
||||||
|
case 'checkbox':
|
||||||
|
$defaultAttribute = 'falseValue';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$defaultAttribute = 'defaultValue';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$value[$i][$gridFieldName] = isset($gridField->$defaultAttribute) ? $gridField->$defaultAttribute : '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$form->fields[$k]->setScrollStyle( $form );
|
||||||
|
$result["form"][$k] = $form->fields[$k]->renderGrid( $value, $form, $therow );
|
||||||
|
} else {
|
||||||
|
switch ($field->type) {
|
||||||
|
case "dropdown":
|
||||||
|
$result["form"][$k] = $form->fields[$k]->renderGrid( $value, $form, false, $therow );
|
||||||
|
break;
|
||||||
|
case "file":
|
||||||
|
$result["form"][$k] = $form->fields[$k]->renderGrid( $value, $form, $therow );
|
||||||
|
break;
|
||||||
|
case "link":
|
||||||
|
$result["form"][$k] = $form->fields[$k]->renderGrid(
|
||||||
|
$value,
|
||||||
|
(isset($form->values[$k . "_label"]))? $form->values[$k . "_label"] : array(),
|
||||||
|
$form
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$result["form"][$k] = $form->fields[$k]->renderGrid( $value, $form );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($form as $name => $value) {
|
||||||
|
if ($name !== 'fields') {
|
||||||
|
$result['form_' . $name] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function printObject
|
||||||
|
* @author David S. Callizaya S. <davidsantos@colosa.com>
|
||||||
|
* @access public
|
||||||
|
* @param string form
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function printObject(&$form, $therow = -1)
|
||||||
|
{
|
||||||
|
//to do: generate the template for templatePower.
|
||||||
|
//DONE: The template was generated in printTemplate, to use it
|
||||||
|
// is necesary to load the file with templatePower and send the array
|
||||||
|
//result
|
||||||
|
$this->register_resource ( 'mem', array (array (&$this, '_get_template' ), array ($this, '_get_timestamp' ), array ($this, '_get_secure' ), array ($this, '_get_trusted' ) ) );
|
||||||
|
$result = $this->getFields ( $form, $therow );
|
||||||
|
|
||||||
|
$this->assign ( array ('PATH_TPL' => PATH_TPL ) );
|
||||||
|
$this->assign ( $result );
|
||||||
|
if ( defined('SYS_LANG_DIRECTION') && SYS_LANG_DIRECTION == 'R' ) {
|
||||||
|
switch( $form->type ){
|
||||||
|
case 'toolbar':
|
||||||
|
$form->align = 'right';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assign ( array ('_form' => $form ) );
|
||||||
|
//'mem:defaultTemplate'.$form->name obtains the template generated for the
|
||||||
|
//current "form" object, then this resource y saved by Smarty in the
|
||||||
|
//cache_dir. To avoiding troubles when two forms with the same id are being
|
||||||
|
//drawed in a same page with different templates, add an . rand(1,1000)
|
||||||
|
//to the resource name. This is because the process of creating templates
|
||||||
|
//(with the method "printTemplate") and painting takes less than 1 second
|
||||||
|
//so the new template resource generally will had the same timestamp.
|
||||||
|
$output = $this->fetch ( 'mem:defaultTemplate' . $form->name );
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smarty plugin
|
||||||
|
* -------------------------------------------------------------
|
||||||
|
* Type: resource
|
||||||
|
* Name: mem
|
||||||
|
* Purpose: Fetches templates from this object
|
||||||
|
* -------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
public function _get_template($tpl_name, &$tpl_source, &$smarty_obj)
|
||||||
|
{
|
||||||
|
$tpl_source = $this->template;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function _get_timestamp
|
||||||
|
* @author David S. Callizaya S. <davidsantos@colosa.com>
|
||||||
|
* @access public
|
||||||
|
* @param string tpl_name
|
||||||
|
* @param string tpl_timestamp
|
||||||
|
* @param string smarty_obj
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function _get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
|
||||||
|
{
|
||||||
|
//NOTE: +1 prevents to load the smarty cache instead of this resource
|
||||||
|
$tpl_timestamp = time () + 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function _get_secure
|
||||||
|
* @author David S. Callizaya S. <davidsantos@colosa.com>
|
||||||
|
* @access public
|
||||||
|
* @param string tpl_name
|
||||||
|
* @param string smarty_obj
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function _get_secure($tpl_name, &$smarty_obj)
|
||||||
|
{
|
||||||
|
// assume all templates are secure
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function _get_trusted
|
||||||
|
* @author David S. Callizaya S. <davidsantos@colosa.com>
|
||||||
|
* @access public
|
||||||
|
* @param string tpl_name
|
||||||
|
* @param string smarty_obj
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function _get_trusted($tpl_name, &$smarty_obj)
|
||||||
|
{
|
||||||
|
// not used for templates
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -477,6 +477,11 @@ class WebEntry
|
|||||||
case "HTML":
|
case "HTML":
|
||||||
global $G_FORM;
|
global $G_FORM;
|
||||||
|
|
||||||
|
if (! class_exists("Smarty")) {
|
||||||
|
$loader = \Maveriks\Util\ClassLoader::getInstance();
|
||||||
|
$loader->addClass("Smarty", PATH_THIRDPARTY . "smarty".PATH_SEP."libs".PATH_SEP."Smarty.class.php");
|
||||||
|
}
|
||||||
|
|
||||||
$G_FORM = new \Form($processUid . "/" . $dynaFormUid, PATH_DYNAFORM, SYS_LANG, false);
|
$G_FORM = new \Form($processUid . "/" . $dynaFormUid, PATH_DYNAFORM, SYS_LANG, false);
|
||||||
$G_FORM->action = $http . $_SERVER["HTTP_HOST"] . "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/services/cases_StartExternal.php";
|
$G_FORM->action = $http . $_SERVER["HTTP_HOST"] . "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/services/cases_StartExternal.php";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user