Merged 3.0.1.8 into MT-10

This commit is contained in:
Gustavo Cruz
2016-03-24 11:44:29 -04:00
18 changed files with 721 additions and 342 deletions

View File

@@ -0,0 +1,181 @@
<?php
namespace ProcessMaker\BusinessModel\Cases;
use Propel;
use StdClass;
use G;
use Cases;
use AppDocument;
use Dynaform;
use Exception;
use Task;
/**
* Return the ChangeLog of a Dynaform
*/
class ChangeLog
{
/**
* List of variables that should not be considered
* @var string[]
*/
private $reserved = [
'TASK',
'INDEX',
'DYN_CONTENT_HISTORY'
];
/**
* Map of variables and its values
* @var mixed[]
*/
private $values = [];
/**
* List of variables changes
* @var object[]
*/
private $tree;
/**
* List of assigned permissions
* @var string[]
*/
private $permissions = [];
public function getChangeLog($appUid, $proUid, $tasUid, $start, $limit)
{
$this->loadPermissions($appUid, $proUid, $tasUid);
$result = $this->getResultSet($appUid);
$totalCount = $this->readRecords($result, $start, $limit);
return ['data' => $this->tree, 'totalCount' => $totalCount];
}
private function getResultSet($appUid)
{
$conn = Propel::getConnection('workflow');
$sql = 'SELECT APP_HISTORY.*, USERS.USR_USERNAME FROM APP_HISTORY'
.' LEFT JOIN USERS ON(APP_HISTORY.USR_UID=USERS.USR_UID)'
.' WHERE APP_UID=? ORDER BY HISTORY_DATE ASC';
$stmt = $conn->prepareStatement($sql);
$stmt->set(1, $appUid);
if (!$stmt->executeQuery()) {
throw Exception(G::LoadTranslation('ID_MSG_AJAX_FAILURE'));
}
return $stmt->getResultSet();
}
private function readRecords($result, $start = 0, $limit = 15)
{
$index = 0;
while ($result->next()) {
$row = $result->getRow();
$data = unserialize($row['HISTORY_DATA']);
if ($this->isEmpty($data)) {
continue;
}
if ($index < $start) {
$index += $this->updateData(
$data, $row, $this->hasPermission($row['DYN_UID']), false);
continue;
}
$a = $this->updateData($data, $row,
$this->hasPermission($row['DYN_UID']), true);
$limit-= $a;
$index+= $a;
}
return $index;
}
private function isEmpty($data)
{
foreach ($data as $key => $value) {
if (array_search($key, $this->reserved) !== false) {
continue;
}
return false;
}
return true;
}
private function updateData($data, $row, $hasPermission, $addToTree = false)
{
$i = 0;
foreach ($data as $key => $value) {
if (array_search($key, $this->reserved) !== false) {
continue;
}
if ($hasPermission && (!isset($this->values[$key]) || $this->values[$key]
!== $value)) {
if ($addToTree) {
$node = new StdClass();
$node->field = $key;
$previousValue = !isset($this->values[$key]) ? null : $this->values[$key];
$node->previousValue = (string) $previousValue;
$node->currentValue = (string) $value;
$node->previousValueType = gettype($previousValue);
$node->currentValueType = gettype($value);
$node->record = $this->getHistoryTitle($row);
$this->tree[] = $node;
}
$i++;
}
$this->values[$key] = $value;
}
return $i;
}
private function getHistoryTitle($row)
{
return $this->getObjectTitle($row['TAS_UID'], 'TASK')
.' / '.$this->getObjectTitle($row['DYN_UID'], $row['OBJ_TYPE'])
.' / '.G::LoadTranslation('ID_LAN_UPDATE_DATE').': '.$row['HISTORY_DATE']
.' / '.G::LoadTranslation('ID_USER').': '.$row['USR_USERNAME'];
}
private function getObjectTitle($uid, $objType)
{
switch ($objType) {
case 'DYNAFORM':
$obj = new Dynaform();
$obj->Load($uid);
$title = $obj->getDynTitle();
break;
case 'OUTPUT_DOCUMENT':
case 'INPUT_DOCUMENT':
$obj = new AppDocument();
$obj->load($uid);
$title = $obj->getDynTitle();
break;
case 'TASK':
$obj = new Task();
$obj->load($uid);
$title = $obj->getTasTitle();
break;
default:
$title = $uid;
}
return $title;
}
private function loadPermissions($APP_UID, $PRO_UID, $TAS_UID)
{
G::LoadClass('case');
$oCase = new Cases();
$oCase->verifyTable();
$this->permissions = $oCase->getAllObjects(
$PRO_UID, $APP_UID, $TAS_UID, $_SESSION['USER_LOGGED']
);
}
private function hasPermission($uid)
{
foreach ($this->permissions as $type => $ids) {
if (array_search($uid, $ids) !== false) {
return true;
}
}
return false;
}
}

View File

@@ -80,16 +80,25 @@ class Pmgmail {
* return uid
*
*/
public function sendEmail($app_uid, $mail, $index)
public function sendEmail($app_uid, $mailToAddresses, $index, $arrayTask = null, $arrayData = null)
{
require_once (PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "Application.php");
//getting the default email server
$defaultEmail = $this->emailAccount();
if ($defaultEmail === null) {
error_log(G::LoadTranslation('ID_EMAIL_ENGINE_IS_NOT_ENABLED'));
return false;
}
$mailCcAddresses = "";
$oApplication = new \Application();
$formData = $oApplication->Load($app_uid);
$frmData = unserialize($formData['APP_DATA']);
$dataFormToShowString = "";
foreach ($frmData as $field=>$value){
if( ($field != 'SYS_LANG') &&
foreach ($frmData as $field => $value) {
if (($field != 'SYS_LANG') &&
($field != 'SYS_SKIN') &&
($field != 'SYS_SYS') &&
($field != 'APPLICATION') &&
@@ -99,13 +108,15 @@ class Pmgmail {
($field != 'USER_LOGGED') &&
($field != 'USR_USERNAME') &&
($field != 'DYN_CONTENT_HISTORY') &&
($field != 'PIN') ){
($field != 'PIN') &&
(!is_array($value))
) {
$dataFormToShowString .= " " . $field . " " . $value;
}
}
$appData = $this->getDraftApp($app_uid, $index);
foreach ($appData as $application){
foreach ($appData as $application) {
$appNumber = $application['APP_NUMBER'];
$appStatus = $application['APP_STATUS'];
$index = $application['DEL_INDEX'];
@@ -119,39 +130,69 @@ class Pmgmail {
$tasUid = $application['TAS_UID'];
$lastIndex = $application['DEL_LAST_INDEX'];
if($appStatus == "DRAFT"){
if ($appStatus == "DRAFT") {
$labelID = "PMDRFT";
} else {
$labelID = "PMIBX";
}
}
if (( string ) $mailToAddresses === "") {
if ($arrayTask) {
$oCases = new \Cases ();
foreach ( $arrayTask as $aTask ) {
if (! isset ( $aTask ["USR_UID"] )) {
$aTask ["USR_UID"] = "";
}
$respTo = $oCases->getTo ( $aTask ["TAS_ASSIGN_TYPE"], $aTask ["TAS_UID"], $aTask ["USR_UID"], $arrayData );
$mailToAddresses = $respTo ['to'];
$mailCcAddresses = $respTo ['cc'];
if ($aTask ["TAS_ASSIGN_TYPE"] === "SELF_SERVICE") {
$labelID = "PMUASS";
if (( string ) $mailToAddresses === "") { // Self Service Value Based
$criteria = new \Criteria ( "workflow" );
$criteria->addSelectColumn ( \AppAssignSelfServiceValuePeer::GRP_UID );
$criteria->add ( \AppAssignSelfServiceValuePeer::APP_UID, $app_uid );
$rsCriteria = \AppAssignSelfServiceValuePeer::doSelectRs ( $criteria );
$rsCriteria->setFetchmode ( \ResultSet::FETCHMODE_ASSOC );
while ( $rsCriteria->next () ) {
$row = $rsCriteria->getRow ();
}
$targetIds = unserialize ( $row ['GRP_UID'] );
$oUsers = new \Users ();
if($mail == ""){
require_once (PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "Users.php");
$oUsers = new \Users();
if($nextUsr == ""){
//Unassigned:
$mail = "";
require_once (PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "TaskUser.php");
$oTaskUsers = new \TaskUser();
$taskUsers = $oTaskUsers->getAllUsersTask($tasUid);
foreach ($taskUsers as $user){
$usrData = $oUsers->loadDetails($user['USR_UID']);
$nextMail = $usrData['USR_EMAIL'];
$mail .= ($mail == '') ? $nextMail : ','. $nextMail;
}
$labelID = "PMUASS";
}else {
$usrData = $oUsers->loadDetails($nextUsr);
$mail = $usrData['USR_EMAIL'];
}
if (is_array($targetIds)) {
foreach ( $targetIds as $user ) {
$usrData = $oUsers->loadDetails ( $user );
$nextMail = $usrData ['USR_EMAIL'];
$mailToAddresses .= ($mailToAddresses == '') ? $nextMail : ',' . $nextMail;
}
} else {
$group = new \Groups();
$users = $group->getUsersOfGroup($targetIds);
foreach ($users as $user) {
$nextMail = $user['USR_EMAIL'];
$mailToAddresses .= ($mailToAddresses == '') ? $nextMail : ',' . $nextMail;
}
}
}
}
}
} else {
$oUsers = new \Users ();
$usrData = $oUsers->loadDetails ( $nextUsr );
$mailToAddresses = $usrData ['USR_EMAIL'];
}
}
//first template
$pathTemplate = PATH_DATA_SITE . "mailTemplates" . PATH_SEP . "pmGmail.html";
if (!file_exists($pathTemplate)){
if (!file_exists($pathTemplate)) {
$file = @fopen($pathTemplate, "w");
fwrite($file, '<div>');
fwrite($file, '<span style="display: none !important;">');
@@ -173,7 +214,8 @@ class Pmgmail {
$change = array('[', ']', '"');
$fdata = str_replace($change, ' ', $dataFormToShowString);
$aFields = array('proName' => $proName,
$aFields = array(
'proName' => $proName,
'appNumber' => $appNumber,
'caseUid' => $app_uid,
'taskName' => $tasName,
@@ -186,18 +228,15 @@ class Pmgmail {
'oform' => $fdata
);
$subject = "[PM] " .$proName. " (" . $index . ") Case: ". $appNumber;
$subject = "[PM] " . $proName . " (" . $index . ") Case: " . $appNumber;
//getting the default email server
$defaultEmail = $this->emailAccount();
require_once (PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "class.wsBase.php");
$ws = new \wsBase();
$resultMail = $ws->sendMessage(
$app_uid,
$defaultEmail, //From,
$mail,//To,
'',
$mailToAddresses,//$To,
$mailCcAddresses,//$Cc
'',
$subject,
'pmGmail.html',//template
@@ -279,5 +318,3 @@ class Pmgmail {
}
}