public function testgetDocumentRevisionNameForDisplay() { $documentRevision = new DocumentRevision(); //test wihout setting attributes $result = $documentRevision->getDocumentRevisionNameForDisplay(); $this->assertEquals('.', $result); //test with attributes preset $documentRevision->filename = 'test.ext'; $documentRevision->revision = 1; $result = $documentRevision->getDocumentRevisionNameForDisplay(); $this->assertEquals('-Revision_1.ext', $result); }
/** * handles attachments of various kinds when sending email */ function handleAttachments() { global $mod_strings; /////////////////////////////////////////////////////////////////////////// //// ATTACHMENTS FROM DRAFTS if (($this->type == 'out' || $this->type == 'draft') && $this->status == 'draft' && isset($_REQUEST['record'])) { $this->getNotes($_REQUEST['record']); // cn: get notes from OLD email for use in new email } //// END ATTACHMENTS FROM DRAFTS /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// //// ATTACHMENTS FROM FORWARDS // Bug 8034 Jenny - Need the check for type 'draft' here to handle cases where we want to save // forwarded messages as drafts. We still need to save the original message's attachments. if (($this->type == 'out' || $this->type == 'draft') && isset($_REQUEST['origType']) && $_REQUEST['origType'] == 'forward' && isset($_REQUEST['return_id']) && !empty($_REQUEST['return_id'])) { $this->getNotes($_REQUEST['return_id'], true); } // cn: bug 8034 - attachments from forward/replies lost when saving in draft if (isset($_REQUEST['prior_attachments']) && !empty($_REQUEST['prior_attachments']) && $this->new_with_id == true) { $exIds = explode(",", $_REQUEST['prior_attachments']); if (!isset($_REQUEST['template_attachment'])) { $_REQUEST['template_attachment'] = array(); } $_REQUEST['template_attachment'] = array_merge($_REQUEST['template_attachment'], $exIds); } //// END ATTACHMENTS FROM FORWARDS /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// //// ATTACHMENTS FROM TEMPLATES // to preserve individual email integrity, we must dupe Notes and associated files // for each outbound email - good for integrity, bad for filespace if (isset($_REQUEST['template_attachment']) && !empty($_REQUEST['template_attachment'])) { $removeArr = array(); $noteArray = array(); if (isset($_REQUEST['temp_remove_attachment']) && !empty($_REQUEST['temp_remove_attachment'])) { $removeArr = $_REQUEST['temp_remove_attachment']; } foreach ($_REQUEST['template_attachment'] as $noteId) { if (in_array($noteId, $removeArr)) { continue; } $noteTemplate = new Note(); $noteTemplate->retrieve($noteId); $noteTemplate->id = create_guid(); $noteTemplate->new_with_id = true; // duplicating the note with files $noteTemplate->parent_id = $this->id; $noteTemplate->parent_type = $this->module_dir; $noteTemplate->date_entered = ''; $noteTemplate->save(); $noteFile = new UploadFile('none'); $noteFile->duplicate_file($noteId, $noteTemplate->id, $noteTemplate->filename); $noteArray[] = $noteTemplate; } $this->attachments = array_merge($this->attachments, $noteArray); } //// END ATTACHMENTS FROM TEMPLATES /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// //// ADDING NEW ATTACHMENTS $max_files_upload = 10; // Jenny - Bug 8211 Since attachments for drafts have already been processed, // we don't need to re-process them. if ($this->status != "draft") { $notes_list = array(); if (!empty($this->id) && !$this->new_with_id) { $note = new Note(); $where = "notes.parent_id='{$this->id}'"; $notes_list = $note->get_full_list("", $where, true); } $this->attachments = array_merge($this->attachments, $notes_list); } // cn: Bug 5995 - rudimentary error checking $filesError = array(0 => 'UPLOAD_ERR_OK - There is no error, the file uploaded with success.', 1 => 'UPLOAD_ERR_INI_SIZE - The uploaded file exceeds the upload_max_filesize directive in php.ini.', 2 => 'UPLOAD_ERR_FORM_SIZE - The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', 3 => 'UPLOAD_ERR_PARTIAL - The uploaded file was only partially uploaded.', 4 => 'UPLOAD_ERR_NO_FILE - No file was uploaded.', 5 => 'UNKNOWN ERROR', 6 => 'UPLOAD_ERR_NO_TMP_DIR - Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3.', 7 => 'UPLOAD_ERR_CANT_WRITE - Failed to write file to disk. Introduced in PHP 5.1.0.'); for ($i = 0; $i < $max_files_upload; $i++) { // cn: Bug 5995 - rudimentary error checking if (!isset($_FILES["email_attachment{$i}"])) { $GLOBALS['log']->debug("Email Attachment {$i} does not exist."); continue; } if ($_FILES['email_attachment' . $i]['error'] != 0 && $_FILES['email_attachment' . $i]['error'] != 4) { $GLOBALS['log']->debug('Email Attachment could not be attach due to error: ' . $filesError[$_FILES['email_attachment' . $i]['error']]); continue; } $note = new Note(); $note->parent_id = $this->id; $note->parent_type = $this->module_dir; $upload_file = new UploadFile('email_attachment' . $i); if (empty($upload_file)) { continue; } if (isset($_FILES['email_attachment' . $i]) && $upload_file->confirm_upload()) { $note->filename = $upload_file->get_stored_file_name(); $note->file = $upload_file; $note->name = $mod_strings['LBL_EMAIL_ATTACHMENT'] . ': ' . $note->file->original_file_name; $this->attachments[] = $note; } } $this->saved_attachments = array(); foreach ($this->attachments as $note) { if (!empty($note->id)) { array_push($this->saved_attachments, $note); continue; } $note->parent_id = $this->id; $note->parent_type = 'Emails'; $note->file_mime_type = $note->file->mime_type; $note_id = $note->save(); $this->saved_attachments[] = $note; $note->id = $note_id; $note->file->final_move($note->id); } //// END NEW ATTACHMENTS /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// //// ATTACHMENTS FROM DOCUMENTS for ($i = 0; $i < 10; $i++) { if (isset($_REQUEST['documentId' . $i]) && !empty($_REQUEST['documentId' . $i])) { $doc = new Document(); $docRev = new DocumentRevision(); $docNote = new Note(); $noteFile = new UploadFile('none'); $doc->retrieve($_REQUEST['documentId' . $i]); $docRev->retrieve($doc->document_revision_id); $this->saved_attachments[] = $docRev; // cn: bug 9723 - Emails with documents send GUID instead of Doc name $docNote->name = $docRev->getDocumentRevisionNameForDisplay(); $docNote->filename = $docRev->filename; $docNote->description = $doc->description; $docNote->parent_id = $this->id; $docNote->parent_type = 'Emails'; $docNote->file_mime_type = $docRev->file_mime_type; $docId = $docNote = $docNote->save(); $noteFile->duplicate_file($docRev->id, $docId, $docRev->filename); } } //// END ATTACHMENTS FROM DOCUMENTS /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// //// REMOVE ATTACHMENTS if (isset($_REQUEST['remove_attachment']) && !empty($_REQUEST['remove_attachment'])) { foreach ($_REQUEST['remove_attachment'] as $noteId) { $q = 'UPDATE notes SET deleted = 1 WHERE id = \'' . $noteId . '\''; $this->db->query($q); } } //this will remove attachments that have been selected to be removed from drafts. if (isset($_REQUEST['removeAttachment']) && !empty($_REQUEST['removeAttachment'])) { $exRemoved = explode('::', $_REQUEST['removeAttachment']); foreach ($exRemoved as $noteId) { $q = 'UPDATE notes SET deleted = 1 WHERE id = \'' . $noteId . '\''; $this->db->query($q); } } //// END REMOVE ATTACHMENTS /////////////////////////////////////////////////////////////////////////// }