<? header('Content-Type: text/xml; charset=utf-8');
$date = date("c"); ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
  <loc>http://www.cutalongstory.com/</loc>
  <lastmod><? echo $date ?></lastmod>
  <changefreq>daily</changefreq>
</url>
<? require_once("config.php");
$connection = @mysql_connect(U_MYSQL_HOST,U_MYSQL_USER,U_MYSQL_PASSWORD);
$db = @mysql_select_db(U_MYSQL_DB, $connection) or die("Couldn't select database.");

$sql="select * from cals_sitepages where sp_url != '' and sp_url is not null order by sp_updated desc";
$dbResults= @mysql_query($sql, $connection) or die("Error #". mysql_errno() . ": " . mysql_error());

while ( $row = mysql_fetch_array( $dbResults ) ) {		
	
		foreach($row as $key=>$value) { 
					$$key = $value; 			
					}
?>
<url>
  <loc>http://www.cutalongstory.com/<?echo $sp_url?>.html</loc>
  <lastmod><? echo $date ?></lastmod>
  <changefreq>daily</changefreq>
</url>
<? } 

$sql="select * from cals_categories where cat_archive != '1'";
$dbResults= @mysql_query($sql, $connection) or die("Error #". mysql_errno() . ": " . mysql_error());

while ( $row = mysql_fetch_array( $dbResults ) ) {		
	
		foreach($row as $key=>$value) { 
					$$key = $value; 			
					}
	$caturl = str_replace("&","and",str_replace(" ","-",strtolower($cat_name)));						
?>
<url>
  <loc>http://www.cutalongstory.com/categories/<? echo $caturl?>/<? echo $cat_id ?>.html</loc>
  <lastmod><? echo $date ?></lastmod>
  <changefreq>daily</changefreq>
</url>
<? } 
 
$sql="select * from cals_genres where genre_archive != '1'";
$dbResults= @mysql_query($sql, $connection) or die("Error #". mysql_errno() . ": " . mysql_error());

while ( $row = mysql_fetch_array( $dbResults ) ) {		
	
		foreach($row as $key=>$value) { 
					$$key = $value; 			
					}
	$genurl = str_replace("&","and",str_replace(" ","-",strtolower($genre_name)));					
?>
<url>
  <loc>http://www.cutalongstory.com/categories/<? echo $genurl?>/<? echo $genre_id ?>.html</loc>
  <lastmod><? echo $date ?></lastmod>
  <changefreq>daily</changefreq>
</url>
<? } 

$sql = "SELECT cs.*, c.cust_firstname, c.cust_lastname, a.auth_publishname, a.auth_id,  
(select p.price_price from cals_prices p where p.price_storyid = cs.story_id order by p.price_date desc limit 1) as price_price 

from cals_stories cs 
inner join cals_customer c on c.cust_id = cs.story_authid
inner join cals_authors a on a.auth_id = c.cust_id
";
$dbResults= @mysql_query($sql, $connection) or die("Error #". mysql_errno() . ": " . mysql_error());	

while ( $row = mysql_fetch_assoc( $dbResults ) ) {
foreach($row as $key=>$value) { 
								$$key = $value; 
								}
$sttitlelink = strtolower(str_replace("'","",str_replace("&","",str_replace(" ","-",$story_title)))).'/'.$story_id;
if ($auth_publishname == "") {
	$stauthorlink = strtolower(str_replace("'","",str_replace(" ","-",$cust_firstname.' '.$cust_lastname))).'/'.$auth_id;
	$stauthor = $cust_firstname.' '.$cust_lastname;
	} else {
	$stauthorlink = strtolower(str_replace("'","",str_replace(" ","-",$auth_publishname))).'/'.$auth_id;
	$stauthor = $auth_publishname;
	}
?>
<url>
  <loc>http://www.cutalongstory.com/stories/<? echo $sttitlelink ?>.html</loc>
  <lastmod><? echo $date ?></lastmod>
  <changefreq>daily</changefreq>
</url>
<url>
  <loc>http://www.cutalongstory.com/authors/<? echo $stauthorlink ?>.html</loc>
  <lastmod><? echo $date ?></lastmod>
  <changefreq>daily</changefreq>
</url>
<?
}								
								
?>

</urlset>