/** * * * 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 * */ public function createFromPMTable($aData, $pmTableUid) { $this->create($aData, $pmTableUid); $aData['DYN_UID'] = $this->getDynUid(); //krumo(BasePeer::getFieldnames('Content')); $fields = array(); //$oCriteria = new Criteria('workflow'); $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']; } } } else { $keys = ' '; } // $addTabKeys = $pmTable->getAddTabDynavars(); // $addTabKeys = unserialize($addTabKeys); // $keys = ''; // foreach ( $addTabKeys as $addTabKey ){ // if (trim($addTabKey['CASE_VARIABLE'])!=''&&$keys!=''){ // $keys = $keys.'|'.$addTabKey['CASE_VARIABLE']; // } else { // $keys = $addTabKey['CASE_VARIABLE']; // } // // } // 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); } else { $sql = 'DESC ' . $addTabName; } $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'); $ses = new DBSession($dbc); $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); } $keyRequered = ''; $countKeys = 0; while ($res->next()) { if ($res->get('Key') != '') { $countKeys++; } if ($res->get('Extra') == 'auto_increment') { $keyRequered .= $res->get('Field'); } } $dbh = Propel::getConnection(AdditionalTablesPeer::DATABASE_NAME); $sth = $dbh->createStatement(); $res = $sth->executeQuery($sql, ResultSet::FETCHMODE_ASSOC); while ($res->next()) { // if(strtoupper($res->get('Null'))=='NO') { 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); //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; } //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); array_push($items, array(array("type" => $type, "dataType" => $dataType, "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); } }
/** * * * 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 * */ public function createFromPMTable($aData, $pmTableUid) { $this->create($aData); $aData['DYN_UID'] = $this->getDynUid(); //krumo(BasePeer::getFieldnames('Content')); $fields = array(); //$oCriteria = new Criteria('workflow'); $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']; } } } else { $keys = ' '; } // $addTabKeys = $pmTable->getAddTabDynavars(); // $addTabKeys = unserialize($addTabKeys); // $keys = ''; // foreach ( $addTabKeys as $addTabKey ){ // if (trim($addTabKey['CASE_VARIABLE'])!=''&&$keys!=''){ // $keys = $keys.'|'.$addTabKey['CASE_VARIABLE']; // } else { // $keys = $addTabKey['CASE_VARIABLE']; // } // // } // 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); } else { $sql = 'DESC ' . $addTabName; } $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'); $ses = new DBSession($dbc); $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); } $keyRequered = ''; $countKeys = 0; while ($res->next()) { if ($res->get('Key') != '') { $countKeys++; } if ($res->get('Extra') == 'auto_increment') { $keyRequered .= $res->get('Field'); } } $dbh = Propel::getConnection(AdditionalTablesPeer::DATABASE_NAME); $sth = $dbh->createStatement(); $res = $sth->executeQuery($sql, ResultSet::FETCHMODE_ASSOC); while ($res->next()) { // if(strtoupper($res->get('Null'))=='NO') { 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); }
}*/ } } } else { if (is_array($value)) { //Is a list: if (is_string(reset($value))) { $attributes[$key] = implode(',', $value); } else { //Is a grid. } } } } unset($attributes['VALIDATE_NAME']); $fields->Save($attributes, $labels, $options); G::LoadClass('xmlDb'); $i = 0; $aFields = array(); $aFields[] = array('XMLNODE_NAME' => 'char', 'TYPE' => 'char', 'UP' => 'char', 'DOWN' => 'char', 'row__' => 'integer'); $oSession = new DBSession(new DBConnection(PATH_DYNAFORM . $file . '.xml', '', '', '', 'myxml')); $oDataset = $oSession->Execute('SELECT * FROM dynaForm WHERE NOT( XMLNODE_NAME = "" )'); $iMaximun = $oDataset->count(); while ($aRow = $oDataset->Read()) { $aFields[] = array('XMLNODE_NAME' => $aRow['XMLNODE_NAME'], 'TYPE' => $aRow['TYPE'], 'UP' => $i > 0 ? G::LoadTranslation('ID_UP') : '', 'DOWN' => $i < $iMaximun - 1 ? G::LoadTranslation('ID_DOWN') : '', 'row__' => $i + 1); $i++; } global $_DBArray; $_DBArray['fields'] = $aFields; $_SESSION['_DBArray'] = $_DBArray; // Additions to javascript