Jump to content

Recommended Posts

If you look on the index.php page you'll see that a session is created or not and if its not then the user is taken to the login form. If there is a session then that means the user is logged in and after logging it the user is taken to that index page and gets the Session data that was created upon logging in.  Two of that data is the user's default character. Which is the ID of that character and that character's name. That index page includes the header.php file which includes the dropdown part. It runs some queries and right below the select tag it uses that defaultCharID and defaultCharacterName to list first that character. After the user selects a new characater it should replace the top character with the selection which includes the characater id and the character's name.

 

index.php

<?php

session_start(); // Access the existing session

if (!isset($_SESSION['userID']) || empty($_SESSION['userID'])) {

Header('Location: login.php');
exit();
} 

// Include the database page
include ('inc/dbconfig.php');

// Include the variables page
include ('inc/variables.php');

$userID = $_SESSION['userID'];
$isAdmin = $_SESSION['isAdmin'];
$defaultCharID = $_SESSION['defaultCharID'];
$defaultCharacterName = $_SESSION['defaultCharacterName'];
$firstName = $_SESSION['firstName'];
$lastName = $_SESSION['lastName'];

?>

<?php include ('inc/header.php'); ?>

<!-- Global -->
<div id="page-content">
<div class="container content">

        <?php include ('inc/sidebar.php'); ?>
        
        <?php include ('inc/content.php'); ?>
        
</div>
</div>

<?php include ('inc/footer.php'); ?>

 

 

header.php

<script>
$(document).ready(function() {
$('#newDefaultCharID').change(function() {
        $('#ChangeDefaultCharacter').submit(); 
});
});
</script>

<?php
        if ((isset($userID)) && ($userID > "0")) {
        ?> 
            <div id="headerCharacter">   
        <?php
            if ($isAdmin == "Yes") {
    			$query = "SELECT
    					characters.ID
    				FROM
    					characters"; 
    			$result = mysqli_query ($dbc,$query); 
    			$totalNumCharacters = mysqli_num_rows($result);
    	
    			$query = "SELECT
    					handlerCharacters.ID
    				FROM
    					handlerCharacters
    				INNER JOIN
    					handlers
    				    ON handlers.ID = handlerCharacters.handlerID"; 
    		} else {	
    			$query = "SELECT
    					handlerCharacters.id
    				FROM
    					handlerCharacters
    				INNER JOIN
    					handlers
    				    ON handlers.ID = handlerCharacters.handlerID
    				WHERE
    					handlers.ID = '".$userID."'"; 
    		}
    		$result = mysqli_query ($dbc,$query);
    		$numAvailableCharacters = mysqli_num_rows($result);
            if (($numAvailableCharacters > "1") || (($isAdmin == "Yes") && (isset($totalNumCharacters)) && ($totalNumCharacters > "0"))) {
            ?>
    			<form method="POST" id="ChangeDefaultCharacter">
                <select class="dropdown" name="newDefaultCharID" id="newDefaultCharID" title="Select Character">                
            <?php
    
    			if ($defaultCharID > "0") {
    				print "<option value=".$defaultCharID.">".$defaultCharacterName;
    			} else {
    				print "<option value=0>- Select -";
    			}
                if ($isAdmin == "Yes") {
    				$query = "SELECT
    						characters.ID,
    						characters.characterName
    					FROM
    						characters
    					WHERE
    						characters.ID <> '".$defaultCharID."' AND
    						characters.statusID = '1'
    					ORDER BY
    						characters.characterName"; 
    			} else {
    				$query = "SELECT
    						characters.ID,
    						characters.characterName
    					FROM
    						characters
    					INNER JOIN
    					    handlerCharacters
    					    ON characters.ID = handlerCharacters.characterID						
    					INNER JOIN
    						handlers
    					    ON handlers.ID = handlerCharacters.handlerID
    					WHERE
    						handlers.ID = '".$userID."' AND
    						handlerCharacters.characterID <> '".$defaultCharID."' AND
    						characters.statusID = '1'
    					ORDER BY
    						characters.characterName"; 
    			}
    			$result = mysqli_query ($dbc,$query);
    			$numRows = mysqli_num_rows ($result);
    			if ($numRows > 0) {
    				if ($isAdmin == "Yes") {
    					print "<optgroup label=\"** Active Characters **\">";
    				}
                    while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) {
    					print "<option value=\"".$row['ID']."\">".$row['characterName']."</option>\r";
    				}
    			}
                if ($isAdmin == "Yes") {
    				$query = "SELECT
    						characters.ID,
    						characters.characterName
    					FROM
    						characters
    					WHERE
    						characters.ID <> '".$defaultCharID."' AND
    						characters.statusID = '2'
    					ORDER BY
    						characters.characterName"; 
    			} else {
    				$query = "SELECT
    						characters.ID,
    						characters.characterName
    					FROM
    						characters
    					LEFT JOIN
    						handlerCharacters
    					    ON characters.ID = handlerCharacters.characterID						
    					LEFT JOIN
    						handlers
    					    ON handlers.ID = handlerCharacters.handlerID
                        WHERE
    						handlers.ID = '".$userID."' AND
    						handlerCharacters.characterID <> '".$defaultCharID."' AND
    						characters.statusID = '2'
    					ORDER BY
    						characters.characterName"; 
    			}
    			$result = mysqli_query ($dbc,$query); 
    			$numRows = mysqli_num_rows($result);
    			if ($numRows > "0") {
    				print "<optgroup label=\"** Inactive Characters **\">";	
    				while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) {
    				    print "<option value=\"".$row['ID']."\">".$row['characterName']."</option>\r";    
    				}
    			}
                ?>
    			</select>
                </form> 
            <?php
    		} else {
    			print "<h1>".$defaultCharacterName."</h1>\n";
    		}
            ?>
            </div>
        <?php          
        }
        ?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.