<?php
/*===================================================+ 
|| # HoloCMS - Website and Content Management System
|+===================================================+ 
|| # Copyright © 2012 DnT [Tutti i diritti riservati]
|| # http://dnt.webnet32.com/
|+===================================================+ 
|| # DnT HoloCMS v2 - Created By Donatello (DnT)
|| # http://code.google.com/p/dnt-project/downloads/list
|+===================================================*/ 

require_once('../core.php');
if($hkzone !== true){ header("Location: index.php?throwBack=true"); exit; }
if(!session_is_registered(acp)){ header("Location: index.php?p=login"); exit; }

$pagename = "Manage Existing Articles";

if($do == "delete" && is_numeric($key)){

	$check = mysql_query("SELECT num FROM cms_news WHERE num = '".$key."' LIMIT 1") or die(mysql_error());
	$exists = mysql_num_rows($check);

	if($exists > 0){
		mysql_query("DELETE FROM cms_news WHERE num = '".$key."' LIMIT 1") or die(mysql_error());
		$msg = "News Eliminata Correttamente.";
	} else {
		$msg = "Clicca sulla 'X'; per eliminare una news!";
	}

} elseif($do == "edit" && is_numeric($key)){

	$check = mysql_query("SELECT * FROM cms_news WHERE num = '".$key."' LIMIT 1") or die(mysql_error());
	$exists = mysql_num_rows($check);

	if($exists > 0){
		$article = mysql_fetch_assoc($check);
		$editor_mode = true;
	} else {
		$msg = "Unable to edit article; this article does not exist!";
	}

} elseif($do == "save" && is_numeric($key) && isset($_POST['topstory'])){

	$check = mysql_query("SELECT num FROM cms_news WHERE num = '".$key."' LIMIT 1") or die(mysql_error());
	$exists = mysql_num_rows($check);

	if($exists > 0){

		$num = $key;

		$title = addslashes($_POST['title']);
		$primopiano = addslashes($_POST['primopiano']);
		$topstory = addslashes($_POST['topstory']);
		$imgprimopiano = addslashes($_POST['imgprimopiano']);
		$short_story = addslashes($_POST['short_story']);
		$story = addslashes($_POST['story']);
                



		mysql_query("UPDATE cms_news SET title = '".$title."', primopiano = '".$primopiano."', topstory = '".$topstory."', imgprimopiano = '".$imgprimopiano."', short_story = '".$short_story."', story = '".$story."' WHERE num = '".$num."' LIMIT 1") or die(mysql_error());

		$msg = "News .";
		$editor_mode = false;

	} else {

		$msg = "Unable to edit article; this article does not exist!";

	}

} elseif($do == "bounce"){

	$msg = "News Aggiornata Correttamente.";

}

@include('subheader.php');
@include('header.php');
?>
<table cellpadding='0' cellspacing='8' width='100%' id='tablewrap'>
<tr> <td width='22%' valign='top' id='leftblock'>
 <div>
 <!-- LEFT CONTEXT SENSITIVE MENU -->
<?php @include('sitemenu.php'); ?>
 <!-- / LEFT CONTEXT SENSITIVE MENU -->
 </div>
 </td>
 <td width='78%' valign='top' id='rightblock'>
 <div><!-- RIGHT CONTENT BLOCK -->
 
<?php if($editor_mode !== true){ ?>
<?php if(isset($msg)){ ?><p><strong><?php echo $msg; ?></strong></p><?php } ?>
 
<form action='index.php?p=news_manage&do=save' method='post' name='theAdminForm' id='theAdminForm'>
 <div class='tableborder'>
 <div class='tableheaderalt'>Gestione News</div>
 <table cellpadding='4' cellspacing='0' width='100%'>
 <tr>
  <td class='tablesubheader' width='1%' align='center'>ID</td>
  <td class='tablesubheader' width='28%'>Titolo</td>
  <td class='tablesubheader' width='10%' align='center'>Data</td>
  <td class='tablesubheader' width='10%' align='center'>Autore</td>
  <td class='tablesubheader' width='10%' align='center'>Modifica</td>
  <td class='tablesubheader' width='12%' align='center'>Elimina</td>
 </tr>
<?php
$get_articles = mysql_query("SELECT num,title,short_story,date,author FROM cms_news ORDER BY num DESC") or die(mysql_error());

while($row = mysql_fetch_assoc($get_articles)){
	printf(" <tr>
  <td class='tablerow1' align='center'>%s</td>
  <td class='tablerow2'><strong>%s</strong><div class='desctext'>%s</div></td>
  <td class='tablerow2' align='center'>%s</td>
  <td class='tablerow2' align='center'>%s</td>
  <td class='tablerow2' align='center'><a href='index.php?p=news_manage&do=edit&key=%s'><img src='./images/edit.gif' alt='Edit'></a></td>
  <td class='tablerow2' align='center'><a href='index.php?p=news_manage&do=delete&key=%s'><img src='./images/delete.gif' alt='Delete'></a></td>															
</tr>", $row['num'], htmlspecialchars(stripslashes($row['title'])), htmlspecialchars(stripslashes($row['short_story'])), $row['date'], $row['author'], $row['num'], $row['num']);
}
?>
 
 </table>
 <div class='tablefooter' align='center'><div class='fauxbutton-wrapper'><span class='fauxbutton'><a href='index.php?p=news_compose'>Crea una nuova news</a></span></div></div>
</div>
<?php } else { ?>
<form action='index.php?p=news_manage&do=save&key=<?php echo $article['num']; ?>' method='post' name='theAdminForm' id='theAdminForm'>
<div class='tableborder'>
<div class='tableheaderalt'>Modifica News (<?php echo $article['title']; ?>)</div>

<table width='100%' cellspacing='0' cellpadding='5' align='center' border='0'>
<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>Titolo</b><div class='graytext'>Il titolo della News.</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='title' value="<?php echo stripslashes($article['title']); ?>" size='30' class='textinput'></td>
</tr>

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>In Primo Piano</b></td>
<td class='tablerow2'  width='60%'  valign='middle'><select name='primopiano' class='dropdown'> <option value='0' <?php if($article['primopiano'] == "0"){ echo 'selected'; } ?>>No</option> <option value='1' <?php if($article['primopiano'] == "1"){ echo 'selected'; } ?>>Si</option> </select> 
</td>
</tr>

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>Immagine</b><div class='graytext'>Per scegliere le immagini <a href="http://raikas77.webnet32.com/immagini_news/immagini_news.html">Clicca quì</A></div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='topstory' value="<?php echo $article['topstory']; ?>" size='30' class='textinput'></td>
</tr>

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>Immagine In Primo Piano</b><div class='graytext'>Per scegliere le immagini Primo <a href="http://raikas77.webnet32.com/immagini_primo/">Clicca quì</A></div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='imgprimopiano' value="<?php echo $article['imgprimopiano']; ?>" size='30' class='textinput'></td>
</tr>

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>Anteprima</b><div class='graytext'>L'HTML non è abilitato.</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><textarea name='short_story' cols='60' rows='5' wrap='soft' id='sub_desc'   class='multitext'><?php echo stripslashes($article['short_story']); ?></textarea></td>
</tr>

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>News Completa</b><div class='graytext'>L'HTML è abilitato.</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><textarea name='story' cols='60' rows='5' wrap='soft' id='sub_desc'   class='multitext'><?php echo stripslashes($article['story']); ?></textarea></td>
</tr>

<tr>
<td class='tablerow1'  width='40%'  valign='middle'><b>Autore</b><div class='graytext'>Chi è l'autore della news?</div></td>
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='author' value="<?php echo $article['author']; ?>" size='30' class='textinput'></td>
</tr>


<tr>
<tr><td align='center' class='tablesubheader' colspan='2' ><input type='submit' value='Modifica News' class='realbutton' accesskey='s'></td></tr>
</form></table></div><br />
<?php } ?>
	 </div><!-- / RIGHT CONTENT BLOCK -->
	 </td></tr>
</table>
</div><!-- / OUTERDIV -->
<div align='center'><br />
<?php
$mtime = explode(' ', microtime());
$totaltime = $mtime[0] + $mtime[1] - $starttime;
printf('Ore: %.3f', $totaltime);
?>
</div>