<?php
if (!class_exists('Database')) require_once("common_cadline_libraries/crm_database.class.php");

$published = isset($_GET['published']) ? $_GET['published'] : false;

$published = $published == 'true' ? 1 : 0;

$query = "SELECT * FROM `cl_hlusers`.`zendesk_api`
    WHERE published = ?
    ORDER BY SUBSTRING_INDEX(fileName, '.json', 1)";
Database::getInstance()->query($query, array('i', $published));
$res = Database::getInstance()->fetchAssoc();

$xml        = new SimpleXMLElement('<ClassDatas/>');
$classes    = $xml->addChild('classes');
$classes->addChild('Count', count($res));

foreach ($res as $value) {
    $item = $classes->addChild('Item');
    $item->addChild('Name', $value['fileName']);
    $item->addChild('Crc', $value['crc']);
    $item->addChild('Url', $value['url']);
    $item->addChild('Published', $value['published']);
}

Header('Content-type: text/xml');
print $xml->asXML();
