<?php
  ///////////////////////////////////////////////////
  //Телефонный справочник,
  //Клиентская часть
  //2008 (C)
  //Карпухин Павел
  ///////////////////////////////////////////////////

  header('Content-Type: text/xml; charset=UTF-8');
  echo '<?xml version="1.0" encoding="UTF-8" ?>'."\n";

  $lang = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0,2);
  if(is_file ("lang/".$lang.".php")) include "lang/".$lang.".php";
     else include "lang/ru.php";

  require_once "config.php";

  if(! @mysql_select_db($dbname,$dbcnx))
  {
    echo("<p>At this moment database is not available, therefore correct display of page is impossible.<br />If you do not install project previously, run script <a href=install.php>http://".$_SERVER['SERVER_ADDR']."/personal/install.php</a></p>");
    exit();
  }

  $query_org_no = "SELECT * FROM `tbl_organizaciya` WHERE `organizaciya` = '-' ";
   $org_no = mysql_query($query_org_no);
     if(!$org_no) puterror($TEXT['error-tbl7']);
       $result_org_no = mysql_fetch_array($org_no,MYSQL_ASSOC);

  if(!empty($_GET['org_id'])) $org_resource = " AND `org_id` = '".$_GET['org_id']."' ";
   else $org_resource = " AND `org_id` = '".$result_org_no['org_id']."' ";

  $query_org_d = "SELECT organizaciya FROM `tbl_organizaciya` WHERE `position` > 0 ".$org_resource." ";
   $org_d = mysql_query($query_org_d);
     if(!$org_d) puterror($TEXT['error-tbl7']);
       $result_org_desc = mysql_fetch_array($org_d,MYSQL_ASSOC);

   $address = "http://".$_SERVER['SERVER_ADDR']."/personal/";
   $iconka = "http://".$_SERVER['SERVER_ADDR']."/personal/img/rss_ch.png";
   $opentg=Array("<");
   $closetg=Array(">");
?>

<rss version="2.0">
<channel>
<title><?php echo $TEXT['global-title']; ?></title>
<description><?php echo $TEXT['global-rss']; ?> <?php echo $result_org_desc['organizaciya']; ?></description>
<language><?php echo $lang; ?></language>
<link><?php echo $address; ?></link>
<copyright><?php echo $TEXT['maker7']; ?></copyright>
<managingEditor><?php echo $TEXT['admin-mail-rss']; ?></managingEditor>
<webMaster><?php echo $TEXT['admin-mail-rss']; ?></webMaster>
<generator><?php echo $TEXT['global-title']; ?> <?php echo $TEXT['maker8']; ?></generator>
<ttl>60</ttl>
<skipDays>7,1</skipDays>
<image>
	<url><?php echo $iconka; ?></url>
	<width>32</width>
	<height>32</height>
	<title><?php echo $TEXT['global-title']; ?></title>
	<description><?php echo $TEXT['top-news-mail']; ?></description>
	<link><?php echo $address; ?></link>
        </image>
<?php
$query = "SELECT * FROM `tbl_news` WHERE `visible` = 'show' ".$org_resource." ORDER BY data DESC ";
	 $result = mysql_query($query);
	 if(!$result) puterror($TEXT['error-tbl17']);
         while($news = mysql_fetch_array($result,MYSQL_ASSOC))
           {
	   $dat=date('D, d M Y H:i:s',$news['data']);
	   $address_new = "http://".$_SERVER['SERVER_ADDR']."/personal/news.php?news_id=".$news['new_id'];
       $news['description'] = str_replace($opentg,"&lt;",$news['description']);
       $news['description'] = str_replace($closetg,"&gt;",$news['description']);
	   ?>
	 <item> 
	 <title><?php echo $news['header']; ?></title>
	 <link><?php echo $address_new; ?></link>
	 <description><?php echo $news['description']; ?> &#8811;</description>
	 <pubDate><?php echo $dat; ?></pubDate>
	 <guid isPermaLink="true"><?php echo $address_new; ?></guid>
	 </item>
	 <?php
           }
?>
</channel>
</rss>