/**
* Generates the CSV content of the metadata for resources passed in the array
*
* @param $resources
* @return string
*/
function generateResourcesMetadataCSV(array $resources)
{
    global $lang;
    $return = '';
    $csv_field_headers = array();
    $resources_fields_data = array();
    foreach ($resources as $resource) {
        foreach (get_resource_field_data($resource['ref'], false, true, -1, getval("k", "") != "") as $field_data) {
            if ($field_data['name'] == '') {
                die('Please check field ID ' . $field_data['ref'] . ' and make sure its "' . $lang['property-shorthand_name'] . '" is set!');
            }
            $csv_field_headers[$field_data['name']] = $field_data['title'];
            $resources_fields_data[$resource['ref']][$field_data['name']] = $field_data['value'];
        }
    }
    $csv_field_headers = array_unique($csv_field_headers);
    // Header
    $return = '"' . $lang['resourceids'] . '","' . implode('","', $csv_field_headers) . "\"\n";
    // Results
    $csv_row = '';
    foreach ($resources_fields_data as $resource_id => $resource_fields) {
        // First column will always be Resource ID
        $csv_row = $resource_id . ',';
        // Field values
        foreach ($csv_field_headers as $column_header => $column_header_title) {
            if (!array_key_exists($column_header, $resource_fields)) {
                $csv_row .= '"",';
                continue;
            }
            foreach ($resource_fields as $field_name => $field_value) {
                if ($column_header == $field_name) {
                    $csv_row .= '"' . tidylist(i18n_get_translated($field_value)) . '",';
                }
            }
        }
        $csv_row .= "\n";
        $return .= $csv_row;
    }
    return $return;
}
/**
* Generates the CSV content of the metadata for resources passed in the array
*
* @param $resources
* @return string
*/
function generateResourcesMetadataCSV(array $resources)
{
    global $lang;
    $return = '';
    $csv_field_headers = array();
    $resources_fields_data = array();
    foreach ($resources as $resource) {
        foreach (get_resource_field_data($resource['ref'], false, true, -1, getval("k", "") != "") as $field_data) {
            $csv_field_headers[$field_data['resource_type_field']] = $field_data['title'];
            $resources_fields_data[$resource['ref']][$field_data['resource_type_field']] = $field_data['value'];
        }
    }
    $csv_field_headers = array_unique($csv_field_headers);
    // Header
    $return = '"' . $lang['resourceids'] . '","' . implode('","', $csv_field_headers) . "\"\n";
    // Results
    $csv_row = '';
    foreach ($resources_fields_data as $resource_id => $resource_fields) {
        // First column will always be Resource ID
        $csv_row = $resource_id . ',';
        // Field values
        foreach ($csv_field_headers as $column_header => $column_header_title) {
            if (!array_key_exists($column_header, $resource_fields)) {
                $csv_row .= '"",';
                continue;
            }
            foreach ($resource_fields as $field_name => $field_value) {
                if ($column_header == $field_name) {
                    $csv_row .= '"' . str_replace(array("\\n", "\\r", "\""), "//", tidylist(i18n_get_translated($field_value))) . '",';
                }
            }
        }
        $csv_row .= "\n";
        $return .= $csv_row;
    }
    return $return;
}
$default_sort = "DESC";
if (substr($order_by, 0, 5) == "field") {
    $default_sort = "ASC";
}
$sort = getval("sort", $default_sort);
$metadata = get_resource_field_data($ref);
$filename = $ref;
$download = getval("download", "") != "";
if ($download) {
    header("Content-type: application/octet-stream");
    header("Content-disposition: attachment; filename=" . $lang["metadata"] . "_" . $filename . ".txt");
    foreach ($metadata as $metadata_entry) {
        echo $metadata_entry['title'];
        // This is the field title - the function got this by joining to the resource_type_field in the sql query
        echo ": ";
        echo tidylist($metadata_entry['value']);
        // This is the value for the field from the resource_data table
        echo "\n";
    }
    ob_flush();
    exit;
}
include "../include/header.php";
?>

<body>
<div class="BasicsBox">
<p><a href="<?php 
echo $baseurl_short;
?>
pages/view.php?ref=<?php 
예제 #4
0
</div></td>
</tr>

<?php 
for ($n = 0; $n < count($fields); $n++) {
    ?>
	<tr>
	<td><div class="ListTitle"><a href="team_fields_edit.php?field=<?php 
    echo $fields[$n]["ref"];
    ?>
"><?php 
    echo $fields[$n]["title"];
    ?>
</a></div></td>
	<td><?php 
    echo substr(tidylist(i18n_get_translated($fields[$n]["options"])), 0, 100) . "...";
    ?>
</td>
	<td><div class="ListTools"><a href="team_fields_edit.php?field=<?php 
    echo $fields[$n]["ref"];
    ?>
">&gt;&nbsp;<?php 
    echo $lang["action-edit"];
    ?>
 </a></div></td>
	</tr>
	<?php 
}
?>

</table>
    echo date('d/m/Y');
    ?>
</td>
				</tr>
			</table>
		</page_footer>
		<!-- Real content starts here -->
		<h2><?php 
    echo $lang['metadata-pdf-title'] . ' ' . $ref;
    ?>
</h2>
		<table style="width: 90%;" align="center" cellspacing="15">
			<tbody>
			<?php 
    foreach ($metadata as $metadata_entry) {
        $metadatavalue = trim(tidylist(i18n_get_translated($metadata_entry['value'])));
        if (!empty($metadatavalue)) {
            ?>
					<tr>
						<td valign="top" style="text-align: left;"><b><?php 
            echo $metadata_entry['title'];
            ?>
</b></td>
						<td style="width: 2%;"></td>
						<td style="width: 70%; text-align: left;"><?php 
            echo $metadatavalue;
            ?>
</td>
					</tr>
				<?php 
        }
if (substr($order_by, 0, 5) == "field") {
    $default_sort = "ASC";
}
$sort = getval("sort", $default_sort);
$metadata = get_resource_field_data($ref);
$filename = $ref;
$download = getval("download", "") != "";
if ($download) {
    header("Content-type: application/octet-stream");
    header("Content-disposition: attachment; filename=" . $lang["metadata"] . "_" . $filename . ".txt");
    foreach ($metadata as $metadata_entry) {
        if (!empty($metadata_entry['value'])) {
            // This is the field title - the function got this by joining to the resource_type_field in the sql query
            echo $metadata_entry['title'] . ': ';
            // This is the value for the field from the resource_data table
            echo tidylist(i18n_get_translated($metadata_entry['value'])) . "\n";
        }
    }
    ob_flush();
    exit;
}
include "../include/header.php";
?>

<body>
<div class="BasicsBox">
<p><a href="<?php 
echo $baseurl_short;
?>
pages/view.php?ref=<?php 
echo urlencode($ref);