D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
inventory.tapaslights.com
/
Filename :
add_project.php
back
Copy
<?php require 'config.php'; // Initialize messages $error_message = ''; $success_message = ''; if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Sanitize input values $project_name = filter_input(INPUT_POST, 'project_name', FILTER_SANITIZE_STRING); $location = filter_input(INPUT_POST, 'location', FILTER_SANITIZE_STRING); $contact_person_name = filter_input(INPUT_POST, 'contact_person_name', FILTER_SANITIZE_STRING); $contact_person_phone = filter_input(INPUT_POST, 'contact_person_phone', FILTER_SANITIZE_STRING); $contact_person_email = filter_input(INPUT_POST, 'contact_person_email', FILTER_SANITIZE_EMAIL); $project_engineer_name = filter_input(INPUT_POST, 'project_engineer_name', FILTER_SANITIZE_STRING); $project_engineer_phone = filter_input(INPUT_POST, 'project_engineer_phone', FILTER_SANITIZE_STRING); $project_engineer_email = filter_input(INPUT_POST, 'project_engineer_email', FILTER_SANITIZE_EMAIL); $estimate_project_value = filter_input(INPUT_POST, 'estimate_project_value', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); $project_start_amount = filter_input(INPUT_POST, 'project_start_amount', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); $no_of_labours = filter_input(INPUT_POST, 'no_of_labours', FILTER_SANITIZE_NUMBER_INT); $project_start_date = $_POST['project_start_date']; $project_deadline = $_POST['project_deadline']; $completed_steps = $_POST['completed_steps'] ?? []; $list_of_works = filter_input(INPUT_POST, 'list_of_works', FILTER_SANITIZE_STRING); $created_at = date('Y-m-d H:i:s'); // Calculate progress percentage $project_progress = round((count($completed_steps) / 5) * 100); // Validation if (empty($project_name) || empty($contact_person_email) || !filter_var($contact_person_email, FILTER_VALIDATE_EMAIL)) { $error_message = "Please fill out required fields correctly."; } if (empty($error_message)) { $sql = "INSERT INTO projects ( project_name, location, contact_person_name, contact_person_phone, contact_person_email, project_engineer_name, project_engineer_phone, project_engineer_email, estimate_project_value, project_start_amount, no_of_labours, project_start_date, project_deadline, project_progress, list_of_works, created_at ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; $stmt = $conn->prepare($sql); if ($stmt) { $stmt->bind_param( "ssssssssddisssss", $project_name, $location, $contact_person_name, $contact_person_phone, $contact_person_email, $project_engineer_name, $project_engineer_phone, $project_engineer_email, $estimate_project_value, $project_start_amount, $no_of_labours, $project_start_date, $project_deadline, $project_progress, $list_of_works, $created_at ); if ($stmt->execute()) { $project_id = $stmt->insert_id; // Add progress steps with completion status $steps = ['Foundation', 'Base Floor', 'Ground Floor', 'First Floor', 'Second Floor']; $step_stmt = $conn->prepare("INSERT INTO project_progress_steps (project_id, step_name, is_completed) VALUES (?, ?, ?)"); foreach ($steps as $step) { $is_completed = in_array($step, $completed_steps) ? 1 : 0; $step_stmt->bind_param("isi", $project_id, $step, $is_completed); $step_stmt->execute(); } $step_stmt->close(); $success_message = "Project added successfully with progress tracking!"; } else { $error_message = "Database error: " . $stmt->error; } $stmt->close(); } else { $error_message = "Prepare failed: " . $conn->error; } } } ?> <!DOCTYPE html> <html lang="en"> <head> <?php include 'style.php'; ?> <style> /* Progress Steps */ .step-card { border: 2px solid #dee2e6; transition: all 0.2s ease-in-out; border-radius: 10px; text-align: left; position: relative; overflow: hidden; } .step-card:hover { border-color: #adb5bd; box-shadow: 0 0 10px rgba(0,0,0,0.1); } .step-card.selected { background-color: #e8f5e9; border-color: #4caf50; } .step-card.selected::after { content: "✓"; position: absolute; top: 5px; right: 10px; color: #4caf50; font-weight: bold; } .step-number { width: 25px; height: 25px; background: #f8f9fa; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: bold; border: 1px solid #dee2e6; } /* Circular Progress */ .circular-chart { display: block; margin: 0 auto; max-width: 100%; max-height: 100%; } .circle-bg { fill: none; stroke: #eee; stroke-width: 3.8; } .circle { fill: none; stroke-width: 2.8; stroke-linecap: round; stroke: #4caf50; transition: all 0.6s ease; } .percentage { fill: #666; font-family: sans-serif; font-size: 0.5em; text-anchor: middle; font-weight: bold; } /* Progress Bar */ .progress-bar { font-weight: bold; transition: width 0.6s ease; } /* Layout */ .progress-visualization { background: #f8f9fa; border-radius: 10px; padding: 20px; margin-bottom: 20px; } .progress-container { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; } .progress-item { flex: 1; min-width: 200px; } </style> </head> <body> <div class="main-wrapper"> <?php include 'header.php'; ?> <?php include 'sidebar.php'; ?> <div class="page-wrapper"> <div class="content container-fluid"> <div class="row"> <div class="col-lg-12"> <div class="card"> <div class="card-header"> <h5 class="card-title">Create Project</h5> <?php if ($success_message): ?> <div class="alert alert-success"><?php echo $success_message; ?></div> <?php elseif ($error_message): ?> <div class="alert alert-danger"><?php echo $error_message; ?></div> <?php endif; ?> </div> <div class="card-body"> <form action="" method="post"> <!-- Project Information --> <div class="input-block mb-3 row"> <label class="col-form-label col-md-2">Project Name</label> <div class="col-md-10"> <input type="text" name="project_name" class="form-control" required> </div> </div> <div class="input-block mb-3 row"> <label class="col-form-label col-md-2">Location</label> <div class="col-md-10"> <input type="text" name="location" class="form-control" required> </div> </div> <!-- Contact Information --> <div class="input-block mb-3 row"> <label class="col-form-label col-md-2">Contact Person Name</label> <div class="col-md-10"> <input type="text" name="contact_person_name" class="form-control" required> </div> </div> <div class="input-block mb-3 row"> <label class="col-form-label col-md-2">Contact Person Phone</label> <div class="col-md-10"> <input type="tel" name="contact_person_phone" class="form-control" required> </div> </div> <div class="input-block mb-3 row"> <label class="col-form-label col-md-2">Contact Person Email</label> <div class="col-md-10"> <input type="email" name="contact_person_email" class="form-control" required> </div> </div> <!-- Engineer Information --> <div class="input-block mb-3 row"> <label class="col-form-label col-md-2">Project Engineer Name</label> <div class="col-md-10"> <input type="text" name="project_engineer_name" class="form-control"> </div> </div> <div class="input-block mb-3 row"> <label class="col-form-label col-md-2">Project Engineer Phone</label> <div class="col-md-10"> <input type="text" name="project_engineer_phone" class="form-control"> </div> </div> <div class="input-block mb-3 row"> <label class="col-form-label col-md-2">Project Engineer Email</label> <div class="col-md-10"> <input type="email" name="project_engineer_email" class="form-control"> </div> </div> <!-- Financial Information --> <div class="input-block mb-3 row"> <label class="col-form-label col-md-2">Estimated Project Value</label> <div class="col-md-10"> <input type="number" step="0.01" name="estimate_project_value" class="form-control" required> </div> </div> <div class="input-block mb-3 row"> <label class="col-form-label col-md-2">Project Start Amount</label> <div class="col-md-10"> <input type="number" step="0.01" name="project_start_amount" class="form-control" required> </div> </div> <div class="input-block mb-3 row"> <label class="col-form-label col-md-2">Number of Labours</label> <div class="col-md-10"> <input type="number" name="no_of_labours" class="form-control" required> </div> </div> <!-- Timeline Information --> <div class="input-block mb-3 row"> <label class="col-form-label col-md-2">Project Start Date</label> <div class="col-md-10"> <input type="date" name="project_start_date" class="form-control" required> </div> </div> <div class="input-block mb-3 row"> <label class="col-form-label col-md-2">Project Deadline</label> <div class="col-md-10"> <input type="date" name="project_deadline" class="form-control" required> </div> </div> <!-- Progress Tracking --> <div class="input-block mb-3 row"> <label class="col-form-label col-md-2">Project Progress</label> <div class="col-md-10"> <div class="progress-visualization"> <div class="progress-container"> <div class="progress-item"> <div class="progress mb-3" style="height: 25px;"> <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" id="progress-bar" style="width: 0%" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"> <span id="progress-text">0%</span> </div> </div> </div> <div class="progress-item text-center"> <div class="progress-circle" style="width: 80px; height: 80px; display: inline-block;"> <svg viewBox="0 0 36 36" class="circular-chart"> <path class="circle-bg" d="M18 2.0845 a 15.9155 15.9155 0 0 1 0 31.831 a 15.9155 15.9155 0 0 1 0 -31.831" /> <path class="circle" stroke-dasharray="0, 100" d="M18 2.0845 a 15.9155 15.9155 0 0 1 0 31.831 a 15.9155 15.9155 0 0 1 0 -31.831" id="progress-circle" /> <text x="18" y="20.35" class="percentage" id="circle-text">0%</text> </svg> </div> </div> </div> <div class="row g-3" id="progress-steps"> <?php $steps = ['Foundation', 'Base Floor', 'Ground Floor', 'First Floor', 'Second Floor']; foreach ($steps as $index => $step) { $step_num = $index + 1; echo ' <div class="col-md-4"> <div class="form-check card p-3 step-card" style="cursor:pointer;"> <input class="form-check-input d-none progress-step" type="checkbox" name="completed_steps[]" value="' . $step . '" id="step-' . $step_num . '"> <label class="form-check-label w-100 fw-semibold" for="step-' . $step_num . '"> <div class="d-flex align-items-center"> <div class="step-number me-2">' . $step_num . '</div> <div>' . $step . '</div> </div> </label> </div> </div>'; } ?> </div> </div> </div> </div> <!-- Additional Information --> <div class="input-block mb-3 row"> <label class="col-form-label col-md-2">List of Works</label> <div class="col-md-10"> <textarea name="list_of_works" class="form-control" rows="3"></textarea> </div> </div> <!-- Form Actions --> <div class="input-block mb-3 mb-0 row"> <div class="col-md-10 offset-md-2"> <div class="d-flex justify-content-end"> <button class="btn btn-success m-2" type="submit">Submit</button> <button class="btn btn-danger m-2" type="reset">Reset</button> </div> </div> </div> </form> </div> </div> </div> </div> </div> </div> <?php include 'footer.php'; ?> </div> <script> document.addEventListener('DOMContentLoaded', function() { // Toggle step selection and update progress document.querySelectorAll('.step-card').forEach(card => { card.addEventListener('click', function() { const checkbox = this.querySelector('input.progress-step'); checkbox.checked = !checkbox.checked; this.classList.toggle('selected', checkbox.checked); updateProgressVisualization(); }); }); // Update all progress indicators function updateProgressVisualization() { const steps = document.querySelectorAll('.progress-step'); const completed = Array.from(steps).filter(step => step.checked).length; const total = steps.length; const percentage = Math.round((completed / total) * 100); // Update progress bar const progressBar = document.getElementById('progress-bar'); progressBar.style.width = percentage + '%'; progressBar.setAttribute('aria-valuenow', percentage); progressBar.querySelector('#progress-text').textContent = percentage + '%'; // Update circular progress const circle = document.getElementById('progress-circle'); const circleText = document.getElementById('circle-text'); const circumference = 2 * Math.PI * 15.9155; const dashoffset = circumference - (percentage / 100) * circumference; circle.style.strokeDasharray = `${circumference}`; circle.style.strokeDashoffset = dashoffset; circleText.textContent = percentage + '%'; // Change colors based on percentage if (percentage < 30) { circle.style.stroke = '#f44336'; progressBar.className = 'progress-bar progress-bar-striped progress-bar-animated bg-danger'; } else if (percentage < 70) { circle.style.stroke = '#ffc107'; progressBar.className = 'progress-bar progress-bar-striped progress-bar-animated bg-warning'; } else { circle.style.stroke = '#4caf50'; progressBar.className = 'progress-bar progress-bar-striped progress-bar-animated bg-success'; } } // Initialize progress visualization updateProgressVisualization(); }); </script> </body> </html>