<?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
*/

require("../inc/stop_cache.php");
$nAdminOnlyPg = 1;
// Secure and connect
require("../../inc/dbconnect.php");
require("../inc/secure_page.php");

// bring in other required files
require("../../inc/config.php");
require("../inc/lang.php");
include("../inc/paginator.php");
include("../inc/pageutil.php");
include("../inc/calendar.php");

$nShowPerPg = 10;

// Get passed-in vars
if(isset($_GET["pg"])){ $nPage = $_GET["pg"]; } else { $nPage = ""; }
if(!$nPage && isset($_POST["pg"])){ $nPage = $_POST["pg"]; }
if(isset($_GET["srt"])){ $nSort = $_GET["srt"]; } else { $nSort = ""; }
if(isset($_GET["ord"])){ $nSortOrder = $_GET["ord"]; } else { $nSortOrder = ""; }
if(isset($_GET["spp"])){ $nShowPerPgOverride = $_GET["spp"]; } else { $nShowPerPgOverride = ""; }
if($nShowPerPgOverride){ $nShowPerPg = $nShowPerPgOverride; }

// Setup SQL query for displayed listing
if(!$nSort){ $nSort="nAdmin"; }  // default sort
if(!$nSortOrder){ $nSortOrder="DESC"; }  // default sort order
//if($nUserID){ $nWhereARRAY[] = "nID='$nUserID'"; }

$nWhereSQL = "";
if(isset($nWhereARRAY)){ $nWhereSQL = "WHERE ".implode(" AND ",$nWhereARRAY); } else { $nWhereSQL = ""; }
$nOrderBySQL = "ORDER BY $nSort $nSortOrder";
$nListingSQL = "SELECT * From nEditor $nWhereSQL $nOrderBySQL";
?>
<div id="listContent" style="padding-top:0px;">
<?php
$nPassThru = "";
$nDivToUpdate = "ajaxUsers";
$nPageInDiv = "list/users.php";
$nCurrQueryStr = $_SERVER['QUERY_STRING'];
if($nCurrQueryStr){ $nFullPageInDiv = $nPageInDiv."?".$nCurrQueryStr; } else { $nFullPageInDiv = $nPageInDiv; }
$nPagingText = nGetPaging($nListingSQL,$nPage,$nShowPerPg,$nPassThru,$nDivToUpdate,$nPageInDiv);
if($nPassThru){ $nPassThruQry="?".$nPassThru; $nPassThru="&".$nPassThru; }
// for extrenal refresh requests
print "<script>refreshUsers = function(){ loadContent('".$nDivToUpdate."','".$nFullPageInDiv."'); }</script>";
?>

<!--[if !IE]>start section inner<![endif]-->
<div class="section_inner">
	<!--[if !IE]>start table_wrapper<![endif]-->
	<div class="table_wrapper">
		<div class="table_wrapper_inner">
		<table cellpadding="0" cellspacing="0" width="100%">
			<tbody><tr>
				<th style="width:25px;"><?php echo _("No."); ?></th>
				<?$nSortFld="nUser"; if($nSortFld==$nSort){ if($nSortOrder=="ASC"){ $nLink="?srt=$nSortFld&ord=DESC$nPassThru";$nSortClass=" class=\"asc\""; } else { $nLink="?srt=$nSortFld&ord=ASC$nPassThru";$nSortClass=" class=\"desc\""; } } else { $nLink="?srt=$nSortFld&ord=ASC$nPassThru";$nSortClass=""; }?>
				<th><a href="javascript:loadContent('<?php echo $nDivToUpdate?>','<?php echo $nPageInDiv.$nLink?>');"<?php echo $nSortClass;?>><?php echo _("Username"); ?></a></th>
				<?$nSortFld="nAdmin"; if($nSortFld==$nSort){ if($nSortOrder=="ASC"){ $nLink="?srt=$nSortFld&ord=DESC$nPassThru";$nSortClass=" class=\"asc\""; } else { $nLink="?srt=$nSortFld&ord=ASC$nPassThru";$nSortClass=" class=\"desc\""; } } else { $nLink="?srt=$nSortFld&ord=ASC$nPassThru";$nSortClass=""; }?>
				<th><a href="javascript:loadContent('<?php echo $nDivToUpdate?>','<?php echo $nPageInDiv.$nLink?>');"<?php echo $nSortClass;?>><?php echo _("Access Level"); ?></a></th>
				<?$nSortFld="nLastLoginDate"; if($nSortFld==$nSort){ if($nSortOrder=="ASC"){ $nLink="?srt=$nSortFld&ord=DESC$nPassThru";$nSortClass=" class=\"asc\""; } else { $nLink="?srt=$nSortFld&ord=ASC$nPassThru";$nSortClass=" class=\"desc\""; } } else { $nLink="?srt=$nSortFld&ord=ASC$nPassThru";$nSortClass=""; }?>
				<th><a href="javascript:loadContent('<?php echo $nDivToUpdate?>','<?php echo $nPageInDiv.$nLink?>');"<?php echo $nSortClass;?>><?php echo _("Last Login"); ?></a></th>
				<th style="width:96px;"><?php echo _("Actions"); ?></th>
			</tr>
			<?php echo nGetCustomerList();?>
		</tbody></table>
		</div>
	</div>
	<!--[if !IE]>end table_wrapper<![endif]-->
</div>
<!--[if !IE]>end section inner<![endif]-->

<?php if($nTotalPg>1){ ?>
	<!--[if !IE]>start pagination<![endif]-->
	<div class="pagination">
		<?php echo $nPagingText;?>
	</div>
	<!--[if !IE]>end pagination<![endif]-->
<?php } else {?>
	<!--[if !IE]>start pagination<![endif]-->
	<div class="pagination">
		<span class="page_no">&nbsp;</span>
	</div>
	<!--[if !IE]>end pagination<![endif]-->
<?php } ?>


<?php
function nGetCustomerList(){
	global $DBName,$Link,$nListingSQL;
	global $nShowPerPg,$nTotalRec,$nStartRec,$nEndRec,$nTotalPg;
	if(!$nListingSQL){ return ""; }
	$nCurrRec = 0;
	$nTable = "";
	$nRowClass = "";
	mysql_select_db($DBName); $Result = mysql_query($nListingSQL,$Link);
	while($Row = mysql_fetch_array($Result)){
		$nCurrRec++;
		if($nCurrRec>=$nStartRec && $nCurrRec<=$nEndRec && $nCurrRec<=$nTotalRec){
			$nID = $Row["nID"];
			$nUser = $Row["nUser"];
			$nPass = $Row["nPass"];
			$nAdmin = $Row["nAdmin"];
			if($nAdmin){ $nAdmin = "<strong>"._("Administrator")."</strong>"; } else { $nAdmin = _("Editor"); }
			$nLoginDT = $Row["nLastLoginDate"];
			$nLoginDTARRAY = explode(" ",$nLoginDT);
			if($nLoginDT){
				$nDateDiff = nGetDateDiffDays($nLoginDTARRAY[0]);
				if($nDateDiff>0){ $nLoginDT = nDateToDisplayCustom($nLoginDTARRAY[0],"m/d/y"); } else { $nLoginDT = _("Today").", ".$nLoginDTARRAY[1]; }
			} else {
				$nLoginDT = "<span class=\"caption\"><em>&lt;"._("never")."&gt;</em></span>";
			}
			if(!$nUser){ $nUser="<span class=\"caption\"><em>&lt;"._("unnamed")."&gt;</em></span>"; }
			if($nRowClass=="second"){ $nRowClass="first"; } else { $nRowClass="second"; }
			$nEditText = _("Edit");
			$nDeleteText = _("Delete");
			$nEditUserText = _("Edit User");
			$nDeleteUserText = _("Delete User");
			$nTable.= <<<CODE
			<tr id="row$nCurrRec" class="$nRowClass" onMouseOver="$('#row$nCurrRec').addClass('rowhilite');" onMouseOut="$('#row$nCurrRec').removeClass('rowhilite');">
				<td>$nCurrRec.</td>
				<td>$nUser</td>
				<td>$nAdmin</td>
				<td>$nLoginDT</td>
				<td>
					<div class="actions_menu">
						<ul>
							<li><a href="user_modify.php?usr=$nID" title="$nEditUserText" class="edit">$nEditText</a></li>
							<li><a href="dialog/user_delete.php?id=$nID" title="$nDeleteUserText" class="modal delete">$nDeleteText</a></li>
						</ul>
					</div>
				</td>
			</tr>
CODE;
		}
	}
	if(!$nTable){ $nTable = "<tr id=\"$nRowClass\"><td height=\"200\" align=\"center\" class=\"caption\" colspan=\"5\"><em>"._("No data available to display.")."</em></td></tr>"; }
	return $nTable;
}
?>
<?php require("../../inc/db_close.php"); ?>
