<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Sitemap extends Controller {
    public function process() {
        $AuthUser   = $this->getVariable("AuthUser");
        $Route      = $this->getVariable("Route");
        
        $Games          = $this->db->from(null,'SELECT count(posts.id) as total FROM `posts` WHERE posts.status = 1')->total(); 
        $Categories          = $this->db->from(null,'SELECT count(categories.id) as total FROM `categories`')->total(); 
       
        header("Content-Type: application/xml; charset=utf-8");
        echo '<sitemapindex xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd">';

        // Games
        for ($igame=1; $igame <=ceil($Games/SITEMAP_PAGE); $igame++) { 
            echo '<sitemap>';
                echo '<loc>'.APP.'/sitemap.game_'.$igame.'.xml</loc>';
                echo '<lastmod>'.date("Y-m-d")."T".date("H:i:s").'+03:00</lastmod>';
            echo '</sitemap>';
        }

        // Categories
        for ($icategory=1; $icategory <=ceil($Categories/SITEMAP_PAGE); $icategory++) { 
            echo '<sitemap>';
                echo '<loc>'.APP.'/sitemap.category_'.$icategory.'.xml</loc>';
                echo '<lastmod>'.date("Y-m-d")."T".date("H:i:s").'+03:00</lastmod>';
            echo '</sitemap>';
        }



        echo '</sitemapindex>'; 
    }

}