Location: PHPKode > projects > eqEpic > eqEpic0.7.8/playersdelete.php
<?php 
/******************************************************************************
* playersdelete.php                                                           *
* Delete Players File                                                         *
* See readme.txt for additional information                                   *
*******************************************************************************
* eqEpic - The Epic Raid Manager                                              *
* Open-Source Project By Ryan Christenson                                     *
* =========================================================================== *
* Software Version:           eqEpic 0.7.8                                    *
* Software by:                The RSWR Network (http://www.rswr.net)          *
* Copyright 2006-2007 by:     Ryan Christenson (http://www.rswr.net)          *
* Support, News, Updates at:  http://forum.rswr.net/                          *
*******************************************************************************
* This program 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 2 of the License, or           *
* (at your option) any later version.                                         *
*                                                                             *
* This program 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 DownloadCounter; if not, write to the Free Software              *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   *
******************************************************************************/
session_start();
ob_start();
?>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
<?php include ("ewconfig.php") ?>
<?php include ("db.php") ?>
<?php include ("playersinfo.php") ?>
<?php include ("advsecu.php") ?>
<?php include ("phpmkrfn.php") ?>
<?php
if (!IsLoggedIn() && (@$_COOKIE[ewCookieAutoLogin] == "autologin" && @$_COOKIE[ewCookiePassword] <> "")) {
	ob_end_clean();
	header("Location: login.php");
	exit();
}
LoadUserLevel();
$ewCurSec = (IsLoggedIn())? CurrentUserLevelPriv("players") : GetAnonymousPriv("players");	
if (($ewCurSec & ewAllowDelete) <> ewAllowDelete) {
	ob_end_clean();
	header("Location: playerslist.php");
	exit();
}
if (IsLoggedIn() && CurrentUserID() == "") {
	ob_end_clean();
	header("Location: login.php");
	exit();
}
?>
<?php

// Initialize common variables
$x_name = NULL;
$ox_name = NULL;
$z_name = NULL;
$ar_x_name = NULL;
$ari_x_name = NULL;
$x_nameList = NULL;
$x_nameChk = NULL;
$cbo_x_name_js = NULL;
$x_class = NULL;
$ox_class = NULL;
$z_class = NULL;
$ar_x_class = NULL;
$ari_x_class = NULL;
$x_classList = NULL;
$x_classChk = NULL;
$cbo_x_class_js = NULL;
$x_steps = NULL;
$ox_steps = NULL;
$z_steps = NULL;
$ar_x_steps = NULL;
$ari_x_steps = NULL;
$x_stepsList = NULL;
$x_stepsChk = NULL;
$cbo_x_steps_js = NULL;
$x_level = NULL;
$ox_level = NULL;
$z_level = NULL;
$ar_x_level = NULL;
$ari_x_level = NULL;
$x_levelList = NULL;
$x_levelChk = NULL;
$cbo_x_level_js = NULL;
$x_orb = NULL;
$ox_orb = NULL;
$z_orb = NULL;
$ar_x_orb = NULL;
$ari_x_orb = NULL;
$x_orbList = NULL;
$x_orbChk = NULL;
$cbo_x_orb_js = NULL;
$x_scheduled = NULL;
$ox_scheduled = NULL;
$z_scheduled = NULL;
$ar_x_scheduled = NULL;
$ari_x_scheduled = NULL;
$x_scheduledList = NULL;
$x_scheduledChk = NULL;
$cbo_x_scheduled_js = NULL;
?>
<?php
$arRecKey = NULL;

// Load key parameters
$sKey = "";
$bSingleDelete = true;
$x_name = @$_GET["name"];
if (($x_name == "") || (is_null($x_name))) {
	$bSingleDelete = false;
} else {
	if ($sKey <> "") $sKey .= ",";
	$sKey .= $x_name;
}
if (!$bSingleDelete) $sKey = @$_POST["key_d"];
if (!is_array($sKey)) {
 if (strlen($sKey) > 0) $arRecKey = split(",", $sKey);
} else {
 $sKey = implode(",", $sKey);
 $arRecKey = split(",", $sKey);
}
if (count($arRecKey) <= 0) {
	ob_end_clean();
	header("Location: playerslist.php");
	exit();
}
$sKey = implode(",", $arRecKey);
$i = 0;
$sDbWhere = "";
while ($i < count($arRecKey)) {
	$sDbWhere .= "(";

	// Remove spaces
	$sRecKey = trim($arRecKey[$i+0]);
	$sRecKey = (!get_magic_quotes_gpc()) ? addslashes($sRecKey) : $sRecKey ;

	// Build the SQL
	$sDbWhere .= "`name`='" . $sRecKey . "' AND ";
	if (substr($sDbWhere, -5) == " AND ") { $sDbWhere = substr($sDbWhere, 0, strlen($sDbWhere)-5) . ") OR "; }
	$i += 1;
}
if (substr($sDbWhere, -4) == " OR ") { $sDbWhere = substr($sDbWhere, 0 , strlen($sDbWhere)-4); }

// Get action
$sAction = @$_POST["a_delete"];
if (($sAction == "") || ((is_null($sAction)))) {
	$sAction = "I";	// Display record
}
$conn = phpmkr_db_connect(HOST, USER, PASS, DB, PORT);
switch ($sAction) {
	case "I": // Display
		if (LoadRecordCount($sDbWhere,$conn) <= 0) {
			phpmkr_db_close($conn);
			ob_end_clean();
			header("Location: playerslist.php");
			exit();
		}
		break;
	case "D": // Delete
		if (DeleteData($sDbWhere,$conn)) {
			$_SESSION[ewSessionMessage] = "Player Deleted Successfully";
			phpmkr_db_close($conn);
			ob_end_clean();
			header("Location: playerslist.php");
			exit();
		}
		break;
}
?>
<?php include ("sources/header.php") ?>
<p><span class="ewmsg">Confirm Deletion</span></p>
<form action="playersdelete.php" method="post">
<p>
<input type="hidden" name="a_delete" value="D" />
<?php $sKey = (get_magic_quotes_gpc()) ? stripslashes($sKey) : $sKey; ?>
<input type="hidden" name="key_d" value="<?php echo htmlspecialchars($sKey); ?>" />
<table class="ewTable">
	<tr class="ewTableHeader">
		<td valign="top">Name</td>
		<td valign="top">Class</td>
		<td valign="top">Progress</td>
		<td valign="top">Level</td>
		<td valign="top">Has Anguish Orb?</td>
		<td valign="top">Scheduled For</td>
	</tr>
<?php
$nRecCount = 0;
$i = 0;
while ($i < count($arRecKey)) {
	$nRecCount++;

	// Set row color
	$sItemRowClass = " class=\"ewTableRow\"";

	// Display alternate color for rows
	if ($nRecCount % 2 <> 0) {
		$sItemRowClass = " class=\"ewTableAltRow\"";
	}
	$sRecKey = trim($arRecKey[$i+0]);
	$sRecKey = (get_magic_quotes_gpc()) ? stripslashes($sRecKey) : $sRecKey;
	$x_name = $sRecKey;
	if (LoadData($conn)) {
?>
	<tr<?php echo $sItemRowClass;?>>
		<td>
<?php echo $x_name; ?>
		</td>
		<td>
<?php
if ((!is_null($x_class)) && ($x_class <> "")) {
	$sSqlWrk = "SELECT `class` FROM `class`";
	$sTmp = $x_class;
	$sTmp = addslashes($sTmp);
	$sSqlWrk .= " WHERE `id` = " . $sTmp . "";
	$sSqlWrk .= " ORDER BY `class` Asc";
	$rswrk = phpmkr_query($sSqlWrk,$conn) or die("Failed to execute query at line " . __LINE__ . ": " . phpmkr_error($conn) . '<br />SQL:' . $sSqlWrk);
	if ($rswrk && $rowwrk = phpmkr_fetch_array($rswrk)) {
		$sTmp = $rowwrk["class"];
	}
	@phpmkr_free_result($rswrk);
} else {
	$sTmp = "";
}
$ox_class = $x_class; // Backup original value
$x_class = $sTmp;
?>
<?php echo $x_class; ?>
<?php $x_class = $ox_class; // Restore original value ?>
</td>
		<td>
<?php
if ((!is_null($x_steps)) && ($x_steps <> "")) {
	$sSqlWrk = "SELECT `step` FROM `steps`";
	$sTmp = $x_steps;
	$sTmp = addslashes($sTmp);
	$sSqlWrk .= " WHERE `id` = " . $sTmp . "";
	$sSqlWrk .= " ORDER BY `step` Asc";
	$rswrk = phpmkr_query($sSqlWrk,$conn) or die("Failed to execute query at line " . __LINE__ . ": " . phpmkr_error($conn) . '<br />SQL:' . $sSqlWrk);
	if ($rswrk && $rowwrk = phpmkr_fetch_array($rswrk)) {
		$sTmp = $rowwrk["step"];
	}
	@phpmkr_free_result($rswrk);
} else {
	$sTmp = "";
}
$ox_steps = $x_steps; // Backup original value
$x_steps = $sTmp;
?>
<?php echo $x_steps; ?>
<?php $x_steps = $ox_steps; // Restore original value ?>
</td>
		<td>
<?php echo $x_level; ?>
</td>
		<td>
<?php
switch ($x_orb) {
	case "Yes":
		$sTmp = "Yes";
		break;
	case "No":
		$sTmp = "No";
		break;
	default:
		$sTmp = "";
}
$ox_orb = $x_orb; // Backup original value
$x_orb = $sTmp;
?>
<?php echo $x_orb; ?>
<?php $x_orb = $ox_orb; // Restore original value ?>
</td>
		<td>
<?php echo FormatDateTime($x_scheduled,5); ?>
</td>
	</tr>
<?php
	}
	$i += 1;
}
?>
</table>
<p>
<input type="submit" name="Action" value="Confirm Deletion" class="button" />
</form>
<?php include ("footer.php") ?>
<?php

//-------------------------------------------------------------------------------
// Function LoadData
// - Variables setup: field variables

function LoadData($conn)
{
	global $x_name;
	$sFilter = ewSqlKeyWhere;
	$x_name =  (get_magic_quotes_gpc()) ? stripslashes($x_name) : $x_name;
	$sFilter = str_replace("@name", AdjustSql($x_name), $sFilter); // Replace key value
	if ((CurrentUserID() <> "-1") && (CurrentUserID() <> "")) {

	//$sFilter .= " AND " . str_replace("#UserID", AdjustSql(CurrentuserID()), ewSqlUserIDFilter);
	$sFilter .= " AND " . ewSqlUserIDFilter;
	$sFilter = str_replace("#Key", "`name`", $sFilter);
	$sFilter = str_replace("#UserID", AdjustSql(CurrentUserID()), $sFilter);
	}
	$sSql = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, $sFilter, "");
	$rs = phpmkr_query($sSql,$conn) or die("Failed to execute query at line " . __LINE__ . ": " . phpmkr_error($conn) . '<br />SQL: ' . $sSql);
	if (phpmkr_num_rows($rs) == 0) {
		$bLoadData = false;
	} else {
		$bLoadData = true;
		$row = phpmkr_fetch_array($rs);

		// Get the field contents
		$GLOBALS["x_name"] = $row["name"];
		$GLOBALS["x_class"] = $row["class"];
		$GLOBALS["x_steps"] = $row["steps"];
		$GLOBALS["x_level"] = $row["level"];
		$GLOBALS["x_orb"] = $row["orb"];
		$GLOBALS["x_scheduled"] = $row["scheduled"];
	}
	phpmkr_free_result($rs);
	return $bLoadData;
}
?>
<?php

//-------------------------------------------------------------------------------
// Function LoadRecordCount
// - Load Record Count based on input sql criteria sqlKey

function LoadRecordCount($sqlKey, $conn)
{
	global $x_name;
	$sFilter = $sqlKey;
	if ((CurrentUserID() <> -1) && (CurrentUserID() <> "")) { // Non system admin

		//$sFilter .= " AND " . str_replace("#UserID", AdjustSql(CurrentUserID()), ewSqlUserIDFilter);
		$sFilter .= " AND " . ewSqlUserIDFilter;
		$sFilter = str_replace("#Key", "`name`", $sFilter);
		$sFilter = str_replace("#UserID", AdjustSql(CurrentUserID()), $sFilter);
	}
	$sSql = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, $sFilter, "");	
	$rs = phpmkr_query($sSql,$conn) or die("Failed to execute query at line " . __LINE__ . ": " . phpmkr_error($conn) . '<br />SQL: ' . $sSql);
	return phpmkr_num_rows($rs);
	phpmkr_free_result($rs);
}

//-------------------------------------------------------------------------------
// Function DeleteData
// - Delete Records based on input sql criteria sqlKey

function DeleteData($sqlKey, $conn)
{
	global $x_name;
	$sFilter = $sqlKey;
	if ((CurrentUserID() <> "-1") && (CurrentUserID() <> "")) { // Non system admin

	//$sFilter .= " AND " . str_replace("#UserID", AdjustSql(CurrentUserID()), ewSqlUserIDFilter);
	$sFilter .= " AND " . ewSqlUserIDFilter;
	$sFilter = str_replace("#Key", "`name`", $sFilter);
	$sFilter = str_replace("#UserID", AdjustSql(CurrentUserID()), $sFilter);
	}

	// Backup the record before delete
	$sSql = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, $sFilter, "");
	$query = phpmkr_query($sSql,$conn) or die("Failed to execute query at line " . __LINE__ . ": " . phpmkr_error($conn) . '<br />SQL: ' . $sSql);
	while ($temp = phpmkr_fetch_array($query)) {
		$oldrs[] = $temp;
	}

	// Delete
	$sSql = "DELETE FROM `players`";
	$sWhere = "";
	if ($sFilter <> "") {
		if ($sWhere <> "") $sWhere .= " AND ";
		$sWhere .= $sFilter;
	}
	if ($sWhere <> "") {
		$sSql .= " WHERE " . $sWhere;
	}

	// Deleting event
	if (Recordset_Deleting($oldrs)) {
		phpmkr_query($sSql,$conn) or die("Failed to execute query at line " . __LINE__ . ": " . phpmkr_error($conn) . '<br />SQL: ' . $sSql);
		$result = (phpmkr_affected_rows($conn) > 0);

		// Deleted event
		if ($result) Recordset_Deleted($oldrs);
	} else {
		$result = false;
	}
	return $result;
}

// Deleting event
function Recordset_Deleting($oldrs)
{

	// Enter your customized codes here
	return true;
}

// Deleted event
function Recordset_Deleted($oldrs)
{
	$table = "players";
}
?>
Return current item: eqEpic