[ Root System Explorer ]
Location:
Root
/
var
/
www
/
html
/
acma.in
/
developer
+ Folder
+ File
Upload
Editing: delete-companies.php
<?php ini_set('display_errors', 1); error_reporting(E_ALL); session_start(); if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) { header("Location: index.php"); exit; } require_once __DIR__ . "/db-connection.php"; function normalizeCompanyName($name) { if (empty($name)) { return ''; } $name = strtolower($name); $remove = [ 'private limited', 'pvt limited', 'pvt ltd', 'pvt. ltd.', 'pvt', 'Private Limited', 'Pvt Limited', 'Pvt Ltd', 'Pvt. Ltd.', 'limited', 'ltd', '.', ',', '-', '_' ]; $name = str_replace($remove, '', $name); $name = preg_replace('/\s+/', ' ', $name); return trim($name); } function html($value) { return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8'); } $companies = []; $query = mysqli_query( $mainDb, "SELECT id, company, email FROM memberlogin" ); while ($row = mysqli_fetch_assoc($query)) { $normalized = normalizeCompanyName($row['company']); $companies[$normalized] = [ 'id' => $row['id'], 'name' => $row['company'], 'email' => $row['email'] ]; } $deleted = []; $notFound = []; $errors = []; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $input = trim($_POST['companies']); $companyList = explode(',', $input); $deleteMemberStmt = mysqli_prepare($mainDb, "DELETE FROM memberlogin WHERE id = ? LIMIT 1"); $selectMailerStmt = mysqli_prepare($mailerDb, "SELECT id FROM users WHERE email = ? LIMIT 1"); $deleteGroupUserStmt = mysqli_prepare($mailerDb, "DELETE FROM group_user WHERE user_id = ?"); $deleteMailerUserStmt = mysqli_prepare($mailerDb, "DELETE FROM users WHERE id = ? LIMIT 1"); if (!$deleteMemberStmt || !$selectMailerStmt || !$deleteGroupUserStmt || !$deleteMailerUserStmt) { $errors[] = [ 'company' => '-', 'error' => 'Unable to prepare delete queries: ' . mysqli_error($mainDb) . ' ' . mysqli_error($mailerDb) ]; $companyList = []; } foreach ($companyList as $company) { $company = trim($company); if (empty($company)) { continue; } $normalized = normalizeCompanyName($company); if (isset($companies[$normalized])) { $companyData = $companies[$normalized]; $companyId = (int) $companyData['id']; $email = $companyData['email']; $mailerStatus = 'Not Found'; $groupUserStatus = 'Not Found'; mysqli_stmt_bind_param($selectMailerStmt, 's', $email); if (!mysqli_stmt_execute($selectMailerStmt)) { $errors[] = [ 'company' => $company, 'error' => mysqli_stmt_error($selectMailerStmt) ]; continue; } mysqli_stmt_bind_result($selectMailerStmt, $mailerId); $mailerFound = mysqli_stmt_fetch($selectMailerStmt); mysqli_stmt_free_result($selectMailerStmt); if ($mailerFound) { $mailerId = (int) $mailerId; mysqli_stmt_bind_param($deleteGroupUserStmt, 'i', $mailerId); if (!mysqli_stmt_execute($deleteGroupUserStmt)) { $errors[] = [ 'company' => $company, 'error' => mysqli_stmt_error($deleteGroupUserStmt) ]; continue; } $groupUserStatus = mysqli_stmt_affected_rows($deleteGroupUserStmt) > 0 ? 'Deleted' : 'Not Found'; mysqli_stmt_bind_param($deleteMailerUserStmt, 'i', $mailerId); if (!mysqli_stmt_execute($deleteMailerUserStmt)) { $errors[] = [ 'company' => $company, 'error' => mysqli_stmt_error($deleteMailerUserStmt) ]; continue; } $mailerStatus = mysqli_stmt_affected_rows($deleteMailerUserStmt) > 0 ? 'Deleted' : 'Not Found'; } mysqli_stmt_bind_param($deleteMemberStmt, 'i', $companyId); if (!mysqli_stmt_execute($deleteMemberStmt)) { $errors[] = [ 'company' => $company, 'error' => mysqli_stmt_error($deleteMemberStmt) ]; continue; } $deleted[] = [ 'input' => $company, 'matched' => $companyData['name'], 'email' => $email, 'main_db' => mysqli_stmt_affected_rows($deleteMemberStmt) > 0 ? 'Deleted' : 'Not Found', 'mailer_db' => $mailerStatus, 'group_user' => $groupUserStatus, ]; } else { $notFound[] = $company; } } } ?> <!DOCTYPE html> <html> <head> <title>Delete Companies</title> <style> body{ font-family: Arial; background:#f5f5f5; padding:40px; } .container{ max-width:1200px; margin:auto; background:#fff; padding:30px; border-radius:10px; } textarea{ width:100%; height:180px; padding:15px; margin-top:10px; font-size:14px; } button{ padding:12px 20px; background:#dc3545; color:#fff; border:none; margin-top:20px; cursor:pointer; } table{ width:100%; border-collapse: collapse; margin-top:20px; } table th, table td{ border:1px solid #ddd; padding:10px; text-align:left; font-size:14px; } .success{ background:#d4edda; } .danger{ background:#f8d7da; } .warning{ background:#fff3cd; } .navbar{ background:#212529; padding:15px 25px; margin-bottom:30px; border-radius:10px; } .navbar a{ color:#fff; text-decoration:none; margin-right:20px; font-weight:bold; } </style> </head> <body> <div class="container"> <!-- NAVBAR --> <?php include "header.php"; ?> <h2>Delete Companies</h2> <form method="POST"> <label> Enter Company Names (Comma Separated) </label> <textarea name="companies" placeholder="ABC Pvt Ltd, XYZ Private Limited" required ></textarea> <button type="submit"> Delete Companies </button> </form> <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { ?> <hr> <h3>Report</h3> <p> Total Deleted: <b><?php echo count($deleted); ?></b> </p> <p> Not Found: <b><?php echo count($notFound); ?></b> </p> <p> Errors: <b><?php echo count($errors); ?></b> </p> <!-- DELETED REPORT --> <?php if (!empty($deleted)) { ?> <table class="success"> <tr> <th>Input Name</th> <th>Matched Company</th> <th>Email</th> <th>Main DB</th> <th>Mailer DB</th> <th>Group User</th> <th>Status</th> </tr> <?php foreach ($deleted as $item) { ?> <tr> <td> <?php echo html($item['input']); ?> </td> <td> <?php echo html($item['matched']); ?> </td> <td> <?php echo html($item['email']); ?> </td> <td> <?php echo html($item['main_db']); ?> </td> <td> <?php echo html($item['mailer_db']); ?> </td> <td> <?php echo html($item['group_user']); ?> </td> <td> Success </td> </tr> <?php } ?> </table> <?php } ?> <!-- NOT FOUND --> <?php if (!empty($notFound)) { ?> <table class="warning"> <tr> <th>Company</th> <th>Status</th> </tr> <?php foreach ($notFound as $item) { ?> <tr> <td> <?php echo html($item); ?> </td> <td> Not Found </td> </tr> <?php } ?> </table> <?php } ?> <!-- ERRORS --> <?php if (!empty($errors)) { ?> <table class="danger"> <tr> <th>Company</th> <th>Error</th> </tr> <?php foreach ($errors as $item) { ?> <tr> <td> <?php echo html($item['company']); ?> </td> <td> <?php echo html($item['error']); ?> </td> </tr> <?php } ?> </table> <?php } ?> <?php } ?> </div> </body> </html>
SAVE CHANGES
[ CANCEL ]
Name
Type
Actions
.. (Parent Directory)
📄 add-companies.php
FILE
Ren
[EDIT]
DEL
📄 db-connection.php
FILE
Ren
[EDIT]
DEL
📄 delete-companies.php
FILE
Ren
[EDIT]
DEL
📄 developer-tools.php
FILE
Ren
[EDIT]
DEL
📁 files/
DIR
Ren
DEL
📄 header.php
FILE
Ren
[EDIT]
DEL
📄 index.php
FILE
Ren
[EDIT]
DEL