/** * 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; } }
$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 if (file_exists($templateFilename)) { $templateHd = fopen($templateFilename, "r"); $templateHd1 = fopen(PATH_DYNAFORM . $PRO_UID . '/' . $dynUid . '.html', "w"); } // also copy all the necessarily conditions if there are any foreach ($aConditions as $condition) { $condition['FCD_UID'] = G::generateUniqueID(); $condition['FCD_DYN_UID'] = $dynUid; $oFieldCondition->quickSave($condition); } // checks if the physical dynaform file exists and copy the contents if ($hd) { while (!feof($hd)) { $line = fgets($hd, 4096); fwrite($hd1, str_replace($DYN_UID, $dynUid, $line)); } } fclose($hd); fclose($hd1); // check if the template file also exists if (isset($templateHd)) { while (!feof($templateHd)) { $line = fgets($templateHd, 4096); fwrite($templateHd1, str_replace($DYN_UID, $dynUid, $line));
$aFields['gFields'][$i++] = array('dynaid' => $aField, 'dynafield' => $aField, 'dynavalue' => ''); } if (sizeof($aFields) > 0) { $G_PUBLISH->AddContent('xmlform', 'xmlform', 'dynaforms/dynaforms_ConditionalShowHideTest', '', $aFields); G::RenderPage('publish', 'raw'); } else { print 'false'; } break; case 'save': require_once 'classes/model/FieldCondition.php'; $oFieldCondition = new FieldCondition(); $aDYN = $_SESSION['Current_Dynafom']['Parameters']; $_POST['FCD_UID'] = $_POST['FCD_UID'] == '0' ? '' : $_POST['FCD_UID']; $aData = array('FCD_UID' => isset($_POST['FCD_UID']) ? $_POST['FCD_UID'] : '', 'FCD_FUNCTION' => $_POST['function'], 'FCD_FIELDS' => $_POST['fields_selected'], 'FCD_CONDITION' => $_POST['condition'], 'FCD_EVENTS' => $_POST['events'], 'FCD_EVENT_OWNERS' => $_POST['event_owner_selected'], 'FCD_STATUS' => $_POST['enabled'], 'FCD_DYN_UID' => $aDYN['DYN_UID']); $oFieldCondition->quickSave($aData); break; case 'delete': require_once 'classes/model/FieldCondition.php'; $oFieldCondition = FieldConditionPeer::retrieveByPk($_POST['FCD_UID']); if (is_object($oFieldCondition)) { $oFieldCondition->delete(); } break; } } catch (Exception $e) { print $e->getMessage(); } /* * <pre>Array (