function news_edit($project_id, $news_id, $poster, $subject, $body)
{
    $tbl_news = NEWS_TBL;
    $f_news_id = NEWS_TBL . "." . NEWS_ID;
    $f_news_project_id = NEWS_TBL . "." . NEWS_PROJECT_ID;
    $f_news_subject = NEWS_TBL . "." . NEWS_SUBJECT;
    $f_news_body = NEWS_TBL . "." . NEWS_BODY;
    $f_news_modified = NEWS_TBL . "." . NEWS_MODIFIED;
    $f_news_poster = NEWS_TBL . "." . NEWS_POSTER;
    $f_news_deleted = NEWS_TBL . "." . NEWS_DELETED;
    $date = date_get_short_dt();
    global $db;
    $q = "\tUPDATE {$tbl_news}\n\t\t\tSET\n\t\t\t\t{$f_news_subject}\t\t= '{$subject}',\n\t\t\t\t{$f_news_body}\t\t= '{$body}',\n\t\t\t\t{$f_news_modified}\t= '{$date}',\n\t\t\t\t{$f_news_poster}\t\t= '{$poster}'\n\t\t\tWHERE\n\t\t\t\t{$f_news_project_id} = {$project_id}\n\t\t\t\tAND {$f_news_id} = {$news_id}";
    db_query($db, $q);
}
function testset_add($testset_name, $testset_description, $build_id, $page_name)
{
    global $db;
    $ts_tbl = TS_TBL;
    $f_ts_id = TS_ID;
    $f_name = TS_NAME;
    $f_desc = TS_DESCRIPTION;
    $f_date_created = TS_DATE_CREATED;
    $f_orderby = TS_ORDERBY;
    $f_archive = TS_ARCHIVE;
    $f_build_id = TS_BUILD_ID;
    $date = date_get_short_dt();
    $archive = 'N';
    # query testset table by build and get the max order by
    # add one to the order by when inserting into the testset table
    $q = "SELECT MAX({$f_orderby}) FROM {$ts_tbl} WHERE {$f_build_id} = '{$build_id}'";
    $order_by = db_get_one($db, $q);
    if (!isset($order_by) || $order_by == '') {
        $order_by = '1';
    } else {
        $order_by = $order_by + 1;
    }
    $q = "INSERT INTO {$ts_tbl}\n\t\t ({$f_name}, {$f_desc}, {$f_date_created}, {$f_orderby}, {$f_archive}, {$f_build_id})\n\t\t VALUES\n\t\t ('{$testset_name}', '{$testset_description}', '{$date}', '{$order_by}', '{$archive}', '{$build_id}')";
    db_query($db, $q);
    $q = "SELECT MAX({$f_ts_id}) FROM {$ts_tbl} WHERE {$f_build_id} = '{$build_id}'";
    $testset_id = db_get_one($db, $q);
    #######################################################################################################
    #Add entry into the log table for the project
    $build_name = admin_get_build_name($build_id);
    $deletion = 'N';
    $creation = 'Y';
    $upload = 'N';
    $action = "ADDED TESTSET {$testset_name} to {$build_name}";
    log_activity_log($page_name, $deletion, $creation, $upload, $action);
    #logfile entry end
    #######################################################################################################
    session_set_properties("release", array("testset_id" => $testset_id));
    return $testset_id;
}
function results_pass_test_run($test_run_id, $assigned_to, $status, $finished)
{
    global $db;
    $results_tbl = TEST_RESULTS_TBL;
    $f_results_id = TEST_RESULTS_ID;
    $f_test_run_id = TEST_RESULTS_TS_UNIQUE_RUN_ID;
    $f_assigned_to = TEST_RESULTS_ASSIGNED_TO;
    $f_status = TEST_RESULTS_TEST_STATUS;
    $f_finished = TEST_RESULTS_FINISHED;
    $f_timestamp = TEST_RESULTS_LOG_TIME_STAMP;
    $date = date_get_short_dt();
    $q = "UPDATE {$results_tbl}\n\t\t SET\n\t\t {$f_assigned_to} = '{$assigned_to}',\n\t\t {$f_status} = '{$status}',\n\t\t {$f_finished} = '{$finished}',\n\t\t {$f_timestamp} = '{$date}'\n\t\t WHERE {$f_test_run_id} = '{$test_run_id}'";
    db_query($db, $q);
}
function test_change_last_update($test_id)
{
    global $db;
    $test_tbl = TEST_TBL;
    $f_test_id = TEST_ID;
    $f_last_updated = TEST_LAST_UPDATED;
    $f_last_updated_by = TEST_LAST_UPDATED_BY;
    $last_updated_date = date_get_short_dt();
    $s_user_properties = session_get_user_properties();
    $s_user_name = $s_user_properties['username'];
    $last_updated_by = $s_user_name;
    $q = "UPDATE {$test_tbl}\n\t\t  SET\n\t\t  {$f_last_updated} = '{$last_updated_date}',\n\t\t  {$f_last_updated_by} = '{$last_updated_by}'\n\t\t  WHERE {$f_test_id} = '{$test_id}'";
    db_query($db, $q);
}
function admin_add_build($release_id, $build_name, $build_description, $page_name)
{
    global $db;
    $build_tbl = BUILD_TBL;
    $f_release_id = BUILD_REL_ID;
    $f_build_name = BUILD_NAME;
    $f_description = BUILD_DESCRIPTION;
    $f_date = BUILD_DATE_REC;
    $f_archive = BUILD_ARCHIVE;
    $date = date_get_short_dt();
    $archive = 'N';
    $q = "INSERT INTO {$build_tbl}\n\t\t ({$f_build_name}, {$f_description}, {$f_date}, {$f_release_id}, {$f_archive})\n\t\t VALUES\n\t\t ('{$build_name}', '{$build_description}', '{$date}', '{$release_id}', '{$archive}')";
    db_query($db, $q);
    #######################################################################################################
    # Add entry into the log table for the project
    $release_name = admin_get_release_name($release_id);
    $deletion = 'N';
    $creation = 'Y';
    $upload = 'N';
    $action = "ADDED BUILD {$build_name} TO RELEASE {$release_name}";
    log_activity_log($page_name, $deletion, $creation, $upload, $action);
    #logfile entry end
    #######################################################################################################
}
function requirement_edit($project_id, $req_id, $req_version_id, $req_defect_id, $name, $area_covered, $type, $status, $detail, $reason_for_change, $functionality, $priority, $release_id)
{
    global $db;
    $tbl_req = REQ_TBL;
    $f_req_proj_id = $tbl_req . "." . REQ_PROJECT_ID;
    $f_req_id = $tbl_req . "." . REQ_ID;
    $f_req_filename = $tbl_req . "." . REQ_FILENAME;
    $f_req_area_covered = $tbl_req . "." . REQ_AREA_COVERED;
    $f_req_type = $tbl_req . "." . REQ_TYPE;
    $f_req_parent = $tbl_req . "." . REQ_PARENT;
    $f_req_label = $tbl_req . "." . REQ_LABEL;
    $f_req_unique_id = $tbl_req . "." . REQ_UNIQUE_ID;
    $f_req_functionality = $tbl_req . "." . REQ_FUNCTIONALITY;
    $f_req_locked_by = $tbl_req . "." . REQ_LOCKED_BY;
    $f_req_locked_date = $tbl_req . "." . REQ_LOCKED_DATE;
    $f_req_priority = $tbl_req . "." . REQ_PRIORITY;
    $f_req_last_updated = $tbl_req . "." . REQ_LAST_UPDATED;
    $tbl_req_ver = REQ_VERS_TBL;
    $f_req_ver_uid = $tbl_req_ver . "." . REQ_VERS_UNIQUE_ID;
    $f_req_ver_req_id = $tbl_req_ver . "." . REQ_VERS_REQ_ID;
    $f_req_ver_version = $tbl_req_ver . "." . REQ_VERS_VERSION;
    $f_req_ver_timestamp = $tbl_req_ver . "." . REQ_VERS_TIMESTAMP;
    $f_req_ver_uploaded_by = $tbl_req_ver . "." . REQ_VERS_UPLOADED_BY;
    $f_req_ver_filename = $tbl_req_ver . "." . REQ_VERS_FILENAME;
    $f_req_ver_comments = $tbl_req_ver . "." . REQ_VERS_COMMENTS;
    $f_req_ver_status = $tbl_req_ver . "." . REQ_VERS_STATUS;
    $f_req_ver_shed_release = $tbl_req_ver . "." . REQ_VERS_SCHEDULED_RELEASE_IMP;
    $f_req_ver_shed_build = $tbl_req_ver . "." . REQ_VERS_SCHEDULED_BUILD_IMP;
    $f_req_ver_actual_release = $tbl_req_ver . "." . REQ_VERS_ACTUAL_RELEASE_IMP;
    $f_req_ver_actual_build = $tbl_req_ver . "." . REQ_VERS_ACTUAL_BUILD_IMP;
    $f_req_ver_detail = $tbl_req_ver . "." . REQ_VERS_DETAIL;
    $f_req_ver_release = $tbl_req_ver . "." . REQ_VERS_ASSIGN_RELEASE;
    $f_req_ver_reason_change = $tbl_req_ver . "." . REQ_VERS_REASON_CHANGE;
    $f_req_ver_latest = $tbl_req_ver . "." . REQ_VERS_LATEST;
    $f_req_ver_last_updated = $tbl_req_ver . "." . REQ_VERS_LAST_UPDATED;
    $f_req_ver_last_updated_by = $tbl_req_ver . "." . REQ_VERS_LAST_UPDATED_BY;
    $f_req_ver_defect_id = $tbl_req_ver . "." . REQ_VERS_DEFECT_ID;
    $last_updated = date_get_short_dt();
    $s_user_properties = session_get_user_properties();
    $s_user_name = $s_user_properties['username'];
    $last_updated_by = $s_user_name;
    if ($area_covered == '') {
        $area_covered = 0;
    }
    if ($type == '') {
        $type = 0;
    }
    $q = "\tUPDATE {$tbl_req}\n\t\t\tSET\n\t\t\t\t{$f_req_filename} = '{$name}',\n\t\t\t\t{$f_req_area_covered} = '{$area_covered}',\n\t\t\t\t{$f_req_type} = '{$type}',\n\t\t\t\t{$f_req_priority} = '{$priority}',\n\t\t\t\t{$f_req_last_updated} = '{$last_updated}'\n\t\t\tWHERE\n\t\t\t\t{$f_req_id} = '{$req_id}'\n\t\t\t\tAND {$f_req_proj_id} = {$project_id}";
    db_query($db, $q);
    //print"$q<br>";
    $q = "\tUPDATE {$tbl_req_ver}\n\t\t\tSET\n\t\t\t\t{$f_req_ver_status} \t\t\t= '{$status}',\n\t\t\t\t{$f_req_ver_detail} \t\t\t= '{$detail}',\n\t\t\t\t{$f_req_ver_reason_change}\t= '{$reason_for_change}',\n\t\t\t\t{$f_req_ver_last_updated}\t\t= '{$last_updated}',\n\t\t\t\t{$f_req_ver_last_updated_by}\t= '{$last_updated_by}',\n\t\t\t\t{$f_req_ver_defect_id}\t\t= '{$req_defect_id}'\n\t\t\tWHERE\n\t\t\t\t{$f_req_ver_uid} = '{$req_version_id}'";
    db_query($db, $q);
    //print"$q<br>";
    requirement_edit_functionality($req_id, $functionality);
    requirement_edit_release($req_version_id, $release_id);
}
function user_reset_password($reset_link, $new_password)
{
    $tbl_reset_pass = RESET_PASS_TBL;
    $f_reset_pass_id = $tbl_reset_pass . "." . RESET_PASS_ID;
    $f_reset_pass_link = $tbl_reset_pass . "." . RESET_PASS_LINK;
    $f_reset_pass_user = $tbl_reset_pass . "." . RESET_PASS_USER;
    $f_reset_pass_used = $tbl_reset_pass . "." . RESET_PASS_RESET_USED;
    $f_reset_pass_expires = $tbl_reset_pass . "." . RESET_PASS_EXPIRES;
    $tbl_user = USER_TBL;
    $f_user_id = $tbl_user . "." . USER_ID;
    $f_username = $tbl_user . "." . USER_UNAME;
    $f_email = $tbl_user . "." . USER_EMAIL;
    $f_first_name = $tbl_user . "." . USER_FNAME;
    $f_last_name = $tbl_user . "." . USER_LNAME;
    $f_phone = $tbl_user . "." . USER_PHONE;
    $f_password = $tbl_user . "." . USER_PWORD;
    $f_tempest_admin = $tbl_user . "." . USER_ADMIN;
    $f_user_default_project = $tbl_user . "." . USER_DEFAULT_PROJECT;
    global $db;
    # fetch the users email address where the record has not expired,
    # and reset link has not already been accessed
    $current_date = date_get_short_dt();
    $q = "\tSELECT {$f_reset_pass_user}\n\t\t\tFROM {$tbl_reset_pass}\n\t\t\tWHERE {$f_reset_pass_link} = '{$reset_link}'\n\t\t\t\tAND {$f_reset_pass_expires} > '{$current_date}'\n\t\t\t\tAND {$f_reset_pass_used} = 'N'";
    $email = db_get_one($db, $q);
    # if a users email address was returned
    if ($email) {
        # mark the reset link as used
        $q = "\tUPDATE {$tbl_reset_pass}\n\t\t\t\tSET {$f_reset_pass_used} = 'Y'\n\t\t\t\tWHERE {$f_reset_pass_link} = '{$reset_link}'";
        db_query($db, $q);
        # encrypt password
        if (LOGIN_METHOD == 'MD5') {
            $new_password = auth_process_plain_password($new_password);
        }
        # change the users password
        $q = "\tUPDATE {$tbl_user}\n\t\t\t\tSET {$f_password} = '{$new_password}'\n\t\t\t\tWHERE {$f_email} = '{$email}'";
        db_query($db, $q);
    }
    return $email;
}
# ---------------------------------------------------------------------
# rth is a requirement, test, and bugtracking system
# Copyright (C) 2005 George Holbrook - rth@lists.sourceforge.net
# This program is distributed under the terms and conditions of the GPL
# See the README and LICENSE files for details
#----------------------------------------------------------------------
# ---------------------------------------------------------------------
# Test Set Signoff Action Page
#
# $RCSfile: testset_signoff_action.php,v $  $Revision: 1.2 $
# ---------------------------------------------------------------------
include "./api/include_api.php";
auth_authenticate_user();
$redirect_page = 'results_page.php';
$testset_id = util_clean_post_vars('testset_id');
$build_id = util_clean_post_vars('build_id');
$status = util_clean_post_vars('signoff_status');
$comments = util_clean_post_vars('signoff_comments');
$user_name = session_get_username();
$date = date_get_short_dt();
testset_update_testset_signoff($testset_id, $build_id, $status, $date, $user_name, $comments);
html_print_operation_successful("testset_signoff_page", $redirect_page);
# ---------------------------------------------------------------------
# $Log: testset_signoff_action.php,v $
# Revision 1.2  2006/01/08 22:00:19  gth2
# bug fixes.  missing some variables - gth
#
# Revision 1.1.1.1  2005/11/30 23:00:58  gth2
# importing initial version - gth
#
# ---------------------------------------------------------------------
function bug_history_log_new_bug($bug_id)
{
    global $db;
    $tbl_history = BUG_HISTORY_TBL;
    $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();
    $field = lang_get('new_bug');
    $q = "INSERT INTO {$tbl_history}\n\t\t  ( {$f_bug_id}, {$f_date_modified}, {$f_user}, {$f_field}, {$f_old_value}, {$f_new_value} )\n\t\t  VALUES\n\t\t  ( '{$bug_id}', '{$current_date}', '{$username}', '{$field}', '', '' )";
    db_query($db, $q);
}