/** * if sponsorship contains a non-zero id, then update the corresponding record. * if sponsorship contains a zero id, search for bug_id/user_id, if found, then update the entry * otherwise add a new entry * @param int $p_sponsorship * @return int */ function sponsorship_set($p_sponsorship) { $t_min_sponsorship = config_get('minimum_sponsorship_amount'); if ($p_sponsorship->amount < $t_min_sponsorship) { error_parameters($p_sponsorship->amount, $t_min_sponsorship); trigger_error(ERROR_SPONSORSHIP_AMOUNT_TOO_LOW, ERROR); } # if id == 0, check if the specified user is already sponsoring the bug, if so, overwrite if ($p_sponsorship->id == 0) { $t_sponsorship_id = sponsorship_get_id($p_sponsorship->bug_id, $p_sponsorship->user_id); if ($t_sponsorship_id !== false) { $p_sponsorship->id = $t_sponsorship_id; } } $t_sponsorship_table = db_get_table('sponsorship'); $c_id = db_prepare_int($p_sponsorship->id); $c_bug_id = db_prepare_int($p_sponsorship->bug_id); $c_user_id = db_prepare_int($p_sponsorship->user_id); $c_amount = db_prepare_int($p_sponsorship->amount); $c_logo = $p_sponsorship->logo; $c_url = $p_sponsorship->url; $c_now = db_now(); # if new sponsorship if ($c_id == 0) { # Insert $query = "INSERT INTO {$t_sponsorship_table}\n\t\t\t\t ( bug_id, user_id, amount, logo, url, date_submitted, last_updated )\n\t\t\t\t VALUES\n\t\t\t\t (" . db_param() . ',' . db_param() . ',' . db_param() . ',' . db_param() . ',' . db_param() . ',' . db_param() . ',' . db_param() . ')'; db_query_bound($query, array($c_bug_id, $c_user_id, $c_amount, $c_logo, $c_url, $c_now, $c_now)); $t_sponsorship_id = db_insert_id($t_sponsorship_table); history_log_event_special($c_bug_id, BUG_ADD_SPONSORSHIP, $c_user_id, $c_amount); } else { $t_old_amount = sponsorship_get_amount($c_id); $t_sponsorship_id = $c_id; if ($t_old_amount == $c_amount) { return $t_sponsorship_id; } # Update $query = "UPDATE {$t_sponsorship_table}\n\t\t\t\t\tSET\tbug_id = " . db_param() . ",\n\t\t\t\t\t\tuser_id = " . db_param() . ",\n\t\t\t\t\t\tamount = " . db_param() . ",\n\t\t\t\t\t\tlogo = " . db_param() . ",\n\t\t\t\t\t\turl = " . db_param() . ",\n\t\t\t\t\t\tlast_updated = " . db_param() . "\n\t\t\t\t\tWHERE\tid = " . db_param(); sponsorship_clear_cache($c_id); db_query_bound($query, array($c_bug_id, $c_user_id, $c_amount, $c_logo, $c_url, $c_now, $c_id)); history_log_event_special($c_bug_id, BUG_UPDATE_SPONSORSHIP, $c_user_id, $c_amount); } sponsorship_update_bug($c_bug_id); bug_monitor($c_bug_id, $c_user_id); if ($c_id == 0) { email_sponsorship_added($c_bug_id); } else { email_sponsorship_updated($c_bug_id); } return $t_sponsorship_id; }
$f_bug_id = gpc_get_int('bug_id'); $f_amount = gpc_get_int('amount'); $t_bug = bug_get($f_bug_id, true); if ($t_bug->project_id != helper_get_current_project()) { # in case the current project is not the same project of the bug we are viewing... # ... override the current project. This to avoid problems with categories and handlers lists etc. $g_project_override = $t_bug->project_id; } if (config_get('enable_sponsorship') == OFF) { trigger_error(ERROR_SPONSORSHIP_NOT_ENABLED, ERROR); } access_ensure_bug_level(config_get('sponsor_threshold'), $f_bug_id); helper_ensure_confirmed(sprintf(lang_get('confirm_sponsorship'), $f_bug_id, sponsorship_format_amount($f_amount)), lang_get('sponsor_issue')); if ($f_amount == 0) { # if amount == 0, delete sponsorship by current user (if any) $t_sponsorship_id = sponsorship_get_id($f_bug_id); if ($t_sponsorship_id !== false) { sponsorship_delete($t_sponsorship_id); } } else { # add sponsorship $t_user = auth_get_current_user_id(); if (is_blank(user_get_email($t_user))) { trigger_error(ERROR_SPONSORSHIP_SPONSOR_NO_EMAIL, ERROR); } else { $sponsorship = new SponsorshipData(); $sponsorship->bug_id = $f_bug_id; $sponsorship->user_id = $t_user; $sponsorship->amount = $f_amount; sponsorship_set($sponsorship); }
/** * if sponsorship contains a non-zero id, then update the corresponding record. * if sponsorship contains a zero id, search for bug_id/user_id, if found, then update the entry * otherwise add a new entry * @param SponsorshipData $p_sponsorship The sponsorship data object to set. * @return integer */ function sponsorship_set(SponsorshipData $p_sponsorship) { $t_min_sponsorship = config_get('minimum_sponsorship_amount'); if ($p_sponsorship->amount < $t_min_sponsorship) { error_parameters($p_sponsorship->amount, $t_min_sponsorship); trigger_error(ERROR_SPONSORSHIP_AMOUNT_TOO_LOW, ERROR); } # if id == 0, check if the specified user is already sponsoring the bug, if so, overwrite if ($p_sponsorship->id == 0) { $t_sponsorship_id = sponsorship_get_id($p_sponsorship->bug_id, $p_sponsorship->user_id); if ($t_sponsorship_id !== false) { $p_sponsorship->id = $t_sponsorship_id; } } $c_id = (int) $p_sponsorship->id; $c_bug_id = (int) $p_sponsorship->bug_id; $c_user_id = (int) $p_sponsorship->user_id; $c_amount = (int) $p_sponsorship->amount; $c_logo = $p_sponsorship->logo; $c_url = $p_sponsorship->url; $c_now = db_now(); # if new sponsorship if ($c_id == 0) { # Insert $t_query = 'INSERT INTO {sponsorship} ( bug_id, user_id, amount, logo, url, date_submitted, last_updated ) VALUES (' . db_param() . ',' . db_param() . ',' . db_param() . ',' . db_param() . ',' . db_param() . ',' . db_param() . ',' . db_param() . ')'; db_query($t_query, array($c_bug_id, $c_user_id, $c_amount, $c_logo, $c_url, $c_now, $c_now)); $t_sponsorship_id = db_insert_id(db_get_table('sponsorship')); history_log_event_special($c_bug_id, BUG_ADD_SPONSORSHIP, $c_user_id, $c_amount); } else { $t_old_amount = sponsorship_get_amount($c_id); $t_sponsorship_id = $c_id; if ($t_old_amount == $c_amount) { return $t_sponsorship_id; } # Update $t_query = 'UPDATE {sponsorship} SET bug_id = ' . db_param() . ', user_id = ' . db_param() . ', amount = ' . db_param() . ', logo = ' . db_param() . ', url = ' . db_param() . ', last_updated = ' . db_param() . ' WHERE id = ' . db_param(); sponsorship_clear_cache($c_id); db_query($t_query, array($c_bug_id, $c_user_id, $c_amount, $c_logo, $c_url, $c_now, $c_id)); history_log_event_special($c_bug_id, BUG_UPDATE_SPONSORSHIP, $c_user_id, $c_amount); } sponsorship_update_bug($c_bug_id); bug_monitor($c_bug_id, $c_user_id); if ($c_id == 0) { email_sponsorship_added($c_bug_id); } else { email_sponsorship_updated($c_bug_id); } return $t_sponsorship_id; }