Server : Apache System : Linux 122.228.205.92.host.secureserver.net 5.14.0-362.18.1.el9_3.x86_64 #1 SMP PREEMPT_DYNAMIC Mon Jan 29 07:05:48 EST 2024 x86_64 User : ondostategov ( 1002) PHP Version : 8.1.33 Disable Function : NONE Directory : /home/ondostategov/public_html/ondo_ict_registration2/inc/ |
<?php
include('dbconnection.php');
$database = new database();
$conn = $database->getConnection();
class PortalUtility
{
public function create_user_id()
{
$uni = substr(str_shuffle(str_repeat("0123456789", 10)), 0, 10);
return $uni;
}
public function create_form($conn, $email, $fullname, $gender, $age_range, $state,
$lga, $address, $phone, $emergency_contact, $relationship, $relationship_phone, $education, $employment, $training_location, $has_laptop,
$prior_experience, $additional_skills, $declarant_name,$image)
{
$status = "";
$exists = $this->checkExists($conn, $email);
if ($exists > 0) {
$status = json_encode(array("responseCode" => "00", "message" => "exist", "email" => $email, "timestamp" => date('d-M-Y H:i:s')));
} else {
$user_id = $this->create_user_id();
$sql = "INSERT INTO `users_details`(`user_id`, `email`, `fullname`, `gender`, `age_range`, `state`, `lga`, `address`, `phone`,
`emergency_contact`, `relationship`, `relationship_phone`, `education`, `employment`, `training_location`, `has_laptop`,
`prior_experience`, `additional_skills`, `declarant_name`, `status`,`image`) VALUES ('$user_id','$email','$fullname', '$gender', '$age_range', '$state',
'$lga', '$address', '$phone', '$emergency_contact', '$relationship', '$relationship_phone', '$education', '$employment', '$training_location',
'$has_laptop', '$prior_experience', '$additional_skills', '$declarant_name', 'Y','$image')";
$result = mysqli_query($conn, $sql);
if ($result) {
$status = json_encode(array("responseCode" => "00", "message" => "success", "user_id" => $user_id, "timestamp" => date('d-M-Y H:i:s')));
} else {
$status = json_encode(array("responseCode" => "04", "message" => "fail", "timestamp" => date('d-M-Y H:i:s')));
}
}
$this->server_logs($status);
return $status;
}
public function checkExists($conn, $email) {
$sql = "SELECT * FROM users_details WHERE email = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $email);
$stmt->execute();
$result = $stmt->get_result();
$rows = $result->num_rows;
$stmt->close();
return $rows;
}
public function server_logs($log_msg)
{
$log_filename = "server_logs";
if (!file_exists($log_filename)) {
// create directory/folder uploads.
mkdir($log_filename, 0777, true);
}
$log_file_data = $log_filename . '/log_' . date('d-M-Y') . '.log';
// if you don't add `FILE_APPEND`, the file will be erased each time you add a log
file_put_contents($log_file_data, $log_msg . "\n", FILE_APPEND);
}
public function service_logs($log_msg)
{
$log_filename = "service_logs";
if (!file_exists($log_filename)) {
// create directory/folder uploads.
mkdir($log_filename, 0777, true);
}
$log_file_data = $log_filename . '/log_' . date('d-M-Y') . '.log';
// if you don't add `FILE_APPEND`, the file will be erased each time you add a log
file_put_contents($log_file_data, $log_msg . "\n", FILE_APPEND);
}
}