<?php
session_start();
include "../functions.php";

$sessionID = session_id();

checkAdmin($sessionID);

?>

<?php

$title = "edit news";
include "header.php";

$id = $_GET["id"];

$query = "select date, subject, author, summary, body, url, img, highlight, categoryID from news where id='$id'";

$result = mysql_query($query);

$row = mysql_fetch_array($result);

$date = $row[0];
?>

	<form action="edit_handler.php" method="post">
	<tr>
	<td>
	<table border=0 cellpadding=5 width=100%>
	  
	  <tr>
	    <td align="right" valign="top">
	    Date(dd/mm/yyyy):
	    </td>
	    
	    <td align="left" valign="top">
	    <input type="text" name="date" maxleng="30" value=
	    <?php
	    $year = substr($date, 0, 4);
	    $month = substr($date, 4, 2);
	    $day = substr($date, 6, 2); 
	    echo "$day/$month/$year";
	    ?>
	    >
	    </td>
	  </tr>
	  
	  <tr>
	    <td align="right" valign="top">
	    Subject:
	    </td>
	    
	    <td align="left" valign="top">
	    <?php
	    $subject = stripslashes($row[1]);
	    $subject = ereg_replace("\"","&quot;",$subject);
	    ?>
	    <input type="text" name="subject" maxleng="30" value="<?php echo $subject; ?>">
	    </td>
	  </tr>
	  
	  <tr>
	    <td align="right" valign="top">
	    Category:
	    </td>
	    
	    <td align="left" valign="top">
	    <select name="categoryID">
	    <?php
	    $query = "select categoryID, categoryName from news_category order by categoryName asc";
	    $result = mysql_query($query) or die (mysql_error());
	    while ($newrow = mysql_fetch_array($result))
	    {
	    	$categoryID = $newrow[0];
	    	$categoryName = $newrow[1];
	    	
	    	if ($categoryID == $row[8])
	    	{
	    		echo "<option value=\"$categoryID\" selected>$categoryName</option>";
	    	}
	    	else
	    	{
	    		echo "<option value=\"$categoryID\">$categoryName</option>";
	    	}
	    }
	    ?>
	    </select>
	    </td>
	  </tr>
	  
	  <tr>
	    <td align="right" valign="top">
	    Author:
	    </td>
	    
	    <td align="left" valign="top">
	    <input type="text" name="author" maxleng="30" value="<?php echo $row[2]; ?>">
	    </td>
	  </tr>
	  
	  <tr>
	    <td align="right" valign="top">
	    Summary:
	    </td>
	    
	    <td align="left" valign="top">
	    <TEXTAREA NAME="summary" ROWS=5 COLS=30 WRAP="virtual"><?php echo $row[3]; ?></TEXTAREA>
	    </td>
	  </tr>
	  
	  <tr>
	    <td align="right" valign="top">
	    Body:
	    </td>
	    
	    <td align="left" valign="top">
	    <TEXTAREA NAME="body" ROWS=5 COLS=30 WRAP="virtual"><?php echo $row[4]; ?></TEXTAREA>
	    </td>
	  </tr>
	  
	  <tr>
	    <td align="right" valign="top">
	    URL:
	    </td>
	    
	    <td align="left" valign="top">
	    <input type="text" name="url" maxlength="80" size=30 value="<?php echo $row[5]; ?>">
	    </td>
	  </tr>
	  
	  <tr>
	    <td align="right" valign="top">
	    Image:
	    </td>
	    
	    <td align="left" valign="top">
	    <input type="text" name="image" maxlength="80" size=30 value="<?php echo $row[6]; ?>">&nbsp;<a href=fileupload/upload.php target=_blank>upload your picture</a>
	    <!--<input type="file" name="upload" value="Browse...">&nbsp;&nbsp;<input type="submit" value="upload">-->
	    </td>
	  </tr>
	  
	  <tr>
	    <td align="right" valign="top">
	    Highlight:
	    </td>
	    
	    <td align="left" valign="top">
	    <input type="checkbox" name="highlight" <?php if ($row[7]) echo "checked"; ?>>
	    </td>
	  </tr>
	  
	  <tr>
	    <td colspan=2 align="center">
	    <input type="hidden"  name="submit" value=1>
	    <input type="hidden" name="id" value="<?php echo $id; ?>">
	    <input type="submit" value="Modify">&nbsp;<input type="reset" value="Cancel">
	    </td>
	  </tr>
	
	</table>
	</td>
	</tr>
	</form>
	<?php
include "footer.php";
	?>