<?php
require_once './Connections/Ixxm.asp';

// 获取新闻分类
$newsClass = $db->fetchAll("SELECT * FROM Ixxm_Newsclass ORDER BY Ixxm_Number ASC");

// 获取新闻
$id = isset($_GET['Id']) ? intval($_GET['Id']) : 0;
if ($id > 0) {
    $news = $db->fetchAll("SELECT * FROM Ixxm_News WHERE Ixxm_Newsclass = ? ORDER BY Ixxm_Time DESC", [$id]);
} else {
    $news = $db->fetchAll("SELECT * FROM Ixxm_News ORDER BY Ixxm_Time DESC");
}

if (empty($news)) {
    echo "<script>alert('NO NEWS！RETURN TO HOME NOW!\\n\\n');window.location='/news.asp';</script>";
    exit;
}
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $Ixxm_webname; ?></title>
<meta content="<?php echo $Ixxm_Keywords; ?>" name="keywords" />
<meta content="<?php echo $Ixxm_Description; ?>" name="description" />
<link href="images/css.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
    background-color: #DADADA;
}
-->
</style>
</head>

<body>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#5E81CF">
  <tr>
    <td height="100" valign="bottom">
        <table width="760" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
                <td height="30" valign="bottom">
                    <table width="200" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td>&nbsp;</td>
                            <td><a href="index.html"><img src="images/logo.png" width="150" height="53" border="0" /></a></td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td height="30">
                    <table width="750" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td align="center" width="80"><a href="news.asp" class="one">CSG</a></td>
                            <?php foreach ($newsClass as $class): ?>
                            <td align="center" width="80">
                                <a href="List/?<?php echo $class['Id']; ?>-0.html" class="one">
                                    <?php echo htmlspecialchars($class['Ixxm_Newsclass']); ?>
                                </a>
                            </td>
                            <?php endforeach; ?>
                            <td align="center" valign="top">
                                <form id="Search" name="Search" method="post" action="Search.asp">
                                    <input name="Title" type="text" class="texborder" id="Title" />
                                    <input name="Submit" type="submit" class="searchbot" value="SEARCH" />
                                </form>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </td>
  </tr>
</table>

<table width="800" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
  <tr>
    <td>
        <?php if (!empty($news)): ?>
        <table width="760" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
                <td width="550">
                    <?php 
                    $newsCount = 0;
                    foreach ($news as $item): 
                        if ($newsCount >= 6) break;
                    ?>
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td>
                                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                    <tr>
                                        <td height="50" align="left" valign="middle">
                                            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                <tr>
                                                    <td>&nbsp;</td>
                                                    <td>
                                                        <a href="View/?<?php echo $item['Id']; ?>.html" target="_blank" class="two">
                                                            <?php echo htmlspecialchars($item['Ixxm_Newstitle']); ?>
                                                        </a>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="content"> &nbsp;&nbsp;&nbsp; <?php echo htmlspecialchars($item['Ixxm_Newsabout']); ?></td>
                                    </tr>
                                    <tr>
                                        <td height="30" align="right" class="content">
                                            —<a href="View/?<?php echo $item['Id']; ?>.html" target="_blank" class="content">Details</a>—
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                    <?php 
                        $newsCount++;
                    endforeach; 
                    ?>
                    
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td>&nbsp;</td>
                        </tr>
                    </table>
                    
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td height="30">&nbsp;</td>
                        </tr>
                    </table>
                </td>
                <td valign="bottom">
                    <div align="right"><img src="images/news-r.jpg" width="200" height="200" /></div>
                </td>
            </tr>
        </table>
        <?php endif; ?>
    </td>
  </tr>
</table>

<table width="800" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
  <tr>
    <td height="60" align="center"> CSG Copyright 2000-2018 / Article by <a href="http://www.colorsortergroup.com/" target="_blank" class="two">COLOR SORTER</a></td>
  </tr>
</table>
</body>
</html>
