<?php
/*
 * This file is part of Web Pro Manager.
 * 
 * Web Pro Manager is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Web Pro Manager is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Web Pro Manager.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * @author The Web Pro Miami, Inc. <info@thewebpro.com>
 * @copyright The Web Pro Miami, Inc. <info@thewebpro.com>, http://www.thewebpro.com/
 * @license http://www.gnu.org/licenses/gpl.html GNU GPL
 * @package WebProManager
*/

if(!isset($_SESSION)){ session_start(); }

$nRequiredAtBeginOfHeadARRAY = array();
$nRequiredAtEndOfHeadARRAY = array();
$nRequiredAtBeginOfBodyARRAY = array();
$nRequiredAtEndOfBodyARRAY = array();

$nRequiredAtBeginOfHeadARRAY[] = "<script type=\"text/javascript\" src=\"{$nFullSitePath}manage/js/jquery-1.7.1.min.js\"></script>";
$nRequiredAtBeginOfHeadARRAY[] = "<script type=\"text/javascript\" src=\"{$nFullSitePath}manage/js/jquery.colorbox-min.js\"></script>";
$nRequiredAtBeginOfHeadARRAY[] = "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$nFullSitePath}manage/css/colorbox.css\">";
$nRequiredAtBeginOfHeadARRAY[] = "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$nFullSitePath}inc/default.css\">";
$nRequiredAtBeginOfHeadARRAY[] = "<link href=\"{$nFullSitePath}manage/css/form.css\" rel=\"stylesheet\" type=\"text/css\" media=\"screen\" />";
$nRequiredAtEndOfHeadARRAY[] = "<script type=\"text/javascript\" src=\"{$nFullSitePath}manage/js/jquery_processor.js\"></script>";

$ValidUser = (isset($_SESSION['ValidUser']) ? $_SESSION['ValidUser'] : NULL);
if($ValidUser) {
	$nAdminAccess = (isset($_SESSION['nAdminAccess']) ? $_SESSION['nAdminAccess'] : NULL);
	if($nAdminAccess) {
		$nUserLink = nGetUserLinkFromName($ValidUser);
		// add required tags to beginning of body
		$nRequiredAtEndOfHeadARRAY[] = "<link href=\"{$nFullSitePath}inc/editbar.css\" rel=\"stylesheet\" type=\"text/css\" media=\"screen\" />";
		$nScriptClose = "</script>";
		$nRequiredAtBeginOfBodyARRAY[] = <<<CODE
			<div id="wpmEditBar">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
				  <tr>
					<td nowrap><a href="{$nFullSitePath}manage/$nUserLink"><img src="{$nFullSitePath}images/logged_in.png" alt="" width="20" height="20" border="0" class="iconS">Logged in: $ValidUser</a>  &nbsp; | &nbsp; <a href="{$nFullSitePath}manage/process_logout.php">logout</a></td>
					<td width="100%">&nbsp;</td>
					<td nowrap><a href="{$nFullSitePath}manage/dialog/component_add.php?id=$nPageID" title="Add Component" class="modal" style="text-decoration:none"><img src="{$nFullSitePath}images/add.png" alt="" width="20" height="20" border="0" class="iconS">Add Component</a></td>
					<td nowrap><a href="{$nFullSitePath}manage/page_edit.php?id=$nPageID"><img src="{$nFullSitePath}images/edit.png" alt="" width="20" height="20" border="0" class="iconS">View page in Editor</a></td>
					<td nowrap><a href="{$nFullSitePath}manage/dialog/page_add.php?id=$nPageID" title="Page Settings" class="modal"><img src="{$nFullSitePath}images/settings.png" alt="" width="20" height="20" border="0" class="iconS">Page Settings</a></td>
				  </tr>
				</table>
				<script>
					setTimeout("$('#wpmEditBar').hide();", 1000*60*30); // hide editbar after 30 minutes of inactivity
					refreshParentsPageAdd = function(){ setTimeout("location.reload(true);", 200); }
					refreshParentsCompAdd = function(){  }
					refreshParentsCompEdit = function(){ setTimeout("location.reload(true);", 200); }
				$nScriptClose
				<style>
					.modal A:link,.modal A:visited{ color:#000; }
					.modal LABEL.caption A:link,.modal LABEL.caption A:visited{ color:#000; }
				</style>
			</div>
CODE;
	}
}

function nGetUserLinkFromName($nUserName){
	global $DBName,$Link;
	if(!$nUserName){ return; }
	$Query = "SELECT nID FROM nEditor WHERE nUser='$nUserName' LIMIT 1";
	mysql_select_db($DBName); $Result = mysql_query($Query,$Link);
	if($Row = mysql_fetch_array($Result)) {
		$nUserID = $Row["nID"];
	}
	if($nUserID){ $nUserLink = "user_edit.php?id=$nUserID"; } else { $nUserLink = ""; }
	return $nUserLink;
}
?>
