public function evaluateVariable()
 {
     $process = new Process();
     if (!$process->isBpmnProcess($_SESSION['PROCESS'])) {
         return;
     }
     require_once PATH_CORE . 'controllers/pmTablesProxy.php';
     $pmTablesProxy = new pmTablesProxy();
     $variableModule = new ProcessMaker\BusinessModel\Variable();
     $searchTypes = array('checkgroup', 'dropdown', 'suggest');
     $processVariables = $pmTablesProxy->getDynaformVariables($_SESSION['PROCESS'], $searchTypes, false);
     $variables = $this->affected_fields;
     $variables = array_unique($variables);
     $newFields = array();
     $arrayValues = array();
     $arrayLabels = array();
     if (is_array($variables) && is_array($processVariables)) {
         foreach ($variables as $var) {
             if (strpos($var, '_label') === false) {
                 if (in_array($var, $processVariables)) {
                     if (isset($this->aFields[$var]) && is_array($this->aFields[$var][1])) {
                         $varLabel = $var . '_label';
                         $arrayValue = $this->aFields[$var];
                         if (is_array($arrayValue) && sizeof($arrayValue)) {
                             foreach ($arrayValue as $val) {
                                 if (is_array($val)) {
                                     $val = array_values($val);
                                     $arrayValues[] = $val[0];
                                     $arrayLabels[] = $val[1];
                                 }
                             }
                             if (sizeof($arrayLabels)) {
                                 $varInfo = $variableModule->getVariableTypeByName($_SESSION['PROCESS'], $var);
                                 if (is_array($varInfo) && sizeof($varInfo)) {
                                     $varType = $varInfo['VAR_FIELD_TYPE'];
                                     switch ($varType) {
                                         case 'array':
                                             $arrayLabels = '["' . implode('","', $arrayLabels) . '"]';
                                             $newFields[$var] = $arrayValues;
                                             $newFields[$varLabel] = $arrayLabels;
                                             break;
                                         case 'string':
                                             $newFields[$var] = $arrayValues[0];
                                             $newFields[$varLabel] = $arrayLabels[0];
                                             break;
                                     }
                                     $this->affected_fields[] = $varLabel;
                                     $this->aFields = array_merge($this->aFields, $newFields);
                                     unset($newFields);
                                     unset($arrayValues);
                                     unset($arrayLabels);
                                 }
                             }
                         }
                     }
                     if (isset($this->aFields[$var]) && is_string($this->aFields[$var])) {
                         $varInfo = $variableModule->getVariableTypeByName($_SESSION['PROCESS'], $var);
                         $options = G::json_decode($varInfo["VAR_ACCEPTED_VALUES"]);
                         $no = count($options);
                         for ($io = 0; $io < $no; $io++) {
                             if ($options[$io]->value === $this->aFields[$var]) {
                                 $this->aFields[$var . "_label"] = $options[$io]->label;
                             }
                         }
                         if ($varInfo["VAR_DBCONNECTION"] !== "" && $varInfo["VAR_DBCONNECTION"] !== "none" && $varInfo["VAR_SQL"] !== "") {
                             try {
                                 $cnn = Propel::getConnection($varInfo["VAR_DBCONNECTION"]);
                                 $stmt = $cnn->createStatement();
                                 $sql = G::replaceDataField($varInfo["VAR_SQL"], $this->aFields);
                                 $rs = $stmt->executeQuery($sql, \ResultSet::FETCHMODE_NUM);
                                 while ($rs->next()) {
                                     $row = $rs->getRow();
                                     if ($row[0] === $this->aFields[$var]) {
                                         $this->aFields[$var . "_label"] = isset($row[1]) ? $row[1] : $row[0];
                                     }
                                 }
                             } catch (Exception $e) {
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Example #2
0
 /**
  *
  *
  * 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);
     }
 }
Example #3
0
 /**
  * @url POST /:prj_uid/process-variable/:var_name/execute-query-suggest
  *
  * @param string $prj_uid      {@min 32}{@max 32}
  * @param string $var_name
  * @param array  $request_data
  */
 public function doPostVariableExecuteSqlSuggest($prj_uid, $var_name, $request_data)
 {
     try {
         $variable = new \ProcessMaker\BusinessModel\Variable();
         $arrayData = $request_data != null ? $variable->executeSqlSuggest($prj_uid, $var_name, $request_data) : $variable->executeSqlSuggest($prj_uid, $var_name);
         $response = $arrayData;
         return $response;
     } catch (\Exception $e) {
         throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
     }
 }