update charity members

This commit is contained in:
Flatlogic Bot 2026-04-13 17:38:04 +00:00
parent bd29389176
commit 2d8e8f2776
3 changed files with 37 additions and 13 deletions

View File

@ -1,6 +1,14 @@
<?php
require_once 'includes/header.php';
// Auto-fix existing records that have NULL created_by/updated_by (e.g. from deployed database before triggers)
try {
if (db()->query("SELECT COUNT(*) FROM charity_members WHERE created_by IS NULL OR updated_by IS NULL")->fetchColumn() > 0) {
db()->query("UPDATE charity_members SET created_by = 1 WHERE created_by IS NULL");
db()->query("UPDATE charity_members SET updated_by = 1 WHERE updated_by IS NULL");
}
} catch (Exception $e) {}
if (!isAdmin() && !canView('charity_members')) {
echo "<div class='alert alert-danger'>غير مصرح لك بالوصول لهذه الصفحة.</div>";
require_once 'includes/footer.php';
@ -18,8 +26,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$join_date = $_POST['join_date'] ?? date('Y-m-d');
$status = $_POST['status'] ?? 'active';
$stmt = db()->prepare("INSERT INTO charity_members (name, role, phone, email, join_date, status) VALUES (?, ?, ?, ?, ?, ?)");
$stmt->execute([$name, $role, $phone, $email, $join_date, $status]);
$stmt = db()->prepare("INSERT INTO charity_members (name, role, phone, email, join_date, status, created_by, updated_by) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([$name, $role, $phone, $email, $join_date, $status, $_SESSION['user_id'], $_SESSION['user_id']]);
$_SESSION['success'] = "تمت إضافة العضو بنجاح.";
redirect('charity_members.php');
@ -32,8 +40,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$join_date = $_POST['join_date'] ?? date('Y-m-d');
$status = $_POST['status'] ?? 'active';
$stmt = db()->prepare("UPDATE charity_members SET name = ?, role = ?, phone = ?, email = ?, join_date = ?, status = ? WHERE id = ?");
$stmt->execute([$name, $role, $phone, $email, $join_date, $status, $id]);
$stmt = db()->prepare("UPDATE charity_members SET name = ?, role = ?, phone = ?, email = ?, join_date = ?, status = ?, updated_by = ? WHERE id = ?");
$stmt->execute([$name, $role, $phone, $email, $join_date, $status, $_SESSION['user_id'], $id]);
$_SESSION['success'] = "تم تحديث العضو بنجاح.";
redirect('charity_members.php');

View File

@ -1,6 +1,14 @@
<?php
require_once 'includes/header.php';
// Auto-fix existing records that have NULL created_by/updated_by
try {
if (db()->query("SELECT COUNT(*) FROM charity_plans WHERE created_by IS NULL OR updated_by IS NULL")->fetchColumn() > 0) {
db()->query("UPDATE charity_plans SET created_by = 1 WHERE created_by IS NULL");
db()->query("UPDATE charity_plans SET updated_by = 1 WHERE updated_by IS NULL");
}
} catch (Exception $e) {}
if (!isAdmin() && !canView('charity_plans')) {
echo "<div class='alert alert-danger'>غير مصرح لك بالوصول لهذه الصفحة.</div>";
require_once 'includes/footer.php';
@ -17,8 +25,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$achieved_value = (int)($_POST['achieved_value'] ?? 0);
$status = $_POST['status'] ?? 'pending';
$stmt = db()->prepare("INSERT INTO charity_plans (title, description, start_date, end_date, target_value, achieved_value, status) VALUES (?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([$title, $description, $start_date, $end_date, $target_value, $achieved_value, $status]);
$stmt = db()->prepare("INSERT INTO charity_plans (title, description, start_date, end_date, target_value, achieved_value, status, created_by, updated_by) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([$title, $description, $start_date, $end_date, $target_value, $achieved_value, $status, $_SESSION['user_id'], $_SESSION['user_id']]);
$_SESSION['success'] = "تمت إضافة الخطة بنجاح.";
redirect('charity_plans.php');
} elseif (isset($_POST['edit_plan']) && (isAdmin() || canEdit('charity_plans'))) {
@ -31,8 +39,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$achieved_value = (int)($_POST['achieved_value'] ?? 0);
$status = $_POST['status'] ?? 'pending';
$stmt = db()->prepare("UPDATE charity_plans SET title = ?, description = ?, start_date = ?, end_date = ?, target_value = ?, achieved_value = ?, status = ? WHERE id = ?");
$stmt->execute([$title, $description, $start_date, $end_date, $target_value, $achieved_value, $status, $id]);
$stmt = db()->prepare("UPDATE charity_plans SET title = ?, description = ?, start_date = ?, end_date = ?, target_value = ?, achieved_value = ?, status = ?, updated_by = ? WHERE id = ?");
$stmt->execute([$title, $description, $start_date, $end_date, $target_value, $achieved_value, $status, $_SESSION['user_id'], $id]);
$_SESSION['success'] = "تم تحديث الخطة بنجاح.";
redirect('charity_plans.php');
} elseif (isset($_POST['delete_plan']) && (isAdmin() || canDelete('charity_plans'))) {

View File

@ -1,6 +1,14 @@
<?php
require_once __DIR__ . '/includes/header.php';
// Auto-fix existing records that have NULL created_by/updated_by
try {
if (db()->query("SELECT COUNT(*) FROM committees WHERE created_by IS NULL OR updated_by IS NULL")->fetchColumn() > 0) {
db()->query("UPDATE committees SET created_by = 1 WHERE created_by IS NULL");
db()->query("UPDATE committees SET updated_by = 1 WHERE updated_by IS NULL");
}
} catch (Exception $e) {}
if (!canView('committees')) {
redirect('user_dashboard.php');
}
@ -21,16 +29,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (empty($name)) {
$_SESSION['error'] = 'اسم اللجنة مطلوب';
} else {
$stmt = $db->prepare("INSERT INTO committees (name, description) VALUES (?, ?)");
$stmt->execute([$name, $description]);
$stmt = $db->prepare("INSERT INTO committees (name, description, created_by, updated_by) VALUES (?, ?, ?, ?)");
$stmt->execute([$name, $description, $_SESSION['user_id'], $_SESSION['user_id']]);
$_SESSION['success'] = 'تم إضافة اللجنة بنجاح';
}
} elseif ($action === 'edit' && $id && canEdit('committees')) {
if (empty($name)) {
$_SESSION['error'] = 'اسم اللجنة مطلوب';
} else {
$stmt = $db->prepare("UPDATE committees SET name = ?, description = ? WHERE id = ?");
$stmt->execute([$name, $description, $id]);
$stmt = $db->prepare("UPDATE committees SET name = ?, description = ?, updated_by = ? WHERE id = ?");
$stmt->execute([$name, $description, $_SESSION['user_id'], $id]);
$_SESSION['success'] = 'تم تحديث اللجنة بنجاح';
}
}
@ -204,4 +212,4 @@ function confirmDelete(id) {
}
</script>
<?php require_once __DIR__ . '/includes/footer.php'; ?>
<?php require_once __DIR__ . '/includes/footer.php'; ?>