示例#1
0
 function action_save()
 {
     require_once 'include/upload_file.php';
     $GLOBALS['log']->debug('PERFORMING NOTES SAVE');
     $upload_file = new UploadFile('uploadfile');
     $do_final_move = 0;
     if (isset($_FILES['uploadfile']) && $upload_file->confirm_upload()) {
         if (!empty($this->bean->id) && !empty($_REQUEST['old_filename'])) {
             $upload_file->unlink_file($this->bean->id, $_REQUEST['old_filename']);
         }
         $this->bean->filename = $upload_file->get_stored_file_name();
         $this->bean->file_mime_type = $upload_file->mime_type;
         $do_final_move = 1;
     } else {
         if (isset($_REQUEST['old_filename'])) {
             $this->bean->filename = $_REQUEST['old_filename'];
         }
     }
     $this->bean->save();
     if ($do_final_move) {
         $upload_file->final_move($this->bean->id);
     } else {
         if (!empty($_REQUEST['old_id'])) {
             $upload_file->duplicate_file($_REQUEST['old_id'], $this->bean->id, $this->bean->filename);
         }
     }
 }
示例#2
0
 function action_save()
 {
     require_once 'include/upload_file.php';
     $GLOBALS['log']->debug('PERFORMING NOTES SAVE');
     $upload_file = new UploadFile('uploadfile');
     $do_final_move = 0;
     if (isset($_FILES['uploadfile']) && $upload_file->confirm_upload()) {
         if (!empty($this->bean->id) && !empty($_REQUEST['old_filename'])) {
             $upload_file->unlink_file($this->bean->id, $_REQUEST['old_filename']);
         }
         $this->bean->filename = $upload_file->get_stored_file_name();
         $this->bean->file_mime_type = $upload_file->mime_type;
         $do_final_move = 1;
     } else {
         if (isset($_REQUEST['old_filename'])) {
             $this->bean->filename = $_REQUEST['old_filename'];
         }
     }
     $check_notify = false;
     if (!empty($_POST['assigned_user_id']) && (empty($this->bean->fetched_row) || $this->bean->fetched_row['assigned_user_id'] != $_POST['assigned_user_id']) && $_POST['assigned_user_id'] != $GLOBALS['current_user']->id) {
         $check_notify = true;
     }
     $this->bean->save($check_notify);
     if ($do_final_move) {
         $upload_file->final_move($this->bean->id);
     } else {
         if (!empty($_REQUEST['old_id'])) {
             $upload_file->duplicate_file($_REQUEST['old_id'], $this->bean->id, $this->bean->filename);
         }
     }
 }
示例#3
0
 function action_save()
 {
     require_once 'include/upload_file.php';
     // CCL - Bugs 41103 and 43751.  41103 address the issue where the parent_id is set, but
     // the relate_id field overrides the relationship.  43751 fixes the problem where the relate_id and
     // parent_id are the same value (in which case it should just use relate_id) by adding the != check
     if (!empty($_REQUEST['relate_id']) && !empty($_REQUEST['parent_id']) && $_REQUEST['relate_id'] != $_REQUEST['parent_id']) {
         $_REQUEST['relate_id'] = false;
     }
     $GLOBALS['log']->debug('PERFORMING NOTES SAVE');
     $upload_file = new UploadFile('uploadfile');
     $do_final_move = 0;
     if (isset($_FILES['uploadfile']) && $upload_file->confirm_upload()) {
         if (!empty($this->bean->id) && !empty($_REQUEST['old_filename'])) {
             $upload_file->unlink_file($this->bean->id, $_REQUEST['old_filename']);
         }
         $this->bean->filename = $upload_file->get_stored_file_name();
         $this->bean->file_mime_type = $upload_file->mime_type;
         $do_final_move = 1;
     } else {
         if (isset($_REQUEST['old_filename'])) {
             $this->bean->filename = $_REQUEST['old_filename'];
         }
     }
     $check_notify = false;
     if (!empty($_POST['assigned_user_id']) && (empty($this->bean->fetched_row) || $this->bean->fetched_row['assigned_user_id'] != $_POST['assigned_user_id']) && $_POST['assigned_user_id'] != $GLOBALS['current_user']->id) {
         $check_notify = true;
     }
     $this->bean->save($check_notify);
     if ($do_final_move) {
         $upload_file->final_move($this->bean->id);
     } else {
         if (!empty($_REQUEST['old_id'])) {
             $upload_file->duplicate_file($_REQUEST['old_id'], $this->bean->id, $this->bean->filename);
         }
     }
 }
示例#4
0
 protected function copyActivityAndRelateToBean($activity, $bean, $parentArr = array())
 {
     global $beanList;
     $newActivity = clone $activity;
     $newActivity->id = create_guid();
     $newActivity->new_with_id = true;
     //set the parent id and type if it was passed in, otherwise use blank to wipe it out
     $parentID = '';
     $parentType = '';
     if (!empty($parentArr)) {
         if (!empty($parentArr['id'])) {
             $parentID = $parentArr['id'];
         }
         if (!empty($parentArr['type'])) {
             $parentType = $parentArr['type'];
         }
     }
     //Special case to prevent duplicated tasks from appearing under Contacts multiple times
     if ($newActivity->module_dir == "Tasks" && $bean->module_dir != "Contacts") {
         $newActivity->contact_id = $newActivity->contact_name = "";
     }
     if ($rel = $this->findRelationship($newActivity, $bean)) {
         if (isset($newActivity->{$rel})) {
             // this comes form $activity, get rid of it and load our own
             $newActivity->{$rel} = '';
         }
         $newActivity->load_relationship($rel);
         $relObj = $newActivity->{$rel}->getRelationshipObject();
         if ($relObj->relationship_type == 'one-to-one' || $relObj->relationship_type == 'one-to-many') {
             $key = $relObj->rhs_key;
             $newActivity->{$key} = $bean->id;
         }
         //parent (related to field) should be blank unless it is explicitly sent in
         //it is not sent in unless the account is being created as well during lead conversion
         $newActivity->parent_id = $parentID;
         $newActivity->parent_type = $parentType;
         $newActivity->update_date_modified = false;
         //bug 41747
         $newActivity->save();
         $newActivity->{$rel}->add($bean);
         if ($newActivity->module_dir == "Notes" && $newActivity->filename) {
             UploadFile::duplicate_file($activity->id, $newActivity->id, $newActivity->filename);
         }
     }
 }
示例#5
0
 /**
  * Function finds the reference email for the campaign. Since a campaign can have multiple email templates
  * the reference email has same id as the marketing id.
  * this function will create an email if one does not exist. also the function will load these relationships leads, accounts, contacts
  * users and targets
  *
  * @param varchar marketing_id message id
  * @param string $subject email subject
  * @param string $body_text Email Body Text
  * @param string $body_html Email Body HTML
  * @param string $campaign_name Campaign Name
  * @param string from_address Email address of the sender, usually email address of the configured inbox.
  * @param string sender_id If of the user sending the campaign.
  * @param array  macro_nv array of name value pair, one row for each replacable macro in email template text.
  * @return
  */
 function create_ref_email($marketing_id, $subject, $body_text, $body_html, $campagin_name, $from_address, $sender_id, $notes, $macro_nv, $newmessage)
 {
     global $mod_Strings, $timedate;
     $upd_ref_email = false;
     if ($newmessage or empty($this->ref_email->id)) {
         $this->ref_email = new Email();
         $this->ref_email->retrieve($marketing_id, true, false);
         //the reference email should be updated when user swithces from test mode to regular mode,and, for every run in test mode, and is user
         //switches back to test mode.
         //this is to account for changes to email template.
         $upd_ref_email = (!empty($this->ref_email->id) and $this->ref_email->parent_type == 'test' and $this->ref_email->parent_id == 'test');
         //following condition is for switching back to test mode.
         if (!$upd_ref_email) {
             $upd_ref_email = ($this->test and !empty($this->ref_email->id) and empty($this->ref_email->parent_type) and empty($this->ref_email->parent_id));
         }
         if (empty($this->ref_email->id) or $upd_ref_email) {
             //create email record.
             $this->ref_email->id = $marketing_id;
             $this->ref_email->date_sent = '';
             if ($upd_ref_email == false) {
                 $this->ref_email->new_with_id = true;
             }
             $this->ref_email->to_addrs = '';
             $this->ref_email->to_addrs_ids = '';
             $this->ref_email->to_addrs_names = '';
             $this->ref_email->to_addrs_emails = '';
             $this->ref_email->type = 'campaign';
             $this->ref_email->deleted = '0';
             $this->ref_email->name = $campagin_name . ': ' . $subject;
             $this->ref_email->description_html = $body_html;
             $this->ref_email->description = $body_text;
             $this->ref_email->from_addr = $from_address;
             $this->ref_email->assigned_user_id = $sender_id;
             if ($this->test) {
                 $this->ref_email->parent_type = 'test';
                 $this->ref_email->parent_id = 'test';
             } else {
                 $this->ref_email->parent_type = '';
                 $this->ref_email->parent_id = '';
             }
             $this->ref_email->date_start = $timedate->nowDate();
             $this->ref_email->time_start = $timedate->asUserTime($timedate->getNow(true));
             $this->ref_email->status = 'sent';
             $retId = $this->ref_email->save();
             foreach ($notes as $note) {
                 if ($note->object_name == 'Note') {
                     if (!empty($note->file->temp_file_location) && is_file($note->file->temp_file_location)) {
                         $file_location = $note->file->temp_file_location;
                         $filename = $note->file->original_file_name;
                         $mime_type = $note->file->mime_type;
                     } else {
                         $file_location = "upload://{$note->id}";
                         $filename = $note->id . $note->filename;
                         $mime_type = $note->file_mime_type;
                     }
                 } elseif ($note->object_name == 'DocumentRevision') {
                     // from Documents
                     $filename = $note->id . $note->filename;
                     $file_location = "upload://{$filename}";
                     $mime_type = $note->file_mime_type;
                 }
                 $noteAudit = new Note();
                 $noteAudit->parent_id = $retId;
                 $noteAudit->parent_type = $this->ref_email->module_dir;
                 $noteAudit->description = "[" . $note->filename . "] " . $mod_strings['LBL_ATTACHMENT_AUDIT'];
                 $noteAudit->filename = $filename;
                 $noteAudit->file_mime_type = $mime_type;
                 $noteAudit_id = $noteAudit->save();
                 UploadFile::duplicate_file($note->id, $noteAudit_id, $filename);
             }
         }
         //load relationships.
         $this->ref_email->load_relationship('users');
         $this->ref_email->load_relationship('prospects');
         $this->ref_email->load_relationship('contacts');
         $this->ref_email->load_relationship('leads');
         $this->ref_email->load_relationship('accounts');
     }
     if (!empty($this->related_id) && !empty($this->related_type)) {
         //save relationships.
         switch ($this->related_type) {
             case 'Users':
                 $rel_name = "users";
                 break;
             case 'Prospects':
                 $rel_name = "prospects";
                 break;
             case 'Contacts':
                 $rel_name = "contacts";
                 break;
             case 'Leads':
                 $rel_name = "leads";
                 break;
             case 'Accounts':
                 $rel_name = "accounts";
                 break;
         }
         //required for one email per campaign per marketing message.
         $this->ref_email->{$rel_name}->add($this->related_id, array('campaign_data' => serialize($macro_nv)));
     }
     return $this->ref_email->id;
 }
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     require_once 'include/formbase.php';
     require_once 'include/upload_file.php';
     global $upload_maxsize;
     global $mod_strings;
     global $sugar_config;
     $focus = new EmailTemplate();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     //process the text only flag
     if (isset($_POST['text_only']) && $_POST['text_only'] == '1') {
         $focus->text_only = 1;
     } else {
         $focus->text_only = 0;
     }
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     if (!isset($_REQUEST['published'])) {
         $focus->published = 'off';
     }
     $preProcessedImages = array();
     $emailTemplateBodyHtml = from_html($focus->body_html);
     if (strpos($emailTemplateBodyHtml, '"cache/images/')) {
         $matches = array();
         preg_match_all('#<img[^>]*[\\s]+src[^=]*=[\\s]*["\']cache/images/(.+?)["\']#si', $emailTemplateBodyHtml, $matches);
         foreach ($matches[1] as $match) {
             $filename = urldecode($match);
             $file_location = sugar_cached("images/{$filename}");
             $mime_type = pathinfo($filename, PATHINFO_EXTENSION);
             if (file_exists($file_location)) {
                 $id = create_guid();
                 $newFileLocation = "upload://{$id}";
                 if (!copy($file_location, $newFileLocation)) {
                     $GLOBALS['log']->debug("EMAIL Template could not copy attachment to {$newFileLocation}");
                 } else {
                     $secureLink = "index.php?entryPoint=download&type=Notes&id={$id}";
                     $emailTemplateBodyHtml = str_replace("cache/images/{$match}", $secureLink, $emailTemplateBodyHtml);
                     unlink($file_location);
                     $preProcessedImages[$filename] = $id;
                 }
             }
             // if
         }
         // foreach
     }
     // if
     if (isset($GLOBALS['check_notify'])) {
         $check_notify = $GLOBALS['check_notify'];
     } else {
         $check_notify = FALSE;
     }
     $focus->body_html = $emailTemplateBodyHtml;
     $return_id = $focus->save($check_notify);
     ///////////////////////////////////////////////////////////////////////////////
     ////	ATTACHMENT HANDLING
     ///////////////////////////////////////////////////////////////////////////
     ////	ADDING NEW ATTACHMENTS
     $max_files_upload = count($_FILES);
     if (!empty($focus->id)) {
         $note = new Note();
         $where = "notes.parent_id='{$focus->id}'";
         if (!empty($_REQUEST['old_id'])) {
             // to support duplication of email templates
             $where .= " OR notes.parent_id='" . $_REQUEST['old_id'] . "'";
         }
         $notes_list = $note->get_full_list("", $where, true);
     }
     if (!isset($notes_list)) {
         $notes_list = array();
     }
     if (!is_array($focus->attachments)) {
         // PHP5 does not auto-create arrays(). Need to initialize it here.
         $focus->attachments = array();
     }
     $focus->attachments = array_merge($focus->attachments, $notes_list);
     //for($i = 0; $i < $max_files_upload; $i++) {
     foreach ($_FILES as $key => $file) {
         $note = new Note();
         //Images are presaved above so we need to prevent duplicate files from being created.
         if (isset($preProcessedImages[$file['name']])) {
             $oldId = $preProcessedImages[$file['name']];
             $note->id = $oldId;
             $note->new_with_id = TRUE;
             $GLOBALS['log']->debug("Image {$file['name']} has already been processed.");
         }
         $i = preg_replace("/email_attachment(.+)/", '$1', $key);
         $upload_file = new UploadFile($key);
         if (isset($_FILES[$key]) && $upload_file->confirm_upload() && preg_match("/^email_attachment/", $key)) {
             $note->filename = $upload_file->get_stored_file_name();
             $note->file = $upload_file;
             $note->name = $mod_strings['LBL_EMAIL_ATTACHMENT'] . ': ' . $note->file->original_file_name;
             if (isset($_REQUEST['embedded' . $i]) && !empty($_REQUEST['embedded' . $i])) {
                 if ($_REQUEST['embedded' . $i] == 'true') {
                     $note->embed_flag = true;
                 } else {
                     $note->embed_flag = false;
                 }
             }
             array_push($focus->attachments, $note);
         }
     }
     $focus->saved_attachments = array();
     foreach ($focus->attachments as $note) {
         if (!empty($note->id) && $note->new_with_id === FALSE) {
             if (empty($_REQUEST['old_id'])) {
                 array_push($focus->saved_attachments, $note);
             } else {
                 // we're duplicating a template with attachments
                 // dupe the file, create a new note, assign the note to the new template
                 $newNote = new Note();
                 $newNote->retrieve($note->id);
                 $newNote->id = create_guid();
                 $newNote->parent_id = $focus->id;
                 $newNote->new_with_id = true;
                 $newNote->date_modified = '';
                 $newNote->date_entered = '';
                 $newNoteId = $newNote->save();
                 UploadFile::duplicate_file($note->id, $newNoteId, $note->filename);
             }
             continue;
         }
         $note->parent_id = $focus->id;
         $note->parent_type = 'Emails';
         $note->file_mime_type = $note->file->mime_type;
         $note_id = $note->save();
         array_push($focus->saved_attachments, $note);
         $note->id = $note_id;
         if ($note->new_with_id === FALSE) {
             $note->file->final_move($note->id);
         } else {
             $GLOBALS['log']->debug("Not performing final move for note id {$note->id} as it has already been processed");
         }
     }
     ////	END NEW ATTACHMENTS
     ///////////////////////////////////////////////////////////////////////////
     ///////////////////////////////////////////////////////////////////////////
     ////	ATTACHMENTS FROM DOCUMENTS
     $count = '';
     //_pp($_REQUEST);
     //_ppd(count($_REQUEST['document']));
     if (!empty($_REQUEST['document'])) {
         $count = count($_REQUEST['document']);
     } else {
         $count = 10;
     }
     for ($i = 0; $i < $count; $i++) {
         if (isset($_REQUEST['documentId' . $i]) && !empty($_REQUEST['documentId' . $i])) {
             $doc = new Document();
             $docRev = new DocumentRevision();
             $docNote = new Note();
             $doc->retrieve($_REQUEST['documentId' . $i]);
             $docRev->retrieve($doc->document_revision_id);
             array_push($focus->saved_attachments, $docRev);
             $docNote->name = $doc->document_name;
             $docNote->filename = $docRev->filename;
             $docNote->description = $doc->description;
             $docNote->parent_id = $focus->id;
             $docNote->parent_type = 'Emails';
             $docNote->file_mime_type = $docRev->file_mime_type;
             $docId = $docNote = $docNote->save();
             UploadFile::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 . '\'';
             $focus->db->query($q);
         }
     }
     ////	END REMOVE ATTACHMENTS
     ///////////////////////////////////////////////////////////////////////////
     ////	END ATTACHMENT HANDLING
     ///////////////////////////////////////////////////////////////////////////////
     clear_register_value('select_array', $focus->object_name);
     if ($redirect) {
         $GLOBALS['log']->debug("Saved record with id of " . $return_id);
         handleRedirect($return_id, "EmailTemplates");
     } else {
         return $focus;
     }
 }
示例#7
0
 public function save(&$bean, $params, $field, $vardef, $prefix = '')
 {
     $fakeDisplayParams = array();
     $this->fillInOptions($vardef, $fakeDisplayParams);
     require_once 'include/upload_file.php';
     $upload_file = new UploadFile($prefix . $field . '_file');
     //remove file
     if (isset($_REQUEST['remove_file_' . $field]) && $params['remove_file_' . $field] == 1) {
         $upload_file->unlink_file($bean->{$field});
         $bean->{$field} = "";
     }
     $move = false;
     if (isset($_FILES[$prefix . $field . '_file']) && $upload_file->confirm_upload()) {
         $bean->{$field} = $upload_file->get_stored_file_name();
         $bean->file_mime_type = $upload_file->mime_type;
         $bean->file_ext = $upload_file->file_ext;
         $move = true;
     }
     if (!empty($params['isDuplicate']) && $params['isDuplicate'] == 'true') {
         // This way of detecting duplicates is used in Notes
         $old_id = $params['relate_id'];
     }
     if (!empty($params['duplicateSave']) && !empty($params['duplicateId'])) {
         // It's a duplicate
         $old_id = $params['duplicateId'];
     }
     // Backwards compatibility for fields that still use customCode to handle the file uploads
     if (!$move && empty($old_id) && isset($_FILES['uploadfile'])) {
         $upload_file = new UploadFile('uploadfile');
         if ($upload_file->confirm_upload()) {
             $bean->{$field} = $upload_file->get_stored_file_name();
             $bean->file_mime_type = $upload_file->mime_type;
             $bean->file_ext = $upload_file->file_ext;
             $move = true;
         }
     } else {
         if (!$move && !empty($old_id) && isset($_REQUEST['uploadfile']) && !isset($_REQUEST[$prefix . $field . '_file'])) {
             // I think we are duplicating a backwards compatibility module.
             $upload_file = new UploadFile('uploadfile');
         }
     }
     if (empty($bean->id)) {
         $bean->id = create_guid();
         $bean->new_with_id = true;
     }
     if ($move) {
         $upload_file->final_move($bean->id);
         $upload_file->upload_doc($bean, $bean->id, $params[$prefix . $vardef['docType']], $bean->{$field}, $upload_file->mime_type);
     } else {
         if (!empty($old_id)) {
             // It's a duplicate, I think
             if (empty($params[$prefix . $vardef['docUrl']])) {
                 $upload_file->duplicate_file($old_id, $bean->id, $bean->{$field});
             } else {
                 $docType = $vardef['docType'];
                 $bean->{$docType} = $params[$prefix . $field . '_old_doctype'];
             }
         } else {
             if (!empty($params[$prefix . $field . '_remoteName'])) {
                 // We aren't moving, we might need to do some remote linking
                 $displayParams = array();
                 $this->fillInOptions($vardef, $displayParams);
                 if (isset($params[$prefix . $vardef['docId']]) && !empty($params[$prefix . $vardef['docId']]) && isset($params[$prefix . $vardef['docType']]) && !empty($params[$prefix . $vardef['docType']])) {
                     $bean->{$field} = $params[$prefix . $field . '_remoteName'];
                     require_once 'include/utils/file_utils.php';
                     $extension = get_file_extension($bean->{$field});
                     if (!empty($extension)) {
                         $bean->file_ext = $extension;
                         $bean->file_mime_type = get_mime_content_type_from_filename($bean->{$field});
                     }
                 }
             }
         }
     }
     if ($vardef['allowEapm'] == true && empty($bean->{$field})) {
         $GLOBALS['log']->info("The {$field} is empty, clearing out the lot");
         // Looks like we are emptying this out
         $clearFields = array('docId', 'docType', 'docUrl', 'docDirectUrl');
         foreach ($clearFields as $clearMe) {
             if (!isset($vardef[$clearMe])) {
                 continue;
             }
             $clearField = $vardef[$clearMe];
             $bean->{$clearField} = '';
         }
     }
 }
示例#8
0
if (isset($_REQUEST['SaveRevision'])) {
    //fetch the document record.
    $Document->retrieve($_REQUEST['return_id']);
    if ($useRequired && !checkRequired($prefix, array_keys($Revision->required_fields))) {
        return null;
    }
    $Revision = populateFromPost($prefix, $Revision);
    $upload_file = new UploadFile('uploadfile');
    if (isset($_FILES['uploadfile']) && $upload_file->confirm_upload()) {
        $Revision->filename = $upload_file->get_stored_file_name();
        $Revision->file_mime_type = $upload_file->mime_type;
        $Revision->file_ext = $upload_file->file_ext;
        $do_final_move = 1;
    }
    //save revision
    $Revision->document_id = $_REQUEST['return_id'];
    $Revision->save();
    //revsion is the document.
    $Document->document_revision_id = $Revision->id;
    $Document->save();
    $return_id = $Document->id;
}
if ($do_final_move) {
    $upload_file->final_move($Revision->id);
} else {
    if (!empty($_REQUEST['old_id'])) {
        $upload_file->duplicate_file($_REQUEST['old_id'], $Revision->id, $Revision->filename);
    }
}
$GLOBALS['log']->debug("Saved record with id of " . $return_id);
handleRedirect($return_id, "Documents");
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     require_once 'include/formbase.php';
     require_once 'include/upload_file.php';
     global $upload_maxsize, $upload_dir;
     global $mod_strings;
     global $sugar_config;
     $focus = new EmailTemplate();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     //process the text only flag
     if (isset($_POST['text_only']) && $_POST['text_only'] == '1') {
         $focus->text_only = 1;
     } else {
         $focus->text_only = 0;
     }
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     if (!isset($_REQUEST['published'])) {
         $focus->published = 'off';
     }
     $emailTemplateBodyHtml = from_html($focus->body_html);
     $fileBasePath = "{$sugar_config['cache_dir']}images/";
     $filePatternSearch = "{$sugar_config['cache_dir']}";
     $filePatternSearch = str_replace("/", "\\/", $filePatternSearch);
     $filePatternSearch = $filePatternSearch . "images\\/";
     $fileBasePath1 = "\"" . $fileBasePath;
     if (strpos($emailTemplateBodyHtml, "\"{$fileBasePath}")) {
         $matches = array();
         preg_match_all("/{$filePatternSearch}.+?\"/i", $emailTemplateBodyHtml, $matches);
         foreach ($matches[0] as $match) {
             $filenameUndecoded = str_replace($fileBasePath, '', $match);
             $filename = urldecode(substr($filenameUndecoded, 0, -1));
             $filenameUndecoded = str_replace("\"", '', $filenameUndecoded);
             $cid = $filename;
             $file_location = clean_path(getcwd() . "/{$sugar_config['cache_dir']}images/{$filename}");
             $mime_type = strtolower(substr($filename, strrpos($filename, ".") + 1, strlen($filename)));
             if (file_exists($file_location)) {
                 $id = create_guid();
                 $newFileLocation = "{$sugar_config['upload_dir']}{$id}.{$mime_type}";
                 if (!copy($file_location, $newFileLocation)) {
                     $GLOBALS['log']->debug("EMAIL Template could not copy attachment to {$sugar_config['upload_dir']} [ {$newFileLocation} ]");
                 } else {
                     $emailTemplateBodyHtml = str_replace("{$sugar_config['cache_dir']}images/{$filenameUndecoded}", $newFileLocation, $emailTemplateBodyHtml);
                     unlink($file_location);
                 }
             }
             // if
         }
         // foreach
     }
     // if
     $focus->body_html = $emailTemplateBodyHtml;
     $return_id = $focus->save();
     ///////////////////////////////////////////////////////////////////////////////
     ////	ATTACHMENT HANDLING
     ///////////////////////////////////////////////////////////////////////////
     ////	ADDING NEW ATTACHMENTS
     $max_files_upload = count($_FILES);
     if (!empty($focus->id)) {
         $note = new Note();
         $where = "notes.parent_id='{$focus->id}'";
         if (!empty($_REQUEST['old_id'])) {
             // to support duplication of email templates
             $where .= " OR notes.parent_id='" . $_REQUEST['old_id'] . "'";
         }
         $notes_list = $note->get_full_list("", $where, true);
     }
     if (!isset($notes_list)) {
         $notes_list = array();
     }
     if (!is_array($focus->attachments)) {
         // PHP5 does not auto-create arrays(). Need to initialize it here.
         $focus->attachments = array();
     }
     $focus->attachments = array_merge($focus->attachments, $notes_list);
     //for($i = 0; $i < $max_files_upload; $i++) {
     foreach ($_FILES as $key => $file) {
         $note = new Note();
         $i = preg_replace("/email_attachment(.+)/", '$1', $key);
         $upload_file = new UploadFile($key);
         if ($upload_file == -1) {
             continue;
         }
         if (isset($_FILES[$key]) && $upload_file->confirm_upload() && preg_match("/^email_attachment/", $key)) {
             $note->filename = $upload_file->get_stored_file_name();
             $note->file = $upload_file;
             $note->name = $mod_strings['LBL_EMAIL_ATTACHMENT'] . ': ' . $note->file->original_file_name;
             if (isset($_REQUEST['embedded' . $i]) && !empty($_REQUEST['embedded' . $i])) {
                 if ($_REQUEST['embedded' . $i] == 'true') {
                     $note->embed_flag = true;
                 } else {
                     $note->embed_flag = false;
                 }
             }
             array_push($focus->attachments, $note);
         }
     }
     $focus->saved_attachments = array();
     foreach ($focus->attachments as $note) {
         if (!empty($note->id)) {
             if (empty($_REQUEST['old_id'])) {
                 // to support duplication of email templates
                 array_push($focus->saved_attachments, $note);
             } else {
                 // we're duplicating a template with attachments
                 // dupe the file, create a new note, assign the note to the new template
                 $newNote = new Note();
                 $newNote->retrieve($note->id);
                 $newNote->id = create_guid();
                 $newNote->parent_id = $focus->id;
                 $newNote->new_with_id = true;
                 $newNote->date_modified = '';
                 $newNote->date_entered = '';
                 $newNoteId = $newNote->save();
                 $dupeFile = new UploadFile('duplicate');
                 $dupeFile->duplicate_file($note->id, $newNoteId, $note->filename);
             }
             continue;
         }
         $note->parent_id = $focus->id;
         $note->parent_type = 'Emails';
         $note->file_mime_type = $note->file->mime_type;
         $note_id = $note->save();
         array_push($focus->saved_attachments, $note);
         $note->id = $note_id;
         $note->file->final_move($note->id);
     }
     ////	END NEW ATTACHMENTS
     ///////////////////////////////////////////////////////////////////////////
     ///////////////////////////////////////////////////////////////////////////
     ////	ATTACHMENTS FROM DOCUMENTS
     $count = '';
     //_pp($_REQUEST);
     //_ppd(count($_REQUEST['document']));
     if (!empty($_REQUEST['document'])) {
         $count = count($_REQUEST['document']);
     } else {
         $count = 10;
     }
     for ($i = 0; $i < $count; $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);
             array_push($focus->saved_attachments, $docRev);
             $docNote->name = $doc->document_name;
             $docNote->filename = $docRev->filename;
             $docNote->description = $doc->description;
             $docNote->parent_id = $focus->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 . '\'';
             $focus->db->query($q);
         }
     }
     ////	END REMOVE ATTACHMENTS
     ///////////////////////////////////////////////////////////////////////////
     ////	END ATTACHMENT HANDLING
     ///////////////////////////////////////////////////////////////////////////////
     if ($redirect) {
         $GLOBALS['log']->debug("Saved record with id of " . $return_id);
         handleRedirect($return_id, "EmailTemplates");
     } else {
         return $focus;
     }
 }
 public function handleAttachments($focus, $redirect, $return_id)
 {
     ///////////////////////////////////////////////////////////////////////////////
     ////	ATTACHMENT HANDLING
     ///////////////////////////////////////////////////////////////////////////
     ////	ADDING NEW ATTACHMENTS
     global $mod_strings;
     $max_files_upload = count($_FILES);
     if (!empty($focus->id)) {
         $note = new Note();
         $where = "notes.parent_id='{$focus->id}'";
         if (!empty($_REQUEST['old_id'])) {
             // to support duplication of email templates
             $where .= " OR notes.parent_id='" . htmlspecialchars($_REQUEST['old_id'], ENT_QUOTES) . "'";
         }
         $notes_list = $note->get_full_list("", $where, true);
     }
     if (!isset($notes_list)) {
         $notes_list = array();
     }
     if (!is_array($focus->attachments)) {
         // PHP5 does not auto-create arrays(). Need to initialize it here.
         $focus->attachments = array();
     }
     $focus->attachments = array_merge($focus->attachments, $notes_list);
     //for($i = 0; $i < $max_files_upload; $i++) {
     foreach ($_FILES as $key => $file) {
         $note = new Note();
         //Images are presaved above so we need to prevent duplicate files from being created.
         if (isset($preProcessedImages[$file['name']])) {
             $oldId = $preProcessedImages[$file['name']];
             $note->id = $oldId;
             $note->new_with_id = TRUE;
             $GLOBALS['log']->debug("Image {$file['name']} has already been processed.");
         }
         $i = preg_replace("/email_attachment(.+)/", '$1', $key);
         $upload_file = new UploadFile($key);
         if (isset($_FILES[$key]) && $upload_file->confirm_upload() && preg_match("/^email_attachment/", $key)) {
             $note->filename = $upload_file->get_stored_file_name();
             $note->file = $upload_file;
             $note->name = $mod_strings['LBL_EMAIL_ATTACHMENT'] . ': ' . $note->file->original_file_name;
             if (isset($_REQUEST['embedded' . $i]) && !empty($_REQUEST['embedded' . $i])) {
                 if ($_REQUEST['embedded' . $i] == 'true') {
                     $note->embed_flag = true;
                 } else {
                     $note->embed_flag = false;
                 }
             }
             array_push($focus->attachments, $note);
         }
     }
     $focus->saved_attachments = array();
     foreach ($focus->attachments as $note) {
         if (!empty($note->id) && $note->new_with_id === FALSE) {
             if (empty($_REQUEST['old_id'])) {
                 array_push($focus->saved_attachments, $note);
             } else {
                 // we're duplicating a template with attachments
                 // dupe the file, create a new note, assign the note to the new template
                 $newNote = new Note();
                 $newNote->retrieve($note->id);
                 $newNote->id = create_guid();
                 $newNote->parent_id = $focus->id;
                 $newNote->new_with_id = true;
                 $newNote->date_modified = '';
                 $newNote->date_entered = '';
                 /* BEGIN - SECURITY GROUPS */
                 //Need to do this so that attachments show under an EmailTemplate correctly for a normal user
                 global $current_user;
                 $newNote->assigned_user_id = $current_user->id;
                 /* END - SECURITY GROUPS */
                 $newNoteId = $newNote->save();
                 UploadFile::duplicate_file($note->id, $newNoteId, $note->filename);
             }
             continue;
         }
         $note->parent_id = $focus->id;
         $note->parent_type = 'Emails';
         $note->file_mime_type = $note->file->mime_type;
         /* BEGIN - SECURITY GROUPS */
         //Need to do this so that attachments show under an EmailTemplate correctly for a normal user
         global $current_user;
         $note->assigned_user_id = $current_user->id;
         /* END - SECURITY GROUPS */
         $note_id = $note->save();
         array_push($focus->saved_attachments, $note);
         $note->id = $note_id;
         if ($note->new_with_id === FALSE) {
             $note->file->final_move($note->id);
         } else {
             $GLOBALS['log']->debug("Not performing final move for note id {$note->id} as it has already been processed");
         }
     }
     ////	END NEW ATTACHMENTS
     ///////////////////////////////////////////////////////////////////////////
     ///////////////////////////////////////////////////////////////////////////
     ////	ATTACHMENTS FROM DOCUMENTS
     $count = '';
     //_pp($_REQUEST);
     //_ppd(count($_REQUEST['document']));
     if (!empty($_REQUEST['document'])) {
         $count = count($_REQUEST['document']);
     } else {
         $count = 10;
     }
     for ($i = 0; $i < $count; $i++) {
         if (isset($_REQUEST['documentId' . $i]) && !empty($_REQUEST['documentId' . $i])) {
             $doc = new Document();
             $docRev = new DocumentRevision();
             $docNote = new Note();
             $doc->retrieve($_REQUEST['documentId' . $i]);
             $docRev->retrieve($doc->document_revision_id);
             array_push($focus->saved_attachments, $docRev);
             $docNote->name = $doc->document_name;
             $docNote->filename = $docRev->filename;
             $docNote->description = $doc->description;
             $docNote->parent_id = $focus->id;
             $docNote->parent_type = 'Emails';
             $docNote->file_mime_type = $docRev->file_mime_type;
             $docId = $docNote = $docNote->save();
             UploadFile::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 . '\'';
             $focus->db->query($q);
         }
     }
     ////	END REMOVE ATTACHMENTS
     ///////////////////////////////////////////////////////////////////////////
     ////	END ATTACHMENT HANDLING
     ///////////////////////////////////////////////////////////////////////////////
     clear_register_value('select_array', $focus->object_name);
     if ($redirect) {
         $GLOBALS['log']->debug("Saved record with id of " . $return_id);
         handleRedirect($return_id, "EmailTemplates");
     } else {
         return $focus;
     }
 }
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     require_once 'modules/EmailTemplates/EmailTemplate.php';
     require_once 'modules/Documents/Document.php';
     require_once 'modules/DocumentRevisions/DocumentRevision.php';
     require_once 'modules/Notes/Note.php';
     require_once 'include/formbase.php';
     require_once 'include/upload_file.php';
     global $upload_maxsize, $upload_dir;
     global $mod_strings;
     $focus = new EmailTemplate();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     if (!isset($_REQUEST['published'])) {
         $focus->published = 'off';
     }
     $return_id = $focus->save();
     ///////////////////////////////////////////////////////////////////////////////
     ////	ATTACHMENT HANDLING
     ///////////////////////////////////////////////////////////////////////////
     ////	ADDING NEW ATTACHMENTS
     $max_files_upload = 10;
     if (!empty($focus->id)) {
         $note = new Note();
         $where = "notes.parent_id='{$focus->id}'";
         if (!empty($_REQUEST['old_id'])) {
             // to support duplication of email templates
             $where .= " OR notes.parent_id='" . $_REQUEST['old_id'] . "'";
         }
         $notes_list = $note->get_full_list("", $where, true);
     }
     if (!isset($notes_list)) {
         $notes_list = array();
     }
     if (!is_array($focus->attachments)) {
         // PHP5 does not auto-create arrays(). Need to initialize it here.
         $focus->attachments = array();
     }
     $focus->attachments = array_merge($focus->attachments, $notes_list);
     for ($i = 0; $i < $max_files_upload; $i++) {
         $note = new Note();
         $upload_file = new UploadFile('email_attachment' . $i);
         if ($upload_file == -1) {
             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;
             array_push($focus->attachments, $note);
         }
     }
     $focus->saved_attachments = array();
     foreach ($focus->attachments as $note) {
         if (!empty($note->id)) {
             if (empty($_REQUEST['old_id'])) {
                 // to support duplication of email templates
                 array_push($focus->saved_attachments, $note);
             } else {
                 // we're duplicating a template with attachments
                 // dupe the file, create a new note, assign the note to the new template
                 $newNote = new Note();
                 $newNote->retrieve($note->id);
                 $newNote->id = create_guid();
                 $newNote->parent_id = $focus->id;
                 $newNote->new_with_id = true;
                 $newNoteId = $newNote->save();
                 $dupeFile = new UploadFile('duplicate');
                 $dupeFile->duplicate_file($note->id, $newNoteId, $note->filename);
             }
             continue;
         }
         $note->parent_id = $focus->id;
         $note->parent_type = 'Emails';
         $note->file_mime_type = $note->file->mime_type;
         $note_id = $note->save();
         array_push($focus->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);
             array_push($focus->saved_attachments, $docRev);
             $docNote->name = $doc->document_name;
             $docNote->filename = $docRev->filename;
             $docNote->description = $doc->description;
             $docNote->parent_id = $focus->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 . '\'';
             $focus->db->query($q);
         }
     }
     ////	END REMOVE ATTACHMENTS
     ///////////////////////////////////////////////////////////////////////////
     ////	END ATTACHMENT HANDLING
     ///////////////////////////////////////////////////////////////////////////////
     if ($redirect) {
         $GLOBALS['log']->debug("Saved record with id of " . $return_id);
         handleRedirect($return_id, "EmailTemplates");
     } else {
         return $focus;
     }
 }
示例#12
0
 public function save(&$bean, $params, $field, $properties, $prefix = '')
 {
     require_once 'include/upload_file.php';
     $upload_file = new UploadFile($field);
     //remove file
     if (isset($_REQUEST['remove_imagefile_' . $field]) && $_REQUEST['remove_imagefile_' . $field] == 1) {
         $upload_file->unlink_file($bean->{$field});
         $bean->{$field} = "";
     }
     //uploadfile
     if (isset($_FILES[$field])) {
         //confirm only image file type can be uploaded
         if (verify_image_file($_FILES[$field]['tmp_name'])) {
             if ($upload_file->confirm_upload()) {
                 // for saveTempImage API
                 if (isset($params['temp']) && $params['temp'] === true) {
                     // Create the new field value
                     $bean->{$field} = create_guid();
                     // Move to temporary folder
                     if (!$upload_file->final_move($bean->{$field}, true)) {
                         // If this was a fail, reset the bean field to original
                         $this->error = $upload_file->getErrorMessage();
                     }
                 } else {
                     // Capture the old value in case of error
                     $oldvalue = $bean->{$field};
                     // Create the new field value
                     $bean->{$field} = create_guid();
                     // Add checking for actual file move for reporting to consumers
                     if (!$upload_file->final_move($bean->{$field})) {
                         // If this was a fail, reset the bean field to original
                         $bean->{$field} = $oldvalue;
                         $this->error = $upload_file->getErrorMessage();
                     }
                 }
             } else {
                 // Added error reporting
                 $this->error = $upload_file->getErrorMessage();
             }
         } else {
             $imgInfo = getimagesize($_FILES[$field]['tmp_name']);
             // if file is image then this image is no longer supported.
             if (false !== $imgInfo) {
                 $ext = end(explode('.', $_FILES[$field]['name']));
                 $this->error = string_format($GLOBALS['app_strings']['LBL_UPLOAD_IMAGE_FILE_NOT_SUPPORTED'], array($ext));
             } else {
                 $this->error = $GLOBALS['app_strings']["LBL_UPLOAD_IMAGE_FILE_INVALID"];
             }
         }
     }
     //Check if we have the duplicate value set and use it if $bean->$field is empty
     if (empty($bean->{$field}) && !empty($_REQUEST[$field . '_duplicate'])) {
         $bean->{$field} = $_REQUEST[$field . '_duplicate'];
     }
     // case when we should copy one file to another using merge-duplicate view
     // $params[$field . '_duplicateBeanId'] contains id of bean from
     // which we should copy file.
     if (!empty($params[$field]) && !empty($params[$field . '_duplicateBeanId'])) {
         $bean->{$field} = create_guid();
         $upload_file->duplicate_file($params[$field], $bean->{$field});
     }
 }
示例#13
0
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     require_once 'include/formbase.php';
     require_once 'include/upload_file.php';
     $focus = new Note();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     if (empty($focus->name)) {
         return null;
     }
     if (!isset($_REQUEST['date_due_flag'])) {
         $focus->date_due_flag = 0;
     }
     if (!isset($_REQUEST['portal_flag'])) {
         $focus->portal_flag = '0';
     }
     $upload_file = new UploadFile('uploadfile');
     $do_final_move = 0;
     if (isset($_FILES['uploadfile']) && $upload_file->confirm_upload()) {
         if (!empty($focus->id) && !empty($_REQUEST['old_filename'])) {
             $upload_file->unlink_file($focus->id, $_REQUEST['old_filename']);
         }
         $focus->filename = $upload_file->get_stored_file_name();
         $focus->file_mime_type = $upload_file->mime_type;
         $do_final_move = 1;
     } else {
         if (isset($_REQUEST['old_filename'])) {
             $focus->filename = $_REQUEST['old_filename'];
         }
     }
     $return_id = $focus->save();
     if ($do_final_move) {
         $upload_file->final_move($focus->id);
     } else {
         if (!empty($_REQUEST['old_id'])) {
             $upload_file->duplicate_file($_REQUEST['old_id'], $focus->id, $focus->filename);
         }
     }
     if ($redirect) {
         $GLOBALS['log']->debug("Saved record with id of " . $return_id);
         handleRedirect($return_id, "Notes");
     } else {
         return $focus;
     }
 }
示例#14
0
 /**
  * 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
     ///////////////////////////////////////////////////////////////////////////
 }
示例#15
0
 protected function copyActivityAndRelateToBean($activity, $bean)
 {
     global $beanList;
     $newActivity = clone $activity;
     $newActivity->id = create_guid();
     $newActivity->new_with_id = true;
     //Special case to prevent duplicated tasks from appearing under Contacts multiple times
     if ($newActivity->module_dir == "Tasks" && $bean->module_dir != "Contacts") {
         $newActivity->contact_id = $activity->contact_name = "";
     }
     if ($rel = $this->findRelationship($newActivity, $bean)) {
         $newActivity->load_relationship($rel);
         $relObj = $newActivity->{$rel}->getRelationshipObject();
         if ($relObj->relationship_type == 'one-to-one' || $relObj->relationship_type == 'one-to-many') {
             $key = $relObj->rhs_key;
             $newActivity->{$key} = $bean->id;
         }
         $newActivity->{$rel}->add($bean->id);
         $newActivity->parent_id = $bean->id;
         $newActivity->parent_type = $bean->module_dir;
         $newActivity->update_date_modified = false;
         //bug 41747
         $newActivity->save();
         if ($newActivity->module_dir == "Notes" && $newActivity->filename) {
             UploadFile::duplicate_file($activity->id, $newActivity->id, $newActivity->filename);
         }
     }
 }
示例#16
0
function clone_history(&$db, $from_id, $to_id, $to_type)
{
    global $timedate;
    $old_note_id = null;
    $old_filename = null;
    require_once 'include/upload_file.php';
    $tables = array('calls' => 'Call', 'meetings' => 'Meeting', 'notes' => 'Note', 'tasks' => 'Task');
    $location = array('Email' => "modules/Emails/Email.php", 'Call' => "modules/Calls/Call.php", 'Meeting' => "modules/Meetings/Meeting.php", 'Note' => "modules/Notes/Note.php", 'Tasks' => "modules/Tasks/Task.php");
    foreach ($tables as $table => $bean_class) {
        if (!class_exists($bean_class)) {
            require_once $location[$bean_class];
        }
        $bProcessingNotes = false;
        if ($table == 'notes') {
            $bProcessingNotes = true;
        }
        $query = "SELECT id FROM {$table} WHERE parent_id='{$from_id}'";
        $results = $db->query($query);
        while ($row = $db->fetchByAssoc($results)) {
            //retrieve existing record.
            $bean = new $bean_class();
            $bean->retrieve($row['id']);
            //process for new instance.
            if ($bProcessingNotes) {
                $old_note_id = $row['id'];
                $old_filename = $bean->filename;
            }
            $bean->id = null;
            $bean->parent_id = $to_id;
            $bean->parent_type = $to_type;
            if ($to_type == 'Contacts' and in_array('contact_id', $bean->column_fields)) {
                $bean->contact_id = $to_id;
            }
            $bean->update_date_modified = false;
            $bean->update_modified_by = false;
            if (isset($bean->date_modified)) {
                $bean->date_modified = $timedate->to_db($bean->date_modified);
            }
            if (isset($bean->date_entered)) {
                $bean->date_entered = $timedate->to_db($bean->date_entered);
            }
            //save
            $new_id = $bean->save();
            //duplicate the file now. for notes.
            if ($bProcessingNotes && !empty($old_filename)) {
                UploadFile::duplicate_file($old_note_id, $new_id, $old_filename);
            }
            //reset the values needed for attachment duplication.
            $old_note_id = null;
            $old_filename = null;
        }
    }
}
示例#17
0
 public function save($bean, $params, $field, $vardef, $prefix = '')
 {
     $fakeDisplayParams = array();
     $this->fillInOptions($vardef, $fakeDisplayParams);
     require_once 'include/upload_file.php';
     $upload_file = new UploadFile($prefix . $field . '_file');
     //remove file
     if (isset($_REQUEST['remove_file_' . $field]) && $params['remove_file_' . $field] == 1) {
         $upload_file->unlink_file($bean->{$field});
         $bean->{$field} = "";
     }
     $move = false;
     // In case of failure midway, we need to reset the values of the bean
     $originalvals = array('value' => $bean->{$field});
     // Bug 57400 - Some beans with a filename field type do NOT have file_mime_type
     // or file_ext. In the case of Documents, for example, this happens to be
     // the case, since the DocumentRevisions bean is where these fields are found.
     if (isset($bean->file_mime_type)) {
         $originalvals['mime'] = $bean->file_mime_type;
     }
     if (isset($bean->file_ext)) {
         $originalvals['ext'] = $bean->file_ext;
     }
     if (isset($_FILES[$prefix . $field . '_file']) && $upload_file->confirm_upload()) {
         // in order to avoid any discrepancies of MIME type with the download code,
         // call the same MIME function instead of using the uploaded file's mime type property.
         $mimeType = get_file_mime_type($upload_file->get_temp_file_location(), 'application/octet-stream');
         //verify the image
         if (in_array($mimeType, self::$imageFileMimeTypes) && !verify_image_file($upload_file->get_temp_file_location())) {
             $this->error = string_format($GLOBALS['app_strings']['LBL_UPLOAD_IMAGE_FILE_NOT_SUPPORTED'], array($upload_file->file_ext));
             return;
         }
         $bean->{$field} = $upload_file->get_stored_file_name();
         $bean->file_mime_type = $upload_file->mime_type;
         $bean->file_ext = $upload_file->file_ext;
         $move = true;
     } else {
         $this->error = $upload_file->getErrorMessage();
     }
     if (!empty($params['isDuplicate']) && $params['isDuplicate'] == 'true') {
         // This way of detecting duplicates is used in Notes
         $old_id = $params['relate_id'];
     }
     if (!empty($params['duplicateSave']) && !empty($params['duplicateId'])) {
         // It's a duplicate
         $old_id = $params['duplicateId'];
     }
     // case when we should copy one file to another using merge-duplicate view
     // $params[$field . '_duplicateBeanId'] contains id of bean from
     // which we should copy file.
     if (!empty($params[$field . '_duplicateBeanId'])) {
         $duplicateModuleId = $params[$field . '_duplicateBeanId'];
     }
     // Backwards compatibility for fields that still use customCode to handle the file uploads
     if (!$move && empty($old_id) && isset($_FILES['uploadfile'])) {
         $upload_file = new UploadFile('uploadfile');
         if ($upload_file->confirm_upload()) {
             $bean->{$field} = $upload_file->get_stored_file_name();
             $bean->file_mime_type = $upload_file->mime_type;
             $bean->file_ext = $upload_file->file_ext;
             $move = true;
         } else {
             $this->error = $upload_file->getErrorMessage();
         }
     } elseif (!$move && !empty($old_id) && isset($_REQUEST['uploadfile']) && !isset($_REQUEST[$prefix . $field . '_file'])) {
         // I think we are duplicating a backwards compatibility module.
         $upload_file = new UploadFile('uploadfile');
     }
     if (empty($bean->id)) {
         $bean->id = create_guid();
         $bean->new_with_id = true;
     }
     if ($move) {
         $temp = !empty($params['temp']);
         // Added checking of final move to capture errors that might occur
         if ($upload_file->final_move($bean->id, $temp)) {
             if (!$temp) {
                 // This fixes an undefined index warning being thrown
                 $docType = isset($vardef['docType']) && isset($params[$prefix . $vardef['docType']]) ? $params[$prefix . $vardef['docType']] : null;
                 $upload_file->upload_doc($bean, $bean->id, $docType, $bean->{$field}, $upload_file->mime_type);
             }
         } else {
             // Reset the bean back to original, but only if we had set them.
             $bean->{$field} = $originalvals['value'];
             // See comments for these properties above in regards to Bug 57400
             if (isset($originalvals['mime'])) {
                 $bean->file_mime_type = $originalvals['mime'];
             }
             if (isset($originalvals['ext'])) {
                 $bean->file_ext = $originalvals['ext'];
             }
             // Report the error
             $this->error = $upload_file->getErrorMessage();
         }
     } elseif (!empty($old_id)) {
         // It's a duplicate, I think
         if (empty($vardef['docUrl']) || empty($params[$prefix . $vardef['docUrl']])) {
             $upload_file->duplicate_file($old_id, $bean->id, $bean->{$field});
         } else {
             $docType = $vardef['docType'];
             $bean->{$docType} = $params[$prefix . $field . '_old_doctype'];
         }
     } elseif (!empty($params[$prefix . $field . '_remoteName'])) {
         // We aren't moving, we might need to do some remote linking
         $displayParams = array();
         $this->fillInOptions($vardef, $displayParams);
         if (isset($params[$prefix . $vardef['docId']]) && !empty($params[$prefix . $vardef['docId']]) && isset($params[$prefix . $vardef['docType']]) && !empty($params[$prefix . $vardef['docType']])) {
             $bean->{$field} = $params[$prefix . $field . '_remoteName'];
             require_once 'include/utils/file_utils.php';
             $extension = get_file_extension($bean->{$field});
             if (!empty($extension)) {
                 $bean->file_ext = $extension;
                 $bean->file_mime_type = get_mime_content_type_from_filename($bean->{$field});
             }
         }
     } elseif (!empty($duplicateModuleId)) {
         $upload_file->duplicate_file($duplicateModuleId, $bean->id, $bean->{$field});
         $bean->{$field} = $params[$field];
         require_once 'include/utils/file_utils.php';
         $extension = get_file_extension($bean->{$field});
         if (!empty($extension)) {
             $bean->file_ext = $extension;
             $bean->file_mime_type = get_mime_content_type_from_filename($bean->{$field});
         }
     }
     if ($vardef['allowEapm'] == true && empty($bean->{$field})) {
         $GLOBALS['log']->info("The {$field} is empty, clearing out the lot");
         // Looks like we are emptying this out
         $clearFields = array('docId', 'docType', 'docUrl', 'docDirectUrl');
         foreach ($clearFields as $clearMe) {
             if (!isset($vardef[$clearMe])) {
                 continue;
             }
             $clearField = $vardef[$clearMe];
             $bean->{$clearField} = '';
         }
     }
 }