/**
 * @param $edit_page
 * @param $obsolete_flag
 */
function print_versions($edit_page, $obsolete_flag)
{
    $specmanagement_database_api = new specmanagement_database_api();
    $specmanagement_print_api = new specmanagement_print_api();
    $obsolote = false;
    if ($obsolete_flag) {
        $obsolote = null;
    }
    if ($edit_page) {
        $versions = version_get_all_rows_with_subs(helper_get_current_project(), null, null);
    } else {
        $versions = version_get_all_rows_with_subs(helper_get_current_project(), null, $obsolote);
    }
    for ($version_index = 0; $version_index < count($versions); $version_index++) {
        $version = $versions[$version_index];
        $current_type = $specmanagement_database_api->get_type_string($specmanagement_database_api->get_type_by_version($version['id']));
        $specmanagement_print_api->printRow();
        echo '<input type="hidden" name="version_ids[]" value="' . $version['id'] . '"/>';
        print_name($edit_page, $version);
        print_released($edit_page, $version_index, $version);
        print_obsolete($edit_page, $version_index, $version);
        print_date($edit_page, $version);
        print_type($edit_page, $current_type, $version);
        print_description($edit_page, $version);
        print_action($edit_page, $version);
        echo '</tr>';
    }
}
function calculate_page_content()
{
    $specmanagement_database_api = new specmanagement_database_api();
    $specmanagement_print_api = new specmanagement_print_api();
    $types = array();
    $types_rows = $specmanagement_database_api->get_full_types();
    foreach ($types_rows as $types_row) {
        $types[] = $types_row[1];
    }
    html_page_top1(plugin_lang_get('select_doc_title'));
    echo '<link rel="stylesheet" href="' . SPECMANAGEMENT_PLUGIN_URL . 'files/specmanagement.css">';
    html_page_top2();
    //   if ( plugin_is_installed( 'WhiteboardMenu' ) && file_exists ( config_get_global ( 'plugin_path' ) . 'WhiteboardMenu' ) )
    //   {
    //      require_once WHITEBOARDMENU_CORE_URI . 'whiteboard_print_api.php';
    //      $whiteboard_print_api = new whiteboard_print_api();
    //      $whiteboard_print_api->printWhiteboardMenu();
    //   }
    if (project_includes_user(helper_get_current_project(), auth_get_current_user_id()) || helper_get_current_project() == 0 || user_is_administrator(auth_get_current_user_id())) {
        echo '<div align="center">';
        echo '<hr size="1" width="50%" />';
        $specmanagement_print_api->printTableTop('50');
        $specmanagement_print_api->printFormTitle(2, 'menu_title');
        $specmanagement_print_api->printCategoryField(1, 1, 'select_type');
        echo '<td>';
        echo '<form method="post" name="form_set_source" action="' . plugin_page('editor') . '">';
        print_document_selection($types);
        $specmanagement_print_api->printRow();
        echo '<td class="center" colspan="2">';
        echo '<input type="submit" name="formSubmit" class="button" value="' . plugin_lang_get('select_confirm') . '"/>';
        echo '</td>';
        echo '</tr>';
        echo '</form>';
        echo '</td>';
        $specmanagement_print_api->printTableFoot();
    } else {
        echo '<table class="width60"><tr><td class="center">' . lang_get('access_denied') . '</td></tr></table>';
    }
    html_page_bottom1();
}
/**
 * @param $edit_page
 */
function print_types($edit_page)
{
    $specmanagement_database_api = new specmanagement_database_api();
    $specmanagement_print_api = new specmanagement_print_api();
    $types = $specmanagement_database_api->get_full_types();
    for ($type_index = 0; $type_index < count($types); $type_index++) {
        $type = $types[$type_index];
        $type_id = $type[0];
        $type_string = $type[1];
        $type_options_set = $type[2];
        $type_options = explode(';', $type_options_set);
        $option_show_duration = $type_options[0];
        $option_show_expenses_overview = $type_options[1];
        $option_show_directory = $type_options[2];
        $specmanagement_print_api->printRow();
        echo '<input type="hidden" name="type_ids[]" value="' . $type_id . '"/>';
        print_name($type_string);
        print_duration($edit_page, $type_index, $option_show_duration);
        print_expoverview($edit_page, $type_index, $option_show_expenses_overview);
        print_dictionary($edit_page, $type_index, $option_show_directory);
        echo '</tr>';
    }
}
/**
 * @param $amount_stat_columns
 * @param $print_flag
 * @param $show_zero_issues
 * @param $versions
 */
function print_tablebody($amount_stat_columns, $print_flag, $show_zero_issues, $versions)
{
    $specmanagement_database_api = new specmanagement_database_api();
    $specmanagement_print_api = new specmanagement_print_api();
    echo '<tbody>';
    for ($version_index = 0; $version_index < count($versions); $version_index++) {
        $version = $versions[$version_index];
        $version_spec_bug_ids = $specmanagement_database_api->get_version_spec_bugs($version['version']);
        if (is_null($version_spec_bug_ids) && !$show_zero_issues) {
            continue;
        }
        $version_deadline = date_is_null($version['date_order']) ? '' : string_attribute(date(config_get('calendar_date_format'), $version['date_order']));
        $timeleft = time() - $version['date_order'];
        $unsolved_bug_duration = null;
        $add_rel_duration = 0;
        $status_process = null;
        $uncertainty_bug_ids = array();
        $add_rel_uncertainty_bug_ids = array();
        $sum_duration = 0;
        $uncertainty_status_process = null;
        $unsolved_bug_finished_date = null;
        $null_issues_flag = true;
        if (!is_null($version_spec_bug_ids)) {
            $unsolveld_bug_ids = get_unsolved_issues($version_spec_bug_ids);
            $unsolved_bug_duration = $specmanagement_database_api->get_bug_array_duration($unsolveld_bug_ids);
            $rel_based_data = calculate_rel_based_data($unsolveld_bug_ids);
            $add_rel_duration = $rel_based_data[0];
            $add_rel_uncertainty_bug_ids = $rel_based_data[1];
            $sum_duration = $unsolved_bug_duration + $add_rel_duration;
            $status_process = 100 * round(1 - count($unsolveld_bug_ids) / count($version_spec_bug_ids), 2);
            $uncertainty_bug_ids = get_uncertainty_issues($unsolveld_bug_ids);
            $uncertainty_status_process = 100 * round(count($uncertainty_bug_ids) / count($version_spec_bug_ids), 2);
            $null_issues_flag = false;
        }
        $time_delay = calc_time_delay($timeleft, $sum_duration);
        $specmanagement_print_api->printRow();
        print_version($version);
        print_date($version_deadline, $time_delay[0]);
        print_issue_amount($amount_stat_columns, $print_flag, $version, $version_spec_bug_ids, $null_issues_flag);
        print_process($status_process, $null_issues_flag);
        print_duration($sum_duration, $add_rel_duration, $null_issues_flag);
        print_uncertainty($uncertainty_bug_ids, $add_rel_uncertainty_bug_ids, $uncertainty_status_process, $null_issues_flag);
        //print_information( $version, $null_issues_flag, $time_delay[1] );
        echo '</tr>';
    }
    echo '</tbody>';
}
auth_reauthenticate();
access_ensure_global_level(plugin_config_get('AccessLevel'));
html_page_top1(plugin_lang_get('config_title'));
html_page_top2();
print_manage_menu();
echo '<br/>';
echo '<form action="' . plugin_page('config_update') . '" method="post">';
echo form_security_field('plugin_SpecManagement_config_update');
if ($specmanagement_print_api->getMantisVersion() == '1.2.') {
    echo '<table align="center" class="width75" cellspacing="1">';
} else {
    echo '<div class="form-container">';
    echo '<table>';
}
$specmanagement_print_api->printFormTitle(2, 'config_caption');
$specmanagement_print_api->printRow();
echo '<td class="category" width="30%" colspan="1">';
echo '<span class="required">*</span>' . plugin_lang_get('config_accesslevel');
echo '</td>';
echo '<td width="200px" colspan="1">';
echo '<select name="AccessLevel">';
print_enum_string_option_list('access_levels', plugin_config_get('AccessLevel', PLUGINS_SPECMANAGEMENT_THRESHOLD_LEVEL_DEFAULT));
echo '</select>';
echo '</td>';
echo '</tr>';
$specmanagement_print_api->printRow();
echo '<td class="category" width="30%" colspan="1">';
echo '<span class="required">*</span>' . plugin_lang_get('config_readlevel');
echo '</td>';
echo '<td width="200px" colspan="1">';
echo '<select name="ReadAccessLevel">';