Location: PHPKode > projects > PhpBlock > A9.8/modules/dungeon/alliance/alliance.php
<?php
include_once "../../../site.class.php";
include_once $PATH_TO_CODE."/script/connect.php";
include_once $PATH_TO_CODE."/script/disconnect.php";
include_once $PATH_TO_CODE."/script/fonction.php";
include_once $PATH_TO_CODE."/script/message/playermessage.class.php";
include_once $PATH_TO_CODE."/modules/dungeon/objectmanager.class.php";

getSessionPlayerId($locPlayerId);
global $gloObjectManager;
$locPlayer = $gloObjectManager->getPlayer($locPlayerId);
$locAlliance = $locPlayer->getAlliance();
$locAllianceId = $locAlliance->allianceId;
$locAllianceLeader = $locAlliance->getLeader();

$locIsLeavingCurrentAlliance=getGetPostTrueFalse("leaveCurrentAlliance");
if($locIsLeavingCurrentAlliance) {
	if($locAllianceId == $locPlayerId) {
		echo "You can't leave your native alliance";
	} else {
		$locAlliance->rejectPlayer($locPlayerId);
		PlayerMessage::addPlayerMessage($locPlayerId, $locAlliance->leaderId, 
			"".$locPlayer->playerName." leave the alliance");
		echo "You leave your current alliance";
		disconnect();
	}
	exit(0);
}

$locJoinAllianceId = getGetPostWithNoEmpty("joinAllianceId", 0);
if($locJoinAllianceId > 0) {
	$locTargetAlliance = Alliance::getAlliance($locJoinAllianceId);
	if($locTargetAlliance) {
		if($locJoinAllianceId == $locAllianceId) {
			echo "You can't ask to join your own alliance";
		} else {
			$locTargetAlliance->playerAskToJoin($locPlayerId);
			echo "You ask to join the alliance '".$locTargetAlliance->getName()."'";
			disconnect();
		}
	} else {
		echo "'$locJoinAllianceId' didn't exist";
	}
	exit(0);
}

$locRemoveAskToJoinAllianceId = getGetPostWithNoEmpty("removeAskingToAllianceId", 0);
if($locRemoveAskToJoinAllianceId > 0) {
	$locTargetAlliance = Alliance::getAlliance($locRemoveAskToJoinAllianceId);
	if($locTargetAlliance) {
		$locTargetAlliance->playerRemoveAskToJoin($locPlayerId);
		echo "You remove your request to join the alliance '".$locTargetAlliance->getName()."'";
		disconnect();
	} else {
		echo "'$locJoinAllianceId' didn't exist";
	}
	exit(0);
}
$locAcceptAskingFromPlayerId = getGetPostWithNoEmpty("acceptAskingFromPlayerId", 0);
if($locAcceptAskingFromPlayerId > 0) {
	if($locAlliance->getLeader()->playerId == $locPlayerId) {
		if($locAlliance->isAskingToJoin($locAcceptAskingFromPlayerId)) {
			$locAlliance->acceptPlayer($locAcceptAskingFromPlayerId);
			echo "player $locAcceptAskingFromPlayerId is accepted";
			disconnect();
		} else {
			echo "Player have no request on your alliance";
		}
	} else {
		echo "You are not the leader of this alliance";
	}
	exit(0);
}
$locRejectAskingFromPlayerId = getGetPostWithNoEmpty("rejectAskingFromPlayerId", 0);
if($locRejectAskingFromPlayerId > 0) {
	if($locAlliance->getLeader()->playerId == $locPlayerId) {
		if($locAlliance->isAskingToJoin($locRejectAskingFromPlayerId)) {
			$locAlliance->playerRemoveAskToJoin($locRejectAskingFromPlayerId);
			echo "player won't join this alliance";
			disconnect();
		} else {
			echo "Player have no request on your alliance";
		}
	} else {
		echo "You are not the leader of this alliance";
	}
	exit(0);
}

$locFirePlayerId = getGetPostWithNoEmpty("firePlayerId", 0);
if($locFirePlayerId > 0) {
	if($locAlliance->getLeader()->playerId == $locPlayerId) {
		if($locFirePlayerId == $locPlayerId) {
			echo "You can't fire yourself";
		} else {
			$locAlliance->rejectPlayer($locFirePlayerId);
			PlayerMessage::addPlayerMessage($locPlayerId, $locFirePlayerId, 
				"You are fire from the alliance");
			disconnect();
			echo "Player is fire";
		}
	} else {
		echo "You are not the leader of this alliance";
	}
	exit(0);
}

echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<script language="javascript">
function leaveCurrentAlliance() {
        $.post("modules/dungeon/alliance/alliance.php",
        { leaveCurrentAlliance: "true"},
        function(data){
            addPlayerInfo(data);
    		refreshPanelContentWithURL("#alliancePanelInnerContent");            
        } );
}
function joinAlliance(parAllianceId) {
        $.post("modules/dungeon/alliance/alliance.php",
        { joinAllianceId: parAllianceId},
        function(data){
            addPlayerInfo(data);
    		refreshPanelContentWithURL("#alliancePanelInnerContent");            
        } );
}
function removeAskingToAlliance(parAllianceId) {
        $.post("modules/dungeon/alliance/alliance.php",
        { removeAskingToAllianceId: parAllianceId},
        function(data){
            addPlayerInfo(data);
    		refreshPanelContentWithURL("#alliancePanelInnerContent");            
        } );
}
function acceptPlayerInAlliance(parPlayerId) {
        $.post("modules/dungeon/alliance/alliance.php",
        { acceptAskingFromPlayerId: parPlayerId},
        function(data){
            addPlayerInfo(data);
    		refreshPanelContentWithURL("#alliancePanelInnerContent");            
        } );
}
function rejectPlayerInAlliance(parPlayerId) {
        $.post("modules/dungeon/alliance/alliance.php",
        { rejectAskingFromPlayerId: parPlayerId},
        function(data){
            addPlayerInfo(data);
    		refreshPanelContentWithURL("#alliancePanelInnerContent");            
        } );
}
function firePlayerInAlliance(parPlayerId) {
        $.post("modules/dungeon/alliance/alliance.php",
        { firePlayerId: parPlayerId},
        function(data){
            addPlayerInfo(data);
    		refreshPanelContentWithURL("#alliancePanelInnerContent");            
        } );
}
</script>
<body>
<?php
echo "<p>";
if($locAllianceLeader->playerId == $locPlayerId) {
	echo "You are the chief of ".$locAlliance->getName();
} else {
	echo "<p>Your alliance is ".$locAlliance->getName().", the leader is '".$locAllianceLeader->playerName."'";
?>
<form method="post" onSubmit="leaveCurrentAlliance(); return false;">
	<input type="submit" value="Leave current alliance" />
</form>
<?php
}
echo "</p>";

$locPlayersAskingJoin = $locAlliance->getAllPlayersAskingJoin();
if(count($locPlayersAskingJoin) > 0) {
	echo "<p>Players which request to join your alliance";
	echo "<ul>";
	foreach($locPlayersAskingJoin as $locPlayerAsking) {
		echo "<li>".$locPlayerAsking->playerName;
		if($locAlliance->getLeader()->playerId == $locPlayerId) {
?>
<input onclick="acceptPlayerInAlliance(<?php echo $locPlayerAsking->playerId;?>)" type='submit' value='Accept'/>
<input onclick="rejectPlayerInAlliance(<?php echo $locPlayerAsking->playerId;?>)" type='submit' value='Reject'/>
<?php
		}
	}
	echo "</ul></p>";
}

echo "<p>Players in the alliance ";
echo "<ul>";
$locAlliancePlayers = $locAlliance->getAllPlayers();
foreach($locAlliancePlayers as $locAlliancePlayer) {
	echo "<li>";
	if($locAllianceLeader->playerId == $locPlayerId
		&& $locAlliancePlayer->playerId != $locPlayerId) {
?>
<input onclick="firePlayerInAlliance(<?php echo $locAlliancePlayer->playerId;?>)" type='submit' value='Fire <?php echo $locAlliancePlayer->playerName?>'/>
<?php
	} else {
		echo $locAlliancePlayer->playerName;
	}
}
echo "</ul></p>";

if($locAllianceLeader->playerId == $locPlayerId) {
echo "<p>Ask to Join alliance ";
?>
<form onsubmit="joinAlliance($('#joinTargetAllianceId').val());return false;" method="post" >
	<input type="submit" value="Join the alliance"/>
	<select id='joinTargetAllianceId'>
<?php
$res = executer("SELECT allianceId 
	FROM alliance 
	WHERE allianceId<>$locAllianceId 
	AND leaderId != 0");
while($row = mysql_fetch_array($res)) {
	$locOtherAllianceId = $row[0];
	$locOtherAlliance = Alliance::getAlliance($locOtherAllianceId);
	echo "<option value='$locOtherAllianceId'>";
	echo $locOtherAlliance->getName();	
}
?>
</select>
</form>
<?php
}
$locAllianceAsking = Alliance::getAllAlliancesWithAsk($locPlayerId);
if(count($locAllianceAsking) > 0) {
echo "<p>You're asking ";
foreach ($locAllianceAsking as $locA) {
?>
<form onsubmit="removeAskingToAlliance(<?php echo $locA->allianceId?>);return false;" method="post" >
	<input type="submit" value="Remove your request on the alliance <?php echo $locA->getName();?>"/>
</form>
<?php
}
} else {
	echo "<p>You have no request to join an alliance";
}
?>
</p>
</body>
</html>
Return current item: PhpBlock