-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit_project.php
More file actions
109 lines (92 loc) · 3.84 KB
/
Copy pathedit_project.php
File metadata and controls
109 lines (92 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
require_once 'auth.php';
require_once 'db.php';
include 'header.php';
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
if (!isset($_SESSION['company_id'])) {
die("Empresa no seleccionada.");
}
$company_id = $_SESSION['company_id'];
$id = $_GET['id'] ?? null;
if (!$id) {
die("ID de proyecto no proporcionado.");
}
// Validar que el proyecto pertenezca a la empresa activa
$stmt = $pdo->prepare("SELECT * FROM projects WHERE id = ? AND company_id = ?");
$stmt->execute([$id, $company_id]);
$project = $stmt->fetch();
if (!$project) {
die("Proyecto no encontrado o no pertenece a esta empresa.");
}
// Procesar edición
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$name = $_POST['name'];
$client = $_POST['client'];
$start_date = $_POST['start_date'];
$end_date = $_POST['end_date'];
$estimated_end = trim($_POST['estimated_end']);
if ($estimated_end !== '') {
$end_date = null; // vacía la fecha real si se usa estimada
}
$stmt = $pdo->prepare("UPDATE projects SET name = ?, client = ?, start_date = ?, end_date = ?, estimated_end = ? WHERE id = ? AND company_id = ?");
$stmt->execute([$name, $client, $start_date, $end_date ?: null, $estimated_end ?: null, $id, $company_id]);
header("Location: projects.php");
exit();
}
?>
<h2 class="mb-4">✏️ Editar Proyecto</h2>
<div class="card shadow mb-4">
<div class="card-body">
<form method="POST">
<div class="mb-3">
<label class="form-label">Nombre del Proyecto</label>
<input type="text" name="name" class="form-control" value="<?= htmlspecialchars($project['name']) ?>" required>
</div>
<div class="mb-3">
<label class="form-label">Cliente</label>
<input type="text" name="client" class="form-control" value="<?= htmlspecialchars($project['client']) ?>">
</div>
<div class="mb-3">
<label class="form-label">Fecha de Inicio</label>
<input type="date" name="start_date" class="form-control" value="<?= $project['start_date'] ?>" required>
</div>
<div class="mb-3">
<label class="form-label">Fecha de Fin</label>
<div class="row g-1 align-items-center">
<div class="col-auto">
<div class="form-check mt-2">
<input class="form-check-input" type="checkbox" id="estimatedCheckbox" onclick="toggleEstimatedDate()" <?= $project['estimated_end'] ? 'checked' : '' ?>>
<label class="form-check-label small" for="estimatedCheckbox">¿Estimada?</label>
</div>
</div>
<div class="col">
<input type="date" name="end_date" id="end_date" class="form-control" value="<?= $project['end_date'] ?>" <?= $project['estimated_end'] ? 'style="display: none;"' : '' ?>>
<input type="text" name="estimated_end" id="estimated_end" class="form-control" placeholder="Ej. Julio 2025" value="<?= htmlspecialchars((string) $project['estimated_end']) ?>"
<?= $project['estimated_end'] ? '' : 'style="display: none;"' ?>>
</div>
</div>
</div>
<button type="submit" class="btn btn-success">Guardar Cambios</button>
<a href="projects.php" class="btn btn-secondary">Cancelar</a>
</form>
</div>
</div>
<script>
function toggleEstimatedDate() {
const checkbox = document.getElementById('estimatedCheckbox');
const endDate = document.getElementById('end_date');
const estimatedEnd = document.getElementById('estimated_end');
if (checkbox.checked) {
endDate.style.display = 'none';
estimatedEnd.style.display = 'block';
endDate.value = '';
} else {
endDate.style.display = 'block';
estimatedEnd.style.display = 'none';
estimatedEnd.value = '';
}
}
</script>
<?php include 'footer.php'; ?>