2012-10-22 05:57:53 -04:00
|
|
|
<?php
|
|
|
|
|
|
2012-11-16 17:13:48 -04:00
|
|
|
//require_once 'classes/model/om/BaseAppNotes.php';
|
2012-10-22 05:57:53 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Skeleton subclass for representing a row from the 'APP_NOTES' table.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* You should add additional methods to this class to meet the
|
|
|
|
|
* application requirements. This class will only be generated as
|
|
|
|
|
* long as it does not already exist in the output directory.
|
|
|
|
|
*
|
|
|
|
|
* @package classes.model
|
|
|
|
|
*/
|
|
|
|
|
class AppNotes extends BaseAppNotes
|
|
|
|
|
{
|
|
|
|
|
public function getNotesList ($appUid, $usrUid = '', $start = '', $limit = '')
|
|
|
|
|
{
|
|
|
|
|
require_once ("classes/model/Users.php");
|
|
|
|
|
|
|
|
|
|
G::LoadClass( 'ArrayPeer' );
|
|
|
|
|
|
|
|
|
|
$Criteria = new Criteria( 'workflow' );
|
|
|
|
|
$Criteria->clearSelectColumns();
|
|
|
|
|
|
|
|
|
|
$Criteria->addSelectColumn( AppNotesPeer::APP_UID );
|
|
|
|
|
$Criteria->addSelectColumn( AppNotesPeer::USR_UID );
|
|
|
|
|
$Criteria->addSelectColumn( AppNotesPeer::NOTE_DATE );
|
|
|
|
|
$Criteria->addSelectColumn( AppNotesPeer::NOTE_CONTENT );
|
|
|
|
|
$Criteria->addSelectColumn( AppNotesPeer::NOTE_TYPE );
|
|
|
|
|
$Criteria->addSelectColumn( AppNotesPeer::NOTE_AVAILABILITY );
|
|
|
|
|
$Criteria->addSelectColumn( AppNotesPeer::NOTE_ORIGIN_OBJ );
|
|
|
|
|
$Criteria->addSelectColumn( AppNotesPeer::NOTE_AFFECTED_OBJ1 );
|
|
|
|
|
$Criteria->addSelectColumn( AppNotesPeer::NOTE_AFFECTED_OBJ2 );
|
|
|
|
|
$Criteria->addSelectColumn( AppNotesPeer::NOTE_RECIPIENTS );
|
|
|
|
|
$Criteria->addSelectColumn( UsersPeer::USR_USERNAME );
|
|
|
|
|
$Criteria->addSelectColumn( UsersPeer::USR_FIRSTNAME );
|
|
|
|
|
$Criteria->addSelectColumn( UsersPeer::USR_LASTNAME );
|
|
|
|
|
$Criteria->addSelectColumn( UsersPeer::USR_EMAIL );
|
|
|
|
|
|
|
|
|
|
$Criteria->addJoin( AppNotesPeer::USR_UID, UsersPeer::USR_UID, Criteria::LEFT_JOIN );
|
|
|
|
|
|
|
|
|
|
$Criteria->add( appNotesPeer::APP_UID, $appUid, CRITERIA::EQUAL );
|
|
|
|
|
|
|
|
|
|
if ($usrUid != '') {
|
|
|
|
|
$Criteria->add( appNotesPeer::USR_UID, $usrUid, CRITERIA::EQUAL );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$Criteria->addDescendingOrderByColumn( AppNotesPeer::NOTE_DATE );
|
|
|
|
|
|
|
|
|
|
$response = array ();
|
|
|
|
|
$totalCount = AppNotesPeer::doCount( $Criteria );
|
|
|
|
|
$response['totalCount'] = $totalCount;
|
|
|
|
|
$response['notes'] = array ();
|
|
|
|
|
|
|
|
|
|
if ($start != '') {
|
|
|
|
|
$Criteria->setLimit( $limit );
|
|
|
|
|
$Criteria->setOffset( $start );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$oDataset = appNotesPeer::doSelectRS( $Criteria );
|
|
|
|
|
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
|
|
|
|
|
while ($aRow = $oDataset->getRow()) {
|
2013-01-29 14:19:03 -04:00
|
|
|
$aRow['NOTE_CONTENT'] = htmlentities(stripslashes($aRow['NOTE_CONTENT']), ENT_QUOTES, 'UTF-8');
|
2012-10-22 05:57:53 -04:00
|
|
|
$response['notes'][] = $aRow;
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result['criteria'] = $Criteria;
|
|
|
|
|
$result['array'] = $response;
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function postNewNote ($appUid, $usrUid, $noteContent, $notify = true, $noteAvalibility = "PUBLIC", $noteRecipients = "", $noteType = "USER", $noteDate = "now")
|
|
|
|
|
{
|
|
|
|
|
$this->setAppUid( $appUid );
|
|
|
|
|
$this->setUsrUid( $usrUid );
|
|
|
|
|
$this->setNoteDate( $noteDate );
|
|
|
|
|
$this->setNoteContent( $noteContent );
|
|
|
|
|
$this->setNoteType( $noteType );
|
|
|
|
|
$this->setNoteAvailability( $noteAvalibility );
|
|
|
|
|
$this->setNoteOriginObj( '' );
|
|
|
|
|
$this->setNoteAffectedObj1( '' );
|
|
|
|
|
$this->setNoteAffectedObj2( '' );
|
|
|
|
|
$this->setNoteRecipients( $noteRecipients );
|
|
|
|
|
|
|
|
|
|
if ($this->validate()) {
|
2012-10-19 21:30:26 +00:00
|
|
|
// we save it, since we get no validation errors, or do whatever else you like.
|
2012-10-22 05:57:53 -04:00
|
|
|
$res = $this->save();
|
|
|
|
|
$msg = '';
|
|
|
|
|
} else {
|
2012-10-19 21:30:26 +00:00
|
|
|
// Something went wrong. We can now get the validationFailures and handle them.
|
2012-10-22 05:57:53 -04:00
|
|
|
$msg = '';
|
|
|
|
|
$validationFailuresArray = $this->getValidationFailures();
|
|
|
|
|
foreach ($validationFailuresArray as $objValidationFailure) {
|
|
|
|
|
$msg .= $objValidationFailure->getMessage() . "<br/>";
|
|
|
|
|
}
|
2012-10-19 21:30:26 +00:00
|
|
|
//return array ( 'codError' => -100, 'rowsAffected' => 0, 'message' => $msg );
|
2012-10-22 05:57:53 -04:00
|
|
|
}
|
|
|
|
|
if ($msg != "") {
|
2013-05-16 20:48:16 +00:00
|
|
|
$response['success'] = G::LoadTranslation("ID_FAILURE");
|
2012-10-22 05:57:53 -04:00
|
|
|
$response['message'] = $msg;
|
|
|
|
|
} else {
|
2013-06-19 18:39:12 -04:00
|
|
|
$response['success'] = 'success';
|
|
|
|
|
$response['message'] = '';
|
2012-10-22 05:57:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($notify) {
|
|
|
|
|
if ($noteRecipients == "") {
|
|
|
|
|
$noteRecipientsA = array ();
|
|
|
|
|
G::LoadClass( 'case' );
|
|
|
|
|
$oCase = new Cases();
|
|
|
|
|
$p = $oCase->getUsersParticipatedInCase( $appUid );
|
|
|
|
|
foreach ($p['array'] as $key => $userParticipated) {
|
|
|
|
|
$noteRecipientsA[] = $key;
|
|
|
|
|
}
|
|
|
|
|
$noteRecipients = implode( ",", $noteRecipientsA );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->sendNoteNotification( $appUid, $usrUid, $noteContent, $noteRecipients );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function sendNoteNotification ($appUid, $usrUid, $noteContent, $noteRecipients, $sFrom = "")
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
require_once ('classes/model/Configuration.php');
|
|
|
|
|
$oConfiguration = new Configuration();
|
|
|
|
|
$sDelimiter = DBAdapter::getStringDelimiter();
|
|
|
|
|
$oCriteria = new Criteria( 'workflow' );
|
2013-05-17 20:56:29 +00:00
|
|
|
$oCriteria->add( ConfigurationPeer::CFG_UID, 'Emails' );
|
2012-10-22 05:57:53 -04:00
|
|
|
$oCriteria->add( ConfigurationPeer::OBJ_UID, '' );
|
|
|
|
|
$oCriteria->add( ConfigurationPeer::PRO_UID, '' );
|
|
|
|
|
$oCriteria->add( ConfigurationPeer::USR_UID, '' );
|
|
|
|
|
$oCriteria->add( ConfigurationPeer::APP_UID, '' );
|
|
|
|
|
if (ConfigurationPeer::doCount( $oCriteria ) == 0) {
|
2013-05-17 20:56:29 +00:00
|
|
|
$oConfiguration->create( array ('CFG_UID' => 'Emails', 'OBJ_UID' => '','CFG_VALUE' => '','PRO_UID' => '','USR_UID' => '','APP_UID' => '') );
|
2012-10-22 05:57:53 -04:00
|
|
|
$aConfiguration = array ();
|
|
|
|
|
} else {
|
2013-05-17 20:56:29 +00:00
|
|
|
$aConfiguration = $oConfiguration->load('Emails', '', '', '', '' );
|
2012-10-22 05:57:53 -04:00
|
|
|
if ($aConfiguration['CFG_VALUE'] != '') {
|
|
|
|
|
$aConfiguration = unserialize( $aConfiguration['CFG_VALUE'] );
|
|
|
|
|
$passwd = $aConfiguration['MESS_PASSWORD'];
|
|
|
|
|
$passwdDec = G::decrypt( $passwd, 'EMAILENCRYPT' );
|
|
|
|
|
$auxPass = explode( 'hash:', $passwdDec );
|
|
|
|
|
if (count( $auxPass ) > 1) {
|
|
|
|
|
if (count( $auxPass ) == 2) {
|
|
|
|
|
$passwd = $auxPass[1];
|
|
|
|
|
} else {
|
|
|
|
|
array_shift( $auxPass );
|
|
|
|
|
$passwd = implode( '', $auxPass );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$aConfiguration['MESS_PASSWORD'] = $passwd;
|
|
|
|
|
} else {
|
|
|
|
|
$aConfiguration = array ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! isset( $aConfiguration['MESS_ENABLED'] ) || $aConfiguration['MESS_ENABLED'] != '1') {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$oUser = new Users();
|
|
|
|
|
$aUser = $oUser->load( $usrUid );
|
|
|
|
|
$authorName = ((($aUser['USR_FIRSTNAME'] != '') || ($aUser['USR_LASTNAME'] != '')) ? $aUser['USR_FIRSTNAME'] . ' ' . $aUser['USR_LASTNAME'] . ' ' : '') . '<' . $aUser['USR_EMAIL'] . '>';
|
|
|
|
|
|
|
|
|
|
G::LoadClass( 'case' );
|
|
|
|
|
$oCase = new Cases();
|
|
|
|
|
$aFields = $oCase->loadCase( $appUid );
|
|
|
|
|
$configNoteNotification['subject'] = G::LoadTranslation( 'ID_MESSAGE_SUBJECT_NOTE_NOTIFICATION' ) . " @#APP_TITLE ";
|
|
|
|
|
$configNoteNotification['body'] = G::LoadTranslation( 'ID_CASE' ) . ": @#APP_TITLE<br />" . G::LoadTranslation( 'ID_AUTHOR' ) . ": $authorName<br /><br />$noteContent";
|
|
|
|
|
|
2013-06-14 12:35:25 -04:00
|
|
|
/*
|
2012-10-22 05:57:53 -04:00
|
|
|
if ($sFrom == '') {
|
|
|
|
|
$sFrom = '"ProcessMaker"';
|
|
|
|
|
}
|
2013-06-14 12:35:25 -04:00
|
|
|
*/
|
|
|
|
|
if (isset($aConfiguration['MESS_FROM_NAME']) && $aConfiguration['MESS_FROM_NAME'] != '') {
|
|
|
|
|
$sFrom = $aConfiguration['MESS_FROM_NAME'];
|
|
|
|
|
}
|
2012-10-22 05:57:53 -04:00
|
|
|
|
|
|
|
|
$hasEmailFrom = preg_match( '/(.+)@(.+)\.(.+)/', $sFrom, $match );
|
|
|
|
|
|
|
|
|
|
if (! $hasEmailFrom || strpos( $sFrom, $aConfiguration['MESS_ACCOUNT'] ) === false) {
|
|
|
|
|
if (($aConfiguration['MESS_ENGINE'] != 'MAIL') && ($aConfiguration['MESS_ACCOUNT'] != '')) {
|
|
|
|
|
$sFrom .= ' <' . $aConfiguration['MESS_ACCOUNT'] . '>';
|
|
|
|
|
} else {
|
|
|
|
|
if (($aConfiguration['MESS_ENGINE'] == 'MAIL')) {
|
|
|
|
|
$sFrom .= ' <info@' . gethostbyaddr( '127.0.0.1' ) . '>';
|
|
|
|
|
} else {
|
|
|
|
|
if ($aConfiguration['MESS_SERVER'] != '') {
|
|
|
|
|
if (($sAux = @gethostbyaddr( $aConfiguration['MESS_SERVER'] ))) {
|
|
|
|
|
$sFrom .= ' <info@' . $sAux . '>';
|
|
|
|
|
} else {
|
|
|
|
|
$sFrom .= ' <info@' . $aConfiguration['MESS_SERVER'] . '>';
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$sFrom .= ' <info@processmaker.com>';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sSubject = G::replaceDataField( $configNoteNotification['subject'], $aFields );
|
|
|
|
|
|
|
|
|
|
$sBody = nl2br( G::replaceDataField( $configNoteNotification['body'], $aFields ) );
|
|
|
|
|
|
|
|
|
|
G::LoadClass( 'spool' );
|
|
|
|
|
$oUser = new Users();
|
|
|
|
|
$recipientsArray = explode( ",", $noteRecipients );
|
|
|
|
|
|
|
|
|
|
foreach ($recipientsArray as $recipientUid) {
|
|
|
|
|
|
|
|
|
|
$aUser = $oUser->load( $recipientUid );
|
|
|
|
|
|
|
|
|
|
$sTo = ((($aUser['USR_FIRSTNAME'] != '') || ($aUser['USR_LASTNAME'] != '')) ? $aUser['USR_FIRSTNAME'] . ' ' . $aUser['USR_LASTNAME'] . ' ' : '') . '<' . $aUser['USR_EMAIL'] . '>';
|
|
|
|
|
$oSpool = new spoolRun();
|
2012-11-19 14:35:10 -04:00
|
|
|
if ($aConfiguration['MESS_RAUTH'] == false || (is_string($aConfiguration['MESS_RAUTH']) && $aConfiguration['MESS_RAUTH'] == 'false')) {
|
|
|
|
|
$aConfiguration['MESS_RAUTH'] = 0;
|
|
|
|
|
} else {
|
|
|
|
|
$aConfiguration['MESS_RAUTH'] = 1;
|
2012-11-15 10:10:04 -04:00
|
|
|
}
|
|
|
|
|
|
2012-10-22 05:57:53 -04:00
|
|
|
$oSpool->setConfig( array ('MESS_ENGINE' => $aConfiguration['MESS_ENGINE'],'MESS_SERVER' => $aConfiguration['MESS_SERVER'],'MESS_PORT' => $aConfiguration['MESS_PORT'],'MESS_ACCOUNT' => $aConfiguration['MESS_ACCOUNT'],'MESS_PASSWORD' => $aConfiguration['MESS_PASSWORD'],'SMTPAuth' => $aConfiguration['MESS_RAUTH'] == '1' ? true : false,'SMTPSecure' => isset( $aConfiguration['SMTPSecure'] ) ? $aConfiguration['SMTPSecure'] : '') );
|
2013-06-28 17:34:33 -04:00
|
|
|
$oSpool->create( array ('msg_uid' => '','app_uid' => $appUid,'del_index' => 0,'app_msg_type' => 'DERIVATION','app_msg_subject' => $sSubject,'app_msg_from' => $sFrom,'app_msg_to' => $sTo,'app_msg_body' => $sBody,'app_msg_cc' => '','app_msg_bcc' => '','app_msg_attach' => '','app_msg_template' => '','app_msg_status' => 'pending') );
|
2012-10-22 05:57:53 -04:00
|
|
|
if (($aConfiguration['MESS_BACKGROUND'] == '') || ($aConfiguration['MESS_TRY_SEND_INMEDIATLY'] == '1')) {
|
|
|
|
|
$oSpool->sendMail();
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-14 10:45:20 -04:00
|
|
|
}
|
2012-10-19 21:30:26 +00:00
|
|
|
//Send derivation notification - End
|
2012-10-22 05:57:53 -04:00
|
|
|
} catch (Exception $oException) {
|
|
|
|
|
throw $oException;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-11-19 14:35:10 -04:00
|
|
|
|
|
|
|
|
public function addCaseNote($applicationUid, $userUid, $note, $sendMail)
|
|
|
|
|
{
|
|
|
|
|
$response = $this->postNewNote($applicationUid, $userUid, $note, false);
|
|
|
|
|
|
|
|
|
|
if ($sendMail == 1) {
|
|
|
|
|
G::LoadClass("case");
|
|
|
|
|
|
|
|
|
|
$case = new Cases();
|
|
|
|
|
|
|
|
|
|
$p = $case->getUsersParticipatedInCase($applicationUid);
|
|
|
|
|
$noteRecipientsList = array();
|
|
|
|
|
|
|
|
|
|
foreach ($p["array"] as $key => $userParticipated) {
|
2013-12-05 14:59:28 -04:00
|
|
|
if ($key != '') {
|
|
|
|
|
$noteRecipientsList[] = $key;
|
|
|
|
|
}
|
2012-11-19 14:35:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$noteRecipients = implode(",", $noteRecipientsList);
|
|
|
|
|
$note = stripslashes($note);
|
|
|
|
|
|
|
|
|
|
$this->sendNoteNotification($applicationUid, $userUid, $note, $noteRecipients);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
|
}
|
2012-10-22 05:57:53 -04:00
|
|
|
}
|
|
|
|
|
|