18 require_once SQ_CORE_PACKAGE_PATH.
'/report/report_edit_fns.inc';
19 require_once SQ_FUDGE_PATH.
'/general/general.inc';
20 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
37 public $report_name =
'report.xml';
38 public $temp_report =
'report.tmp';
47 parent::__construct();
66 $am = $GLOBALS[
'SQ_SYSTEM']->am;
67 $owner = $am->getAsset($job->_running_vars[
'assetid'],
'report_asset_counter');
68 $job_vars =& $job->_running_vars;
70 $report_contents =
'';
71 $report_dir = $owner->data_path;
73 $xml_file_name = $report_dir.
'/'.$this->report_name;
74 $types = $owner->attr(
'types');
76 if (empty($job_vars[
'unique_types'])) {
79 $step_data[
'message'] = translate(
'core_obtaining_asset_list');
83 foreach ($types as $type => $inherit_bool) {
84 $children_one = $am->getChildren($this->
getRootAssetid($owner), $type, !$inherit_bool, NULL, NULL, NULL, TRUE, NULL, NULL, TRUE, NULL, Array(), TRUE);
85 $children = array_merge($children, $children_one);
89 $children = $am->getChildren($this->
getRootAssetid($owner),
'', TRUE, NULL, NULL, NULL, TRUE, NULL, NULL, TRUE, NULL, Array(), TRUE);
93 foreach($children as $child_id => $child_info) {
94 $id_parts = explode(
':', $child_id);
96 if (isset($id_parts[1]) && empty($child_info[0][
'type_code'])) {
97 $shdw_asset_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($child_id, Array(), TRUE,
'type_code');
98 if (!empty($shdw_asset_info[$child_id])) {
99 $children[$child_id][0][
'type_code'] = $shdw_asset_info[$child_id];
101 $children[$child_id][0][
'type_code'] =
'unknown_asset_type';
107 if (empty($children)) {
108 $step_data[
'percent_done'] = 100;
109 $step_data[
'complete'] = TRUE;
110 $job->
_addError(translate(
'report_not_generated'),TRUE);
115 foreach ($children as $i => $info) {
116 if (!isset($job_vars[
'type_counts'][$info[0][
'type_code']])) {
117 $job_vars[
'type_counts'][$info[0][
'type_code']] = 1;
119 $job_vars[
'type_counts'][$info[0][
'type_code']]++;
122 $job_vars[
'unique_types'] = array_keys($job_vars[
'type_counts']);
124 if (!is_dir($report_dir)) {
125 if (!create_directory($report_dir)) {
126 trigger_localised_error(
'CORE0011', E_USER_WARNING);
131 $step_data[
'percent_done'] = 50;
132 $step_data[
'complete'] = FALSE;
138 $step_data[
'message'] = translate(
'core_get_readable_asset_descriptions');
140 $report_contents .=
'<?xml version="1.0" encoding="'.SQ_CONF_DEFAULT_CHARACTER_SET.
'"?>'.
"\n";
142 $report_contents .=
'<asset_types>';
144 foreach ($job_vars[
'unique_types'] as $asset_id => $type_code) {
145 $name = $am->getTypeInfo($type_code,
'name');
146 $count = $job_vars[
'type_counts'][$type_code];
148 $report_contents .=
'<asset_type code="'.$type_code.
'">';
149 $report_contents .=
'<name>'.$name.
'</name>';
150 $report_contents .=
'<count>'.$count.
'</count>';
151 $report_contents .=
'</asset_type>';
154 $report_contents .=
'</asset_types>';
157 $file_handler = fopen($xml_file_name,
'w');
158 if ($file_handler === FALSE) {
159 trigger_localised_error(
'CORE0017', E_USER_WARNING);
162 fwrite($file_handler, $report_contents);
163 fclose($file_handler);
165 $step_data[
'percent_done'] = 100;
166 $step_data[
'complete'] = TRUE;
187 $am = $GLOBALS[
'SQ_SYSTEM']->am;
188 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
190 $report_path = $asset->data_path.
'/'.$this->report_name;
191 if (!is_file($report_path)) {
192 echo translate(
'report_not_generated');
199 $root =
new SimpleXMLElement($report_path, LIBXML_NOCDATA, TRUE);
200 }
catch (Exception $e) {
201 throw new Exception(
'Unable to parse report file "'.$report_path.
'": '.$e->getMessage());
207 $asset_types = Array();
208 foreach ($root->asset_type as $node) {
209 $type = (string)$node->attributes()->code;
210 $asset_types[$type] = Array(
211 'name' => (
string)$node->name,
212 'count' => (
int)$node->count,
216 if (SQ_IN_BACKEND || SQ_IN_LIMBO) {
217 echo
'<b>Note</b> The current asset counter report is shown below. You can regenerate this report on the details screen.';
224 if (empty($asset_types)) {
225 echo
'Report is empty';
230 $sort_by = $sort_by_attr->value;
235 <td class="sq-backend-table-cell">
236 <script language="JavaScript" type="text/javascript">sq_print_icon("%s", "16", "16", "");</script>
238 <td class="sq-backend-table-cell" style="width: 10px;">
241 <td class="sq-backend-table-cell">
244 <td class="sq-backend-table-cell">
252 foreach ($asset_types as $typecode => $data) {
253 $counts[$typecode] = $data[
'count'];
254 $names[$typecode] = $data[
'name'];
255 $types[$typecode] = $typecode;
257 $rows[$typecode] = sprintf($row_format,$am->getAssetIconURL($typecode),$data[
'count'],$typecode,$data[
'name']);
264 $target_array = $counts;
268 $target_array = $names;
274 $target_array = $types;
278 if ($asset->
attr(
'reverse_sort')) {
279 arsort($target_array);
281 asort($target_array);
284 $sort_by_name = $sort_by_attr->_params[
'options'][$sort_by];
288 <h3>Sorted by: <span style="color: red">'.$sort_by_name.
'</span></h3>
289 <table class="sq-backend-table">
291 <td class="sq-backend-table-header" style="width: 10ex">Icon</td>
292 <td class="sq-backend-table-header" style="width: 10ex">Count</td>
293 <td class="sq-backend-table-header">Code</td>
294 <td class="sq-backend-table-header" width="70%%">Type</td>
300 foreach ($target_array as $typecode => $data) {
301 $rows_string .= $rows[$typecode];
303 $table = sprintf($table_format,$rows_string);
324 $types = $asset->
attr(
'types');
326 echo translate(
'core_no_types_defined');
331 <table
class=
"sq-backend-table">
333 <td
class=
"sq-backend-table-header"><?php echo translate(
'asset_type'); ?></td>
334 <td
class=
"sq-backend-table-header"><?php echo translate(
'inherit_types'); ?></td>
338 <td
class=
"sq-backend-table-header"><?php echo translate(
'remove_question'); ?></td>
344 foreach ($types as $type => $inherit) {
347 <td
class=
"sq-backend-table-cell">
349 echo ucwords(str_replace(
'_',
' ', $type));
352 <td
class=
"sq-backend-table-cell">
355 check_box($prefix.
"_inherit_types[$type]", $type, $inherit);
357 echo ($inherit) ? translate(
'yes') : translate(
'no');
364 <td
class=
"sq-backend-table-cell">
366 check_box($prefix.
"_remove[$type]", $type, FALSE);
396 $types = $asset->
attr(
'types');
399 if (isset($_POST[$prefix.
'_remove'])) {
401 foreach ($_POST[$prefix.
'_remove'] as $type) {
402 if (isset($types[$type])) unset($types[$type]);
406 $inherit_types = array_get_index($_POST, $prefix.
'_inherit_types', Array());
407 foreach ($types as $key => $val) {
408 $types[$key] = isset($inherit_types[$key]) ? TRUE : FALSE;
432 $types = $GLOBALS[
'SQ_SYSTEM']->am->getTypeList();
433 $types = array_diff($types, $asset->
attr(
'types'));
436 $uc_types = Array(
'' =>
'');
437 foreach ($types as $type) {
438 $uc_types[$type] = ucwords(str_replace(
'_',
' ', $type));
440 combo_box($prefix.
'_new_type', $uc_types, FALSE,
'');
459 if (isset($_POST[$prefix.
'_new_type'])) {
460 $type = trim($_POST[$prefix.
'_new_type']);
462 if (empty($type))
return FALSE;
464 $types = $asset->
attr(
'types');
466 if (!isset($types[$type])) {
467 $types[$type] = TRUE;