science-ation/admin/fundraising_sponsorship_handler.inc.php

87 lines
3.1 KiB
PHP

<?
if ($_POST['action'] == 'sponsorshipdelete') {
$stmt = $pdo->prepare("DELETE FROM fundraising_donations WHERE id=?");
$stmt->execute([intval($_POST['delete'])]);
if ($pdo->rowCount())
happy_('Successfully removed sponsorship');
exit;
}
if ($_POST['action'] == 'sponsorshipedit' || $_POST['action'] == 'sponsorshipadd') {
$sponsors_id = intval($_POST['sponsors_id']);
$fundraising_donations_id = intval($_POST['fundraising_donations_id']);
$fundraising_type = $_POST['fundraising_type'];
$value = $_POST['value'];
$status = $_POST['status'];
$probability = $_POST['probability'];
if ($status == 'confirmed' || $status == 'received')
$probability = '100';
if ($probability == 100 && $status == 'pending')
$status = 'confirmed';
}
if ($_POST['action'] == 'sponsorshipedit') {
if ($fundraising_donations_id && $fundraising_type && $value) {
$q = $pdo->prepare("SELECT * FROM fundraising_donations WHERE id=?");
$q->execute([$fundraising_donations_id]);
$current = $q->fetch(PDO::FETCH_OBJ);
unset($log);
$log = array();
if ($current->fundraising_type != $fundraising_type)
$log[] = "Changed sponsorship type from $current->fundraising_type to $fundraising_type";
if ($current->value != $value)
$log[] = "Changed sponsorship value from $current->value to $value";
if ($current->status != $status)
$log[] = "Changed sponsorship status from $current->status to $status";
if ($current->probability != $probability)
$log[] = "Changed sponsorship probability from $current->probability to $probability";
if (count($log)) {
$stmt = $pdo->prepare("UPDATE fundraising_donations SET fundraising_type=?, value=?, status=?, probability=? WHERE id=?");
$stmt->execute([$fundraising_type,$value,$status,$probability,$fundraising_donations_id]);
foreach ($log AS $l) {
$stmt = $pdo->prepare("INSERT INTO fundraising_donor_logs (sponsors_id,dt,users_id,log) VALUES (
?,
NOW(),
?,
?)");
$stmt->execute([$current->sponsors_id,$_SESSION['users_id'],$l]);
}
if ($pdo->errorInfo())
echo error_($pdo->errorInfo());
else
echo happy_('Saved sponsorship changes');
} else
echo error_('No changes were made');
} else {
echo error_('Required fields were missing, please try again' . print_r($_POST, true));
}
exit;
}
if ($_POST['action'] == 'sponsorshipadd') {
if ($sponsors_id && $fundraising_type && $value) {
$stmt = $pdo->prepare("INSERT INTO fundraising_donations (sponsors_id,fundraising_type,value,status,probability,fiscalyear) VALUES (?,?,?,?,?,?)");
$stmt->execute([$sponsors_id,$fundraising_type,$value,$status,$probability,$config['FISCALYEAR']]);
$stmt = $pdo->prepare("INSERT INTO fundraising_donor_logs (sponsors_id,dt,users_id,log) VALUES (
?,
NOW(),
?,
'" . "Created sponsorship: type=?, value=\$?, status=?, probability=?%") . "')";
happy_('Added new sponsorship');
$stmt->execute([$sponsors_id,$_SESSION['users_id'],$fundraising_type,$value,$status,$probability]);
} else
error_('Required fields were missing, please try again');
if ($pdo->errorInfo())
error_($pdo->errorInfo());
exit;
}
?>