18 require_once SQ_SYSTEM_ROOT.
'/core/assets/system/tool/tool.inc';
19 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
20 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
21 require_once SQ_DATA_PATH.
'/private/conf/tools.inc';
48 $this->
Tool($assetid);
65 $import_mgr = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'import_tools_manager');
66 $locks = $GLOBALS[
'SQ_SYSTEM']->am->getLockInfo($import_mgr->id,
'attributes', TRUE, TRUE);
67 $userid = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
71 foreach ($locks as $lock) {
72 if(empty($lock))
continue;
73 if($lock[
'lock_type'] ==
'attributes' && $lock[
'userid'] == $userid) {
76 else if ($lock[
'lock_type'] ==
'attributes' ) {
78 $userHasLockId = $lock[
'userid'];
84 echo (translate(
'tool_export_assets_to_xml_can_not_acquire_lock', $userHasLockId));
90 $show_download = FALSE;
91 if(isset($_REQUEST[
'show_download'])) {
92 $show_download = TRUE;
94 else if (isset($_REQUEST[
'download'])) {
95 $export_dir = SQ_DATA_PATH.
'/private/export_assets';
96 if (!create_directory($export_dir))
return FALSE;
98 $command =
"cd $export_dir ; tar -czf export.tgz * --remove-files";
99 exec($command, $output, $return);
104 trigger_localised_error(
'EXP0001', E_USER_ERROR, $return);
110 $filesize = filesize($export_dir.
'/export.tgz');
112 trigger_localised_error(
'EXP0002', E_USER_ERROR);
117 require_once SQ_FUDGE_PATH.
'/standards_lists/mime_types.inc';
119 $type = (empty($standards_lists_mime_types[$ext])) ?
'text/plain' : $standards_lists_mime_types[$ext];
122 header(
"Pragma: public");
123 header(
"Expires: 0");
124 header(
"Cache-Control: must-revalidate, post-check=0, pre-check=0");
125 header(
"Cache-Control: private",
false);
128 header(
'Content-Type: '.$type);
131 header(
'Content-Disposition: attachment; filename="export.tgz";');
132 header(
'Content-Length: '.$filesize);
135 self::_readfile_chunked($export_dir.
'/export.tgz');
138 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($import_mgr->id,
'attributes');
145 $tool_info = $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($type_code);
146 $o->openSection($tool_info[
'name']);
148 $o->openField(translate(
'tool_export_assets_to_xml_root_node'));
150 asset_finder($type_code.
'_root_node[0]', 0, Array(
'asset' =>
'D'),
'sq_sidenav', FALSE,
'null', Array(
'clear'));
151 echo
'<span id ="tool_export_assets_to_xml_mapping" style="margin-left:10px;">';
152 echo translate(
'tool_export_assets_to_xml_target_parent');
153 text_box($type_code.
'_target_parent[0]',
'1',
'1',
'',
'',
'style="margin-left:10px;"');
155 $map_frame_exp = trim(
'parent.frames["sq_sidenav"]',
'.');
156 $name =$type_code.
'_root_node';
157 $safe_name =
'sq_asset_finder_'.preg_replace(
'/[^A-Za-z0-9]/',
'_', $name);
159 <script
type=
"text/javascript">
161 var target_parent_index = 1;
162 function addParentNode(node) {
163 var new_span = document.getElementById(
'tool_export_assets_to_xml_mapping').cloneNode(
true);
164 new_span.lastChild.setAttribute(
'id',
'<?php echo $type_code; ?>' +
'_target_parent[' + target_parent_index +
']');
165 new_span.lastChild.setAttribute(
'name',
'<?php echo $type_code; ?>' +
'_target_parent[' + target_parent_index +
']');
166 node.parentNode.insertBefore(new_span, node);
167 target_parent_index = target_parent_index + 1;
171 echo
'<input type="button" name="'.htmlspecialchars($safe_name.
'_more_btn').
'" id="'.htmlspecialchars($safe_name.
'_more_btn').
'" value="'.translate(
'more').
'..." onclick="addNewAssetFinder(this, \''.$name.
'\', \
''.$safe_name.
'\', \
'\', \
''.htmlentities($map_frame_exp, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET).
'\', \
'null\', true); addParentNode(this);" style="margin-left:10px;"/>';
172 $o->note(translate(
'tool_export_assets_to_xml_root_node_note'));
176 $o->openField(translate(
'download'));
177 $backend_url = $GLOBALS[
'SQ_SYSTEM']->backend->getBackendUrl();
178 $download_url = $backend_url.
'&backend_section=tools&tool_type_code='.$type_code.
'&download=1';
179 echo
'<a href="'.$download_url.
'" >'.translate(
'download').
'</a>';
202 $import_mgr = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'import_tools_manager');
203 if(!$GLOBALS[
'SQ_SYSTEM']->am->acquireLock($import_mgr->id,
'attributes')) {
204 trigger_localised_error(
'EXP0003', E_USER_ERROR);
209 $export_dir = SQ_DATA_PATH.
'/private/export_assets';
210 if (!create_directory($export_dir))
return FALSE;
213 $command =
"rm -rf $export_dir/*";
215 $root_node_mapping = Array();
216 foreach ($_POST[$type_code.
'_root_node'] as $index => $node) {
217 $node_id = $node[
'assetid'];
218 $target_parentid = $_POST[$type_code.
'_target_parent'][$index];
219 if(empty($node_id) || empty($target_parentid))
continue;
220 $root_node_mapping[] = $node_id.
':'.$target_parentid;
224 if (empty($root_node_mapping)) {
225 trigger_error (
'There is no root node mapping specified');
229 $vars[
'export_path'] = $export_dir;
230 $vars[
'root_node_mapping'] = $root_node_mapping;
234 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
235 $hh->queueHipo(
'hipo_job_export_assets_to_xml', $vars,
'', SQ_PACKAGES_PATH.
'/import_tools/hipo_jobs');
236 $backend_url = $GLOBALS[
'SQ_SYSTEM']->backend->getBackendUrl();
238 $url = $hh->runQueuedJobs($backend_url.
'&backend_section=tools&tool_type_code='.$type_code.
'&show_download=1');
240 if (!empty($url)) $o->setRedirect($url);
258 private static function _readfile_chunked($filename, $retbytes = TRUE, $chunksize = 1048576) {
262 $handle = fopen($filename,
'rb');
263 if ($handle ===
false) {
266 while (!feof($handle)) {
267 $buffer = fread($handle, $chunksize);
272 $cnt += strlen($buffer);
275 $status = fclose($handle);
276 if ($retbytes && $status) {