Updated the activity logging function for more generic use.

This commit is contained in:
jacob 2009-10-06 15:09:13 +00:00
parent 1da21bea9e
commit 0283036dc2

View File

@ -100,7 +100,11 @@ switch($_GET['action']) {
exit;
break;
case 'activityinfo_save':
save_activityinfo();
if(save_activityinfo()){
happy_(i18n("Activity Logged"));
}else{
error_(i18n("Unable to save activity log"));
}
exit;
break;
}
@ -356,16 +360,34 @@ function draw_activityinfo_form(){
<?php
}
// Save the activity info that was submitted
function save_activityinfo(){
$query = "INSERT INTO fundraising_donor_logs (sponsors_id, dt, users_id, log)";
$query .= "VALUES (" . $_GET['id'] . ",NOW(), " . $_SESSION['users_id'] . ",'" . $_POST['comment'] . "')";
if(mysql_query($query)){
happy_(i18n("Note Added"));
}else{
error_(i18n("Error Inserting Record"));
}
// Save an activity info log. Returns true on success, false on failure.
// if arguments are omitted, we try try to get them from the environment
function save_activityinfo($comment = null, $donorId = null, $userId = null){
$returnval = false;
// grab the values from our environment if they're not passed as arguments
if($comment == null) $comment = getValue('comment');
if($donorId == null) $donorId = getValue('id');
if($userId == null) $userId = getValue('users_id');
// if all is good, add a record
if($comment != null && $donorId != null && $userId != null){
$query = "INSERT INTO fundraising_donor_logs (sponsors_id, dt, users_id, log) ";
$query .= "VALUES (" . $donorId . ",NOW()," . $userId . ",'" . $comment . "')";
if(mysql_query($query)){
$returnval = true;
}
}
return $returnval;
}
// attempts to grab the desired index from _GET, _POST, and _SESSION in that order,
// and returns it's value on success. returnl null on failure.
function getValue($index){
if(array_key_exists($index, $_GET)) return $_GET[$index];
if(array_key_exists($index, $_POST)) return $_POST[$index];
if(array_key_exists($index, $_SESSION)) return $_SESSION[$index];
return null;
}
?>