예제 #1
0
 function action_save()
 {
     require_once 'include/upload_file.php';
     $GLOBALS['log']->debug('PERFORMING NOTES SAVE');
     $upload_file = new UploadFile('uploadfile');
     $do_final_move = 0;
     if (isset($_FILES['uploadfile']) && $upload_file->confirm_upload()) {
         if (!empty($this->bean->id) && !empty($_REQUEST['old_filename'])) {
             $upload_file->unlink_file($this->bean->id, $_REQUEST['old_filename']);
         }
         $this->bean->filename = $upload_file->get_stored_file_name();
         $this->bean->file_mime_type = $upload_file->mime_type;
         $do_final_move = 1;
     } else {
         if (isset($_REQUEST['old_filename'])) {
             $this->bean->filename = $_REQUEST['old_filename'];
         }
     }
     $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);
         }
     }
 }
예제 #2
0
 /**
  * This method prepares the received data and call the addFont method of the fontManager
  * @return boolean true on success
  */
 private function addFont()
 {
     $this->log = "";
     $error = false;
     $files = array("pdf_metric_file", "pdf_font_file");
     foreach ($files as $k) {
         // handle uploaded file
         $uploadFile = new UploadFile($k);
         if (isset($_FILES[$k]) && $uploadFile->confirm_upload()) {
             $uploadFile->final_move(basename($_FILES[$k]['name']));
             $uploadFileNames[$k] = $uploadFile->get_upload_path(basename($_FILES[$k]['name']));
         } else {
             $this->log = translate('ERR_PDF_NO_UPLOAD', "Configurator");
             $error = true;
         }
     }
     if (!$error) {
         require_once 'include/Sugarpdf/FontManager.php';
         $fontManager = new FontManager();
         $error = $fontManager->addFont($uploadFileNames["pdf_font_file"], $uploadFileNames["pdf_metric_file"], $_REQUEST['pdf_embedded'], $_REQUEST['pdf_encoding_table'], array(), htmlspecialchars_decode($_REQUEST['pdf_cidinfo'], ENT_QUOTES), $_REQUEST['pdf_style_list']);
         $this->log .= $fontManager->log;
         if ($error) {
             $this->log .= implode("\n", $fontManager->errors);
         }
     }
     return $error;
 }
예제 #3
0
 function action_save()
 {
     require_once 'include/upload_file.php';
     $GLOBALS['log']->debug('PERFORMING NOTES SAVE');
     $upload_file = new UploadFile('uploadfile');
     $do_final_move = 0;
     if (isset($_FILES['uploadfile']) && $upload_file->confirm_upload()) {
         if (!empty($this->bean->id) && !empty($_REQUEST['old_filename'])) {
             $upload_file->unlink_file($this->bean->id, $_REQUEST['old_filename']);
         }
         $this->bean->filename = $upload_file->get_stored_file_name();
         $this->bean->file_mime_type = $upload_file->mime_type;
         $do_final_move = 1;
     } else {
         if (isset($_REQUEST['old_filename'])) {
             $this->bean->filename = $_REQUEST['old_filename'];
         }
     }
     $this->bean->save();
     if ($do_final_move) {
         $upload_file->final_move($this->bean->id);
     } else {
         if (!empty($_REQUEST['old_id'])) {
             $upload_file->duplicate_file($_REQUEST['old_id'], $this->bean->id, $this->bean->filename);
         }
     }
 }
예제 #4
0
 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();
 }
예제 #5
0
 public function save(&$bean, $params, $field, $vardef, $prefix = '')
 {
     $fakeDisplayParams = array();
     $this->fillInOptions($vardef, $fakeDisplayParams);
     require_once 'include/upload_file.php';
     $upload_file = new UploadFile($prefix . $field . '_file');
     //remove file
     if (isset($_REQUEST['remove_file_' . $field]) && $params['remove_file_' . $field] == 1) {
         $upload_file->unlink_file($bean->{$field});
         $bean->{$field} = "";
     }
     $move = false;
     if (isset($_FILES[$prefix . $field . '_file']) && $upload_file->confirm_upload()) {
         if ($this->verify_image($upload_file)) {
             $bean->{$field} = $upload_file->get_stored_file_name();
             $move = true;
         } else {
             //not valid image.
             $GLOBALS['log']->fatal("Image Field : Not a Valid Image.");
             $temp = $vardef['vname'];
             $temp = translate($temp, $bean->module_name);
             SugarApplication::appendErrorMessage($temp . " Field :  Not a valid image format.");
         }
     }
     if (empty($bean->id)) {
         $bean->id = create_guid();
         $bean->new_with_id = true;
     }
     if ($move) {
         $upload_file->final_move($bean->id . '_' . $field);
         //BEAN ID IS THE FILE NAME IN THE INSTANCE.
         $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});
                     }
                 }
             }
         }
     }
 }
예제 #6
0
파일: File.php 프로젝트: klr2003/sourceread
 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);
 }
예제 #7
0
 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);
 }
예제 #8
0
 function action_save()
 {
     require_once 'include/upload_file.php';
     // CCL - Bugs 41103 and 43751.  41103 address the issue where the parent_id is set, but
     // the relate_id field overrides the relationship.  43751 fixes the problem where the relate_id and
     // parent_id are the same value (in which case it should just use relate_id) by adding the != check
     if (!empty($_REQUEST['relate_id']) && !empty($_REQUEST['parent_id']) && $_REQUEST['relate_id'] != $_REQUEST['parent_id']) {
         $_REQUEST['relate_id'] = false;
     }
     $GLOBALS['log']->debug('PERFORMING NOTES SAVE');
     $upload_file = new UploadFile('uploadfile');
     $do_final_move = 0;
     if (isset($_FILES['uploadfile']) && $upload_file->confirm_upload()) {
         if (!empty($this->bean->id) && !empty($_REQUEST['old_filename'])) {
             $upload_file->unlink_file($this->bean->id, $_REQUEST['old_filename']);
         }
         $this->bean->filename = $upload_file->get_stored_file_name();
         $this->bean->file_mime_type = $upload_file->mime_type;
         $do_final_move = 1;
     } else {
         if (isset($_REQUEST['old_filename'])) {
             $this->bean->filename = $_REQUEST['old_filename'];
         }
     }
     $check_notify = false;
     if (!empty($_POST['assigned_user_id']) && (empty($this->bean->fetched_row) || $this->bean->fetched_row['assigned_user_id'] != $_POST['assigned_user_id']) && $_POST['assigned_user_id'] != $GLOBALS['current_user']->id) {
         $check_notify = true;
     }
     $this->bean->save($check_notify);
     if ($do_final_move) {
         $upload_file->final_move($this->bean->id);
     } else {
         if (!empty($_REQUEST['old_id'])) {
             $upload_file->duplicate_file($_REQUEST['old_id'], $this->bean->id, $this->bean->filename);
         }
     }
 }
예제 #9
0
 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);
     }
 }
예제 #10
0
 /**
  * @see SugarView::display()
  */
 public function display()
 {
     global $mod_strings, $app_strings, $current_user;
     global $sugar_config, $locale;
     $this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']);
     $this->ss->assign("TYPE", !empty($_REQUEST['type']) ? $_REQUEST['type'] : "import");
     $this->ss->assign("SOURCE_ID", $_REQUEST['source_id']);
     $this->instruction = 'LBL_SELECT_PROPERTY_INSTRUCTION';
     $this->ss->assign('INSTRUCTION', $this->getInstruction());
     $this->ss->assign("MODULE_TITLE", $this->getModuleTitle(false), ENT_NOQUOTES);
     $this->ss->assign("CURRENT_STEP", $this->currentStep);
     $sugar_config['import_max_records_per_file'] = empty($sugar_config['import_max_records_per_file']) ? 1000 : $sugar_config['import_max_records_per_file'];
     $importSource = isset($_REQUEST['source']) ? $_REQUEST['source'] : 'csv';
     // Clear out this user's last import
     $seedUsersLastImport = BeanFactory::getBean('Import_2');
     $seedUsersLastImport->mark_deleted_by_user_id($current_user->id);
     ImportCacheFiles::clearCacheFiles();
     // handle uploaded file
     $uploadFile = new UploadFile('userfile');
     if (isset($_FILES['userfile']) && $uploadFile->confirm_upload()) {
         $uploadFile->final_move('IMPORT_' . $this->bean->object_name . '_' . $current_user->id);
         $uploadFileName = $uploadFile->get_upload_path('IMPORT_' . $this->bean->object_name . '_' . $current_user->id);
     } elseif (!empty($_REQUEST['tmp_file'])) {
         $uploadFileName = "upload://" . basename($_REQUEST['tmp_file']);
     } else {
         $this->_showImportError($mod_strings['LBL_IMPORT_MODULE_ERROR_NO_UPLOAD'], $_REQUEST['import_module'], 'Step2', true, null, true);
         return;
     }
     //check the file size, we dont want to process an empty file
     if (isset($_FILES['userfile']['size']) && $_FILES['userfile']['size'] == 0) {
         //this file is empty, throw error message
         $this->_showImportError($mod_strings['LBL_NO_LINES'], $_REQUEST['import_module'], 'Step2', false, null, true);
         return;
     }
     $mimeTypeOk = true;
     //check to see if the file mime type is not a form of text or application octed streramand fire error if not
     if (isset($_FILES['userfile']['type']) && strpos($_FILES['userfile']['type'], 'octet-stream') === false && strpos($_FILES['userfile']['type'], 'text') === false && strpos($_FILES['userfile']['type'], 'application/vnd.ms-excel') === false) {
         //this file does not have a known text or application type of mime type, issue the warning
         $error_msgs[] = $mod_strings['LBL_MIME_TYPE_ERROR_1'];
         $error_msgs[] = $mod_strings['LBL_MIME_TYPE_ERROR_2'];
         $this->_showImportError($error_msgs, $_REQUEST['import_module'], 'Step2', true, $mod_strings['LBL_OK']);
         $mimeTypeOk = false;
     }
     $this->ss->assign("FILE_NAME", $uploadFileName);
     // Now parse the file and look for errors
     $importFile = new ImportFile($uploadFileName, $_REQUEST['custom_delimiter'], html_entity_decode($_REQUEST['custom_enclosure'], ENT_QUOTES), FALSE);
     if ($this->shouldAutoDetectProperties($importSource)) {
         $GLOBALS['log']->debug("Auto detecing csv properties...");
         $autoDetectOk = $importFile->autoDetectCSVProperties();
         $importFileMap = array();
         $this->ss->assign("SOURCE", 'csv');
         if ($autoDetectOk === FALSE) {
             //show error only if previous mime type check has passed
             if ($mimeTypeOk) {
                 $this->ss->assign("AUTO_DETECT_ERROR", $mod_strings['LBL_AUTO_DETECT_ERROR']);
             }
         } else {
             $dateFormat = $importFile->getDateFormat();
             $timeFormat = $importFile->getTimeFormat();
             if ($dateFormat) {
                 $importFileMap['importlocale_dateformat'] = $dateFormat;
             }
             if ($timeFormat) {
                 $importFileMap['importlocale_timeformat'] = $timeFormat;
             }
         }
     } else {
         $impotMapSeed = $this->getImportMap($importSource);
         $importFile->setImportFileMap($impotMapSeed);
         $importFileMap = $impotMapSeed->getMapping($_REQUEST['import_module']);
     }
     $delimeter = $importFile->getFieldDelimeter();
     $enclosure = $importFile->getFieldEnclosure();
     $hasHeader = $importFile->hasHeaderRow();
     $encodeOutput = TRUE;
     //Handle users navigating back through the wizard.
     if (!empty($_REQUEST['previous_action']) && $_REQUEST['previous_action'] == 'Confirm') {
         $encodeOutput = FALSE;
         $importFileMap = $this->overloadImportFileMapFromRequest($importFileMap);
         $delimeter = !empty($_REQUEST['custom_delimiter']) ? $_REQUEST['custom_delimiter'] : $delimeter;
         $enclosure = isset($_REQUEST['custom_enclosure']) ? $_REQUEST['custom_enclosure'] : $enclosure;
         $enclosure = html_entity_decode($enclosure, ENT_QUOTES);
         $hasHeader = !empty($_REQUEST['has_header']) ? $_REQUEST['has_header'] : $hasHeader;
         if ($hasHeader == 'on') {
             $hasHeader = true;
         } else {
             if ($hasHeader == 'off') {
                 $hasHeader = false;
             }
         }
     }
     $this->ss->assign("IMPORT_ENCLOSURE_OPTIONS", $this->getEnclosureOptions($enclosure));
     $this->ss->assign("IMPORT_DELIMETER_OPTIONS", $this->getDelimeterOptions($delimeter));
     $this->ss->assign("CUSTOM_DELIMITER", $delimeter);
     $this->ss->assign("CUSTOM_ENCLOSURE", htmlentities($enclosure, ENT_QUOTES, 'utf-8'));
     $hasHeaderFlag = $hasHeader ? " CHECKED" : "";
     $this->ss->assign("HAS_HEADER_CHECKED", $hasHeaderFlag);
     if (!$importFile->fileExists()) {
         $this->_showImportError($mod_strings['LBL_CANNOT_OPEN'], $_REQUEST['import_module'], 'Step2', false, null, true);
         return;
     }
     //Check if we will exceed the maximum number of records allowed per import.
     $maxRecordsExceeded = FALSE;
     $maxRecordsWarningMessg = "";
     $lineCount = $importFile->getNumberOfLinesInfile();
     $maxLineCount = isset($sugar_config['import_max_records_total_limit']) ? $sugar_config['import_max_records_total_limit'] : 5000;
     if (!empty($maxLineCount) && $lineCount > $maxLineCount) {
         $maxRecordsExceeded = TRUE;
         $maxRecordsWarningMessg = string_format($mod_strings['LBL_IMPORT_ERROR_MAX_REC_LIMIT_REACHED'], array($lineCount, $maxLineCount));
     }
     //Retrieve a sample set of data
     $rows = $this->getSampleSet($importFile);
     $this->ss->assign('column_count', $this->getMaxColumnsInSampleSet($rows));
     $this->ss->assign('HAS_HEADER', $importFile->hasHeaderRow(FALSE));
     $this->ss->assign('getNumberJs', $locale->getNumberJs());
     $this->setImportFileCharacterSet($importFile, $importFileMap);
     $this->setDateTimeProperties($importFileMap);
     $this->setCurrencyOptions($importFileMap);
     $this->setNumberFormatOptions($importFileMap);
     $this->setNameFormatProperties($importFileMap);
     $importMappingJS = $this->getImportMappingJS();
     $this->ss->assign("SAMPLE_ROWS", $rows);
     $JS = $this->_getJS($maxRecordsExceeded, $maxRecordsWarningMessg, $importMappingJS, $importFileMap);
     $this->ss->assign("JAVASCRIPT", $JS);
     $content = $this->ss->fetch('modules/Import/tpls/confirm.tpl');
     $this->ss->assign("CONTENT", $content);
     $this->ss->display('modules/Import/tpls/wizardWrapper.tpl');
 }
예제 #11
0
 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);
     }
 }
예제 #12
0
 public function save(&$bean, $params, $field, $properties, $prefix = '')
 {
     require_once 'include/upload_file.php';
     $upload_file = new UploadFile($field);
     //remove file
     if (isset($_REQUEST['remove_imagefile_' . $field]) && $_REQUEST['remove_imagefile_' . $field] == 1) {
         $upload_file->unlink_file($bean->{$field});
         $bean->{$field} = "";
     }
     //uploadfile
     if (isset($_FILES[$field])) {
         //confirm only image file type can be uploaded
         if (verify_image_file($_FILES[$field]['tmp_name'])) {
             if ($upload_file->confirm_upload()) {
                 // for saveTempImage API
                 if (isset($params['temp']) && $params['temp'] === true) {
                     // Create the new field value
                     $bean->{$field} = create_guid();
                     // Move to temporary folder
                     if (!$upload_file->final_move($bean->{$field}, true)) {
                         // If this was a fail, reset the bean field to original
                         $this->error = $upload_file->getErrorMessage();
                     }
                 } else {
                     // Capture the old value in case of error
                     $oldvalue = $bean->{$field};
                     // Create the new field value
                     $bean->{$field} = create_guid();
                     // Add checking for actual file move for reporting to consumers
                     if (!$upload_file->final_move($bean->{$field})) {
                         // If this was a fail, reset the bean field to original
                         $bean->{$field} = $oldvalue;
                         $this->error = $upload_file->getErrorMessage();
                     }
                 }
             } else {
                 // Added error reporting
                 $this->error = $upload_file->getErrorMessage();
             }
         } else {
             $imgInfo = getimagesize($_FILES[$field]['tmp_name']);
             // if file is image then this image is no longer supported.
             if (false !== $imgInfo) {
                 $ext = end(explode('.', $_FILES[$field]['name']));
                 $this->error = string_format($GLOBALS['app_strings']['LBL_UPLOAD_IMAGE_FILE_NOT_SUPPORTED'], array($ext));
             } else {
                 $this->error = $GLOBALS['app_strings']["LBL_UPLOAD_IMAGE_FILE_INVALID"];
             }
         }
     }
     //Check if we have the duplicate value set and use it if $bean->$field is empty
     if (empty($bean->{$field}) && !empty($_REQUEST[$field . '_duplicate'])) {
         $bean->{$field} = $_REQUEST[$field . '_duplicate'];
     }
     // case when we should copy one file to another using merge-duplicate view
     // $params[$field . '_duplicateBeanId'] contains id of bean from
     // which we should copy file.
     if (!empty($params[$field]) && !empty($params[$field . '_duplicateBeanId'])) {
         $bean->{$field} = create_guid();
         $upload_file->duplicate_file($params[$field], $bean->{$field});
     }
 }
예제 #13
0
     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);
예제 #14
0
$success = TRUE;
if (isset($_FILES['reportfile']) && $upload_file->confirm_upload()) {
    $success = $template->set_reportfile($_FILES['reportfile']['tmp_name'], $upload_file->original_file_name);
    if (!$success) {
        $errors[] = "error compiling report " . $upload_file->original_file_name . " - " . $template->report_output;
    }
}
for ($i = 0; $i < 5; $i++) {
    $paramName = "subreport" . $i;
    $upload_file = new UploadFile($paramName);
    if (isset($_FILES[$paramName]) && $upload_file->confirm_upload()) {
        $success = $template->add_subreportfile($_FILES[$paramName]['tmp_name'], $upload_file->original_file_name);
        if (!$success) {
            $errors[] = "error compiling subreport " . $upload_file->original_file_name . " - " . $template->report_output;
        }
    }
}
for ($i = 0; $i < 5; $i++) {
    $paramName = "resource" . $i;
    $upload_file = new UploadFile($paramName);
    if (isset($_FILES[$paramName]) && $upload_file->confirm_upload()) {
        $template->add_resource_file($_FILES[$paramName]['tmp_name'], $upload_file->original_file_name);
    }
}
if (empty($errors)) {
    $return_id = $template->save();
    handleRedirect("", "");
} else {
    $_REQUEST["ZR_ERROR_MSG"] = join("<br/>", $errors);
    include "modules/ZuckerReportTemplate/EditView.php";
}
 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;
     }
 }
예제 #16
0
$uploadResult = '';
//commitModules();
if (isset($_REQUEST['languagePackAction']) && !empty($_REQUEST['languagePackAction'])) {
    switch ($_REQUEST['languagePackAction']) {
        case 'upload':
            $perform = false;
            $tempFile = '';
            if (isset($_REQUEST['release_id']) && $_REQUEST['release_id'] != "") {
                require_once 'ModuleInstall/PackageManager/PackageManager.php';
                $pm = new PackageManager();
                $tempFile = $pm->download($_REQUEST['release_id'], getcwd() . '/' . $sugar_config['upload_dir']);
                $perform = true;
                //$base_filename = urldecode($tempFile);
            } else {
                $file = new UploadFile('language_pack');
                if ($file->confirm_upload()) {
                    $perform = true;
                    if (strpos($file->mime_type, 'zip') !== false) {
                        // only .zip files
                        if (langPackFinalMove($file)) {
                            $perform = true;
                        } else {
                            $errors[] = $mod_strings['ERR_LANG_UPLOAD_3'];
                        }
                    } else {
                        $errors[] = $mod_strings['ERR_LANG_UPLOAD_2'];
                    }
                }
            }
            if ($perform) {
                // check for a real file
예제 #17
0
//		Module: module name, this module should have a file called TreeData.php
//		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 '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;
     }
 }
예제 #19
0
 /**
  * handles attachments of various kinds when sending email
  */
 function handleAttachments()
 {
     global $mod_strings;
     ///////////////////////////////////////////////////////////////////////////
     ////    ATTACHMENTS FROM DRAFTS
     if (($this->type == 'out' || $this->type == 'draft') && $this->status == 'draft' && isset($_REQUEST['record'])) {
         $this->getNotes($_REQUEST['record']);
         // cn: get notes from OLD email for use in new email
     }
     ////    END ATTACHMENTS FROM DRAFTS
     ///////////////////////////////////////////////////////////////////////////
     ///////////////////////////////////////////////////////////////////////////
     ////    ATTACHMENTS FROM FORWARDS
     // Bug 8034 Jenny - Need the check for type 'draft' here to handle cases where we want to save
     // forwarded messages as drafts.  We still need to save the original message's attachments.
     if (($this->type == 'out' || $this->type == 'draft') && isset($_REQUEST['origType']) && $_REQUEST['origType'] == 'forward' && isset($_REQUEST['return_id']) && !empty($_REQUEST['return_id'])) {
         $this->getNotes($_REQUEST['return_id'], true);
     }
     // cn: bug 8034 - attachments from forward/replies lost when saving in draft
     if (isset($_REQUEST['prior_attachments']) && !empty($_REQUEST['prior_attachments']) && $this->new_with_id == true) {
         $exIds = explode(",", $_REQUEST['prior_attachments']);
         if (!isset($_REQUEST['template_attachment'])) {
             $_REQUEST['template_attachment'] = array();
         }
         $_REQUEST['template_attachment'] = array_merge($_REQUEST['template_attachment'], $exIds);
     }
     ////    END ATTACHMENTS FROM FORWARDS
     ///////////////////////////////////////////////////////////////////////////
     ///////////////////////////////////////////////////////////////////////////
     ////	ATTACHMENTS FROM TEMPLATES
     // to preserve individual email integrity, we must dupe Notes and associated files
     // for each outbound email - good for integrity, bad for filespace
     if (isset($_REQUEST['template_attachment']) && !empty($_REQUEST['template_attachment'])) {
         $removeArr = array();
         $noteArray = array();
         if (isset($_REQUEST['temp_remove_attachment']) && !empty($_REQUEST['temp_remove_attachment'])) {
             $removeArr = $_REQUEST['temp_remove_attachment'];
         }
         foreach ($_REQUEST['template_attachment'] as $noteId) {
             if (in_array($noteId, $removeArr)) {
                 continue;
             }
             $noteTemplate = new Note();
             $noteTemplate->retrieve($noteId);
             $noteTemplate->id = create_guid();
             $noteTemplate->new_with_id = true;
             // duplicating the note with files
             $noteTemplate->parent_id = $this->id;
             $noteTemplate->parent_type = $this->module_dir;
             $noteTemplate->date_entered = '';
             $noteTemplate->save();
             $noteFile = new UploadFile('none');
             $noteFile->duplicate_file($noteId, $noteTemplate->id, $noteTemplate->filename);
             $noteArray[] = $noteTemplate;
         }
         $this->attachments = array_merge($this->attachments, $noteArray);
     }
     ////	END ATTACHMENTS FROM TEMPLATES
     ///////////////////////////////////////////////////////////////////////////
     ///////////////////////////////////////////////////////////////////////////
     ////	ADDING NEW ATTACHMENTS
     $max_files_upload = 10;
     // Jenny - Bug 8211 Since attachments for drafts have already been processed,
     // we don't need to re-process them.
     if ($this->status != "draft") {
         $notes_list = array();
         if (!empty($this->id) && !$this->new_with_id) {
             $note = new Note();
             $where = "notes.parent_id='{$this->id}'";
             $notes_list = $note->get_full_list("", $where, true);
         }
         $this->attachments = array_merge($this->attachments, $notes_list);
     }
     // cn: Bug 5995 - rudimentary error checking
     $filesError = array(0 => 'UPLOAD_ERR_OK - There is no error, the file uploaded with success.', 1 => 'UPLOAD_ERR_INI_SIZE - The uploaded file exceeds the upload_max_filesize directive in php.ini.', 2 => 'UPLOAD_ERR_FORM_SIZE - The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', 3 => 'UPLOAD_ERR_PARTIAL - The uploaded file was only partially uploaded.', 4 => 'UPLOAD_ERR_NO_FILE - No file was uploaded.', 5 => 'UNKNOWN ERROR', 6 => 'UPLOAD_ERR_NO_TMP_DIR - Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3.', 7 => 'UPLOAD_ERR_CANT_WRITE - Failed to write file to disk. Introduced in PHP 5.1.0.');
     for ($i = 0; $i < $max_files_upload; $i++) {
         // cn: Bug 5995 - rudimentary error checking
         if (!isset($_FILES["email_attachment{$i}"])) {
             $GLOBALS['log']->debug("Email Attachment {$i} does not exist.");
             continue;
         }
         if ($_FILES['email_attachment' . $i]['error'] != 0 && $_FILES['email_attachment' . $i]['error'] != 4) {
             $GLOBALS['log']->debug('Email Attachment could not be attach due to error: ' . $filesError[$_FILES['email_attachment' . $i]['error']]);
             continue;
         }
         $note = new Note();
         $note->parent_id = $this->id;
         $note->parent_type = $this->module_dir;
         $upload_file = new UploadFile('email_attachment' . $i);
         if (empty($upload_file)) {
             continue;
         }
         if (isset($_FILES['email_attachment' . $i]) && $upload_file->confirm_upload()) {
             $note->filename = $upload_file->get_stored_file_name();
             $note->file = $upload_file;
             $note->name = $mod_strings['LBL_EMAIL_ATTACHMENT'] . ': ' . $note->file->original_file_name;
             $this->attachments[] = $note;
         }
     }
     $this->saved_attachments = array();
     foreach ($this->attachments as $note) {
         if (!empty($note->id)) {
             array_push($this->saved_attachments, $note);
             continue;
         }
         $note->parent_id = $this->id;
         $note->parent_type = 'Emails';
         $note->file_mime_type = $note->file->mime_type;
         $note_id = $note->save();
         $this->saved_attachments[] = $note;
         $note->id = $note_id;
         $note->file->final_move($note->id);
     }
     ////	END NEW ATTACHMENTS
     ///////////////////////////////////////////////////////////////////////////
     ///////////////////////////////////////////////////////////////////////////
     ////	ATTACHMENTS FROM DOCUMENTS
     for ($i = 0; $i < 10; $i++) {
         if (isset($_REQUEST['documentId' . $i]) && !empty($_REQUEST['documentId' . $i])) {
             $doc = new Document();
             $docRev = new DocumentRevision();
             $docNote = new Note();
             $noteFile = new UploadFile('none');
             $doc->retrieve($_REQUEST['documentId' . $i]);
             $docRev->retrieve($doc->document_revision_id);
             $this->saved_attachments[] = $docRev;
             // cn: bug 9723 - Emails with documents send GUID instead of Doc name
             $docNote->name = $docRev->getDocumentRevisionNameForDisplay();
             $docNote->filename = $docRev->filename;
             $docNote->description = $doc->description;
             $docNote->parent_id = $this->id;
             $docNote->parent_type = 'Emails';
             $docNote->file_mime_type = $docRev->file_mime_type;
             $docId = $docNote = $docNote->save();
             $noteFile->duplicate_file($docRev->id, $docId, $docRev->filename);
         }
     }
     ////	END ATTACHMENTS FROM DOCUMENTS
     ///////////////////////////////////////////////////////////////////////////
     ///////////////////////////////////////////////////////////////////////////
     ////	REMOVE ATTACHMENTS
     if (isset($_REQUEST['remove_attachment']) && !empty($_REQUEST['remove_attachment'])) {
         foreach ($_REQUEST['remove_attachment'] as $noteId) {
             $q = 'UPDATE notes SET deleted = 1 WHERE id = \'' . $noteId . '\'';
             $this->db->query($q);
         }
     }
     //this will remove attachments that have been selected to be removed from drafts.
     if (isset($_REQUEST['removeAttachment']) && !empty($_REQUEST['removeAttachment'])) {
         $exRemoved = explode('::', $_REQUEST['removeAttachment']);
         foreach ($exRemoved as $noteId) {
             $q = 'UPDATE notes SET deleted = 1 WHERE id = \'' . $noteId . '\'';
             $this->db->query($q);
         }
     }
     ////	END REMOVE ATTACHMENTS
     ///////////////////////////////////////////////////////////////////////////
 }
예제 #20
0
 public function save(&$bean, $params, $field, $vardef, $prefix = '')
 {
     $fakeDisplayParams = array();
     $this->fillInOptions($vardef, $fakeDisplayParams);
     require_once 'include/upload_file.php';
     $upload_file = new UploadFile($prefix . $field . '_file');
     //remove file
     if (isset($_REQUEST['remove_file_' . $field]) && $params['remove_file_' . $field] == 1) {
         $upload_file->unlink_file($bean->{$field});
         $bean->{$field} = "";
     }
     $move = false;
     if (isset($_FILES[$prefix . $field . '_file']) && $upload_file->confirm_upload()) {
         $bean->{$field} = $upload_file->get_stored_file_name();
         $bean->file_mime_type = $upload_file->mime_type;
         $bean->file_ext = $upload_file->file_ext;
         $move = true;
     }
     if (!empty($params['isDuplicate']) && $params['isDuplicate'] == 'true') {
         // This way of detecting duplicates is used in Notes
         $old_id = $params['relate_id'];
     }
     if (!empty($params['duplicateSave']) && !empty($params['duplicateId'])) {
         // It's a duplicate
         $old_id = $params['duplicateId'];
     }
     // Backwards compatibility for fields that still use customCode to handle the file uploads
     if (!$move && empty($old_id) && isset($_FILES['uploadfile'])) {
         $upload_file = new UploadFile('uploadfile');
         if ($upload_file->confirm_upload()) {
             $bean->{$field} = $upload_file->get_stored_file_name();
             $bean->file_mime_type = $upload_file->mime_type;
             $bean->file_ext = $upload_file->file_ext;
             $move = true;
         }
     } else {
         if (!$move && !empty($old_id) && isset($_REQUEST['uploadfile']) && !isset($_REQUEST[$prefix . $field . '_file'])) {
             // I think we are duplicating a backwards compatibility module.
             $upload_file = new UploadFile('uploadfile');
         }
     }
     if (empty($bean->id)) {
         $bean->id = create_guid();
         $bean->new_with_id = true;
     }
     if ($move) {
         $upload_file->final_move($bean->id);
         $upload_file->upload_doc($bean, $bean->id, $params[$prefix . $vardef['docType']], $bean->{$field}, $upload_file->mime_type);
     } else {
         if (!empty($old_id)) {
             // It's a duplicate, I think
             if (empty($params[$prefix . $vardef['docUrl']])) {
                 $upload_file->duplicate_file($old_id, $bean->id, $bean->{$field});
             } else {
                 $docType = $vardef['docType'];
                 $bean->{$docType} = $params[$prefix . $field . '_old_doctype'];
             }
         } else {
             if (!empty($params[$prefix . $field . '_remoteName'])) {
                 // We aren't moving, we might need to do some remote linking
                 $displayParams = array();
                 $this->fillInOptions($vardef, $displayParams);
                 if (isset($params[$prefix . $vardef['docId']]) && !empty($params[$prefix . $vardef['docId']]) && isset($params[$prefix . $vardef['docType']]) && !empty($params[$prefix . $vardef['docType']])) {
                     $bean->{$field} = $params[$prefix . $field . '_remoteName'];
                     require_once 'include/utils/file_utils.php';
                     $extension = get_file_extension($bean->{$field});
                     if (!empty($extension)) {
                         $bean->file_ext = $extension;
                         $bean->file_mime_type = get_mime_content_type_from_filename($bean->{$field});
                     }
                 }
             }
         }
     }
     if ($vardef['allowEapm'] == true && empty($bean->{$field})) {
         $GLOBALS['log']->info("The {$field} is empty, clearing out the lot");
         // Looks like we are emptying this out
         $clearFields = array('docId', 'docType', 'docUrl', 'docDirectUrl');
         foreach ($clearFields as $clearMe) {
             if (!isset($vardef[$clearMe])) {
                 continue;
             }
             $clearField = $vardef[$clearMe];
             $bean->{$clearField} = '';
         }
     }
 }
 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;
     }
 }
예제 #22
0
<?php

require_once 'include/formbase.php';
require_once 'include/upload_file.php';
require_once 'modules/ZuckerWordTemplate/WordTemplate.php';
global $mod_strings;
$mod_strings = return_module_language($current_language, 'ZuckerReports');
$template = new WordTemplate();
if (!empty($_REQUEST['record'])) {
    $template = $template->retrieve($_REQUEST['record']);
    if ($template == null) {
        echo "no access";
        exit;
    }
}
$template = populateFromPost("", $template);
$template->querytemplate_id = $_REQUEST["querytemplate_id"];
$upload_file = new UploadFile('templatefile');
$success = TRUE;
if (isset($_FILES['templatefile']) && $upload_file->confirm_upload()) {
    $success = $template->set_templatefile($_FILES['templatefile']['tmp_name'], $upload_file->original_file_name);
    if (!$success) {
        $_REQUEST["ZR_ERROR_MSG"] = $template->report_output;
    }
}
if ($success) {
    $return_id = $template->save();
    handleRedirect("", "");
} else {
    include "modules/ZuckerWordTemplate/EditView.php";
}
예제 #23
0
 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;
     }
 }
예제 #24
0
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     require_once 'include/formbase.php';
     require_once 'include/upload_file.php';
     $focus = new Note();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     if (empty($focus->name)) {
         return null;
     }
     if (!isset($_REQUEST['date_due_flag'])) {
         $focus->date_due_flag = 0;
     }
     if (!isset($_REQUEST['portal_flag'])) {
         $focus->portal_flag = '0';
     }
     $upload_file = new UploadFile('uploadfile');
     $do_final_move = 0;
     if (isset($_FILES['uploadfile']) && $upload_file->confirm_upload()) {
         if (!empty($focus->id) && !empty($_REQUEST['old_filename'])) {
             $upload_file->unlink_file($focus->id, $_REQUEST['old_filename']);
         }
         $focus->filename = $upload_file->get_stored_file_name();
         $focus->file_mime_type = $upload_file->mime_type;
         $do_final_move = 1;
     } else {
         if (isset($_REQUEST['old_filename'])) {
             $focus->filename = $_REQUEST['old_filename'];
         }
     }
     $return_id = $focus->save();
     if ($do_final_move) {
         $upload_file->final_move($focus->id);
     } else {
         if (!empty($_REQUEST['old_id'])) {
             $upload_file->duplicate_file($_REQUEST['old_id'], $focus->id, $focus->filename);
         }
     }
     if ($redirect) {
         $GLOBALS['log']->debug("Saved record with id of " . $return_id);
         handleRedirect($return_id, "Notes");
     } else {
         return $focus;
     }
 }
 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;
     }
 }
예제 #26
0
    /**
     * @see SugarView::display()
     */
    public function display()
    {
        global $mod_strings, $app_strings, $current_user, $sugar_config, $app_list_strings, $locale;
        $this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']);
        $has_header = isset($_REQUEST['has_header']) ? 1 : 0;
        $sugar_config['import_max_records_per_file'] = empty($sugar_config['import_max_records_per_file']) ? 1000 : $sugar_config['import_max_records_per_file'];
        // Clear out this user's last import
        $seedUsersLastImport = new UsersLastImport();
        $seedUsersLastImport->mark_deleted_by_user_id($current_user->id);
        ImportCacheFiles::clearCacheFiles();
        // attempt to lookup a preexisting field map
        // use the custom one if specfied to do so in step 1
        $field_map = array();
        $default_values = array();
        $ignored_fields = array();
        if (!empty($_REQUEST['source_id'])) {
            $mapping_file = new ImportMap();
            $mapping_file->retrieve($_REQUEST['source_id'], false);
            $_REQUEST['source'] = $mapping_file->source;
            $has_header = $mapping_file->has_header;
            if (isset($mapping_file->delimiter)) {
                $_REQUEST['custom_delimiter'] = $mapping_file->delimiter;
            }
            if (isset($mapping_file->enclosure)) {
                $_REQUEST['custom_enclosure'] = htmlentities($mapping_file->enclosure);
            }
            $field_map = $mapping_file->getMapping();
            $default_values = $mapping_file->getDefaultValues();
            $this->ss->assign("MAPNAME", $mapping_file->name);
            $this->ss->assign("CHECKMAP", 'checked="checked" value="on"');
        } else {
            // Try to see if we have a custom mapping we can use
            // based upon the where the records are coming from
            // and what module we are importing into
            $classname = 'ImportMap' . ucfirst($_REQUEST['source']);
            if (file_exists("modules/Import/{$classname}.php")) {
                require_once "modules/Import/{$classname}.php";
            } elseif (file_exists("custom/modules/Import/{$classname}.php")) {
                require_once "custom/modules/Import/{$classname}.php";
            } else {
                require_once "custom/modules/Import/ImportMapOther.php";
                $classname = 'ImportMapOther';
                $_REQUEST['source'] = 'other';
            }
            if (class_exists($classname)) {
                $mapping_file = new $classname();
                if (isset($mapping_file->delimiter)) {
                    $_REQUEST['custom_delimiter'] = $mapping_file->delimiter;
                }
                if (isset($mapping_file->enclosure)) {
                    $_REQUEST['custom_enclosure'] = htmlentities($mapping_file->enclosure);
                }
                $ignored_fields = $mapping_file->getIgnoredFields($_REQUEST['import_module']);
                $field_map = $mapping_file->getMapping($_REQUEST['import_module']);
            }
        }
        $this->ss->assign("CUSTOM_DELIMITER", !empty($_REQUEST['custom_delimiter']) ? $_REQUEST['custom_delimiter'] : ",");
        $this->ss->assign("CUSTOM_ENCLOSURE", !empty($_REQUEST['custom_enclosure']) ? $_REQUEST['custom_enclosure'] : "");
        // handle uploaded file
        $uploadFile = new UploadFile('userfile');
        if (isset($_FILES['userfile']) && $uploadFile->confirm_upload()) {
            $uploadFile->final_move('IMPORT_' . $this->bean->object_name . '_' . $current_user->id);
            $uploadFileName = $uploadFile->get_upload_path('IMPORT_' . $this->bean->object_name . '_' . $current_user->id);
        } else {
            $this->_showImportError($mod_strings['LBL_IMPORT_MODULE_ERROR_NO_UPLOAD'], $_REQUEST['import_module'], 'Step2');
            return;
        }
        // split file into parts
        $splitter = new ImportFileSplitter($uploadFileName, $sugar_config['import_max_records_per_file']);
        $splitter->splitSourceFile($_REQUEST['custom_delimiter'], html_entity_decode($_REQUEST['custom_enclosure'], ENT_QUOTES), $has_header);
        // Now parse the file and look for errors
        $importFile = new ImportFile($uploadFileName, $_REQUEST['custom_delimiter'], html_entity_decode($_REQUEST['custom_enclosure'], ENT_QUOTES));
        if (!$importFile->fileExists()) {
            $this->_showImportError($mod_strings['LBL_CANNOT_OPEN'], $_REQUEST['import_module'], 'Step2');
            return;
        }
        // retrieve first 3 rows
        $rows = array();
        $system_charset = $locale->default_export_charset;
        $user_charset = $locale->getExportCharset();
        $other_charsets = 'UTF-8, UTF-7, ASCII, CP1252, EUC-JP, SJIS, eucJP-win, SJIS-win, JIS, ISO-2022-JP';
        $detectable_charsets = "UTF-8, {$user_charset}, {$system_charset}, {$other_charsets}";
        // Bug 26824 - mb_detect_encoding() thinks CP1252 is IS0-8859-1, so use that instead in the encoding list passed to the function
        $detectable_charsets = str_replace('CP1252', 'ISO-8859-1', $detectable_charsets);
        $charset_for_import = $user_charset;
        //We will set the default import charset option by user's preference.
        $able_to_detect = function_exists('mb_detect_encoding');
        for ($i = 0; $i < 3; $i++) {
            $rows[$i] = $importFile->getNextRow();
            if (!empty($rows[$i]) && $able_to_detect) {
                foreach ($rows[$i] as &$temp_value) {
                    $current_charset = mb_detect_encoding($temp_value, $detectable_charsets);
                    if (!empty($current_charset) && $current_charset != "UTF-8") {
                        $temp_value = $locale->translateCharset($temp_value, $current_charset);
                        // we will use utf-8 for displaying the data on the page.
                        $charset_for_import = $current_charset;
                        //set the default import charset option according to the current_charset.
                        //If it is not utf-8, tt may be overwritten by the later one. So the uploaded file should not contain two types of charset($user_charset, $system_charset), and I think this situation will not occur.
                    }
                }
            }
        }
        $ret_field_count = $importFile->getFieldCount();
        // Bug 14689 - Parse the first data row to make sure it has non-empty data in it
        $isempty = true;
        if ($rows[(int) $has_header] != false) {
            foreach ($rows[(int) $has_header] as $value) {
                if (strlen(trim($value)) > 0) {
                    $isempty = false;
                    break;
                }
            }
        }
        if ($isempty || $rows[(int) $has_header] == false) {
            $this->_showImportError($mod_strings['LBL_NO_LINES'], $_REQUEST['import_module'], 'Step2');
            return;
        }
        // save first row to send to step 4
        $this->ss->assign("FIRSTROW", base64_encode(serialize($rows[0])));
        // Now build template
        $this->ss->assign("TMP_FILE", $uploadFileName);
        $this->ss->assign("FILECOUNT", $splitter->getFileCount());
        $this->ss->assign("RECORDCOUNT", $splitter->getRecordCount());
        $this->ss->assign("RECORDTHRESHOLD", $sugar_config['import_max_records_per_file']);
        $this->ss->assign("SOURCE", $_REQUEST['source']);
        $this->ss->assign("TYPE", $_REQUEST['type']);
        $this->ss->assign("DELETE_INLINE_PNG", SugarThemeRegistry::current()->getImage('basic_search', 'align="absmiddle" alt="' . $app_strings['LNK_DELETE'] . '" border="0"'));
        $this->ss->assign("PUBLISH_INLINE_PNG", SugarThemeRegistry::current()->getImage('advanced_search', 'align="absmiddle" alt="' . $mod_strings['LBL_PUBLISH'] . '" border="0"'));
        $this->ss->assign("MODULE_TITLE", $this->getModuleTitle());
        $this->ss->assign("STEP4_TITLE", strip_tags(str_replace("\n", "", getClassicModuleTitle($mod_strings['LBL_MODULE_NAME'], array($mod_strings['LBL_MODULE_NAME'], $mod_strings['LBL_STEP_4_TITLE']), false))));
        $this->ss->assign("HEADER", $app_strings['LBL_IMPORT'] . " " . $mod_strings['LBL_MODULE_NAME']);
        // we export it as email_address, but import as email1
        $field_map['email_address'] = 'email1';
        // build each row; row count is determined by the the number of fields in the import file
        $columns = array();
        $mappedFields = array();
        for ($field_count = 0; $field_count < $ret_field_count; $field_count++) {
            // See if we have any field map matches
            $defaultValue = "";
            // Bug 31260 - If the data rows have more columns than the header row, then just add a new header column
            if (!isset($rows[0][$field_count])) {
                $rows[0][$field_count] = '';
            }
            // See if we can match the import row to a field in the list of fields to import
            $firstrow_name = trim(str_replace(":", "", $rows[0][$field_count]));
            if ($has_header && isset($field_map[$firstrow_name])) {
                $defaultValue = $field_map[$firstrow_name];
            } elseif (isset($field_map[$field_count])) {
                $defaultValue = $field_map[$field_count];
            } elseif (empty($_REQUEST['source_id'])) {
                $defaultValue = trim($rows[0][$field_count]);
            }
            // build string of options
            $fields = $this->bean->get_importable_fields();
            $options = array();
            $defaultField = '';
            foreach ($fields as $fieldname => $properties) {
                // get field name
                if (!empty($properties['vname'])) {
                    $displayname = str_replace(":", "", translate($properties['vname'], $this->bean->module_dir));
                } else {
                    $displayname = str_replace(":", "", translate($properties['name'], $this->bean->module_dir));
                }
                // see if this is required
                $req_mark = "";
                $req_class = "";
                if (array_key_exists($fieldname, $this->bean->get_import_required_fields())) {
                    $req_mark = ' ' . $app_strings['LBL_REQUIRED_SYMBOL'];
                    $req_class = ' class="required" ';
                }
                // see if we have a match
                $selected = '';
                if (!empty($defaultValue) && !in_array($fieldname, $mappedFields) && !in_array($fieldname, $ignored_fields)) {
                    if (strtolower($fieldname) == strtolower($defaultValue) || strtolower($fieldname) == str_replace(" ", "_", strtolower($defaultValue)) || strtolower($displayname) == strtolower($defaultValue) || strtolower($displayname) == str_replace(" ", "_", strtolower($defaultValue))) {
                        $selected = ' selected="selected" ';
                        $defaultField = $fieldname;
                        $mappedFields[] = $fieldname;
                    }
                }
                // get field type information
                $fieldtype = '';
                if (isset($properties['type']) && isset($mod_strings['LBL_IMPORT_FIELDDEF_' . strtoupper($properties['type'])])) {
                    $fieldtype = ' [' . $mod_strings['LBL_IMPORT_FIELDDEF_' . strtoupper($properties['type'])] . '] ';
                }
                if (isset($properties['comment'])) {
                    $fieldtype .= ' - ' . $properties['comment'];
                }
                $options[$displayname . $fieldname] = '<option value="' . $fieldname . '" title="' . $displayname . htmlentities($fieldtype) . '"' . $selected . $req_class . '>' . $displayname . $req_mark . '</option>\\n';
            }
            // get default field value
            $defaultFieldHTML = '';
            if (!empty($defaultField)) {
                $defaultFieldHTML = getControl($_REQUEST['import_module'], $defaultField, $fields[$defaultField], isset($default_values[$defaultField]) ? $default_values[$defaultField] : '');
            }
            if (isset($default_values[$defaultField])) {
                unset($default_values[$defaultField]);
            }
            // Bug 27046 - Sort the column name picker alphabetically
            ksort($options);
            $columns[] = array('field_choices' => implode('', $options), 'default_field' => $defaultFieldHTML, 'cell1' => str_replace("&quot;", '', htmlspecialchars($rows[0][$field_count])), 'cell2' => str_replace("&quot;", '', htmlspecialchars($rows[1][$field_count])), 'cell3' => str_replace("&quot;", '', htmlspecialchars($rows[2][$field_count])), 'show_remove' => false);
        }
        // add in extra defaulted fields if they are in the mapping record
        if (count($default_values) > 0) {
            foreach ($default_values as $field_name => $default_value) {
                // build string of options
                $fields = $this->bean->get_importable_fields();
                $options = array();
                $defaultField = '';
                foreach ($fields as $fieldname => $properties) {
                    // get field name
                    if (!empty($properties['vname'])) {
                        $displayname = str_replace(":", "", translate($properties['vname'], $this->bean->module_dir));
                    } else {
                        $displayname = str_replace(":", "", translate($properties['name'], $this->bean->module_dir));
                    }
                    // see if this is required
                    $req_mark = "";
                    $req_class = "";
                    if (array_key_exists($fieldname, $this->bean->get_import_required_fields())) {
                        $req_mark = ' ' . $app_strings['LBL_REQUIRED_SYMBOL'];
                        $req_class = ' class="required" ';
                    }
                    // see if we have a match
                    $selected = '';
                    if (strtolower($fieldname) == strtolower($field_name) && !in_array($fieldname, $mappedFields) && !in_array($fieldname, $ignored_fields)) {
                        $selected = ' selected="selected" ';
                        $defaultField = $fieldname;
                        $mappedFields[] = $fieldname;
                    }
                    // get field type information
                    $fieldtype = '';
                    if (isset($properties['type']) && isset($mod_strings['LBL_IMPORT_FIELDDEF_' . strtoupper($properties['type'])])) {
                        $fieldtype = ' [' . $mod_strings['LBL_IMPORT_FIELDDEF_' . strtoupper($properties['type'])] . '] ';
                    }
                    if (isset($properties['comment'])) {
                        $fieldtype .= ' - ' . $properties['comment'];
                    }
                    $options[$displayname . $fieldname] = '<option value="' . $fieldname . '" title="' . $displayname . $fieldtype . '"' . $selected . $req_class . '>' . $displayname . $req_mark . '</option>\\n';
                }
                // get default field value
                $defaultFieldHTML = '';
                if (!empty($defaultField)) {
                    $defaultFieldHTML = getControl($_REQUEST['import_module'], $defaultField, $fields[$defaultField], $default_value);
                }
                // Bug 27046 - Sort the column name picker alphabetically
                ksort($options);
                $columns[] = array('field_choices' => implode('', $options), 'default_field' => $defaultFieldHTML, 'show_remove' => true);
                $ret_field_count++;
            }
        }
        $this->ss->assign("COLUMNCOUNT", $ret_field_count);
        $this->ss->assign("rows", $columns);
        // get list of valid date/time formats
        $timeFormat = $current_user->getUserDateTimePreferences();
        $timeOptions = get_select_options_with_id($sugar_config['time_formats'], $timeFormat['time']);
        $dateOptions = get_select_options_with_id($sugar_config['date_formats'], $timeFormat['date']);
        $this->ss->assign('TIMEOPTIONS', $timeOptions);
        $this->ss->assign('DATEOPTIONS', $dateOptions);
        $this->ss->assign('datetimeformat', $GLOBALS['timedate']->get_cal_date_time_format());
        // get list of valid timezones
        $userTZ = $current_user->getPreference('timezone');
        if (empty($userTZ)) {
            $userTZ = TimeDate::userTimezone();
        }
        $this->ss->assign('TIMEZONE_CURRENT', $userTZ);
        $this->ss->assign('TIMEZONEOPTIONS', TimeDate::getTimezoneList());
        // get currency preference
        require_once 'modules/Currencies/ListCurrency.php';
        $currency = new ListCurrency();
        $cur_id = $locale->getPrecedentPreference('currency', $current_user);
        if ($cur_id) {
            $selectCurrency = $currency->getSelectOptions($cur_id);
            $this->ss->assign("CURRENCY", $selectCurrency);
        } else {
            $selectCurrency = $currency->getSelectOptions();
            $this->ss->assign("CURRENCY", $selectCurrency);
        }
        $currenciesVars = "";
        $i = 0;
        foreach ($locale->currencies as $id => $arrVal) {
            $currenciesVars .= "currencies[{$i}] = '{$arrVal['symbol']}';\n";
            $i++;
        }
        $currencySymbolsJs = <<<eoq
var currencies = new Object;
{$currenciesVars}
function setSymbolValue(id) {
    document.getElementById('symbol').value = currencies[id];
}
eoq;
        $this->ss->assign('currencySymbolJs', $currencySymbolsJs);
        // fill significant digits dropdown
        $significantDigits = $locale->getPrecedentPreference('default_currency_significant_digits', $current_user);
        $sigDigits = '';
        for ($i = 0; $i <= 6; $i++) {
            if ($significantDigits == $i) {
                $sigDigits .= '<option value="' . $i . '" selected="true">' . $i . '</option>';
            } else {
                $sigDigits .= '<option value="' . $i . '">' . $i . '</option>';
            }
        }
        $this->ss->assign('sigDigits', $sigDigits);
        $num_grp_sep = $current_user->getPreference('num_grp_sep');
        $dec_sep = $current_user->getPreference('dec_sep');
        $this->ss->assign("NUM_GRP_SEP", empty($num_grp_sep) ? $sugar_config['default_number_grouping_seperator'] : $num_grp_sep);
        $this->ss->assign("DEC_SEP", empty($dec_sep) ? $sugar_config['default_decimal_seperator'] : $dec_sep);
        $this->ss->assign('getNumberJs', $locale->getNumberJs());
        // Name display format
        $this->ss->assign('default_locale_name_format', $locale->getLocaleFormatMacro($current_user));
        $this->ss->assign('getNameJs', $locale->getNameJs());
        // Charset
        $charsetOptions = get_select_options_with_id($locale->getCharsetSelect(), $charset_for_import);
        //wdong,  bug 25927, here we should use the charset testing results from above.
        $this->ss->assign('CHARSETOPTIONS', $charsetOptions);
        // handle building index selector
        global $dictionary, $current_language;
        require_once "include/templates/TemplateGroupChooser.php";
        $chooser_array = array();
        $chooser_array[0] = array();
        $idc = new ImportDuplicateCheck($this->bean);
        $chooser_array[1] = $idc->getDuplicateCheckIndexes();
        $chooser = new TemplateGroupChooser();
        $chooser->args['id'] = 'selected_indices';
        $chooser->args['values_array'] = $chooser_array;
        $chooser->args['left_name'] = 'choose_index';
        $chooser->args['right_name'] = 'ignore_index';
        $chooser->args['left_label'] = $mod_strings['LBL_INDEX_USED'];
        $chooser->args['right_label'] = $mod_strings['LBL_INDEX_NOT_USED'];
        $this->ss->assign("TAB_CHOOSER", $chooser->display());
        // show notes
        if ($this->bean instanceof Person) {
            $module_key = "LBL_CONTACTS_NOTE_";
        } elseif ($this->bean instanceof Company) {
            $module_key = "LBL_ACCOUNTS_NOTE_";
        } else {
            $module_key = "LBL_" . strtoupper($_REQUEST['import_module']) . "_NOTE_";
        }
        $notetext = '';
        for ($i = 1; isset($mod_strings[$module_key . $i]); $i++) {
            $notetext .= '<li>' . $mod_strings[$module_key . $i] . '</li>';
        }
        $this->ss->assign("NOTETEXT", $notetext);
        $this->ss->assign("HAS_HEADER", $has_header ? 'on' : 'off');
        // get list of required fields
        $required = array();
        foreach (array_keys($this->bean->get_import_required_fields()) as $name) {
            $properties = $this->bean->getFieldDefinition($name);
            if (!empty($properties['vname'])) {
                $required[$name] = str_replace(":", "", translate($properties['vname'], $this->bean->module_dir));
            } else {
                $required[$name] = str_replace(":", "", translate($properties['name'], $this->bean->module_dir));
            }
        }
        // include anything needed for quicksearch to work
        require_once "include/TemplateHandler/TemplateHandler.php";
        $quicksearch_js = TemplateHandler::createQuickSearchCode($fields, $fields, 'importstep3');
        $this->ss->assign("JAVASCRIPT", $quicksearch_js . "\n" . $this->_getJS($required));
        $this->ss->assign('required_fields', implode(', ', $required));
        $this->ss->display('modules/Import/tpls/step3.tpl');
    }
예제 #27
0
require_once 'include/entryPoint.php';
require_once 'include/upload_file.php';
global $sugar_config;
$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)) {
예제 #28
0
 /**
  * Method that extracts contents of a file and upload
  * @param string $fileName
  * @param boolean $getFileContents
  * @return type
  * @throws Exception
  * @codeCoverageIgnore
  */
 public static function uploadPublicFile($fileName, $getFileContents = true)
 {
     try {
         $sugarUploader = new UploadFile($fileName);
         if ($getFileContents) {
             return $sugarUploader->get_file_contents();
         } else {
             $sugarUploader->confirm_upload();
             $sugarUploader->final_move($fileName . '_' . create_guid());
             return array();
         }
     } catch (Exception $oException) {
         throw $oException;
     }
 }
 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;
     }
 }
예제 #30
0
 function preprocess_fields_on_save()
 {
     parent::preprocess_fields_on_save();
     require_once 'include/upload_file.php';
     $upload_file = new UploadFile("picture");
     //remove file
     if (isset($_REQUEST['remove_imagefile_picture']) && $_REQUEST['remove_imagefile_picture'] == 1) {
         UploadFile::unlink_file($this->picture);
         $this->picture = "";
     }
     //uploadfile
     if (isset($_FILES['picture'])) {
         //confirm only image file type can be uploaded
         $imgType = array('image/gif', 'image/png', 'image/bmp', 'image/jpeg', 'image/jpg', 'image/pjpeg');
         if (in_array($_FILES['picture']["type"], $imgType)) {
             if ($upload_file->confirm_upload()) {
                 $this->picture = create_guid();
                 $upload_file->final_move($this->picture);
             }
         }
     }
 }