Skip to content
Snippets Groups Projects
Commit 292c89c7 authored by Florian Azizian's avatar Florian Azizian
Browse files

FEAT #202 fusion M2M refactoring

parent 02f41b41
No related branches found
No related tags found
No related merge requests found
...@@ -12,290 +12,291 @@ while ($state <> 'END') { ...@@ -12,290 +12,291 @@ while ($state <> 'END') {
$GLOBALS['logger']->write('STATE:' . $state, 'INFO'); $GLOBALS['logger']->write('STATE:' . $state, 'INFO');
} }
switch ($state) { switch ($state) {
/**********************************************************************/ /**********************************************************************/
/* LOAD_EMAILS */ /* LOAD_EMAILS */
/* List the records to proceed */ /* List the records to proceed */
/**********************************************************************/ /**********************************************************************/
case 'LOAD_EMAILS' : case 'LOAD_EMAILS':
$query = "SELECT * FROM " . EMAILS_TABLE $query = "SELECT * FROM " . EMAILS_TABLE
. " WHERE email_status = 'W' and send_date is NULL"; . " WHERE email_status = 'W' and send_date is NULL";
$stmt = Bt_doQuery($GLOBALS['db'], $query); $stmt = Bt_doQuery($GLOBALS['db'], $query);
$totalEmailsToProcess = $stmt->rowCount(); $totalEmailsToProcess = $stmt->rowCount();
$currentEmail = 0; $currentEmail = 0;
if ($totalEmailsToProcess === 0) { if ($totalEmailsToProcess === 0) {
Bt_exitBatch(0, 'No e-mails to process'); Bt_exitBatch(0, 'No e-mails to process');
}
$GLOBALS['logger']->write($totalEmailsToProcess . ' e-mails to proceed.', 'INFO');
$GLOBALS['emails'] = array();
while ($emailRecordset = $stmt->fetchObject()) {
$GLOBALS['emails'][] = $emailRecordset;
} }
$GLOBALS['logger']->write($totalEmailsToProcess . ' e-mails to proceed.', 'INFO'); $state = 'SEND_AN_EMAIL';
$GLOBALS['emails'] = array(); $err = 0;
while ($emailRecordset = $stmt->fetchObject()) {
$GLOBALS['emails'][] = $emailRecordset;
}
$state = 'SEND_AN_EMAIL';
$err = 0;
$errTxt = ''; $errTxt = '';
break; break;
/**********************************************************************/ /**********************************************************************/
/* SEND_AN_EMAIL */ /* SEND_AN_EMAIL */
/* Load parameters and send an e-mail */ /* Load parameters and send an e-mail */
/**********************************************************************/ /**********************************************************************/
case 'SEND_AN_EMAIL' : case 'SEND_AN_EMAIL':
if($currentEmail < $totalEmailsToProcess) { if ($currentEmail < $totalEmailsToProcess) {
$email = $GLOBALS['emails'][$currentEmail]; $email = $GLOBALS['emails'][$currentEmail];
//var_dump($email);exit; //var_dump($email);exit;
$GLOBALS['mailer'] = new htmlMimeMail(); $GLOBALS['mailer'] = new htmlMimeMail();
$GLOBALS['mailer']->setSMTPParams( $GLOBALS['mailer']->setSMTPParams(
$host = (string)$mailerParams->smtp_host, $host = (string)$mailerParams->smtp_host,
$port = (string)$mailerParams->smtp_port, $port = (string)$mailerParams->smtp_port,
$helo = (string)$mailerParams->domains, $helo = (string)$mailerParams->domains,
$auth = filter_var($mailerParams->smtp_auth, FILTER_VALIDATE_BOOLEAN), $auth = filter_var($mailerParams->smtp_auth, FILTER_VALIDATE_BOOLEAN),
$user = (string)$mailerParams->smtp_user, $user = (string)$mailerParams->smtp_user,
$pass = (string)$mailerParams->smtp_password $pass = (string)$mailerParams->smtp_password
); );
$mailfrom_generic = (string)$mailerParams->mailfrom; $mailfrom_generic = (string)$mailerParams->mailfrom;
//Composing email //Composing email
//--> Set from //--> Set from
$userInfo = $users->get_user($email->user_id); $userInfo = $users->get_user($email->user_id);
//var_dump($userInfo); //var_dump($userInfo);
//echo 'userInfo : ' . $userInfo['mail'] . '==' . ' sender_email : ' . $email->sender_email . PHP_EOL; //echo 'userInfo : ' . $userInfo['mail'] . '==' . ' sender_email : ' . $email->sender_email . PHP_EOL;
if ($userInfo['mail'] == $email->sender_email) { if ($userInfo['mail'] == $email->sender_email) {
if (!empty($mailfrom_generic)) { if (!empty($mailfrom_generic)) {
$GLOBALS['logger']->write('process e-mail '.($currentEmail+1)."/".$totalEmailsToProcess.' (FROM => '.$userInfo['firstname'].' '.$userInfo['lastname'].' <'.$mailfrom_generic.'>'.', TO => '.$email->to_list.', SUBJECT => '.$email->email_object.', CC =>'.$email->cc_list.', CCI => '.$email->cci_list.') ...', 'INFO');
$GLOBALS['logger']->write('process e-mail '.($currentEmail+1)."/".$totalEmailsToProcess.' (FROM => '.$userInfo['firstname'].' '.$userInfo['lastname'].' <'.$mailfrom_generic.'>'.', TO => '.$email->to_list.', SUBJECT => '.$email->email_object.', CC =>'.$email->cc_list.', CCI => '.$email->cci_list.') ...', 'INFO');
$GLOBALS['mailer']->setFrom($userInfo['firstname'].' '
$GLOBALS['mailer']->setFrom($userInfo['firstname'].' ' . $userInfo['lastname'].' <'.$mailfrom_generic.'> ');
. $userInfo['lastname'].' <'.$mailfrom_generic.'> '); $emailFrom = $mailfrom_generic;
$emailFrom = $mailfrom_generic; $email->email_body = 'Courriel envoyé par : ' . $userInfo['firstname'].' '
$email->email_body = 'Courriel envoyé par : ' . $userInfo['firstname'].' ' . $userInfo['lastname'] . ' ' . $email->sender_email . ' ' . '.<br/><br/>' . $email->email_body;
. $userInfo['lastname'] . ' ' . $email->sender_email . ' ' . '.<br/><br/>' . $email->email_body; } else {
} else { $GLOBALS['logger']->write('process e-mail '.($currentEmail+1)."/".$totalEmailsToProcess.' (FROM => '.$userInfo['firstname'].' '.$userInfo['lastname'].' <'.$email->sender_email.'>'.', TO => '.$email->to_list.', SUBJECT => '.$email->email_object.', CC =>'.$email->cc_list.', CCI => '.$email->cci_list.') ...', 'INFO');
$GLOBALS['logger']->write('process e-mail '.($currentEmail+1)."/".$totalEmailsToProcess.' (FROM => '.$userInfo['firstname'].' '.$userInfo['lastname'].' <'.$email->sender_email.'>'.', TO => '.$email->to_list.', SUBJECT => '.$email->email_object.', CC =>'.$email->cc_list.', CCI => '.$email->cci_list.') ...', 'INFO'); $GLOBALS['mailer']->setFrom($userInfo['firstname'].' '
. $userInfo['lastname'].' <'.$email->sender_email.'> ');
$GLOBALS['mailer']->setFrom($userInfo['firstname'].' ' $emailFrom = $email->sender_email;
. $userInfo['lastname'].' <'.$email->sender_email.'> '); }
$emailFrom = $email->sender_email; $GLOBALS['mailer']->setReplyTo($email->sender_email);
} } else {
$GLOBALS['mailer']->setReplyTo($email->sender_email); if (!empty($mailfrom_generic)) {
$mailsEntities = $sendmail_tools->getAttachedEntitiesMails();
} else { $entityShortLabel = substr($mailsEntities[$email->sender_email], 0, strrpos($mailsEntities[$email->sender_email], "("));
if (!empty($mailfrom_generic)) {
$mailsEntities = $sendmail_tools->getAttachedEntitiesMails(); $GLOBALS['mailer']->setFrom($entityShortLabel . ' <' . $mailfrom_generic. '> ');
$entityShortLabel = substr($mailsEntities[$email->sender_email], 0, strrpos($mailsEntities[$email->sender_email], "(")); $emailFrom = $mailfrom_generic;
$email->email_body = 'Courriel envoyé par : ' . $entityShortLabel . ' ' . $sendmail_tools->explodeSenderEmail($email->sender_email) . ' ' . '.<br/><br/>' . $email->email_body;
$GLOBALS['mailer']->setFrom($entityShortLabel . ' <' . $mailfrom_generic. '> '); } else {
$emailFrom = $mailfrom_generic; $mailsEntities = $sendmail_tools->getAttachedEntitiesMails();
$email->email_body = 'Courriel envoyé par : ' . $entityShortLabel . ' ' . $sendmail_tools->explodeSenderEmail($email->sender_email) . ' ' . '.<br/><br/>' . $email->email_body; $entityShortLabel = substr($mailsEntities[$email->sender_email], 0, strrpos($mailsEntities[$email->sender_email], "("));
} else {
$mailsEntities = $sendmail_tools->getAttachedEntitiesMails(); $GLOBALS['mailer']->setFrom($entityShortLabel . ' <' . $sendmail_tools->explodeSenderEmail($email->sender_email) . '> ');
$entityShortLabel = substr($mailsEntities[$email->sender_email], 0, strrpos($mailsEntities[$email->sender_email], "(")); $emailFrom = $sendmail_tools->explodeSenderEmail($email->sender_email);
}
$GLOBALS['mailer']->setFrom($entityShortLabel . ' <' . $sendmail_tools->explodeSenderEmail($email->sender_email) . '> '); $GLOBALS['mailer']->setReplyTo($sendmail_tools->explodeSenderEmail($email->sender_email));
$emailFrom = $sendmail_tools->explodeSenderEmail($email->sender_email); }
}
$GLOBALS['mailer']->setReplyTo($sendmail_tools->explodeSenderEmail($email->sender_email)); //echo $email->email_body . PHP_EOL;exit;
}
if (!empty($email->cc_list)) {
//echo $email->email_body . PHP_EOL;exit; $GLOBALS['logger']->write("Copy e-mail to : " . $email->cc_list, 'INFO');
}
if (!empty($email->cc_list))$GLOBALS['logger']->write("Copy e-mail to : " . $email->cc_list, 'INFO'); if (!empty($email->cci_list)) {
if (!empty($email->cci_list))$GLOBALS['logger']->write("Copy invisible e-mail to : " . $email->cci_list, 'INFO'); $GLOBALS['logger']->write("Copy invisible e-mail to : " . $email->cci_list, 'INFO');
}
//--> Set the return path
if (!empty($mailfrom_generic)) { //--> Set the return path
$GLOBALS['mailer']->setReturnPath( if (!empty($mailfrom_generic)) {
$userInfo['firstname'] . ' ' . $userInfo['lastname'] . ' <' . $mailfrom_generic . '> ' $GLOBALS['mailer']->setReturnPath(
); $userInfo['firstname'] . ' ' . $userInfo['lastname'] . ' <' . $mailfrom_generic . '> '
} else { );
$GLOBALS['mailer']->setReturnPath($userInfo['mail']);
}
//--> To
$to = array();
$to = explode(',', $email->to_list);
//--> Cc
if (!empty($email->cc_list)) {
$GLOBALS['mailer']->setCc($email->cc_list);
}
//--> Cci
if (!empty($email->cci_list)) {
$GLOBALS['mailer']->setBcc($email->cci_list);
}
//--> Set subject
$GLOBALS['mailer']->setSubject($email->email_object);
//--> Set body: Is Html/raw text ?
if ($email->is_html == 'Y') {
$body = str_replace('###', ';', $email->email_body);
$body = str_replace('___', '--', $body);
$body = $sendmail_tools->rawToHtml($body);
$GLOBALS['mailer']->setHtml($body);
} else {
$body = $sendmail_tools->htmlToRaw($email->email_body);
$GLOBALS['mailer']->setText($body);
}
//--> Set charset
$GLOBALS['mailer']->setTextCharset($GLOBALS['charset']);
$GLOBALS['mailer']->setHtmlCharset($GLOBALS['charset']);
$GLOBALS['mailer']->setHeadCharset($GLOBALS['charset']);
//--> Set attachments
//zip M2M
if ($email->message_exchange_id) {
$GLOBALS['logger']->write("set zip on message: " . $email->message_exchange_id, 'INFO');
//Get uri zip
$query = "SELECT * FROM message_exchange WHERE message_id = ?";
$smtp = $stmt = Bt_doQuery($GLOBALS['db'], $query, array($email->message_exchange_id));
$messageExchange = $smtp->fetchObject();
$docserver = \Core\Models\DocserverModel::getById(['docserver_id' => $messageExchange->docserver_id]);
$docserverType = \Core\Models\DocserverTypeModel::getById(['docserver_type_id' => $docserver[0]['docserver_type_id']]);
$pathDirectory = str_replace('#', DIRECTORY_SEPARATOR, $messageExchange->path);
$filePath = $docserver[0]['path_template'] . $pathDirectory . $messageExchange->filename;
$fingerprint = \Core\Controllers\DocserverToolsController::doFingerprint([
'path' => $filePath,
'fingerprintMode' => $docserverType[0]['fingerprint_mode'],
]);
if($fingerprint['fingerprint'] != $messageExchange->fingerprint){
$GLOBALS['logger']->write(_PB_WITH_FINGERPRINT_OF_DOCUMENT.'. ResId master : ' . $email->res_id, 'ERROR');
}
//Get file content
if(is_file($filePath)) {
//Filename
$resFilename = $sendmail_tools->createFilename($messageExchange->reference, 'zip');
$GLOBALS['logger']->write("set attachment filename : " . $resFilename, 'INFO');
//File content
$file_content = $GLOBALS['mailer']->getFile($filePath);
//Add file
$GLOBALS['mailer']->addAttachment($file_content, $resFilename);
}
} else { } else {
//Res master $GLOBALS['mailer']->setReturnPath($userInfo['mail']);
if ($email->is_res_master_attached == 'Y') { }
$GLOBALS['logger']->write("set attachment on res master : " . $email->res_id, 'INFO');
//--> To
//Get file from docserver $to = array();
$resFile = $sendmail_tools->getResource($GLOBALS['collections'], $email->coll_id, $email->res_id); $to = explode(',', $email->to_list);
//Get file content //--> Cc
if(is_file($resFile['file_path'])) { if (!empty($email->cc_list)) {
//Filename $GLOBALS['mailer']->setCc($email->cc_list);
$resFilename = $sendmail_tools->createFilename($resFile['label'], $resFile['ext']); }
$GLOBALS['logger']->write("set attachment filename : " . $resFilename, 'INFO'); //--> Cci
if (!empty($email->cci_list)) {
//File content $GLOBALS['mailer']->setBcc($email->cci_list);
$file_content = $GLOBALS['mailer']->getFile($resFile['file_path']); }
//Add file //--> Set subject
$GLOBALS['mailer']->addAttachment($file_content, $resFilename, $resFile['mime_type']); $GLOBALS['mailer']->setSubject($email->email_object);
} //--> Set body: Is Html/raw text ?
} if ($email->is_html == 'Y') {
$body = str_replace('###', ';', $email->email_body);
//Other version of the document $body = str_replace('___', '--', $body);
if (!empty($email->res_version_id_list)) { $body = $sendmail_tools->rawToHtml($body);
$GLOBALS['mailer']->setHtml($body);
} else {
$body = $sendmail_tools->htmlToRaw($email->email_body);
$GLOBALS['mailer']->setText($body);
}
//--> Set charset
$GLOBALS['mailer']->setTextCharset($GLOBALS['charset']);
$GLOBALS['mailer']->setHtmlCharset($GLOBALS['charset']);
$GLOBALS['mailer']->setHeadCharset($GLOBALS['charset']);
//--> Set attachments
//zip M2M
if ($email->message_exchange_id) {
$GLOBALS['logger']->write("set zip on message: " . $email->message_exchange_id, 'INFO');
//Get uri zip
$query = "SELECT * FROM message_exchange WHERE message_id = ?";
$smtp = $stmt = Bt_doQuery($GLOBALS['db'], $query, array($email->message_exchange_id));
$messageExchange = $smtp->fetchObject();
$docserver = \Docserver\models\DocserverModel::getById(['id' => $messageExchange->docserver_id]);
$docserverType = \Docserver\models\DocserverTypeModel::getById(['id' => $docserver[0]['docserver_type_id']]);
$pathDirectory = str_replace('#', DIRECTORY_SEPARATOR, $messageExchange->path);
$filePath = $docserver[0]['path_template'] . $pathDirectory . $messageExchange->filename;
$fingerprint = \SrcCore\controllers\StoreController::getFingerPrint([
'filePath' => $filePath,
'mode' => $docserverType[0]['fingerprint_mode'],
]);
if ($fingerprint['fingerprint'] != $messageExchange->fingerprint) {
$GLOBALS['logger']->write(_PB_WITH_FINGERPRINT_OF_DOCUMENT.'. ResId master : ' . $email->res_id, 'ERROR');
}
//Get file content
if (is_file($filePath)) {
//Filename
$resFilename = $sendmail_tools->createFilename($messageExchange->reference, 'zip');
$GLOBALS['logger']->write("set attachment filename : " . $resFilename, 'INFO');
//File content
$file_content = $GLOBALS['mailer']->getFile($filePath);
//Add file
$GLOBALS['mailer']->addAttachment($file_content, $resFilename);
}
} else {
//Res master
if ($email->is_res_master_attached == 'Y') {
$GLOBALS['logger']->write("set attachment on res master : " . $email->res_id, 'INFO');
//Get file from docserver
$resFile = $sendmail_tools->getResource($GLOBALS['collections'], $email->coll_id, $email->res_id);
//Get file content
if (is_file($resFile['file_path'])) {
//Filename
$resFilename = $sendmail_tools->createFilename($resFile['label'], $resFile['ext']);
$GLOBALS['logger']->write("set attachment filename : " . $resFilename, 'INFO');
//File content
$file_content = $GLOBALS['mailer']->getFile($resFile['file_path']);
//Add file
$GLOBALS['mailer']->addAttachment($file_content, $resFilename, $resFile['mime_type']);
}
}
//Other version of the document
if (!empty($email->res_version_id_list)) {
$version = explode(',', $email->res_version_id_list); $version = explode(',', $email->res_version_id_list);
foreach($version as $version_id) { foreach ($version as $version_id) {
$GLOBALS['logger']->write("set attachment for version : " . $version_id, 'INFO'); $GLOBALS['logger']->write("set attachment for version : " . $version_id, 'INFO');
$versionFile = $sendmail_tools->getVersion( $versionFile = $sendmail_tools->getVersion(
$GLOBALS['collections'], $GLOBALS['collections'],
$email->coll_id, $email->coll_id,
$email->res_id, $email->res_id,
$version_id $version_id
); );
if(is_file($versionFile['file_path'])) { if (is_file($versionFile['file_path'])) {
//Filename //Filename
$versionFilename = $sendmail_tools->createFilename($versionFile['label'], $versionFile['ext']); $versionFilename = $sendmail_tools->createFilename($versionFile['label'], $versionFile['ext']);
$GLOBALS['logger']->write("set attachment filename for version : " . $versionFilename, 'INFO'); $GLOBALS['logger']->write("set attachment filename for version : " . $versionFilename, 'INFO');
//File content //File content
$file_content = $GLOBALS['mailer']->getFile($versionFile['file_path']); $file_content = $GLOBALS['mailer']->getFile($versionFile['file_path']);
//Add file //Add file
$GLOBALS['mailer']->addAttachment($file_content, $versionFilename, $versionFile['mime_type']); $GLOBALS['mailer']->addAttachment($file_content, $versionFilename, $versionFile['mime_type']);
} }
} }
} }
//Res attachment //Res attachment
if (!empty($email->res_attachment_id_list)) { if (!empty($email->res_attachment_id_list)) {
$attachments = explode(',', $email->res_attachment_id_list); $attachments = explode(',', $email->res_attachment_id_list);
foreach($attachments as $attachment_id) { foreach ($attachments as $attachment_id) {
$GLOBALS['logger']->write("set attachment on res attachment : " . $attachment_id, 'INFO'); $GLOBALS['logger']->write("set attachment on res attachment : " . $attachment_id, 'INFO');
$attachmentFile = $sendmail_tools->getAttachment( $attachmentFile = $sendmail_tools->getAttachment(
$email->coll_id, $email->coll_id,
$email->res_id, $email->res_id,
$attachment_id $attachment_id
); );
if(is_file($attachmentFile['file_path'])) { if (is_file($attachmentFile['file_path'])) {
//Filename //Filename
$attachmentFilename = $sendmail_tools->createFilename($attachmentFile['label'], $attachmentFile['ext']); $attachmentFilename = $sendmail_tools->createFilename($attachmentFile['label'], $attachmentFile['ext']);
$GLOBALS['logger']->write("set attachment filename : " . $attachmentFilename, 'INFO'); $GLOBALS['logger']->write("set attachment filename : " . $attachmentFilename, 'INFO');
//File content //File content
$file_content = $GLOBALS['mailer']->getFile($attachmentFile['file_path']); $file_content = $GLOBALS['mailer']->getFile($attachmentFile['file_path']);
//Add file //Add file
$GLOBALS['mailer']->addAttachment($file_content, $attachmentFilename, $attachmentFile['mime_type']); $GLOBALS['mailer']->addAttachment($file_content, $attachmentFilename, $attachmentFile['mime_type']);
} }
} }
} }
//Res version attachment //Res version attachment
if (!empty($email->res_version_att_id_list)) { if (!empty($email->res_version_att_id_list)) {
$attachments = explode(',', $email->res_version_att_id_list); $attachments = explode(',', $email->res_version_att_id_list);
foreach($attachments as $attachment_id) { foreach ($attachments as $attachment_id) {
$GLOBALS['logger']->write("set attachment version on res attachment : " . $attachment_id, 'INFO'); $GLOBALS['logger']->write("set attachment version on res attachment : " . $attachment_id, 'INFO');
$attachmentFile = $sendmail_tools->getAttachment( $attachmentFile = $sendmail_tools->getAttachment(
$email->coll_id, $email->coll_id,
$email->res_id, $email->res_id,
$attachment_id, $attachment_id,
true true
); );
if(is_file($attachmentFile['file_path'])) { if (is_file($attachmentFile['file_path'])) {
//Filename //Filename
$attachmentFilename = $sendmail_tools->createFilename($attachmentFile['label'], $attachmentFile['ext']); $attachmentFilename = $sendmail_tools->createFilename($attachmentFile['label'], $attachmentFile['ext']);
$GLOBALS['logger']->write("set attachment version filename : " . $attachmentFilename, 'INFO'); $GLOBALS['logger']->write("set attachment version filename : " . $attachmentFilename, 'INFO');
//File content //File content
$file_content = $GLOBALS['mailer']->getFile($attachmentFile['file_path']); $file_content = $GLOBALS['mailer']->getFile($attachmentFile['file_path']);
//Add file //Add file
$GLOBALS['mailer']->addAttachment($file_content, $attachmentFilename, $attachmentFile['mime_type']); $GLOBALS['mailer']->addAttachment($file_content, $attachmentFilename, $attachmentFile['mime_type']);
} }
} }
}
//Notes
if (!empty($email->note_id_list)) {
$notes = explode(',', $email->note_id_list);
$noteFile = $sendmail_tools->createNotesFile($email->coll_id, $email->res_id, $notes);
if (is_file($noteFile['file_path'])) {
//File content
$file_content = $GLOBALS['mailer']->getFile($noteFile['file_path']);
//Add file
$GLOBALS['mailer']->addAttachment($file_content, $noteFile['filename'], $noteFile['mime_type']);
}
} }
//Notes
if (!empty($email->note_id_list)) {
$notes = explode(',', $email->note_id_list);
$noteFile = $sendmail_tools->createNotesFile($email->coll_id, $email->res_id, $notes);
if(is_file($noteFile['file_path'])) {
//File content
$file_content = $GLOBALS['mailer']->getFile($noteFile['file_path']);
//Add file
$GLOBALS['mailer']->addAttachment($file_content, $noteFile['filename'], $noteFile['mime_type']);
}
}
} }
//Now send the mail //Now send the mail
$GLOBALS['logger']->write("sending e-mail ...", 'INFO'); $GLOBALS['logger']->write("sending e-mail ...", 'INFO');
$return = $GLOBALS['mailer']->send($to, (string)$mailerParams->type); $return = $GLOBALS['mailer']->send($to, (string)$mailerParams->type);
if( ($return == 1 && ((string)$mailerParams->type == "smtp" || (string)$mailerParams->type == "mail" )) || ($return == 0 && (string)$mailerParams->type == "sendmail")) { if (($return == 1 && ((string)$mailerParams->type == "smtp" || (string)$mailerParams->type == "mail")) || ($return == 0 && (string)$mailerParams->type == "sendmail")) {
$exec_result = 'S'; $exec_result = 'S';
$GLOBALS['logger']->write("e-mail sent.", 'INFO'); $GLOBALS['logger']->write("e-mail sent.", 'INFO');
} else { } else {
//$GLOBALS['logger']->write("Errors when sending message through SMTP :" . implode(', ', $GLOBALS['mailer']->errors), 'ERROR'); //$GLOBALS['logger']->write("Errors when sending message through SMTP :" . implode(', ', $GLOBALS['mailer']->errors), 'ERROR');
$GLOBALS['logger']->write("SENDING EMAIL ERROR ! (" . $return[0].")", 'ERROR'); $GLOBALS['logger']->write("SENDING EMAIL ERROR ! (" . $return[0].")", 'ERROR');
$GLOBALS['logger']->write("e-mail not sent !", 'ERROR'); $GLOBALS['logger']->write("e-mail not sent !", 'ERROR');
$exec_result = 'E'; $exec_result = 'E';
$err++; $err++;
$errTxt = ' (Last Error : '.$return[0].')'; $errTxt = ' (Last Error : '.$return[0].')';
$query = "INSERT INTO notif_email_stack (sender, recipient, subject, html_body, charset, module) VALUES (?, ?, ?, ?, ?, 'notifications')"; $query = "INSERT INTO notif_email_stack (sender, recipient, subject, html_body, charset, module) VALUES (?, ?, ?, ?, ?, 'notifications')";
$html = "Message automatique : <br><br> $html = "Message automatique : <br><br>
Le courriel avec l'identifiant ".$email->email_id." dans la table 'sendmail' n'a pas été envoyé. <br> Le courriel avec l'identifiant ".$email->email_id." dans la table 'sendmail' n'a pas été envoyé. <br>
...@@ -303,41 +304,40 @@ while ($state <> 'END') { ...@@ -303,41 +304,40 @@ while ($state <> 'END') {
Répertoire d'installation de l'application : ".$GLOBALS['maarchDirectory']."<br> Répertoire d'installation de l'application : ".$GLOBALS['maarchDirectory']."<br>
Fichier de configuration de sendmail : " . $GLOBALS['configFile']; Fichier de configuration de sendmail : " . $GLOBALS['configFile'];
$queryMlb = "SELECT alt_identifier FROM mlb_coll_ext WHERE res_id = ? "; $queryMlb = "SELECT alt_identifier FROM mlb_coll_ext WHERE res_id = ? ";
$stmt = Bt_doQuery($GLOBALS['db'], $queryMlb, array($email->res_id)); $stmt = Bt_doQuery($GLOBALS['db'], $queryMlb, array($email->res_id));
$mlbRecordSet = $stmt->fetchObject(); $mlbRecordSet = $stmt->fetchObject();
$html .= '<br><br>Le courriel a été envoyé depuis le courrier dont le numéro chrono est : ' . $mlbRecordSet->alt_identifier; $html .= '<br><br>Le courriel a été envoyé depuis le courrier dont le numéro chrono est : ' . $mlbRecordSet->alt_identifier;
$adminMails = explode(',', $GLOBALS['adminmail']); $adminMails = explode(',', $GLOBALS['adminmail']);
if(!empty($adminMails)){ if (!empty($adminMails)) {
foreach($adminMails as $recipient){ foreach ($adminMails as $recipient) {
if(!empty($recipient)){ if (!empty($recipient)) {
Bt_doQuery($GLOBALS['db'], $query, array($emailFrom, $recipient, $GLOBALS['subjectmail'], $html, $GLOBALS['charset'])); Bt_doQuery($GLOBALS['db'], $query, array($emailFrom, $recipient, $GLOBALS['subjectmail'], $html, $GLOBALS['charset']));
} }
} }
} }
if(!empty($userInfo['mail'])){ if (!empty($userInfo['mail'])) {
if(strlen($email->email_object) >= 100) { if (strlen($email->email_object) >= 100) {
$objectToSend = mb_substr($email->email_object, 0, 100); $objectToSend = mb_substr($email->email_object, 0, 100);
$objectToSend = substr($objectToSend, 0, strrpos($objectToSend, ' ')).'...'; $objectToSend = substr($objectToSend, 0, strrpos($objectToSend, ' ')).'...';
} else { } else {
$objectToSend = $email->email_object; $objectToSend = $email->email_object;
} }
$bodyMailError = "Message automatique : <br><br> $bodyMailError = "Message automatique : <br><br>
Votre envoi de courriel dont l'objet est \"". $objectToSend . "\" avec le numéro chrono \"" . $mlbRecordSet->alt_identifier . "\" n'a pas été envoyé. Veuillez réessayer ou contacter votre administreur."; Votre envoi de courriel dont l'objet est \"". $objectToSend . "\" avec le numéro chrono \"" . $mlbRecordSet->alt_identifier . "\" n'a pas été envoyé. Veuillez réessayer ou contacter votre administreur.";
Bt_doQuery($GLOBALS['db'], $query, array($emailFrom, $userInfo['mail'], $GLOBALS['subjectmail'], $bodyMailError, $GLOBALS['charset'])); Bt_doQuery($GLOBALS['db'], $query, array($emailFrom, $userInfo['mail'], $GLOBALS['subjectmail'], $bodyMailError, $GLOBALS['charset']));
} }
}
} //Update emails table
//Update emails table $query = "UPDATE " . EMAILS_TABLE
$query = "UPDATE " . EMAILS_TABLE . " SET send_date = CURRENT_TIMESTAMP "
. " SET send_date = CURRENT_TIMESTAMP " . ", email_status = ? "
. ", email_status = ? " . " WHERE email_id = ? ";
. " WHERE email_id = ? "; $stmt = Bt_doQuery($GLOBALS['db'], $query, array($exec_result, $email->email_id));
$stmt = Bt_doQuery($GLOBALS['db'], $query, array($exec_result, $email->email_id));
if ($email->message_exchange_id) { if ($email->message_exchange_id) {
//Update message table //Update message table
...@@ -346,13 +346,13 @@ while ($state <> 'END') { ...@@ -346,13 +346,13 @@ while ($state <> 'END') {
. " WHERE message_id = ? "; . " WHERE message_id = ? ";
$stmt = Bt_doQuery($GLOBALS['db'], $query, array($exec_result, $email->message_exchange_id)); $stmt = Bt_doQuery($GLOBALS['db'], $query, array($exec_result, $email->message_exchange_id));
} }
$currentEmail++; $currentEmail++;
$state = 'SEND_AN_EMAIL'; $state = 'SEND_AN_EMAIL';
} else { } else {
$state = 'END'; $state = 'END';
} }
break; break;
} }
} }
$emailSent = $totalEmailsToProcess - $err; $emailSent = $totalEmailsToProcess - $err;
...@@ -371,4 +371,3 @@ array_map('unlink', glob($_SESSION['config']['tmppath']."/*")); ...@@ -371,4 +371,3 @@ array_map('unlink', glob($_SESSION['config']['tmppath']."/*"));
//unlink($GLOBALS['lckFile']); //unlink($GLOBALS['lckFile']);
exit($GLOBALS['exitCode']); exit($GLOBALS['exitCode']);
?>
...@@ -21,18 +21,14 @@ $select["message_exchange"] = []; ...@@ -21,18 +21,14 @@ $select["message_exchange"] = [];
$orderstr = "order by date desc"; $orderstr = "order by date desc";
//Request //Request
$tab=$request->PDOselect($select, $where, [$identifier], $orderstr,$_SESSION['config']['databasetype']); $tab=$request->PDOselect($select, $where, [$identifier], $orderstr, $_SESSION['config']['databasetype']);
if(!empty($tab)){ if (!empty($tab)) {
//Result Array //Result Array
for ($i=0;$i<count($tab);$i++) for ($i=0;$i<count($tab);$i++) {
{ for ($j=0;$j<count($tab[$i]);$j++) {
for ($j=0;$j<count($tab[$i]);$j++) foreach (array_keys($tab[$i][$j]) as $value) {
{ if ($tab[$i][$j][$value]=="message_id") {
foreach(array_keys($tab[$i][$j]) as $value)
{
if($tab[$i][$j][$value]=="message_id")
{
$tab[$i][$j]["message_id"] = $tab[$i][$j]['value']; $tab[$i][$j]["message_id"] = $tab[$i][$j]['value'];
$tab[$i][$j]["label"] = 'ID'; $tab[$i][$j]["label"] = 'ID';
$tab[$i][$j]["size"] = "1"; $tab[$i][$j]["size"] = "1";
...@@ -42,8 +38,7 @@ if(!empty($tab)){ ...@@ -42,8 +38,7 @@ if(!empty($tab)){
$tab[$i][$j]["show"] = false; $tab[$i][$j]["show"] = false;
$tab[$i][$j]["order"] = 'message_id'; $tab[$i][$j]["order"] = 'message_id';
} }
if($tab[$i][$j][$value]=="date") if ($tab[$i][$j][$value]=="date") {
{
$tab[$i][$j]["label"] = _CREATION_DATE; $tab[$i][$j]["label"] = _CREATION_DATE;
$tab[$i][$j]["size"] = "9"; $tab[$i][$j]["size"] = "9";
$tab[$i][$j]["label_align"] = "left"; $tab[$i][$j]["label_align"] = "left";
...@@ -52,8 +47,7 @@ if(!empty($tab)){ ...@@ -52,8 +47,7 @@ if(!empty($tab)){
$tab[$i][$j]["show"] = true; $tab[$i][$j]["show"] = true;
$tab[$i][$j]["order"] = 'date'; $tab[$i][$j]["order"] = 'date';
} }
if($tab[$i][$j][$value]=="reference") if ($tab[$i][$j][$value]=="reference") {
{
$tab[$i][$j]["label"] = _IDENTIFIER; $tab[$i][$j]["label"] = _IDENTIFIER;
$tab[$i][$j]["size"] = "9"; $tab[$i][$j]["size"] = "9";
$tab[$i][$j]["label_align"] = "left"; $tab[$i][$j]["label_align"] = "left";
...@@ -62,8 +56,7 @@ if(!empty($tab)){ ...@@ -62,8 +56,7 @@ if(!empty($tab)){
$tab[$i][$j]["show"] = false; $tab[$i][$j]["show"] = false;
$tab[$i][$j]["order"] = 'reference'; $tab[$i][$j]["order"] = 'reference';
} }
if($tab[$i][$j][$value]=="type") if ($tab[$i][$j][$value]=="type") {
{
$tab[$i][$j]["value"] = constant('_M2M_'.strtoupper($tab[$i][$j]["value"])); $tab[$i][$j]["value"] = constant('_M2M_'.strtoupper($tab[$i][$j]["value"]));
$tab[$i][$j]["label"] = _TYPE; $tab[$i][$j]["label"] = _TYPE;
$tab[$i][$j]["size"] = "8"; $tab[$i][$j]["size"] = "8";
...@@ -73,8 +66,7 @@ if(!empty($tab)){ ...@@ -73,8 +66,7 @@ if(!empty($tab)){
$tab[$i][$j]["show"] = true; $tab[$i][$j]["show"] = true;
$tab[$i][$j]["order"] = 'type'; $tab[$i][$j]["order"] = 'type';
} }
if($tab[$i][$j][$value]=="operation_date") if ($tab[$i][$j][$value]=="operation_date") {
{
$tab[$i][$j]["value"] = $request->dateformat($tab[$i][$j]["value"]); $tab[$i][$j]["value"] = $request->dateformat($tab[$i][$j]["value"]);
$tab[$i][$j]["label"] = _OPERATION_DATE; $tab[$i][$j]["label"] = _OPERATION_DATE;
$tab[$i][$j]["size"] = "9"; $tab[$i][$j]["size"] = "9";
...@@ -84,8 +76,7 @@ if(!empty($tab)){ ...@@ -84,8 +76,7 @@ if(!empty($tab)){
$tab[$i][$j]["show"] = true; $tab[$i][$j]["show"] = true;
$tab[$i][$j]["order"] = 'operation_date'; $tab[$i][$j]["order"] = 'operation_date';
} }
if($tab[$i][$j][$value]=="reception_date") if ($tab[$i][$j][$value]=="reception_date") {
{
$tab[$i][$j]["value"] = $request->dateformat($tab[$i][$j]["value"]); $tab[$i][$j]["value"] = $request->dateformat($tab[$i][$j]["value"]);
$tab[$i][$j]["label"] = _RECEPTION_DATE; $tab[$i][$j]["label"] = _RECEPTION_DATE;
$tab[$i][$j]["size"] = "9"; $tab[$i][$j]["size"] = "9";
...@@ -95,8 +86,7 @@ if(!empty($tab)){ ...@@ -95,8 +86,7 @@ if(!empty($tab)){
$tab[$i][$j]["show"] = true; $tab[$i][$j]["show"] = true;
$tab[$i][$j]["order"] = 'reception_date'; $tab[$i][$j]["order"] = 'reception_date';
} }
if($tab[$i][$j][$value]=="recipient_org_name") if ($tab[$i][$j][$value]=="recipient_org_name") {
{
$tab[$i][$j]["value"] = $tab[$i][$j]["value"] . " (" . $recipient_org_identifier . ")"; $tab[$i][$j]["value"] = $tab[$i][$j]["value"] . " (" . $recipient_org_identifier . ")";
$tab[$i][$j]["label"] = _RECIPIENT; $tab[$i][$j]["label"] = _RECIPIENT;
$tab[$i][$j]["size"] = "20"; $tab[$i][$j]["size"] = "20";
...@@ -106,19 +96,16 @@ if(!empty($tab)){ ...@@ -106,19 +96,16 @@ if(!empty($tab)){
$tab[$i][$j]["show"] = true; $tab[$i][$j]["show"] = true;
$tab[$i][$j]["order"] = 'recipient_org_name'; $tab[$i][$j]["order"] = 'recipient_org_name';
} }
if($tab[$i][$j][$value]=="sender_org_name") if ($tab[$i][$j][$value]=="sender_org_name") {
{
$sender_org_name = $tab[$i][$j]["value"]; $sender_org_name = $tab[$i][$j]["value"];
$tab[$i][$j]["show"] = false; $tab[$i][$j]["show"] = false;
} }
if($tab[$i][$j][$value]=="recipient_org_identifier") if ($tab[$i][$j][$value]=="recipient_org_identifier") {
{
$recipient_org_identifier = $tab[$i][$j]["value"]; $recipient_org_identifier = $tab[$i][$j]["value"];
$tab[$i][$j]["show"] = false; $tab[$i][$j]["show"] = false;
} }
if($tab[$i][$j][$value]=="account_id") if ($tab[$i][$j][$value]=="account_id") {
{ $userInfo = \User\models\UserModel::getById(['id' => $tab[$i][$j]["value"]]);
$userInfo = \Core\Models\UserModel::getById(['userId' => $tab[$i][$j]["value"]]);
$tab[$i][$j]["value"] = $userInfo['firstname'] . " " . $userInfo['lastname'] . " (".$sender_org_name.")"; $tab[$i][$j]["value"] = $userInfo['firstname'] . " " . $userInfo['lastname'] . " (".$sender_org_name.")";
$tab[$i][$j]["label"] = _SENDER; $tab[$i][$j]["label"] = _SENDER;
$tab[$i][$j]["size"] = "20"; $tab[$i][$j]["size"] = "20";
...@@ -128,8 +115,7 @@ if(!empty($tab)){ ...@@ -128,8 +115,7 @@ if(!empty($tab)){
$tab[$i][$j]["show"] = true; $tab[$i][$j]["show"] = true;
$tab[$i][$j]["order"] = 'account_id'; $tab[$i][$j]["order"] = 'account_id';
} }
if($tab[$i][$j][$value]=="status") if ($tab[$i][$j][$value]=="status") {
{
$tab[$i][$j]["value"] = '<img src="' $tab[$i][$j]["value"] = '<img src="'
.$_SESSION['config']['businessappurl'].'static.php?module=sendmail&filename=' .$_SESSION['config']['businessappurl'].'static.php?module=sendmail&filename='
.$_SESSION['sendmail']['status'][$tab[$i][$j]["value"]]['img'].'" title="' .$_SESSION['sendmail']['status'][$tab[$i][$j]["value"]]['img'].'" title="'
...@@ -152,12 +138,12 @@ if(!empty($tab)){ ...@@ -152,12 +138,12 @@ if(!empty($tab)){
$paramsTab['bool_sortColumn'] = false; //Affichage Tri $paramsTab['bool_sortColumn'] = false; //Affichage Tri
$paramsTab['pageTitle'] = '<br><br>'._NUMERIC_PACKAGE_SENT; //Titre de la page $paramsTab['pageTitle'] = '<br><br>'._NUMERIC_PACKAGE_SENT; //Titre de la page
$paramsTab['bool_bigPageTitle'] = false; //Affichage du titre en grand $paramsTab['bool_bigPageTitle'] = false; //Affichage du titre en grand
$paramsTab['urlParameters'] = 'identifier='.$identifier."&origin=".$origin.'&display=true'.$parameters; //Parametres d'url supplementaires $paramsTab['urlParameters'] = 'identifier='.$identifier."&origin=".$origin.'&display=true'.$parameters; //Parametres d'url supplementaires
$paramsTab['listHeight'] = '100%'; //Hauteur de la liste $paramsTab['listHeight'] = '100%'; //Hauteur de la liste
$paramsTab['listCss'] = $css; //CSS $paramsTab['listCss'] = $css; //CSS
//Action icons array //Action icons array
$paramsTab['actionIcons'] = array(); $paramsTab['actionIcons'] = array();
$read = array( $read = array(
"script" => "showEmailForm('".$_SESSION['config']['businessappurl'] "script" => "showEmailForm('".$_SESSION['config']['businessappurl']
."index.php?display=true&module=sendmail&page=sendmail_ajax_content" ."index.php?display=true&module=sendmail&page=sendmail_ajax_content"
...@@ -166,7 +152,7 @@ if(!empty($tab)){ ...@@ -166,7 +152,7 @@ if(!empty($tab)){
"icon" => 'eye', "icon" => 'eye',
"tooltip" => _READ "tooltip" => _READ
); );
array_push($paramsTab['actionIcons'], $read); array_push($paramsTab['actionIcons'], $read);
$download = array( $download = array(
"script" => "window.location = 'index.php?display=true&module=sendmail&page=sendmail_ajax_content" "script" => "window.location = 'index.php?display=true&module=sendmail&page=sendmail_ajax_content"
...@@ -176,7 +162,7 @@ if(!empty($tab)){ ...@@ -176,7 +162,7 @@ if(!empty($tab)){
"tooltip" => _SIMPLE_DOWNLOAD, "tooltip" => _SIMPLE_DOWNLOAD,
"disabledRules" => "empty(@@filename@@)" "disabledRules" => "empty(@@filename@@)"
); );
array_push($paramsTab['actionIcons'], $download); array_push($paramsTab['actionIcons'], $download);
//Output //Output
$status = 0; $status = 0;
......
...@@ -43,10 +43,6 @@ require_once 'modules/notifications/notifications_tables_definition.php'; ...@@ -43,10 +43,6 @@ require_once 'modules/notifications/notifications_tables_definition.php';
require_once "modules" . DIRECTORY_SEPARATOR . "sendmail" . DIRECTORY_SEPARATOR require_once "modules" . DIRECTORY_SEPARATOR . "sendmail" . DIRECTORY_SEPARATOR
. "class" . DIRECTORY_SEPARATOR . "class_modules_tools.php"; . "class" . DIRECTORY_SEPARATOR . "class_modules_tools.php";
require_once 'modules/sendmail/Controllers/SendMessageExchangeController.php'; require_once 'modules/sendmail/Controllers/SendMessageExchangeController.php';
require_once "core/Models/DocserverModel.php";
require_once "core/Models/DocserverTypeModel.php";
require_once "core/Controllers/DocserverToolsController.php";
$core_tools = new core_tools(); $core_tools = new core_tools();
$request = new request(); $request = new request();
...@@ -57,17 +53,16 @@ $users_tools = new class_users(); ...@@ -57,17 +53,16 @@ $users_tools = new class_users();
$sendmail_tools = new sendmail(); $sendmail_tools = new sendmail();
if($_SESSION['features']['send_to_contact_with_mandatory_attachment'] == true && !isset($_REQUEST['join_attachment']) && $_REQUEST['action'] == 'send_to_contact_with_mandatory_attachment'){ if ($_SESSION['features']['send_to_contact_with_mandatory_attachment'] == true && !isset($_REQUEST['join_attachment']) && $_REQUEST['action'] == 'send_to_contact_with_mandatory_attachment') {
$error = $request->wash_html(_PLEASE_CHOOSE_AN_ATTACHMENT, 'NONE');
$error = $request->wash_html(_PLEASE_CHOOSE_AN_ATTACHMENT,'NONE');
$status = 1; $status = 1;
echo "{status : " . $status . ", content : '" . addslashes(_parse($content)) . "', error : '" . addslashes(_parse_error($error)) . "', exec_js : '".addslashes($js)."'}"; echo "{status : " . $status . ", content : '" . addslashes(_parse($content)) . "', error : '" . addslashes(_parse_error($error)) . "', exec_js : '".addslashes($js)."'}";
exit (); exit();
} }
function _parse($text) { function _parse($text)
{
//... //...
$text = str_replace("\r\n", PHP_EOL, $text); $text = str_replace("\r\n", PHP_EOL, $text);
$text = str_replace("\r", PHP_EOL, $text); $text = str_replace("\r", PHP_EOL, $text);
...@@ -76,7 +71,8 @@ function _parse($text) { ...@@ -76,7 +71,8 @@ function _parse($text) {
$text = str_replace(PHP_EOL, "\\n ", $text); $text = str_replace(PHP_EOL, "\\n ", $text);
return $text; return $text;
} }
function _parse_error($text) { function _parse_error($text)
{
//... //...
$text = str_replace("###", "\\n ", $text); $text = str_replace("###", "\\n ", $text);
return $text; return $text;
...@@ -117,14 +113,24 @@ if (isset($_REQUEST['coll_id']) && ! empty($_REQUEST['coll_id'])) { ...@@ -117,14 +113,24 @@ if (isset($_REQUEST['coll_id']) && ! empty($_REQUEST['coll_id'])) {
} }
//Keep some origin parameters //Keep some origin parameters
if (isset($_REQUEST['size']) && !empty($_REQUEST['size'])) $parameters .= '&size='.$_REQUEST['size']; if (isset($_REQUEST['size']) && !empty($_REQUEST['size'])) {
$parameters .= '&size='.$_REQUEST['size'];
}
if (isset($_REQUEST['order']) && !empty($_REQUEST['order'])) { if (isset($_REQUEST['order']) && !empty($_REQUEST['order'])) {
$parameters .= '&order='.$_REQUEST['order']; $parameters .= '&order='.$_REQUEST['order'];
if (isset($_REQUEST['order_field']) && !empty($_REQUEST['order_field'])) $parameters .= '&order_field='.$_REQUEST['order_field']; if (isset($_REQUEST['order_field']) && !empty($_REQUEST['order_field'])) {
$parameters .= '&order_field='.$_REQUEST['order_field'];
}
}
if (isset($_REQUEST['what']) && !empty($_REQUEST['what'])) {
$parameters .= '&what='.$_REQUEST['what'];
}
if (isset($_REQUEST['template']) && !empty($_REQUEST['template'])) {
$parameters .= '&template='.$_REQUEST['template'];
}
if (isset($_REQUEST['start']) && !empty($_REQUEST['start'])) {
$parameters .= '&start='.$_REQUEST['start'];
} }
if (isset($_REQUEST['what']) && !empty($_REQUEST['what'])) $parameters .= '&what='.$_REQUEST['what'];
if (isset($_REQUEST['template']) && !empty($_REQUEST['template'])) $parameters .= '&template='.$_REQUEST['template'];
if (isset($_REQUEST['start']) && !empty($_REQUEST['start'])) $parameters .= '&start='.$_REQUEST['start'];
//Keep the origin to reload the origin list //Keep the origin to reload the origin list
$list_origin = $origin = ''; $list_origin = $origin = '';
...@@ -160,18 +166,18 @@ switch ($mode) { ...@@ -160,18 +166,18 @@ switch ($mode) {
if (isset($_REQUEST['id']) && !empty($_REQUEST['id'])) { if (isset($_REQUEST['id']) && !empty($_REQUEST['id'])) {
$parameters .= '&id='.$_REQUEST['id']; $parameters .= '&id='.$_REQUEST['id'];
} else { } else {
$error = $request->wash_html(_ID.' '._IS_EMPTY.'!','NONE'); $error = $request->wash_html(_ID.' '._IS_EMPTY.'!', 'NONE');
$status = 1; $status = 1;
//Close the modal //Close the modal
$js = "window.parent.destroyModal('form_email');"; $js = "window.parent.destroyModal('form_email');";
break; break;
} }
case 'add': case 'add':
if (empty($identifier)) { if (empty($identifier)) {
$error = $request->wash_html(_IDENTIFIER.' '._IS_EMPTY.'!','NONE'); $error = $request->wash_html(_IDENTIFIER.' '._IS_EMPTY.'!', 'NONE');
$status = 1; $status = 1;
//Close the modal //Close the modal
$js = "window.parent.destroyModal('form_email');"; $js = "window.parent.destroyModal('form_email');";
} else { } else {
//Reset arry of adresses //Reset arry of adresses
unset($_SESSION['adresses']); unset($_SESSION['adresses']);
...@@ -186,9 +192,9 @@ switch ($mode) { ...@@ -186,9 +192,9 @@ switch ($mode) {
break; break;
case 'added': case 'added':
if($formContent == 'messageExchange'){ if ($formContent == 'messageExchange') {
$return = SendMessageExchangeController::createMessageExchange($_REQUEST); $return = SendMessageExchangeController::createMessageExchange($_REQUEST);
if(!empty($return['errors'])){ if (!empty($return['errors'])) {
$error = implode(", ", $return['errors']); $error = implode(", ", $return['errors']);
$status = 1; $status = 1;
} }
...@@ -200,13 +206,13 @@ switch ($mode) { ...@@ -200,13 +206,13 @@ switch ($mode) {
$userEntitiesMails = $sendmail_tools->checkAttachedEntitiesMails($_SESSION['user']['UserId']); $userEntitiesMails = $sendmail_tools->checkAttachedEntitiesMails($_SESSION['user']['UserId']);
} }
if (empty($identifier)) { if (empty($identifier)) {
$error = $request->wash_html(_IDENTIFIER.' '._IS_EMPTY.'!','NONE'); $error = $request->wash_html(_IDENTIFIER.' '._IS_EMPTY.'!', 'NONE');
$status = 1; $status = 1;
} else if (!in_array($_REQUEST['sender_email'], array_keys($userEntitiesMails)) && $core_tools->test_service('use_mail_services', 'sendmail', false)) { } elseif (!in_array($_REQUEST['sender_email'], array_keys($userEntitiesMails)) && $core_tools->test_service('use_mail_services', 'sendmail', false)) {
$error = $request->wash_html(_INCORRECT_SENDER,'NONE'); $error = $request->wash_html(_INCORRECT_SENDER, 'NONE');
$status = 1; $status = 1;
} else { } else {
if (isset($_SESSION['adresses']['to']) && count($_SESSION['adresses']['to']) > 0 ) { if (isset($_SESSION['adresses']['to']) && count($_SESSION['adresses']['to']) > 0) {
if (!empty($_REQUEST['object'])) { if (!empty($_REQUEST['object'])) {
//Check adress for to //Check adress for to
...@@ -216,14 +222,14 @@ switch ($mode) { ...@@ -216,14 +222,14 @@ switch ($mode) {
if (empty($error)) { if (empty($error)) {
//Check adress for cc //Check adress for cc
(isset($_SESSION['adresses']['cc']) && count($_SESSION['adresses']['cc']) > 0)? (isset($_SESSION['adresses']['cc']) && count($_SESSION['adresses']['cc']) > 0)?
$cc = join(',', $_SESSION['adresses']['cc']) : $cc = ''; $cc = join(',', $_SESSION['adresses']['cc']) : $cc = '';
$error = $sendmail_tools->CheckEmailAdress($cc); $error = $sendmail_tools->CheckEmailAdress($cc);
if (empty($error)) { if (empty($error)) {
//Check adress for cci //Check adress for cci
(isset($_SESSION['adresses']['cci']) && count($_SESSION['adresses']['cci']) > 0)? (isset($_SESSION['adresses']['cci']) && count($_SESSION['adresses']['cci']) > 0)?
$cci = join(',', $_SESSION['adresses']['cci']) : $cci = ''; $cci = join(',', $_SESSION['adresses']['cci']) : $cci = '';
$error = $sendmail_tools->CheckEmailAdress($cci); $error = $sendmail_tools->CheckEmailAdress($cci);
...@@ -233,22 +239,22 @@ switch ($mode) { ...@@ -233,22 +239,22 @@ switch ($mode) {
$collId = $_REQUEST['coll_id']; $collId = $_REQUEST['coll_id'];
$object = $_REQUEST['object']; $object = $_REQUEST['object'];
$senderEmail = $_REQUEST['sender_email']; $senderEmail = $_REQUEST['sender_email'];
(isset($_REQUEST['join_file']) (isset($_REQUEST['join_file'])
&& count($_REQUEST['join_file']) > 0 && count($_REQUEST['join_file']) > 0
)? $res_master_attached = 'Y' : $res_master_attached = 'N'; )? $res_master_attached = 'Y' : $res_master_attached = 'N';
//attachment //attachment
if (isset($_REQUEST['join_attachment']) && count($_REQUEST['join_attachment']) > 0) { if (isset($_REQUEST['join_attachment']) && count($_REQUEST['join_attachment']) > 0) {
$attachment_list = join(',', $_REQUEST['join_attachment']); $attachment_list = join(',', $_REQUEST['join_attachment']);
} }
//Version attachment //Version attachment
if (isset($_REQUEST['join_version_attachment']) && count($_REQUEST['join_version_attachment']) > 0) { if (isset($_REQUEST['join_version_attachment']) && count($_REQUEST['join_version_attachment']) > 0) {
$attachment_version_list = join(',', $_REQUEST['join_version_attachment']); $attachment_version_list = join(',', $_REQUEST['join_version_attachment']);
} }
//version document //version document
if (isset($_REQUEST['join_version']) && count($_REQUEST['join_version']) > 0) { if (isset($_REQUEST['join_version']) && count($_REQUEST['join_version']) > 0) {
$version_list = join(',', $_REQUEST['join_version']); $version_list = join(',', $_REQUEST['join_version']);
} }
//Notes //Notes
if (isset($_REQUEST['notes']) && count($_REQUEST['notes']) > 0) { if (isset($_REQUEST['notes']) && count($_REQUEST['notes']) > 0) {
$note_list = join(',', $_REQUEST['notes']); $note_list = join(',', $_REQUEST['notes']);
} }
...@@ -259,23 +265,23 @@ switch ($mode) { ...@@ -259,23 +265,23 @@ switch ($mode) {
if ($isHtml == 'Y') { if ($isHtml == 'Y') {
$body = $sendmail_tools->cleanHtml($_REQUEST['body_from_html']); $body = $sendmail_tools->cleanHtml($_REQUEST['body_from_html']);
} else { } else {
$body = $_REQUEST['body_from_raw']; $body = $_REQUEST['body_from_raw'];
} }
//Status //Status
if ($_REQUEST['for'] == 'save') { if ($_REQUEST['for'] == 'save') {
$email_status = 'D'; $email_status = 'D';
} else if ($_REQUEST['for'] == 'send'){ } elseif ($_REQUEST['for'] == 'send') {
$email_status = 'W'; $email_status = 'W';
} }
//Query //Query
$stmt = $db->query( $stmt = $db->query(
"INSERT INTO " . EMAILS_TABLE . "(coll_id, res_id, user_id, to_list, cc_list, "INSERT INTO " . EMAILS_TABLE . "(coll_id, res_id, user_id, to_list, cc_list,
cci_list, email_object, email_body, is_res_master_attached, res_version_id_list, cci_list, email_object, email_body, is_res_master_attached, res_version_id_list,
res_attachment_id_list, res_version_att_id_list,note_id_list, is_html, email_status, creation_date, sender_email) res_attachment_id_list, res_version_att_id_list,note_id_list, is_html, email_status, creation_date, sender_email)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, ?)", VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, ?)",
array($collId, $identifier, $userId, $to, $cc, $cci, $object, $body, $res_master_attached, array($collId, $identifier, $userId, $to, $cc, $cci, $object, $body, $res_master_attached,
$version_list, $attachment_list, $attachment_version_list, $note_list, $isHtml, $email_status, $senderEmail) $version_list, $attachment_list, $attachment_version_list, $note_list, $isHtml, $email_status, $senderEmail)
); );
...@@ -292,9 +298,9 @@ switch ($mode) { ...@@ -292,9 +298,9 @@ switch ($mode) {
. $identifier . ' (' . $id . ') : "' . $request->cut_string($object, 254) .'"', . $identifier . ' (' . $id . ') : "' . $request->cut_string($object, 254) .'"',
$_SESSION['config']['databasetype'], 'sendmail' $_SESSION['config']['databasetype'], 'sendmail'
); );
} else if (isset($_REQUEST['origin']) && $_REQUEST['origin'] == "document") { } elseif (isset($_REQUEST['origin']) && $_REQUEST['origin'] == "document") {
$hist->add( $hist->add(
$view, $identifier, "UP", 'resup', _EMAIL_ADDED . _ON_DOC_NUM $view, $identifier, "UP", 'resup', _EMAIL_ADDED . _ON_DOC_NUM
. $identifier . ' (' . $id . ') : "' . $request->cut_string($object, 254) .'"', . $identifier . ' (' . $id . ') : "' . $request->cut_string($object, 254) .'"',
$_SESSION['config']['databasetype'], 'sendmail' $_SESSION['config']['databasetype'], 'sendmail'
); );
...@@ -308,7 +314,6 @@ switch ($mode) { ...@@ -308,7 +314,6 @@ switch ($mode) {
//Reload and show message //Reload and show message
$js = $list_origin."window.parent.top.$('main_info').innerHTML = '"._EMAIL_ADDED."';"; $js = $list_origin."window.parent.top.$('main_info').innerHTML = '"._EMAIL_ADDED."';";
} else { } else {
$status = 1; $status = 1;
} }
...@@ -319,11 +324,11 @@ switch ($mode) { ...@@ -319,11 +324,11 @@ switch ($mode) {
$status = 1; $status = 1;
} }
} else { } else {
$error = $request->wash_html(_EMAIL_OBJECT.' '._IS_EMPTY.'!','NONE'); $error = $request->wash_html(_EMAIL_OBJECT.' '._IS_EMPTY.'!', 'NONE');
$status = 1; $status = 1;
} }
} else { } else {
$error = $request->wash_html(_SEND_TO.' '._IS_EMPTY.'!','NONE'); $error = $request->wash_html(_SEND_TO.' '._IS_EMPTY.'!', 'NONE');
$status = 1; $status = 1;
} }
} }
...@@ -340,17 +345,17 @@ switch ($mode) { ...@@ -340,17 +345,17 @@ switch ($mode) {
} }
//Res ID //Res ID
if (empty($identifier)) { if (empty($identifier)) {
$error = $request->wash_html(_IDENTIFIER.' '._IS_EMPTY.'!','NONE'); $error = $request->wash_html(_IDENTIFIER.' '._IS_EMPTY.'!', 'NONE');
$status = 1; $status = 1;
} else if (!in_array($_REQUEST['sender_email'], array_keys($userEntitiesMails)) && $core_tools->test_service('use_mail_services', 'sendmail', false)) { } elseif (!in_array($_REQUEST['sender_email'], array_keys($userEntitiesMails)) && $core_tools->test_service('use_mail_services', 'sendmail', false)) {
$error = $request->wash_html(_INCORRECT_SENDER,'NONE'); $error = $request->wash_html(_INCORRECT_SENDER, 'NONE');
$status = 1; $status = 1;
} else { } else {
if ((isset($_SESSION['adresses']['to']) && count($_SESSION['adresses']['to']) > 0) || $_REQUEST['for'] == 'save') { if ((isset($_SESSION['adresses']['to']) && count($_SESSION['adresses']['to']) > 0) || $_REQUEST['for'] == 'save') {
if (!empty($_REQUEST['object']) || $_REQUEST['for'] == 'save') { if (!empty($_REQUEST['object']) || $_REQUEST['for'] == 'save') {
//Check adress for to //Check adress for to
if(!empty($_SESSION['adresses']['to'])){ if (!empty($_SESSION['adresses']['to'])) {
$to = join(',', $_SESSION['adresses']['to']); $to = join(',', $_SESSION['adresses']['to']);
$error = $sendmail_tools->CheckEmailAdress($to); $error = $sendmail_tools->CheckEmailAdress($to);
} }
...@@ -358,14 +363,14 @@ switch ($mode) { ...@@ -358,14 +363,14 @@ switch ($mode) {
if (empty($error)) { if (empty($error)) {
//Check adress for cc //Check adress for cc
(isset($_SESSION['adresses']['cc']) && count($_SESSION['adresses']['cc']) > 0)? (isset($_SESSION['adresses']['cc']) && count($_SESSION['adresses']['cc']) > 0)?
$cc = join(',', $_SESSION['adresses']['cc']) : $cc = ''; $cc = join(',', $_SESSION['adresses']['cc']) : $cc = '';
$error = $sendmail_tools->CheckEmailAdress($cc); $error = $sendmail_tools->CheckEmailAdress($cc);
if (empty($error)) { if (empty($error)) {
//Check adress for cci //Check adress for cci
(isset($_SESSION['adresses']['cci']) && count($_SESSION['adresses']['cci']) > 0)? (isset($_SESSION['adresses']['cci']) && count($_SESSION['adresses']['cci']) > 0)?
$cci = join(',', $_SESSION['adresses']['cci']) : $cci = ''; $cci = join(',', $_SESSION['adresses']['cci']) : $cci = '';
$error = $sendmail_tools->CheckEmailAdress($cci); $error = $sendmail_tools->CheckEmailAdress($cci);
...@@ -375,7 +380,7 @@ switch ($mode) { ...@@ -375,7 +380,7 @@ switch ($mode) {
$collId = $_REQUEST['coll_id']; $collId = $_REQUEST['coll_id'];
$object = $_REQUEST['object']; $object = $_REQUEST['object'];
$senderEmail = $_REQUEST['sender_email']; $senderEmail = $_REQUEST['sender_email'];
(isset($_REQUEST['join_file']) (isset($_REQUEST['join_file'])
&& count($_REQUEST['join_file']) > 0 && count($_REQUEST['join_file']) > 0
)? $res_master_attached = 'Y' : $res_master_attached = 'N'; )? $res_master_attached = 'Y' : $res_master_attached = 'N';
if (isset($_REQUEST['join_version']) && count($_REQUEST['join_version']) > 0) { if (isset($_REQUEST['join_version']) && count($_REQUEST['join_version']) > 0) {
...@@ -397,16 +402,16 @@ switch ($mode) { ...@@ -397,16 +402,16 @@ switch ($mode) {
if ($isHtml == 'Y') { if ($isHtml == 'Y') {
$body = $sendmail_tools->cleanHtml($_REQUEST['body_from_html']); $body = $sendmail_tools->cleanHtml($_REQUEST['body_from_html']);
} else { } else {
$body = $_REQUEST['body_from_raw']; $body = $_REQUEST['body_from_raw'];
} }
//Status //Status
if ($_REQUEST['for'] == 'save') { if ($_REQUEST['for'] == 'save') {
$email_status = 'D'; $email_status = 'D';
} else if ($_REQUEST['for'] == 'send'){ } elseif ($_REQUEST['for'] == 'send') {
$email_status = 'W'; $email_status = 'W';
} }
//Query //Query
$db->query( $db->query(
"UPDATE " . EMAILS_TABLE . " SET to_list = ?, cc_list = ?, cci_list = ?, email_object = ?, "UPDATE " . EMAILS_TABLE . " SET to_list = ?, cc_list = ?, cci_list = ?, email_object = ?,
email_body = ?, is_res_master_attached = ?, res_version_id_list = ?, email_body = ?, is_res_master_attached = ?, res_version_id_list = ?,
...@@ -414,7 +419,7 @@ switch ($mode) { ...@@ -414,7 +419,7 @@ switch ($mode) {
is_html = ?, email_status = ?, sender_email = ?, send_date = ? where email_id = ? " is_html = ?, email_status = ?, sender_email = ?, send_date = ? where email_id = ? "
." and res_id = ? and user_id = ?", ." and res_id = ? and user_id = ?",
array($to, $cc, $cci, $object, $body, $res_master_attached, $version_list, $attachment_list, $attachment_version_list, $note_list, $isHtml, array($to, $cc, $cci, $object, $body, $res_master_attached, $version_list, $attachment_list, $attachment_version_list, $note_list, $isHtml,
$email_status, $senderEmail, NULL, $id, $identifier, $userId ) $email_status, $senderEmail, null, $id, $identifier, $userId )
); );
//History //History
...@@ -426,9 +431,9 @@ switch ($mode) { ...@@ -426,9 +431,9 @@ switch ($mode) {
. $identifier . ' (' . $id . ') : "' . $request->cut_string($object, 254) .'"', . $identifier . ' (' . $id . ') : "' . $request->cut_string($object, 254) .'"',
$_SESSION['config']['databasetype'], 'sendmail' $_SESSION['config']['databasetype'], 'sendmail'
); );
} else if (isset($_REQUEST['origin']) && $_REQUEST['origin'] == "document") { } elseif (isset($_REQUEST['origin']) && $_REQUEST['origin'] == "document") {
$hist->add( $hist->add(
$view, $identifier, "UP", 'resup', _EMAIL_UPDATED . _ON_DOC_NUM $view, $identifier, "UP", 'resup', _EMAIL_UPDATED . _ON_DOC_NUM
. $identifier . ' (' . $id . ') : "' . $request->cut_string($object, 254) .'"', . $identifier . ' (' . $id . ') : "' . $request->cut_string($object, 254) .'"',
$_SESSION['config']['databasetype'], 'sendmail' $_SESSION['config']['databasetype'], 'sendmail'
); );
...@@ -441,7 +446,7 @@ switch ($mode) { ...@@ -441,7 +446,7 @@ switch ($mode) {
} }
//Reload and show message //Reload and show message
$js = $list_origin."window.parent.top.$('main_info').innerHTML = '"._EMAIL_UPDATED."';"; $js = $list_origin."window.parent.top.$('main_info').innerHTML = '"._EMAIL_UPDATED."';";
} else { } else {
$status = 1; $status = 1;
} }
...@@ -452,20 +457,19 @@ switch ($mode) { ...@@ -452,20 +457,19 @@ switch ($mode) {
$status = 1; $status = 1;
} }
} else { } else {
$error = $request->wash_html(_EMAIL_OBJECT.' '._IS_EMPTY.'!','NONE'); $error = $request->wash_html(_EMAIL_OBJECT.' '._IS_EMPTY.'!', 'NONE');
$status = 1; $status = 1;
} }
} else { } else {
$error = $request->wash_html(_SEND_TO.' '._IS_EMPTY.'!','NONE'); $error = $request->wash_html(_SEND_TO.' '._IS_EMPTY.'!', 'NONE');
$status = 1; $status = 1;
} }
} }
} else { } else {
$error = $request->wash_html(_ID.' '._IS_EMPTY.'!','NONE'); $error = $request->wash_html(_ID.' '._IS_EMPTY.'!', 'NONE');
$status = 1; $status = 1;
//Close the modal //Close the modal
$js = "window.parent.destroyModal('form_email');"; $js = "window.parent.destroyModal('form_email');";
} }
break; break;
...@@ -480,7 +484,7 @@ switch ($mode) { ...@@ -480,7 +484,7 @@ switch ($mode) {
$request->query("delete from " . EMAILS_TABLE . " where email_id = " . $id); $request->query("delete from " . EMAILS_TABLE . " where email_id = " . $id);
//Delete email from stack too ??? //Delete email from stack too ???
$request->query("delete from " . _NOTIF_EVENT_STACK_TABLE_NAME $request->query("delete from " . _NOTIF_EVENT_STACK_TABLE_NAME
. " where table_name = '" . EMAILS_TABLE . "' and record_id = '" . $id . "'"); . " where table_name = '" . EMAILS_TABLE . "' and record_id = '" . $id . "'");
//History //History
...@@ -492,16 +496,16 @@ switch ($mode) { ...@@ -492,16 +496,16 @@ switch ($mode) {
. $identifier . ' (' . $id . ') : "' . $request->cut_string($object, 254) .'"', . $identifier . ' (' . $id . ') : "' . $request->cut_string($object, 254) .'"',
$_SESSION['config']['databasetype'], 'sendmail' $_SESSION['config']['databasetype'], 'sendmail'
); );
} else if (isset($_REQUEST['origin']) && $_REQUEST['origin'] == "document") { } elseif (isset($_REQUEST['origin']) && $_REQUEST['origin'] == "document") {
$hist->add( $hist->add(
$view, $identifier, "UP", 'resup', _EMAIL_REMOVED . _ON_DOC_NUM $view, $identifier, "UP", 'resup', _EMAIL_REMOVED . _ON_DOC_NUM
. $identifier . ' (' . $id . ') : "' . $request->cut_string($object, 254) .'"', . $identifier . ' (' . $id . ') : "' . $request->cut_string($object, 254) .'"',
$_SESSION['config']['databasetype'], 'sendmail' $_SESSION['config']['databasetype'], 'sendmail'
); );
} }
$hist->add( $hist->add(
EMAILS_TABLE, $id, "DEL", 'maildel', _EMAIL_REMOVED . ' (' . $id . ') : "' EMAILS_TABLE, $id, "DEL", 'maildel', _EMAIL_REMOVED . ' (' . $id . ') : "'
. $request->cut_string($object, 254) .'"', . $request->cut_string($object, 254) .'"',
$_SESSION['config']['databasetype'], 'sendmail' $_SESSION['config']['databasetype'], 'sendmail'
); );
...@@ -509,12 +513,11 @@ switch ($mode) { ...@@ -509,12 +513,11 @@ switch ($mode) {
//Reload and show message //Reload and show message
$js = $list_origin."window.parent.top.$('main_info').innerHTML = '"._EMAIL_REMOVED."';"; $js = $list_origin."window.parent.top.$('main_info').innerHTML = '"._EMAIL_REMOVED."';";
} else { } else {
$error = $request->wash_html(_ID.' '._IS_EMPTY.'!','NONE'); $error = $request->wash_html(_ID.' '._IS_EMPTY.'!', 'NONE');
$status = 1; $status = 1;
//Close the modal //Close the modal
$js = "window.parent.destroyModal('form_email');"; $js = "window.parent.destroyModal('form_email');";
} }
break; break;
case 'adress': case 'adress':
...@@ -523,26 +526,29 @@ switch ($mode) { ...@@ -523,26 +526,29 @@ switch ($mode) {
//Clean up email //Clean up email
$email = trim($_REQUEST['email']); $email = trim($_REQUEST['email']);
//Reset session adresses if necessary //Reset session adresses if necessary
if (!isset($_SESSION['adresses'][$_REQUEST['field']])) $_SESSION['adresses'][$_REQUEST['field']] = array(); if (!isset($_SESSION['adresses'][$_REQUEST['field']])) {
$_SESSION['adresses'][$_REQUEST['field']] = array();
}
//For ADD //For ADD
if ($_REQUEST['for'] == 'add') { if ($_REQUEST['for'] == 'add') {
array_push($_SESSION['adresses'][$_REQUEST['field']], $email); array_push($_SESSION['adresses'][$_REQUEST['field']], $email);
//For DEL //For DEL
} else if ($_REQUEST['for'] == 'del') { } elseif ($_REQUEST['for'] == 'del') {
//unset adress in array //unset adress in array
unset($_SESSION['adresses'][$_REQUEST['field']][$_REQUEST['index']]); unset($_SESSION['adresses'][$_REQUEST['field']][$_REQUEST['index']]);
//If no adresse for field, unset the entire sub-array //If no adresse for field, unset the entire sub-array
if (count($_SESSION['adresses'][$_REQUEST['field']]) == 0) if (count($_SESSION['adresses'][$_REQUEST['field']]) == 0) {
unset($_SESSION['adresses'][$_REQUEST['field']]); unset($_SESSION['adresses'][$_REQUEST['field']]);
}
} }
//Get content //Get content
$content = $sendmail_tools->updateAdressInputField($path_to_script, $_SESSION['adresses'], $_REQUEST['field']); $content = $sendmail_tools->updateAdressInputField($path_to_script, $_SESSION['adresses'], $_REQUEST['field']);
} else { } else {
$error = $request->wash_html(_EMAIL.' '._IS_EMPTY.'!','NONE'); $error = $request->wash_html(_EMAIL.' '._IS_EMPTY.'!', 'NONE');
$status = 1; $status = 1;
} }
} else { } else {
$error = $request->wash_html(_UNKNOW_ERROR.'!','NONE'); $error = $request->wash_html(_UNKNOW_ERROR.'!', 'NONE');
$status = 1; $status = 1;
} }
break; break;
...@@ -550,28 +556,30 @@ switch ($mode) { ...@@ -550,28 +556,30 @@ switch ($mode) {
if (isset($_REQUEST['for']) && isset($_REQUEST['field']) && isset($_REQUEST['contactAddress'])) { if (isset($_REQUEST['for']) && isset($_REQUEST['field']) && isset($_REQUEST['contactAddress'])) {
if (isset($_REQUEST['contactAddress']) && !empty($_REQUEST['contactAddress'])) { if (isset($_REQUEST['contactAddress']) && !empty($_REQUEST['contactAddress'])) {
$contactAddress = trim($_REQUEST['contactAddress']); $contactAddress = trim($_REQUEST['contactAddress']);
if (!isset($_SESSION['adresses'][$_REQUEST['field']])) $_SESSION['adresses'][$_REQUEST['field']] = array(); if (!isset($_SESSION['adresses'][$_REQUEST['field']])) {
$_SESSION['adresses'][$_REQUEST['field']] = array();
}
if ($_REQUEST['for'] == 'add') { if ($_REQUEST['for'] == 'add') {
$contactLabel = \Contact\models\ContactModel::getContactFullLabel(['addressId' => $contactAddress]); $contactLabel = \Contact\models\ContactModel::getContactFullLabel(['addressId' => $contactAddress]);
$contactInfo = \Contact\models\ContactModel::getFullAddressById(['addressId' => $contactAddress]); $contactInfo = \Contact\models\ContactModel::getFullAddressById(['addressId' => $contactAddress]);
$contactCommunication = \Contact\models\ContactModel::getContactCommunication(['contactId' => $contactInfo[0]['contact_id']]); $contactCommunication = \Contact\models\ContactModel::getContactCommunication(['contactId' => $contactInfo[0]['contact_id']]);
$_SESSION['adresses'][$_REQUEST['field']][$contactAddress] = $contactLabel.'. ('._COMMUNICATION_TYPE.' : '.$contactCommunication['value'].'))'; $_SESSION['adresses'][$_REQUEST['field']][$contactAddress] = $contactLabel.'. ('._COMMUNICATION_TYPE.' : '.$contactCommunication['value'].'))';
} elseif ($_REQUEST['for'] == 'del') {
} else if ($_REQUEST['for'] == 'del') {
unset($_SESSION['adresses'][$_REQUEST['field']][$_REQUEST['index']]); unset($_SESSION['adresses'][$_REQUEST['field']][$_REQUEST['index']]);
//If no adresse for field, unset the entire sub-array //If no adresse for field, unset the entire sub-array
if (count($_SESSION['adresses'][$_REQUEST['field']]) == 0) if (count($_SESSION['adresses'][$_REQUEST['field']]) == 0) {
unset($_SESSION['adresses'][$_REQUEST['field']]); unset($_SESSION['adresses'][$_REQUEST['field']]);
}
} }
$content = $sendmail_tools->updateContactInputField($path_to_script, $_SESSION['adresses'], $_REQUEST['field']); $content = $sendmail_tools->updateContactInputField($path_to_script, $_SESSION['adresses'], $_REQUEST['field']);
} else { } else {
$error = $request->wash_html(_EMAIL.' '._IS_EMPTY.'!','NONE'); $error = $request->wash_html(_EMAIL.' '._IS_EMPTY.'!', 'NONE');
$status = 1; $status = 1;
} }
} else { } else {
$error = $request->wash_html(_UNKNOW_ERROR.'!','NONE'); $error = $request->wash_html(_UNKNOW_ERROR.'!', 'NONE');
$status = 1; $status = 1;
} }
break; break;
...@@ -580,21 +588,22 @@ switch ($mode) { ...@@ -580,21 +588,22 @@ switch ($mode) {
$RequestSeda = new RequestSeda(); $RequestSeda = new RequestSeda();
$messageExchangeData = $RequestSeda->getMessageByIdentifierAndResId(['message_id' => $_GET['id'], 'res_id_master' => $_GET['identifier']]); $messageExchangeData = $RequestSeda->getMessageByIdentifierAndResId(['message_id' => $_GET['id'], 'res_id_master' => $_GET['identifier']]);
$docserver = \Core\Models\DocserverModel::getById(['docserver_id' => $messageExchangeData->docserver_id]); $docserver = \Docserver\models\DocserverModel::getById(['id' => $messageExchangeData->docserver_id]);
$docserverType = \Core\Models\DocserverTypeModel::getById(['docserver_type_id' => $docserver[0]['docserver_type_id']]); $docserverType = \Docserver\models\DocserverTypeModel::getById(['id' => $docserver[0]['docserver_type_id']]);
$pathDirectory = str_replace('#', DIRECTORY_SEPARATOR, $messageExchangeData->path); $pathDirectory = str_replace('#', DIRECTORY_SEPARATOR, $messageExchangeData->path);
$filePath = $docserver[0]['path_template'] . $pathDirectory . $messageExchangeData->filename; $filePath = $docserver[0]['path_template'] . $pathDirectory . $messageExchangeData->filename;
$fingerprint = \Core\Controllers\DocserverToolsController::doFingerprint([ $fingerprint = \SrcCore\controllers\StoreController::getFingerPrint([
'path' => $filePath, 'filePath' => $filePath,
'fingerprintMode' => $docserverType[0]['fingerprint_mode'], 'mode' => $docserverType[0]['fingerprint_mode'],
]); ]);
if($fingerprint['fingerprint'] != $messageExchangeData->fingerprint){ if ($fingerprint['fingerprint'] != $messageExchangeData->fingerprint) {
echo _PB_WITH_FINGERPRINT_OF_DOCUMENT;exit; echo _PB_WITH_FINGERPRINT_OF_DOCUMENT;
exit;
} }
if(file_exists($filePath)){ if (file_exists($filePath)) {
header('Pragma: public'); header('Pragma: public');
header('Expires: 0'); header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
...@@ -611,5 +620,4 @@ switch ($mode) { ...@@ -611,5 +620,4 @@ switch ($mode) {
exit(); exit();
} }
echo "{status : " . $status . ", content : '" . addslashes(_parse($content)) . "', error : '" . addslashes(_parse_error($error)) . "', exec_js : '".addslashes($js)."'}"; echo "{status : " . $status . ", content : '" . addslashes(_parse($content)) . "', error : '" . addslashes(_parse_error($error)) . "', exec_js : '".addslashes($js)."'}";
exit (); exit();
?>
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
<file>core/Test/ResControllerTest.php</file> <file>core/Test/ResControllerTest.php</file>
<file>core/Test/StatusControllerTest.php</file> <file>core/Test/StatusControllerTest.php</file>
<file>core/Test/UserControllerTest.php</file> <file>core/Test/UserControllerTest.php</file>
<!-- <file>core/Test/GroupControllerTest.php</file> -->
<file>modules/convert/Test/ProcessConvertTest.php</file> <file>modules/convert/Test/ProcessConvertTest.php</file>
<file>modules/convert/Test/ProcessFulltextTest.php</file> <file>modules/convert/Test/ProcessFulltextTest.php</file>
<file>modules/convert/Test/ProcessManageConvertTest.php</file> <file>modules/convert/Test/ProcessManageConvertTest.php</file>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment