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); } } }
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); } } }
public function pre_save() { require_once 'include/upload_file.php'; $upload_file = new UploadFile('filename_file'); if (isset($_FILES['filename_file']) && $upload_file->confirm_upload()) { $filename = $upload_file->get_stored_file_name(); $file_ext = $upload_file->file_ext; if (empty($this->bean->id)) { $this->bean->id = create_guid(); $this->bean->new_with_id = true; } $account = null; if (isset($_POST['xphotobucketaccount_id'])) { $account = BeanFactory::getBean('xPhotobucketAccounts', $_POST['xphotobucketaccount_id']); } // $resp = $account->upload_media('image', $upload_file->temp_file_location, "{$this->bean->id}.{$file_ext}", $_POST['name']); $resp = $account->upload_media('base64', base64_encode(file_get_contents($upload_file->temp_file_location)), "{$this->bean->id}.{$file_ext}", $_POST['name']); $this->bean->browse_url = $resp['browseurl']; $this->bean->image_url = $resp['url']; $this->bean->thumb_url = $resp['thumb']; } else { echo "Upload file error"; sugar_cleanup(true); } parent::pre_save(); }
function save($check_notify = false) { $move = false; $upload_file = new UploadFile('uploadfile'); if (isset($_FILES['uploadfile']) && $upload_file->confirm_upload()) { $this->filename = $upload_file->get_stored_file_name(); $this->file_mime_type = $upload_file->mime_type; $this->file_ext = $upload_file->file_ext; $move = true; } parent::save($check_notify); if ($move) { $upload_file->final_move($this->id); } return $this->id; //handleRedirect($return_id, $this->object_name); }
function action_save() { $move = false; $file = new File(); $file = populateFromPost('', $file); $upload_file = new UploadFile('uploadfile'); $return_id = ''; if (isset($_FILES['uploadfile']) && $upload_file->confirm_upload()) { $file->filename = $upload_file->get_stored_file_name(); $file->file_mime_type = $upload_file->mime_type; $file->file_ext = $upload_file->file_ext; $move = true; } $return_id = $file->save(); if ($move) { $upload_file->final_move($file->id); } handleRedirect($return_id, $this->object_name); }
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); } } }
public function save(&$bean, $params, $field, $properties, $prefix = '') { require_once 'include/upload_file.php'; $upload_file = new UploadFile($prefix . $field); //remove file if (isset($_REQUEST['remove_file_' . $field]) && $_REQUEST['remove_file_' . $field] == 1) { $upload_file->unlink_file($bean->{$field}); $bean->{$field} = ""; } $move = false; if (isset($_FILES[$prefix . $field]) && $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 ($move) { if (empty($bean->id)) { $bean->id = create_guid(); $bean->new_with_id = true; } $upload_file->final_move($bean->id); } }
function handleSave($prefix, $redirect = true, $useRequired = false) { require_once 'modules/ClientOrders/Clientorder.php'; require_once 'log4php/LoggerManager.php'; require_once 'include/formbase.php'; require_once 'include/TimeDate.php'; require_once 'include/upload_file.php'; require_once 'config.php'; global $sugar_config; $timedate = new TimeDate(); $focus = new Clientorder(); if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) { return null; } $focus = populateFromPost($prefix, $focus); if (!ACLController::checkAccess($focus->module_dir, 'edit', $focus->isOwner($current_user->id))) { ACLController::displayNoAccess(true); } $upload_file = new UploadFile('uploadfile'); if (isset($_FILES['uploadfile']) && $upload_file->confirm_upload()) { $focus->stored_file_name = $upload_file->get_stored_file_name(); $focus->imagename = $upload_file->get_stored_file_name(); $focus->imagepath = $sugar_config['upload_dir'] . $return_id . $upload_file->get_stored_file_name(); $do_final_move = 1; } if (isset($_REQUEST['is_active']) && $_REQUEST['is_active'] == "1") { $focus->is_active = 1; } else { $focus->is_active = 0; } if (!$focus->ACLAccess('Save')) { ACLController::displayNoAccess(true); sugar_cleanup(true); } //Goodwill if (empty($_POST['record']) && empty($_POST['dup_checked'])) { $duplicateClientOrders = $this->checkForDuplicates($prefix); if (isset($duplicateClientOrders)) { //$GLOBALS['log']->info("Duplicate Clientorder:".$duplicateClientOrders['id']); $this->handleRedirect($return_id, "ClientOrders"); return null; } } //End Goodwill $return_id = $focus->save(); if ($do_final_move) { $upload_file->final_move($return_id); $focus->stored_file_name = $sugar_config['upload_dir'] . $return_id . $upload_file->get_stored_file_name(); $focus->imagename = $upload_file->get_stored_file_name(); $focus->imagepath = $sugar_config['upload_dir'] . $return_id . $upload_file->get_stored_file_name(); $focus->save(); //echo "dir:".$sugar_config['upload_dir']."<br/>"; //echo $focus->imagepath."<br/>"; } //echo "Saved record with id of ".$return_id; $GLOBALS['log']->debug("Saved record with id of " . $return_id); if ($redirect) { handleRedirect($return_id, "ClientOrders"); } else { return $focus; } }
public function saveUpdate($bean, $event, $arguments) { if (!isAOPEnabled()) { return; } global $current_user, $app_list_strings; if (empty($bean->fetched_row) || !$bean->id) { if (!$bean->state) { $bean->state = $app_list_strings['case_state_default_key']; } if ($bean->status == "New") { $bean->status = $app_list_strings['case_status_default_key']; } //New case - assign if (!$bean->assigned_user_id) { $userId = $this->getAssignToUser(); $bean->assigned_user_id = $userId; $bean->notify_inworkflow = true; } return; } if ($_REQUEST['module'] == 'Import') { return; } //Grab the update field and create a new update with it. $text = $bean->update_text; if (!$text && empty($_FILES['case_update_file'])) { //No text or files, so nothing really to save. return; } $bean->update_text = ""; $case_update = new AOP_Case_Updates(); $case_update->name = $text; $case_update->internal = $bean->internal; $bean->internal = false; $case_update->assigned_user_id = $current_user->id; if (strlen($text) > $this->slug_size) { $case_update->name = substr($text, 0, $this->slug_size) . "..."; } $case_update->description = nl2br($text); $case_update->case_id = $bean->id; $case_update->save(); $fileCount = $this->arrangeFilesArray(); for ($x = 0; $x < $fileCount; $x++) { if ($_FILES['case_update_file']['error'][$x] == UPLOAD_ERR_NO_FILE) { continue; } $uploadFile = new UploadFile('case_update_file' . $x); if (!$uploadFile->confirm_upload()) { continue; } $note = $this->newNote($case_update->id); $note->name = $uploadFile->get_stored_file_name(); $note->file_mime_type = $uploadFile->mime_type; $note->filename = $uploadFile->get_stored_file_name(); $note->save(); $uploadFile->final_move($note->id); } $postPrefix = 'case_update_id_'; foreach ($_POST as $key => $val) { if (strpos($key, $postPrefix) !== 0 || empty($val)) { continue; } //Val is selected doc id $doc = BeanFactory::getBean('Documents', $val); if (!$doc) { continue; } $note = $this->newNote($case_update->id); $note->name = $doc->document_name; $note->file_mime_type = $doc->last_rev_mime_type; $note->filename = $doc->filename; $note->save(); $srcFile = "upload://{$doc->document_revision_id}"; $destFile = "upload://{$note->id}"; copy($srcFile, $destFile); } }
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; } }
require_once 'ModuleInstall/PackageManager.php'; $pm = new PackageManager(); $tempFile = $pm->download('', '', $_REQUEST['release_id']); $perform = true; $base_filename = urldecode($tempFile); } elseif (!empty($_REQUEST['load_module_from_dir'])) { //copy file to proper location then call performSetup copy($_REQUEST['load_module_from_dir'] . '/' . $_REQUEST['upgrade_zip_escaped'], "upload://" . $_REQUEST['upgrade_zip_escaped']); $perform = true; $base_filename = urldecode($_REQUEST['upgrade_zip_escaped']); } else { if (empty($_FILES['upgrade_zip']['tmp_name'])) { echo $mod_strings['ERR_UW_NO_UPLOAD_FILE']; } else { $upload = new UploadFile('upgrade_zip'); if (!$upload->confirm_upload() || strtolower(pathinfo($upload->get_stored_file_name(), PATHINFO_EXTENSION)) != 'zip' || !$upload->final_move($upload->get_stored_file_name())) { unlinkTempFiles(); sugar_die("Invalid Package"); } else { $tempFile = "upload://" . $upload->get_stored_file_name(); $perform = true; $base_filename = urldecode($_REQUEST['upgrade_zip_escaped']); } } } if ($perform) { $manifest_file = extractManifest($tempFile); if (is_file($manifest_file)) { //SCAN THE MANIFEST FILE TO MAKE SURE NO COPIES OR ANYTHING ARE HAPPENING IN IT $ms = new ModuleScanner(); $fileIssues = $ms->scanFile($manifest_file);
$Document->retrieve($_REQUEST['record']); } if (!$Document->ACLAccess('Save')) { ACLController::displayNoAccess(true); sugar_cleanup(true); } 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 {
// Function: name of the function to be called in TreeData.php, the function will be called statically. // PARAM prefixed properties: array of these property/values will be passed to the function as parameter. require_once 'include/JSON.php'; require_once 'include/upload_file.php'; if (!is_dir($cachedir = sugar_cached('images/'))) { mkdir_recursive($cachedir); } // cn: bug 11012 - fixed some MIME types not getting picked up. Also changed array iterator. $imgType = array('image/gif', 'image/png', 'image/x-png', 'image/bmp', 'image/jpeg', 'image/jpg', 'image/pjpeg'); $ret = array(); foreach ($_FILES as $k => $file) { if (in_array(strtolower($_FILES[$k]['type']), $imgType) && $_FILES[$k]['size'] > 0) { $upload_file = new UploadFile($k); // check the file if ($upload_file->confirm_upload()) { $dest = $cachedir . basename($upload_file->get_stored_file_name()); // target name $guid = create_guid(); if ($upload_file->final_move($guid)) { // move to uploads $path = $upload_file->get_upload_path($guid); // if file is OK, copy to cache if (verify_uploaded_image($path) && copy($path, $dest)) { $ret[] = $dest; } // remove temp file unlink($path); } } } }
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; } }
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} = ''; } } }
$supportedExtensions = array('jpg', 'png', 'jpeg'); $json = getJSONobj(); $rmdir = true; $returnArray = array(); if ($json->decode(html_entity_decode($_REQUEST['forQuotes']))) { $returnArray['forQuotes'] = "quotes"; } else { $returnArray['forQuotes'] = "company"; } $upload_ok = false; if (isset($_FILES['file_1'])) { $upload = new UploadFile('file_1'); if ($upload->confirm_upload()) { $dir = "upload://cache/images"; UploadStream::ensureDir($dir); $file_name = $dir . "/" . $upload->get_stored_file_name(); if ($upload->final_move($file_name)) { $upload_ok = true; } } } if (!$upload_ok) { $returnArray['data'] = 'not_recognize'; echo $json->encode($returnArray); sugar_cleanup(); exit; } if (file_exists($file_name) && is_file($file_name)) { $returnArray['path'] = substr($file_name, 9); // strip upload prefix $returnArray['url'] = 'cache/images/' . $upload->get_stored_file_name();
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} = ''; } } }
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; } }
/** * 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 /////////////////////////////////////////////////////////////////////////// }
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; } }
/** * Create a new Note object * @param array $data Note data * @param Email $email parent email */ protected function createNote($data, $email) { require_once 'include/upload_file.php'; $upload_file = new UploadFile('uploadfile'); $decodedFile = base64_decode($data['content']); $upload_file->set_for_soap($data['filename'], $decodedFile); $ext_pos = strrpos($upload_file->stored_file_name, "."); $upload_file->file_ext = substr($upload_file->stored_file_name, $ext_pos + 1); $note = BeanFactory::getBean('Notes'); $note->id = create_guid(); $note->new_with_id = true; if (in_array($upload_file->file_ext, $this->config['upload_badext'])) { $upload_file->stored_file_name .= ".txt"; $upload_file->file_ext = "txt"; } $note->filename = $upload_file->get_stored_file_name(); if (isset($data['type'])) { $note->file_mime_type = $data['type']; } else { $note->file_mime_type = $upload_file->getMimeSoap($note->filename); } $note->team_id = $email->team_id; $note->team_set_id = $email->team_set_id; $note->assigned_user_id = $email->assigned_user_id; $note->parent_type = 'Emails'; $note->parent_id = $email->id; $note->name = $note->filename; $note->save(); $upload_file->final_move($note->id); }
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; } }
$json = getJSONobj(); $rmdir = true; $returnArray = array(); if ($json->decode(html_entity_decode($_REQUEST['forQuotes']))) { $returnArray['forQuotes'] = "quotes"; } else { $returnArray['forQuotes'] = "company"; } $upload_ok = false; $upload_path = 'tmp_logo_' . $returnArray['forQuotes'] . '_upload'; if (isset($_FILES['file_1'])) { $upload = new UploadFile('file_1'); if ($upload->confirm_upload()) { $upload_dir = 'upload://' . $upload_path; UploadStream::ensureDir($upload_dir); $file_name = $upload_dir . "/" . $upload->get_stored_file_name(); if ($upload->final_move($file_name)) { $upload_ok = true; } } } if (!$upload_ok) { $returnArray['data'] = 'not_recognize'; echo $json->encode($returnArray); sugar_cleanup(true); } if (file_exists($file_name) && is_file($file_name)) { $encoded_file_name = rawurlencode($upload->get_stored_file_name()); $returnArray['path'] = $upload_path . '/' . $encoded_file_name; $returnArray['url'] = 'cache/images/' . $encoded_file_name; if (!verify_uploaded_image($file_name, $returnArray['forQuotes'] == 'quotes')) {
function handleSave($prefix, $redirect = true, $useRequired = false) { require_once 'modules/Paper/Paper.php'; require_once 'log4php/LoggerManager.php'; require_once 'include/formbase.php'; require_once 'include/TimeDate.php'; require_once 'include/upload_file.php'; require_once 'config.php'; global $sugar_config; $timedate = new TimeDate(); $focus = new Paper(); /*if($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))){ return null; }*/ $focus = populateFromPost($prefix, $focus); if (!ACLController::checkAccess($focus->module_dir, 'edit', $focus->isOwner($current_user->id))) { ACLController::displayNoAccess(true); } $upload_file = new UploadFile('uploadfile'); if (isset($_FILES['uploadfile']) && $upload_file->confirm_upload()) { $focus->stored_file_name = $upload_file->get_stored_file_name(); $focus->imagename = $upload_file->get_stored_file_name(); $focus->imagepath = $sugar_config['upload_dir'] . $return_id . $upload_file->get_stored_file_name(); $do_final_move = 1; } if (!isset($_REQUEST['active'])) { $focus->active = 'off'; } if (!$focus->ACLAccess('Save')) { ACLController::displayNoAccess(true); sugar_cleanup(true); } //Goodwill if (empty($_POST['record']) && empty($_POST['dup_checked'])) { $duplicatePaper = $this->checkForDuplicates($prefix); if (isset($duplicatePaper)) { //$GLOBALS['log']->info("Duplicate Product:".$duplicateProducts['id']); $this->handleRedirect($return_id, "Paper"); return null; } } //End Goodwill $return_id = $focus->save(); if ($do_final_move) { $upload_file->final_move($return_id); $focus->stored_file_name = $sugar_config['upload_dir'] . $return_id . $upload_file->get_stored_file_name(); $focus->imagename = $upload_file->get_stored_file_name(); $focus->imagepath = $sugar_config['upload_dir'] . $return_id . $upload_file->get_stored_file_name(); $focus->save(); //echo "dir:".$sugar_config['upload_dir']."<br/>"; //echo $focus->imagepath."<br/>"; } $paper_id = $return_id; $pref_supplier_id = $focus->pref_supplier_id; $result = $focus->db->query("SELECT count(*) AS the_count FROM papers_relation WHERE material_id = '{$paper_id}' AND relation_id = '{$pref_supplier_id}'"); $row = $focus->db->fetchByAssoc($result, -1, true); $row_count = $row['the_count']; if ($row_count == 0) { $id = create_guid(); $result = $focus->db->query("INSERT INTO papers_relation (id, paper_id, relation_id, relation_type, deleted) VALUES ('{$id}','{$paper_id}','{$pref_supplier_id}','Suppliers', '0')"); } //echo "Saved record with id of ".$return_id; $GLOBALS['log']->debug("Saved record with id of " . $return_id); if ($redirect) { handleRedirect($return_id, "Paper"); } else { return $focus; } }
/* Bug 51722 - Cannot Upload Upgrade File if System Settings Are Not Sufficient, Just Make sure that we can upload no matter what, set the default to 60M */ global $sugar_config; $upload_maxsize_backup = $sugar_config['upload_maxsize']; $sugar_config['upload_maxsize'] = 60000000; /* End Bug 51722 */ if (!$upload->confirm_upload()) { logThis('ERROR: no file uploaded!'); echo $mod_strings['ERR_UW_NO_FILE_UPLOADED']; $error = $upload->get_upload_error(); // add PHP error if isset if ($error) { $out = "<b><span class='error'>{$mod_strings['ERR_UW_PHP_FILE_ERRORS'][$error]}</span></b><br />"; } } else { $tempFile = "upload://" . $upload->get_stored_file_name(); if (!$upload->final_move($tempFile)) { logThis('ERROR: could not move temporary file to final destination!'); unlinkUWTempFiles(); $out = "<b><span class='error'>{$mod_strings['ERR_UW_NOT_VALID_UPLOAD']}</span></b><br />"; } else { logThis('File uploaded to ' . $tempFile); $base_filename = urldecode(basename($tempFile)); $perform = true; } } /* Bug 51722 - Restore the upload size in the config */ $sugar_config['upload_maxsize'] = $upload_maxsize_backup; /* End Bug 51722 */ } if ($perform) {