Skip to content

Commit

Permalink
Update on select all feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Jumanjigobez committed Dec 21, 2024
1 parent a9c302f commit 3188cbe
Show file tree
Hide file tree
Showing 35 changed files with 2,311 additions and 205 deletions.
19 changes: 10 additions & 9 deletions PHP/admin/addUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
$terms_agreed = $_POST['TermsAgreed'];

function generateUserID() {
$datePart = date("Ymd");
// $datePart = date("Ymd");
$randomPart = generateRandomString(8);
return "user_".$randomPart . $datePart;
return "user_".$randomPart;
}

function generateRandomString($length) {
Expand All @@ -25,13 +25,13 @@ function generateRandomString($length) {
return $randomString;
}

function getRegDate($userId) {
// function getRegDate($userId) {

$RegDate = substr($userId, -8);
if (substr($RegDate, 0, 1) === "2") {
return $RegDate; // Outputs: 20240609
}
}
// $RegDate = substr($userId, -8);
// if (substr($RegDate, 0, 1) === "2") {
// return $RegDate; // Outputs: 20240609
// }
// }

if(!empty($username) && !empty($psk) && !empty($email) && !empty($terms_agreed) && !empty($status) && !empty($user_type)){
$query = $conn->prepare("SELECT * FROM `users` WHERE username = (?) OR email = (?)");
Expand All @@ -46,7 +46,8 @@ function getRegDate($userId) {
echo "Account Exists";
}else{
$user_id = generateUserID();
$reg_date = getRegDate($user_id);
date_default_timezone_set('Africa/Nairobi');
$reg_date = date('Y-m-d H:i:s');
$psk = password_hash($psk,PASSWORD_DEFAULT);//Hashed Password

$query = $conn->prepare("INSERT INTO `users` VALUES((?),(?),(?),(?),(?),(?), (?), (?))");
Expand Down
20 changes: 20 additions & 0 deletions PHP/admin/deleteMarkedUsers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

include "../config.php";

$IdsArray = $_GET['checkedIds'];



$placeholders = implode(',',array_fill(0, count($IdsArray), '?'));
$query = $conn->prepare("DELETE FROM users WHERE user_id IN ($placeholders)");
$query->bind_param(str_repeat('s',count($IdsArray)), ...$IdsArray);
$query->execute();

if ($query){
echo 1;
} else {
echo 0;
}

?>
3 changes: 2 additions & 1 deletion PHP/admin/editUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
$user_type = $_POST['UserType'];
$terms_agreed = $_POST['TermsAgreed'];

$psk_hashed = password_hash($psk,PASSWORD_DEFAULT);//Hashed Password

$query = $conn->prepare("UPDATE users SET
username = (?), email = (?), psk = (?),
status = (?), user_type = (?), terms_agreed = (?) WHERE user_id = (?)");

$query->bind_param("sssssss", $username, $email, $psk, $status, $user_type, $terms_agreed, $user_id);
$query->bind_param("sssssss", $username, $email, $psk_hashed, $status, $user_type, $terms_agreed, $user_id);
$query->execute();

if ($query){
Expand Down
5 changes: 3 additions & 2 deletions PHP/admin/userSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
status like '%{$term}%' OR
user_type like '%{$term}%' OR
terms_agreed like '%{$term}%' OR
reg_date like '%{$term}%'
)
reg_date like '%{$term}%'
) ORDER BY reg_date DESC
");

Expand Down
2 changes: 1 addition & 1 deletion PHP/admin/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

include "../config.php";

$query = $conn->prepare("SELECT * FROM users");
$query = $conn->prepare("SELECT * FROM users ORDER BY reg_date DESC");

if($query->execute()){
$result = $query->get_result();
Expand Down
20 changes: 20 additions & 0 deletions PHP/appointments/deleteMarkedAppointments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

include "../config.php";

$IdsArray = $_GET['checkedIds'];



$placeholders = implode(',',array_fill(0, count($IdsArray), '?'));
$query = $conn->prepare("DELETE FROM appointments WHERE id IN ($placeholders)");
$query->bind_param(str_repeat('i',count($IdsArray)), ...$IdsArray);
$query->execute();

if ($query){
echo 1;
} else {
echo 0;
}

?>
20 changes: 20 additions & 0 deletions PHP/classTimetable/deleteMarkedClassTimetable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

include "../config.php";

$IdsArray = $_GET['checkedIds'];



$placeholders = implode(',',array_fill(0, count($IdsArray), '?'));
$query = $conn->prepare("DELETE FROM class_timetable WHERE id IN ($placeholders)");
$query->bind_param(str_repeat('i',count($IdsArray)), ...$IdsArray);
$query->execute();

if ($query){
echo 1;
} else {
echo 0;
}

?>
20 changes: 20 additions & 0 deletions PHP/contacts/deleteMarkedContacts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

include "../config.php";

$IdsArray = $_GET['checkedIds'];



$placeholders = implode(',',array_fill(0, count($IdsArray), '?'));
$query = $conn->prepare("DELETE FROM contacts WHERE id IN ($placeholders)");
$query->bind_param(str_repeat('i',count($IdsArray)), ...$IdsArray);
$query->execute();

if ($query){
echo 1;
} else {
echo 0;
}

?>
20 changes: 20 additions & 0 deletions PHP/events/deleteMarkedEvents.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

include "../config.php";

$IdsArray = $_GET['checkedIds'];



$placeholders = implode(',',array_fill(0, count($IdsArray), '?'));
$query = $conn->prepare("DELETE FROM events WHERE id IN ($placeholders)");
$query->bind_param(str_repeat('i',count($IdsArray)), ...$IdsArray);
$query->execute();

if ($query){
echo 1;
} else {
echo 0;
}

?>
20 changes: 20 additions & 0 deletions PHP/goals/deleteMarkedGoals.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

include "../config.php";

$IdsArray = $_GET['checkedIds'];



$placeholders = implode(',',array_fill(0, count($IdsArray), '?'));
$query = $conn->prepare("DELETE FROM goals WHERE id IN ($placeholders)");
$query->bind_param(str_repeat('i',count($IdsArray)), ...$IdsArray);
$query->execute();

if ($query){
echo 1;
} else {
echo 0;
}

?>
18 changes: 17 additions & 1 deletion PHP/payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,30 @@

$user_id = $_GET['user_id'];

function formatToLocaleString($value) {
// Remove any commas from the string
$number = str_replace(',', '', $value);

// Convert the string to a float
$number = (float)$number;

// Format the number with commas as thousands separators
$formattedNumber = number_format($number,2, '.', ',');

return (string)$formattedNumber;
}

if(!empty($TransCode)&&!empty($AccNo)&&!empty($AccName)&&!empty($Amount)&&!empty($Date)&&!empty($Type)){

$DateValue = ($Date !== ' ') ? $Date : null;
$formatedAmount = formatToLocaleString($Amount);

$query = $conn->prepare("INSERT INTO payments (
`Trans. Code`, `Acc. No.`, `Acc. Name`,Amount, Date, Type, user_id
) VALUES (?, ?, ?, ?, ?, ?, ?)");

$query->bind_param("sssssss",
$TransCode, $AccNo, $AccName, $Amount, $DateValue, $Type, $user_id);
$TransCode, $AccNo, $AccName, $formatedAmount, $DateValue, $Type, $user_id);

$query->execute();//Execute the query

Expand Down
20 changes: 20 additions & 0 deletions PHP/payments/deleteMarkedPayments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

include "../config.php";

$IdsArray = $_GET['checkedIds'];



$placeholders = implode(',',array_fill(0, count($IdsArray), '?'));
$query = $conn->prepare("DELETE FROM payments WHERE id IN ($placeholders)");
$query->bind_param(str_repeat('i',count($IdsArray)), ...$IdsArray);
$query->execute();

if ($query){
echo 1;
} else {
echo 0;
}

?>
17 changes: 16 additions & 1 deletion PHP/payments/editPayments.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,27 @@
$Date = $_POST['Date'];
$Type = $_POST['Type'];

function formatToLocaleString($value) {
// Remove any commas from the string
$number = str_replace(',', '', $value);

// Convert the string to a float
$number = (float)$number;

// Format the number with commas as thousands separators
$formattedNumber = number_format($number,2, '.', ',');

return (string)$formattedNumber;
}


$formatedAmount = formatToLocaleString($Amount);

$query = $conn->prepare("UPDATE payments SET
`Trans. Code` = (?), `Acc. No.` = (?), `Acc. Name` = (?),
Amount = (?), Date = (?), Type = (?) WHERE id = (?)");

$query->bind_param("sssssss", $TransCode, $AccNo, $AccName, $Amount, $Date, $Type, $id);
$query->bind_param("sssssss", $TransCode, $AccNo, $AccName, $formatedAmount, $Date, $Type, $id);
$query->execute();

if ($query){
Expand Down
20 changes: 20 additions & 0 deletions PHP/personalTimetable/deleteMarkedPersonalTimetable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

include "../config.php";

$IdsArray = $_GET['checkedIds'];



$placeholders = implode(',',array_fill(0, count($IdsArray), '?'));
$query = $conn->prepare("DELETE FROM personal_timetable WHERE id IN ($placeholders)");
$query->bind_param(str_repeat('i',count($IdsArray)), ...$IdsArray);
$query->execute();

if ($query){
echo 1;
} else {
echo 0;
}

?>
20 changes: 20 additions & 0 deletions PHP/projects/deleteMarkedProjects.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

include "../config.php";

$IdsArray = $_GET['checkedIds'];



$placeholders = implode(',',array_fill(0, count($IdsArray), '?'));
$query = $conn->prepare("DELETE FROM projects WHERE id IN ($placeholders)");
$query->bind_param(str_repeat('i',count($IdsArray)), ...$IdsArray);
$query->execute();

if ($query){
echo 1;
} else {
echo 0;
}

?>
2 changes: 1 addition & 1 deletion PHP/psk/forgot.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'jumagobe3@gmail.com';//your email

$mail->Password = '';//your email password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = '587';

Expand Down
19 changes: 10 additions & 9 deletions PHP/signup.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@


function generateUserID() {
$datePart = date("Ymd");
// $datePart = date("Ymd");
$randomPart = generateRandomString(8);
return "user_".$randomPart . $datePart;
return "user_".$randomPart;
}

function generateRandomString($length) {
Expand All @@ -25,13 +25,13 @@ function generateRandomString($length) {
return $randomString;
}

function getRegDate($userId) {
// function getRegDate($userId) {

$RegDate = substr($userId, -8);
if (substr($RegDate, 0, 1) === "2") {
return $RegDate; // Outputs: 20240609
}
}
// $RegDate = substr($userId, -8);
// if (substr($RegDate, 0, 1) === "2") {
// return $RegDate; // Outputs: 20240609
// }
// }

if(!empty($username) && !empty($psk) && !empty($email) && $terms_check){
$query = $conn->prepare("SELECT * FROM `users` WHERE username = (?) OR email = (?)");
Expand All @@ -46,7 +46,8 @@ function getRegDate($userId) {
echo "Account Exists";
}else{
$user_id = generateUserID();
$reg_date = getRegDate($user_id);
date_default_timezone_set('Africa/Nairobi');
$reg_date = date('Y-m-d H:i:s');
$user_type = "normal";
$status = "offline";
$terms_check = "Agreed";
Expand Down
Loading

0 comments on commit 3188cbe

Please sign in to comment.