diff --git a/admin/fundraising_sponsorship_handler.inc.php b/admin/fundraising_sponsorship_handler.inc.php index f445130c..7a0a0048 100644 --- a/admin/fundraising_sponsorship_handler.inc.php +++ b/admin/fundraising_sponsorship_handler.inc.php @@ -19,12 +19,42 @@ if($_POST['action']=="sponsorshipedit" || $_POST['action']=="sponsorshipadd") { } if($_POST['action']=="sponsorshipedit") { - if($sponsorships_id && $sponsors_id && $fundraising_type && $value) { - mysql_query("UPDATE sponsorships SET sponsors_id='$sponsors_id', fundraising_type='$fundraising_type', value='$value', status='$status', probability='$probability' WHERE id='$sponsorships_id'"); - if(mysql_error()) - message_push(error(mysql_error())); + if($sponsorships_id && $fundraising_type && $value) { + $q=mysql_query("SELECT * FROM sponsorships WHERE id='$sponsorships_id'"); + $current=mysql_fetch_object($q); + + 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)) { + mysql_query("UPDATE sponsorships SET fundraising_type='$fundraising_type', value='$value', status='$status', probability='$probability' WHERE id='$sponsorships_id'"); + + foreach($log AS $l) { + mysql_query("INSERT INTO sponsors_logs (sponsors_id,dt,users_id,log) VALUES ( + '$current->sponsors_id', + NOW(), + '".$_SESSION['users_id']."', + '".mysql_real_escape_string($l)."')"); + + } + if(mysql_error()) + message_push(error(mysql_error())); + else + message_push(happy(i18n("Saved sponsorship changes"))); + } else - message_push(happy(i18n("Saved sponsorship changes"))); + message_push(happy(i18n("No changes were made"))); } else { message_push(error(i18n("Required fields were missing, please try again"))); @@ -34,6 +64,11 @@ if($_POST['action']=="sponsorshipedit") { if($_POST['action']=="sponsorshipadd") { if($sponsors_id && $fundraising_type && $value) { mysql_query("INSERT INTO sponsorships (sponsors_id,fundraising_type,value,status,probability,year) VALUES ('$sponsors_id','$fundraising_type','$value','$status','$probability','{$config['FAIRYEAR']}')"); + mysql_query("INSERT INTO sponsors_logs (sponsors_id,dt,users_id,log) VALUES ( + '$sponsors_id', + NOW(), + '".$_SESSION['users_id']."', + '".mysql_real_escape_string("Created sponsorship: type=$fundraising_type, value=\$$value, status=$status, probability=$probability%")."')"); message_push(happy(i18n("Added new sponsorship"))); } else