2009-09-09 00:26:12 +00:00
< ?
2009-09-17 21:48:57 +00:00
if ( $_POST [ 'action' ] == " sponsorshipdelete " ) {
2024-12-07 01:54:02 +00:00
$stmt = $pdo -> prepare ( " DELETE FROM fundraising_donations WHERE id=' " . intval ( $_POST [ 'delete' ]) . " ' " );
$stmt -> execute ();
if ( $pdo -> rowCount ())
2009-09-18 19:25:26 +00:00
happy_ ( " Successfully removed sponsorship " );
2009-09-17 21:48:57 +00:00
exit ;
2009-09-09 00:26:12 +00:00
}
if ( $_POST [ 'action' ] == " sponsorshipedit " || $_POST [ 'action' ] == " sponsorshipadd " ) {
$sponsors_id = intval ( $_POST [ 'sponsors_id' ]);
2009-10-02 16:46:13 +00:00
$fundraising_donations_id = intval ( $_POST [ 'fundraising_donations_id' ]);
2024-12-07 01:54:02 +00:00
$fundraising_type = $_POST [ 'fundraising_type' ];
2009-09-09 00:26:12 +00:00
2024-12-07 01:54:02 +00:00
$value = $_POST [ 'value' ];
$status = $_POST [ 'status' ];
$probability = $_POST [ 'probability' ];
2009-09-09 00:26:12 +00:00
if ( $status == " confirmed " || $status == " received " ) $probability = " 100 " ;
if ( $probability == 100 && $status == " pending " ) $status = " confirmed " ;
}
if ( $_POST [ 'action' ] == " sponsorshipedit " ) {
2009-09-30 20:29:34 +00:00
2009-10-02 16:46:13 +00:00
if ( $fundraising_donations_id && $fundraising_type && $value ) {
2024-12-07 01:54:02 +00:00
$q = $pdo -> prepare ( " SELECT * FROM fundraising_donations WHERE id=' $fundraising_donations_id ' " );
$q -> execute ();
$current = $q -> fetch ( PDO :: FETCH_OBJ );
2009-09-09 00:26:12 +00:00
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 )) {
2024-12-07 01:54:02 +00:00
$stmt = $pdo -> prepare ( " UPDATE fundraising_donations SET fundraising_type=' $fundraising_type ', value=' $value ', status=' $status ', probability=' $probability ' WHERE id=' $fundraising_donations_id ' " );
$stmt -> execute ();
2009-09-09 00:26:12 +00:00
foreach ( $log AS $l ) {
2024-12-07 01:54:02 +00:00
$stmt = $pdo -> prepare ( " INSERT INTO fundraising_donor_logs (sponsors_id,dt,users_id,log) VALUES (
2009-09-09 00:26:12 +00:00
'$current->sponsors_id' ,
NOW (),
'".$_SESSION[' users_id ']."' ,
2024-12-07 01:54:02 +00:00
'".$l."' ) " );
$stmt -> execute ();
2009-09-09 00:26:12 +00:00
}
2024-12-07 01:54:02 +00:00
if ( $pdo -> errorInfo ())
echo error_ ( $pdo -> errorInfo ());
2009-09-09 00:26:12 +00:00
else
2009-09-18 19:25:26 +00:00
echo happy_ ( " Saved sponsorship changes " );
2009-09-09 00:26:12 +00:00
}
else
2009-09-18 19:25:26 +00:00
echo error_ ( " No changes were made " );
2009-09-09 00:26:12 +00:00
}
else {
2009-09-30 20:29:34 +00:00
echo error_ ( " Required fields were missing, please try again " . print_r ( $_POST , true ));
2009-09-09 00:26:12 +00:00
}
2009-09-17 21:48:57 +00:00
exit ;
2009-09-09 00:26:12 +00:00
}
if ( $_POST [ 'action' ] == " sponsorshipadd " ) {
if ( $sponsors_id && $fundraising_type && $value ) {
2024-12-07 01:54:02 +00:00
$stmt = $pdo -> prepare ( " INSERT INTO fundraising_donations (sponsors_id,fundraising_type,value,status,probability,fiscalyear) VALUES (' $sponsors_id ',' $fundraising_type ',' $value ',' $status ',' $probability ',' { $config [ 'FISCALYEAR' ] } ') " );
$stmt -> execute ();
$stmt = $pdo -> prepare ( " INSERT INTO fundraising_donor_logs (sponsors_id,dt,users_id,log) VALUES (
$stmt -> execute ();
2009-09-09 00:26:12 +00:00
'$sponsors_id' ,
NOW (),
'".$_SESSION[' users_id ']."' ,
2024-12-07 01:54:02 +00:00
'"."Created sponsorship: type=$fundraising_type, value=\$$value, status=$status, probability=$probability%")."' ) " ;
2009-09-18 19:25:26 +00:00
happy_ ( " Added new sponsorship " );
2009-09-09 00:26:12 +00:00
}
else
2009-09-18 19:25:26 +00:00
error_ ( " Required fields were missing, please try again " );
2024-12-07 01:54:02 +00:00
if ( $pdo -> errorInfo ())
error_ ( $pdo -> errorInfo ());
2009-09-17 21:48:57 +00:00
exit ;
2009-09-09 00:26:12 +00:00
}
?>