public function activity_edit($activityID, $data, $activityGroups)
{
$data = $this->clean_data($data);
$values = array();
$strings = array('name', 'comment');
foreach ($strings as $key) {
if (isset($data[$key])) {
$values[$key] = MySQL::SQLValue($data[$key]);
}
}
$numbers = array('visible', 'filter');
foreach ($numbers as $key) {
if (isset($data[$key])) {
$values[$key] = MySQL::SQLValue($data[$key], MySQL::SQLVALUE_NUMBER);
}
}
$filter['activityID'] = MySQL::SQLValue($activityID, MySQL::SQLVALUE_NUMBER);
$table = $this->getActivityTable();
if (!$this->conn->TransactionBegin()) {
$this->logLastError('activity_edit');
return false;
}
$query = MySQL::BuildSQLUpdate($table, $values, $filter);
if ($this->conn->Query($query)) {
if (isset($data['defaultRate'])) {
if (is_numeric($data['defaultRate'])) {
$this->save_rate(null, null, $activityID, $data['defaultRate']);
} else {
$this->remove_rate(null, null, $activityID);
}
}
if (isset($data['myRate'])) {
if (is_numeric($data['myRate'])) {
$this->save_rate($this->kga['user']['userID'], null, $activityID, $data['myRate']);
} else {
$this->remove_rate($this->kga['user']['userID'], null, $activityID);
}
}
if (isset($data['fixedRate'])) {
if (is_numeric($data['fixedRate'])) {
foreach ($activityGroups as $activityGroup) {
$this->save_fixed_rate($activityGroup, $activityID, $data['fixedRate']);
}
} else {
foreach ($activityGroups as $activityGroup) {
$this->remove_fixed_rate($activityGroup, $activityID);
}
}
}
if (!$this->conn->TransactionEnd()) {
$this->logLastError('activity_edit');
return false;
}
return true;
} else {
$this->logLastError('activity_edit');
if (!$this->conn->TransactionRollback()) {
$this->logLastError('activity_edit');
return false;
}
return false;
}
}