<?php

if (!defined('XOOPS_ROOT_PATH')) exit();

require_once XOONIPS_CONTROL_PATH.'control_base.php';
require_once XOONIPS_CLASS_PATH.'util.php';
require_once XOONIPS_MAIN_PATH.'/class/XmlIndexExport.class.php';

class indexget extends control_base {

  public function init() {
  }
  
  private function mk_index_xml($code, &$append_dom) {
    res_code($code, null, true);
    return $append_dom->saveXML();
  }

  public function run($req) {
    $indexpath = $req->get('path');
    if (is_null($indexpath)) {
      $this->rest_notify_err(400, 'Parameter path not found.');
    }

    $export = new XmlIndexExport();
    $dom = $export->getDom($indexpath, $this->uid ,$this->user);
    if (is_null($dom)) {
      $this->rest_notify_err(404, 'Index get fail.');
    }
    
    $xml = $this->mk_index_xml(200 , $dom);
    echo $xml;
  }
}
