18 require_once SQ_INCLUDE_PATH.
'/asset_edit/asset_edit_fns.inc';
19 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
59 if (!$asset->writeAccess(
'attributes'))
return FALSE;
60 $o->openField(
'Existing Asset');
61 asset_finder($prefix.
'_existing_asset', 0, Array(
'file' =>
'D'));
62 echo
' <span style="font-weight: bold">OR</span>';
64 $o->openField(translate(
'import_tool_new_doc_select'));
65 file_upload($prefix.
'_file_import_upload', $extras=
'');
66 echo
' ';
67 check_box($prefix.
'_file_import_upload_overwrite');
68 label(translate(
'import_tools_overwrite_existing'), $prefix.
'_file_import_upload_overwrite');
88 if (!$asset->writeAccess(
'attributes'))
return FALSE;
89 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
91 $import_dir = $asset->attr(
'upload_directory');
92 $compatible_types = $asset->attr(
'valid_file_types');
95 if (isset($_POST[$prefix.
'_existing_asset']) && ($_POST[$prefix.
'_existing_asset'][
'assetid'] !=
'0')) {
96 $existing_asset = $am->getAsset($_POST[$prefix.
'_existing_asset'][
'assetid']);
97 $file_data = $existing_asset->getExistingFile();
98 if (!empty($file_data)) {
99 copy($file_data[
'path'], $import_dir.
'/'.str_replace(
' ',
'_', $file_data[
'filename']));
104 $new_file_upload = get_file_upload_info($prefix.
'_file_import_upload');
106 if ($new_file_upload === FALSE) {
107 trigger_error(
'Error Uploading Word Document', E_USER_WARNING);
109 if (!empty($new_file_upload)) {
110 $itm = $am->getSystemAsset(
'import_tools_manager');
111 $max_size = $itm->attr(
'max_file_size');
112 if (!is_dir($import_dir)) {
113 create_directory($import_dir);
115 $overwrite = isset($_POST[$prefix.
'_file_import_upload_overwrite']);
116 commit_file_upload($prefix.
'_file_import_upload', $import_dir, $overwrite, $max_size, TRUE, $compatible_types);
119 $filename = $new_file_upload[
'name'];
120 $import_link = Array(
'asset' => $asset,
'link_type' => SQ_LINK_TYPE_2);
121 $temp_info = Array(
'name' => $filename,
'tmp_name' => $import_dir.
'/'.$filename,
'non_uploaded_file' => TRUE);
123 $asset_type = $asset->attr(
'create_asset_type');
124 $am->includeAsset($asset_type);
125 $new_file =
new $asset_type;
126 $new_file->_tmp[
'uploading_file'] = TRUE;
127 $new_file->setAttrValue(
'name', $filename);
129 if (!$new_file->create($import_link, $temp_info)) {
130 trigger_error(
'Failed to import '.$asset_type.
' '.$filename, E_USER_WARNING);
133 rename($import_dir.
'/'.$new_file_upload[
'name'], $import_dir.
'/'.str_replace(
' ',
'_', $new_file_upload[
'name']));