18 require_once SQ_CORE_PACKAGE_PATH.
'/report/report_edit_fns.inc';
19 require_once SQ_FUDGE_PATH.
'/general/general.inc';
41 parent::__construct();
59 require_once SQ_FUDGE_PATH.
'/general/text.inc';
60 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
61 $owner = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($job->_running_vars[
'assetid'],
'report_incomplete_metadata');
63 $asset_types = $owner->getAllowedAssetTypeMap();
65 if (!isset($job->_running_vars[
'results'])) {
66 $job->_running_vars[
'todo'] = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($this->
getRootAssetid($owner));
67 $job->_running_vars[
'done'] = Array();
68 $job->_running_vars[
'results'] = Array();
70 if (!is_dir($owner->data_path)) {
71 if (!create_directory($owner->data_path)) {
72 trigger_localised_error(
'CORE0198', E_USER_WARNING);
76 $temp_file = fopen($owner->data_path.
'/report.tmp',
'w');
77 if ($temp_file === FALSE) {
78 trigger_localised_error(
'CORE0201', E_USER_WARNING);
83 fwrite($temp_file,
'<?xml version="1.0" encoding="'.SQ_CONF_DEFAULT_CHARACTER_SET.
'"?>'.
"\n");
84 fwrite($temp_file,
"<assets>\n");
86 $temp_file = fopen($owner->data_path.
'/report.tmp',
'a');
87 if ($temp_file === FALSE) {
88 trigger_localised_error(
'CORE0201', E_USER_WARNING);
93 if (!empty($job->_running_vars[
'todo'])) {
94 $keys = array_keys($job->_running_vars[
'todo']);
95 $assetid = array_shift($keys);
96 $asset_type = $job->_running_vars[
'todo'][$assetid][0][
'type_code'];
97 unset($job->_running_vars[
'todo'][$assetid]);
98 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid, $asset_type);
100 if (!is_null($asset)) {
103 if (empty($asset_types) || isset($asset_types[$asset->type()])) {
104 $step_data[
'message'] = translate(
'core_checking_for_metadata', $asset->name);
106 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
107 $field_values = $mm->getMetadataFieldValues($asset->id);
109 $empty_fields = FALSE;
110 $content =
"\t".
'<asset assetid="'.$asset->id.
'" name="'.htmlSpecialChars($asset->name).
'" short_name="'.htmlSpecialChars($asset->short_name).
'" type_code="'.$asset->type().
'" status="'.$asset->status.
'">'.
"\n";
111 foreach ($field_values as $field_name => $value) {
112 $value = trim($value);
114 $content .=
"\t\t".
'<field>'.$field_name.
'</field>'.
"\n";
115 $empty_fields = TRUE;
118 $content .=
"\t".
'</asset>'.
"\n";
121 if ($empty_fields) fwrite($temp_file, $content);
123 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
126 $step_data[
'message'] = translate(
'hipo_skipping_asset', $assetid);
129 $step_data[
'message'] = translate(
'hipo_skipping_asset', $assetid);
130 $job->
_addError(translate(
'core_cannot_generate_incomplete_metadata_report', $assetid));
134 $job->_running_vars[
'done'][] = $assetid;
138 if (empty($job->_running_vars[
'todo'])) {
139 $step_data[
'percent_done'] = 100;
140 $step_data[
'complete'] = TRUE;
141 $job->_running_vars[
'complete'] = TRUE;
144 fwrite($temp_file,
"</assets>\n");
145 if (!copy($owner->data_path.
'/report.tmp', $owner->data_path.
'/report.xml')) {
146 trigger_localised_error(
'CORE0200', E_USER_WARNING);
149 if (!unlink($owner->data_path.
'/report.tmp')) {
150 trigger_localised_error(
'CORE0199', E_USER_WARNING);
153 $total = count($job->_running_vars[
'todo']) + count($job->_running_vars[
'done']);
154 $step_data[
'percent_done'] = (count($job->_running_vars[
'done']) / $total) * 100;
155 $step_data[
'complete'] = FALSE;
175 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
177 $report_path = $asset->data_path.
'/report.xml';
178 if (!is_file($report_path)) {
179 echo translate(
'report_not_generated');
185 $root =
new SimpleXMLElement($report_path, LIBXML_NOCDATA, TRUE);
186 }
catch (Exception $e) {
187 throw new Exception(
'Unable to parse report file "'.$report_path.
'": '.$e->getMessage());
193 $missing_fields = Array();
194 foreach ($root->asset as $node) {
195 $assetid = (int) $node->attributes()->assetid;
196 foreach ($node->field as $field) {
197 $missing_fields[$assetid][] = (string) $field;
201 if (SQ_IN_BACKEND || SQ_IN_LIMBO) {
202 echo
'<b>Note</b> The current incomplete metadata report is shown below. You can regenerate this report on the details screen.';
206 $o->
openSection(translate(
'missing_metadata_fields'));
208 if (empty($missing_fields)) {
209 echo translate(
'core_no_missing_metadata_fields_found');
214 <table
class=
"sq-backend-table">
216 <td colspan=
"4" class=
"sq-backend-table-header" style=
"width: 226px;"><?php echo translate(
'found_in'); ?></td>
217 <td
class=
"sq-backend-table-header"><?php echo translate(
'empty_fields'); ?></td>
220 foreach ($missing_fields as $assetid => $fields) {
223 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid,
'', TRUE);
225 if (is_null($asset)) {
227 $asset_string =
'Unknown asset #'.$assetid;
228 $asset_bg =
'FFFFFF';
231 $asset_type = $asset->
type();
232 $asset_bg = get_asset_status_icon($asset->status);
233 $asset_status = get_status_description($asset->status);
235 $asset_string =
'<u title="'.$asset->name.
'">'.ellipsisize($asset->name, 40).
'</u>';
240 <td
class=
"sq-backend-table-cell" style=
"width: 10px; padding-right: 1px; text-align: right;">
242 if (!empty($asset_type)) {
244 <a href=
"<?php echo $asset_url; ?>" title=
"Edit this asset's metadata">#<?php echo (
int) $asset->id; ?></a>
250 <td
class=
"sq-backend-table-cell" style=
"width: 16px; padding-right: 2px; padding-left: 15px;">
252 if (!empty($asset_type)) {
253 echo get_asset_type_icon($asset_type);
257 <td
class=
"sq-backend-table-cell" style=
"padding-left: 2px;">
258 <?php echo $asset_string; ?>
260 <td
class=
"sq-backend-table-cell" style=
"padding-right: 1px;">
261 <?php echo $asset_bg; ?><?php echo $asset_status; ?>
263 <td
class=
"sq-backend-table-cell">
265 echo implode(
'<br />', $fields);
292 $types = $asset->
attr(
'types');
294 echo translate(
'core_no_types_defined');
299 <table
class=
"sq-backend-table">
301 <td
class=
"sq-backend-table-header"><?php echo translate(
'asset_type'); ?></td>
302 <td
class=
"sq-backend-table-header"><?php echo translate(
'inherit_types'); ?></td>
306 <td
class=
"sq-backend-table-header"><?php echo translate(
'remove_question'); ?></td>
312 foreach ($types as $type => $inherit) {
315 <td
class=
"sq-backend-table-cell">
317 echo ucwords(str_replace(
'_',
' ', $type));
320 <td
class=
"sq-backend-table-cell">
323 check_box($prefix.
"_inherit_types[$type]", $type, $inherit);
325 echo ($inherit) ? translate(
'yes') : translate(
'no');
332 <td
class=
"sq-backend-table-cell">
334 check_box($prefix.
"_remove[$type]", $type, FALSE);
362 $types = $asset->
attr(
'types');
365 if (isset($_POST[$prefix.
'_remove'])) {
367 foreach ($_POST[$prefix.
'_remove'] as $type) {
368 if (isset($types[$type])) unset($types[$type]);
372 $inherit_types = array_get_index($_POST, $prefix.
'_inherit_types', Array());
373 foreach ($types as $key => $val) {
374 $types[$key] = isset($inherit_types[$key]) ? TRUE : FALSE;
398 $types = $GLOBALS[
'SQ_SYSTEM']->am->getTypeList();
399 $types = array_diff($types, $asset->
attr(
'types'));
402 $uc_types = Array(
'' =>
'');
403 foreach ($types as $type) {
404 $uc_types[$type] = ucwords(str_replace(
'_',
' ', $type));
406 combo_box($prefix.
'_new_type', $uc_types, FALSE,
'');
423 if (isset($_POST[$prefix.
'_new_type'])) {
424 $type = trim($_POST[$prefix.
'_new_type']);
426 if (empty($type))
return FALSE;
428 $types = $asset->
attr(
'types');
430 if (!isset($types[$type])) {
431 $types[$type] = TRUE;