function project_edit_bug_component($project_id, $id, $name)
{
    global $db;
    $component_tbl = BUG_COMPONENT_TBL;
    $f_id = $component_tbl . "." . COMPONENT_ID;
    $f_proj_id = $component_tbl . "." . COMPONENT_PROJECT_ID;
    $f_name = $component_tbl . "." . COMPONENT_NAME;
    $history_tbl = BUG_HISTORY_TBL;
    $f_field = BUG_HISTORY_FIELD;
    $f_old_value = BUG_HISTORY_OLD_VALUE;
    $f_new_value = BUG_HISTORY_NEW_VALUE;
    $bug_component = BUG_COMPONENT;
    # Get current component name
    $old_component = bug_get_component($id);
    # Update the component
    $q = "UPDATE {$component_tbl}\n\t\t  SET\n\t\t\t{$f_name} = '{$name}'\n\t\t  WHERE\n\t\t\t{$f_id} = {$id}\n\t\t  AND {$f_proj_id} = {$project_id}";
    db_query($db, $q);
    # Update the history table to the new value where it was the old value
    $q1 = "UPDATE {$history_tbl}\n\t\t   SET {$f_old_value} = '{$name}'\n\t\t   WHERE {$f_field} = '{$bug_component}'\n\t\t   AND {$f_old_value} = '{$old_component}'";
    db_query($db, $q1);
    $q2 = "UPDATE {$history_tbl}\n\t\t   SET {$f_new_value} = '{$name}'\n\t\t   WHERE {$f_field} = '{$bug_component}'\n\t\t   AND {$f_new_value} = '{$old_component}'";
    db_query($db, $q2);
}
function bug_history_log_event_special($bug_id, $field, $old_value, $new_value)
{
    if ($old_value != $new_value && $new_value != '') {
        global $db;
        $tbl_history = BUG_HISTORY_TBL;
        $f_history_id = BUG_HISTORY_ID;
        $f_bug_id = BUG_HISTORY_BUG_ID;
        $f_date_modified = BUG_HISTORY_DATE;
        $f_user = BUG_HISTORY_USER;
        $f_field = BUG_HISTORY_FIELD;
        $f_old_value = BUG_HISTORY_OLD_VALUE;
        $f_new_value = BUG_HISTORY_NEW_VALUE;
        $username = session_get_username();
        $current_date = date_get_short_dt();
        switch ($field) {
            case BUG_CATEGORY:
                $old_value = bug_get_category($old_value);
                $new_value = bug_get_category($new_value);
                break;
            case BUG_COMPONENT:
                $old_value = bug_get_component($old_value);
                $new_value = bug_get_component($new_value);
                break;
        }
        $q = "INSERT INTO {$tbl_history}\n\t\t\t  ( {$f_bug_id}, {$f_date_modified}, {$f_user}, {$f_field}, {$f_old_value}, {$f_new_value} )\n\t\t\t  VALUES\n\t\t\t  ('{$bug_id}', '{$current_date}', '{$username}', '{$field}', '{$old_value}', '{$new_value}' )";
        db_query($db, $q);
    }
}