本文整理汇总了PHP中UploadFile::duplicate_file方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadFile::duplicate_file方法的具体用法?PHP UploadFile::duplicate_file怎么用?PHP UploadFile::duplicate_file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UploadFile
的用法示例。
在下文中一共展示了UploadFile::duplicate_file方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: UploadFile
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: UploadFile
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: UploadFile
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: copyActivityAndRelateToBean
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: create_ref_email
/**
* 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;
//.........这里部分代码省略.........
示例6: handleSave
//.........这里部分代码省略.........
}
$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();
示例7: save
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: populateFromPost
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");
示例9: handleSave
//.........这里部分代码省略.........
$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;
}
}
示例10: handleAttachments
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']));
//.........这里部分代码省略.........
示例11: handleSave
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;
//.........这里部分代码省略.........
示例12: save
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: handleSave
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: handleAttachments
/**
* 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;
//.........这里部分代码省略.........
示例15: copyActivityAndRelateToBean
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);
}
}
}