This commit is contained in:
Kar l5
2024-05-06 16:29:00 +05:30
parent 757e44b02d
commit 13133d2d2a
21 changed files with 820 additions and 2991 deletions

View File

@@ -10,32 +10,70 @@
}
if ($_SERVER["REQUEST_METHOD"] == "POST" && $_POST['name'] && $_POST['pass'] && $_POST['email']) {
$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];
$mysqli = new mysqli($mariaServer, $mariaUser, $mariaPass, $mariaDb);
if ($mysqli->connect_error) die("Connection failed: " . $mysqli->connect_error);
$result = $mysqli->query("SELECT bv FROM business_verticals");
if ($result) {
$access_array = array();
while ($row = $result->fetch_assoc()) {
$access_array[] = $row['bv'];
}
}
$access_value = implode(',', $access_values_array);
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$password = md5($_POST['pass']);
$selected_states = implode(',', $_POST['selectedStates']); // Collect selected state values
// $access_array = ['beanstalk', 'inhouse', 'teenybeans', 'iimtt', 'buzzapp', 'atheneum', 'teenybeans_curriculum'];
$access_values_array = [];
foreach ($access_array as $access) {
if (isset($_POST[$access])) {
$access_values_array[] = $_POST[$access];
}
}
$selected_access = implode(',', $access_values_array);
$result->free();
// print_r($access_array);
} else { echo "Error: " . $mysqli->error; }
$mysqli->close();
$apiUrl = 'https://api.siliconpin.com/v3/list/country/state/?country=IN';
$handle = fopen($apiUrl, 'rb');
if ($handle === false) {
echo 'Unable to open URL';
} else {
$jsonResponse = stream_get_contents($handle);
fclose($handle);
$states = json_decode($jsonResponse, true);
if ($states === null) {
echo 'Error decoding JSON from API';
} else {
$state_values_array = [];
if (isset($_POST['international'])) $state_values_array[] ='international';
foreach ($states as $state) {
if (isset($_POST[$state['iso2']])) $state_values_array[] = $_POST[$state['iso2']];
}
$selected_states = implode(',', $state_values_array);
}
}
try {
$pass=md5($_POST['pass']);
$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(':name', $_POST['name']);
$stmt->bindParam(':email', $_POST['email']);
$stmt->bindParam(':mobile', $_POST['phone']);
$stmt->bindParam(':access', $selected_access);
$stmt->bindParam(':pass', $pass);
$stmt->bindParam(':states', $selected_states); // Bind selected states
$stmt->execute();
echo "Record added successfully";
echo "A new user added.";
} catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
@@ -136,11 +174,39 @@
?>
</div>
</div>
<hr> <br>
<div style="display: flex; flex-direction: column;">
<p style="font-size: 16px; font-weight: bold; margin-top: 10px;">Access by state:</p>
<div class="" id="stateList">
<!-- State checkboxes will be dynamically added here -->
</div>
<p style="font-size: 16px; font-weight: bold; margin-top: 10px;"> Responsible Area:</p>
<div class="flex flex-row">
<input type="checkbox" name="international" id="international" value="international" /> &nbsp;&nbsp;
<label for="international" style="text-transform: uppercase;">international</label>
</div>
<hr><br>
<div style="height:200px; overflow:scroll;white-space: nowrap; overflow-x: visible;">
<?php
$apiUrl = 'https://api.siliconpin.com/v3/list/country/state/?country=IN';
$handle = fopen($apiUrl, 'rb');
if ($handle === false) {
echo 'Unable to open URL';
} else {
$jsonResponse = stream_get_contents($handle);
fclose($handle);
$states = json_decode($jsonResponse, true);
if ($states === null) {
echo 'Error decoding JSON from API';
} else {
foreach ($states as $state) {
echo '<input type="checkbox" id="'.$state["iso2"].'" name="'.$state["iso2"].'"'. ' value="' . $state["iso2"] . '" />';
echo '<label for="' . $state["iso2"] . '">' . $state["name"] . '</label><br>';
}
}
}
?>
</div>
</div>
<div style="display: flex; flex-direction: column;">
<label for="pass">Password:</label>
@@ -153,23 +219,23 @@
</div>
<script>
// JavaScript code to fetch data and populate checkboxes
fetch(`https://api.siliconpin.com/v3/list/country/state/?country=IN`)
.then(res => res.json())
.then(data => {
const stateList = document.getElementById('stateList');
data.forEach(state => {
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.value = state.iso2;
checkbox.name = 'selectedStates[]'; // Adjust name as per your form's needs
// fetch(`https://api.siliconpin.com/v3/list/country/state/?country=IN`)
// .then(res => res.json())
// .then(data => {
// const stateList = document.getElementById('stateList');
// data.forEach(state => {
// const checkbox = document.createElement('input');
// checkbox.type = 'checkbox';
// checkbox.value = state.iso2;
// checkbox.name = 'selectedStates[]'; // Adjust name as per your form's needs
const label = document.createElement('label');
label.appendChild(checkbox);
label.appendChild(document.createTextNode('\u00A0' + state.name)); // Adding a non-breaking space before the state name
// const label = document.createElement('label');
// label.appendChild(checkbox);
// label.appendChild(document.createTextNode('\u00A0' + state.name)); // Adding a non-breaking space before the state name
stateList.appendChild(label);
});
});
// stateList.appendChild(label);
// });
// });
function toggleDisplay() {
var element = document.getElementById('add-user-form');
if (element.style.display === 'block') {