# 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
#----------------------------------------------------------------------
# ---------------------------------------------------------------------
# Results Update Test Run Action Page
#
# $RCSfile: results_update_test_run_action.php,v $  $Revision: 1.2 $
# ---------------------------------------------------------------------
include "./api/include_api.php";
auth_authenticate_user();
$page = basename(__FILE__);
$s_results = session_get_properties('results', $_POST);
$s_user = session_get_user_properties();
$email_to = user_get_email_by_username($email_users);
session_validate_form_set($_POST);
$test_run_id = $s_results['test_run_id'];
$testset_id = $s_results['testset_id'];
$test_id = $s_results['test_id'];
$redirect_page = "results_test_run_page.php?test_id={$test_id}&testset_id={$testset_id}";
$username = $s_user['username'];
$comments = session_validate_form_get_field('test_run_comments');
$email_comments = $_POST['test_run_comments'];
# don't escape characters when sending e-mail
$status = $_POST['test_run_status'];
$root_cause = $_POST['root_cause'];
$email_users = $_POST['email_users'];
/*
print"comments = $comments<br>";
print"status = $status<br>";
    if ($email_ba_owner == 'Y' && $test_detail[TEST_BA_OWNER] != '' && $username != $test_detail[TEST_BA_OWNER]) {
        $send_email = true;
        $owner_array = array($test_detail[TEST_BA_OWNER]);
    }
    if ($email_qa_owner == 'Y' && $test_detail[TEST_QA_OWNER] != '' && $username != $test_detail[TEST_QA_OWNER]) {
        $send_email = true;
        if (is_array($owner_array)) {
            array_push($owner_array, $test_detail[TEST_QA_OWNER]);
        } else {
            $owner_array = array($test_detail[TEST_QA_OWNER]);
        }
    }
}
// Compose message and send email
if ($send_email) {
    $recipients = user_get_email_by_username($owner_array);
    test_compose_email($project_id, $test_id, $recipients, "status_change");
}
/*
if ($teststatus == 'Not Running' AND $assigned_to != '' AND $email=='YES') {

    $current_user_row = user_get_current_user_name();
    $assigned_to_row = user_get_name_by_username($assigned_to);

    $f_email     = USER_EMAIL;
    $f_firstname = USER_FNAME;
    $f_lastname  = USER_LNAME;

    $current_user_email = $current_user_row[$f_email];
    $current_user_firstname = $current_user_row[$f_firstname];
    $current_user_lastname = $current_user_row[$f_lastname];
 print "<tr>" . NEWLINE;
 print "<td class=form-lbl-r>" . lang_get('root_cause') . "</td>" . NEWLINE;
 print "<td class=left>" . NEWLINE;
 print "<select name='root_cause' size=1>" . NEWLINE;
 $selected_value = $root_cause;
 $root_causes = results_get_root_cause_values();
 html_print_list_box_from_array($root_causes, $selected_value);
 print "</select>" . NEWLINE;
 print "</td>" . NEWLINE;
 print "</tr>" . NEWLINE;
 # E-mail user
 print "<tr>" . NEWLINE;
 print "<td class=form-lbl-r>" . lang_get('email_test_run_status') . "</td>" . NEWLINE;
 print "<td class=left>" . NEWLINE;
 print "<select name='email_users[]' multiple size='5'>" . NEWLINE;
 $selected_value = user_get_email_by_username($assigned_to);
 $users = user_get_details_all($project_id);
 $email_users = array();
 foreach ($users as $user) {
     $email_users[$user[USER_EMAIL]] = $user[USER_UNAME];
 }
 $email_users[""] = "";
 html_print_list_box_from_key_array($email_users, $selected_value);
 print "</select>" . NEWLINE;
 print "</td>" . NEWLINE;
 print "</tr>";
 #print"<tr><td><input type='hidden' name='test_id' value='$test_id'></td></tr>". NEWLINE;
 util_add_spacer();
 print "<tr><td class=center colspan=2><input type=submit name='save' value='" . lang_get('update') . "'><br/><br/></td>" . NEWLINE;
 print "</table>" . NEWLINE;
 print "</td>" . NEWLINE;