<?php

header("Content-Type: text/html; charset=UTF-8");
header("Expires: on, 01 Jan 1970 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

//later: geo ip und spracheinstellungen
error_reporting(E_ALL);
ini_set('display_errors', '1');

require_once( "/home/www/wwwbuzzerstar/libraryv3/Template.inc.php" ); 
require_once( "/home/www/wwwbuzzerstar/libraryv3/Config.inc.php" );
require_once( "/home/www/wwwbuzzerstar/libraryv3/Functions.inc.php" );
require_once( "/home/www/wwwbuzzerstar/libraryv3/Connection.inc.php");
require_once( "/home/www/wwwbuzzerstar/libraryv3/SSDTube.php" ); 

$SSDTube 			= new SSDTube();
$func	 			= new Functions();
$config 			= new Config();
$design 			= new Template();
$conn 				= new Connection();
$pdo				= $conn->prepareQuery();
$table 				= $config->sql_tablename_publish_de();
$pdo				= $conn->prepareQuery();

$action				= $func->stripHtml($_REQUEST['a']);
$shortid			= $func->stripHtml($_REQUEST['sid']);
$p_isdelete			= $func->stripHtml($_REQUEST['del']);

if (stripos($action, 'set_online_simple') !== false ){

	if ( $p_isdelete == 1 && strlen($p_isdelete) == 1 ){
		$sql = "DELETE FROM $table WHERE p_shortcode = :shortcode LIMIT 1;";
		$stmt = $pdo->prepare($sql);
		$stmt->bindParam(':shortcode', $shortid, PDO::PARAM_STR);   
		$stmt->execute();
	} else {
		$p_isonline		= 1;
		$stmt 			= $pdo->prepare("UPDATE $table SET p_isonline=? WHERE p_shortcode=?");
		$stmt->execute(array($p_isonline,$shortid));
	}
	
	$stmt = null; // doing this is mandatory for connection to get closed
	$pdo  = null;	
		
	header("Location: /manage/");
	exit(0);

} elseif (stripos($action, 'set_online_advanced') !== false){
 
} elseif (stripos($action, 'show_advanced') !== false){
/* 	<!--
				<b><strong>Artikel intensiv begutachten:</b></strong> <a href="/manage/?a=show_advanced&sid=$shortcode" target="_blank">Artikel querlesen</a><br />
	-->
*/
} else if ( empty($action) || strlen($action) <=0 || !isset($action) ||  empty($shortid) || strlen($shortid) <=0 || !isset($shortid) ) {
	
	//echo "trying to get from db";
	
	$stmt 			= $pdo->prepare("SELECT * FROM $table WHERE id>0 AND p_isonline='0' ORDER BY p_timestamp DESC LIMIT 30;");
	$stmt->execute();
	$content_html 	= '<section id="columnsdemo" style="margin-bottom:60px; width:100%" class="clearfix"><div class="grid_12">';
	
	while($rows = $stmt->fetch(PDO::FETCH_ASSOC)) {
		$headline			= trim($rows["p_headline"]);
		$author				= trim($rows["p_authorname"]);
		$backlink			= trim($rows["p_backlink"]);
		$shortcode			= trim($rows["p_shortcode"]);
		$article			= trim($rows["p_articletext"]);
		$pic_desc			= trim($rows["p_picture_1_description"]);
		$videolink			= trim($rows["p_videolink"]);
		$SSDTube->identify($videolink, true);
		$EmbeddedVideo 		= $SSDTube->embed;
		
		if (stripos($videolink, "https")===false){
			$error = "Videolink ist kein HTTPS LINK - eventuelle Bildbeschreibung und Videolink vertauscht?";
		}
		$text_short 		= substr($article,0,250). "...";
		//$neuertext 			= wordwrap( $headline, 75, "<br />");
		$content_html 		.= <<<END
			<span>
				
				<img src="http://www.sichtbarkeitsindex.de/a/buzzerstar.com" alt="SISTRIX SEO Tools" width="88" height="31"/>
				<b><strong>Schlagzeile:</b></strong> $headline<br /><br />
				<b><strong>Artikelauszug:</b></strong> $article<br /><br />
				<ul>
					<li>Bilder und Videos: <br />
							<img src="/a.php?s=$shortcode" alt="Bild" /></li>
					<li>Bildunterschrift: $pic_desc</li>
					<li>Video: $videolink - $error<br />
					$EmbeddedVideo
					</li>
				</ul><br />		
				<b><strong>Artikel freischalten:</b></strong> <a href="/manage/?a=set_online_simple&sid=$shortcode" target="_self">Artikel (sofort) freischalten</a><br />
				<hr>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:red;">Artikel löschen: <a href="/manage/?a=set_online_simple&sid=$shortcode&del=1" target="_self">Artikel (sofort) löschen</a></span><br /><br />
				
				<hr><br />
			</span>  
END;
	}

	if ( stripos($content_html, 'Schlagzeile') === false){
		$content_html 	.= '<b><strong>Es warten keine Einträge auf deine Administration!</b></strong>';
	}
	$content_html 	.= '</div></section>';
} 
  
$copyYear 	= 2012; 
$curYear 	= date('Y'); 
$year 		= $copyYear . (($copyYear != $curYear) ? '-' . $curYear : '');
$copy 		= "&copy;$year BuzzerStar.com - M.Sc. Sebastian Enger";

$content = array_merge(
	array('image'=>"http://www.buzzerstar.com/images/logo_header.png"), // change for final version
	array('copyright'=>$copy),
	array('robots'=>"NOINDEX,NOFOLLOW,NONE"),
	array('html_content'=>$content_html)
	
);	
$design->setPath( "/home/www/wwwbuzzerstar/tpl-new/" );
$design->display_cache('administration_simple', $content, true, 3600*24*3);
$stmt 				= null; // doing this is mandatory for connection to get closed
$pdo 				= null;
exit(0);
?>