0

目前我有一个大页面,当用户登录并且是管理员时显示。此页面变得非常大,我想将其拆分为多个页面(每个页面上的一个功能)或选项卡式菜单。无论哪种方式,我都试图找出一种方法,让顶部有一个菜单,当用户按下菜单项时,它会显示该项目

涉及的文件:

login Index.php - 如果用户已登录,则处理:

<?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 决定显示管理员视图或用户视图:

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

?>

然后是我需要跨页面或选项卡拆分的 admin.php,它们也是文件中的一个 php 类,但无论如何这将被移出到它自己的文件中。

<!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>

需要独立的部分是每个<h2>,因此用户一次只能看到<h2>一个

4

1 回答 1

0

在此处和此处了解Jquery 选项卡。它可能会解决您的问题。干杯

于 2013-09-09T07:46:03.170 回答