<?php
include 'common.php';
 header('Content-type: text/xml'); ?>
<?php
$newsdbname = $_ENV['DB_NAME'];
$dbuser = $_ENV['DB_USER'];
$dbpass = $_ENV['DB_PASS'];
$linkID = @mysqli_connect($_ENV['DB_HOST'], $dbuser, $dbpass);
mysqli_select_db($linkID, $newsdbname);
$today = date("Y-m-d H:i:s");
$todaysdate = date("D, d M Y H:i:s T");
if(isset($_GET['industry'])) {
    $CategoryID = cleannum($_GET['industry']);
    $more = " and  frcategory LIKE '%" . $CategoryID . "%' ";
    $query = mysqli_query($linkID, "SELECT category FROM sitecats WHERE id = '" . mysqli_real_escape_string($linkID, $CategoryID) . "'");
    $CategoryName =  "";
    while ($c = mysqli_fetch_object($query)) {
        $CategoryName = $c->category;
    }


} else {
    $more = "";
    $CategoryName = "";
}
?>
<rss version="2.0" xmlns:atom="https://www.w3.org/2005/Atom">
<channel>
    <atom:link href="https://www.franchising.com/newfranchises.xml" rel="self" type="application/rss+xml" />
    <title><?PHP print $CategoryName; ?> Franchises at <?PHP print $siteident; ?></title>
    <link>https://<?PHP print $sitedomain; ?>/</link>
    <description>A list of  <?PHP print strtolower($CategoryName); ?> franchise opportunities currently listed on <?PHP print $siteident; ?>.</description>
    <language>en-us</language>
	<managingEditor>benjaminf@franchiseupdatemedia.com (Franchising.com)</managingEditor>
	<lastBuildDate><?php print $todaysdate; ?></lastBuildDate>
	<copyright>Copyright <?PHP print date("Y"); ?> Franchise Update Media Group. All rights reserved.</copyright>
	<image>
		<title><?PHP print $CategoryName; ?> Franchises at <?PHP print $siteident; ?></title>
 	<url>https://<?PHP print $sitedomain; ?>/images/<?PHP print $siteid; ?>_xml.gif</url>
		<link>https://<?PHP print $sitedomain; ?>/</link>
		<width>135</width> 
		<height>40</height> 
  	</image>
<?PHP
$rsssanitize = array(chr(150), chr(147), chr(148), chr(146), chr(130),	 chr(133), chr(145), chr(151), chr(150), chr(180), chr(169), chr(174), chr(153));
$rssreplaced = array ( "-", "\"", "\"", "'", ",", "...", "'", "--", "-", "'", "(C)", "(R)", "TM" );
$resultID = mysqli_query($linkID, "select companycode,company,frsb,frdescription,frlldate from admanager WHERE frstatus=4 and fr=1 $more order by frpp desc, fradlevel desc, frlldate desc");
$recordcount = mysqli_num_rows($resultID);
while ($row = mysqli_fetch_object($resultID)) {
$description = strip_tags(htmlentities($row->frdescription));
$headline = strip_tags(str_replace($rsssanitize, $rssreplaced, $row->company));
$thislink = "/".$row->companycode."/";
if($row->frsb == "1") {
            $ImageBanner = $row->companycode . "/images/banner_sm.gif";
            $ImageType = "gif";
        } else {
            $ImageBanner = $row->companycode . "/images/banner_sm.jpg";
            $ImageType = "jpeg";
        }
?>
<item>
<guid>https://<?PHP print $sitedomain; ?><?php print $thislink; ?></guid>
<title><?php print htmlentities($headline); ?></title>
<description><![CDATA[<a href="https://www.franchising.com/<?PHP print $row->companycode; ?>/"><img src="https://www.franchising.com/<?PHP print $ImageBanner; ?>" width="120" height="60" border="0" align="right" hspace="10" /></a><?php print $description; ?>]]></description>
<link>https://<?PHP print $sitedomain; ?><?php print $thislink; ?></link>
<pubDate><?php print date("D, d M Y H:i:s T",  strtotime($row->frlldate)); ?></pubDate>
</item>
<?php
	} 
?>
</channel>
</rss>