1

これが私が達成しようとしているワークフローです。

Users.html ページの読み込み時に、php コードを実行して mysql データベースからデータを取得し、php を使用して動的テーブルを作成し、ループしてテーブル行と各行のデータ要素を作成します。

各行には削除ボタンがあります。削除ボタンを押すと、jQuery UI モーダル ダイアログ ボックスが開き、ユーザー データが渡されてダイアログ ボックスに表示されます。

ユーザーが削除の確認を押した場合、$.post を使用して php ページを開き、php ページのデータを渡してユーザーの削除を実行します。

拒否 (またはエラー) が成功すると、ヘッダー "users.html?error=x" を使用します。ここで、x はエラー番号であり、ユーザーは開始した元の users.html ページに戻ります。

問題は、users.html ページが更新されないことです (そして、modal-php リダイレクト プロセス全体でページが実際に変更されることはありません。

(#divIDx).remove() を使用してテーブルのエントリを削除しましたが、これは動的なテーブルであるため、ユーザーがテーブルのページを変更したり、ページごとに許可するエントリを増やしたり減らしたりするように選択したりすると、ユーザーはデータベースから削除されても戻ってきます。ユーザーが削除の確認ボタンを押した結果、 document.location.reload() を呼び出してみましたが、セキュリティがその呼び出しを聞き、現在のセッションを強制終了します。

したがって、HTML アンカー クリック -> jquery ダイアログ ボックス -> ユーザー php の削除 -> 同じ users.html に戻るが、users.html は更新されません。

データベースクエリが実行される users.html は次のとおりです。

<?php
    require_once( '_/connections/login.php' );

    $stmt = $mysqli_login->stmt_init();
    //$businessid =  $mysqli_login->real_escape_string($orgid);
    $stmt = $mysqli_login->prepare("SELECT firstname, lastname, role, email, id, organizationid FROM login where organizationid = " . $mysqli_login->real_escape_string($orgid) );
    //$stmt = $mysqli_login->prepare("SELECT firstname, lastname, role, email, id, organizationid FROM login where organizationid = ?");
    if(!isset($stmt)){}else{
        ///////////////////////////////////////////////////////////
        //TODO: find out why bind_params is not working here
        ///////////////////////////////////////////////////////////
        //$stmt->bind_params('s', $businessid);
        $stmt->execute(); // Execute the prepared query.
        $stmt->store_result();
    $stmt->bind_result($Ufirstname, $Ulastname, $Urole, $Uemail, $Uid, $Uorgid);
    }
?>

次に、このコードを使用してテーブルを作成します

<?php if(!$stmt){echo $users_found = 0;} else {$users_found = $stmt->num_rows;}?>

        <div class="widget">
            <div class="whead">
                <h6>Registered Dashboard Users: 
                    <?php echo $users_found; ?>&nbsp;&nbsp;
                    <?php if(isset($_GET['del_error'])){
                        switch($_GET['del_error']) {
                        case '0':
                            echo "User Deleted";
                            break;
                        case '1':
                            echo "Error deleting user";
                            break;
                        case '2':
                            echo "Error deleting user";
                            break;
                        case '3':
                            echo "Error deleting user";
                            break;
                        default:

                            break;
                        }
                    }?>
                </h6>
                <div class="clear"></div>
            </div>
            <div id="dyn" class="hiddenpars">
                <a class="tOptions" title="Options"><img src="images/icons/options" alt="" /></a>
                <table cellpadding="0" cellspacing="0" border="0" class="dTable" id="dynamic">
                    <thead>
                        <tr>
                        <th>First Name<span class="sorting" style="display: block;"></span></th>
                        <th>Last Name</th>
                        <th>Role</th>
                        <th>Email</th>
                        <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php while ($stmt->fetch()) { ?>
                        <tr id="div<?php printf ("%s", $Uid); ?>">
                            <td><?php printf ("%s", $Ufirstname); ?></td>
                            <td><?php printf ("%s", $Ulastname);  ?></td>
                            <td><?php printf ("%s", $Urole);      ?></td>
                            <td><?php printf ("%s", $Uemail);     ?></td>
                            <td class="tableActs">
                                <a class="usereditbutton tablectrl_small bDefault tipS" title="Edit"
                                user-dlg-divid="div<?php printf ("%s", $Uid); ?>"
                                user-dlg-fname="<?php printf ("%s", $Ufirstname); ?>" 
                                user-dlg-lname="<?php printf ("%s", $Ulastname); ?>"
                                user-dlg-role="<?php printf ("%s", $Urole); ?>"
                                user-dlg-email="<?php printf ("%s", $Uemail); ?>"
                                user-dlg-id="<?php printf ("%s", $Uid); ?>" 
                                user-dlg-orgid="<?php printf ("%s", $Uorgid); ?>"
                                ><span class="iconb" data-icon="&#xe1db;"></span></a>
                                <a class="userdeletebutton tablectrl_small bDefault tipS" title="Remove" 
                                user-dlg-divid="div<?php printf ("%s", $Uid); ?>"
                                user-dlg-fname="<?php printf ("%s", $Ufirstname); ?>" 
                                user-dlg-lname="<?php printf ("%s", $Ulastname); ?>"
                                user-dlg-role="<?php printf ("%s", $Urole); ?>"
                                user-dlg-email="<?php printf ("%s", $Uemail); ?>"
                                user-dlg-id="<?php printf ("%s", $Uid); ?>" 
                                user-dlg-orgid="<?php printf ("%s", $Uorgid); ?>"
                                ><span class="iconb" data-icon="&#xe136;"></span></a>
                            </td>
                        </tr>
                        <?php } $stmt->close(); ?>
                    </tbody>
                </table> 
                </div>
            </div>
        </div>

別の HTML ページから HTML を動的に挿入するため、フォーム div は単純です。

<div id="dialog_edituser" title="Edit User Form">
    <a id="dialog_edituser_content"></a>
</div>

ダイアログ ボックスの JavaScript コードは、必要なパラメーターの値を取得し、それらをいくつかのグローバルに格納します。次に、開くと、HTML のコンテンツが適切な div に挿入され、サーバーはいくつかのパラメーターを使用して必要な動的データを既に入力しています。 echo $_POST['...'] コマンド

//==================================//
//===== Remove User Dialog Box =====//
//==================================//
var dialog_deluser_divid = ''; //tr to delete from table
var dialog_deluser_fname = ''; //first name
var dialog_deluser_lname = ''; //last name
var dialog_deluser_email = ''; //email
var dialog_deluser_role = ''; //role
var dialog_deluser_id = ''; //id
var dialog_deluser_orgid = ''; //business id
$('#dialog_deluser').dialog({
    autoOpen: false, 
    width: 400,
    modal: true,
    buttons: {
            "Submit": function() {
                //remove the data from the table
                $('#'+dialog_deluser_divid).remove();
                //remove the user from the database
                $.post("_/processUserRemove.php", { 
                    'fname': dialog_deluser_fname, 
                    'lname': dialog_deluser_lname,
                    'email': dialog_deluser_email,
                    'role': dialog_deluser_role,
                    'id': dialog_deluser_id,
                    'orgid': dialog_deluser_orgid
                });
                //close the dialog box
                $( this ).dialog( "close" );
            },
            "Cancel": function() {
                $( this ).dialog( "close" );
            }
    },
    //load the dialog box with the contents of an HTML file replacing the ID in a <div id=
    open: function(event, ui) {
           $('#dialog_deluser_content').load('_/processUserRemoveDialog.html', 
           {'divid':dialog_deluser_divid,
            'fname':dialog_deluser_fname, 
            'lname':dialog_deluser_lname,
            'email':dialog_deluser_email,
            'role':dialog_deluser_role,
            'id':dialog_deluser_id,
            'orgid':dialog_deluser_orgid},
            function() {
           });
   }

});

$('.userdeletebutton').click(function (e) {
    e.preventDefault();
    dialog_deluser_divid = $(this).attr("user-dlg-divid");//id of tr to delete
    dialog_deluser_fname = $(this).attr("user-dlg-fname");//set first name
    dialog_deluser_lname = $(this).attr("user-dlg-lname");//set last name
    dialog_deluser_email = $(this).attr("user-dlg-email");//set email
    dialog_deluser_role = $(this).attr("user-dlg-role");//set role
    dialog_deluser_id = $(this).attr("user-dlg-id");//set id
    dialog_deluser_orgid = $(this).attr("user-dlg-orgid");//set organization id;
    $('#dialog_deluser').dialog('open');
});
//===== End Remove User Dialog Box =====//

ユーザーが [送信] ボタンをクリックすると、値が processUserRemove.php にポストされ、processUserRemove.php が header('Location: ../users.html?del_error=x'); を実行します。ここで、「x」は適切なエラー番号です。

これがprocessUserRemove.phpコードです

<?php
require_once( './connections/login.php' );
require_once( 'login_functions.php' );
sec_session_start(); // Our custom secure way of starting a php session. 

if(isset($_POST['fname'], $_POST['lname'], $_POST['email'], $_POST['role'], $_POST['id'],             $_POST['orgid'])) {
//////////////////////////////////////////////////////////////////////
//TODO: get the associated business ID from the current user
//////////////////////////////////////////////////////////////////////
$RUfirstname = $_POST['fname'];
$RUlastname = $_POST['lname'];
$RUemail = $_POST['email'];
$RUrole = $_POST['role'];
$RUid = $_POST['id'];
$RUorgid = $_POST['orgid'];
$RU_currentuser_orgid = $_SESSION['organizationid'];
$del_stmt = $mysqli_login->init();
if ($RU_currentuser_orgid == $RUorgid) {
    if ($del_stmt = $mysqli_login->prepare("DELETE FROM login WHERE firstname = ? and lastname = ? and email = ? and role = ? and organizationid = ? and id = ?")) {    
       $del_stmt->bind_param('ssssss', $RUfirstname, $RUlastname, $RUemail, $RUrole, $RUorgid, $RUid); 
       // Execute the prepared query.
       $del_stmt->execute();
       header('Location: ../index.html'); 
    } else {
        // Registration Failed
        header('Location: ../users.html?del_error=1');
    }
} else {
  //  orgainization id's don't match
  header("Location: ../users.html?del_error=2_firstname=" . $RUfirstname . "_lastname=" . $RUlastname  . 
        "_email=" . $RUemail . "_role=" . $RUrole . "_organizationid=" . $RUorgid . "_id=" . $RUid . "_cuid=" . $RU_currentuser_orgid); 
}
} else { 
// The correct POST variables were not sent to this page.
header('Location: ../users.html?del_error=3'); 
}
?>

しかし、ボタン -> モーダル -> php -> users.html のプロセス全体で、users.html ページが更新されることはありません。テーブル エントリの削除は機能しますが、ユーザーがテーブルを操作すると、削除されたデータが戻ってきて、document.location.reload(true) によってシステムからログアウトされますか?!?

すべてのコードで申し訳ありませんが、何かが欠けている方法や、単純な操作であるはずの操作が非常に複雑になっていることを完全に明確にしたかったのです。

どんな助けでも大歓迎です、ありがとう。

4

0 に答える 0