/** * Copy/Import a DynaForm * * @param string $processUid Unique id of Process * @param array $arrayData Data * * return array Return data of the new DynaForm created */ public function copyImport($processUid, $arrayData) { try { $arrayData = \G::array_change_key_case2($arrayData, CASE_UPPER); unset($arrayData["DYN_UID"]); unset($arrayData["PMTABLE"]); //Verify data $process = new \ProcessMaker\BusinessModel\Process(); $process->throwExceptionIfNotExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]); $process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, true); if (!isset($arrayData["COPY_IMPORT"])) { throw new \Exception(\G::LoadTranslation("ID_UNDEFINED_VALUE_IS_REQUIRED", array($this->getFieldNameByFormatFieldName("COPY_IMPORT")))); } if (!isset($arrayData["COPY_IMPORT"]["PRJ_UID"])) { throw new \Exception(\G::LoadTranslation("ID_UNDEFINED_VALUE_IS_REQUIRED", array($this->getFieldNameByFormatFieldName("COPY_IMPORT.PRJ_UID")))); } $arrayData["COPY_IMPORT"]["PRJ_UID"] = trim($arrayData["COPY_IMPORT"]["PRJ_UID"]); if ($arrayData["COPY_IMPORT"]["PRJ_UID"] == "") { throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_CAN_NOT_BE_EMPTY", array($this->getFieldNameByFormatFieldName("COPY_IMPORT.PRJ_UID")))); } if (!isset($arrayData["COPY_IMPORT"]["DYN_UID"])) { throw new \Exception(\G::LoadTranslation("ID_UNDEFINED_VALUE_IS_REQUIRED", array($this->getFieldNameByFormatFieldName("COPY_IMPORT.DYN_UID")))); } $arrayData["COPY_IMPORT"]["DYN_UID"] = trim($arrayData["COPY_IMPORT"]["DYN_UID"]); if ($arrayData["COPY_IMPORT"]["DYN_UID"] == "") { throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_CAN_NOT_BE_EMPTY", array($this->getFieldNameByFormatFieldName("COPY_IMPORT.DYN_UID")))); } $this->throwExceptionIfExistsTitle($processUid, $arrayData["DYN_TITLE"], $this->arrayFieldNameForException["dynaFormTitle"]); //Copy/Import Uids $processUidCopyImport = $arrayData["COPY_IMPORT"]["PRJ_UID"]; $dynaFormUidCopyImport = $arrayData["COPY_IMPORT"]["DYN_UID"]; //Verify data $process->throwExceptionIfNotExistsProcess($processUidCopyImport, $this->getFieldNameByFormatFieldName("COPY_IMPORT.PRJ_UID")); $this->throwExceptionIfNotExistsDynaForm($dynaFormUidCopyImport, $processUidCopyImport, $this->getFieldNameByFormatFieldName("COPY_IMPORT.DYN_UID")); //Copy/Import //Copy content if version is 2 if ($arrayData["DYN_VERSION"] === 2) { $dynaFormOld = new \Dynaform(); $arrayDynaFormData = $dynaFormOld->Load($dynaFormUidCopyImport); $arrayData["DYN_CONTENT"] = $arrayDynaFormData["DYN_CONTENT"]; } //Create $arrayData = $this->create($processUid, $arrayData); $dynaFormUid = $arrayData[$this->getFieldNameByFormatFieldName("DYN_UID")]; //Copy files of the DynaForm $umaskOld = umask(0); $fileXml = PATH_DYNAFORM . $processUidCopyImport . PATH_SEP . $dynaFormUidCopyImport . ".xml"; if (file_exists($fileXml)) { $fileXmlCopy = PATH_DYNAFORM . $processUid . PATH_SEP . $dynaFormUid . ".xml"; $fhXml = fopen($fileXml, "r"); $fhXmlCopy = fopen($fileXmlCopy, "w"); while (!feof($fhXml)) { $strLine = fgets($fhXml, 4096); $strLine = str_replace($processUidCopyImport . "/" . $dynaFormUidCopyImport, $processUid . "/" . $dynaFormUid, $strLine); //DynaForm Grid preg_match_all("/<.*type\\s*=\\s*[\"\\']grid[\"\\'].*xmlgrid\\s*=\\s*[\"\\']\\w{32}\\/(\\w{32})[\"\\'].*\\/>/", $strLine, $arrayMatch, PREG_SET_ORDER); foreach ($arrayMatch as $value) { $dynaFormGridUidCopyImport = $value[1]; //Get data $criteria = new \Criteria(); $criteria->addSelectColumn(\ContentPeer::CON_VALUE); $criteria->add(\ContentPeer::CON_ID, $dynaFormGridUidCopyImport); $criteria->add(\ContentPeer::CON_CATEGORY, "DYN_TITLE"); $criteria->add(\ContentPeer::CON_LANG, SYS_LANG); $rsCriteria = \ContentPeer::doSelectRS($criteria); $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); $rsCriteria->next(); $row = $rsCriteria->getRow(); $dynGrdTitleCopyImport = $row["CON_VALUE"]; $criteria = new \Criteria(); $criteria->addSelectColumn(\ContentPeer::CON_VALUE); $criteria->add(\ContentPeer::CON_ID, $dynaFormGridUidCopyImport); $criteria->add(\ContentPeer::CON_CATEGORY, "DYN_DESCRIPTION"); $criteria->add(\ContentPeer::CON_LANG, SYS_LANG); $rsCriteria = \ContentPeer::doSelectRS($criteria); $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); $rsCriteria->next(); $row = $rsCriteria->getRow(); $dynGrdDescriptionCopyImport = $row["CON_VALUE"]; //Create Grid $dynaFormGrid = new \Dynaform(); $arrayDataAux = array("PRO_UID" => $processUid, "DYN_TITLE" => $dynGrdTitleCopyImport . ($this->existsTitle($processUid, $dynGrdTitleCopyImport) ? " (" . $arrayData["DYN_TITLE"] . ")" : ""), "DYN_DESCRIPTION" => $dynGrdDescriptionCopyImport, "DYN_TYPE" => "grid"); $dynaFormGridUid = $dynaFormGrid->create($arrayDataAux); //Copy files of the DynaForm Grid $fileGridXml = PATH_DYNAFORM . $processUidCopyImport . PATH_SEP . $dynaFormGridUidCopyImport . ".xml"; if (file_exists($fileGridXml)) { $fileGridXmlCopy = PATH_DYNAFORM . $processUid . PATH_SEP . $dynaFormGridUid . ".xml"; $fhGridXml = fopen($fileGridXml, "r"); $fhGridXmlCopy = fopen($fileGridXmlCopy, "w"); while (!feof($fhGridXml)) { $strLineAux = fgets($fhGridXml, 4096); $strLineAux = str_replace($processUidCopyImport . "/" . $dynaFormGridUidCopyImport, $processUid . "/" . $dynaFormGridUid, $strLineAux); fwrite($fhGridXmlCopy, $strLineAux); } fclose($fhGridXmlCopy); fclose($fhGridXml); chmod($fileGridXmlCopy, 0777); } $fileGridHtml = PATH_DYNAFORM . $processUidCopyImport . PATH_SEP . $dynaFormGridUidCopyImport . ".html"; if (file_exists($fileGridHtml)) { $fileGridHtmlCopy = PATH_DYNAFORM . $processUid . PATH_SEP . $dynaFormGridUid . ".html"; copy($fileGridHtml, $fileGridHtmlCopy); chmod($fileGridHtmlCopy, 0777); } $strLine = str_replace($processUidCopyImport . "/" . $dynaFormGridUidCopyImport, $processUid . "/" . $dynaFormGridUid, $strLine); } fwrite($fhXmlCopy, $strLine); } fclose($fhXmlCopy); fclose($fhXml); chmod($fileXmlCopy, 0777); } $fileHtml = PATH_DYNAFORM . $processUidCopyImport . PATH_SEP . $dynaFormUidCopyImport . ".html"; if (file_exists($fileHtml)) { $fileHtmlCopy = PATH_DYNAFORM . $processUid . PATH_SEP . $dynaFormUid . ".html"; copy($fileHtml, $fileHtmlCopy); chmod($fileHtmlCopy, 0777); } //Copy if there are conditions attached to the DynaForm $fieldCondition = new \FieldCondition(); $arrayCondition = $fieldCondition->getAllByDynUid($dynaFormUidCopyImport); foreach ($arrayCondition as $condition) { $condition["FCD_UID"] = ""; $condition["FCD_DYN_UID"] = $dynaFormUid; $fieldCondition->quickSave($condition); } umask($umaskOld); //Return return $arrayData; } catch (\Exception $e) { throw $e; } }
* the html template if its required too. */ require_once 'classes/model/Dynaform.php'; if (!class_exists("FieldCondition")) { require_once "classes/model/FieldCondition.php"; } try { G::LoadSystem('inputfilter'); $filter = new InputFilter(); $frm = $_POST['form']; $PRO_UID = $frm['PRO_UID']; $DYN_UID = $frm['DYN_UID']; $DYN_TYPE = $frm['DYN_TYPE']; // checks if there are conditions attached to the dynaform $oFieldCondition = new FieldCondition(); $aConditions = $oFieldCondition->getAllByDynUid($DYN_UID); $dynaform = new dynaform(); $arrayData = array(); $arrayData["PRO_UID"] = $PRO_UID; $arrayData["DYN_TYPE"] = $DYN_TYPE; $arrayData["DYN_TITLE"] = $frm["DYN_TITLENEW"]; if (isset($frm["DYN_DESCRIPTIONNEW"])) { $arrayData["DYN_DESCRIPTION"] = $frm["DYN_DESCRIPTIONNEW"]; } $aFields = $dynaform->create($arrayData); $dynUid = $dynaform->getDynUid(); $hd = fopen(PATH_DYNAFORM . $PRO_UID . '/' . $DYN_UID . '.xml', "r"); $hd1 = fopen(PATH_DYNAFORM . $PRO_UID . '/' . $dynUid . '.xml', "w"); $templateFilename = PATH_DYNAFORM . $PRO_UID . '/' . $DYN_UID . '.html'; $templateFilename = $filter->xssFilterHard($templateFilename, 'path'); // also make a copy of the template file in case that the html edition is enabled
} fwrite($fhXmlCopy, $strLine); } fclose($fhXmlCopy); fclose($fhXml); chmod($fileXmlCopy, 0777); } $fileHtml = PATH_DYNAFORM . $aData["COPY_PROCESS_UID"] . PATH_SEP . $aData["COPY_DYNAFORM_UID"] . ".html"; if (file_exists($fileHtml)) { $fileHtmlCopy = PATH_DYNAFORM . $aData["PRO_UID"] . PATH_SEP . $dynaformUid . ".html"; copy($fileHtml, $fileHtmlCopy); chmod($fileHtmlCopy, 0777); } //Copy if there are conditions attached to the dynaform $fieldCondition = new FieldCondition(); $arrayCondition = $fieldCondition->getAllByDynUid($aData["COPY_DYNAFORM_UID"]); foreach ($arrayCondition as $condition) { $condition["FCD_UID"] = ""; $condition["FCD_DYN_UID"] = $dynaformUid; $fieldCondition->quickSave($condition); } umask($umaskOld); break; default: //normal //pmtable if (!isset($aData["ADD_TABLE"]) || $aData["ADD_TABLE"] == "") { $aFields = $dynaform->create($aData); } else { $aFields = $dynaform->createFromPMTable($aData, $aData["ADD_TABLE"]); }