public function save_rate($userID, $projectID, $activityID, $rate)
{
// validate input
if ($userID == null || !is_numeric($userID)) {
$userID = "NULL";
}
if ($projectID == null || !is_numeric($projectID)) {
$projectID = "NULL";
}
if ($activityID == null || !is_numeric($activityID)) {
$activityID = "NULL";
}
if (!is_numeric($rate)) {
return false;
}
// build update or insert statement
if ($this->get_rate($userID, $projectID, $activityID) === false) {
$query = "INSERT INTO " . $this->kga['server_prefix'] . "rates VALUES({$userID},{$projectID},{$activityID},{$rate});";
} else {
$query = "UPDATE " . $this->kga['server_prefix'] . "rates SET rate = {$rate} WHERE " . ($userID == "NULL" ? "userID is NULL" : "userID = {$userID}") . " AND " . ($projectID == "NULL" ? "projectID is NULL" : "projectID = {$projectID}") . " AND " . ($activityID == "NULL" ? "activityID is NULL" : "activityID = {$activityID}");
}
$result = $this->conn->Query($query);
if ($result == false) {
$this->logLastError('save_rate');
return false;
} else {
return true;
}
}