$project_id = $project_properties['project_id'];
$project_name = $project_properties['project_name'];
$username = session_get_username();
$display_options = session_set_display_options("requirements", array_merge($_POST, $_GET));
$s_tab = $display_options['tab'];
$s_properties = session_set_properties("requirements", $_GET);
$s_req_id = $s_properties['req_id'];
$s_req_version_id = $s_properties['req_version_id'];
html_window_title();
html_print_body();
html_page_title($project_name . " - REQUIREMENT DETAIL");
html_page_header($db, $project_name);
html_print_menu();
requirement_menu_print($page);
error_report_check($_GET);
$rows_requirement = requirement_get_detail($project_id, $s_req_id, $s_req_version_id);
$row_requirement = $rows_requirement[0];
$req_version_id = $row_requirement[REQ_VERS_UNIQUE_ID];
$req_rec_or_file = $row_requirement[REQ_REC_FILE];
$req_name = $row_requirement[REQ_FILENAME];
$req_detail = $row_requirement[REQ_VERS_DETAIL];
$req_reason_for_change = $row_requirement[REQ_VERS_REASON_CHANGE];
$req_version_status = $row_requirement[REQ_VERS_STATUS];
$req_area_covered = $row_requirement[REQ_AREA_COVERAGE];
$req_area_covered_id = $row_requirement[REQ_AREA_COVERAGE_ID];
$req_doc_type = $row_requirement[REQ_DOC_TYPE_NAME];
$req_doc_type = $row_requirement[REQ_DOC_TYPE_ID];
$req_priority = $row_requirement[REQ_PRIORITY];
$req_defect_id = $row_requirement[REQ_VERS_DEFECT_ID];
$selected_release = requirement_get_release($req_version_id);
print "<br>";
$s_project_name = $s_project_properties['project_name'];
$history_detail_page = 'requirement_version_view_history_page.php';
$req_detail_page = 'requirement_detail_page.php';
$row_style = '';
$s_properties = session_set_properties("requirements", $_GET);
$s_req_id = $s_properties['req_id'];
$s_req_version_id = $s_properties['req_version_id'];
html_window_title();
html_print_body();
html_page_title($s_project_name . " - REQUIREMENTS");
html_page_header($db, $s_project_name);
html_print_menu();
#### Change to api submenu function for this page type ####
requirement_menu_print($page);
error_report_check($_GET);
$rows = requirement_get_detail($s_project_id, $s_req_id);
$row_requirement = $rows[0];
$req_name = $row_requirement[REQ_FILENAME];
$record_or_file = $row_requirement[REQ_REC_FILE];
$req_version_num = requirement_get_version_number($s_req_id, $s_req_version_id);
print "<br>" . NEWLINE;
print "<div align=center>" . NEWLINE;
print "<table class=width100 rules=cols>" . NEWLINE;
print "<tr>" . NEWLINE;
print "<td width='33%' nowrap class=grid-header-c>" . lang_get('req_id') . "</td>" . NEWLINE;
print "<td width='33%' nowrap class=grid-header-c>" . lang_get('req_name') . "</td>" . NEWLINE;
print "<td width='33%' nowrap class=grid-header-c>" . lang_get('req_version') . "</td>" . NEWLINE;
print "</tr>" . NEWLINE;
print "<tr>" . NEWLINE;
print "<td width='33%' class=grid-data-c><a href='{$req_detail_page}?req_id={$s_req_id}'>" . sprintf("%05s", trim($s_req_id)) . "</a></td>" . NEWLINE;
print "<td width='33%'class=grid-data-c>{$req_name}</td>" . NEWLINE;
    $q = "\tUpdate\n\t\t\t\tRequirement\n\t\t\tSet\n\t\t\t\tLockedBy = '{$username}',\n\t\t\t\tLockedDate = '" . date("Y-m-d H:i:s") . "'\n\t\t\tWHERE\n\t\t\t\tReqID = '{$s_req_id}'";
    db_query($db, $q);
}
if (isset($_POST['submit_req_unlock'])) {
    global $db;
    $q = "\tUpdate\n\t\t\t\tRequirement\n\t\t\tSet\n\t\t\t\tLockedBy = '',\n\t\t\t\tLockedDate = ''\n\t\t\tWHERE\n\t\t\t\tReqID = '{$s_req_id}'";
    db_query($db, $q);
}
html_window_title();
html_print_body();
html_page_title($project_name . " - " . lang_get("req_detail_page"));
html_page_header($db, $project_name);
html_print_menu();
requirement_menu_print($page);
error_report_check($_GET);
$rows_requirement = requirement_get_detail($project_id, $s_req_id, $_GET['version']);
$row_requirement = $rows_requirement[0];
print "<br>" . NEWLINE;
print "<form method=post action='{$page}'>" . NEWLINE;
print "<table class=width100 rules=cols>" . NEWLINE;
print "<tr>" . NEWLINE;
print "<td width='33%' nowrap class=grid-header-c>" . lang_get('req_id') . "</td>" . NEWLINE;
print "<td width='33%' nowrap class=grid-header-c>" . lang_get('req_name') . "</td>" . NEWLINE;
print "<td width='33%' nowrap class=grid-header-c>" . lang_get('req_version') . "</td>" . NEWLINE;
print "</tr>" . NEWLINE;
print "<tr>" . NEWLINE;
print "<td width='33%' class=grid-data-c>" . sprintf("%05s", trim($s_req_id)) . "</td>" . NEWLINE;
print "<td width='33%' class=grid-data-c>" . $row_requirement[REQ_FILENAME] . "</td>" . NEWLINE;
print "<td width='33%' class=grid-data-c>" . $row_requirement[REQ_VERS_VERSION] . "</td>" . NEWLINE;
print "</tr>" . NEWLINE;
print "</table>" . NEWLINE;
function requirement_email($project_id, $req_id, $recipients, $action, $discussion_id = null)
{
    $display_generic_info = true;
    $display_generic_url = true;
    # Link to the req detail page
    $generic_url = RTH_URL . "login.php?project_id={$project_id}&page=requirement_detail_page.php&req_id={$req_id}";
    $username = session_get_username();
    $project_name = session_get_project_name();
    $req_id = util_pad_id($req_id);
    $user_details = user_get_name_by_username($username);
    $first_name = $user_details[USER_FNAME];
    $last_name = $user_details[USER_LNAME];
    $rows_requirement = requirement_get_detail($project_id, $req_id);
    $row_requirement = $rows_requirement[0];
    $req_version_id = $row_requirement[REQ_VERS_UNIQUE_ID];
    $req_rec_or_file = $row_requirement[REQ_REC_FILE];
    $req_name = $row_requirement[REQ_FILENAME];
    $req_detail = $row_requirement[REQ_VERS_DETAIL];
    $req_reason_for_change = $row_requirement[REQ_VERS_REASON_CHANGE];
    $req_version_status = $row_requirement[REQ_VERS_STATUS];
    $req_area_covered = $row_requirement[REQ_AREA_COVERAGE];
    $req_doc_type = $row_requirement[REQ_DOC_TYPE_NAME];
    $req_version = $row_requirement[REQ_VERS_VERSION];
    # REQ FUNCTIONALITY
    $rows_functions = requirement_get_functionality($project_id, $req_id);
    $req_functionality = "";
    foreach ($rows_functions as $function) {
        $req_functionality .= $function . ", ";
    }
    $req_functionality = trim($req_functionality, ", ");
    # CREATE EMAIL SUBJECT AND MESSAGE
    switch ($action) {
        case "updated":
            $subject = "RTH: Requirement Updated in {$project_name}";
            $message = "Requirement {$req_name} has been updated by {$first_name} {$last_name}\n" . NEWLINE;
            break;
        case "new_version":
            $subject = "RTH: Requirement Updated in {$project_name}";
            $message = "A new version of Requirement {$req_name} has been created by {$first_name} {$last_name}\n" . NEWLINE;
            break;
        case "delete":
            $display_generic_info = false;
            $display_generic_url = false;
            $url = RTH_URL . "login.php?project_id={$project_id}&page=requirement_page.php";
            $subject = "RTH: Requirement Deleted in {$project_name}";
            $message = "Requirement {$req_name} has been deleted by {$first_name} {$last_name}\n" . NEWLINE;
            $message .= "Click the following link to view Requirements in {$project_name}:" . NEWLINE;
            $message .= "{$url}\n" . NEWLINE;
            break;
        case "lock":
            $subject = "RTH: Requirement Locked in {$project_name}";
            $message = "Requirement {$req_name} has been locked by {$first_name} {$last_name}\n" . NEWLINE;
            break;
        case "unlock":
            $subject = "RTH: Requirement Unlocked in {$project_name}";
            $message = "Requirement {$req_name} has been unlocked by {$first_name} {$last_name}\n" . NEWLINE;
            break;
        case "edit_children":
            # Get requirement children
            //$rows_children = requirement_get_children($req_id);
            $generic_url .= "&tab=1";
            $subject = "RTH: Requirement Updated in {$project_name}";
            $message = "The children of Requirement {$req_name} have been edited by {$first_name} {$last_name}\n" . NEWLINE;
            break;
        case "edit_test_assoc":
            # Get related tests
            //$assoc_tests = requirement_get_test_relationships($req_id);
            $generic_url .= "&tab=2";
            $subject = "RTH: Requirement Updated in {$project_name}";
            $message = "The Tests related to Requirement {$req_name} have been edited by {$first_name} {$last_name}\n" . NEWLINE;
            break;
        case "edit_release_assoc":
            # Get related releases
            //requirement_get_assoc_releases($s_req_version_id)
            $generic_url .= "&tab=4";
            $subject = "RTH: Requirement Updated in {$project_name}";
            $message = "The Releases related to Requirement {$req_name} have been edited by {$first_name} {$last_name}\n" . NEWLINE;
            break;
        case "new_discussion":
            # GET LAST DISCUSSION
            $rows_discussion = discussion_get($req_id);
            foreach ($rows_discussion as $row_discussion) {
                $discussion_subject = $row_discussion[DISC_SUBJECT];
            }
            $generic_url .= "&tab=3";
            $subject = "RTH: New Requirement Discussion in {$project_name}";
            $message = "A new discussion has been added to Requirement {$req_name} by {$first_name} {$last_name}\n" . NEWLINE;
            $message .= "" . lang_get("subject") . ": {$discussion_subject}\n" . NEWLINE;
            break;
        case "new_post":
            # GET DISCUSSION
            $row_discussion = discussion_get_detail($discussion_id);
            $discussion_subject = $row_discussion[DISC_SUBJECT];
            $url = RTH_URL . "login.php?project_id={$project_id}&page=requirement_discussion_page.php&discussion_id={$discussion_id}";
            $subject = "RTH: Discussion {$discussion_subject} in {$project_name}";
            $message = "A new post has been added to Discussion {$discussion_subject} by {$first_name} {$last_name}\n" . NEWLINE;
            $message .= "Click the following link to view the discussion:\n" . NEWLINE;
            $message .= "{$url}\n" . NEWLINE;
            break;
        case "close_discussion":
            $display_generic_info = false;
            $display_generic_url = false;
            # GET DISCUSSION
            $row_discussion = discussion_get_detail($discussion_id);
            $discussion_subject = $row_discussion[DISC_SUBJECT];
            $url = RTH_URL . "login.php?project_id={$project_id}&page=requirement_discussion_page.php&discussion_id={$discussion_id}";
            $subject = "RTH: Discussion {$discussion_subject} in {$project_name}";
            $message = "Discussion {$discussion_subject} has been closed by {$first_name} {$last_name}\n" . NEWLINE;
            $message .= "Click the following link to view the discussion:" . NEWLINE;
            $message .= "{$url}\n" . NEWLINE;
            break;
    }
    # Generic link to requirement detail page if the $url variable has been set
    if ($display_generic_url) {
        $message .= "Click the following link to view the Requirement:" . NEWLINE;
        $message .= "{$generic_url}\n" . NEWLINE;
    }
    if ($display_generic_info) {
        $message .= "" . lang_get("project_name") . ": {$project_name}" . NEWLINE;
        $message .= "" . lang_get("req_id") . ": {$req_id}" . NEWLINE;
        $message .= "" . lang_get("req_version") . ": {$req_version}" . NEWLINE;
        $message .= "" . lang_get("req_name") . ": {$req_name}" . NEWLINE;
        $message .= "" . lang_get("req_detail") . ": {$req_detail}" . NEWLINE;
        $message .= "" . lang_get("req_status") . ": {$req_version_status}" . NEWLINE;
        $message .= "" . lang_get("req_area_covered") . ": {$req_area_covered}" . NEWLINE;
        $message .= "" . lang_get("req_functionality") . ": {$req_functionality}" . NEWLINE;
        $message .= "" . lang_get("req_doc_type") . ": {$req_doc_type}\n" . NEWLINE;
    }
    # Convert any html entities stored in the DB back to characters.
    $message = util_unhtmlentities($message);
    email_send($recipients, $subject, $message);
}
$project_manager = user_has_rights($project_id, $user_id, MANAGER);
html_window_title();
html_print_body();
html_page_title($project_name . " - " . lang_get("req_discussion_page"));
html_page_header($db, $project_name);
html_print_menu();
requirement_menu_print($page);
error_report_check($_GET);
$row_discussion = discussion_get_detail($s_discussion_id);
$req_id = util_pad_id($row_discussion[DISC_REQ_ID]);
$discussion_author = $row_discussion[DISC_AUTHOR];
$discussion_date = $row_discussion[DISC_DATE];
$discussion_subject = $row_discussion[DISC_SUBJECT];
$discussion_status = $row_discussion[DISC_STATUS];
$discussion_discussion = util_html_encode_string($row_discussion[DISC_DISCUSSION]);
$rows_requirement = requirement_get_detail($project_id, $req_id);
$row_requirement = $rows_requirement[0];
$req_name = $row_requirement[REQ_FILENAME];
print "<br>" . NEWLINE;
print "<div align=center>";
# REQUIREMENT DETAILS
print "<table class=width100 rules=cols>" . NEWLINE;
print "<tr>" . NEWLINE;
html_tbl_print_header(lang_get('req_id'));
html_tbl_print_header(lang_get('req_name'));
print "</tr>" . NEWLINE;
print "<tr>" . NEWLINE;
print "<td width='33%' class=grid-data-c><a href='requirement_detail_page.php?req_id={$req_id}'>{$req_id}</a></td>" . NEWLINE;
print "<td width='33%' class=grid-data-c>{$req_name}</td>" . NEWLINE;
print "</tr>" . NEWLINE;
print "</table>" . NEWLINE;