existsRecord($weTaskUid, "DYNAFORM", $weDynaFormUid)) { $flagPush = 1; } break; case "UID": if ($taskUid != "" && $dynaFormUid != "" && $weTaskUid == $taskUid && $weDynaFormUid == $dynaFormUid && $step->existsRecord($weTaskUid, "DYNAFORM", $weDynaFormUid)) { $flagPush = 1; $flagNext = 0; } break; case "DYN_UID": if ($dynaFormUid != "" && $weDynaFormUid == $dynaFormUid && $step->existsRecord($weTaskUid, "DYNAFORM", $weDynaFormUid)) { $flagPush = 1; $flagNext = 0; } break; } if ($flagPush == 1) { $arrayTaskData = $task->load($weTaskUid); $arrayDynaFormData = $dynaForm->Load($weDynaFormUid); $arrayData[$weTaskUid . "/" . $weDynaFormUid] = array( "processUid" => $processUid, "taskUid" => $weTaskUid, "taskTitle" => $arrayTaskData["TAS_TITLE"], "dynaFormUid" => $weDynaFormUid, "dynaFormTitle" => $arrayDynaFormData["DYN_TITLE"], "fileName" => $weFileName, "url" => $url . "/" . $weFileName . ".php" ); } } } } } } return $arrayData; } catch (\Exception $e) { throw $e; } } /** * Create Web Entry for a Process * * @param string $processUid Unique id of Process * @param array $arrayData Data * * return array Return data of the new Web Entry created */ public function create($processUid, $arrayData) { try { $arrayData = array_change_key_case($arrayData, CASE_UPPER); //Verify data $process = new \Process(); if (!$process->exists($processUid)) { throw (new \Exception(str_replace(array("{0}", "{1}"), array($processUid, "PROCESS"), "The UID \"{0}\" doesn't exist in table {1}"))); } if (!isset($arrayData["TAS_UID"])) { throw (new \Exception(str_replace(array("{0}"), array(strtolower("TAS_UID")), "The \"{0}\" attribute is not defined"))); } if (!isset($arrayData["DYN_UID"])) { throw (new \Exception(str_replace(array("{0}"), array(strtolower("DYN_UID")), "The \"{0}\" attribute is not defined"))); } if (!isset($arrayData["METHOD"])) { throw (new \Exception(str_replace(array("{0}"), array(strtolower("METHOD")), "The \"{0}\" attribute is not defined"))); } if (!isset($arrayData["INPUT_DOCUMENT_ACCESS"])) { throw (new \Exception(str_replace(array("{0}"), array(strtolower("INPUT_DOCUMENT_ACCESS")), "The \"{0}\" attribute is not defined"))); } $projectUser = new \BusinessModel\ProjectUser(); if ($arrayData["METHOD"] == "WS") { if (!isset($arrayData["USR_USERNAME"])) { throw (new \Exception(str_replace(array("{0}"), array(strtolower("USR_USERNAME")), "The \"{0}\" attribute is not defined"))); } if (!isset($arrayData["USR_PASSWORD"])) { throw (new \Exception(str_replace(array("{0}"), array(strtolower("USR_PASSWORD")), "The \"{0}\" attribute is not defined"))); } $loginData = $projectUser->userLogin($arrayData["USR_USERNAME"], $arrayData["USR_PASSWORD"]); if ($loginData->status_code != 0) { throw (new \Exception($loginData->message)); } } $task = new \Task(); if (!$task->taskExists($arrayData["TAS_UID"])) { throw (new \Exception(str_replace(array("{0}", "{1}"), array($arrayData["TAS_UID"], "TASK"), "The UID \"{0}\" doesn't exist in table {1}"))); } $arrayTaskData = $task->load($arrayData["TAS_UID"]); if ($arrayTaskData["TAS_START"] == "FALSE") { throw (new \Exception(str_replace(array("{0}"), array($arrayTaskData["TAS_TITLE"]), "The task \"{0}\" isn't initial task"))); } if ($arrayTaskData["TAS_ASSIGN_TYPE"] != "BALANCED") { throw (new \Exception(str_replace(array("{0}"), array($arrayTaskData["TAS_TITLE"]), "Web Entry only works with tasks which have \"Cyclical Assignment\", the task \"{0}\" doesn't have a valid assignment type. Please change the Assignment Rules"))); } $task = new \Tasks(); if ($task->assignUsertoTask($arrayData["TAS_UID"]) == 0) { throw (new \Exception(str_replace(array("{0}"), array($arrayTaskData["TAS_TITLE"]), "The task \"{0}\" doesn't have users"))); } $dynaForm = new \Dynaform(); if (!$dynaForm->dynaformExists($arrayData["DYN_UID"])) { throw (new \Exception(str_replace(array("{0}", "{1}"), array($arrayData["DYN_UID"], "DYNAFORM"), "The UID \"{0}\" doesn't exist in table {1}"))); } $arrayDynaFormData = $dynaForm->Load($arrayData["DYN_UID"]); $step = new \BusinessModel\Step(); if (!$step->existsRecord($arrayData["TAS_UID"], "DYNAFORM", $arrayData["DYN_UID"])) { throw (new \Exception(str_replace(array("{0}", "{1}"), array($arrayDynaFormData["DYN_TITLE"], $arrayTaskData["TAS_TITLE"]), "The DynaForm \"{0}\" isn't assigned to the task \"{1}\""))); } if ($arrayData["METHOD"] == "WS") { //Verify if the Web Entry exist $arrayWebEntryData = $this->getData($processUid, "UID", $arrayData["TAS_UID"], $arrayData["DYN_UID"]); if (count($arrayWebEntryData) > 0) { throw (new \Exception("The Web Entry exist")); } //Verify if User is assigned to Task $criteria = new \Criteria("workflow"); $criteria->addSelectColumn(\UsersPeer::USR_UID); $criteria->add(\UsersPeer::USR_USERNAME, $arrayData["USR_USERNAME"], \Criteria::EQUAL); $rsCriteria = \UsersPeer::doSelectRS($criteria); $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); $rsCriteria->next(); $row = $rsCriteria->getRow(); if (!$projectUser->userIsAssignedToTask($row["USR_UID"], $arrayData["TAS_UID"])) { throw (new \Exception(str_replace(array("{0}", "{1}"), array($arrayData["USR_USERNAME"], $arrayTaskData["TAS_TITLE"]), "The user \"{0}\" doesn't have the task \"{1}\" assigned"))); } } //Create $taskUid = $arrayData["TAS_UID"]; $dynaFormUid = $arrayData["DYN_UID"]; $method = $arrayData["METHOD"]; $inputDocumentAccess = $arrayData["INPUT_DOCUMENT_ACCESS"]; $wsRoundRobin = 0; //0, 1 //0 - Cyclical Assignment $pathProcess = PATH_DATA_SITE . "public" . PATH_SEP . $processUid; \G::mk_dir($pathProcess, 0777); $http = (\G::is_https())? "https://" : "http://"; $arrayDataAux = array(); switch ($method) { case "WS": $usrUsername = $arrayData["USR_USERNAME"]; $usrPassword = $arrayData["USR_PASSWORD"]; $task = new \Task(); $weEventUid = $task->getStartingEvent($taskUid); //Creating sys.info; $site_public_path = ""; if (file_exists($site_public_path . "")) { } //Creating the first file $dynTitle = $this->sanitizeFilename($arrayDynaFormData["DYN_TITLE"]); $fileName = $dynTitle; $fileContent = "AddContent('dynaform', 'xmlform', '" . $processUid . '/' . $dynaFormUid . "', '', array(), '" . $fileName . 'Post.php' . "');\n"; $fileContent .= "G::RenderPage('publish', 'blank');"; file_put_contents($pathProcess . PATH_SEP . $fileName . ".php", $fileContent); //Creating the second file, the post file who receive the post form. $pluginTpl = PATH_CORE . "templates" . PATH_SEP . "processes" . PATH_SEP . "webentryPost.tpl"; $template = new \TemplatePower($pluginTpl); $template->prepare(); $template->assign("wsdlUrl", $http . $_SERVER["HTTP_HOST"] . "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/services/wsdl2"); $template->assign("wsUploadUrl", $http . $_SERVER["HTTP_HOST"] . "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/services/upload"); $template->assign("processUid", $processUid); $template->assign("dynaformUid", $dynaFormUid); $template->assign("taskUid", $taskUid); $template->assign("wsUser", $usrUsername); $template->assign("wsPass", "md5:" . md5($usrPassword)); $template->assign("wsRoundRobin", $wsRoundRobin); if ($inputDocumentAccess == 0) { //Restricted to process permissions $template->assign("USR_VAR", "\$cInfo = ws_getCaseInfo(\$caseId);\n\t \$USR_UID = \$cInfo->currentUsers->userId;"); } else { //No Restriction $template->assign("USR_VAR", "\$USR_UID = -1;"); } $template->assign("dynaform", $dynTitle); $template->assign("timestamp", date("l jS \of F Y h:i:s A")); $template->assign("ws", SYS_SYS); $template->assign("version", \System::getVersion()); $fileName = $pathProcess . PATH_SEP . $dynTitle . "Post.php"; file_put_contents($fileName, $template->getOutputContent()); //Creating the third file, only if this wsClient.php file doesn't exist. $fileName = $pathProcess . PATH_SEP . "wsClient.php"; $pluginTpl = PATH_CORE . "test" . PATH_SEP . "unit" . PATH_SEP . "ws" . PATH_SEP . "wsClient.php"; if (file_exists($fileName)) { if (filesize($fileName) != filesize($pluginTpl)) { @copy($fileName, $pathProcess . PATH_SEP . "wsClient.php.bck"); @unlink($fileName); $template = new \TemplatePower($pluginTpl); $template->prepare(); file_put_contents($fileName, $template->getOutputContent()); } } else { $template = new \TemplatePower($pluginTpl); $template->prepare(); file_put_contents($fileName, $template->getOutputContent()); } //Event $event = new \Event(); $arrayEventData = array(); $arrayEventData["EVN_UID"] = $weEventUid; $arrayEventData["EVN_RELATED_TO"] = "MULTIPLE"; $arrayEventData["EVN_ACTION"] = $dynaFormUid; $arrayEventData["EVN_CONDITIONS"] = $usrUsername; $result = $event->update($arrayEventData); //Data $url = $http . $_SERVER["HTTP_HOST"] . "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/" . $processUid . "/" . $dynTitle . ".php"; $arrayDataAux = array("url" => $url); break; case "HTML": global $G_FORM; $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"; $scriptCode = ""; $scriptCode = $G_FORM->render(PATH_CORE . "templates/" . "xmlform" . ".html", $scriptCode); $scriptCode = str_replace("/controls/", $http . $_SERVER["HTTP_HOST"] . "/controls/", $scriptCode); $scriptCode = str_replace("/js/maborak/core/images/", $http . $_SERVER["HTTP_HOST"] . "/js/maborak/core/images/", $scriptCode); //Render the template $pluginTpl = PATH_CORE . "templates" . PATH_SEP . "processes" . PATH_SEP . "webentry.tpl"; $template = new \TemplatePower($pluginTpl); $template->prepare(); $step = new \Step(); $sUidGrids = $step->lookingforUidGrids($processUid, $dynaFormUid); $template->assign("URL_MABORAK_JS", \G::browserCacheFilesUrl("/js/maborak/core/maborak.js")); $template->assign("URL_TRANSLATION_ENV_JS", \G::browserCacheFilesUrl("/jscore/labels/" . SYS_LANG . ".js")); $template->assign("siteUrl", $http . $_SERVER["HTTP_HOST"]); $template->assign("sysSys", SYS_SYS); $template->assign("sysLang", SYS_LANG); $template->assign("sysSkin", SYS_SKIN); $template->assign("processUid", $processUid); $template->assign("dynaformUid", $dynaFormUid); $template->assign("taskUid", $taskUid); $template->assign("dynFileName", $processUid . "/" . $dynaFormUid); $template->assign("formId", $G_FORM->id); $template->assign("scriptCode", $scriptCode); if (sizeof($sUidGrids) > 0) { foreach ($sUidGrids as $k => $v) { $template->newBlock("grid_uids"); $template->assign("siteUrl", $http . $_SERVER["HTTP_HOST"]); $template->assign("gridFileName", $processUid . "/" . $v); } } //Data $html = str_replace("", "", str_replace("", "", $template->getOutputContent())); $arrayDataAux = array("html" => $html); break; } //Return $arrayData = array_change_key_case($arrayData, CASE_LOWER); return array_merge($arrayData, $arrayDataAux); } catch (\Exception $e) { throw $e; } } /** * Delete Web Entry * * @param string $processUid Unique id of Process * @param string $taskUid Unique id of Task * @param string $dynaFormUid Unique id of DynaForm * * return void */ public function delete($processUid, $taskUid, $dynaFormUid) { try { //Verify data $process = new \Process(); if (!$process->exists($processUid)) { throw (new \Exception(str_replace(array("{0}", "{1}"), array($processUid, "PROCESS"), "The UID \"{0}\" doesn't exist in table {1}"))); } $arrayWebEntryData = $this->getData($processUid, "UID", $taskUid, $dynaFormUid); if (count($arrayWebEntryData) == 0) { throw (new \Exception("The Web Entry doesn't exist")); } //Delete $webEntryPath = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "public" . PATH_SEP . $processUid; unlink($webEntryPath . PATH_SEP . $arrayWebEntryData[$taskUid . "/" . $dynaFormUid]["fileName"] . ".php"); unlink($webEntryPath . PATH_SEP . $arrayWebEntryData[$taskUid . "/" . $dynaFormUid]["fileName"] . "Post.php"); } catch (\Exception $e) { throw $e; } } /** * Get data of a Web Entry from a record * * @param array $record Record * * return array Return an array with data of a Web Entry */ public function getWebEntryDataFromRecord($record) { try { return array( "tas_uid" => $record["taskUid"], "tas_title" => $record["taskTitle"], "dyn_uid" => $record["dynaFormUid"], "dyn_title" => $record["dynaFormTitle"], "url" => $record["url"] ); } catch (\Exception $e) { throw $e; } } /** * Get data of a Web Entry * * @param string $processUid Unique id of Process * @param string $taskUid Unique id of Task * @param string $dynaFormUid Unique id of DynaForm * * return array Return an array with data of a Web Entry */ public function getWebEntry($processUid, $taskUid, $dynaFormUid) { try { //Verify data $process = new \Process(); if (!$process->exists($processUid)) { throw (new \Exception(str_replace(array("{0}", "{1}"), array($processUid, "PROCESS"), "The UID \"{0}\" doesn't exist in table {1}"))); } $arrayWebEntryData = $this->getData($processUid, "UID", $taskUid, $dynaFormUid); if (count($arrayWebEntryData) == 0) { throw (new \Exception("The Web Entry doesn't exist")); } //Get data //Return return $this->getWebEntryDataFromRecord($arrayWebEntryData[$taskUid . "/" . $dynaFormUid]); } catch (\Exception $e) { throw $e; } } }