<?php

class site_sitemap extends module {
	
	var $obj;
    var $templ = 'site_sitemap.htm';


	function _on_() {
        Header('Content-Type: text/xml');
		global $R, $core_db;
        $tpl = $R->getTpl( $this->templ, 'body' );
        $tplr = $R->getTpl( $this->templ, 'row' );

        $tt = $tplr;
        $tt = $R->set('url', _SITE_ROOT_, $tt );
        $tt = $R->set('freq', 'daily', $tt );
        $tt = $R->set('prio', '1', $tt );
        $tt = $R->set('lastmod', (date('Y-m-d').'T01:00:00+00:00'), $tt );

        $tpl = $R->parse('rows', $tt, $tpl );

        $db3 = $core_db->q('SELECT `cat_id` FROM `_sys_cat` WHERE !`_sys_unvisible` AND !`_sys_deleted` AND `parent_cat` != "" ');
        while ($db3->nr() ) {
            $url = $db3->f('cat_id');
            $tt = $R->set('url', _SITE_ROOT_.$url, $tplr );
            $tt = $R->set('prio', '0.9', $tt );
            $tt = $R->set('lastmod', (date('Y-m-d').'T00:00:00+00:00'), $tt );
            $tpl = $R->parse('rows', $tt, $tpl );
        }

        
        $db2 = $core_db->q('SELECT `obj_name`, `attr_templ` FROM `_sys_datatypes` WHERE `attr_type` = "full_url" ');
        while ( $db2->nr() ) {
            $obj_name = $db2->f('obj_name');
            list( $url_prefix, $url_cat ) = explode('|', $db2->f('attr_templ'));
            $db3 = $core_db->q('SELECT `url`,`_sys_lastchange` FROM `' . $obj_name . '` WHERE !`_sys_unvisible` AND !`_sys_deleted`');
            while ($db3->nr() ) {
                $url = $db3->f('url');
                $tt = $R->set('url', _SITE_ROOT_.$url, $tplr );
                $tt = $R->set('prio', '0.8', $tt );
                $tt = $R->set('lastmod', (date('Y-m-d',$db3->f('_sys_lastchange')).'T01:00:00+00:00'), $tt );
                $tpl = $R->parse('rows', $tt, $tpl );
            }
        }
        
  		return $R->clear( $tpl );
	}
    

}	

?>