Divida la página PHP en varias pestañas/páginas

Currently I have a large page that is displayed when the user logs in and is an admin. This page has gotten very large and I want to split it across many pages (one function on each page) or across a tabbed menu. Either way I am trying to work out a way for there to be a menu across the top and when the user presses a menu item it displays that items

The files involved:

login Index.php - handles if the user has logged in:

<?php
if (version_compare(PHP_VERSION, '5.3.7', '<')) {
    exit("Sorry, Simple PHP Login does not run on a PHP version smaller than 5.3.7 !");
} else if (version_compare(PHP_VERSION, '5.5.0', '<')) {
    require_once("libraries/password_compatibility_library.php");
}

require_once("config/db.php");

require_once("classes/Login.php");

$login = new Login();

if ($login->isUserLoggedIn() == true) {
    include("views/logged_in.php");

} else {
    include("views/not_logged_in.php");
} 

logged_in.php decides to display either the admin view or the user view:

 <?php 
    if ($_SESSION['user_admin'] == 0) {
        include("views/user.php");
    }
    if ($_SESSION['user_admin'] == 1) {
        include("views/admin.php");
    }

?>

And then the admin.php which I need to split across pages or tabs, their is also a php class in the file but this will be moved out to its own file anyway.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

<title>Admin Page</title>
<script type="text/javascript" src="../jquery.js"></script>
<script type='text/javascript' src='../jquery.autocomplete.js'></script>
<link rel="stylesheet" type="text/css" href="../jquery.autocomplete.css" />

<script type="text/javascript">
$(document).ready(function(){
    $("#html-form").submit(function() {
        //Do the AJAX post
        $.post($("#log").attr("action"), $("#log").serialize(), function(data){
            //do stuff here...
        });
        //Important. Stop the normal POST
        return false;
    });
});
</script>

<script type="text/javascript">
$(document).ready(function(){
    $("#html-form").submit(function() {
        //Do the AJAX post
        $.post($("#tables").attr("action"), $("#tables").serialize(), function(data){
            //do stuff here...
        });
        //Important. Stop the normal POST
        return false;
    });
});
</script>

<script type="text/javascript">
$(document).ready(function(){
    $("#html-form").submit(function() {
        //Do the AJAX post
        $.post($("#createtable").attr("action"), $("#createtable").serialize(), function(data){
            //do stuff here...
        });
        //Important. Stop the normal POST
        return false;
    });
});
</script>

<script type="text/javascript">
$(document).ready(function(){
    $("#html-form").submit(function() {
        //Do the AJAX post
        $.post($("#deletetable").attr("action"), $("#deletetable").serialize(), function(data){
            //do stuff here...
        });
        //Important. Stop the normal POST
        return false;
    });
});
</script>

<script type="text/javascript">
$(document).ready(function(){
    $("#html-form").submit(function() {
        //Do the AJAX post
        $.post($("#unassign").attr("action"), $("#unassign").serialize(), function(data){
            //do stuff here...
        });
        //Important. Stop the normal POST
        return false;
    });
});
</script>

<script type="text/javascript">
$(document).ready(function(){
    $("#html-form").submit(function() {
        //Do the AJAX post
        $.post($("#edittable").attr("action"), $("#edittable").serialize(), function(data){
            //do stuff here...
        });
        //Important. Stop the normal POST
        return false;
    });
});
</script>

<script type="text/javascript">
$(document).ready(function(){
    $("#html-form").submit(function() {
        //Do the AJAX post
        $.post($("#save_edit").attr("action"), $("#save_edit").serialize(), function(data){
            //do stuff here...
        });
        //Important. Stop the normal POST
        return false;
    });
});
</script>
</head>
<body>
<?php
// show negative messages
if ($registration->errors) {
    foreach ($registration->errors as $error) {
        echo $error;    
    }
}
// show positive messages
if ($registration->messages) {
    foreach ($registration->messages as $message) {
        echo $message;
    }
}
?>   
<a href="index.php?logout">Logout</a>
<div id="content">
<h2>Create Username</h2>
<br/>
<form method="post" action="register.php" name="registerform">   

    <!-- the user name input field uses a HTML5 pattern check -->
    <label for="login_input_username">Username (only letters and numbers, 2 to 64 characters)</label>
    <input id="login_input_username" class="login_input" type="text" pattern="[a-zA-Z0-9]{2,64}" name="user_name" required />
    <br/>
    <!-- the email input field uses a HTML5 email type check -->
    <label for="login_input_email">User's email</label>    
    <input id="login_input_email" class="login_input" type="email" name="user_email" required />        
    <br/>
    <label for="login_input_password_new">Password (min. 6 characters)</label>
    <input id="login_input_password_new" class="login_input" type="password" name="user_password_new" pattern=".{6,}" required autocomplete="off" />  
    <br/>
    <label for="login_input_password_repeat">Repeat password</label>
    <input id="login_input_password_repeat" class="login_input" type="password" name="user_password_repeat" pattern=".{6,}" required autocomplete="off" />        
    <input type="submit"  name="register" value="Register" />

</form>
<h2>View Search Logs</h2>
<br/>
<form name="log" action="?page=log" method="POST" autocomplete="off">
    <input type=submit value="View Logs">
</form>
<?php
if($page == "log"){
     $log->viewall();
}
?> 
<br/>
<h2>Assign Values Table</h2>
<br/>
<form name="tables" action="?page=tables" method="POST" autocomplete="off">
    <input type=submit value="View Tables/Users">
</form>
<?php
if($page == "tables"){
     $log->viewtables();
}

if($page == "deletetable"){
    while( list( $field, $value ) = each( $_POST )) {
        $tablename = $field;
    }
    $log->deletetables($tablename);
}

if($page == "assign"){
    $username = $_POST['user'];
    $tablename = array_search('Assign', $_POST);
    $log->assigntable($username, $tablename);
}

if($page == "unassign"){
    while( list( $field, $value ) = each( $_POST )) {
        $tablename = $field;
    }
    $log->unassign($tablename);
}
?> 
<br/>
<h2>Edit Values Table</h2>
<br/>
<form name="edittable" action="?page=edittable" method="POST" autocomplete="off">
    <select name="user">
        <?php 
        $con=mysqli_connect("localhost","*****","*****","*****");
        $sql = mysqli_query($con,"SHOW TABLES LIKE 'rates_%'");
         while ($row1 = mysqli_fetch_array($sql)){
              echo "<option value=\"".$row1[0]. "\">" . $row1[0] . "</option>";
         }
         ?>
    </select>
    <input type=submit value="Select Table">
</form>
<?php
if($page == "edittable"){
    $tablename = $_POST['user'];
    $log->edittable($tablename);
}

if($page == "save_edit"){
    $tablename = $_POST['tablename'];
    $numrows = $_POST['rows'];
    $valuearray = array();
    $i = 1;
    while ($i <= $numrows){
        array_push($valuearray, array($_POST['value1'.$i], $_POST['value2'.$i], $_POST['value3'.$i], $_POST['value4'.$i], $_POST['value5'.$i], $_POST['value6'.$i], $_POST['value7'.$i],
                $_POST['value8'.$i], $_POST['value9'.$i] ,$_POST['value10'.$i], $_POST['value11'.$i], $_POST['value12'.$i], $_POST['value13'.$i], $_POST['value14'.$i], $_POST['value15'.$i],
                $_POST['value16'.$i], $_POST['value17'.$i], $_POST['value18'.$i], $_POST['value19'.$i], $_POST['value20'.$i], $_POST['value21'.$i], $_POST['value22'.$i], $_POST['value23'.$i], $_POST['value24'.$i],
                $_POST['value25'.$i], $_POST['value26'.$i] ,$_POST['value27'.$i], $_POST['value28'.$i], $_POST['value29'.$i], $_POST['value30'.$i]));
        $i++;
    } 
    $log->saveedit($tablename, $numrows, $valuearray);
}
?> 
<br/>
<h2>Create Values Table</h2>
<br/>
<?php $rows = array(
        array('weight' => 1000, 'cbm_min' => 0.1, 'cbm_max' => 2.3 ),
        array('weight' => 1500, 'cbm_min' => 2.31, 'cbm_max' => 3.5 ),
        array('weight' => 2000, 'cbm_min' => 3.51, 'cbm_max' => 4.6 ),
        array('weight' => 2500, 'cbm_min' => 4.61, 'cbm_max' => 5.75 ),
        array('weight' => 3000, 'cbm_min' => 5.75, 'cbm_max' => 6.9 ),
        array('weight' => 3500, 'cbm_min' => 6.91, 'cbm_max' => 8 ),
        array('weight' => 4000, 'cbm_min' => 8.01, 'cbm_max' => 9.2 ),
        array('weight' => 4500, 'cbm_min' => 9.21, 'cbm_max' => 10.3 ),
        array('weight' => 5000, 'cbm_min' => 10.31, 'cbm_max' => 11.5 ),
        array('weight' => 5500, 'cbm_min' => 11.51, 'cbm_max' => 13),
        array('weight' => 6000, 'cbm_min' => 13.01, 'cbm_max' => 14 ),
        array('weight' => 6500, 'cbm_min' => 14.01, 'cbm_max' => 15 ),
        array('weight' => 7000, 'cbm_min' => 15.01, 'cbm_max' => 16 ),
        array('weight' => 7500, 'cbm_min' => 16.01, 'cbm_max' => 17 ),
        array('weight' => 8000, 'cbm_min' => 17.01, 'cbm_max' => 18.25 ),
        array('weight' => 8500, 'cbm_min' => 18.26, 'cbm_max' => 19.5 ),
        array('weight' => 9000, 'cbm_min' => 19.51, 'cbm_max' => 20.5),
        array('weight' => 9500, 'cbm_min' => 20.51, 'cbm_max' => 22 ),
        array('weight' => 10000, 'cbm_min' => 22.01, 'cbm_max' => 23 ),
        array('weight' => 10500, 'cbm_min' => 23.01, 'cbm_max' => 24.25 ),
        array('weight' => 11000, 'cbm_min' => 24.26, 'cbm_max' => 25.45 ),
        array('weight' => 11500, 'cbm_min' => 25.46, 'cbm_max' => 26.65 ),
        array('weight' => 12000, 'cbm_min' => 26.66, 'cbm_max' => 27.85 ),
        array('weight' => 12500, 'cbm_min' => 27.86, 'cbm_max' => 29.05 ),
        array('weight' => 13000, 'cbm_min' => 29.06, 'cbm_max' => 30.25 ),
        array('weight' => 13500, 'cbm_min' => 30.26, 'cbm_max' => 31.45 ),
        array('weight' => 14000, 'cbm_min' => 31.46, 'cbm_max' => 32.65 ),
        array('weight' => 14500, 'cbm_min' => 32.66, 'cbm_max' => 33.85 ),
        array('weight' => 15000, 'cbm_min' => 33.86, 'cbm_max' => 35.05 ),
        array('weight' => 15500, 'cbm_min' => 35.06, 'cbm_max' => 36.25 ),
); 

?>  
<form name="createtable" action="?page=createtable" method="POST" autocomplete="off">
    <label for=tablename>Name of Table</label>
    <input type=text name=tablename id=tablename>
      <table border='1'>
            <tr>
                <th> Weight </th>
                <th> CBM Min </th>
                <th> CBM Max </th>
                <th> Min </th>
                <?php 
                $a = 1;
                while ($a < 8){
                    ?>
                    <th> <input type=text name="miles<?= (float) $a ?>" size="10"> </th>
                    <?php
                    $a++;
                }
                ?>
            </tr>
<?php
$i = 1; // I'll use this to increment the input text name
foreach ($rows as $row) {
  // Everything happening inside this foreach will loop for as many records/rows that are in the $rows array.
 ?>
    <tr>
      <td> <?= (float) $row['weight'] ?> </td>
      <td> <?= (float) $row['cbm_min'] ?> </td>
      <td> <?= (float) $row['cbm_max'] ?> </td>
      <td> <input type=text name="min<?= (float) $i ?>" size="10"> </td>
      <?php 
      $a = 1;
            while ($a < 8){
            ?>
                <td> <input type=text name="miles<?= (float) $i ?><?= (float) $a ?>" size="10"> </td>
                <?php
                $a++;
            }
        ?>
    </tr>
  <?php
  $i++;
}
?>
  </table>
  <input type=submit value="Create Table">
</form>
<?php
if($page == "createtable"){
    $tablename = $_POST['tablename'];
    $mins = array($_POST['min1'],$_POST['min1'],$_POST['min2'],$_POST['min3'],$_POST['min4'],$_POST['min5'],$_POST['min6'],$_POST['min7'],$_POST['min8'],
            $_POST['min9'],$_POST['min10'],$_POST['min11'],$_POST['min12'],$_POST['min13'],$_POST['min14'],$_POST['min15'],$_POST['min16'],$_POST['min17'],$_POST['min18'],
            $_POST['min19'],$_POST['min20'],$_POST['min21'],$_POST['min22'],$_POST['min23'],$_POST['min24'],$_POST['min25'],$_POST['min26'],$_POST['min27'],$_POST['min28'],
            $_POST['min29'],$_POST['min30']);  
    $titles = array($_POST['miles1'], $_POST['miles2'], $_POST['miles3'], $_POST['miles4'], $_POST['miles5'], $_POST['miles6'], $_POST['miles7']); 
    $i = 1;
    $array = array();
    foreach ($titles as $title){
        if (empty($title) ){

        }else{
            array_push($array, array($_POST['miles1'.$i], $_POST['miles2'.$i], $_POST['miles3'.$i], $_POST['miles4'.$i], $_POST['miles5'.$i], $_POST['miles6'.$i], $_POST['miles7'.$i], 
                    $_POST['miles8'.$i], $_POST['miles9'.$i] ,$_POST['miles10'.$i], $_POST['miles11'.$i], $_POST['miles12'.$i], $_POST['miles13'.$i], $_POST['miles14'.$i], $_POST['miles15'.$i],
                     $_POST['miles16'.$i], $_POST['miles17'.$i], $_POST['miles18'.$i], $_POST['miles19'.$i], $_POST['miles20'.$i], $_POST['miles21'.$i], $_POST['miles22'.$i], $_POST['miles23'.$i], $_POST['miles24'.$i], 
                    $_POST['miles25'.$i], $_POST['miles26'.$i] ,$_POST['miles27'.$i], $_POST['miles28'.$i], $_POST['miles29'.$i], $_POST['miles30'.$i]));
        }
        $i++;
    }
    $log->createTable($tablename, $mins, $array, $titles);
}
?> 
</div>
</body>
</html>

The parts that need to be on their own is each <h2> so the user can only see one <h2> a la vez

preguntado el 09 de septiembre de 13 a las 08:09

1 Respuestas

Obtenga más información sobre Jquery Tabs Here y Aquí. Puede que resuelva su problema.
¡Salud

Respondido el 09 de Septiembre de 13 a las 08:09

Both those links contain examples where the content is all on one html page. How do you make the content come from different files? - user3217883

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.