<?php
/**
* Export resources metadata
* 
* This is used to accumulate metadata representation of efront resources, which can be used, for example, in an indexer engine
* Usage:
* xml_indexer.php&type=<type>
* where type can be 'content', 'file', etc
* 
* @package eFront
* @version 3.5.0
*/

$path = "../libraries/";

/** Configuration file.*/
include_once $path."configuration.php";

debug();

$xmlString = '';
switch ($_GET['type']) {
    case 'content':
    case 'unit:':
        $result = eF_getTableDataFlat("content", "id, metadata");
        $result = array_combine($result['id'], $result['metadata']);

        foreach ($result as $value) {
            if ($value && unserialize($value)) {
                $metadata   = unserialize($value);
                $dc         = new DublinCoreMetadata($metadata);
                $xmlString .= '<efront_resource>'.($dc -> toXML()).'</efront_resource>';
            }
        }
        $xmlString = '<efront_resources>'.$xmlString.'</efront_resources>';
        break;
    case 'file':
    case 'files':
        $result = eF_getTableDataFlat("files", "id, metadata");
        $result = array_combine($result['id'], $result['metadata']);

        foreach ($result as $value) {
            if ($value && unserialize($value)) {
                $metadata   = unserialize($value);
                $dc         = new DublinCoreMetadata($metadata);
                $xmlString .= '<efront_resource>'.($dc -> toXML()).'</efront_resource>';
            }
        }
        $xmlString = '<efront_resources>'.$xmlString.'</efront_resources>';
        break;
    default: break;
}

pr($xmlString);
?>