<?php
session_start();

include("../include/config.php");

include("../include/functions.php");
define('SITE_URL_domain',"https://www.quicklly.com/");

validate_admin();
if($_POST['submit']=='Update Sitemap' && isset($_POST['submit'])){
//url validation
if(SITE_URL==MAINSITE_URL){
$datavalue=$_POST['datavalue'];
//file handling
	// The path to the FTP file, including login arguments
$ftp_path = 'ftp://mainuser@quicklly.com:n3At8hv3LZKCiF6@quicklly.com/sitemap_prod.xml';
if(!$ftp_path){
echo "Sitemap file doesn't exist!";
exit();
}
// Allows overwriting of existing files on the remote FTP server
$stream_options = array('ftp' => array('overwrite' => true));

// Creates a stream context resource with the defined options
$stream_context = stream_context_create($stream_options);

// Opens the file for writing and truncates it to zero length
if ($fh = fopen($ftp_path, 'w', 0, $stream_context))
{
    // Writes contents to the file
    fputs($fh, $datavalue);
   
    // Closes the file handle
    fclose($fh);
	$_SESSION['sess_msg']="Sitemap Updated Successfuly!";
}
else
{
    die('Could not open file.');
}
//file handling end
}else{
die('Could not open file. URL validation failed');
}//url validation end
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

    <head>

        <title><?php echo SITE_TITLE; ?></title>

        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

        <link href="css/admin.css" rel="stylesheet" type="text/css" />

        <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
       </head>
<body>
<?php include("menu.php"); ?>
<br />
<br />
<div align="center" style="color:#00CC00"><?php echo $_SESSION['sess_msg']; $_SESSION['sess_msg']=''; ?></div>
<form action="" enctype="multipart/form-data" method="post">
<textarea name="datavalue" rows="30" style="width:98%; height:80%; margin:15px">
<?php echo htmlentities("<?xml version='1.0' encoding='UTF-8'?>"); ?>
<?php echo htmlentities("<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'>"); ?>
<?php 
$sql=$obj->query("select tbl_product.id,product_name,tbl_product.storeid from tbl_product join stores on tbl_product.storeid=stores.storeid where tbl_product.status=1 and stores.status=1 and stores.sectionid like '%1%' and stores.sectionid<10");
while($rec=$obj->fetchNextObject($sql)){
    
    $sqlcategory=$obj->query("select id from tbl_maincategory where storeid like '%$rec->storeid%' and status=1");
if($obj->numRows($sqlcategory)>0){

 echo htmlentities("<url>"); 
 echo htmlentities("<loc>"); echo SITE_URL_domain."grocery-store/".strtolower(preg_replace('/-+/', '-',buildURL(str_replace('&','-',$rec->product_name))))."/".$rec->id; echo htmlentities("</loc>");
 echo htmlentities("<changefreq>"); echo "daily";?><?php echo htmlentities("</changefreq>"); 
 echo htmlentities("<priority>"); ?>0.80<?php echo htmlentities("</priority>"); 
echo htmlentities("</url>");
} }?>
<?php echo htmlentities("</urlset>"); ?>
</textarea>
<input type="submit" name="submit" value="Update Sitemap"  style="padding: 10px; font-weight: bold; margin-left: 45%;">
</form>
<br>
<?php include('footer.php'); ?>
    </body>
</html>