Merge remote-tracking branch 'origin/feature/HOR-3274' into feature/HOR-3559

This commit is contained in:
davidcallizaya
2017-08-10 21:38:58 -04:00
44 changed files with 60980 additions and 710 deletions

View File

@@ -0,0 +1,43 @@
<?php
namespace ProcessMaker\BusinessModel;
use Translation;
/**
* Translation class
*
*/
class Language
{
/**
* Web Entry 2.0 Rest - Get languages
*
* @category HOR-3209,PROD-181
* @return array
*/
public function getLanguageList()
{
$Translations = new Translation();
$translationsTable = $Translations->getTranslationEnvironments();
$availableLangArray = [];
foreach ($translationsTable as $locale) {
$row = [];
$row['LANG_ID'] = $locale['LOCALE'];
if ($locale['COUNTRY'] != '.') {
$row['LANG_NAME'] = $locale['LANGUAGE'].' ('.
(ucwords(strtolower($locale['COUNTRY']))).')';
} else {
$row['LANG_NAME'] = $locale['LANGUAGE'];
}
$availableLangArray [] = $row;
}
return $availableLangArray;
}
}

View File

@@ -0,0 +1,181 @@
<?php
namespace ProcessMaker\BusinessModel;
use System;
use Exception;
use G;
/**
* Skins business model
*/
class Skins
{
/**
* Get a list of skins.
*
* @category HOR-3208,PROD-181
* @return array
*/
public function getSkins()
{
$list = System::getSkingList();
return $list['skins'];
}
/**
* Create a new skin.
*
* @param string $skinName
* @param string $skinFolder
* @param string $skinDescription
* @param string $skinAuthor
* @param string $skinWorkspace
* @param string $skinBase
* @return array
* @throws Exception
*/
public function createSkin(
$skinName,
$skinFolder,
$skinDescription = '',
$skinAuthor = 'ProcessMaker Team',
$skinWorkspace = 'global',
$skinBase = 'neoclassic'
) {
try {
if (!(isset($skinName))) {
throw (new Exception(G::LoadTranslation('ID_SKIN_NAME_REQUIRED')));
}
if (!(isset($skinFolder))) {
throw (new Exception(G::LoadTranslation('ID_SKIN_FOLDER_REQUIRED')));
}
if (is_dir(PATH_CUSTOM_SKINS.$skinFolder)) {
throw (new Exception(G::LoadTranslation('ID_SKIN_ALREADY_EXISTS')));
}
if (strtolower($skinFolder) == 'classic') {
throw (new Exception(G::LoadTranslation('ID_SKIN_ALREADY_EXISTS')));
}
//All validations OK then create skin
switch ($skinBase) {
//Validate skin base
case 'uxmodern':
$this->copySkinFolder(G::ExpandPath("skinEngine").'uxmodern'.PATH_SEP,
PATH_CUSTOM_SKINS.$skinFolder,
array("config.xml"
));
$pathBase = G::ExpandPath("skinEngine").'base'.PATH_SEP;
break;
case 'classic':
//Special Copy of this dir + xmlreplace
$this->copySkinFolder(G::ExpandPath("skinEngine").'base'.PATH_SEP,
PATH_CUSTOM_SKINS.$skinFolder,
array("config.xml", "baseCss"
));
$pathBase = G::ExpandPath("skinEngine").'base'.PATH_SEP;
break;
case 'neoclassic':
//Special Copy of this dir + xmlreplace
$this->copySkinFolder(G::ExpandPath("skinEngine").'neoclassic'.PATH_SEP,
PATH_CUSTOM_SKINS.$skinFolder,
array("config.xml", "baseCss"
));
$pathBase = G::ExpandPath("skinEngine").'neoclassic'.PATH_SEP;
break;
default:
//Commmon copy/paste of a folder + xmlrepalce
$this->copySkinFolder(PATH_CUSTOM_SKINS.$skinBase,
PATH_CUSTOM_SKINS.$skinFolder,
array("config.xml"
));
$pathBase = PATH_CUSTOM_SKINS.$skinBase.PATH_SEP;
break;
}
//@todo Improve this pre_replace lines
$configFileOriginal = $pathBase."config.xml";
$configFileFinal = PATH_CUSTOM_SKINS.$skinFolder.PATH_SEP.'config.xml';
$xmlConfiguration = file_get_contents($configFileOriginal);
$workspace = ($skinWorkspace == 'global') ? '' : SYS_SYS;
$xmlConfigurationObj = G::xmlParser($xmlConfiguration);
$skinInformationArray = $xmlConfigurationObj->result["skinConfiguration"]["__CONTENT__"]["information"]["__CONTENT__"];
$xmlConfiguration = preg_replace('/(<id>)(.+?)(<\/id>)/i',
'<id>'.G::generateUniqueID().'</id><!-- $2 -->',
$xmlConfiguration);
if (isset($skinInformationArray["workspace"]["__VALUE__"])) {
$workspace = ($workspace != "" && !empty($skinInformationArray["workspace"]["__VALUE__"]))
? $skinInformationArray["workspace"]["__VALUE__"]."|".$workspace
: $workspace;
$xmlConfiguration = preg_replace("/(<workspace>)(.*)(<\/workspace>)/i",
"<workspace>".$workspace."</workspace><!-- $2 -->",
$xmlConfiguration);
$xmlConfiguration = preg_replace("/(<name>)(.*)(<\/name>)/i",
"<name>".$skinName."</name><!-- $2 -->",
$xmlConfiguration);
} else {
$xmlConfiguration = preg_replace("/(<name>)(.*)(<\/name>)/i",
"<name>".$skinName."</name><!-- $2 -->\n<workspace>".$workspace."</workspace>",
$xmlConfiguration);
}
$xmlConfiguration = preg_replace("/(<description>)(.+?)(<\/description>)/i",
"<description>".$skinDescription."</description><!-- $2 -->",
$xmlConfiguration);
$xmlConfiguration = preg_replace("/(<author>)(.+?)(<\/author>)/i",
"<author>".$skinAuthor."</author><!-- $2 -->",
$xmlConfiguration);
$xmlConfiguration = preg_replace("/(<createDate>)(.+?)(<\/createDate>)/i",
"<createDate>".date("Y-m-d H:i:s")."</createDate><!-- $2 -->",
$xmlConfiguration);
$xmlConfiguration = preg_replace("/(<modifiedDate>)(.+?)(<\/modifiedDate>)/i",
"<modifiedDate>".date("Y-m-d H:i:s")."</modifiedDate><!-- $2 -->",
$xmlConfiguration);
file_put_contents($configFileFinal, $xmlConfiguration);
$response['success'] = true;
$response['message'] = G::LoadTranslation('ID_SKIN_SUCCESS_CREATE');
G::auditLog("CreateSkin", "Skin Name: ".$skinName);
return $response;
} catch (Exception $e) {
$response['success'] = false;
$response['message'] = $e->getMessage();
$response['error'] = $e->getMessage();
return $response;
}
}
private function copySkinFolder($path, $dest, $exclude = array())
{
$defaultExcluded = array(".", "..");
$excludedItems = array_merge($defaultExcluded, $exclude);
if (is_dir($path)) {
mkdir($dest);
$objects = scandir($path);
if (sizeof($objects) > 0) {
foreach ($objects as $file) {
if (in_array($file, $excludedItems)) {
continue;
}
if (is_dir($path.PATH_SEP.$file)) {
$this->copySkinFolder($path.PATH_SEP.$file,
$dest.PATH_SEP.$file, $exclude);
} else {
copy($path.PATH_SEP.$file, $dest.PATH_SEP.$file);
}
}
}
return true;
} elseif (is_file($path)) {
return copy($path, $dest);
} else {
return false;
}
}
}

View File

@@ -7,8 +7,8 @@ class WebEntry
"WE_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "webEntryUid"),
"TAS_UID" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "taskUid"),
"DYN_UID" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "dynaFormUid"),
"USR_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "userUid"),
"DYN_UID" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "dynaFormUid"),
"USR_UID" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "userUid"),
"WE_TITLE" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "webEntryTitle"),
"WE_DESCRIPTION" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "webEntryDescription"),
"WE_METHOD" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array("WS", "HTML"), "fieldNameAux" => "webEntryMethod"),
@@ -16,7 +16,7 @@ class WebEntry
);
private $arrayUserFieldDefinition = array(
"USR_UID" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "userUid")
"USR_UID" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "userUid")
);
private $formatFieldNameInUppercase = true;
@@ -269,13 +269,13 @@ class WebEntry
$task->throwExceptionIfNotExistsTask($processUid, $arrayData["TAS_UID"], $this->arrayFieldNameForException["taskUid"]);
}
if (isset($arrayData["DYN_UID"])) {
if (!empty($arrayData["DYN_UID"])) {
$dynaForm = new \ProcessMaker\BusinessModel\DynaForm();
$dynaForm->throwExceptionIfNotExistsDynaForm($arrayData["DYN_UID"], $processUid, $this->arrayFieldNameForException["dynaFormUid"]);
}
if ($arrayDataMain["WE_METHOD"] == "WS" && isset($arrayData["USR_UID"])) {
if ($arrayDataMain["WE_METHOD"] == "WS" && !empty($arrayData["USR_UID"])) {
$process->throwExceptionIfNotExistsUser($arrayData["USR_UID"], $this->arrayFieldNameForException["userUid"]);
}
@@ -293,7 +293,7 @@ class WebEntry
}
}
if ($arrayDataMain["WE_METHOD"] == "WS" && isset($arrayData["TAS_UID"])) {
if ($arrayDataMain["WE_METHOD"] == "WS" && isset($arrayData["TAS_UID"]) && (!isset($arrayData["WE_AUTHENTICATION"]) || $arrayData["WE_AUTHENTICATION"]!='LOGIN_REQUIRED')) {
$task = new \Tasks();
if ($task->assignUsertoTask($arrayData["TAS_UID"]) == 0) {
@@ -301,7 +301,7 @@ class WebEntry
}
}
if (isset($arrayData["DYN_UID"])) {
if (isset($arrayData["DYN_UID"]) && (!isset($arrayData["WE_TYPE"]) || $arrayData["WE_TYPE"]==='SINGLE')) {
$dynaForm = new \Dynaform();
$arrayDynaFormData = $dynaForm->Load($arrayData["DYN_UID"]);
@@ -313,7 +313,7 @@ class WebEntry
}
}
if ($arrayDataMain["WE_METHOD"] == "WS" && isset($arrayData["USR_UID"])) {
if ($arrayDataMain["WE_METHOD"] == "WS" && !empty($arrayData["USR_UID"])) {
$user = new \Users();
$arrayUserData = $user->load($arrayData["USR_UID"]);
@@ -321,9 +321,6 @@ class WebEntry
//Verify if User is assigned to Task
$projectUser = new \ProcessMaker\BusinessModel\ProjectUser();
if (!$projectUser->userIsAssignedToTask($arrayData["USR_UID"], $arrayDataMain["TAS_UID"])) {
throw new \Exception(\G::LoadTranslation("ID_USER_DOES_NOT_HAVE_ACTIVITY_ASSIGNED", array($arrayUserData["USR_USERNAME"], $arrayTaskData["TAS_TITLE"])));
}
}
} catch (\Exception $e) {
throw $e;
@@ -337,7 +334,7 @@ class WebEntry
*
* return void
*/
public function setWeData($webEntryUid)
protected function setWeData($webEntryUid, $arrayData)
{
try {
//Verify data
@@ -386,7 +383,9 @@ class WebEntry
$dynaForm = new \Dynaform();
$arrayDynaFormData = $dynaForm->Load($arrayWebEntryData["DYN_UID"]);
if (!empty($arrayWebEntryData["DYN_UID"])) {
$arrayDynaFormData = $dynaForm->Load($arrayWebEntryData["DYN_UID"]);
}
//Creating sys.info;
$sitePublicPath = "";
@@ -400,6 +399,12 @@ class WebEntry
$fileContent = "<?php\n\n";
$fileContent .= "global \$_DBArray;\n";
$fileContent .= '$webEntry = new ' . WebEntry::class . ";\n";
$fileContent .= "\$processUid = \"" . $processUid . "\";\n";
$fileContent .= "\$weUid = \"" . $arrayWebEntryData['WE_UID'] . "\";\n";
$fileContent .= 'if (!$webEntry->isWebEntryOne($weUid)) {'."\n";
$fileContent .= " return require(PATH_METHODS . 'webentry/access.php');\n";
$fileContent .= "}\n";
$fileContent .= "if (!isset(\$_DBArray)) {\n";
$fileContent .= " \$_DBArray = array();\n";
$fileContent .= "}\n";
@@ -407,7 +412,8 @@ class WebEntry
$fileContent .= "\$_SESSION[\"CURRENT_DYN_UID\"] = \"" . $dynaFormUid . "\";\n";
$fileContent .= "\$G_PUBLISH = new Publisher();\n";
$fileContent .= "\$a = new pmDynaform(array(\"CURRENT_DYNAFORM\" => \"" . $arrayWebEntryData["DYN_UID"] . "\"));\n";
$fileContent .= "G::LoadClass(\"pmDynaform\");\n";
$fileContent .= "\$a = new pmDynaform(array(\"CURRENT_DYNAFORM\" => \"" . $dynaFormUid . "\"));\n";
$fileContent .= "if (\$a->isResponsive()) {\n";
$fileContent .= " \$a->printWebEntry(\"" . $fileName . "Post.php\");\n";
$fileContent .= "} else {\n";
@@ -444,7 +450,7 @@ class WebEntry
$template->assign("USR_VAR", "\$USR_UID = -1;");
}
$template->assign("dynaform", $arrayDynaFormData["DYN_TITLE"]);
$template->assign("dynaform", empty($arrayDynaFormData) ? '' : $arrayDynaFormData["DYN_TITLE"]);
$template->assign("timestamp", date("l jS \of F Y h:i:s A"));
$template->assign("ws", $this->sysSys);
$template->assign("version", \PmSystem::getVersion());
@@ -551,15 +557,17 @@ class WebEntry
}
//Update
//Update where
$criteriaWhere = new \Criteria("workflow");
$criteriaWhere->add(\WebEntryPeer::WE_UID, $webEntryUid);
if (!isset($arrayData['WE_LINK_GENERATION']) || $arrayData['WE_LINK_GENERATION']==='DEFAULT') {
//Update where
$criteriaWhere = new \Criteria("workflow");
$criteriaWhere->add(\WebEntryPeer::WE_UID, $webEntryUid);
//Update set
$criteriaSet = new \Criteria("workflow");
$criteriaSet->add(\WebEntryPeer::WE_DATA, $webEntryData);
//Update set
$criteriaSet = new \Criteria("workflow");
$criteriaSet->add(\WebEntryPeer::WE_DATA, $webEntryData);
\BasePeer::doUpdate($criteriaWhere, $criteriaSet, \Propel::getConnection("workflow"));
\BasePeer::doUpdate($criteriaWhere, $criteriaSet, \Propel::getConnection("workflow"));
}
} catch (\Exception $e) {
throw $e;
}
@@ -629,7 +637,7 @@ class WebEntry
}
//Set WE_DATA
$this->setWeData($webEntryUid);
$this->setWeData($webEntryUid, $arrayData);
//Return
return $this->getWebEntry($webEntryUid);
@@ -710,7 +718,7 @@ class WebEntry
}
//Set WE_DATA
$this->setWeData($webEntryUid);
$this->setWeData($webEntryUid, $arrayData);
//Return
if (!$this->formatFieldNameInUppercase) {
@@ -839,7 +847,7 @@ class WebEntry
public function getWebEntryDataFromRecord(array $record)
{
try {
if ($record["WE_METHOD"] == "WS") {
if ((!isset($record['WE_LINK_GENERATION']) || $record['WE_LINK_GENERATION']==='DEFAULT') && $record["WE_METHOD"] == "WS") {
$http = (\G::is_https())? "https://" : "http://";
$url = $http . $_SERVER["HTTP_HOST"] . "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/" . $record["PRO_UID"];
@@ -1061,5 +1069,55 @@ class WebEntry
file_put_contents($pathFileName, $code);
}
/**
* Verify if web entry is a single dynaform without login required.
*
* @param type $processUid
* @param type $weUid
* @return boolean
*/
public function isWebEntryOne($weUid)
{
$webEntry = \WebEntryPeer::retrieveByPK($weUid);
return $webEntry->getWeType()==='SINGLE' && $webEntry->getWeAuthentication()==='ANONYMOUS';
}
/**
* Verify if a Task is and Web Entry auxiliar task.
*
* @param type $tasUid
* @return boolean
*/
public function isTaskAWebEntry($tasUid)
{
return substr($tasUid, 0, 4) === 'wee-';
}
public function getCallbackUrlByTask($tasUid)
{
$criteria = new \Criteria;
$criteria->add(\WebEntryPeer::TAS_UID, $tasUid);
$webEntry = \WebEntryPeer::doSelectOne($criteria);
if ($webEntry->getWeCallback()==='CUSTOM' || $webEntry->getWeCallback()==='CUSTOM_CLEAR') {
return $webEntry->getWeCallbackUrl();
} else {
return '../services/webentry/completed?message=@%_DELEGATION_MESSAGE';
}
}
public function getDelegationMessage($data)
{
$appNumber = $data['APP_NUMBER'];
$appUid = $data['APPLICATION'];
$message = "\n".\G::LoadTranslation('ID_CASE_CREATED').
"\n".\G::LoadTranslation('ID_CASE_NUMBER').": $appNumber".
"\n".\G::LoadTranslation('ID_CASESLIST_APP_UID').": $appUid";
foreach($data['_DELEGATION_DATA'] as $task) {
$message.="\n".\G::LoadTranslation('ID_CASE_ROUTED_TO').": ".
$task['NEXT_TASK']['TAS_TITLE'].
"(".htmlentities($task['NEXT_TASK']['USER_ASSIGNED']['USR_USERNAME']).")";
}
return $message;
}
}

View File

@@ -11,6 +11,9 @@ use \Luracast\Restler\RestException;
*/
class WebEntryEvent extends Api
{
/**
* @var \ProcessMaker\BusinessModel\WebEntryEvent $webEntryEvent
*/
private $webEntryEvent;
/**
@@ -32,6 +35,8 @@ class WebEntryEvent extends Api
/**
* @url GET /:prj_uid/web-entry-events
* @access protected
* @class AccessControl {@permission PM_FACTORY}
*
* @param string $prj_uid {@min 32}{@max 32}
*/
@@ -48,6 +53,7 @@ class WebEntryEvent extends Api
/**
* @url GET /:prj_uid/web-entry-event/:wee_uid
* @class AccessControl {@permission PM_FACTORY}
*
* @param string $prj_uid {@min 32}{@max 32}
* @param string $wee_uid {@min 32}{@max 32}
@@ -65,6 +71,7 @@ class WebEntryEvent extends Api
/**
* @url GET /:prj_uid/web-entry-event/event/:evn_uid
* @class AccessControl {@permission PM_FACTORY}
*
* @param string $prj_uid {@min 32}{@max 32}
* @param string $evn_uid {@min 32}{@max 32}
@@ -82,6 +89,7 @@ class WebEntryEvent extends Api
/**
* @url POST /:prj_uid/web-entry-event
* @class AccessControl {@permission PM_FACTORY}
*
* @param string $prj_uid {@min 32}{@max 32}
* @param array $request_data
@@ -103,6 +111,7 @@ class WebEntryEvent extends Api
/**
* @url PUT /:prj_uid/web-entry-event/:wee_uid
* @class AccessControl {@permission PM_FACTORY}
*
* @param string $prj_uid {@min 32}{@max 32}
* @param string $wee_uid {@min 32}{@max 32}
@@ -112,6 +121,7 @@ class WebEntryEvent extends Api
{
try {
$arrayData = $this->webEntryEvent->update($wee_uid, $this->getUserId(), $request_data);
return $this->webEntryEvent->getWebEntryEvent($wee_uid);
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
@@ -119,6 +129,7 @@ class WebEntryEvent extends Api
/**
* @url DELETE /:prj_uid/web-entry-event/:wee_uid
* @class AccessControl {@permission PM_FACTORY}
*
* @param string $prj_uid {@min 32}{@max 32}
* @param string $wee_uid {@min 32}{@max 32}
@@ -127,6 +138,24 @@ class WebEntryEvent extends Api
{
try {
$this->webEntryEvent->delete($wee_uid);
return ['success' => true];
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* Get the web entry URL.
*
* @url GET /:prj_uid/web-entry-event/:wee_uid/generate-link
* @access protected
* @class AccessControl {@permission PM_FACTORY}
*/
public function generateLink($prj_uid, $wee_uid)
{
try {
$link = $this->webEntryEvent->generateLink($prj_uid, $wee_uid);
return ["link" => $link];
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}

View File

@@ -7,7 +7,6 @@ use \Luracast\Restler\RestException;
/**
* Pmtable Api Controller
*
* @protected
*/
class System extends Api
{
@@ -18,6 +17,7 @@ class System extends Api
* @copyright Colosa - Bolivia
*
* @url GET /db-engines
* @protected
*/
public function doGetDataBaseEngines()
{
@@ -39,6 +39,7 @@ class System extends Api
* @copyright Colosa - Bolivia
*
* @url GET /counters-lists
* @protected
*/
public function doGetCountersLists()
{
@@ -52,6 +53,25 @@ class System extends Api
}
}
/**
* Get a list of the installed languages.
*
* @category HOR-3209,PROD-181
* @return array
* @url GET /languages
* @public
*/
public function doGetLanguages()
{
try {
$language = new \ProcessMaker\BusinessModel\Language;
$list = $language->getLanguageList();
return ["data" => $list];
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
* @return array
*
@@ -59,6 +79,7 @@ class System extends Api
* @copyright Colosa - Bolivia
*
* @url GET /enabled-features
* @protected
*/
public function doGetEnabledFeatures()
{
@@ -81,4 +102,25 @@ class System extends Api
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
* Get the list of installed skins.
*
* @url GET /skins
* @return array
* @access protected
* @class AccessControl {@permission PM_FACTORY}
* @protected
*/
public function doGetSkins()
{
try {
$model = new \ProcessMaker\BusinessModel\Skins();
$response = $model->getSkins();
return ["data" => $response];
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
}