diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php index 5726b02ac84..63d8ab77f6e 100644 --- a/htdocs/core/class/CMailFile.class.php +++ b/htdocs/core/class/CMailFile.class.php @@ -1227,8 +1227,8 @@ class CMailFile $encoded = chunk_split(base64_encode($contents), 76, $this->eol); // 76 max is defined into http://tools.ietf.org/html/rfc2047 return $encoded; } else { - $this->error = "Error: Can't read file '".$sourcefile."' into _encode_file"; - dol_syslog("CMailFile::encode_file: ".$this->error, LOG_ERR); + $this->error = "Error in _encode_file() method: Can't read file '".$sourcefile."'"; + dol_syslog("CMailFile::_encode_file: ".$this->error, LOG_ERR); return -1; } } diff --git a/htdocs/public/ticket/create_ticket.php b/htdocs/public/ticket/create_ticket.php index 80ea664292b..0c61e6a5cb2 100644 --- a/htdocs/public/ticket/create_ticket.php +++ b/htdocs/public/ticket/create_ticket.php @@ -117,12 +117,10 @@ if (empty($reshook)) { } if (GETPOST('addfile', 'alpha') && !GETPOST('save', 'alpha')) { - ////$res = $object->fetch('','',GETPOST('track_id')); - ////if($res > 0) - ////{ include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - // Set tmp directory TODO Use a dedicated directory for temp mails files + // Set tmp directory + // TODO Use a dedicated directory for temporary emails files $vardir = $conf->ticket->dir_output; $upload_dir_tmp = $vardir.'/temp/'.session_id(); if (!dol_is_dir($upload_dir_tmp)) { @@ -131,7 +129,6 @@ if (empty($reshook)) { dol_add_file_process($upload_dir_tmp, 0, 0, 'addedfile', '', null, '', 0); $action = 'create_ticket'; - ////} } // Remove file @@ -139,10 +136,11 @@ if (empty($reshook)) { include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; // Set tmp directory + // TODO Use a dedicated directory for temporary emails files $vardir = $conf->ticket->dir_output.'/'; $upload_dir_tmp = $vardir.'/temp/'.session_id(); - // TODO Delete only files that was uploaded from email form + // TODO Delete only files that was uploaded from form dol_remove_file_process(GETPOST('removedfile'), 0, 0); $action = 'create_ticket'; } @@ -345,6 +343,7 @@ if (empty($reshook)) { } if (!$error) { + // Creation of the ticket $id = $object->create($user); if ($id <= 0) { $error++; @@ -465,14 +464,7 @@ if (empty($reshook)) { } // Copy files into ticket directory - $destdir = $conf->ticket->dir_output.'/'.$object->ref; - if (!dol_is_dir($destdir)) { - dol_mkdir($destdir); - } - foreach ($filename as $i => $val) { - dol_move($filepath[$i], $destdir.'/'.$filename[$i], 0, 1); - $formmail->remove_attached_files($i); - } + $object->copyFilesForTicket(''); //setEventMessages($langs->trans('YourTicketSuccessfullySaved'), null, 'mesgs'); diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index 1286f35d913..42a72678b00 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -2271,7 +2271,7 @@ class Ticket extends CommonObject * Used for files linked into messages. * Files may be renamed during copy to avoid overwriting existing files. * - * @param string $forcetrackid Force trackid + * @param string $forcetrackid Force trackid used for $keytoavoidconflict into get_attached_files() * @return array|int Array with final path/name/mime of files. */ public function copyFilesForTicket($forcetrackid = null) @@ -2292,7 +2292,7 @@ class Ticket extends CommonObject $formmail->trackid = (is_null($forcetrackid) ? 'tic'.$this->id : ''); $attachedfiles = $formmail->get_attached_files(); - $filepath = $attachedfiles['paths']; + $filepath = $attachedfiles['paths']; // path is for example user->dir_temp.'/'.$user->id.'/'... $filename = $attachedfiles['names']; $mimetype = $attachedfiles['mimes']; @@ -2319,17 +2319,19 @@ class Ticket extends CommonObject // Move has failed $this->error = "Failed to move file ".dirbasename($filepath[$i])." into ".dirbasename($destfile); return -1; + } else { + // If file is an image, we create thumbs + if (image_format_supported($destfile) == 1) { + // Create small thumbs for image (Ratio is near 16/9) + // Used on logon for example + $imgThumbSmall = vignette($destfile, $maxwidthsmall, $maxheightsmall, '_small', 50, "thumbs"); + // Create mini thumbs for image (Ratio is near 16/9) + // Used on menu or for setup page for example + $imgThumbMini = vignette($destfile, $maxwidthmini, $maxheightmini, '_mini', 50, "thumbs"); + } } - if (image_format_supported($destfile) == 1) { - // Create small thumbs for image (Ratio is near 16/9) - // Used on logon for example - $imgThumbSmall = vignette($destfile, $maxwidthsmall, $maxheightsmall, '_small', 50, "thumbs"); - // Create mini thumbs for image (Ratio is near 16/9) - // Used on menu or for setup page for example - $imgThumbMini = vignette($destfile, $maxwidthmini, $maxheightmini, '_mini', 50, "thumbs"); - } - + // Clear variables into session $formmail->remove_attached_files($i); // Fill array with new names