Files
crm_php/.hta_slug/users/edit-user copy.php
2024-05-01 18:13:22 +05:30

122 lines
5.4 KiB
PHP

<?php
require_once('.hta_config/crm_config.php');
require_once('.htac_header.php');
require_once('.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>";
}
?>