<?php
 /*-------------------------------------------------------+
 | PHP-Fusion Content Management System
 | Copyright (C) 2002 - 2008 Nick Jones
 | http://www.php-fusion.co.uk/
 +--------------------------------------------------------+
 | Filename: news_cats.php
 | Author: Nick Jones (Digitanium)
 +--------------------------------------------------------+
 | This program is released as free software under the
 | Affero GPL license. You can redistribute it and/or
 | modify it under the terms of this license which you
 | can read by viewing the included agpl.txt or online
 | at www.gnu.org/licenses/agpl.html. Removal of this
 | copyright header is strictly prohibited without
 | written permission from the original author(s).
 +--------------------------------------------------------*/
 require_once "maincore.php";
 require_once THEMES."templates/header.php";
 include LOCALE.LOCALESET."news_cats.php";

 $rowmax = 20;
 $rowstart=(isset($_GET['rowstart'])&&isnum($_GET['rowstart']))?$_GET['rowstart']:0;
 $miktar=5; 
 opentable($locale['400']);
 echo THEME_BULLET."<a href='".BASEDIR."news_cats.php'>".$locale['406']."</a> | ";
 echo THEME_BULLET."<a href='".BASEDIR."news_cats.php?cat_id=0'>".$locale['403']."</a> | "; 
 $result = dbquery("SELECT * FROM ".$db_prefix."news_cats ORDER BY news_cat_id");
    if (dbrows($result)) {
    while ($data = dbarray($result)) {
    echo THEME_BULLET." <a href=".BASEDIR."news_cats.php?cat_id=".$data['news_cat_id']." class=side>".$data['news_cat_name']."</a> | ";
    }
 } else {
    echo "<center>".$locale['407']."</center>\n";
 }
 closetable();
 add_to_title($locale['global_200'].$locale['400']);

 if (isset($_GET['cat_id']) && isnum($_GET['cat_id'])) {
    $res = 0;
    $result = dbquery("SELECT * FROM ".DB_NEWS_CATS." WHERE news_cat_id='".$_GET['cat_id']."'");
    if (dbrows($result) || $_GET['cat_id'] == 0) {
       $data = dbarray($result);
       $rows = dbcount("(news_id)", DB_NEWS, "news_cat='".$_GET['cat_id']."' AND ".groupaccess('news_visibility')." AND (news_start='0'||news_start<=".time().") AND (news_end='0'||news_end>=".time().") AND news_draft='0'");
       if ($rows) {
          $res = 1;
          set_title($data['news_cat_name']);
          opentable($data['news_cat_name']);
          echo "<!--pre_news_cat--><table cellpadding='0' cellspacing='1' width='100%' class='tbl-border'>\n";
          if ($_GET['cat_id'] != 0) {
             echo "<tr>\n";
             echo "<td class='tbl1' style='vertical-align:top'>\n";
          } else {
             echo "</td>\n</tr>\n<tr>\n<td class='tbl1' style='vertical-align:top'><!--news_cat_news-->\n";
          }
          $result2 = dbquery("SELECT * FROM ".DB_NEWS." tn LEFT JOIN ".DB_USERS." tu ON tn.news_name=tu.user_id  WHERE news_cat='".$_GET['cat_id']."' AND ".groupaccess('news_visibility')." AND (news_start='0'||news_start<=".time().") AND (news_end='0'||news_end>=".time().") AND news_draft='0' ORDER BY news_datestamp DESC LIMIT $rowstart, $miktar");
          while ($data2 = dbarray($result2)) {
          if ($data2['news_image']) {
             $news_image = "";
          }  else {
             $news_image = "";   
          }

$news_cat_image = "<a href='news.php?readmore=".$data2['news_id']."' title='".$data2['news_subject']."'><img src='".IMAGES_N_T.$data2['news_image_t2']."' alt='".$data2['news_subject']."' class='news-category' /></a>";

             $unif = THEME_BULLET." <a href='news.php?readmore=".$data2['news_id']."' title='".$data2['news_subject']."'>".$data2['news_subject']."</a> <a href='http://www.google.com.tr/search?hl=tr&q=".$data2['news_subject']."' target='_blank'></a>\n";
             $frog = $news_image.stripslashes($data2['news_news']);
             opentable($unif);
             echo $news_cat_image;
             echo $frog;


             echo"<div> ".THEME_BULLET."<strong>".$locale['409']."</strong> ".THEME_BULLET." ".$locale['410']."".$locale['global_081']."".$data2['news_reads'].". ".$locale['411']."".$locale['global_082']."".showdate("forumdate",$data2['news_datestamp'])." <a href='print.php?type=N&amp;item_id=".$data2['news_id']."'><img src='".get_image("printer")."' alt='".$locale['global_075']."' style='vertical-align:middle;border:0;' /></a>"; if (checkrights("N")) { echo " <a href='".ADMIN."news.php".$aidlink."&amp;action=edit&amp;news_id=".$data2['news_id']."'><img src='".get_image("edit")."' alt='".$locale['global_076']."' title='".$locale['global_076']."' style='vertical-align:middle;border:0;' /></a>\n"; }echo"</div>";
             closetable();


             echo"<hr style='border: 4px;' />";
          }
          echo "</td>\n</tr>\n</table><!--sub_news_cat-->\n";
          if ($rows>$miktar) {
 echo makepagenav($_GET['rowstart'],$miktar,$rows,3,FUSION_SELF."?cat_id=".$_GET['cat_id']."&amp;");
 }
       }
    }
    if (!$res) { redirect(FUSION_SELF); }
 } else {
    opentable($locale['400']);

    $res = 0;
    $result = dbquery("SELECT * FROM ".DB_NEWS_CATS." ORDER BY news_cat_id");
    if (dbrows($result)) {
       echo "<!--pre_news_cat_idx--><table cellpadding='0' cellspacing='1' width='100%' class='tbl-border'>\n";
       while ($data = dbarray($result)) {
          $rows = dbcount("(news_id)", DB_NEWS, "news_cat='".$data['news_cat_id']."' AND ".groupaccess('news_visibility')." AND (news_start='0'||news_start<=".time().") AND (news_end='0'||news_end>=".time().") AND news_draft='0'");
          echo "<tr>\n<td width='150' class='tbl1' style='vertical-align:top'><!--news_cat_image--><img src='".get_image("nc_".$data['news_cat_name'])."' alt='".$data['news_cat_name']."' /><br /><br />\n";
          echo "<strong>".$locale['401']."</strong> ".$data['news_cat_name']."<br />\n<strong>".$locale['402']."</strong> $rows</td>\n";
          echo "<td class='tbl1' style='vertical-align:top'><!--news_cat_news-->\n";
          if ($rows) {
             $result2 = dbquery("SELECT * FROM ".DB_NEWS." tn LEFT JOIN ".DB_USERS." tu ON tn.news_name=tu.user_id WHERE news_cat='".$data['news_cat_id']."' AND ".groupaccess('news_visibility')." AND (news_start='0'||news_start<=".time().") AND (news_end='0'||news_end>=".time().") AND news_draft='0' ORDER BY news_datestamp DESC LIMIT 5");
             while ($data2 = dbarray($result2)) {
             if ($data2['news_image']) {
             $news_image = "";
          }  else {
             $news_image = "";   
          }
$news_cat_image = "<a href='news.php?readmore=".$data2['news_id']."' title='".$data2['news_subject']."'><img src='".IMAGES_N_T.$data2['news_image_t2']."' alt='".$data2['news_subject']."' class='news-category' /></a>";

             $unif = THEME_BULLET." <a href='news.php?readmore=".$data2['news_id']."' title='".$data2['news_subject']."'>".$data2['news_subject']."</a> <a href='http://www.google.com.tr/search?hl=tr&q=".$data2['news_subject']."' target='_blank'></a>\n";
             $frog = $news_image.stripslashes($data2['news_news']);
             opentable($unif);

             echo $frog;

             echo"<div> ".THEME_BULLET."<strong>".$locale['409']."</strong>  ".THEME_BULLET." ".$locale['410']."".$locale['global_081']."".$data2['news_reads'].". ".$locale['411']."".$locale['global_082']."".showdate("forumdate",$data2['news_datestamp'])." <a href='print.php?type=N&amp;item_id=".$data2['news_id']."'><img src='".get_image("printer")."' alt='".$locale['global_075']."' style='vertical-align:middle;border:0;' /></a> ";if (checkrights("N")) { echo "<a href='".ADMIN."news.php".$aidlink."&amp;action=edit&amp;news_id=".$data2['news_id']."'><img src='".get_image("edit")."' alt='".$locale['global_076']."' title='".$locale['global_076']."' style='vertical-align:middle;border:0;' /></a>\n"; } echo"</div>";
             closetable();

             echo"<hr style='border: 4px;' />";
             }
             if ($rows > 5) { echo "<div style='text-align:right'>".THEME_BULLET." <a href='".FUSION_SELF."?cat_id=".$data['news_cat_id']."&rowstart=0'>".$locale['405']."</a></div>\n"; }
             echo"<hr style='border: 4px;' />\n";
          } else {
             echo THEME_BULLET." ".$locale['404']."\n";
          }
          echo "</td>\n</tr>\n";
       }
       $res = 1;
    }
    $result = dbquery("SELECT * FROM ".DB_NEWS." tn LEFT JOIN ".DB_USERS." tu ON tn.news_name=tu.user_id WHERE news_cat='0' AND ".groupaccess('news_visibility')." AND (news_start='0'||news_start<=".time().") AND (news_end='0'||news_end>=".time().") AND news_draft='0' ORDER BY news_datestamp DESC LIMIT 5");
    if (dbrows($result)) {
       if ($res == 0) { echo "<table cellpadding='0' cellspacing='1' width='100%' class='tbl-border'>\n"; }
       $nrows = dbcount("(news_id)", DB_NEWS, "news_cat='0' AND ".groupaccess('news_visibility')." AND (news_start='0'||news_start<=".time().") AND (news_end='0'||news_end>=".time().") AND news_draft='0'");
       echo "<tr>\n<td width='150' class='tbl1' style='vertical-align:top'>".$locale['403']."<br />\n";
       echo "<strong>".$locale['402']."</strong> $nrows</td>\n<td class='tbl1' style='vertical-align:top'>\n";
       while ($data = dbarray($result)) {
             if ($data['news_image']) {
             $news_image = "";
          }  else {
             $news_image = "";   
          }
             $unif = THEME_BULLET." <a href='news.php?readmore=".$data['news_id']."' title='".$data['news_subject']."'>".$data['news_subject']."</a> <a href='http://www.google.com.tr/search?hl=tr&q=".$data['news_subject']."' target='_blank'></a>\n";
             $frog = $news_image;
             opentable($unif);
             echo $frog;
             echo"<div> ".THEME_BULLET."<strong>".$locale['409']."</strong> <a href='profile.php?lookup=".$data['user_id']."'>".$data['user_name']."</a> ".THEME_BULLET." ".$locale['410']." ".$data['news_reads']."".$locale['411']."  ".THEME_BULLET."<strong>".$locale['412']."</strong>:".showdate("forumdate",$data['news_datestamp'])." <a href='print.php?type=N&amp;item_id=".$data['news_id']."'><img src='".get_image("printer")."' alt='".$locale['global_075']."' style='vertical-align:middle;border:0;' /></a> ";if (checkrights("N")) { echo "<a href='".ADMIN."news.php".$aidlink."&amp;action=edit&amp;news_id=".$data['news_id']."'><img src='".get_image("edit")."' alt='".$locale['global_076']."' title='".$locale['global_076']."' style='vertical-align:middle;border:0;' /></a>\n"; } echo"</div>";

             closetable();
             echo"<hr style='border: 4px;' />";
       }
       $res = 1;
       if ($nrows > 5) { echo "<div style='text-align:right'>".THEME_BULLET." <a href='".FUSION_SELF."?cat_id=0'>".$locale['405']."</a></div>\n"; }
       echo "</td>\n</tr>\n";
    }
    if ($res == 1) {
       echo "</table><!--sub_news_cat_idx-->\n";
    } else {
       echo "<div style='text-align:center'><br />\n".$locale['407']."<br /><br />\n</div>\n";
    }
 }
 echo "<div style='text-align: right;'><a href='http://burak.berkturk.com' onclick='window.open(this.href); return false;' onkeypress='window.open(this.href); return false;'>&#169;</a></div>";

 closetable();

 require_once THEMES."templates/footer.php";
 ?>