
<?php require_once('Connections/CCOM.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_CCOM, $CCOM);
$query_Recordset1 = "SELECT * FROM newsadmin ORDER BY username DESC";
$Recordset1 = mysql_query($query_Recordset1, $CCOM) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['passwd'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "newsAdmin.php";
  $MM_redirectLoginFailed = "newsLogin.php?errMsg=1";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_CCOM, $CCOM);
  
  $LoginRS__query=sprintf("SELECT username, passwd FROM newsadmin WHERE username=%s AND passwd=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $CCOM) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
	if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
<!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>:: 新聞公佈系統 ::</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table border="0" cellpadding="0" cellspacing="0" width="640" align="center">
  <tr>
    <td><img src="images/newsCenter_r1_c1.jpg" alt="" name="newsCenter_r1_c1" width="640" height="10" border="0" id="newsCenter_r1_c1" /></td>
  </tr>
  <tr>
    <td style="height: 60px"><table align="left" border="0" cellpadding="0" cellspacing="0" width="640">
      <tr>
        <td><img src="images/newsCenter_r2_c1.jpg" alt="" name="newsCenter_r2_c1" width="188" height="60" border="0" id="newsCenter_r2_c1" /></td>
        <td width="452"><table align="left" border="0" cellpadding="0" cellspacing="0" width="452">
          <tr>
            <td width="452" height="45" background="images/newsCenter_r2_c2.jpg" align="right" valign="bottom" class="nav"><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr align="right">
                <td><img align="absmiddle" src="images/board_mark_list.gif" /> <a href="news.php" class="nav">回到新聞公告</a></td>
                <td width="8%">&nbsp;</td>
              </tr>
            </table></td>
          </tr>
          <tr style="font-size: 12pt; color: #000000">
            <td><img src="images/newsCenter_r3_c2.jpg" alt="" name="newsCenter_r3_c2" width="452" height="15" border="0" id="newsCenter_r3_c2" /></td>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
  <tr class="row1" style="font-size: 12pt; color: #000000">
    <td background="images/newsCenter_r4_c1.jpg" align="center"><form ACTION="<?php echo $loginFormAction; ?>" id="form1" name="form1" method="POST">
          <span class="fonthead">《登 ‧ 入 ‧ 管 ‧ 理 ‧ 介 ‧ 面》</span>
        <hr width="60%" />
      <table width="50%" border="0" cellpadding="4" cellspacing="1" class="forumline">
        <tr>
          <td width="32%" class="row3">管理者帳號：</td>
          <td width="68%" class="row1"><input name="username" type="text" id="username" value="<?php echo $row_Recordset1['username']; ?>" /></td>
        </tr>
        <tr>
          <td class="row3">管理者密碼：</td>
          <td class="row1"><input name="passwd" type="text" id="passwd" /> </td>
        </tr>
      </table>
      <h2>
         <?php /*start inputVar script*/ if (isset($_GET['errMsg'])){ ?>
          <?php /*start input_input script*/ if ($_GET['errMsg'] == 1){ ?>
         
            帳號密碼錯誤
            <?php } /*end input_input script*/ ?>
          <?php } /*end inputVar script*/ ?>
      </h2>
      <h1>
      <?php /*start inputVar script*/ if (isset($_GET['errMsg'])){ ?>
        <?php /*start input_input script*/ if ($_GET['errMsg'] == 2){ ?>
          
          
            <?php } /*end inputVar script*/ ?>
          <?php } /*end input_input script*/ ?>
      </h1>
      <hr width="60%" />
      <label>
      <input type="submit" name="Submit" value="登入管理畫面" />
      </label>
            </form>    </td>
  </tr>
  <tr style="font-size: 12pt; color: #000000">
    <td><img src="images/newsCenter_r5_c1.jpg" alt="" name="newsCenter_r5_c1" width="640" height="25" border="0" id="newsCenter_r5_c1" /></td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
