alert('$message'); window.location.href = '$redirectUrl'; "; exit(); } else { setcookie($_COOKIE["username"], '', time() - 3600, '/'); header("Location: https://blackhoundenterprises.com/invoices/index.php"); exit(); } } } else { setcookie($_COOKIE["username"], '', time() - 3600, '/'); header("Location: https://blackhoundenterprises.com/invoices/index.php"); exit(); } if(isset($_GET['logout']) && $_GET['logout'] == 1) { // Delete the cookie by setting its expiration time to a past value setcookie("username", $_COOKIE["username"], time() - 3600, '/'); // Redirect to the login page or any other page header("Location: https://blackhoundenterprises.com/invoices/index.php"); exit(); } // Check if the projects.db file exists, and if not, create it $dbFile2 = 'database/projects.db'; if (!file_exists($dbFile2)) { $db = new SQLite3($dbFile2); if (!$db) { die("Failed to create the database file."); } // Create the 'projects' table $createQuery = "CREATE TABLE IF NOT EXISTS projects ( id INTEGER PRIMARY KEY AUTOINCREMENT, projectname TEXT, erfno TEXT, allotment TEXT, client TEXT, clientid TEXT, clientprogress TEXT )"; $db->exec($createQuery); if (!$db->exec($createQuery)) { die("Failed to create the 'projects' table."); } $db->close(); } else { $db = new SQLite3($dbFile2); if (!$db) { die("Database connection failed: " . $db->lastErrorMsg()); } } // Function to fetch and display data function displayData($db) { $activeCount = 0; $completedCount = 0; $activeProjects = []; $completedProjects = []; $query = "SELECT id, projectname, clientprogress FROM projects"; $result = $db->query($query); while ($row = $result->fetchArray(SQLITE3_ASSOC)) { $projectName = $row['projectname']; $projectData = $row['clientprogress']; $dataParts = explode('«', $projectData ); $projectOverallProgress = $dataParts[3]; $overallProgress = str_replace("%", "", $projectOverallProgress); if ($overallProgress == 100.00){ $completedCount +=1; $completedProjects[] = $projectName; } else { $activeCount +=1; $activeProjects[] = $projectName; } } // Echo JavaScript variables immediately echo ""; } ?>