<?php if (!defined('DASHBOARD_ROOT')) { http_response_code(403); exit; } $userId = (int)($_POST['user_id'] ?? 0); if ($userId <= 0) { echo '<div class="alert-error"><span>Invalid user.</span></div>'; return; } $user = Database::fetchOne("SELECT id, username, email, encrypted_username, encrypted_email, status, is_verified, credit_balance FROM users WHERE id=:id", [':id'=>$userId]); if (!$user) { echo '<div class="alert-error"><span>User not found.</span></div>'; return; } $username = $user['username']; $email = $user['email']; $balance = number_format((float)$user['credit_balance'], 2); ?> <div id="customer-save" class="editor-form"> <span class="section-label">Edit Customer #<?= $userId ?> </span> <div class="form-group"><span>Username</span><input id="cs-username" class="form-group input" type="text" value="<?= UI::e($username) ?> "></div> <div class="form-group"><span>Email</span><input id="cs-email" class="form-group input" type="text" value="<?= UI::e($email) ?> "></div> <div class="form-group"><span>Credit Balance ($)</span><input id="cs-balance" class="form-group input" type="text" value="<?= UI::e($balance) ?> "></div> <div class="form-group"><span>Status</span> <select id="cs-status" class="form-group input"> <option value="user"<?= $user['status']==='user'?'selected':'' ?> >User</option> <option value="admin"<?= $user['status']==='admin'?'selected':'' ?> >Admin</option> <option value="banned"<?= $user['status']==='banned'?'selected':'' ?> >Banned</option> <option value="suspended"<?= $user['status']==='suspended'?'selected':'' ?> >Suspended</option> </select> </div> <div class="form-group"><span>Verified</span> <select id="cs-verified" class="form-group input"> <option value="1"<?= $user['is_verified'] ? 'selected' : '' ?> >Yes</option> <option value="0"<?= !$user['is_verified'] ? 'selected' : '' ?> >No</option> </select> </div> <div class="form-group"><span>New Password (leave blank to keep current)</span><input id="cs-password" class="form-group input" type="password" placeholder=""></div> <div class="form-actions"> <a id="cs-save-btn" class="btn btn-primary" href="javascript:void(0)" data-uid="<?= $userId ?> "><span>Save Customer</span></a> </div> </div> <script nonce="<?= $cspNonce ?? '' ?> "> document.getElementById('cs-save-btn').addEventListener('click',function(){ var uid=this.dataset.uid; var data={entity:'customer',id:uid,'data[username]':document.getElementById('cs-username').value,'data[email]':document.getElementById('cs-email').value,'data[credit_balance]':document.getElementById('cs-balance').value,'data[status]':document.getElementById('cs-status').value,'data[is_verified]':document.getElementById('cs-verified').value}; var pw=document.getElementById('cs-password').value; if(pw)data['data[password]']=pw; window.dashFetch('modify',data,function(r){if(r.ok){alert('Saved. Reloading...');location.reload();}else{alert(r.error||'Save failed');}}); }); </script>