') !== false) { $projectname = preg_replace('//i', '', $projectname); } $erfno = $_POST["erfno"]; $allotment = $_POST["allotment"]; $client = $_POST["client"]; $deposit= $_POST["deposit"]; $totalfees = $_POST["totalfees"]; // Set the time zone to your desired time zone date_default_timezone_set('Africa/Johannesburg'); // Get the current date and time $currentDateTime = date('Y-m-d H:i'); $clientprogress = $currentDateTime; $db2 = new SQLite3('database/clients.db'); $query2 = "SELECT name, id FROM clients"; $result2 = $db2->query($query2); // Populate the dropdown with data while ($row2 = $result2->fetchArray()) { if ($row2['name'] == $client) { $clientid = $row2['id']; } } $db2->close(); $db = new SQLite3('database/projects.db'); // Prepare and execute the INSERT query to add the client to the database $insertQuery = "INSERT INTO projects (projectname, erfno, allotment, client, clientid, clientprogress) VALUES ('$projectname', '$erfno', '$allotment', '$client', $clientid, '$clientprogress')"; $db->exec($insertQuery); $newRowID = $db->lastInsertRowID(); $currentDate = date('Y-m-d'); $currentYear = date('Y'); // Remove all non-numeric characters except for the decimal point $numericPartTotalfees = preg_replace('/[^0-9.]/', '', $totalfees); $phaseFeeValueTotalfees = floatval($numericPartTotalfees); // Remove all non-numeric characters except for the decimal point for the deposit $numericPartDeposit = preg_replace('/[^0-9.]/', '', $deposit); $phaseFeeValueDeposit = floatval($numericPartDeposit); // Calculate the Fees $Fees = $phaseFeeValueTotalfees - $phaseFeeValueDeposit; $formattedFees = formatNumberWithSpaces($Fees); $formattedDeposit = formatNumberWithSpaces($deposit); $clientprogress = $currentDate . "«" . $projectname . "«" . $currentYear . $newRowID . "«" . "50%" . "«" . "Project Started, Coming Soon" . "«" . "100%, 0%" . "«" . $currentDate . " - Started., " . "Not Started" . "«" . $currentDateTime . ", " . $currentDateTime . "«" . $formattedDeposit . ", " . $formattedFees; // Update $clientprogress to include the new row ID // $clientprogress .= " (Row ID: $newRowID)"; // Adjust the format as needed // Optionally, if you want to update the database with the new client progress including the row ID $updateQuery = "UPDATE projects SET clientprogress = '$clientprogress' WHERE rowid = $newRowID"; $db->exec($updateQuery); // Close the database connection $db->close(); /// FTP Creating Project Folder $ftp_server = "blackhoundenterprises.myqnapcloud.com"; $ftp_username = "BHDomain02"; $ftp_password = "h&92#8C7g92d}&B"; $ftp_port = 21; $remote_directory1 = "/$currentYear"; $remote_directory2 = "/$projectname"; // Establish FTP connection $conn_id = ftp_connect($ftp_server, $ftp_port); if (!$conn_id) { die("Couldn't connect to FTP server."); } // Login to FTP $login_result = ftp_login($conn_id, $ftp_username, $ftp_password); if (!$login_result) { ftp_close($conn_id); die("Couldn't log in to FTP server."); } // Set passive mode ftp_pasv($conn_id, true); // Check if the upload folder exists $remote_folder_exists = ftp_chdir($conn_id, $remote_directory1); if (!$remote_folder_exists) { // Folder doesn't exist, so create it if (!ftp_mkdir($conn_id, $remote_directory1)) { ftp_close($conn_id); die("Failed to create 'Upload' directory on FTP server."); } // Change to the newly created directory ftp_chdir($conn_id, $remote_directory1); } // Check if the upload folder exists $remote_folder_exists = ftp_chdir($conn_id, $remote_directory1 . "/" . $remote_directory2); if (!$remote_folder_exists) { // Folder doesn't exist, so create it if (!ftp_mkdir($conn_id, $remote_directory1 . "/" . $remote_directory2)) { ftp_close($conn_id); die("Failed to create 'Upload' directory on FTP server."); } // Change to the newly created directory ftp_chdir($conn_id, $remote_directory1 . "/" . $remote_directory2); } // Ensure files are uploaded if (!empty($_FILES['files']['name'][0])) { foreach ($_FILES['files']['name'] as $key => $name) { $tmpName = $_FILES['files']['tmp_name'][$key]; $remote_file = $remote_directory1 . "/" . $remote_directory2 . "/" . basename($name); // Upload file to FTP server if (ftp_put($conn_id, $remote_file, $tmpName, FTP_BINARY)) { echo "$name uploaded successfully to FTP.\n"; } else { echo "Failed to upload $name to FTP.\n"; } } } else { echo "No files selected."; } // Close FTP connection ftp_close($conn_id); ?>