Location: PHPKode > projects > WH Community > wh_community/admin/news.php
<?php include('files/header.php'); ?>
<div id="content-outer">
<div id="content">

	<div id="page-heading">
		<h1><?php echo $lang_admin['admin_news']; ?></h1>
	</div>
	
	<table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
	<tr>
		<th rowspan="3" class="sized"><img src="files/shared/side_shadowleft.jpg" width="20" height="300" alt="shadow_l"></th>
		<th class="topleft"></th>
		<td id="tbl-border-top">&nbsp;</td>
		<th class="topright"></th>
		<th rowspan="3" class="sized"><img src="files/shared/side_shadowright.jpg" width="20" height="300" alt="shadow_r"></th>
	</tr>
	<tr>
		<td id="tbl-border-left"></td>
		<td><div id="content-table-inner">
			<div id="table-content">
			<p><?php
			
			$sql = "SELECT
						`id`,
						`author`,
						`title`,
						`date`,
						`check`
					FROM
						`news`";
						
			$result = mysql_query($sql);
			
			echo '<br>[ <a href="news.php?action=new">' . $lang_admin['new_news'] . '</a> ]<br><br><br>';
		
			if(mysql_num_rows($result)) {
			
				echo '<strong>' . mysql_num_rows($result) . ' ' . $lang_admin['news_available'] . '</strong>';
				echo '<br><br>';
				echo '<table width="100%" class="maintable">';
				for ($i = 0; $i < mysql_num_rows($result); $i++) {
					$row = mysql_fetch_object($result);
					$date = date('d.m.Y - H:i', strtotime($row->date));
				
				echo '<tr>
					  <td width="300">' . $row->title . '</td>
					  <td width="200">' . $date . '</td>
					  <td>
					  <a href="news.php?action=edit&id=' . $row->id . '">' . $lang_admin['to_edit'] . '</a> | 
					  <a href="news.php?action=delete&id=' . $row->id . '">' . $lang_admin['delete'] . '</a> | ';
				if($row->check=='1') {
					echo '<a href="news.php?action=lock&id=' . $row->id . '">' . $lang_admin['lock'] . '</a>';
				
					}else{
					echo '<a href="news.php?action=unlock&id=' . $row->id . '">' . $lang_admin['unlock'] . '</a>';
					}
				
				echo '</td>';
				echo '</tr>';
				}
			
			echo '</table>';
			
			}else{
			echo '<p class="false">' . $lang_admin['no_news_available'] . '.</p>';
			}
			echo '<br><br>';
		
			if(isset($_GET['action'])) {
				 switch ($_GET['action']) {
					 case "edit":
						$sql = "SELECT
									`id`,
									`author`,
									`title`,
									`text`
								FROM
									`news`
								WHERE
									`id` = '". $_GET['id'] ."'";
									
					$result = mysql_query($sql);
					$row = mysql_fetch_object($result);
		
					if(isset($_POST['sent']) && $_POST['sent']=='1') {
						$sql = "UPDATE
									`news`
								SET
									`author` = '". $_POST['author'] ."',
									`title` = '". $_POST['title'] ."',
									`text` = '". $_POST['text'] ."'
								WHERE
									`id` = '". $row->id ."'";
						
						mysql_query($sql);
						
						echo '<meta http-equiv="refresh" content="0; URL=news.php">';
				   
					}else{
					
						echo '<form action="news.php?action=edit&id=' . $_GET['id'] . '" method="post">
						<input name="title" type="input" class="fields" size="40" value="' . $row->title . '"><br>
						<br>
						<input name="author" type="input" class="fields" size="40" value="' . $row->author . '"><br>
						<br>
						<textarea cols="60" name="text" class="fields" rows="10">' . $row->text . '</textarea><br>
						<input name="sent" type="hidden" value="1" class="fields">
						<br>
						<input name="send" type="submit" value="' . $lang_admin['execute'] . '" class="button">
						</form>';
					}
					break;
		
					case "delete":
						if(isset($_GET['check']) && $_GET['check']=='ok') {
							$sql = "DELETE FROM
										`news`
									WHERE
										`id` = '". $_GET['id'] ."'";
						mysql_query($sql);
						
						echo '<meta http-equiv="refresh" content="0; URL=news.php">';
					
					}elseif (isset($_GET['check']) && $_GET['check']=='no') {
						echo '<meta http-equiv="refresh" content="0; URL=news.php">';
					
					}else{
					
						echo '' . $lang_admin['delete_news'] . '?<br>';
						echo '<a href="news.php?action=delete&id=' . $_GET['id'] . '&check=ok">' . $lang_admin['yes'] . '</a> |';
						echo '<a href="news.php?action=delete&id=' . $_GET['id'] . '&check=no">' . $lang_admin['no'] . '</a>';
						}
					
					break;
		
				case "lock":
					$sql = "UPDATE
								`news`
							SET
								`check` = '-1'
							WHERE
								`id` = '". $_GET['id'] ."'";
					
					mysql_query($sql);
					
					echo '<meta http-equiv="refresh" content="0; URL=news.php">';
					break;
		
				case "unlock":
					$sql = "UPDATE
								`news`
							SET
								`check` = '1'
							WHERE
								`id` = '". $_GET['id'] ."'";
					mysql_query($sql);
					
					echo '<meta http-equiv="refresh" content="0; URL=news.php">';
					break;
		
				case "new":
					if(isset($_POST['sent']) && $_POST['sent']=='1') {
						if(!$_POST['title'] OR !$_POST['text']) {
							echo '<p class="false">' . $lang_admin['check_title_text'] . '.</p>';
						
						}else{
						
							$sql = "INSERT INTO
										`news` (author,
												title,
												imageurl,
												text)
									VALUES
										('". $_POST['author'] ."',
										'". $_POST['title'] ."',
										'". $_POST['imageurl'] ."',
										'". $_POST['text'] ."')";
							
							mysql_query($sql);
							
							echo '<meta http-equiv="refresh" content="0; URL=news.php">';
						}
					}
					echo '<form action="news.php?action=new" method="post">';
					
					echo '<input name="author" class="fields" size="40" type="input"';
					if(isset($_POST['author'])) {
						echo ' value="' . $_POST['author'] . '" ';
					}
					echo '> <strong>' . $lang_admin['author'] . '</strong><br><br>';
					
					echo '<input name="title" class="fields" size="40" type="input"';
					if(isset($_POST['title'])) {
						echo ' value="' . $_POST['title'] . '" ';
					}
					echo '> <strong>' . $lang_admin['title'] . '</strong><br><br>';
					echo '<input name="imageurl" class="fields" size="40" type="input"';
					if(isset($_POST['imageurl'])) {
						echo ' value="' . $_POST['imageurl'] . '" ';
					}
					echo '> <strong>' . $lang_admin['picture'] . '</strong> <small>(optional)</small><br><br>';
					echo '<strong>' . $lang_admin['news_text'] . ':</strong><br>';
					echo '<textarea cols="60" name="text" rows="10" class="fields">';
					if(isset($_POST['text'])) {
						echo $_POST['text'];
					}
					echo '</textarea><br>
						  <input name="sent" type="hidden" value="1" class="fields"><br>
						  <input name="send" type="submit" value="' . $lang_admin['do_entry'] . '" class="button">
						  </form>';
					break;
		
				default:
					break;
				}
			}
		
			?></p>
			</div>
		</div></td>
		<td id="tbl-border-right"></td>
	</tr>
	<tr>
		<th class="sized bottomleft"></th>
		<td id="tbl-border-bottom">&nbsp;</td>
		<th class="sized bottomright"></th>
	</tr>
	</table>
			
	<div class="clear"></div>
		 
	</div>

	<div class="clear">&nbsp;</div>

</div>
<div class="clear">&nbsp;</div>
</div>
<?php include('files/footer.php'); ?>
Return current item: WH Community