/** * 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; }
function action_save() { require_once 'include/upload_file.php'; $GLOBALS['log']->debug('PERFORMING NOTES SAVE'); $upload_file = new UploadFile('uploadfile'); $do_final_move = 0; if (isset($_FILES['uploadfile']) && $upload_file->confirm_upload()) { if (!empty($this->bean->id) && !empty($_REQUEST['old_filename'])) { $upload_file->unlink_file($this->bean->id, $_REQUEST['old_filename']); } $this->bean->filename = $upload_file->get_stored_file_name(); $this->bean->file_mime_type = $upload_file->mime_type; $do_final_move = 1; } else { if (isset($_REQUEST['old_filename'])) { $this->bean->filename = $_REQUEST['old_filename']; } } $this->bean->save(); if ($do_final_move) { $upload_file->final_move($this->bean->id); } else { if (!empty($_REQUEST['old_id'])) { $upload_file->duplicate_file($_REQUEST['old_id'], $this->bean->id, $this->bean->filename); } } }
function action_save() { require_once 'include/upload_file.php'; $GLOBALS['log']->debug('PERFORMING NOTES SAVE'); $upload_file = new UploadFile('uploadfile'); $do_final_move = 0; if (isset($_FILES['uploadfile']) && $upload_file->confirm_upload()) { if (!empty($this->bean->id) && !empty($_REQUEST['old_filename'])) { $upload_file->unlink_file($this->bean->id, $_REQUEST['old_filename']); } $this->bean->filename = $upload_file->get_stored_file_name(); $this->bean->file_mime_type = $upload_file->mime_type; $do_final_move = 1; } else { if (isset($_REQUEST['old_filename'])) { $this->bean->filename = $_REQUEST['old_filename']; } } $check_notify = false; if (!empty($_POST['assigned_user_id']) && (empty($this->bean->fetched_row) || $this->bean->fetched_row['assigned_user_id'] != $_POST['assigned_user_id']) && $_POST['assigned_user_id'] != $GLOBALS['current_user']->id) { $check_notify = true; } $this->bean->save($check_notify); if ($do_final_move) { $upload_file->final_move($this->bean->id); } else { if (!empty($_REQUEST['old_id'])) { $upload_file->duplicate_file($_REQUEST['old_id'], $this->bean->id, $this->bean->filename); } } }
function save($check_notify = false) { $move = false; $upload_file = new UploadFile('uploadfile'); if (isset($_FILES['uploadfile']) && $upload_file->confirm_upload()) { $this->filename = $upload_file->get_stored_file_name(); $this->file_mime_type = $upload_file->mime_type; $this->file_ext = $upload_file->file_ext; $move = true; } parent::save($check_notify); if ($move) { $upload_file->final_move($this->id); } return $this->id; //handleRedirect($return_id, $this->object_name); }
function action_save() { $move = false; $file = new File(); $file = populateFromPost('', $file); $upload_file = new UploadFile('uploadfile'); $return_id = ''; if (isset($_FILES['uploadfile']) && $upload_file->confirm_upload()) { $file->filename = $upload_file->get_stored_file_name(); $file->file_mime_type = $upload_file->mime_type; $file->file_ext = $upload_file->file_ext; $move = true; } $return_id = $file->save(); if ($move) { $upload_file->final_move($file->id); } handleRedirect($return_id, $this->object_name); }
function action_save() { require_once 'include/upload_file.php'; // CCL - Bugs 41103 and 43751. 41103 address the issue where the parent_id is set, but // the relate_id field overrides the relationship. 43751 fixes the problem where the relate_id and // parent_id are the same value (in which case it should just use relate_id) by adding the != check if (!empty($_REQUEST['relate_id']) && !empty($_REQUEST['parent_id']) && $_REQUEST['relate_id'] != $_REQUEST['parent_id']) { $_REQUEST['relate_id'] = false; } $GLOBALS['log']->debug('PERFORMING NOTES SAVE'); $upload_file = new UploadFile('uploadfile'); $do_final_move = 0; if (isset($_FILES['uploadfile']) && $upload_file->confirm_upload()) { if (!empty($this->bean->id) && !empty($_REQUEST['old_filename'])) { $upload_file->unlink_file($this->bean->id, $_REQUEST['old_filename']); } $this->bean->filename = $upload_file->get_stored_file_name(); $this->bean->file_mime_type = $upload_file->mime_type; $do_final_move = 1; } else { if (isset($_REQUEST['old_filename'])) { $this->bean->filename = $_REQUEST['old_filename']; } } $check_notify = false; if (!empty($_POST['assigned_user_id']) && (empty($this->bean->fetched_row) || $this->bean->fetched_row['assigned_user_id'] != $_POST['assigned_user_id']) && $_POST['assigned_user_id'] != $GLOBALS['current_user']->id) { $check_notify = true; } $this->bean->save($check_notify); if ($do_final_move) { $upload_file->final_move($this->bean->id); } else { if (!empty($_REQUEST['old_id'])) { $upload_file->duplicate_file($_REQUEST['old_id'], $this->bean->id, $this->bean->filename); } } }
public function save(&$bean, $params, $field, $properties, $prefix = '') { require_once 'include/upload_file.php'; $upload_file = new UploadFile($prefix . $field); //remove file if (isset($_REQUEST['remove_file_' . $field]) && $_REQUEST['remove_file_' . $field] == 1) { $upload_file->unlink_file($bean->{$field}); $bean->{$field} = ""; } $move = false; if (isset($_FILES[$prefix . $field]) && $upload_file->confirm_upload()) { $bean->{$field} = $upload_file->get_stored_file_name(); $bean->file_mime_type = $upload_file->mime_type; $bean->file_ext = $upload_file->file_ext; $move = true; } if ($move) { if (empty($bean->id)) { $bean->id = create_guid(); $bean->new_with_id = true; } $upload_file->final_move($bean->id); } }
upload no matter what, set the default to 60M */ global $sugar_config; $upload_maxsize_backup = $sugar_config['upload_maxsize']; $sugar_config['upload_maxsize'] = 60000000; /* End Bug 51722 */ if (!$upload->confirm_upload()) { logThis('ERROR: no file uploaded!'); echo $mod_strings['ERR_UW_NO_FILE_UPLOADED']; $error = $upload->get_upload_error(); // add PHP error if isset if ($error) { $out = "<b><span class='error'>{$mod_strings['ERR_UW_PHP_FILE_ERRORS'][$error]}</span></b><br />"; } } else { $tempFile = "upload://" . $upload->get_stored_file_name(); if (!$upload->final_move($tempFile)) { logThis('ERROR: could not move temporary file to final destination!'); unlinkUWTempFiles(); $out = "<b><span class='error'>{$mod_strings['ERR_UW_NOT_VALID_UPLOAD']}</span></b><br />"; } else { logThis('File uploaded to ' . $tempFile); $base_filename = urldecode(basename($tempFile)); $perform = true; } } /* Bug 51722 - Restore the upload size in the config */ $sugar_config['upload_maxsize'] = $upload_maxsize_backup; /* End Bug 51722 */ } if ($perform) { $manifest_file = extractManifest($tempFile);
$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']); $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 $tempFile = $file->get_stored_filename(); if ($file->final_move($tempFile)) { $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 $uploadResult = $mod_strings['LBL_LANG_SUCCESS']; $result = langPackUnpack('langpack', $tempFile); } else { $errors[] = $mod_strings['ERR_LANG_UPLOAD_1'];
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);
/** * @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(""", '', htmlspecialchars($rows[0][$field_count])), 'cell2' => str_replace(""", '', htmlspecialchars($rows[1][$field_count])), 'cell3' => str_replace(""", '', 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'); }
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); } } } } if (!empty($ret)) { $json = getJSONobj(); echo $json->encode($ret);
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); } } } }
$json = getJSONobj(); $rmdir = true; $returnArray = array(); if ($json->decode(html_entity_decode($_REQUEST['forQuotes']))) { $returnArray['forQuotes'] = "quotes"; } else { $returnArray['forQuotes'] = "company"; } $upload_ok = false; if (isset($_FILES['file_1'])) { $upload = new UploadFile('file_1'); if ($upload->confirm_upload()) { $dir = "upload://cache/images"; UploadStream::ensureDir($dir); $file_name = $dir . "/" . $upload->get_stored_file_name(); if ($upload->final_move($file_name)) { $upload_ok = true; } } } if (!$upload_ok) { $returnArray['data'] = 'not_recognize'; echo $json->encode($returnArray); sugar_cleanup(); exit; } if (file_exists($file_name) && is_file($file_name)) { $returnArray['path'] = substr($file_name, 9); // strip upload prefix $returnArray['url'] = 'cache/images/' . $upload->get_stored_file_name(); if (!verify_uploaded_image($file_name, $returnArray['forQuotes'] == 'quotes')) {
if (isset($_REQUEST['SaveRevision'])) { //fetch the document record. $Document->retrieve($_REQUEST['return_id']); if ($useRequired && !checkRequired($prefix, array_keys($Revision->required_fields))) { return null; } $Revision = populateFromPost($prefix, $Revision); $upload_file = new UploadFile('uploadfile'); if (isset($_FILES['uploadfile']) && $upload_file->confirm_upload()) { $Revision->filename = $upload_file->get_stored_file_name(); $Revision->file_mime_type = $upload_file->mime_type; $Revision->file_ext = $upload_file->file_ext; $do_final_move = 1; } //save revision $Revision->document_id = $_REQUEST['return_id']; $Revision->save(); //revsion is the document. $Document->document_revision_id = $Revision->id; $Document->save(); $return_id = $Document->id; } if ($do_final_move) { $upload_file->final_move($Revision->id); } else { if (!empty($_REQUEST['old_id'])) { $upload_file->duplicate_file($_REQUEST['old_id'], $Revision->id, $Revision->filename); } } $GLOBALS['log']->debug("Saved record with id of " . $return_id); handleRedirect($return_id, "Documents");
public function saveUpdate($bean, $event, $arguments) { if (!isAOPEnabled()) { return; } global $current_user, $app_list_strings; if (empty($bean->fetched_row) || !$bean->id) { if (!$bean->state) { $bean->state = $app_list_strings['case_state_default_key']; } if ($bean->status == "New") { $bean->status = $app_list_strings['case_status_default_key']; } //New case - assign if (!$bean->assigned_user_id) { $userId = $this->getAssignToUser(); $bean->assigned_user_id = $userId; $bean->notify_inworkflow = true; } return; } if ($_REQUEST['module'] == 'Import') { return; } //Grab the update field and create a new update with it. $text = $bean->update_text; if (!$text && empty($_FILES['case_update_file'])) { //No text or files, so nothing really to save. return; } $bean->update_text = ""; $case_update = new AOP_Case_Updates(); $case_update->name = $text; $case_update->internal = $bean->internal; $bean->internal = false; $case_update->assigned_user_id = $current_user->id; if (strlen($text) > $this->slug_size) { $case_update->name = substr($text, 0, $this->slug_size) . "..."; } $case_update->description = nl2br($text); $case_update->case_id = $bean->id; $case_update->save(); $fileCount = $this->arrangeFilesArray(); for ($x = 0; $x < $fileCount; $x++) { if ($_FILES['case_update_file']['error'][$x] == UPLOAD_ERR_NO_FILE) { continue; } $uploadFile = new UploadFile('case_update_file' . $x); if (!$uploadFile->confirm_upload()) { continue; } $note = $this->newNote($case_update->id); $note->name = $uploadFile->get_stored_file_name(); $note->file_mime_type = $uploadFile->mime_type; $note->filename = $uploadFile->get_stored_file_name(); $note->save(); $uploadFile->final_move($note->id); } $postPrefix = 'case_update_id_'; foreach ($_POST as $key => $val) { if (strpos($key, $postPrefix) !== 0 || empty($val)) { continue; } //Val is selected doc id $doc = BeanFactory::getBean('Documents', $val); if (!$doc) { continue; } $note = $this->newNote($case_update->id); $note->name = $doc->document_name; $note->file_mime_type = $doc->last_rev_mime_type; $note->filename = $doc->filename; $note->save(); $srcFile = "upload://{$doc->document_revision_id}"; $destFile = "upload://{$note->id}"; copy($srcFile, $destFile); } }
function handleSave($prefix, $redirect = true, $useRequired = false) { require_once '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; } }
$note->name = $focus->name; if ($zuckerreports_config["debug"] == "yes") { $note->description = $focus->report_output; } $note->filename = $focus->report_result_name; if ($_REQUEST['parent_module'] == 'Contacts') { $note->contact_id = $_REQUEST['parent_id']; } else { $note->parent_type = $_REQUEST['parent_module']; $note->parent_id = $_REQUEST['parent_id']; } $note->save(); $uf = new UploadFile("upload"); $uf->set_for_soap($focus->report_result_name, file_get_contents($focus->report_result)); $uf->stored_file_name = $uf->create_stored_filename(); $uf->final_move($note->id); $note_url = "index.php?action=DetailView&module=Notes&record=" . $note->id . "&return_module=ZuckerReports&return_action=ReportOnDemand"; } if (!empty($_REQUEST['send_email'])) { $mail = new SugarPHPMailer(); $emails = split(",", $_REQUEST['send_email']); foreach ($emails as $email) { $mail->AddAddress($email); } $admin = new Administration(); $admin->retrieveSettings(); if ($admin->settings['mail_sendtype'] == "SMTP") { $mail->Mailer = "smtp"; $mail->Host = $admin->settings['mail_smtpserver']; $mail->Port = $admin->settings['mail_smtpport']; if ($admin->settings['mail_smtpauth_req']) {
/** * Create a new Note object * @param array $data Note data * @param Email $email parent email */ protected function createNote($data, $email) { require_once 'include/upload_file.php'; $upload_file = new UploadFile('uploadfile'); $decodedFile = base64_decode($data['content']); $upload_file->set_for_soap($data['filename'], $decodedFile); $ext_pos = strrpos($upload_file->stored_file_name, "."); $upload_file->file_ext = substr($upload_file->stored_file_name, $ext_pos + 1); $note = BeanFactory::getBean('Notes'); $note->id = create_guid(); $note->new_with_id = true; if (in_array($upload_file->file_ext, $this->config['upload_badext'])) { $upload_file->stored_file_name .= ".txt"; $upload_file->file_ext = "txt"; } $note->filename = $upload_file->get_stored_file_name(); if (isset($data['type'])) { $note->file_mime_type = $data['type']; } else { $note->file_mime_type = $upload_file->getMimeSoap($note->filename); } $note->team_id = $email->team_id; $note->team_set_id = $email->team_set_id; $note->assigned_user_id = $email->assigned_user_id; $note->parent_type = 'Emails'; $note->parent_id = $email->id; $note->name = $note->filename; $note->save(); $upload_file->final_move($note->id); }
/** * 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; } }
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}); } }
/** * @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'); }
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; } }
/** * Presaves one attachment for new email 2.0 spec * DOES NOT CREATE A NOTE * @return string ID of note associated with the attachment */ public function email2saveAttachment() { $email_uploads = "modules/Emails/{$GLOBALS['current_user']->id}"; $upload = new UploadFile('email_attachment'); if (!$upload->confirm_upload()) { $err = $upload->get_upload_error(); if ($err) { $GLOBALS['log']->error("Email Attachment could not be attached due to error: {$err}"); } return array(); } $guid = create_guid(); $fileName = $upload->create_stored_filename(); $GLOBALS['log']->debug("Email Attachment [{$fileName}]"); if ($upload->final_move($guid)) { copy("upload://{$guid}", sugar_cached("{$email_uploads}/{$guid}")); return array('guid' => $guid, 'name' => $GLOBALS['db']->quote($fileName), 'nameForDisplay' => $fileName); } else { $GLOBALS['log']->debug("Email Attachment [{$fileName}] could not be moved to upload dir"); return array(); } }
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/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; } }
public function save($bean, $params, $field, $vardef, $prefix = '') { $fakeDisplayParams = array(); $this->fillInOptions($vardef, $fakeDisplayParams); require_once 'include/upload_file.php'; $upload_file = new UploadFile($prefix . $field . '_file'); //remove file if (isset($_REQUEST['remove_file_' . $field]) && $params['remove_file_' . $field] == 1) { $upload_file->unlink_file($bean->{$field}); $bean->{$field} = ""; } $move = false; // In case of failure midway, we need to reset the values of the bean $originalvals = array('value' => $bean->{$field}); // Bug 57400 - Some beans with a filename field type do NOT have file_mime_type // or file_ext. In the case of Documents, for example, this happens to be // the case, since the DocumentRevisions bean is where these fields are found. if (isset($bean->file_mime_type)) { $originalvals['mime'] = $bean->file_mime_type; } if (isset($bean->file_ext)) { $originalvals['ext'] = $bean->file_ext; } if (isset($_FILES[$prefix . $field . '_file']) && $upload_file->confirm_upload()) { // in order to avoid any discrepancies of MIME type with the download code, // call the same MIME function instead of using the uploaded file's mime type property. $mimeType = get_file_mime_type($upload_file->get_temp_file_location(), 'application/octet-stream'); //verify the image if (in_array($mimeType, self::$imageFileMimeTypes) && !verify_image_file($upload_file->get_temp_file_location())) { $this->error = string_format($GLOBALS['app_strings']['LBL_UPLOAD_IMAGE_FILE_NOT_SUPPORTED'], array($upload_file->file_ext)); return; } $bean->{$field} = $upload_file->get_stored_file_name(); $bean->file_mime_type = $upload_file->mime_type; $bean->file_ext = $upload_file->file_ext; $move = true; } else { $this->error = $upload_file->getErrorMessage(); } if (!empty($params['isDuplicate']) && $params['isDuplicate'] == 'true') { // This way of detecting duplicates is used in Notes $old_id = $params['relate_id']; } if (!empty($params['duplicateSave']) && !empty($params['duplicateId'])) { // It's a duplicate $old_id = $params['duplicateId']; } // case when we should copy one file to another using merge-duplicate view // $params[$field . '_duplicateBeanId'] contains id of bean from // which we should copy file. if (!empty($params[$field . '_duplicateBeanId'])) { $duplicateModuleId = $params[$field . '_duplicateBeanId']; } // Backwards compatibility for fields that still use customCode to handle the file uploads if (!$move && empty($old_id) && isset($_FILES['uploadfile'])) { $upload_file = new UploadFile('uploadfile'); if ($upload_file->confirm_upload()) { $bean->{$field} = $upload_file->get_stored_file_name(); $bean->file_mime_type = $upload_file->mime_type; $bean->file_ext = $upload_file->file_ext; $move = true; } else { $this->error = $upload_file->getErrorMessage(); } } elseif (!$move && !empty($old_id) && isset($_REQUEST['uploadfile']) && !isset($_REQUEST[$prefix . $field . '_file'])) { // I think we are duplicating a backwards compatibility module. $upload_file = new UploadFile('uploadfile'); } if (empty($bean->id)) { $bean->id = create_guid(); $bean->new_with_id = true; } if ($move) { $temp = !empty($params['temp']); // Added checking of final move to capture errors that might occur if ($upload_file->final_move($bean->id, $temp)) { if (!$temp) { // This fixes an undefined index warning being thrown $docType = isset($vardef['docType']) && isset($params[$prefix . $vardef['docType']]) ? $params[$prefix . $vardef['docType']] : null; $upload_file->upload_doc($bean, $bean->id, $docType, $bean->{$field}, $upload_file->mime_type); } } else { // Reset the bean back to original, but only if we had set them. $bean->{$field} = $originalvals['value']; // See comments for these properties above in regards to Bug 57400 if (isset($originalvals['mime'])) { $bean->file_mime_type = $originalvals['mime']; } if (isset($originalvals['ext'])) { $bean->file_ext = $originalvals['ext']; } // Report the error $this->error = $upload_file->getErrorMessage(); } } elseif (!empty($old_id)) { // It's a duplicate, I think if (empty($vardef['docUrl']) || empty($params[$prefix . $vardef['docUrl']])) { $upload_file->duplicate_file($old_id, $bean->id, $bean->{$field}); } else { $docType = $vardef['docType']; $bean->{$docType} = $params[$prefix . $field . '_old_doctype']; } } elseif (!empty($params[$prefix . $field . '_remoteName'])) { // We aren't moving, we might need to do some remote linking $displayParams = array(); $this->fillInOptions($vardef, $displayParams); if (isset($params[$prefix . $vardef['docId']]) && !empty($params[$prefix . $vardef['docId']]) && isset($params[$prefix . $vardef['docType']]) && !empty($params[$prefix . $vardef['docType']])) { $bean->{$field} = $params[$prefix . $field . '_remoteName']; require_once 'include/utils/file_utils.php'; $extension = get_file_extension($bean->{$field}); if (!empty($extension)) { $bean->file_ext = $extension; $bean->file_mime_type = get_mime_content_type_from_filename($bean->{$field}); } } } elseif (!empty($duplicateModuleId)) { $upload_file->duplicate_file($duplicateModuleId, $bean->id, $bean->{$field}); $bean->{$field} = $params[$field]; require_once 'include/utils/file_utils.php'; $extension = get_file_extension($bean->{$field}); if (!empty($extension)) { $bean->file_ext = $extension; $bean->file_mime_type = get_mime_content_type_from_filename($bean->{$field}); } } if ($vardef['allowEapm'] == true && empty($bean->{$field})) { $GLOBALS['log']->info("The {$field} is empty, clearing out the lot"); // Looks like we are emptying this out $clearFields = array('docId', 'docType', 'docUrl', 'docDirectUrl'); foreach ($clearFields as $clearMe) { if (!isset($vardef[$clearMe])) { continue; } $clearField = $vardef[$clearMe]; $bean->{$clearField} = ''; } } }