Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
import_tool_converter_edit_fns.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset_edit/asset_edit_fns.inc';
19 require_once SQ_FUDGE_PATH.'/general/file_system.inc';
20 
33 {
34 
35 
41  {
42  $this->Asset_Edit_Fns();
43 
44  }//end constructor
45 
46 
57  function paintUpload(&$asset, &$o, $prefix)
58  {
59  if (!$asset->writeAccess('attributes')) return FALSE;
60  $o->openField('Existing Asset');
61  asset_finder($prefix.'_existing_asset', 0, Array('file' => 'D'));
62  echo '&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight: bold">OR</span>';
63  $o->closeField();
64  $o->openField(translate('import_tool_new_doc_select'));
65  file_upload($prefix.'_file_import_upload', $extras='');
66  echo '&nbsp;&nbsp;&nbsp;&nbsp;';
67  check_box($prefix.'_file_import_upload_overwrite');
68  label(translate('import_tools_overwrite_existing'), $prefix.'_file_import_upload_overwrite');
69  $o->closeField();
70 
71  return TRUE;
72 
73  }//end paintUpload()
74 
75 
86  function processUpload(&$asset, &$o, $prefix)
87  {
88  if (!$asset->writeAccess('attributes')) return FALSE;
89  $am =& $GLOBALS['SQ_SYSTEM']->am;
90  // Handle some file uploads
91  $import_dir = $asset->attr('upload_directory');
92  $compatible_types = $asset->attr('valid_file_types');
93 
94  // Check if we have an existing asset selected and copy it over
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']));
100  }
101  return TRUE;
102  }
103 
104  $new_file_upload = get_file_upload_info($prefix.'_file_import_upload');
105 
106  if ($new_file_upload === FALSE) {
107  trigger_error('Error Uploading Word Document', E_USER_WARNING);
108  } else {
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);
114  }
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);
117 
118  // create a word document under the manager
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);
122 
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);
128 
129  if (!$new_file->create($import_link, $temp_info)) {
130  trigger_error('Failed to import '.$asset_type.' '.$filename, E_USER_WARNING);
131  }
132  // Change the file name, so we can use it in windows
133  rename($import_dir.'/'.$new_file_upload['name'], $import_dir.'/'.str_replace(' ', '_', $new_file_upload['name']));
134  }
135  }
136 
137  }//end processUpload()
138 
139 
140 }//end class
141 ?>