diff --git a/modules/sendmail/batch/process_emails.php b/modules/sendmail/batch/process_emails.php index 0c8c9b987782102f1e852ee51df57fdb3af11c60..22f0b4d87630adb040f9e4bfc84d9d4840742cee 100755 --- a/modules/sendmail/batch/process_emails.php +++ b/modules/sendmail/batch/process_emails.php @@ -203,6 +203,30 @@ while ($state <> 'END') { } } } + + //Res version attachment + if (!empty($email->res_version_att_id_list)) { + $attachments = explode(',', $email->res_version_att_id_list); + foreach($attachments as $attachment_id) { + $GLOBALS['logger']->write("set attachment version on res attachment : " . $attachment_id, 'INFO'); + $attachmentFile = $sendmail_tools->getAttachment( + $email->coll_id, + $email->res_id, + $attachment_id, + true + ); + if(is_file($attachmentFile['file_path'])) { + //Filename + $attachmentFilename = $sendmail_tools->createFilename($attachmentFile['label'], $attachmentFile['ext']); + $GLOBALS['logger']->write("set attachment version filename : " . $attachmentFilename, 'INFO'); + + //File content + $file_content = $GLOBALS['mailer']->getFile($attachmentFile['file_path']); + //Add file + $GLOBALS['mailer']->addAttachment($file_content, $attachmentFilename, $attachmentFile['mime_type']); + } + } + } //Notes if (!empty($email->note_id_list)) { diff --git a/modules/sendmail/class/class_modules_tools_Abstract.php b/modules/sendmail/class/class_modules_tools_Abstract.php index 4825177546d569b95b3070f69735c6a20c42c7ad..803623d8c78d38f18150220ddf8d594ae82cc034 100644 --- a/modules/sendmail/class/class_modules_tools_Abstract.php +++ b/modules/sendmail/class/class_modules_tools_Abstract.php @@ -128,6 +128,7 @@ abstract class SendmailAbstract extends Database . EMAILS_TABLE . " where email_id = ? and (is_res_master_attached ='Y' or" . " res_attachment_id_list <> '' or" + . " res_version_att_id_list <> '' or" . " res_version_id_list <> '' or" . " note_id_list <> '')", array($id ) ); @@ -177,12 +178,12 @@ abstract class SendmailAbstract extends Database array_push( $joinedFiles, - array('id' => $res->res_id, //ID - 'label' => $this->show_string($label), //Label - 'format' => $res->format, //Format - 'filesize' => $res->filesize, //Filesize + array('id' => $res->res_id, //ID + 'label' => $this->show_string($label), //Label + 'format' => $res->format, //Format + 'filesize' => $res->filesize, //Filesize 'is_version' => true, //Have version bool - 'version' => $res->relation //Version + 'version' => $res->relation //Version ) ); } @@ -196,20 +197,19 @@ abstract class SendmailAbstract extends Database } else { include_once 'modules/attachments/attachments_tables.php'; $stmt = $db->query( - "SELECT rva.res_id, rva.description, rva.subject, rva.title, rva.format, rva.filesize, rva.res_id_master, rva.attachment_type, rva.identifier, cv2.society, cv2.firstname, cv2.lastname, rva.filename, rva.path + "SELECT rva.res_id, rva.res_id_version, rva.description, rva.subject, rva.title, rva.format, rva.filesize, rva.res_id_master, rva.attachment_type, rva.identifier, cv2.society, cv2.firstname, cv2.lastname, rva.filename, rva.path FROM res_view_attachments rva LEFT JOIN contacts_v2 cv2 ON rva.dest_contact_id = cv2.contact_id WHERE rva.res_id_master = ? and rva.coll_id = ? and rva.status <> 'DEL' and rva.status <> 'OBS' and rva.attachment_type NOT IN ('converted_pdf','print_folder') ORDER BY rva.attachment_type, rva.description", array($id, $coll_id) ); } - // $db->show(); while ($res = $stmt->fetchObject()) { //check converted_pdf - $pathConvert = $res->path; - $realFilename = explode('.', $res->filename); + $pathConvert = $res->path; + $realFilename = explode('.', $res->filename); $filenameConvert = $realFilename[0].'.pdf'; - //var_dump($filenameConvert); + $stmt2 = $db->query( "SELECT rva.res_id FROM res_view_attachments rva WHERE rva.path = ? and rva.filename = ? and rva.attachment_type = 'converted_pdf'", @@ -225,20 +225,28 @@ abstract class SendmailAbstract extends Database elseif (strlen(trim($res->description)) > 0) $label = $res->description; + if(!empty($res->res_id)) { + $id = $res->res_id; + $isVersion = false; + } else { + $id = $res->res_id_version; + $isVersion = true; + } + array_push( $joinedFiles, - array('id' => $res->res_id, //ID - 'label' => $this->show_string($label), //Label - 'format' => $res->format, //Format - 'filesize' => $res->filesize, //Filesize - 'is_version' => false, // - 'version' => '', // + array('id' => $id, //ID + 'label' => $this->show_string($label), //Label + 'format' => $res->format, //Format + 'filesize' => $res->filesize, //Filesize + 'is_version' => $isVersion, + 'version' => '', 'attachment_type' => $res->attachment_type, - 'identifier' => $res->identifier, - 'society' => $res->society, - 'firstname' => $res->firstname, - 'lastname' => $res->lastname, - 'converted_pdf' => $converted->res_id + 'identifier' => $res->identifier, + 'society' => $res->society, + 'firstname' => $res->firstname, + 'lastname' => $res->lastname, + 'converted_pdf' => $converted->res_id ) ); } @@ -293,7 +301,6 @@ abstract class SendmailAbstract extends Database if (!empty($id)) { $db = new Database(); if ($owner=== true) { - $where = " and user_id = ? "; $arrayPDO = array($_SESSION['user']['UserId']); $stmt = $db->query( @@ -311,10 +318,10 @@ abstract class SendmailAbstract extends Database } if ($stmt->rowCount() > 0) { - $res = $stmt->fetchObject(); - $email['id'] = $res->email_id; + $res = $stmt->fetchObject(); + $email['id'] = $res->email_id; $email['collId'] = $res->coll_id; - $email['resId'] = $res->res_id; + $email['resId'] = $res->res_id; $email['userId'] = $res->user_id; $email['to'] = array(); if (!empty($res->to_list)) { @@ -336,20 +343,24 @@ abstract class SendmailAbstract extends Database if (!empty($res->res_attachment_id_list)) { $email['attachments'] = explode(',', $res->res_attachment_id_list); } + $email['attachments_version'] = array(); + if (!empty($res->res_version_att_id_list)) { + $email['attachments_version'] = explode(',', $res->res_version_att_id_list); + } $email['notes'] = array(); if (!empty($res->note_id_list)) { $email['notes'] = explode(',', $res->note_id_list); } - $email['object'] = $this->show_string($res->email_object); - $body = str_replace('###', ';', $res->email_body); - $body = str_replace('___', '--', $body); - $email['body'] = $this->show_string($body); + $email['object'] = $this->show_string($res->email_object); + $body = str_replace('###', ';', $res->email_body); + $body = str_replace('___', '--', $body); + $email['body'] = $this->show_string($body); $email['resMasterAttached'] = $res->is_res_master_attached; - $email['isHtml'] = $res->is_html; - $email['status'] = $res->email_status; - $email['creationDate'] = $this->format_date_db($res->creation_date); - $email['sendDate'] = $this->format_date_db($res->send_date); - $email['sender_email'] = $res->sender_email; + $email['isHtml'] = $res->is_html; + $email['status'] = $res->email_status; + $email['creationDate'] = $this->format_date_db($res->creation_date); + $email['sendDate'] = $this->format_date_db($res->send_date); + $email['sender_email'] = $res->sender_email; } } @@ -361,7 +372,6 @@ abstract class SendmailAbstract extends Database $content = ''; //Init with loading div $content .= '<div id="loading_'.$inputField.'" style="display:none;"><i class="fa fa-spinner fa-spin" title="loading..."></i></div>'; - // $content .= print_r($adressArray, true); //Get info from session array and display tag if (isset($adressArray[$inputField]) && count($adressArray[$inputField]) > 0) { foreach ($adressArray[$inputField] as $key => $adress) { @@ -403,7 +413,6 @@ abstract class SendmailAbstract extends Database . 'docservers_controler.php'; $docserverControler = new docservers_controler(); $docserverLocation = array(); - // echo '--> '.$coll_id.'/'.$res_id.'/'.$table.'/'.$adrTable.PHP_EOL; $docserverLocation = $docserverControler->retrieveDocserverNetLinkOfResource( $res_id, $table, $adrTable ); @@ -436,17 +445,13 @@ abstract class SendmailAbstract extends Database $label = $res->description; $viewResourceArr['label'] = $this->show_string($label); - //$viewResourceArr['status'] /ko /ok - //$viewResourceArr['error'] - // $this->show_array($viewResourceArr); } return $viewResourceArr; } - public function getAttachment($coll_id, $res_id_master, $res_attachment) + public function getAttachment($coll_id, $res_id_master, $res_attachment, $isVersion = false) { - include_once 'modules/attachments/attachments_tables.php'; include_once 'core/core_tables.php'; include_once 'core/docservers_tools.php'; @@ -454,9 +459,14 @@ abstract class SendmailAbstract extends Database $viewAttachmentArr = array(); $db = new Database(); + if(!$isVersion){ + $table = "res_attachments"; + } else { + $table = "res_version_attachments"; + } $stmt = $db->query( "select description, subject, title, docserver_id, path, filename, format from " - . RES_ATTACHMENTS_TABLE . " where res_id = ? and coll_id = ? and res_id_master = ? ", + . $table . " where res_id = ? and coll_id = ? and res_id_master = ? ", array($res_attachment, $coll_id, $res_id_master) ); if ($stmt->rowCount() > 0) { @@ -468,11 +478,11 @@ abstract class SendmailAbstract extends Database $label = $line->subject; elseif (strlen(trim($line->description)) > 0) $label = $line->description; - // + $docserver = $line->docserver_id; - $path = $line->path; - $filename = $line->filename; - $format = $line->format; + $path = $line->path; + $filename = $line->filename; + $format = $line->format; $stmt = $db->query( "select path_template from " . _DOCSERVERS_TABLE_NAME . " where docserver_id = ? ", @@ -494,47 +504,44 @@ abstract class SendmailAbstract extends Database copy($file, $filePathOnTmp); $viewAttachmentArr = array( - 'status' => 'ok', - 'label' => $this->show_string($label), - 'mime_type' => $mimeType, - 'ext' => $format, + 'status' => 'ok', + 'label' => $this->show_string($label), + 'mime_type' => $mimeType, + 'ext' => $format, 'file_content' => '', - 'tmp_path' => $_SESSION['config'] - ['tmppath'], - 'file_path' => $filePathOnTmp, + 'tmp_path' => $_SESSION['config']['tmppath'], + 'file_path' => $filePathOnTmp, 'called_by_ws' => '', - 'error' => '' + 'error' => '' ); } else { $viewAttachmentArr = array( - 'status' => 'ko', - 'label' => '', - 'mime_type' => '', - 'ext' => '', + 'status' => 'ko', + 'label' => '', + 'mime_type' => '', + 'ext' => '', 'file_content' => '', - 'tmp_path' => '', - 'file_path' => '', + 'tmp_path' => '', + 'file_path' => '', 'called_by_ws' => '', - 'error' => _FILE_NOT_EXISTS_ON_THE_SERVER + 'error' => _FILE_NOT_EXISTS_ON_THE_SERVER ); } } else { $viewAttachmentArr = array( - 'status' => 'ko', - 'label' => '', - 'mime_type' => '', - 'ext' => '', + 'status' => 'ko', + 'label' => '', + 'mime_type' => '', + 'ext' => '', 'file_content' => '', - 'tmp_path' => '', - 'file_path' => '', + 'tmp_path' => '', + 'file_path' => '', 'called_by_ws' => '', - 'error' => _NO_RIGHT_ON_RESOURCE_OR_RESOURCE_NOT_EXISTS + 'error' => _NO_RIGHT_ON_RESOURCE_OR_RESOURCE_NOT_EXISTS ); } - // $this->show_array($viewAttachmentArr); - return $viewAttachmentArr; } @@ -876,4 +883,3 @@ abstract class SendmailAbstract extends Database } } - diff --git a/modules/sendmail/js/functions.js b/modules/sendmail/js/functions.js index 8c52ba5f15e6e28c77319e1a334f2eeb9daf451f..61b0fc7c021b0ddb8df61424c65c86b0ae2d45a7 100644 --- a/modules/sendmail/js/functions.js +++ b/modules/sendmail/js/functions.js @@ -245,6 +245,9 @@ MyAjax.Autocompleter = Class.create(Ajax.Autocompleter, { function clickAttachments(id){ $("join_file_"+id).click(); } +function clickAttachmentsInput(id){ + $("join_attachment_"+id).click(); +} function clickAttachmentsNotes(id){ $("note_"+id).click(); } \ No newline at end of file diff --git a/modules/sendmail/mail_form.php b/modules/sendmail/mail_form.php index 9d47edf11590767beb5b27b41ef7ef33e2bc445c..ee38fd1f444cafb03c57a49d8bead9b60fada209 100644 --- a/modules/sendmail/mail_form.php +++ b/modules/sendmail/mail_form.php @@ -103,7 +103,7 @@ $core_tools->load_header('', true, false); $core_tools->load_js(); //ADD if ($mode == 'add') { - $content .= '<div class="block">'; + $content .= '<div>'; $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">'; @@ -249,13 +249,13 @@ if ($mode == 'add') { $content .='<div style="color:rgb(22, 173, 235);font-weight:bold;">'._DOC.'</div>'; for($i=0; $i < count($joined_files); $i++) { //Get data - $id = $joined_files[$i]['id']; + $id = $joined_files[$i]['id']; $description = $joined_files[$i]['label']; - $format = $joined_files[$i]['format']; - $format = $joined_files[$i]['format']; - $mime_type = $is->get_mime_type($joined_files[$i]['format']); - $att_type = $joined_files[$i]['format']; - $filesize = $joined_files[$i]['filesize']/1024; + $format = $joined_files[$i]['format']; + $format = $joined_files[$i]['format']; + $mime_type = $is->get_mime_type($joined_files[$i]['format']); + $att_type = $joined_files[$i]['format']; + $filesize = $joined_files[$i]['filesize']/1024; ($filesize > 1)? $filesize = ceil($filesize).' Ko' : $filesize = round($filesize,2).' Octets'; //Show data $version = ''; @@ -296,45 +296,44 @@ if ($mode == 'add') { $content .='<br/>'; $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%;\">"; - //var_dump($attachment_files); + for($i=0; $i < count($attachment_files); $i++) { $it = $i+1; - //nouvelle ligne toutes les 3 infos - //if($it%4 == 0 || $it == 1){ - $content .= "<tr style=\"vertical-align:top;\">"; - //} + $content .= "<tr style=\"vertical-align:top;\">"; //Get data - $id = $attachment_files[$i]['id']; + $id = $attachment_files[$i]['id']; + $isVersion = $attachment_files[$i]['is_version']; $id_converted = $attachment_files[$i]['converted_pdf']; - $description = $attachment_files[$i]['label']; + $description = $attachment_files[$i]['label']; if (strlen($description) > 73) { $description = substr($description, 0, 70); $description .= "..."; } - $format = $attachment_files[$i]['format']; - $mime_type = $is->get_mime_type($attachment_files[$i]['format']); - $att_type = $attachment_files[$i]['format']; - $filesize = $attachment_files[$i]['filesize']/1024; + $format = $attachment_files[$i]['format']; + $mime_type = $is->get_mime_type($attachment_files[$i]['format']); + $att_type = $attachment_files[$i]['format']; + $filesize = $attachment_files[$i]['filesize']/1024; $attachment_type = $_SESSION['attachment_types'][$attachment_files[$i]['attachment_type']]; - $chrono = $attachment_files[$i]['identifier']; - $dest_society = $attachment_files[$i]['society']; - $dest_firstname = $attachment_files[$i]['firstname']; - $dest_lastname = $attachment_files[$i]['lastname']; + $chrono = $attachment_files[$i]['identifier']; + $dest_society = $attachment_files[$i]['society']; + $dest_firstname = $attachment_files[$i]['firstname']; + $dest_lastname = $attachment_files[$i]['lastname']; ($filesize > 1)? $filesize = ceil($filesize).' Ko' : $filesize = $filesize.' Octets'; + if($isVersion){ + $inputName = "join_version_attachment[]"; + } else { + $inputName = "join_attachment[]"; + } + $content .= "<th style=\"width:25px;border: dashed 1px grey;border-right:none;vertical-align:middle;\" alt=\"".$description . "\" title=\"".$description - . "\"><input style=\"margin-left: 3px\" type=\"checkbox\" id=\"join_file_".$id."\" name=\"join_attachment[]\"" + . "\"><input style=\"margin-left: 3px\" type=\"checkbox\" id=\"join_attachment_".$i."\" name=\"".$inputName."\"" . " class=\"check\" value=\"" . $id."\""; - /*if ($_SESSION['attachment_types_attach_in_mail'][$attachment_type]) { - $content .= " checked=\"checked\" "; - }*/ - /* - avec la condition ci-dessous, toutes les réponses signées sont cochées lorsqu'on veut envoyer le courrier par mail - */ + // avec la condition ci-dessous, toutes les réponses signées sont cochées lorsqu'on veut envoyer le courrier par mail if ($attachment_type == _SIGNED_RESPONSE) { $content .= " checked=\"checked\" "; } @@ -342,14 +341,14 @@ if ($mode == 'add') { if(!$id_converted){ $content .= "<td style=\"cursor:pointer;border: dashed 1px grey;border-left:none;padding:5px;\""; - $content .= ' onclick="clickAttachments('.$id.')" '; + $content .= ' onclick="clickAttachmentsInput('.$i.')" '; }else{ $content .= "<td style=\"border: dashed 1px grey;border-left:none;padding:5px;\""; } $content .= "><span style=\"font-size: 10px;color: rgb(22, 173, 235);\">" . $attachment_type . "</span> <span style=\"font-size: 10px;color: grey;\">(" . $att_type . " - " . $filesize .")</span><br/><strong>" . $description . "</strong>"; if($id_converted){ - $content .= " (<input style=\"margin: 0px\" title=\"envoyer la version PDF\" type=\"checkbox\" id=\"join_file_".$id_converted."\" name=\"join_attachment[]\"" + $content .= " (<input style=\"margin: 0px\" title=\"envoyer la version PDF\" type=\"checkbox\" id=\"join_attachment_".$id_converted."\" name=\"join_attachment[]\"" . " class=\"check\" value=\"" . $id_converted."\" />version pdf)"; } @@ -359,13 +358,10 @@ if ($mode == 'add') { $content .= "<span style='font-size: 10px;color: grey;font-style:italic;'>" . $dest_firstname . " " . $dest_lastname. " " . $dest_society . "</span>"; $content .= "</td>"; - //if($it%3 == 0 && $it != 1){ - $content .= "</tr>"; - //} + $content .= "</tr>"; $filename = $sendmail_tools->createFilename($description, $format); - // $all_joined_files .= $description.': '.$filename.PHP_EOL; } $content .= "</table>"; } @@ -383,10 +379,7 @@ if ($mode == 'add') { $content .= "<table cellspacing=\"3\" style=\"border-collapse:collapse;width:100%;\">"; for($i=0; $i < count($user_notes); $i++) { $it = $i+1; - //nouvelle ligne toutes les 3 infos - //if($it%4 == 0 || $it == 1){ - $content .= "<tr style=\"vertical-align:top;\">"; - //} + $content .= "<tr style=\"vertical-align:top;\">"; //Get data $id = $user_notes[$i]['id']; @@ -404,12 +397,9 @@ if ($mode == 'add') { $content .= "title=\"".$note."\"><span style=\"font-size: 10px;color: rgb(22, 173, 235);\">".$userArray['firstname']." ".$userArray['lastname']." </span><span style=\"font-size: 10px;color: grey;\">".$date."</span><br/>" ."<strong>". $noteShort."</strong></td>"; - //if($it%3 == 0 && $it != 1){ - $content .= "</tr>"; - //} + $content .= "</tr>"; } - // $all_joined_files .= _NOTES.": notes_".$identifier."_".date(dmY).".html\n"; $content .= "</table>"; } } @@ -494,7 +484,7 @@ if ($mode == 'add') { //Check if mail exists if (count($emailArray) > 0 ) { - $content .= '<div class="block">'; + $content .= '<div>'; $content .= '<form name="formEmail" id="formEmail" method="post" action="#">'; $content .= '<input type="hidden" value="'.$identifier.'" name="identifier" id="identifier">'; $content .= '<input type="hidden" value="'.$id.'" name="id" id="id">'; @@ -609,13 +599,13 @@ if ($mode == 'add') { $content .='<div style="color:rgb(22, 173, 235);font-weight:bold;">'._DOC.'</div>'; for($i=0; $i < count($joined_files); $i++) { //Get data - $id = $joined_files[$i]['id']; + $id = $joined_files[$i]['id']; $description = $joined_files[$i]['label']; - $format = $joined_files[$i]['format']; - $format = $joined_files[$i]['format']; - $mime_type = $is->get_mime_type($joined_files[$i]['format']); - $att_type = $joined_files[$i]['format']; - $filesize = $joined_files[$i]['filesize']/1024; + $format = $joined_files[$i]['format']; + $format = $joined_files[$i]['format']; + $mime_type = $is->get_mime_type($joined_files[$i]['format']); + $att_type = $joined_files[$i]['format']; + $filesize = $joined_files[$i]['filesize']/1024; ($filesize > 1)? $filesize = ceil($filesize).' Ko' : $filesize = round($filesize,2).' Octets'; //Show data @@ -665,44 +655,47 @@ 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; - //nouvelle ligne toutes les 3 infos - //if($it%4 == 0 || $it == 1){ - $content .= "<tr style=\"vertical-align:top;\">"; - //} + $content .= "<tr style=\"vertical-align:top;\">"; //Get data - $id = $attachment_files[$i]['id']; + $id = $attachment_files[$i]['id']; + $isVersion = $attachment_files[$i]['is_version']; $id_converted = $attachment_files[$i]['converted_pdf']; - $description = $attachment_files[$i]['label']; + $description = $attachment_files[$i]['label']; if (strlen($description) > 73) { $description = substr($description, 0, 70); $description .= "..."; } - $format = $attachment_files[$i]['format']; - $mime_type = $is->get_mime_type($attachment_files[$i]['format']); - $att_type = $attachment_files[$i]['format']; - $filesize = $attachment_files[$i]['filesize']/1024; + $format = $attachment_files[$i]['format']; + $mime_type = $is->get_mime_type($attachment_files[$i]['format']); + $att_type = $attachment_files[$i]['format']; + $filesize = $attachment_files[$i]['filesize']/1024; $attachment_type = $_SESSION['attachment_types'][$attachment_files[$i]['attachment_type']]; - $chrono = $attachment_files[$i]['identifier']; - $dest_society = $attachment_files[$i]['society']; - $dest_firstname = $attachment_files[$i]['firstname']; - $dest_lastname = $attachment_files[$i]['lastname']; + $chrono = $attachment_files[$i]['identifier']; + $dest_society = $attachment_files[$i]['society']; + $dest_firstname = $attachment_files[$i]['firstname']; + $dest_lastname = $attachment_files[$i]['lastname']; ($filesize > 1)? $filesize = ceil($filesize).' Ko' : $filesize = $filesize.' Octets'; - + + if($isVersion){ + $inputName = "join_version_attachment[]"; + } else { + $inputName = "join_attachment[]"; + } + $content .= "<th style=\"width:25px;border: dashed 1px grey;border-right:none;vertical-align:middle;\" alt=\"".$description . "\" title=\"".$description - . "\"><input style=\"margin-left: 3px\" type=\"checkbox\" id=\"join_file_".$id."\" name=\"join_attachment[]\""; - (in_array($id, $emailArray['attachments']))? $checked = ' checked="checked"' : $checked = ''; + . "\"><input style=\"margin-left: 3px\" type=\"checkbox\" id=\"join_attachment_".$id."\" name=\"".$inputName."\""; + + if(($isVersion && in_array($id, $emailArray['attachments_version'])) || (!$isVersion && in_array($id, $emailArray['attachments']))){ + $checked = ' checked="checked"'; + } + $content .= " ".$checked . " class=\"check\" value=\"" . $id."\""; - /*if ($_SESSION['attachment_types_attach_in_mail'][$attachment_type]) { - $content .= " checked=\"checked\" "; - }*/ - /* - avec la condition ci-dessous, toutes les réponses signées sont cochées lorsqu'on veut envoyer le courrier par mail - */ + //avec la condition ci-dessous, toutes les réponses signées sont cochées lorsqu'on veut envoyer le courrier par mail if ($attachment_type == _SIGNED_RESPONSE && $mode == 'transfer') { $content .= " checked=\"checked\" "; } @@ -710,14 +703,14 @@ if ($mode == 'add') { if(!$id_converted){ $content .= "<td style=\"cursor:pointer;border: dashed 1px grey;border-left:none;padding:5px;\""; - $content .= ' onclick="clickAttachments('.$id.')" '; + $content .= ' onclick="clickAttachmentsInput('.$id.')" '; }else{ $content .= "<td style=\"border: dashed 1px grey;border-left:none;padding:5px;\""; } $content .= "><span style=\"font-size: 10px;color: rgb(22, 173, 235);\">" . $attachment_type . "</span> <span style=\"font-size: 10px;color: grey;\">(" . $att_type . " - " . $filesize .")</span><br/><strong>" . $description . "</strong>"; if($id_converted){ - $content .= " (<input style=\"margin: 0px\" title=\"envoyer la version PDF\" type=\"checkbox\" id=\"join_file_".$id_converted."\" name=\"join_attachment[]\"" + $content .= " (<input style=\"margin: 0px\" title=\"envoyer la version PDF\" type=\"checkbox\" id=\"join_attachment_".$id_converted."\" name=\"join_attachment[]\"" . " class=\"check\""; (in_array($id_converted, $emailArray['attachments']))? $checked = ' checked="checked"' : $checked = ''; @@ -731,9 +724,8 @@ if ($mode == 'add') { $content .= "<span style='font-size: 10px;color: grey;font-style:italic;'>" . $dest_firstname . " " . $dest_lastname. " " . $dest_society . "</span>"; $content .= "</td>"; - //if($it%3 == 0 && $it != 1){ - $content .= "</tr>"; - //} + $content .= "</tr>"; + //Filename $filename = $sendmail_tools->createFilename($description, $format); $all_joined_files .= $description.': '.$filename.PHP_EOL; @@ -755,10 +747,7 @@ if ($mode == 'add') { $content .= "<table cellspacing=\"3\" style=\"border-collapse:collapse;width:100%;\">"; for($i=0; $i < count($user_notes); $i++) { $it = $i+1; - //nouvelle ligne toutes les 3 infos - //if($it%4 == 0 || $it == 1){ - $content .= "<tr style=\"vertical-align:top;\">"; - //} + $content .= "<tr style=\"vertical-align:top;\">"; //Get data $id = $user_notes[$i]['id']; @@ -780,12 +769,9 @@ if ($mode == 'add') { $content .= "title=\"".$note."\"><span style=\"font-size: 10px;color: rgb(22, 173, 235);\">".$userArray['firstname']." ".$userArray['lastname']." </span><span style=\"font-size: 10px;color: grey;\">".$date."</span><br/>" ."<strong>". $noteShort."</strong></td>"; - //if($it%3 == 0 && $it != 1){ - $content .= "</tr>"; - //} + $content .= "</tr>"; } - // $all_joined_files .= _NOTES.": notes_".$identifier."_".date(dmY).".html\n"; $content .= "</table>"; //Filename $filename = "notes_".$identifier."_".date(dmY).".html"; @@ -905,7 +891,7 @@ if ($mode == 'add') { if (count($emailArray) > 0 ) { $usermailArray = $users_tools->get_user($emailArray['userId']); - $content .= '<div class="block">'; + $content .= '<div>'; $content .= '<table border="0" align="left" width="100%" cellspacing="5">'; $content .= '<tr>'; @@ -982,13 +968,13 @@ if ($mode == 'add') { $content .='<div style="color:rgb(22, 173, 235);font-weight:bold;">'._DOC.'</div>'; for($i=0; $i < count($joined_files); $i++) { //Get data - $id = $joined_files[$i]['id']; + $id = $joined_files[$i]['id']; $description = $joined_files[$i]['label']; - $format = $joined_files[$i]['format']; - $format = $joined_files[$i]['format']; - $mime_type = $is->get_mime_type($joined_files[$i]['format']); - $att_type = $joined_files[$i]['format']; - $filesize = $joined_files[$i]['filesize']/1024; + $format = $joined_files[$i]['format']; + $format = $joined_files[$i]['format']; + $mime_type = $is->get_mime_type($joined_files[$i]['format']); + $att_type = $joined_files[$i]['format']; + $filesize = $joined_files[$i]['filesize']/1024; ($filesize > 1)? $filesize = ceil($filesize).' Ko' : $filesize = round($filesize,2).' Octets'; //Show data @@ -1038,34 +1024,42 @@ 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; - //nouvelle ligne toutes les 3 infos - //if($it%4 == 0 || $it == 1){ - $content .= "<tr style=\"vertical-align:top;\">"; - //} + $content .= "<tr style=\"vertical-align:top;\">"; //Get data - $id = $attachment_files[$i]['id']; + $id = $attachment_files[$i]['id']; + $isVersion = $attachment_files[$i]['is_version']; $id_converted = $attachment_files[$i]['converted_pdf']; - $description = $attachment_files[$i]['label']; + $description = $attachment_files[$i]['label']; if (strlen($description) > 73) { $description = substr($description, 0, 70); $description .= "..."; } - $format = $attachment_files[$i]['format']; - $mime_type = $is->get_mime_type($attachment_files[$i]['format']); - $att_type = $attachment_files[$i]['format']; - $filesize = $attachment_files[$i]['filesize']/1024; + $format = $attachment_files[$i]['format']; + $mime_type = $is->get_mime_type($attachment_files[$i]['format']); + $att_type = $attachment_files[$i]['format']; + $filesize = $attachment_files[$i]['filesize']/1024; $attachment_type = $_SESSION['attachment_types'][$attachment_files[$i]['attachment_type']]; - $chrono = $attachment_files[$i]['identifier']; - $dest_society = $attachment_files[$i]['society']; - $dest_firstname = $attachment_files[$i]['firstname']; - $dest_lastname = $attachment_files[$i]['lastname']; + $chrono = $attachment_files[$i]['identifier']; + $dest_society = $attachment_files[$i]['society']; + $dest_firstname = $attachment_files[$i]['firstname']; + $dest_lastname = $attachment_files[$i]['lastname']; ($filesize > 1)? $filesize = ceil($filesize).' Ko' : $filesize = $filesize.' Octets'; - + + if($isVersion){ + $inputName = "join_version_attachment[]"; + } else { + $inputName = "join_attachment[]"; + } + $content .= "<th style=\"width:25px;border: dashed 1px grey;border-right:none;vertical-align:middle;\" alt=\"".$description . "\" title=\"".$description - . "\"><input style=\"margin-left: 3px\" disabled=\"disabled\" type=\"checkbox\" id=\"join_file_".$id."\" name=\"join_attachment[]\""; - (in_array($id, $emailArray['attachments']))? $checked = ' checked="checked"' : $checked = ''; + . "\"><input style=\"margin-left: 3px\" disabled=\"disabled\" type=\"checkbox\" id=\"join_attachment_".$id."\" name=\"".$inputName."\""; + + if(($isVersion && in_array($id, $emailArray['attachments_version'])) || (!$isVersion && in_array($id, $emailArray['attachments']))){ + $checked = ' checked="checked"'; + } + $content .= " ".$checked . " class=\"check\" value=\"" . $id."\""; @@ -1074,14 +1068,14 @@ if ($mode == 'add') { if(!$id_converted){ $content .= "<td style=\"cursor:pointer;border: dashed 1px grey;border-left:none;padding:5px;\""; - $content .= ' onclick="clickAttachments('.$id.')" '; + $content .= ' onclick="clickAttachmentsInput('.$id.')" '; }else{ $content .= "<td style=\"border: dashed 1px grey;border-left:none;padding:5px;\""; } $content .= "><span style=\"font-size: 10px;color: rgb(22, 173, 235);\">" . $attachment_type . "</span> <span style=\"font-size: 10px;color: grey;\">(" . $att_type . " - " . $filesize .")</span><br/><strong>" . $description . "</strong>"; if($id_converted){ - $content .= " (<input style=\"margin: 0px\" title=\"envoyer la version PDF\" disabled=\"disabled\" type=\"checkbox\" id=\"join_file_".$id_converted."\" name=\"join_attachment[]\"" + $content .= " (<input style=\"margin: 0px\" title=\"envoyer la version PDF\" disabled=\"disabled\" type=\"checkbox\" id=\"join_attachment_".$id_converted."\" name=\"join_attachment[]\"" . " class=\"check\""; (in_array($id_converted, $emailArray['attachments']))? $checked = ' checked="checked"' : $checked = ''; @@ -1095,9 +1089,7 @@ if ($mode == 'add') { $content .= "<span style='font-size: 10px;color: grey;font-style:italic;'>" . $dest_firstname . " " . $dest_lastname. " " . $dest_society . "</span>"; $content .= "</td>"; - //if($it%3 == 0 && $it != 1){ - $content .= "</tr>"; - //} + $content .= "</tr>"; //Filename $filename = $sendmail_tools->createFilename($description, $format); $all_joined_files .= $description.': '.$filename.PHP_EOL; @@ -1119,10 +1111,7 @@ if ($mode == 'add') { $content .= "<table cellspacing=\"3\" style=\"border-collapse:collapse;width:100%;\">"; for($i=0; $i < count($user_notes); $i++) { $it = $i+1; - //nouvelle ligne toutes les 3 infos - //if($it%4 == 0 || $it == 1){ - $content .= "<tr style=\"vertical-align:top;\">"; - //} + $content .= "<tr style=\"vertical-align:top;\">"; //Get data $id = $user_notes[$i]['id']; @@ -1144,12 +1133,9 @@ if ($mode == 'add') { $content .= "title=\"".$note."\"><span style=\"font-size: 10px;color: rgb(22, 173, 235);\">".$userArray['firstname']." ".$userArray['lastname']." </span><span style=\"font-size: 10px;color: grey;\">".$date."</span><br/>" ."<strong>". $noteShort."</strong></td>"; - //if($it%3 == 0 && $it != 1){ - $content .= "</tr>"; - //} + $content .= "</tr>"; } - // $all_joined_files .= _NOTES.": notes_".$identifier."_".date(dmY).".html\n"; $content .= "</table>"; //Filename $filename = "notes_".$identifier."_".date(dmY).".html"; diff --git a/modules/sendmail/sendmail_ajax_content.php b/modules/sendmail/sendmail_ajax_content.php index 7cdb95a5fbc5d85e692395a63ab913e37f39d541..f98f59364de04a4d66dbb9ddee9281af28f629b5 100644 --- a/modules/sendmail/sendmail_ajax_content.php +++ b/modules/sendmail/sendmail_ajax_content.php @@ -225,11 +225,15 @@ switch ($mode) { (isset($_REQUEST['join_file']) && count($_REQUEST['join_file']) > 0 )? $res_master_attached = 'Y' : $res_master_attached = 'N'; - //Version attached + //attachment if (isset($_REQUEST['join_attachment']) && count($_REQUEST['join_attachment']) > 0) { $attachment_list = join(',', $_REQUEST['join_attachment']); - } - //Attachments + } + //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']); } @@ -258,10 +262,10 @@ switch ($mode) { $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, note_id_list, is_html, email_status, creation_date, sender_email) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, ?)", + 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, $note_list, $isHtml, $email_status, $senderEmail) + $version_list, $attachment_list, $attachment_version_list, $note_list, $isHtml, $email_status, $senderEmail) ); @@ -367,6 +371,9 @@ switch ($mode) { if (isset($_REQUEST['join_attachment']) && count($_REQUEST['join_attachment']) > 0) { $attachment_list = join(',', $_REQUEST['join_attachment']); } + if (isset($_REQUEST['join_version_attachment']) && count($_REQUEST['join_version_attachment']) > 0) { + $attachment_version_list = join(',', $_REQUEST['join_version_attachment']); + } if (isset($_REQUEST['notes']) && count($_REQUEST['notes']) > 0) { $note_list = join(',', $_REQUEST['notes']); } @@ -390,10 +397,10 @@ switch ($mode) { $db->query( "UPDATE " . EMAILS_TABLE . " SET to_list = ?, cc_list = ?, cci_list = ?, email_object = ?, email_body = ?, is_res_master_attached = ?, res_version_id_list = ?, - res_attachment_id_list = ?, note_id_list = ?, + res_attachment_id_list = ?, res_version_att_id_list = ?, note_id_list = ?, is_html = ?, email_status = ?, sender_email = ? where email_id = ? " ." and res_id = ? and user_id = ?", - array($to, $cc, $cci, $object, $body, $res_master_attached, $version_list, $attachment_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, $id, $identifier, $userId ) ); diff --git a/modules/sendmail/xml/IVS/validation_rules.xml b/modules/sendmail/xml/IVS/validation_rules.xml index e668a35628eecb6094f895ff44496f11f8cc02f3..a112fc6ad9c87dd2e19aa698e93f556467c91519 100755 --- a/modules/sendmail/xml/IVS/validation_rules.xml +++ b/modules/sendmail/xml/IVS/validation_rules.xml @@ -18,6 +18,7 @@ <parameter name="body_from_raw" type="string" /> <parameter name="cancel" type="identifier" /> <parameter name="join_attachment" type="identifier" /> + <parameter name="join_version_attachment" type="identifier" /> <parameter name="join_file" type="identifier" /> <parameter name="notes" type="string" /> <parameter name="object" type="string" /> diff --git a/sql/17_xx.sql b/sql/17_xx.sql index 79d47e0734e2864d65b175bc7151323ed063a9cb..5614caa74e3aca67ef6d5eac0a9447ba8a3ce036 100644 --- a/sql/17_xx.sql +++ b/sql/17_xx.sql @@ -70,3 +70,6 @@ ALTER TABLE user_signatures ADD FOREIGN KEY (user_serial_id) REFERENCES users(id UPDATE user_signatures set user_serial_id = (select id FROM users where users.user_id = user_signatures.user_id); ALTER TABLE user_signatures ALTER COLUMN user_serial_id set not null; ALTER TABLE user_signatures DROP COLUMN IF EXISTS user_id; + +ALTER TABLE sendmail DROP COLUMN IF EXISTS res_version_att_id_list; +ALTER TABLE sendmail ADD COLUMN res_version_att_id_list character varying(255); diff --git a/sql/structure.sql b/sql/structure.sql index e463c05a772948db111b4df2d55cdab4c5bf8101..a3e292af396a1d334d01aa8429946796dfa6df11 100644 --- a/sql/structure.sql +++ b/sql/structure.sql @@ -2369,6 +2369,7 @@ CREATE TABLE sendmail is_res_master_attached character varying(1) NOT NULL DEFAULT 'Y', res_version_id_list character varying(255) DEFAULT NULL, res_attachment_id_list character varying(255) DEFAULT NULL, + res_version_att_id_list character varying(255) DEFAULT NULL, note_id_list character varying(255) DEFAULT NULL, is_html character varying(1) NOT NULL DEFAULT 'Y', email_status character varying(1) NOT NULL DEFAULT 'D',