From f07f14fb6a3e473db95f32fedf88ffaadf9776bf Mon Sep 17 00:00:00 2001 From: "florian.azizian" <florian.azizian@maarch.org> Date: Tue, 13 Mar 2018 14:49:00 +0100 Subject: [PATCH] FEAT #202 fusion M2M sendmail --- .../sendmail/batch/load_process_emails.php | 9 + modules/sendmail/batch/process_emails.php | 46 +- .../class/class_modules_tools_Abstract.php | 22 + modules/sendmail/js/functions.js | 63 ++- modules/sendmail/lang/en.php | 49 ++ modules/sendmail/lang/fr.php | 52 +- modules/sendmail/mail_form.php | 474 ++++++++++++------ modules/sendmail/sendmail.php | 22 +- modules/sendmail/sendmail_ajax_content.php | 319 +++++++----- modules/sendmail/xml/IVS/validation_rules.xml | 10 +- modules/sendmail/xml/menu.xml | 11 +- modules/sendmail/xml/services.xml | 10 +- 12 files changed, 797 insertions(+), 290 deletions(-) diff --git a/modules/sendmail/batch/load_process_emails.php b/modules/sendmail/batch/load_process_emails.php index c821bea6b12..159d4881f39 100755 --- a/modules/sendmail/batch/load_process_emails.php +++ b/modules/sendmail/batch/load_process_emails.php @@ -205,6 +205,15 @@ try { $GLOBALS['maarchDirectory'] . "modules" . DIRECTORY_SEPARATOR . "entities" . DIRECTORY_SEPARATOR . "class". DIRECTORY_SEPARATOR . "class_manage_entities.php" ); + Bt_myInclude( + $GLOBALS['maarchDirectory'] . "core" . DIRECTORY_SEPARATOR . "Models" . DIRECTORY_SEPARATOR . "DocserverModel.php" + ); + Bt_myInclude( + $GLOBALS['maarchDirectory'] . "core" . DIRECTORY_SEPARATOR . "Models" . DIRECTORY_SEPARATOR . "DocserverTypeModel.php" + ); + Bt_myInclude( + $GLOBALS['maarchDirectory'] . "core" . DIRECTORY_SEPARATOR . "Controllers" . DIRECTORY_SEPARATOR . "DocserverToolsController.php" + ); Bt_myInclude( $GLOBALS['maarchDirectory'] . $path_to_mailer ); diff --git a/modules/sendmail/batch/process_emails.php b/modules/sendmail/batch/process_emails.php index 77e6ab77d50..6af7a703373 100755 --- a/modules/sendmail/batch/process_emails.php +++ b/modules/sendmail/batch/process_emails.php @@ -141,6 +141,42 @@ while ($state <> 'END') { $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 { //Res master if ($email->is_res_master_attached == 'Y') { $GLOBALS['logger']->write("set attachment on res master : " . $email->res_id, 'INFO'); @@ -242,7 +278,7 @@ while ($state <> 'END') { $GLOBALS['mailer']->addAttachment($file_content, $noteFile['filename'], $noteFile['mime_type']); } } - + } //Now send the mail $GLOBALS['logger']->write("sending e-mail ...", 'INFO'); @@ -302,6 +338,14 @@ while ($state <> 'END') { . ", email_status = ? " . " WHERE email_id = ? "; $stmt = Bt_doQuery($GLOBALS['db'], $query, array($exec_result, $email->email_id)); + + if ($email->message_exchange_id) { + //Update message table + $query = "UPDATE message_exchange" + . " SET status = ? " + . " WHERE message_id = ? "; + $stmt = Bt_doQuery($GLOBALS['db'], $query, array($exec_result, $email->message_exchange_id)); + } $currentEmail++; $state = 'SEND_AN_EMAIL'; } else { diff --git a/modules/sendmail/class/class_modules_tools_Abstract.php b/modules/sendmail/class/class_modules_tools_Abstract.php index 803623d8c78..faa8ec229d5 100755 --- a/modules/sendmail/class/class_modules_tools_Abstract.php +++ b/modules/sendmail/class/class_modules_tools_Abstract.php @@ -391,6 +391,28 @@ abstract class SendmailAbstract extends Database return $content; } + public function updateContactInputField($ajaxPath, $adressArray, $inputField, $readOnly=false) + { + $content = '<div id="loading_'.$inputField.'" style="display:none;"><i class="fa fa-spinner fa-spin" title="loading..."></i></div>'; + //Get info from session array and display tag + if (isset($adressArray[$inputField]) && count($adressArray[$inputField]) > 0) { + foreach ($adressArray[$inputField] as $key => $adress) { + if (!empty($adress)) { + $content .= '<div class="email_element" id="'.$key.'_'.$adress.'">'.$adress; + if ($readOnly === false) { + $content .= ' <div class="email_delete_button" id="'.$key.'"' + . 'onclick="updateDestUser(\''.$ajaxPath + .'&mode=destUser\', \'del\', this.id, \'' + .$inputField.'\', this.id);" alt="'._DELETE.'" title="' + ._DELETE.'">x</div>'; + } + $content .= '</div>'; + } + } + } + return $content; + } + public function getResource($collectionArray, $coll_id, $res_id) { $viewResourceArr = array(); diff --git a/modules/sendmail/js/functions.js b/modules/sendmail/js/functions.js index 777c3b0f310..d7adda6ec00 100755 --- a/modules/sendmail/js/functions.js +++ b/modules/sendmail/js/functions.js @@ -11,6 +11,19 @@ var addEmailAdress = function (idField, idList, theUrlToListScript, paramNameSrv }); }; + var addDestUser = function (idField, idList, theUrlToListScript, paramNameSrv, minCharsSrv) { + new Ajax.Autocompleter( + idField, + idList, + theUrlToListScript, + { + paramName: paramNameSrv, + minChars: minCharsSrv, + tokens: ',', + afterUpdateElement:extractDestUser + }); + }; + function addTemplateToEmail(templateMails, path){ new Ajax.Request(path, @@ -128,11 +141,38 @@ function updateAdress(path, action, adress, target, array_index, email_format_te } } +function updateDestUser(path, action, adress, target, array_index) { + + new Ajax.Request(path, + { + method:'post', + parameters: { url : path, + 'for': action, + contactAddress: adress, + field: target, + index: array_index + }, + onLoading: function(answer) { + $('loading_' + target).style.display='inline'; + }, + onSuccess: function(answer) { + eval("response = "+answer.responseText); + if(response.status == 0){ + $(target).innerHTML = response.content; + if (action == 'add') {$('user').value = '';} + } else { + alert(response.error); + eval(response.exec_js); + } + } + }); +} + function validEmailForm(path, form_id) { var attachments = $j("#joined_files input.check"); - if (attachments.length > 0 && path.includes("for=send")) { + if (attachments.length > 0 && (path.includes("for=send") || path.includes("formContent=messageExchange"))) { var hasOneChecked = false; for (var i = 0; i < attachments.length; i++) { if (attachments[i].checked == true) { @@ -142,13 +182,23 @@ function validEmailForm(path, form_id) { } if (!hasOneChecked) { - var cfm = confirm('Aucune pièce jointe sélectionnée. Voulez-vous quand même envoyer le mail ?'); - if (!cfm) { + if(path.includes("formContent=messageExchange")){ + alert('Aucune pièce jointe sélectionnée'); return; + } else if(path.includes("for=send")){ + var cfm = confirm('Aucune pièce jointe sélectionnée. Voulez-vous quand même envoyer le mail ?'); + if (!cfm) { + return; + } } } } + if (typeof($j('input[name=main_exchange_doc]:checked', '#formEmail').val()) === 'undefined' && path.includes("formContent=messageExchange")) { + alert('Aucun document principal sélectionné'); + return; + } + tinyMCE.triggerSave(); new Ajax.Request(path, { @@ -209,6 +259,11 @@ function extractEmailAdress(field, item) { field.value = fullAdress.match(/\(([^)]+)\)/)[1]; } +function extractDestUser(field, item) { + $j('#user').val(item.id); + $j('#valid').click(); +} + function validateEmail(email) { var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(email); @@ -263,4 +318,4 @@ function clickAttachmentsInput(id){ } function clickAttachmentsNotes(id){ $("note_"+id).click(); -} \ No newline at end of file +} diff --git a/modules/sendmail/lang/en.php b/modules/sendmail/lang/en.php index 8a8d6221ec4..984523d6298 100755 --- a/modules/sendmail/lang/en.php +++ b/modules/sendmail/lang/en.php @@ -81,6 +81,20 @@ if (!defined("_EMAIL_NOT_EXIST")) //ADD if (!defined("_NEW_EMAIL")) define("_NEW_EMAIL","New mail"); +if (!defined("_NEW_NUMERIC_PACKAGE")) + define("_NEW_NUMERIC_PACKAGE","New numeric package"); +if (!defined("_NUMERIC_PACKAGE_ADDED")) + define("_NUMERIC_PACKAGE_ADDED","Numeric package added"); +if (!defined("_NUMERIC_PACKAGE_IMPORTED")) + define("_NUMERIC_PACKAGE_IMPORTED","Numeric package imported"); +if (!defined("_NUMERIC_PACKAGE_SENT")) + define("_NUMERIC_PACKAGE_SENT","Numeric package sent"); +if (!defined("_NUMERIC_PACKAGE")) + define("_NUMERIC_PACKAGE","Numeric package"); +if (!defined("_NO_COMMUNICATION_MODE")) + define("_NO_COMMUNICATION_MODE","No communication mode"); +if (!defined("_NOTHING")) + define("_NOTHING","Aucun"); if (!defined("_CREATE_EMAIL")) define("_CREATE_EMAIL", "Create"); if (!defined("_EMAIL_ADDED")) @@ -137,3 +151,38 @@ if (!defined("_USE_MAIL_SERVICES_DESC")) define("_USE_MAIL_SERVICES_DESC", "Use emails services as sender"); if (!defined("_INCORRECT_SENDER")) define("_INCORRECT_SENDER", "Incorrect sender"); + +if (!defined("_OPERATION_DATE")) + define("_OPERATION_DATE", "Operation date"); +if (!defined("_RECEPTION_DATE")) + define("_RECEPTION_DATE", "Reception date"); + +if (!defined("_SENDS_FAIL")) + define("_SENDS_FAIL", "Sends fail"); +if (!defined("_WRONG_FILE_TYPE_M2M")) + define("_WRONG_FILE_TYPE_M2M", "Only ZIP file allowed"); +if (!defined("_ERROR_RECEIVE_FAIL")) + define("_ERROR_RECEIVE_FAIL", "Error receive zip fail"); + +if (!defined("_ERROR_CONTACT_UNKNOW")) + define("_ERROR_CONTACT_UNKNOW", "Contact unknow."); +if (!defined("_NO_RECIPIENT")) + define("_NO_RECIPIENT", "No recipient"); +if (!defined("_NO_SENDER")) + define("_NO_SENDER", "No sender"); +if (!defined("_SIMPLE_DOWNLOAD")) + define("_SIMPLE_DOWNLOAD", "Download"); +if (!defined("_MORE_INFORMATIONS")) + define("_MORE_INFORMATIONS", "Informations about the transfer"); +if (!defined("_REPLY_RESPONSE_SENT")) + define("_REPLY_RESPONSE_SENT", "Reply sent on"); +if (!defined("_M2M_ARCHIVETRANSFER")) + define("_M2M_ARCHIVETRANSFER", "Archive transfer"); +if (!defined("_M2M_ARCHIVETRANSFERREPLYSENT")) + define("_M2M_ARCHIVETRANSFERREPLYSENT", "Archive transfer reply"); +if (!defined("_M2M_ACTION_DONE")) + define("_M2M_ACTION_DONE", "done by"); +if (!defined("_M2M_ENTITY_DESTINATION")) + define("_M2M_ENTITY_DESTINATION", "Mail is in the department"); +if (!defined("_M2M_FOLLOWUP_REQUEST")) + define("_M2M_FOLLOWUP_REQUEST", "Follow-up of the request"); diff --git a/modules/sendmail/lang/fr.php b/modules/sendmail/lang/fr.php index 4c817beced2..bef1e3b4edd 100755 --- a/modules/sendmail/lang/fr.php +++ b/modules/sendmail/lang/fr.php @@ -28,7 +28,7 @@ if (!defined("_EMAIL_LIST")) if (!defined("_EMAIL_LIST_DESC")) define("_EMAIL_LIST_DESC", "Liste des courriels"); if (!defined("_SENDED_EMAILS")) - define("_SENDED_EMAILS", "Courriels"); + define("_SENDED_EMAILS", "Eléments envoyés"); //STATUS if (!defined("_EMAIL_DRAFT")) @@ -82,6 +82,20 @@ if (!defined("_EMAIL_NOT_EXIST")) //ADD if (!defined("_NEW_EMAIL")) define("_NEW_EMAIL","Nouveau message"); +if (!defined("_NEW_NUMERIC_PACKAGE")) + define("_NEW_NUMERIC_PACKAGE","Nouveau pli numérique"); +if (!defined("_NUMERIC_PACKAGE_ADDED")) + define("_NUMERIC_PACKAGE_ADDED","Pli numérique ajouté"); +if (!defined("_NUMERIC_PACKAGE_IMPORTED")) + define("_NUMERIC_PACKAGE_IMPORTED","Pli numérique importé"); +if (!defined("_NUMERIC_PACKAGE_SENT")) + define("_NUMERIC_PACKAGE_SENT","Plis numériques envoyés"); +if (!defined("_NUMERIC_PACKAGE")) + define("_NUMERIC_PACKAGE","Pli numérique"); +if (!defined("_NO_COMMUNICATION_MODE")) + define("_NO_COMMUNICATION_MODE","Aucun moyen de communication"); +if (!defined("_NOTHING")) + define("_NOTHING","Aucun"); if (!defined("_CREATE_EMAIL")) define("_CREATE_EMAIL", "Créer"); if (!defined("_EMAIL_ADDED")) @@ -127,7 +141,7 @@ if (!defined("_EMAIL_REMOVED")) if (!defined("_Label_ADD_TEMPLATE_MAIL")) - define("_Label_ADD_TEMPLATE_MAIL", "Modèle : "); + define("_Label_ADD_TEMPLATE_MAIL", "Modèle d'accompagnement : "); if (!defined("_ADD_TEMPLATE_MAIL")) define("_ADD_TEMPLATE_MAIL", "Sélectionnez le modèle désiré"); @@ -139,3 +153,37 @@ if (!defined("_USE_MAIL_SERVICES_DESC")) define("_USE_MAIL_SERVICES_DESC", "Utiliser les courriels de ses services en tant qu'expéditeur"); if (!defined("_INCORRECT_SENDER")) define("_INCORRECT_SENDER", "Expéditeur inccorect"); +if (!defined("_OPERATION_DATE")) + define("_OPERATION_DATE", "Date de prise en charge"); +if (!defined("_RECEPTION_DATE")) + define("_RECEPTION_DATE", "Date de réception"); + +if (!defined("_SENDS_FAIL")) + define("_SENDS_FAIL", "L'envoi a échoué"); +if (!defined("_WRONG_FILE_TYPE_M2M")) + define("_WRONG_FILE_TYPE_M2M", "Seuls les fichiers ZIP sont acceptés"); +if (!defined("_ERROR_RECEIVE_FAIL")) + define("_ERROR_RECEIVE_FAIL", "Erreur lors de l'envoi du zip."); + +if (!defined("_ERROR_CONTACT_UNKNOW")) + define("_ERROR_CONTACT_UNKNOW", "Contact inconnu."); +if (!defined("_NO_RECIPIENT")) + define("_NO_RECIPIENT", "Aucun destinataire"); +if (!defined("_NO_SENDER")) + define("_NO_SENDER", "Aucun expéditeur"); +if (!defined("_SIMPLE_DOWNLOAD")) + define("_SIMPLE_DOWNLOAD", "Télécharger"); +if (!defined("_MORE_INFORMATIONS")) + define("_MORE_INFORMATIONS", "Informations sur le transfert"); +if (!defined("_REPLY_RESPONSE_SENT")) + define("_REPLY_RESPONSE_SENT", "Accusé de prise en charge envoyé le"); +if (!defined("_M2M_ARCHIVETRANSFER")) + define("_M2M_ARCHIVETRANSFER", "Pli numérique"); +if (!defined("_M2M_ARCHIVETRANSFERREPLYSENT")) + define("_M2M_ARCHIVETRANSFERREPLYSENT", "Réponse envoyée"); +if (!defined("_M2M_ACTION_DONE")) + define("_M2M_ACTION_DONE", "actionné par"); +if (!defined("_M2M_ENTITY_DESTINATION")) + define("_M2M_ENTITY_DESTINATION", "Le courrier est dans le service"); +if (!defined("_M2M_FOLLOWUP_REQUEST")) + define("_M2M_FOLLOWUP_REQUEST", "Suivi de la demande"); diff --git a/modules/sendmail/mail_form.php b/modules/sendmail/mail_form.php index de3b58502f6..66cd65d4388 100755 --- a/modules/sendmail/mail_form.php +++ b/modules/sendmail/mail_form.php @@ -42,7 +42,9 @@ require_once 'modules/sendmail/sendmail_tables.php'; require_once "modules" . DIRECTORY_SEPARATOR . "sendmail" . DIRECTORY_SEPARATOR . "class" . DIRECTORY_SEPARATOR . "class_modules_tools.php"; require_once 'modules/sendmail/class/class_email_signatures.php'; - +require_once 'apps/maarch_entreprise/Models/ContactsModel.php'; +require_once 'modules/sendmail/Controllers/ReadMessageExchangeController.php'; + $core_tools = new core_tools(); $request = new request(); $sec = new security(); @@ -84,17 +86,22 @@ if (isset($_REQUEST['what']) && !empty($_REQUEST['what'])) $parameters .= '&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['formContent']) && !empty($_REQUEST['formContent'])) { + $formContent = $_GET['formContent']; +} else { + $formContent = 'mail'; +} + //Keep the origin $origin = ''; if (isset($_REQUEST['origin']) && !empty($_REQUEST['origin'])) { - // $origin = $_REQUEST['origin']; } //Path to actual script $path_to_script = $_SESSION['config']['businessappurl'] ."index.php?display=true&module=sendmail&page=sendmail_ajax_content&identifier=" - .$identifier."&origin=".$origin.$parameters; + .$identifier."&origin=".$origin."&formContent=".$formContent.$parameters; $core_tools->load_lang(); $core_tools->load_html(); @@ -121,66 +128,104 @@ $userTemplates = \SrcCore\models\DatabaseModel::select(['select' => ['t.templa //ADD if ($mode == 'add') { - $content .= '<div>'; + $content .= '<div style="padding: 10px;">'; $content .= '<form name="formEmail" id="formEmail" method="post" action="#">'; $content .= '<input type="hidden" value="'.$identifier.'" name="identifier" id="identifier">'; - $content .= '<input type="hidden" value="Y" name="is_html" id="is_html">'; - $content .= '<table border="0" align="left" width="100%" cellspacing="5">'; + if($formContent == 'messageExchange'){ + $content .= '<input type="hidden" value="N" name="is_html" id="is_html">'; + } else { + $content .= '<input type="hidden" value="Y" name="is_html" id="is_html">'; + } + $content .= '<input type="hidden" value="'.$_GET['formContent'].'" name="formContent" id="formContent">'; + $content .= '<table border="0" align="left" width="100%" cellspacing="5" '; + if($formContent == 'messageExchange'){ + $content .= 'style="margin-left: -30px;" '; + } + $content .= '>'; $content .= '<tr>'; $content .= '<td align="right" nowrap width="10%"><b>'.ucfirst(_FROM_SHORT).' </b></td><td>'; + $content .='<select name="sender_email" id="sender_email">'; $userEntitiesMails = array(); - if ($core_tools->test_service('use_mail_services', 'sendmail', false)) { - $userEntitiesMails = $sendmail_tools->getAttachedEntitiesMails($_SESSION['user']['UserId']); - } + if($formContent != 'messageExchange'){ + if ($core_tools->test_service('use_mail_services', 'sendmail', false)) { + $userEntitiesMails = $sendmail_tools->getAttachedEntitiesMails($_SESSION['user']['UserId']); + } - $content .='<select name="sender_email" id="sender_email"> - <option value="'.$_SESSION['user']['Mail'].'" '; - if(empty($userEntitiesMails)){ - $content .= 'selected="selected"'; - } - $content .='>'.functions::xssafe($_SESSION['user']['FirstName']) . ' ' . functions::xssafe($_SESSION['user']['LastName']) . ' (' . $_SESSION['user']['Mail'] . ')</option>'; - foreach ($userEntitiesMails as $key => $value) { - $primaryentity = explode(',', $key); - if($primaryentity[0] == $_SESSION['user']['primaryentity']['id']){ - $content .= '<option value="'.$key.'" selected="selected" >' . $value . '</option>'; - }else{ - $content .= '<option value="'.$key.'" >' . $value . '</option>'; + $content .='<option value="'.$_SESSION['user']['Mail'].'" '; + if(empty($userEntitiesMails)){ + $content .= 'selected="selected"'; + } + $content .='>'.functions::xssafe($_SESSION['user']['FirstName']) . ' ' . functions::xssafe($_SESSION['user']['LastName']) . ' (' . $_SESSION['user']['Mail'] . ')</option>'; + foreach ($userEntitiesMails as $key => $value) { + $primaryentity = explode(',', $key); + if($primaryentity[0] == $_SESSION['user']['primaryentity']['id']){ + $content .= '<option value="'.$key.'" selected="selected" >' . $value . '</option>'; + }else{ + $content .= '<option value="'.$key.'" >' . $value . '</option>'; + } + } + } else { + $userEntitiesMails = \Entities\Models\EntitiesModel::getEntitiesByUserId(['user_id' => $_SESSION['user']['UserId']]); + if(empty($userEntitiesMails)){ + $content .= '<option value="" >'._NO_SENDER.'</option>'; + } else { + foreach ($userEntitiesMails as $value) { + if(!empty($value['business_id'])){ + if($value['entity_id'] == $_SESSION['user']['primaryentity']['id']){ + $content .= '<option value="'.$value['entity_id'].'" selected="selected" >' . $value['entity_label'] . ' ('.$value['business_id'].')</option>'; + }else{ + $content .= '<option value="'.$value['entity_id'].'" >' . $value['entity_label'] . ' ('.$value['business_id'].')</option>'; + } + } + } } } + $content .='</select>'; $content .='</td>'; $content .= '</tr>'; - $content .= '<tr>'; - $content .= '<td align="right" >'._EMAIL.'</label></td>'; - $content .= '<td colspan="2"><input type="text" name="email" id="email" value="" class="emailSelect" />'; - $content .= '<div id="adressList" class="autocomplete"></div>'; - $content .= '<script type="text/javascript">addEmailAdress(\'email\', \'adressList\', \'' - .$_SESSION['config']['businessappurl'] - .'index.php?display=true&module=sendmail&page=adresss_autocomletion\', \'what\', \'2\');</script>'; - $content .= ' <select name="target" id="target">' - .'<option id="target_target_to" value="to">'._SEND_TO_SHORT.'</option>' - .'<option id="target_cc" value="cc">'._COPY_TO_SHORT.'</option>' - .'<option id="target_cci" value="cci">'._COPY_TO_INVISIBLE_SHORT.'</option>' - .'</select>'; - $content .=' <input type="button" name="add" value=" '._ADD - .' " id="valid" class="button" onclick="updateAdress(\''.$path_to_script - .'&mode=adress\', \'add\', document.getElementById(\'email\').value, ' - .'document.getElementById(\'target\').value, false, \''.(addslashes(_EMAIL_WRONG_FORMAT)).'\');" /> '; - $content .= '</td>'; - $content .= '</tr>'; + if($formContent != 'messageExchange'){ + $content .= '<tr>'; + $content .= '<td align="right" >'._EMAIL.'</label></td>'; + $content .= '<td colspan="2"><input type="text" name="email" id="email" value="" class="emailSelect" />'; + $content .= '<div id="adressList" class="autocomplete"></div>'; + $content .= '<script type="text/javascript">addEmailAdress(\'email\', \'adressList\', \'' + .$_SESSION['config']['businessappurl'] + .'index.php?display=true&module=sendmail&page=adresss_autocomletion\', \'what\', \'2\');</script>'; + $content .= ' <select name="target" id="target">' + .'<option id="target_target_to" value="to">'._SEND_TO_SHORT.'</option>' + .'<option id="target_cc" value="cc">'._COPY_TO_SHORT.'</option>' + .'<option id="target_cci" value="cci">'._COPY_TO_INVISIBLE_SHORT.'</option>' + .'</select>'; + $content .=' <input type="button" name="add" value=" '._ADD + .' " id="valid" class="button" onclick="updateAdress(\''.$path_to_script + .'&mode=adress\', \'add\', document.getElementById(\'email\').value, ' + .'document.getElementById(\'target\').value, false, \''.(addslashes(_EMAIL_WRONG_FORMAT)).'\');" /> '; + $content .= '</td>'; + $content .= '</tr>'; + } else { + $content .= '<tr>'; + $content .= '<td align="right" >Contact</label></td>'; + $content .= '<td colspan="2"><input type="text" name="user" id="user" style="width:96%" />'; + $content .= '<div id="destUSer" class="autocomplete"></div>'; + $content .= '<script type="text/javascript">addDestUser(\'user\', \'destUSer\', \'index.php?display=true&module=sendmail&page=contact_autocompletion\', \'what\', \'2\');</script>'; + $content .=' <input type="hidden" id="valid" onclick="updateDestUser(\''.$path_to_script + .'&mode=destUser\', \'add\', document.getElementById(\'user\').value, \'to\', false);" /> '; + $content .= '</td>'; + $content .= '</tr>'; + } $content .= '<tr>'; $content .= '<td align="right" nowrap width="10%"><span class="red_asterisk"><i class="fa fa-star"></i></span> <label>' ._SEND_TO_SHORT.'</label></td>'; - $exp_contact_id = null; + $exp_user_id = null; + $dest_user_id = null; + $exp_contact_id = null; $dest_contact_id = null; - $exp_user_id = null; - $dest_user_id = null; - $adresse_mail = null; $db = new Database(); - $stmt = $db->query("SELECT res_id, category_id, address_id, exp_user_id, dest_user_id, admission_date + $stmt = $db->query("SELECT res_id, category_id, address_id, exp_user_id, dest_user_id, admission_date, exp_contact_id, dest_contact_id FROM mlb_coll_ext WHERE (( exp_contact_id is not null or dest_contact_id is not null @@ -189,64 +234,98 @@ if ($mode == 'add') { and res_id = ?)", array($_SESSION['doc_id'])); $res = $stmt->fetchObject(); - $res_id = $res->res_id; - $category_id = $res->category_id; - $address_id = $res->address_id; - $exp_user_id = $res->exp_user_id; - $dest_user_id = $res->dest_user_id; - $admission_date = $res->admission_date; + $res_id = $res->res_id; + $category_id = $res->category_id; + $address_id = $res->address_id; + $exp_user_id = $res->exp_user_id; + $dest_user_id = $res->dest_user_id; + $admission_date = $res->admission_date; + $exp_contact_id = $res->exp_contact_id; + $dest_contact_id = $res->dest_contact_id; if ($res_id != null) { $stmt = $db->query("SELECT subject FROM res_letterbox WHERE res_id = ?", array($res_id)); $rawSubject = $stmt->fetchObject(); $subject = $rawSubject->subject; } - if($address_id != null){ - $stmt = $db->query("SELECT email FROM contact_addresses WHERE id = ?", array($address_id)); - $adr = $stmt->fetchObject(); - $adress_mail = $adr->email; - }elseif($exp_user_id != null){ - $stmt = $db->query("SELECT mail FROM users WHERE user_id = ?", array($exp_user_id)); - $adr = $stmt->fetchObject(); - $adress_mail = $adr->mail; - }elseif($dest_user_id != null){ - $stmt = $db->query("SELECT mail FROM users WHERE user_id = ?", array($dest_user_id)); - $adr = $stmt->fetchObject(); - $adress_mail = $adr->mail; + if($formContent != 'messageExchange'){ + if($address_id != null){ + $adr = ContactsModel::getFullAddressById(['select' => ['email'], 'addressId' => $address_id]); + $adress_mail = $adr[0]['email']; + }elseif($exp_user_id != null){ + $stmt = $db->query("SELECT mail FROM users WHERE user_id = ?", array($exp_user_id)); + $adr = $stmt->fetchObject(); + $adress_mail = $adr->mail; + }elseif($dest_user_id != null){ + $stmt = $db->query("SELECT mail FROM users WHERE user_id = ?", array($dest_user_id)); + $adr = $stmt->fetchObject(); + $adress_mail = $adr->mail; + } + } else if($address_id != null) { + if($exp_contact_id != null){ + $contact_id = $exp_contact_id; + } else { + $contact_id = $dest_contact_id; + } + if(!empty($contact_id)){ + $communicationTypeModel = ContactsModel::getContactCommunication(['contactId' => $contact_id]); + $contactInfo = ContactsModel::getById(['id' => $contact_id, 'table' => ['view_contacts']]); + if(!empty($communicationTypeModel) && !empty($contactInfo[0]['external_contact_id'])){ + $adress_mail = ContactsModel::getContactFullLabel(['addressId' => $address_id]); + $adress_mail .= '. (' . _COMMUNICATION_TYPE . ' : '.$communicationTypeModel['value'] . ')'; + } + } } - if($adress_mail != null and ($_SESSION['user']['UserId'] != $exp_user_id and $_SESSION['user']['UserId'] != $dest_user_id)){ - $content .= '<td width="90%" colspan="2"><div name="to" id="to" class="emailInput"><div id="loading_to" style="display:none;"></div><div class="email_element" id="0_'.$adress_mail.'">'.$adress_mail.' <div class="email_delete_button" id="0" onclick="updateAdress(\''.$_SESSION['config']['coreurl'].'apps/maarch_entreprise/index.php?display=true&module=sendmail&page=sendmail_ajax_content&identifier=106&origin=document&coll_id=letterbox_coll&size=full&mode=adress\', \'del\', \''.$adress_mail.'\', \'to\', this.id);" - alt=\"Supprimer\" title=\"Supprimer\">x</div></div></div>' + if($adress_mail != null and $_SESSION['user']['UserId'] != $exp_user_id and $_SESSION['user']['UserId'] != $dest_user_id){ + if($formContent == 'messageExchange'){ + $_SESSION['adresses']['to'][$address_id] = $adress_mail; + $onclickfunction = 'updateDestUser'; + $elementToDel = $address_id; + $modeUrl = 'destUser'; + $idToDel = $address_id; + } else { + $_SESSION['adresses']['to'][0] = $adress_mail; + $onclickfunction = 'updateAdress'; + $elementToDel = $adress_mail; + $idToDel = 0; + } + $content .= '<td width="90%" colspan="2"><div name="to" id="to" class="emailInput"><div id="loading_to" style="display:none;"></div><div class="email_element" id="0_'.$adress_mail.'">'. + $adress_mail.' <div class="email_delete_button" id="'.$idToDel.'" onclick="'.$onclickfunction.'(\''.$path_to_script + .'&mode='.$modeUrl.'\', \'del\', \''.$elementToDel.'\', \'to\', this.id);" + alt=\"Supprimer\" title=\"Supprimer\">x</div></div></div>' .'<div id="loading_to" style="display:none;"><i class="fa fa-spinner fa-spin" title="loading..."></div></div></td>'; - $_SESSION['adresses']['to'][0] = $adress_mail; - }else{ - $content .= '<td width="90%" colspan="2"><div name="to" id="to" class="emailInput">' + } else { + $content .= '<td width="90%" colspan="2"><div name="to" id="to" class="emailInput">' .'<div id="loading_to" style="display:none;"><i class="fa fa-spinner fa-spin" title="loading..."></div></div></td>'; - } + } $content .= '</tr>'; - $content .= '<tr><td colspan="3"><a href="javascript://" ' - .'onclick="new Effect.toggle(\'tr_cc\', \'blind\', {delay:0.2});' - .'new Effect.toggle(\'tr_cci\', \'blind\', {delay:0.2});">' - ._SHOW_OTHER_COPY_FIELDS.'</a></td></tr>'; - $content .= '<tr id="tr_cc" style="display:none">'; - $content .= '<td align="right" nowrap><label>'._COPY_TO_SHORT.'</label></td>'; - $content .= '<td colspan="2"><div name="cc" id="cc" class="emailInput">' - .'<div id="loading_cc" style="display:none;"><i class="fa fa-spinner fa-spin" title="loading..."></div></div></td>'; - $content .= '</tr>'; - $content .= '<tr id="tr_cci" style="display:none">'; - $content .= '<td align="right" nowrap><label>'._COPY_TO_INVISIBLE_SHORT.'</label></td>'; - $content .= '<td colspan="2"><div name="cci" id="cci" class="emailInput">' - .'<div id="loading_cci" style="display:none;"><i class="fa fa-spinner fa-spin" title="loading..."></div></div></td>'; - $content .= '</tr>'; - $content .= '<tr>'; + + if($formContent != 'messageExchange'){ + $content .= '<tr><td colspan="3"><a href="javascript://" ' + .'onclick="new Effect.toggle(\'tr_cc\', \'blind\', {delay:0.2});' + .'new Effect.toggle(\'tr_cci\', \'blind\', {delay:0.2});">' + ._SHOW_OTHER_COPY_FIELDS.'</a></td></tr>'; + $content .= '<tr id="tr_cc" style="display:none">'; + $content .= '<td align="right" nowrap><label>'._COPY_TO_SHORT.'</label></td>'; + $content .= '<td colspan="2"><div name="cc" id="cc" class="emailInput">' + .'<div id="loading_cc" style="display:none;"><i class="fa fa-spinner fa-spin" title="loading..."></div></div></td>'; + $content .= '</tr>'; + $content .= '<tr id="tr_cci" style="display:none">'; + $content .= '<td align="right" nowrap><label>'._COPY_TO_INVISIBLE_SHORT.'</label></td>'; + $content .= '<td colspan="2"><div name="cci" id="cci" class="emailInput">' + .'<div id="loading_cci" style="display:none;"><i class="fa fa-spinner fa-spin" title="loading..."></div></div></td>'; + $content .= '</tr>'; + $content .= '<tr>'; + } $content .= '<td align="right" nowrap><span class="red_asterisk"><i class="fa fa-star"></i></span><label> '._EMAIL_OBJECT.' </label></td>'; $content .= '<td colspan="2">'; - if ($category_id === 'outgoing') - $content .= '<input name="object" id="object" class="emailInput" type="text" value="' . $subject . '" />'; + + if ($category_id == 'outgoing') + $content .= '<input name="object" id="object" class="emailInput" type="text" value="' . $subject . '" '.$readOnlyObject.'/>'; else - $content .= '<input name="object" id="object" class="emailInput" type="text" value="' . _EMAIL_OBJECT_ANSWER . ' ' . functions::format_date_db($admission_date).'" />'; + $content .= '<input name="object" id="object" class="emailInput" type="text" value="' . _EMAIL_OBJECT_ANSWER . ' ' . functions::format_date_db($admission_date).'" '.$readOnlyObject.'/>'; $content .= '</td></tr>'; $content .= '</table><br />'; @@ -264,7 +343,11 @@ if ($mode == 'add') { $joined_files = $sendmail_tools->getJoinedFiles($collId, $table, $identifier); if (count($joined_files) >0) { $content .='<br/>'; - $content .='<div style="color:rgb(22, 173, 235);font-weight:bold;">'._DOC.'</div>'; + $content .='<div><span style="color:rgb(22, 173, 235);font-weight:bold;">'._DOC.'</span>'; + if($formContent == 'messageExchange'){ + $content .='<span style="float: right;font-weight:bold">Principal</span>'; + } + $content .='</div>'; for($i=0; $i < count($joined_files); $i++) { //Get data $id = $joined_files[$i]['id']; @@ -301,6 +384,10 @@ if ($mode == 'add') { $content .= ' onclick="clickAttachments('.$id.')" '; $content .= "><strong>" . $description . "</strong> <span style=\"font-size: 10px;color: grey;\">(" . $att_type . " - " . $filesize .")</span></td>"; } + if($formContent == 'messageExchange'){ + $content .= "<td style=\"width:1%;text-align:center;width: 8%;margin-right: 2px;vertical-align: middle\"><input type=radio name=\"main_exchange_doc\" value=\"res_letterbox__".$id."\">"; + $content .= "</td>"; + } $content .= "</tr></table>"; $filename = $sendmail_tools->createFilename($description.$version, $format); $all_joined_files .= $description.': '.$filename.PHP_EOL; @@ -316,7 +403,7 @@ if ($mode == 'add') { $content .= "<table cellspacing=\"3\" id=\"show_pj_mail\" style=\"border-collapse:collapse;width:100%;\">"; for($i=0; $i < count($attachment_files); $i++) { - $it = $i+1; + $content .= "<tr style=\"vertical-align:top;\">"; //Get data @@ -341,8 +428,10 @@ if ($mode == 'add') { if($isVersion){ $inputName = "join_version_attachment[]"; + $mainExchangeDocValue = "res_version_attachments"; } else { $inputName = "join_attachment[]"; + $mainExchangeDocValue = "res_attachments"; } $content .= "<th style=\"width:25px;border: dashed 1px grey;border-right:none;vertical-align:middle;\" alt=\"".$description @@ -375,6 +464,10 @@ if ($mode == 'add') { $content .= "<span style='font-size: 10px;color: rgb(22, 173, 235);font-style:italic;'>" . $chrono . "</span> - "; $content .= "<span style='font-size: 10px;color: grey;font-style:italic;'>" . $dest_firstname . " " . $dest_lastname. " " . $dest_society . "</span>"; $content .= "</td>"; + if($formContent == 'messageExchange'){ + $content .= "<td style=\"width:1%;text-align:center;width: 8%;margin-right: 2px;vertical-align: middle\"><input type=radio name=\"main_exchange_doc\" value=\"".$mainExchangeDocValue."__".$id."\">"; + $content .= "</td>"; + } $content .= "</tr>"; @@ -396,7 +489,6 @@ if ($mode == 'add') { $content .='<div style="color:rgb(22, 173, 235);font-weight:bold;">'._NOTES.'</div>'; $content .= "<table cellspacing=\"3\" style=\"border-collapse:collapse;width:100%;\">"; for($i=0; $i < count($user_notes); $i++) { - $it = $i+1; $content .= "<tr style=\"vertical-align:top;\">"; //Get data @@ -424,6 +516,7 @@ if ($mode == 'add') { $content .= '</div>'; $content .='<hr />'; + $content .= '<tr>'; $content .= '<td><label style="padding-right:10px">' . _Label_ADD_TEMPLATE_MAIL . '</label></td>'; $content .= '<select name="templateMail" id="templateMail" style="width:200px" ' @@ -451,11 +544,23 @@ if ($mode == 'add') { $content .= '</tr></br></br>'; //Body - $displayHtml = 'block'; - $displayRaw = 'none'; - $content .='<script type="text/javascript">var mode="html";</script>'; + + if($formContent != 'messageExchange'){ + $displayHtml = 'block'; + $displayRaw = 'none'; + $textAreaMode = 'html'; + } else { + $displayHtml = 'none'; + $displayRaw = 'block'; + $textAreaMode = 'raw'; + } + + $content .='<script type="text/javascript">var mode="'.$textAreaMode.'";</script>'; + //Show/hide html VS raw mode - $content .= '<a href="javascript://" onclick="switchMode(\'show\');"><em>'._HTML_OR_RAW.'</em></a>'; + if($formContent != 'messageExchange'){ + $content .= '<a href="javascript://" onclick="switchMode(\'show\');"><em>'._HTML_OR_RAW.'</em></a>'; + } //load tinyMCE editor ob_start(); @@ -480,10 +585,12 @@ if ($mode == 'add') { $content .=' <input type="button" name="valid" value=" '._SEND_EMAIL .' " id="valid" class="button" onclick="validEmailForm(\'' .$path_to_script.'&mode=added&for=send\', \'formEmail\');" /> '; - //Save - $content .=' <input type="button" name="valid" value=" '._SAVE_EMAIL - .' " id="valid" class="button" onclick="validEmailForm(\'' - .$path_to_script.'&mode=added&for=save\', \'formEmail\');" /> '; + if($formContent != 'messageExchange'){ + //Save + $content .=' <input type="button" name="valid" value=" '._SAVE_EMAIL + .' " id="valid" class="button" onclick="validEmailForm(\'' + .$path_to_script.'&mode=added&for=save\', \'formEmail\');" /> '; + } //Cancel $content .='<input type="button" name="cancel" id="cancel" class="button" value="' ._CANCEL.'" onclick="window.parent.destroyModal(\'form_email\');"/>'; @@ -671,7 +778,6 @@ if ($mode == 'add') { $content .='<div style="color:rgb(22, 173, 235);font-weight:bold;">'._ATTACHMENTS.'</div>'; $content .= "<table cellspacing=\"3\" id=\"show_pj_mail\" style=\"border-collapse:collapse;width:100%;\">"; for($i=0; $i < count($attachment_files); $i++) { - $it = $i+1; $content .= "<tr style=\"vertical-align:top;\">"; //Get data @@ -763,7 +869,6 @@ if ($mode == 'add') { $content .='<div style="color:rgb(22, 173, 235);font-weight:bold;">'._NOTES.'</div>'; $content .= "<table cellspacing=\"3\" style=\"border-collapse:collapse;width:100%;\">"; for($i=0; $i < count($user_notes); $i++) { - $it = $i+1; $content .= "<tr style=\"vertical-align:top;\">"; //Get data @@ -811,7 +916,7 @@ if ($mode == 'add') { $content .= "<option value='" . $result['template_id'] ."'>" . $result['template_label'] . "</option>"; } $content .='</select>'; - $content .= '<label style="margin-left: 15%;padding-right:10px">' . 'Signature : ' . '</label>'; + $content .= '<label style="margin-left: 15%;padding-right:10px">' . 'Signature de mail' . '</label>'; $emailSignaturesClass = new EmailSignatures(); $mailSignatures = $emailSignaturesClass->getForCurrentUser(); @@ -824,15 +929,14 @@ if ($mode == 'add') { $content .= '</select>'; $content .= '</tr></br></br>'; - //Body if ($emailArray['isHtml'] == 'Y') { - $displayRaw = 'none'; - $displayHtml = 'block'; + $displayRaw = 'none'; + $displayHtml = 'block'; $textAreaMode = 'html'; } else { - $displayRaw = 'block'; - $displayHtml = 'none'; + $displayRaw = 'block'; + $displayHtml = 'none'; $textAreaMode = 'raw'; } $content .='<script type="text/javascript">var mode="'.$textAreaMode.'";</script>'; @@ -901,26 +1005,33 @@ if ($mode == 'add') { if (isset($_REQUEST['id']) && !empty($_REQUEST['id'])) { $id = $_REQUEST['id']; - $emailArray = $sendmail_tools->getEmail($id, false); + if($formContent == 'messageExchange'){ + $emailArray = ReadMessageExchangeController::getMessageExchange(['id' => $id]); + } else { + $emailArray = $sendmail_tools->getEmail($id, false); + } //Check if mail exists - if (count($emailArray) > 0 ) { - $usermailArray = $users_tools->get_user($emailArray['userId']); - + if (count($emailArray) > 0 && $emailArray['type'] != 'ArchiveTransferReplySent') { $content .= '<div>'; $content .= '<table border="0" align="left" width="100%" cellspacing="5">'; $content .= '<tr>'; - $content .= '<td width="10%" align="right" nowrap><b>'.ucfirst(_FROM_SHORT).' </b></td><td width="90%" colspan="2">'; - - $mailEntities = $sendmail_tools->getAttachedEntitiesMails(); + $content .= '<td width="10%" align="right" nowrap><b>'.ucfirst(_FROM_SHORT).' </b></td><td width="90%" colspan="2">'; - if (in_array($emailArray['sender_email'], array_keys($mailEntities))) { - $content .= $mailEntities[$emailArray['sender_email']]; - } else if ($emailArray['sender_email'] == $usermailArray['mail']) { - $content .= $usermailArray['firstname'] . " " . $usermailArray['lastname'] . " (".$emailArray['sender_email'].")"; + if($formContent == 'messageExchange'){ + $content .= $emailArray['from']; } else { - $content .= $sendmail_tools->explodeSenderEmail($emailArray['sender_email']); + $usermailArray = $users_tools->get_user($emailArray['userId']); + $mailEntities = $sendmail_tools->getAttachedEntitiesMails(); + + if (in_array($emailArray['sender_email'], array_keys($mailEntities))) { + $content .= $mailEntities[$emailArray['sender_email']]; + } else if ($emailArray['sender_email'] == $usermailArray['mail']) { + $content .= $usermailArray['firstname'] . " " . $usermailArray['lastname'] . " (".$emailArray['sender_email'].")"; + } else { + $content .= $sendmail_tools->explodeSenderEmail($emailArray['sender_email']); + } } $content .= '<br/></td>'; @@ -934,37 +1045,48 @@ if ($mode == 'add') { $content .= '<td align="right" nowrap width="10%"><span class="red_asterisk"><i class="fa fa-star"></i></span> <label>' ._SEND_TO_SHORT.'</label></td>'; $content .= '<td width="90%" colspan="2"><div name="to" id="to" class="emailInput">'; - $content .= $sendmail_tools->updateAdressInputField($path_to_script, $_SESSION['adresses'], 'to', true); - $content .= '</div></td>'; - $content .= '</tr>'; - //CC - if (count($emailArray['cc']) > 0) { - $_SESSION['adresses']['cc'] = array(); - $_SESSION['adresses']['cc'] = $emailArray['cc']; + if($formContent == 'messageExchange'){ + $content .= $emailArray['contactInfo']; + } else { + $content .= $sendmail_tools->updateAdressInputField($path_to_script, $_SESSION['adresses'], 'to', true); } - $content .= '<tr>'; - $content .= '<td align="right" nowrap><label>'._COPY_TO_SHORT.'</label></td>'; - $content .= '<td colspan="2"><div name="cc" id="cc" class="emailInput">'; - $content .= $sendmail_tools->updateAdressInputField($path_to_script, $_SESSION['adresses'], 'cc', true); $content .= '</div></td>'; $content .= '</tr>'; - //CCI - if (count($emailArray['cci']) > 0) { - $_SESSION['adresses']['cci'] = array(); - $_SESSION['adresses']['cci'] = $emailArray['cci']; - } - $content .= '<tr>'; - $content .= '<td align="right" nowrap><label>'._COPY_TO_INVISIBLE_SHORT.'</label></td>'; - $content .= '<td colspan="2"><div name="cci" id="cci" class="emailInput">'; - $content .= $sendmail_tools->updateAdressInputField($path_to_script, $_SESSION['adresses'], 'cci', true); - $content .= '</div></td>'; - $content .= '</tr>'; + if($formContent == 'messageExchange'){ + $content .= '<tr><td align="right" nowrap width="10%"></td><td width="90%">' . _COMMUNICATION_TYPE . ' : '.$emailArray['communicationType'].'</td></tr>'; + } else { + //CC + if (count($emailArray['cc']) > 0) { + $_SESSION['adresses']['cc'] = array(); + $_SESSION['adresses']['cc'] = $emailArray['cc']; + } + $content .= '<tr>'; + $content .= '<td align="right" nowrap><label>'._COPY_TO_SHORT.'</label></td>'; + $content .= '<td colspan="2"><div name="cc" id="cc" class="emailInput">'; + $content .= $sendmail_tools->updateAdressInputField($path_to_script, $_SESSION['adresses'], 'cc', true); + $content .= '</div></td>'; + $content .= '</tr>'; + //CCI + if (count($emailArray['cci']) > 0) { + $_SESSION['adresses']['cci'] = array(); + $_SESSION['adresses']['cci'] = $emailArray['cci']; + } + $content .= '<tr>'; + $content .= '<td align="right" nowrap><label>'._COPY_TO_INVISIBLE_SHORT.'</label></td>'; + $content .= '<td colspan="2"><div name="cci" id="cci" class="emailInput">'; + $content .= $sendmail_tools->updateAdressInputField($path_to_script, $_SESSION['adresses'], 'cci', true); + $content .= '</div></td>'; + $content .= '</tr>'; + } //Object $content .= '<tr>'; $content .= '<td align="right" nowrap><span class="red_asterisk"><i class="fa fa-star"></i></span> <label>'._EMAIL_OBJECT.' </label></td>'; $content .= '<td colspan="2"><div name="object" id="object" class="emailInput">' .$emailArray['object'].'</div></td>'; $content .= '</tr>'; + if($formContent == 'messageExchange'){ + $content .= '<tr><td width="10%" align="right" nowrap>'._IDENTIFIER.'</td><td><div class="emailInput">'.$emailArray['reference'].'</div></td></tr>'; + } $content .= '</table><br />'; $content .='<hr />'; @@ -981,7 +1103,11 @@ if ($mode == 'add') { $joined_files = $sendmail_tools->getJoinedFiles($collId, $table, $identifier); if (count($joined_files) >0) { $content .='<br/>'; - $content .='<div style="color:rgb(22, 173, 235);font-weight:bold;">'._DOC.'</div>'; + $content .='<div><span style="color:rgb(22, 173, 235);font-weight:bold;">'._DOC.'</span>'; + if($formContent == 'messageExchange'){ + $content .='<span style="float: right;font-weight:bold">Principal</span>'; + } + $content .='</div>'; for($i=0; $i < count($joined_files); $i++) { //Get data $id = $joined_files[$i]['id']; @@ -1024,6 +1150,13 @@ if ($mode == 'add') { $content .= ' onclick="clickAttachments('.$id.')" '; $content .= "><strong>" . $description . "</strong> <span style=\"font-size: 10px;color: grey;\">(" . $att_type . " - " . $filesize .")</span></td>"; } + if($formContent == 'messageExchange'){ + $content .= "<td style=\"width:1%;text-align:center;width: 8%;margin-right: 2px;vertical-align: middle\"><input type=radio name=\"main_exchange_doc\" disabled "; + if($emailArray['disposition']->tablename == 'res_letterbox' && $emailArray['disposition']->res_id == $id){ + $content .= " checked "; + } + $content .= "></td>"; + } $content .= "</tr></table>"; //Filename $filename = $sendmail_tools->createFilename($description.$version, $format); @@ -1039,7 +1172,6 @@ if ($mode == 'add') { $content .='<div style="color:rgb(22, 173, 235);font-weight:bold;">'._ATTACHMENTS.'</div>'; $content .= "<table cellspacing=\"3\" id=\"show_pj_mail\" style=\"border-collapse:collapse;width:100%;\">"; for($i=0; $i < count($attachment_files); $i++) { - $it = $i+1; $content .= "<tr style=\"vertical-align:top;\">"; //Get data @@ -1072,6 +1204,7 @@ if ($mode == 'add') { . "\" title=\"".$description . "\"><input style=\"margin-left: 3px\" disabled=\"disabled\" type=\"checkbox\" id=\"join_attachment_".$id."\" name=\"".$inputName."\""; + $checked = ""; if(($isVersion && in_array($id, $emailArray['attachments_version'])) || (!$isVersion && in_array($id, $emailArray['attachments']))){ $checked = ' checked="checked"'; } @@ -1104,8 +1237,16 @@ if ($mode == 'add') { $content .= "<span style='font-size: 10px;color: rgb(22, 173, 235);font-style:italic;'>" . $chrono . "</span> - "; $content .= "<span style='font-size: 10px;color: grey;font-style:italic;'>" . $dest_firstname . " " . $dest_lastname. " " . $dest_society . "</span>"; $content .= "</td>"; - + if($formContent == 'messageExchange'){ + $content .= "<td style=\"width:1%;text-align:center;width: 8%;margin-right: 2px;vertical-align: middle\"><input type=radio name=\"main_exchange_doc\" disabled "; + if($emailArray['disposition']->res_id == $id && ($emailArray['disposition']->tablename == 'res_attachments' && !$isVersion) + || ($emailArray['disposition']->tablename == 'res_version_attachments' && $isVersion)){ + $content .= " checked "; + } + $content .= "></td>"; + } $content .= "</tr>"; + //Filename $filename = $sendmail_tools->createFilename($description, $format); $all_joined_files .= $description.': '.$filename.PHP_EOL; @@ -1126,7 +1267,6 @@ if ($mode == 'add') { $content .='<div style="color:rgb(22, 173, 235);font-weight:bold;">'._NOTES.'</div>'; $content .= "<table cellspacing=\"3\" style=\"border-collapse:collapse;width:100%;\">"; for($i=0; $i < count($user_notes); $i++) { - $it = $i+1; $content .= "<tr style=\"vertical-align:top;\">"; //Get data @@ -1150,6 +1290,7 @@ if ($mode == 'add') { ."<strong>". $noteShort."</strong></td>"; $content .= "</tr>"; + } $content .= "</table>"; @@ -1182,15 +1323,54 @@ if ($mode == 'add') { .$sendmail_tools->htmlToRaw($emailArray['body']).'</textarea>'; $content .='</div>'; } - + + if(!empty($emailArray['receptionDate'])){ + $content .='<br><hr style="margin-top:2px;" />'; + $content .= '<b>'._RECEPTION_DATE.' : </b>' . $emailArray['receptionDate'].'<br><br>'; + } + if(!empty($emailArray['operationDate'])){ + + $content .= '<div onclick="new Effect.toggle(\'operationCommentsDiv\', \'blind\', {delay:0.2});" onmouseover="this.style.cursor=\'pointer\';"> + <span id="divStatus_operationComments" style="color:#1C99C5;"><i class="fa fa-plus-square-o"></i></span> '._MORE_INFORMATIONS.' + </div>'; + $content .= '<div id="operationCommentsDiv" style="display:none">'; + foreach ($emailArray['operationComments'] as $value) { + $content .= $value->value.'<br>'; + } + $content .= '</div><br>'; + $content .= '<b>'._OPERATION_DATE.' : </b>' . $emailArray['operationDate'].'<br><br>'; + } + if(!empty($emailArray['messageReview'])){ + + $content .= '<h4>'._M2M_FOLLOWUP_REQUEST.'</h4>'; + $content .= '<div>'; + foreach ($emailArray['messageReview'] as $value) { + $content .= $value.'<br>'; + } + $content .= '</div>'; + } + //Buttons + $content .='<br><hr style="margin-top:2px;" />'; + $content .='<div align="center">'; + //Close button + $content .='<input type="button" name="cancel" id="cancel" class="button" value="' + ._CLOSE.'" onclick="window.parent.destroyModal(\'form_email\');"/>'; + $content .='</div>'; + $content .= '</div>'; + } else if ($emailArray['type'] == 'ArchiveTransferReplySent'){ + $content .= '<b>'._REPLY_RESPONSE_SENT.' : </b>' . $emailArray['creationDate'].'<br><br>'; + + foreach ($emailArray['operationComments'] as $value) { + $content .= $value.'<br>'; + } + //Buttons - $content .='<hr style="margin-top:2px;" />'; + $content .='<br><hr style="margin-top:2px;" />'; $content .='<div align="center">'; //Close button $content .='<input type="button" name="cancel" id="cancel" class="button" value="' ._CLOSE.'" onclick="window.parent.destroyModal(\'form_email\');"/>'; $content .='</div>'; - $content .= '</div>'; } else { $content = $request->wash_html($id.': '._EMAIL_DONT_EXIST.'!','NONE'); } diff --git a/modules/sendmail/sendmail.php b/modules/sendmail/sendmail.php index 2be85296719..13f2d1f5179 100755 --- a/modules/sendmail/sendmail.php +++ b/modules/sendmail/sendmail.php @@ -336,16 +336,27 @@ if (isset($_REQUEST['start']) && !empty($_REQUEST['start'])) $parameters .= '&st $paramsTab['listCss'] = $css; //CSS $paramsTab['tools'] = array(); //Icones dans la barre d'outils - $add = array( + $addMail = array( "script" => "showEmailForm('".$_SESSION['config']['businessappurl'] . "index.php?display=true&module=sendmail&page=sendmail_ajax_content" - . "&mode=add&identifier=".$identifier."&origin=".$origin + . "&mode=add&identifier=".$identifier."&origin=".$origin."&formContent=email" . $parameters."')", "icon" => 'envelope', "tooltip" => _NEW_EMAIL, "alwaysVisible" => true ); - array_push($paramsTab['tools'],$add); + + $addExchangeMessage = array( + "script" => "showEmailForm('".$_SESSION['config']['businessappurl'] + . "index.php?display=true&module=sendmail&page=sendmail_ajax_content" + . "&mode=add&identifier=".$identifier."&origin=".$origin."&formContent=messageExchange" + . $parameters."')", + "icon" => 'exchange', + "tooltip" => _NEW_NUMERIC_PACKAGE, + "alwaysVisible" => true + ); + + array_push($paramsTab['tools'], $addMail, $addExchangeMessage); //Action icons array $paramsTab['actionIcons'] = array(); @@ -388,6 +399,9 @@ if (isset($_REQUEST['start']) && !empty($_REQUEST['start'])) $parameters .= '&st $content .= '<script>loadToolbarBadge(\'sendmail_tab\',\''.$toolbarBagde_script.'\');</script>'; // $debug = $list->debug(); + /********* MESSAGE EXCHANGE PART ***************/ + include_once "modules/sendmail/messageExchangeList.php"; + - echo "{status : " . $status . ", content : '" . addslashes($debug.$content) . "', error : '" . addslashes($error) . "'}"; + echo "{status : " . $status . ", content : '" . addslashes($debug.$content.$contentMessageExchange) . "', error : '" . addslashes($error) . "'}"; } diff --git a/modules/sendmail/sendmail_ajax_content.php b/modules/sendmail/sendmail_ajax_content.php index 4716345fccb..91f34a6c475 100755 --- a/modules/sendmail/sendmail_ajax_content.php +++ b/modules/sendmail/sendmail_ajax_content.php @@ -42,22 +42,20 @@ require_once 'modules/sendmail/sendmail_tables.php'; require_once 'modules/notifications/notifications_tables_definition.php'; require_once "modules" . DIRECTORY_SEPARATOR . "sendmail" . DIRECTORY_SEPARATOR . "class" . DIRECTORY_SEPARATOR . "class_modules_tools.php"; - -$core_tools = new core_tools(); -$request = new request(); -$db = new Database(); -$sec = new security(); -$is = new indexing_searching_app(); -$users_tools = new class_users(); -$sendmail_tools = new sendmail(); +require_once 'modules/sendmail/Controllers/SendMessageExchangeController.php'; +require_once 'apps/maarch_entreprise/Models/ContactsModel.php'; +require_once "core/Models/DocserverModel.php"; +require_once "core/Models/DocserverTypeModel.php"; +require_once "core/Controllers/DocserverToolsController.php"; - // require_once('core'.DIRECTORY_SEPARATOR.'class'.DIRECTORY_SEPARATOR.'class_request.php'); - // $db = new Database(); - // $stmt = $db->query("SELECT action_page FROM actions WHERE id = ?", array($_SESSION['id_action'])); - // $action_page = $stmt->fetchObject(); - // $action_page = $action_page->action_page; - //var_dump($action_page); +$core_tools = new core_tools(); +$request = new request(); +$db = new Database(); +$sec = new security(); +$is = new indexing_searching_app(); +$users_tools = new class_users(); +$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'){ @@ -105,6 +103,12 @@ if (isset($_REQUEST['identifier']) && ! empty($_REQUEST['identifier'])) { $identifier = trim($_REQUEST['identifier']); } +//formContent of the element wich is noted +$formContent = ''; +if (isset($_GET['formContent']) && ! empty($_GET['formContent'])) { + $formContent = trim($_GET['formContent']); +} + //Collection if (isset($_REQUEST['coll_id']) && ! empty($_REQUEST['coll_id'])) { $collId = trim($_REQUEST['coll_id']); @@ -177,128 +181,138 @@ switch ($mode) { $content .='<iframe name="form_mail" id="form_mail" src="' . $_SESSION['config']['businessappurl'] . 'index.php?display=true&module=sendmail&page=mail_form&identifier=' - . $identifier.'&origin=document&coll_id='.$collId.'&mode='.$mode.$parameters.'" ' + . $identifier.'&origin=document&coll_id='.$collId.'&mode='.$mode.$parameters.'&formContent='.$_GET['formContent'].'" ' . 'frameborder="0" width="100%" style="height:540px;padding:0px;overflow-x:hidden;overflow-y: auto;"></iframe>'; } break; case 'added': - $userEntitiesMails = array(); - if ($core_tools->test_service('use_mail_services', 'sendmail', false)) { - $userEntitiesMails = $sendmail_tools->checkAttachedEntitiesMails($_SESSION['user']['UserId']); - } - if (empty($identifier)) { - $error = $request->wash_html(_IDENTIFIER.' '._IS_EMPTY.'!','NONE'); - $status = 1; - } else if (!in_array($_REQUEST['sender_email'], array_keys($userEntitiesMails)) && $core_tools->test_service('use_mail_services', 'sendmail', false)) { - $error = $request->wash_html(_INCORRECT_SENDER,'NONE'); - $status = 1; + if($formContent == 'messageExchange'){ + $return = SendMessageExchangeController::createMessageExchange($_REQUEST); + if(!empty($return['errors'])){ + $error = implode(", ", $return['errors']); + $status = 1; + } + //Reload and show message + $js = $list_origin."window.parent.top.$('main_info').innerHTML = '"._EMAIL_ADDED."';"; } else { - if ((isset($_SESSION['adresses']['to']) && count($_SESSION['adresses']['to']) > 0) || $_REQUEST['for'] == 'save') { - if (!empty($_REQUEST['object']) || $_REQUEST['for'] == 'save') { - - //Check adress for to - if(!empty($_SESSION['adresses']['to'])){ + $userEntitiesMails = array(); + if ($core_tools->test_service('use_mail_services', 'sendmail', false)) { + $userEntitiesMails = $sendmail_tools->checkAttachedEntitiesMails($_SESSION['user']['UserId']); + } + if (empty($identifier)) { + $error = $request->wash_html(_IDENTIFIER.' '._IS_EMPTY.'!','NONE'); + $status = 1; + } else if (!in_array($_REQUEST['sender_email'], array_keys($userEntitiesMails)) && $core_tools->test_service('use_mail_services', 'sendmail', false)) { + $error = $request->wash_html(_INCORRECT_SENDER,'NONE'); + $status = 1; + } else { + if (isset($_SESSION['adresses']['to']) && count($_SESSION['adresses']['to']) > 0 ) { + if (!empty($_REQUEST['object'])) { + + //Check adress for to $to = join(',', $_SESSION['adresses']['to']); $error = $sendmail_tools->CheckEmailAdress($to); - } - - if (empty($error)) { - - //Check adress for cc - (isset($_SESSION['adresses']['cc']) && count($_SESSION['adresses']['cc']) > 0)? - $cc = join(',', $_SESSION['adresses']['cc']) : $cc = ''; - $error = $sendmail_tools->CheckEmailAdress($cc); if (empty($error)) { - - //Check adress for cci - (isset($_SESSION['adresses']['cci']) && count($_SESSION['adresses']['cci']) > 0)? - $cci = join(',', $_SESSION['adresses']['cci']) : $cci = ''; - $error = $sendmail_tools->CheckEmailAdress($cci); + + //Check adress for cc + (isset($_SESSION['adresses']['cc']) && count($_SESSION['adresses']['cc']) > 0)? + $cc = join(',', $_SESSION['adresses']['cc']) : $cc = ''; + $error = $sendmail_tools->CheckEmailAdress($cc); if (empty($error)) { - //Data - $collId = $_REQUEST['coll_id']; - $object = $_REQUEST['object']; - $senderEmail = $_REQUEST['sender_email']; - (isset($_REQUEST['join_file']) - && count($_REQUEST['join_file']) > 0 - )? $res_master_attached = 'Y' : $res_master_attached = 'N'; - //attachment - if (isset($_REQUEST['join_attachment']) && count($_REQUEST['join_attachment']) > 0) { - $attachment_list = join(',', $_REQUEST['join_attachment']); - } - //Version attachment - if (isset($_REQUEST['join_version_attachment']) && count($_REQUEST['join_version_attachment']) > 0) { - $attachment_version_list = join(',', $_REQUEST['join_version_attachment']); - } - //version document - if (isset($_REQUEST['join_version']) && count($_REQUEST['join_version']) > 0) { - $version_list = join(',', $_REQUEST['join_version']); - } - //Notes - if (isset($_REQUEST['notes']) && count($_REQUEST['notes']) > 0) { - $note_list = join(',', $_REQUEST['notes']); - } - - $userId = $_SESSION['user']['UserId']; - (!empty($_REQUEST['is_html']) && $_REQUEST['is_html'] == 'Y')? $isHtml = 'Y' : $isHtml = 'N'; - //Body content - if ($isHtml == 'Y') { - $body = $sendmail_tools->cleanHtml($_REQUEST['body_from_html']); - } else { - $body = $_REQUEST['body_from_raw']; - } + //Check adress for cci + (isset($_SESSION['adresses']['cci']) && count($_SESSION['adresses']['cci']) > 0)? + $cci = join(',', $_SESSION['adresses']['cci']) : $cci = ''; + $error = $sendmail_tools->CheckEmailAdress($cci); - //Status - if ($_REQUEST['for'] == 'save') { - $email_status = 'D'; - } else if ($_REQUEST['for'] == 'send'){ - $email_status = 'W'; - } - - //Query - $stmt = $db->query( - "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, - res_attachment_id_list, res_version_att_id_list,note_id_list, is_html, email_status, creation_date, sender_email) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, ?)", - 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) - ); - + if (empty($error)) { - //Last insert ID from sequence - $id = $request->last_insert_id('sendmail_email_id_seq'); + //Data + $collId = $_REQUEST['coll_id']; + $object = $_REQUEST['object']; + $senderEmail = $_REQUEST['sender_email']; + (isset($_REQUEST['join_file']) + && count($_REQUEST['join_file']) > 0 + )? $res_master_attached = 'Y' : $res_master_attached = 'N'; + //attachment + if (isset($_REQUEST['join_attachment']) && count($_REQUEST['join_attachment']) > 0) { + $attachment_list = join(',', $_REQUEST['join_attachment']); + } + //Version attachment + if (isset($_REQUEST['join_version_attachment']) && count($_REQUEST['join_version_attachment']) > 0) { + $attachment_version_list = join(',', $_REQUEST['join_version_attachment']); + } + //version document + if (isset($_REQUEST['join_version']) && count($_REQUEST['join_version']) > 0) { + $version_list = join(',', $_REQUEST['join_version']); + } + //Notes + if (isset($_REQUEST['notes']) && count($_REQUEST['notes']) > 0) { + $note_list = join(',', $_REQUEST['notes']); + } + + $userId = $_SESSION['user']['UserId']; + (!empty($_REQUEST['is_html']) && $_REQUEST['is_html'] == 'Y')? $isHtml = 'Y' : $isHtml = 'N'; + //Body content + if ($isHtml == 'Y') { + $body = $sendmail_tools->cleanHtml($_REQUEST['body_from_html']); + } else { + $body = $_REQUEST['body_from_raw']; + } + + //Status + if ($_REQUEST['for'] == 'save') { + $email_status = 'D'; + } else if ($_REQUEST['for'] == 'send'){ + $email_status = 'W'; + } + + //Query + $stmt = $db->query( + "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, + res_attachment_id_list, res_version_att_id_list,note_id_list, is_html, email_status, creation_date, sender_email) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, ?)", + 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) + ); + + + //Last insert ID from sequence + $id = $request->last_insert_id('sendmail_email_id_seq'); + + //History + if ($_SESSION['history']['mailadd']) { + $hist = new history(); + if (isset($_REQUEST['origin']) && $_REQUEST['origin'] == "folder") { + $hist->add( + $table, $identifier, "UP", 'folderup', _EMAIL_ADDED . _ON_FOLDER_NUM + . $identifier . ' (' . $id . ') : "' . $request->cut_string($object, 254) .'"', + $_SESSION['config']['databasetype'], 'sendmail' + ); + } else if (isset($_REQUEST['origin']) && $_REQUEST['origin'] == "document") { + $hist->add( + $view, $identifier, "UP", 'resup', _EMAIL_ADDED . _ON_DOC_NUM + . $identifier . ' (' . $id . ') : "' . $request->cut_string($object, 254) .'"', + $_SESSION['config']['databasetype'], 'sendmail' + ); + } - //History - if ($_SESSION['history']['mailadd']) { - $hist = new history(); - if (isset($_REQUEST['origin']) && $_REQUEST['origin'] == "folder") { - $hist->add( - $table, $identifier, "UP", 'folderup', _EMAIL_ADDED . _ON_FOLDER_NUM - . $identifier . ' (' . $id . ') : "' . $request->cut_string($object, 254) .'"', - $_SESSION['config']['databasetype'], 'sendmail' - ); - } else if (isset($_REQUEST['origin']) && $_REQUEST['origin'] == "document") { $hist->add( - $view, $identifier, "UP", 'resup', _EMAIL_ADDED . _ON_DOC_NUM - . $identifier . ' (' . $id . ') : "' . $request->cut_string($object, 254) .'"', + EMAILS_TABLE, $id, "ADD", 'mailadd', _EMAIL_ADDED . ' (' . $id . ')', $_SESSION['config']['databasetype'], 'sendmail' ); } - - $hist->add( - EMAILS_TABLE, $id, "ADD", 'mailadd', _EMAIL_ADDED . ' (' . $id . ')', - $_SESSION['config']['databasetype'], 'sendmail' - ); + + //Reload and show message + $js = $list_origin."window.parent.top.$('main_info').innerHTML = '"._EMAIL_ADDED."';"; + + } else { + $status = 1; } - - //Reload and show message - $js = $list_origin."window.parent.top.$('main_info').innerHTML = '"._EMAIL_ADDED."';"; - } else { $status = 1; } @@ -306,15 +320,13 @@ switch ($mode) { $status = 1; } } else { + $error = $request->wash_html(_EMAIL_OBJECT.' '._IS_EMPTY.'!','NONE'); $status = 1; } } else { - $error = $request->wash_html(_EMAIL_OBJECT.' '._IS_EMPTY.'!','NONE'); + $error = $request->wash_html(_SEND_TO.' '._IS_EMPTY.'!','NONE'); $status = 1; } - } else { - $error = $request->wash_html(_SEND_TO.' '._IS_EMPTY.'!','NONE'); - $status = 1; } } break; @@ -499,11 +511,6 @@ switch ($mode) { //Reload and show message $js = $list_origin."window.parent.top.$('main_info').innerHTML = '"._EMAIL_REMOVED."';"; - - - - - } else { $error = $request->wash_html(_ID.' '._IS_EMPTY.'!','NONE'); $status = 1; @@ -513,7 +520,6 @@ switch ($mode) { break; case 'adress': if (isset($_REQUEST['for']) && isset($_REQUEST['field']) && isset($_REQUEST['email'])) { - // if (isset($_REQUEST['email']) && !empty($_REQUEST['email'])) { //Clean up email $email = trim($_REQUEST['email']); @@ -541,6 +547,69 @@ switch ($mode) { $status = 1; } break; + case 'destUser': + if (isset($_REQUEST['for']) && isset($_REQUEST['field']) && isset($_REQUEST['contactAddress'])) { + if (isset($_REQUEST['contactAddress']) && !empty($_REQUEST['contactAddress'])) { + $contactAddress = trim($_REQUEST['contactAddress']); + if (!isset($_SESSION['adresses'][$_REQUEST['field']])) $_SESSION['adresses'][$_REQUEST['field']] = array(); + + if ($_REQUEST['for'] == 'add') { + $contactLabel = ContactsModel::getContactFullLabel(['addressId' => $contactAddress]); + $contactInfo = ContactsModel::getFullAddressById(['addressId' => $contactAddress]); + $contactCommunication = ContactsModel::getContactCommunication(['contactId' => $contactInfo[0]['contact_id']]); + $_SESSION['adresses'][$_REQUEST['field']][$contactAddress] = $contactLabel.'. ('._COMMUNICATION_TYPE.' : '.$contactCommunication['value'].'))'; + + } else if ($_REQUEST['for'] == 'del') { + unset($_SESSION['adresses'][$_REQUEST['field']][$_REQUEST['index']]); + //If no adresse for field, unset the entire sub-array + if (count($_SESSION['adresses'][$_REQUEST['field']]) == 0) + unset($_SESSION['adresses'][$_REQUEST['field']]); + } + + $content = $sendmail_tools->updateContactInputField($path_to_script, $_SESSION['adresses'], $_REQUEST['field']); + } else { + $error = $request->wash_html(_EMAIL.' '._IS_EMPTY.'!','NONE'); + $status = 1; + } + } else { + $error = $request->wash_html(_UNKNOW_ERROR.'!','NONE'); + $status = 1; + } + break; + case 'download': + require_once 'modules/export_seda/RequestSeda.php'; + $RequestSeda = new RequestSeda(); + $messageExchangeData = $RequestSeda->getMessageByIdentifierAndResId(['message_id' => $_GET['id'], 'res_id_master' => $_GET['identifier']]); + + $docserver = \Core\Models\DocserverModel::getById(['docserver_id' => $messageExchangeData->docserver_id]); + $docserverType = \Core\Models\DocserverTypeModel::getById(['docserver_type_id' => $docserver[0]['docserver_type_id']]); + + $pathDirectory = str_replace('#', DIRECTORY_SEPARATOR, $messageExchangeData->path); + $filePath = $docserver[0]['path_template'] . $pathDirectory . $messageExchangeData->filename; + $fingerprint = \Core\Controllers\DocserverToolsController::doFingerprint([ + 'path' => $filePath, + 'fingerprintMode' => $docserverType[0]['fingerprint_mode'], + ]); + + if($fingerprint['fingerprint'] != $messageExchangeData->fingerprint){ + echo _PB_WITH_FINGERPRINT_OF_DOCUMENT;exit; + } + + if(file_exists($filePath)){ + header('Pragma: public'); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Cache-Control: public'); + header('Content-Description: File Transfer'); + header('Content-Type: ' . strtolower(mime_content_type($filePath))); + header("Content-length: " . filesize($filePath)); + header('Content-Disposition: attachment; filename=' . basename($messageExchangeData->reference.'.zip') . ';'); + header("Content-Type: application/force-download"); + header('Content-Transfer-Encoding: binary'); + readfile($filePath); + exit(); + } + exit(); } echo "{status : " . $status . ", content : '" . addslashes(_parse($content)) . "', error : '" . addslashes(_parse_error($error)) . "', exec_js : '".addslashes($js)."'}"; exit (); diff --git a/modules/sendmail/xml/IVS/validation_rules.xml b/modules/sendmail/xml/IVS/validation_rules.xml index a112fc6ad9c..d6d22874802 100755 --- a/modules/sendmail/xml/IVS/validation_rules.xml +++ b/modules/sendmail/xml/IVS/validation_rules.xml @@ -1,7 +1,7 @@ <validationRules> <validationRule name="sendmail_ajax_content" extends="standardForm" mode="error"> <parameter name="module" type="identifier" /> - <parameter name="id" type="integer" /> + <parameter name="id" type="base64" /> <parameter name="identifier" type="integer" /> <parameter name="origin" type="identifier" /> <parameter name="coll_id" type="collection_list" /> @@ -27,6 +27,9 @@ <parameter name="templateMail" type="integer" /> <parameter name="selectSignatures" type="string" /> <parameter name="action" type="string" /> + <parameter name="formContent" type="string" /> + <parameter name="main_exchange_doc" type="string" /> + <parameter name="contactAddress" type="integer" /> </validationRule> <validationRule name="mail_form" extends="standardForm" mode="error"> @@ -34,8 +37,9 @@ <parameter name="identifier" type="integer" /> <parameter name="origin" type="identifier" /> <parameter name="coll_id" type="collection_list" /> - <parameter name="id" type="integer" /> + <parameter name="id" type="base64" /> <parameter name="size" type="size" /> + <parameter name="formContent" type="string" /> </validationRule> <validationRule name="sendmail" extends="standardForm" mode="error"> @@ -52,5 +56,3 @@ </validationRule> </validationRules> - - diff --git a/modules/sendmail/xml/menu.xml b/modules/sendmail/xml/menu.xml index fa75d84946a..d32c3afe078 100755 --- a/modules/sendmail/xml/menu.xml +++ b/modules/sendmail/xml/menu.xml @@ -1,3 +1,10 @@ <?xml version="1.0" encoding="utf-8"?> -<root> -</root> \ No newline at end of file +<ROOT> + <MENU> + <id>save_numeric_package</id> + <libconst>_SAVE_NUMERIC_PACKAGE</libconst> + <url>/saveNumericPackage</url> + <style>fa fa-file-archive-o</style> + <angular>true</angular> + </MENU> +</ROOT> diff --git a/modules/sendmail/xml/services.xml b/modules/sendmail/xml/services.xml index 3e5e103166c..6c4456c5735 100755 --- a/modules/sendmail/xml/services.xml +++ b/modules/sendmail/xml/services.xml @@ -30,4 +30,12 @@ <page>mail_form.php</page> </WHEREAMIUSED> </SERVICE> -</root> \ No newline at end of file + <SERVICE> + <id>save_numeric_package</id> <!-- if servicetype = menu, this id must be equal to the id of the menu item --> + <name>_SAVE_NUMERIC_PACKAGE</name> + <comment>_SAVE_NUMERIC_PACKAGE</comment> + <servicetype>menu</servicetype> + <system_service>false</system_service> + <enabled>true</enabled> + </SERVICE> +</root> -- GitLab