<?php
// +------------------------------------------------------------------------+
// | PHP Melody version 1.6.7 ( www.phpsugar.com )
// +------------------------------------------------------------------------+
// | PHP Melody IS NOT FREE SOFTWARE
// | If you have downloaded this software from a website other
// | than www.phpsugar.com or if you have received
// | this software from someone who is not a representative of
// | phpSugar, you are involved in an illegal activity.
// | ---
// | In such case, please contact: support@phpsugar.com.
// +------------------------------------------------------------------------+
// | Developed by: phpSugar (www.phpsugar.com) / support@phpsugar.com
// | Copyright: (c) 2004-2011 PhpSugar.com. All rights reserved.
// +------------------------------------------------------------------------+

session_start();
require('../config.php');
include_once(ABSPATH . 'include/user_functions.php');
include_once(ABSPATH . 'include/islogged.php');
include(ABSPATH .'admin/functions.php');

if ( ! $logged_in || ( ! is_admin() && ! is_moderator() && ! is_editor()))
{
	header("Location: login.php");
	exit();
}

$mod_can = array();
$restricted_access = array();

if (is_moderator())
{
	$mod_can = mod_can();
	$restricted_access = array( 'mod_pages',	// Pages
								'3',			// Categories 
								'7',			// Statistics
								'8',			// Settings
								'9',			// Ads
								'10');			// System

	if ( ! $mod_can['manage_videos']) 
		$restricted_access[] = '2';
	
	if ( ! $mod_can['manage_comments']) 
		$restricted_access[] = '4';
	
	if ( ! $mod_can['manage_users'])
		$restricted_access[] = '6';
	
	if ( ! $mod_can['manage_articles'])  
		$restricted_access[] = 'mod_article';
}

if (is_editor())
{
	$restricted_access = array( 'mod_pages',	// Pages
								'2', 			// Videos
								'3',			// Categories 
								'4',			// Comments
								'6', 			// Users
								'7',			// Statistics
								'8',			// Settings
								'9',			// Ads
								'10');			// System
	if ( ! _MOD_ARTICLE)
	{
		$restricted_access[] = 'mod_article';
	}
}

require(ABSPATH . 'include/article_functions.php');

define('VS_UNCHECKED', 0);
define('VS_OK', 1);
define('VS_BROKEN', 2);
define('VS_RESTRICTED', 3);
define('VS_UNCHECKED_IMG', "images/vs_unchecked.gif");
define('VS_OK_IMG', "images/vs_ok.gif");
define('VS_BROKEN_IMG', "images/vs_broken.gif");
define('VS_RESTRICTED_IMG', "images/vs_restricted.gif");
define('VS_NOTAVAILABLE_IMG', "images/vs_na.gif");

$upload_max_filesize = get_true_max_filesize();

?>
<!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>Admin Area - <?php echo _SITENAME; ?></title>
<?php 
	if(!empty($_COOKIE['style'])) $styleme = $_COOKIE['style'];
	else $styleme = 'admin';
?>
<?php if ($showm == '2' || $showm == '8') :?>
<link rel="stylesheet" href="jquery-ui-1.8.4.custom.css" type="text/css" />
<?php endif;?>	
<link id="stylesheet" href="<?php echo $styleme ?>.css" rel="stylesheet" type="text/css" />   	                     
<!--[if IE]>
<link rel="stylesheet" href="admin_ie.css" type="text/css" media="screen" charset="utf-8" />
<![endif]-->
<link rel="stylesheet" href="prettyPop.css" type="text/css" media="screen" charset="utf-8" />
<link rel="stylesheet" href="gritter.css" type="text/css" media="screen" charset="utf-8" />
<link rel="shortcut icon" href="<?php echo _URL; ?>/<?php echo _UPFOLDER; ?>/favicon.ico">
<script type="text/javascript" src="../js/general.js"></script>
<!--<script type="text/javascript" src="../js/jquery.js"></script>-->                               
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.persist.min.js"></script>
<script type="text/javascript" src="js/wysiwyg.js"></script>
<script type="text/javascript" src="js/jquery.tablesorter.min.js"></script>
<script type="text/javascript" src="js/jquery.prettyPhoto.js"></script>
<script type="text/javascript" src="js/jquery.gritter.js"></script>
<script type="text/javascript" src="js/jquery.anchor.js"></script>
<script type="text/javascript" src="js/jquery.styleme.js"></script>
<script type="text/javascript" src="js/jquery.ajaxmanager.js"></script>
<?php if ($showm == '8' && $_POST['submit'] != ''): ?>
<script type="text/javascript">
var php_post_arr = <?php echo json_encode($_POST); ?>;
</script>
<?php endif; ?>
<script type="text/javascript" src="a_general.js"></script>



<?php 
if ($showm == 'mod_article' || $showm == 'mod_pages')
{
	?>
	<script type="text/javascript" src="js/article.js"></script>
	<script type="text/javascript" src="js/swfupload.js"></script>
	<script type="text/javascript" src="js/swfupload.handlers.js"></script>
	<?php
}
?>
<script type="text/javascript" src="js/ColorPicker.js"></script>
<script type="text/javascript">

$(document).ready(function() {
	$("#usersSortTable").tablesorter({
	 headers: { 0: { sorter: false}, 8: { sorter: false} },
	 //sortList: [[0,1]],
	 widgets: ['zebra']
	 });
	$("#videosSortTable").tablesorter({
	 headers: { 0: { sorter: false}, 
	 			1: { sorter: false}, 
				2: { sorter: false}, 
				3: { sorter: false}, 
				4: { sorter: false}, 
				7: { sorter: false}, 
				8: { sorter: false}, 
				9: { sorter: false},
				10: { sorter: false}
			},
	 //sortList: [[5,1]],
	 widgets: ['zebra']
	 });

});

//	Other JS functions
function validateFormOnSubmit(theForm, say_reason) {	
 
 var reason = say_reason;
 var counter = 0;
 
 $("input,textarea").each(function(){
 
 	if($(this).attr('id') == "must")
	{
		if ($(this).attr("value").length == 0)
		{
			$(this).css("background", "#FFD2D2");
			counter++;
		}
		else
		{
			$(this).css("background", "#FFFFFF");
		}	
	}
 });
 
 if (counter > 0) {
   alert(reason);
   return false;
 }
 return true;
}

function confirm_delete_all() {
	var confirm_msg = "You are about to delete all these selected items. Click 'Cancel' to stop or 'OK' to continue";	 // refers to articles, videos and users
	var response = false;
	if (confirm(confirm_msg)) {
	} else {
		return false;
	}
}

$(document).ready(function()
{
  $(".msg_body").hide();
  $(".msg_head").click(function()
  {
    $(this).next(".msg_body").slideToggle('normal');
  });
});

jQuery(function($)
{
	$("#bg_bar").attachColorPicker();
	$("#play_timer").attachColorPicker();
	
});
$(document).ready(function(){
	$("a[rel^='prettyPop']").prettyPhoto({
		animationSpeed: 'fast', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.70, /* Value betwee 0 and 1 */
		showTitle: false, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'dark_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
		width: <?php echo _PLAYER_W;?>,
		height: <?php echo _PLAYER_H;?>,
		// flowplayer settings - start
		fp_bgcolor: '<?php echo '0x' . _BGCOLOR;?>',
		fp_timecolor: '<?php echo '0x' . _TIMECOLOR;?>',
		fp_swf_loc: '<?php echo _URL .'/player.swf';  ?>',
		// flowplayer settings - end 
		callback: function(){}
	});
});

</script>

<script type="text/javascript">
	var show_pm_notes = $.cookie('showNotice');
	if (show_pm_notes != 'off') {
	
		jQuery(document).ready( 
		function() {
			<?php show_pm_notes(); ?>
		});
	
	}	
</script>
<?php
	if($showm == '2')
	{	//	Add Videos
?>

<script type="text/javascript" src="jquploader/jquery.flash.js"></script>
<script type="text/javascript" src="jquploader/jquery.jqUploader.js"></script>
<script type="text/javascript" src="js/vscheck.js"></script>
<?php
	}
	
	if ($showm == '2' || $showm == 'mod_article' || $showm == '8')
	{
?>
<script type="text/javascript" src="js/jquery-ui-1.8.4.custom.min.js"></script>
<?php 
	}
	if ($showm == '2' || $showm == 'mod_article')
	{
?>
<script type="text/javascript" src="js/ui.dropdownchecklist-1.3-min.js"></script>
<script type="text/javascript">

$(document).ready(function(){

	$('#main_select_category').dropdownchecklist({		
		emptyText: 'Select categories...',
		forceMultiple: true,
		icon: {
			placement: 'right', 
			toOpen:'ui-icon-triangle-1-s', 
			toClose:'ui-icon-triangle-1-n'
		},
		width: 160
	});
	jQuery('select[id^="select_category-"]').dropdownchecklist({
		emptyText: 'Select...',
		forceMultiple: true,
		icon: {
			placement: 'right', 
			toOpen:'ui-icon-triangle-1-s', 
			toClose:'ui-icon-triangle-1-n'
		},
		width: 160
	});


	$("#addvideo_direct_input").change(function() {
		var value = $(this).val();
		var output_sel = '#addvideo_direct_response';
		
		if (value.length > 8) {
			$(output_sel).html('<img src="./images/status_loading.gif" alt="Loading" id="loading" align="absmiddle" /> Checking...').show();
			$.ajax({
				type: "POST",
				url: "./addvideo.php",
				data: "do=checkurl&url=" + value,
				dataType: 'html',
				success: function(data){
					if (output_sel.length > 0) {
						$(output_sel).html(data).show();
					}
				}
			});
		}
	});
	
	$("img[name='video_thumbnail']").click(function() {
		
		var img = $(this);
		var ul = img.parents('.thumbs_ul');
		var li = img.parent();
		var tr = img.parents('tr');	
		var input = tr.find("input[name^='thumb_url']");

		if ( ! li.hasClass('thumbs_li_selected'))
		{
			ul.children().removeClass('thumbs_li_selected').addClass('thumbs_li_default');
			li.addClass('thumbs_li_selected');
			input.val(img.attr('src'));
		}
	});

	$("#uploader").jqUploader({
		uploadScript:		'../upload_file.php?PHPSESSID=<?php echo session_id();?>',
		afterScript:		'addvideo.php?step=2',
		background:			"FFFFFF",
		barColor:			"666666",
		allowedExt:     	"*.flv; *.mp4; *.wmv; *.mov; *.divx; *.avi; *.mkv; *.asf; *.wma; *.mp3; *.m4v; *.m4a; *.3gp; *.3g2",
		allowedExtDescr: 	"(*.flv,*.mp4,*.wmv,*.mov,*.divx,*.avi,*.mkv, *.asf, *.wma, *.mp3, *.m4v, *.m4a, *.3gp, *.3g2)",
		width:				430,
		height:				70,
		src:				'jquploader/jqUploader.swf',
		hideSubmit:			true,
		errorSizeMessage: 	'The FLV is too big!',
		validFileMessage: 	'now click "Step 2" to proceed',
		progressMessage:  	'Please wait, uploading ',
		endMessage:    	  	'The video has been uploaded.'
	});
});
</script>
		
<?php
	}
?>
<!--[if lt IE 7]>
<style type="text/css"  type="text/css" media="screen, projection">
	.png {
		background-image: expression(
		this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + (this.tagName==\'IMG\' ? this[\'src\'] : this.currentStyle[\'backgroundImage\'].split(\'\"\')[1]) + ")",
		this.runtimeStyle.backgroundImage = "none",
		this.src = "images/pixel.gif",
		this.width = this.style.width | this.clientWidth,
		this.height = this.style.height | this.clientHeight
		);
	}

	.pngbg {
			behavior : url(iepngfix.htc);
		}
</style><![endif]-->
	<script type="text/javascript">
		jQuery(function($){
			$(document).ready(function(){
				if(($.browser.msie)&(parseInt($.browser.version)<7)){
					$("img[src$='.png']").each(function(){$(this).addClass("png");});
					//$("span").each(function(){$(this).addClass("pngbg");});
				}
			});
		});
	</script>
<script>
// Javascript originally by Patrick Griffiths and Dan Webb.
// http://htmldog.com/articles/suckerfish/dropdowns/
sfHover = function() {
	var sfEls = document.getElementById("sub_menu").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" hover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" hover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
</script>
</head>
<body>
<div id="menu_header">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="78%">
	<h1><a href="<?php echo _URL; ?>/" target="_blank"><?php echo _SITENAME; ?></a></h1>
	<br />
	</td>
	
    <td width="22%" align="right">
	<div id="style-switcher">
		<ul>
			<li id="admin"><a href="styleme.php?style=admin"><img src="images/style_default.gif" alt="Default" width="20" height="9" border="0" /></a></li>
			<li id="admin_nite"><a href="styleme.php?style=admin_nite"><img src="images/style_nite.gif" alt="Nite" width="20" height="9" border="0" /></a></li>
			<li id="admin_sky"><a href="styleme.php?style=admin_sky"><img src="images/style_sky.gif" alt="Sky" width="20" height="9" border="0" /></a></li>
		</ul>
	</div>
	</td>
  </tr>
  <tr>
    <td colspan="2">
		<div id="menu">
		<ul>
		<?php
		if (is_moderator() || is_editor())
		{			
			$li_menu = '';
			
			// Index
			$li_menu .= '<li><a href="index.php" ';
			if ($showm == '1') 
				$li_menu .= 'class="selectedm"';
			$li_menu .= '>Home</a></li>';
			
			// Videos
			if ($mod_can['manage_videos']) 
			{
				$li_menu .= '<li><a href="videos.php" ';
				if ($showm == '2')
					$li_menu .= 'class="selectedm"';
				$li_menu .= '>Videos</a></li>';
			}
			
			// Articles
			if ($mod_can['manage_articles'] || is_editor()) 
			{
				$li_menu .= '<li><a href="articles.php" ';
				if ($showm == 'mod_article')
					$li_menu .= 'class="selectedm"';
				$li_menu .= '>Articles</a></li>';
			}
			
			// Comments
			if ($mod_can['manage_comments'])
			{
				$li_menu .= '<li><a href="comments.php" ';
				if ($showm == '4')
					$li_menu .= 'class="selectedm"';
				$li_menu .= '>Comments</a></li>';
			}
			
			// Users
			if ($mod_can['manage_users'])
			{
				$li_menu .= '<li><a href="members.php" ';
				if ($showm == '6')
					$li_menu .= 'class="selectedm"';
				$li_menu .= '>Users</a></li>';
			}
			
			// Logout
			$li_menu .= '<li><a href="'. _URL .'/login.php?do=logout">Logout</a></li>';
			
			echo $li_menu;
		}
		else
		{
		?>
		<li><a href="index.php" <?php if($showm == '1') { echo 'class="selectedm"'; } ?>>Home</a></li>
		<li><a href="videos.php" <?php if($showm == '2') { echo 'class="selectedm"'; } ?>>Videos</a></li>
		<li><a href="articles.php" <?php if($showm == 'mod_article') { echo 'class="selectedm"'; } ?>>Articles</a></li>
		<li><a href="pages.php" <?php if($showm == 'mod_pages') { echo 'class="selectedm"'; } ?>>Pages</a></li>
		<li><a href="cat_manager.php" <?php if($showm == '3') { echo 'class="selectedm"'; } ?>>Categories</a></li>
		<li><a href="comments.php" <?php if($showm == '4') { echo 'class="selectedm"'; } ?>>Comments</a></li>
		<li><a href="members.php" <?php if($showm == '6') { echo 'class="selectedm"'; } ?>>Users</a></li>
		<li><a href="ad_manager.php" <?php if($showm == '9') { echo 'class="selectedm"'; } ?>>Ad Manager</a></li>
		<li><a href="statistics.php" <?php if($showm == '7') { echo 'class="selectedm"'; } ?>>Statistics</a></li>
		<li><a href="sys_phpinfo.php" <?php if($showm == '10') { echo 'class="selectedm"'; } ?>>System</a></li>
		<li><a href="settings.php" <?php if($showm == '8') { echo 'class="selectedm"'; } ?>>Settings</a></li>
		<li><a href="<?php echo _URL; ?>/login.php?do=logout">Logout</a></li>
		<?php
		} // else
		?>
		</ul>
		</div>	</td>
    </tr>
</table>
</div>

<?php

if (is_array($restricted_access)  && in_array($showm, $restricted_access))
{
	echo '<div id="content">';
	restricted_access(true);
}
?>