This commit is contained in:
dev sp
2024-04-29 12:55:11 +00:00
commit ca6af2f5e2
67 changed files with 6792 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
<?php
require_once('/var/www/html/.hta_config/crm_config.php');
require_once('/var/www/html/.htac_header.php');
require_once('/var/www/html/.htac_nav.php');
?>
<div>
<table style="overflow-x: auto;">
<thead>
<tr>
<th style="text-align: center;">Name</th>
<th style="text-align: center;">Email</th>
<th style="text-align: center;">Phone</th>
<th style="text-align: center;">Access</th>
<th style="text-align: center;">Time</th>
<th style="text-align: center;">Action</th>
</tr>
</thead>
<tbody>
<?php
try {
$conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT * FROM users");
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$num_rows = $stmt->rowCount();
if ($num_rows >= 1) {
foreach($rows as $row){
echo ' <tr>
<td style="text-align: center;">'.$row['name'].'</td>
<td style="text-align: center;">'.$row['email'].'</td>
<td style="text-align: center;">'.$row['mobile'].'</td>
<td style="text-align: center;">'.$row['access'].'</td>
<td style="text-align: center;">'.$row['time'].'</td>
<td style="text-align: center;"><a href="/users/edit-user/?id='.$row['id'].'">Edit</a> | <a href="/users/delete-user/?id='.$row['id'].'">Delete</a> </td>
</tr>';
}
} else{
echo "<p class='text-danger'>Not Found any Data</p>";
}
} catch (PDOException $e) {
echo "<p class='text-danger'>Error: " . $e->getMessage() . "</p>";
}
?>
</tbody>
</table>
</div>

54
.hta_slug/users/_home.php Normal file
View File

@@ -0,0 +1,54 @@
<?php
require_once('/var/www/html/.hta_config/crm_config.php');
require_once('/var/www/html/.htac_header.php');
require_once('/var/www/html/.htac_nav.php');
?>
<div>
<a href="/users/add-user" class="" style="background: linear-gradient(90deg, rgba(111, 107, 255, 0.91) 0%, rgba(68, 55, 128, 0.91) 100%); text-align: center; padding: 10px 20px 10px 20px; color: #fff; border-radius: 6px; float: right; margin-top: 30px;">Add User</a>
</div>
<table class="bg-[#fff] text-[#3F4254] rounded-lg font-bold">
<thead>
<tr>
<th class="text-center border-b-2 p-3">Name</th>
<th class="text-center border-b-2 p-3">Email</th>
<th class="text-center border-b-2 p-3">Mobile</th>
<th class="text-center border-b-2 p-3">Time</th>
<th class="text-center border-b-2 p-3">Access</th>
<th class="text-center border-b-2 p-3">Access by State</th>
<th class="text-center border-b-2 p-3">Action</th>
</tr>
</thead>
<tbody>
<?php
try {
$conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT * FROM users");
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($rows as $row){
?>
<tr>
<td class="border-y-2 p-2"><?php echo $row['name']; ?></td>
<td class="border-y-2 p-2"><?php echo $row['email']; ?></td>
<td class="border-y-2 p-2"><?php echo $row['mobile']; ?></td>
<td class="border-y-2 p-2"><?php echo $row['time']; ?></td>
<td class="border-y-2 p-2"><?php echo $row['access']; ?></td>
<td class="border-y-2 p-2"><?php echo $row['access']; ?></td>
<td class="border-y-2 p-2">
<div class="flex flex-row justify-center">
<a href="/admin/edit-user/?id=<?php echo $row['id']; ?>">Edit</a> &nbsp; | &nbsp;
<a href="/admin/delete-user/?id=<?php echo $row['id']; ?>">Delete</a>
</div>
</td>
</tr>
<?php }
$num_rows = $stmt->rowCount();
} catch (PDOException $e) {
echo "<p class='text-danger'>Error: " . $e->getMessage() . "</p>";
}
?>
</tbody>
</table>

View File

@@ -0,0 +1,145 @@
<?php
require_once('/var/www/html/.hta_config/crm_config.php');
require_once('/var/www/html/.htac_header.php');
require_once('/var/www/html/.htac_nav.php');
try {
$conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$select_access = ['beanstalk', 'inhouse', 'teenybeans', 'iimtt', 'buzzapp', 'atheneum', 'teenybeans_curriculum'];
$access_values_array = [];
foreach ($select_access as $access) {
if (isset($_POST[$access])) {
$access_values_array[] = $_POST[$access];
}
}
$access_value = implode(',', $access_values_array);
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$password = md5($_POST['pass']);
try {
$stmt = $conn->prepare("INSERT INTO users (name, email, mobile, access, pass) VALUES (:name, :email, :mobile, :access, :pass)");
$stmt->bindParam(':name', $name);
$stmt->bindParam(':email', $email);
$stmt->bindParam(':mobile', $phone);
$stmt->bindParam(':access', $access_value);
$stmt->bindParam(':pass', $password);
$stmt->execute();
echo "Record added successfully";
} catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
?>
<div style="display: flex; flex-direction: column; justify-content: center; align-items: center; margin-top: 30px; margin-bottom: 30px;">
<form action="" method="post" style="width: 600px; max-width: 600px; border: 1px solid #36365050; padding: 20px; border-radius: 20px; box-shadow: 0px 0px 10px 0px #363650;">
<p style="font-size: 25px; font-weight: bold; margin-top: 10px; margin-bottom: 10px;">Add new user</p>
<div style="display: flex; flex-direction: column;">
<label for="name">Name:</label>
<input type="text" name="name" id="name" style="border: 1px solid #363650; border-radius: 5px; padding: 6px;" />
</div>
<div style="display: flex; flex-direction: column;">
<label for="email">E-mail:</label>
<input type="text" name="email" id="email" style="border: 1px solid #363650; border-radius: 5px; padding: 6px;" />
</div>
<div style="display: flex; flex-direction: column;">
<label for="phone">Phone:</label>
<input type="text" name="phone" id="phone" style="border: 1px solid #363650; border-radius: 5px; padding: 6px;" />
</div>
<div style="display: flex; flex-direction: column;">
<p>Access:</p>
<?php
try {
$conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT * FROM business_verticals");
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$num_rows = $stmt->rowCount();
if ($num_rows >= 1) {
foreach($rows as $row){ ?>
<div>
<input type="checkbox" name="<?php echo $row['bv']; ?>" id="<?php echo $row['bv']; ?>" value="<?php echo $row['bv']; ?>" />
<label for="<?php echo $row['bv']; ?>" style="text-transform: uppercase;"><?php echo $row['bv']; ?></label>
</div>
<?php
}
} else{
echo "<p class='text-danger'>Not Found any Data</p>";
}
} catch (PDOException $e) {
echo "<p class='text-danger'>Error: " . $e->getMessage() . "</p>";
}
?>
</div>
<div style="display: flex; flex-direction: column;">
<p style="font-size: 16px; font-weight: bold; margin-top: 10px;">Access by state:</p>
<div id="stateCheckboxes"></div>
</div>
<div style="display: flex; flex-direction: column;">
<label for="pass">Password:</label>
<input type="text" name="pass" id="pass" style="border: 1px solid #363650; border-radius: 5px; padding: 6px;" />
</div>
<div style="display: flex; flex-direction: column;">
<input type="submit" name="submit" id="submit" value="Submit" style="background: linear-gradient(90deg, rgba(111, 107, 255, 0.91) 0%, rgba(68, 55, 128, 0.91) 100%); text-align: center; padding: 10px 20px 10px 20px; color: #fff; border-radius: 6px; float: right; margin-top: 30px;" />
</div>
</form>
</div>
<script>
function fetchStates() {
fetch(`https://api.siliconpin.com/v3/list/country/state/?country=IN`)
.then(res => res.json())
.then(data => {
const stateCheckboxes = document.getElementById('stateCheckboxes');
stateCheckboxes.innerHTML = ''; // Clear previous checkboxes
data.forEach(state => {
const checkboxDiv = document.createElement('div');
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.name = 'states[]'; // You might want to use an array here if submitting form
checkbox.value = state.iso2;
const label = document.createElement('label');
label.textContent = ' ' + state.name;
label.style = 'text-transform: uppercase'
checkboxDiv.appendChild(checkbox);
checkboxDiv.appendChild(label);
stateCheckboxes.appendChild(checkboxDiv);
});
});
}
fetchStates();
</script>
<style>
/* For small screens */
@media screen and (max-width: 767px) {
#stateCheckboxes {
display: grid;
grid-template-columns: repeat(2, 1fr); /* 2 columns */
gap: 10px; /* Adjust the gap as needed */
}
}
/* For large screens */
@media screen and (min-width: 768px) {
#stateCheckboxes {
display: grid;
grid-template-columns: repeat(3, 1fr); /* 3 columns */
gap: 10px; /* Adjust the gap as needed */
}
}
</style>

View File

@@ -0,0 +1,223 @@
<?php
require_once('/var/www/html/.hta_config/crm_config.php');
require_once('/var/www/html/.htac_header.php');
require_once('/var/www/html/.htac_nav.php');
try {
$conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$select_access = ['beanstalk', 'inhouse', 'teenybeans', 'iimtt', 'buzzapp', 'atheneum', 'teenybeans_curriculum'];
$access_values_array = [];
foreach ($select_access as $access) {
if (isset($_POST[$access])) {
$access_values_array[] = $_POST[$access];
}
}
$access_value = implode(',', $access_values_array);
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$password = md5($_POST['pass']);
$selected_states = implode(',', $_POST['states']); // Collect selected state values
try {
$stmt = $conn->prepare("INSERT INTO users (name, email, mobile, access, pass, states) VALUES (:name, :email, :mobile, :access, :pass, :states)");
$stmt->bindParam(':name', $name);
$stmt->bindParam(':email', $email);
$stmt->bindParam(':mobile', $phone);
$stmt->bindParam(':access', $access_value);
$stmt->bindParam(':pass', $password);
$stmt->bindParam(':states', $selected_states); // Bind selected states
$stmt->execute();
echo "Record added successfully";
} catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
?>
<div style="display: flex; flex-direction: column; justify-content: center; align-items: center; margin-top: 30px; margin-bottom: 30px;">
<form action="" method="post" style="width: 600px; max-width: 600px; border: 1px solid #36365050; padding: 20px; border-radius: 20px; box-shadow: 0px 0px 10px 0px #363650;">
<p style="font-size: 25px; font-weight: bold; margin-top: 10px; margin-bottom: 10px;">Add new user</p>
<div style="display: flex; flex-direction: column;">
<label for="name">Name:</label>
<input type="text" name="name" id="name" style="border: 1px solid #363650; border-radius: 5px; padding: 6px;" />
</div>
<div style="display: flex; flex-direction: column;">
<label for="email">E-mail:</label>
<input type="text" name="email" id="email" style="border: 1px solid #363650; border-radius: 5px; padding: 6px;" />
</div>
<div style="display: flex; flex-direction: column;">
<label for="phone">Phone:</label>
<input type="text" name="phone" id="phone" style="border: 1px solid #363650; border-radius: 5px; padding: 6px;" />
</div>
<div style="display: flex; flex-direction: column;">
<p>Access:</p>
<?php
try {
$stmt = $conn->prepare("SELECT * FROM business_verticals");
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$num_rows = $stmt->rowCount();
if ($num_rows >= 1) {
foreach($rows as $row){ ?>
<div>
<input type="checkbox" name="<?php echo $row['bv']; ?>" id="<?php echo $row['bv']; ?>" value="<?php echo $row['bv']; ?>" />
<label for="<?php echo $row['bv']; ?>" style="text-transform: uppercase;"><?php echo $row['bv']; ?></label>
</div>
<?php
}
} else{
echo "<p class='text-danger'>Not Found any Data</p>";
}
} catch (PDOException $e) {
echo "<p class='text-danger'>Error: " . $e->getMessage() . "</p>";
}
?>
</div>
<div style="display: flex; flex-direction: column;">
<p style="font-size: 16px; font-weight: bold; margin-top: 10px;">Access by state:</p>
<div id="selectedStateDisplay"></div>
<div class="dropdown">
<button class="dropbtn" id="selectStatesBtn">Select States</button>
<div class="dropdown-content" id="stateDropdown">
<!-- State options will be populated here -->
</div>
</div>
</div>
<div style="display: flex; flex-direction: column;">
<label for="pass">Password:</label>
<input type="text" name="pass" id="pass" style="border: 1px solid #363650; border-radius: 5px; padding: 6px;" />
</div>
<div style="display: flex; flex-direction: column;">
<input type="submit" name="submit" id="submit" value="Submit" style="background: linear-gradient(90deg, rgba(111, 107, 255, 0.91) 0%, rgba(68, 55, 128, 0.91) 100%); text-align: center; padding: 10px 20px 10px 20px; color: #fff; border-radius: 6px; float: right; margin-top: 30px;" />
</div>
</form>
</div>
<script>
function fetchStates() {
fetch(`https://api.siliconpin.com/v3/list/country/state/?country=IN`)
.then(res => res.json())
.then(data => {
const dropdownContent = document.getElementById('stateDropdown');
dropdownContent.innerHTML = ''; // Clear previous content
data.forEach(state => {
const checkboxDiv = document.createElement('div');
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.name = 'states[]'; // You might want to use an array here if submitting form
checkbox.value = state.iso2;
checkbox.id = state.iso2;
const label = document.createElement('label');
label.textContent = state.name;
label.style = 'text-transform: uppercase';
label.setAttribute('for', state.iso2);
checkboxDiv.appendChild(checkbox);
checkboxDiv.appendChild(label);
dropdownContent.appendChild(checkboxDiv);
// Add event listener to checkbox change
checkbox.addEventListener('change', function() {
updateSelectedStateDisplay();
});
});
});
}
function toggleDropdown() {
const dropdownContent = document.getElementById('stateDropdown');
dropdownContent.classList.toggle('show');
}
// Update the selected state display
function updateSelectedStateDisplay() {
const selectedStates = Array.from(document.querySelectorAll('input[name="states[]"]:checked'))
.map(checkbox => checkbox.parentNode.querySelector('label').textContent);
const selectedStateDisplay = document.getElementById('selectedStateDisplay');
selectedStateDisplay.textContent = 'Selected States: ' + selectedStates.join(', ');
}
// Add an event listener to the button
document.getElementById('selectStatesBtn').addEventListener('click', function(event) {
// Prevent the default form submission behavior
event.preventDefault();
// Toggle the dropdown visibility
toggleDropdown();
});
fetchStates();
</script>
<style>
.dropdown {
position: relative;
display: inline-block;
border: 1px solid #363650;
border-radius: 5px;
width: 100%;
}
.dropbtn {
border: 1px solid #363650;
padding: 6px;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
/* min-width: 160px; */
width: 100%;
overflow-y: auto;
max-height: 230px; /* Adjust as needed */
border: 1px solid #ddd;
z-index: 1;
}
.dropdown-content div {
display: flex;
align-items: center;
padding: 5px;
}
.dropdown-content div label {
margin-left: 5px;
}
.dropdown-content div:hover {
background-color: #ddd;
}
.show {
display: block;
}
/* For small screens */
@media screen and (max-width: 767px) {
#stateCheckboxes {
display: grid;
grid-template-columns: repeat(2, 1fr); /* 2 columns */
gap: 10px; /* Adjust the gap as needed */
}
}
/* For large screens */
@media screen and (min-width: 768px) {
#stateCheckboxes {
display: grid;
grid-template-columns: repeat(3, 1fr); /* 3 columns */
gap: 10px; /* Adjust the gap as needed */
}
}
</style>

View File

@@ -0,0 +1,29 @@
<?php
require_once('/var/www/html/.hta_config/crm_config.php');
require_once('/var/www/html/.htac_header.php');
require_once('/var/www/html/.htac_nav.php');
if($_SERVER['REQUEST_METHOD'] == "POST"){
try {
$conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("DELETE FROM users WHERE id = :id");
$stmt->bindParam(':id', $_POST['id']);
$stmt->execute();
echo '<script>window.location.href = "/admin/users";</script>';
exit();
} catch (PDOException $e) {
echo "<p class='text-danger'>Error: " . $e->getMessage() . "</p>";
}
}
?>
<div>
<form method="post">
<p>Confirm to Delete id <?php echo $_GET['id']; ?>? </p>
<input type="hidden" name="id" value="<?php echo $_GET['id']; ?>">
<input type="submit" name="submit" id="submit" value="YES" />
<a href="/users">NO</a>
</form>
</div>

View File

@@ -0,0 +1,122 @@
<?php
require_once('/var/www/html/.hta_config/crm_config.php');
require_once('/var/www/html/.htac_header.php');
require_once('/var/www/html/.htac_nav.php');
if ($_SERVER["REQUEST_METHOD"] == "POST") {
try {
$conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$select_access = ['beanstalk', 'inhouse', 'teenybeans', 'iimtt', 'buzzapp', 'atheneum', 'teenybeans_curriculum'];
$access_values_array = [];
foreach ($select_access as $access) {
if (isset($_POST[$access])) {
$access_values_array[] = $_POST[$access];
}
}
$access_value = implode(',', $access_values_array);
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$password = md5($_POST['pass']);
$user_id = $_GET['id'];
$stmt = $conn->prepare("UPDATE users SET name = :name, email = :email, mobile = :mobile, access = :access, pass = :pass WHERE id = :id");
$stmt->bindParam(':name', $name);
$stmt->bindParam(':email', $email);
$stmt->bindParam(':mobile', $phone);
$stmt->bindParam(':access', $access_value);
$stmt->bindParam(':pass', $password);
$stmt->bindParam(':id', $user_id);
$stmt->execute();
echo "Record updated successfully";
} catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
?>
<?php
try {
$conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT * FROM users WHERE id = :id");
$stmt->bindParam(':id', $_GET['id']);
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$num_rows = $stmt->rowCount();
if ($num_rows >= 1) {
foreach($rows as $row){?>
<div style="max-width: 600px;">
<form action="" method="post">
<div style="display: flex; flex-direction: column;">
<label for="name">Name:</label>
<input type="text" name="name" id="name" value="<?php echo $row['name'] ?>" />
</div>
<div style="display: flex; flex-direction: column;">
<label for="email">E-mail:</label>
<input type="text" name="email" id="email" value="<?php echo $row['email'] ?>" />
</div>
<div style="display: flex; flex-direction: column;">
<label for="phone">Phone:</label>
<input type="text" name="phone" id="phone" value="<?php echo $row['mobile'] ?>" />
</div>
<div style="display: flex; flex-direction: column;">
<p>Access:</p>
<?php
try {
$conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT * FROM business_verticals");
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$num_rows = $stmt->rowCount();
if ($num_rows >= 1) {
$user_stmt = $conn->prepare("SELECT `access` FROM `users` WHERE `id` = '".$_GET["id"]."'");
$user_stmt->execute();
$user_bvs = $user_stmt->fetchAll(PDO::FETCH_COLUMN);
$user_bvs=explode(",", $user_bvs[0]); // you need to make the CSV to array.
foreach($rows as $row) {
$isChecked = in_array($row['bv'], $user_bvs);
?>
<div>
<input type="checkbox" name="bvs[]" id="<?php echo $row['bv']; ?>" value="<?php echo $row['bv']; ?>" <?php if($isChecked) echo "checked"; ?> />
<label for="<?php echo $row['bv']; ?>" style="text-transform: uppercase;"><?php echo $row['bv']; ?></label>
</div>
<?php
}
} else {
echo "<p class='text-danger'>Not Found any Data</p>";
}
} catch (PDOException $e) {
echo "<p class='text-danger'>Error: " . $e->getMessage() . "</p>";
}
?>
</div>
<div style="display: flex; flex-direction: column;">
<label for="pass">Password:</label>
<input type="text" name="pass" id="pass" />
</div>
<div style="display: flex; flex-direction: column;">
<input type="submit" name="submit" id="submit" value="Submit"/>
</div>
</form>
</div>
<?php
}
} else{
echo "<p class='text-danger'>Not Found any Data</p>";
}
} catch (PDOException $e) {
echo "<p class='text-danger'>Error: " . $e->getMessage() . "</p>";
}
?>

View File

@@ -0,0 +1,130 @@
<?php
require_once('/var/www/html/.hta_config/crm_config.php');
require_once('/var/www/html/.htac_header.php');
require_once('/var/www/html/.htac_nav.php');
try {
$conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// $name = $_POST['name'];
// $email = $_POST['email'];
// $phone = $_POST['phone'];
// $password = md5($_POST['pass']);
try {
$select_access = ['beanstalk', 'inhouse', 'teenybeans', 'iimtt', 'buzzapp', 'atheneum', 'teenybeans_curriculum'];
$access_values_array = [];
foreach ($select_access as $access) {
if (isset($_POST[$access])) {
$access_values_array[] = $_POST[$access];
}
}
$access_value = implode(',', $access_values_array);
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$password = md5($_POST['pass']);
$user_id = $_GET['id'];
$stmt = $conn->prepare("UPDATE users SET name = :name, email = :email, mobile = :mobile, access = :access, pass = :pass WHERE id = :id");
$stmt->bindParam(':name', $name);
$stmt->bindParam(':email', $email);
$stmt->bindParam(':mobile', $phone);
$stmt->bindParam(':access', $access_value);
$stmt->bindParam(':pass', $password);
$stmt->bindParam(':id', $user_id);
$stmt->execute();
echo "Record Updated successfully";
} catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
?>
<?php
try {
$conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT * FROM users WHERE id = :id");
$stmt->bindParam(':id', $_GET['id']);
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$num_rows = $stmt->rowCount();
if ($num_rows >= 1) {
foreach($rows as $row){?>
<div style="max-width: 600px;">
<form action="" method="post">
<div style="display: flex; flex-direction: column;">
<label for="name">Name:</label>
<input type="text" name="name" id="name" value="<?php echo $row['name'] ?>" />
</div>
<div style="display: flex; flex-direction: column;">
<label for="email">E-mail:</label>
<input type="text" name="email" id="email" value="<?php echo $row['email'] ?>" />
</div>
<div style="display: flex; flex-direction: column;">
<label for="phone">Phone:</label>
<input type="text" name="phone" id="phone" value="<?php echo $row['mobile'] ?>" />
</div>
<div style="display: flex; flex-direction: column;">
<p>Access:</p>
<?php
try {
$conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT * FROM business_verticals");
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$num_rows = $stmt->rowCount();
if ($num_rows >= 1) {
$user_stmt = $conn->prepare("SELECT `access` FROM `users` WHERE `id` = '".$_GET["id"]."'");
$user_stmt->execute();
$user_bvs = $user_stmt->fetchAll(PDO::FETCH_COLUMN);
$user_bvs=explode(",", $user_bvs[0]); // you need to make the CSV to array.
foreach($rows as $row) {
$isChecked = in_array($row['bv'], $user_bvs);
?>
<div>
<input type="checkbox" name="<?php echo $row['bv']; ?>" id="<?php echo $row['bv']; ?>" value="<?php echo $row['bv']; ?>" <?php if($isChecked) echo "checked"; ?> />
<label for="<?php echo $row['bv']; ?>" style="text-transform: uppercase;"><?php echo $row['bv']; ?></label>
</div>
<?php
}
} else {
echo "<p class='text-danger'>Not Found any Data</p>";
}
} catch (PDOException $e) {
echo "<p class='text-danger'>Error: " . $e->getMessage() . "</p>";
}
?>
</div>
<div style="display: flex; flex-direction: column;">
<label for="pass">Password:</label>
<input type="text" name="pass" id="pass" />
</div>
<div style="display: flex; flex-direction: column;">
<input type="submit" name="submit" id="submit" value="Submit"/>
</div>
</form>
</div>
<?php
}
} else{
echo "<p class='text-danger'>Not Found any Data</p>";
}
} catch (PDOException $e) {
echo "<p class='text-danger'>Error: " . $e->getMessage() . "</p>";
}
?>