/**
 * @param $type_id
 * @param $project_id
 * @return array
 */
function get_version_ids($type_id, $project_id)
{
    $specmanagement_database_api = new specmanagement_database_api();
    $version_id_array = array();
    $version_ids = $specmanagement_database_api->get_version_ids($type_id, $project_id);
    foreach ($version_ids as $version_id) {
        array_push($version_id_array, $version_id);
    }
    if ($project_id != 0) {
        $sub_project_ids = project_hierarchy_get_all_subprojects($project_id);
        foreach ($sub_project_ids as $sub_project_id) {
            $version_ids = $specmanagement_database_api->get_version_ids($type_id, $sub_project_id);
            foreach ($version_ids as $version_id) {
                array_push($version_id_array, $version_id);
            }
        }
    }
    return $version_id_array;
}
/**
 * @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>';
    }
}
<?php

require_once SPECMANAGEMENT_CORE_URI . 'specmanagement_constant_api.php';
require_once SPECMANAGEMENT_CORE_URI . 'specmanagement_database_api.php';
$specmanagement_database_api = new specmanagement_database_api();
if (isset($_POST['con_reset'])) {
    $specmanagement_database_api->reset_plugin();
} else {
    print_successful_redirect(plugin_page('config_page', true));
}
print_successful_redirect('manage_plugin_page.php');
 /**
  * Trigger the removal of plugin data if a bug was removed
  *
  * @param $event
  * @param $bug_id
  */
 function deleteBugReference($event, $bug_id)
 {
     require_once SPECMANAGEMENT_CORE_URI . 'specmanagement_database_api.php';
     $specmanagement_database_api = new specmanagement_database_api();
     $specmanagement_database_api->delete_source_row_by_bug($bug_id);
     $specmanagement_database_api->delete_ptime_row($bug_id);
 }
<?php

auth_reauthenticate();
require_once SPECMANAGEMENT_CORE_URI . 'specmanagement_database_api.php';
$specmanagement_database_api = new specmanagement_database_api();
$update = gpc_get_bool('update', false);
$addversion = gpc_get_bool('addversion', false);
/**
 * Submit new version
 */
if ($addversion && isset($_POST['new_version_name']) && isset($_POST['new_version_date'])) {
    $project_id = helper_get_current_project();
    $new_version_date = new DateTime($_POST['new_version_date']);
    $new_version_date_timestamp = date_timestamp_get($new_version_date);
    $new_version_name = $_POST['new_version_name'];
    $new_version_name_trimmed = trim(preg_replace('/\\s+/', ' ', $new_version_name));
    if (version_is_unique($new_version_name_trimmed, $project_id) && strlen($new_version_name_trimmed) > 0) {
        version_add($project_id, $new_version_name_trimmed, false, '', $new_version_date_timestamp);
    }
}
/**
 * Change all existing versions
 */
if ($update && isset($_POST['version_ids'])) {
    $version_ids = $_POST['version_ids'];
    $versions = $_POST['version'];
    $date_order = $_POST['date_order'];
    $type = $_POST['type'];
    $description = $_POST['description'];
    for ($version_index = 0; $version_index < count($version_ids); $version_index++) {
        $version = version_get($version_ids[$version_index]);
/**
 * @param $unsolveld_bug_ids
 * @return array
 */
function get_uncertainty_issues($unsolveld_bug_ids)
{
    $specmanagement_database_api = new specmanagement_database_api();
    $uncertainty_bug_ids = array();
    foreach ($unsolveld_bug_ids as $unsolveld_bug_id) {
        if ($specmanagement_database_api->get_bug_duration($unsolveld_bug_id) == 0) {
            array_push($uncertainty_bug_ids, $unsolveld_bug_id);
        }
    }
    return $uncertainty_bug_ids;
}
function print_type($edit_page, $current_type, $version)
{
    $specmanagement_database_api = new specmanagement_database_api();
    echo '<td>';
    if ($edit_page) {
        $types = array();
        $types_rows = $specmanagement_database_api->get_full_types();
        foreach ($types_rows as $types_row) {
            $types[] = $types_row[1];
        }
        echo '<span class="select">';
        echo '<select ' . helper_get_tab_index() . ' id="proj-version-type" name="type[]">';
        echo '<option value=""></option>';
        foreach ($types as $type) {
            echo '<option value="' . $type . '"';
            check_selected(string_attribute($current_type), $type);
            echo '>' . $type . '</option>';
        }
        echo '</select>';
    } else {
        $type_id = $specmanagement_database_api->get_type_by_version($version['id']);
        $type_string = $specmanagement_database_api->get_type_string($type_id);
        echo string_display($type_string);
    }
    echo '</td>';
}
/**
 * @param $project_ids
 * @return mixed
 */
function prepare_relevant_issues($project_ids)
{
    $specmanagement_database_api = new specmanagement_database_api();
    $reachable_issue_ids = array();
    foreach ($project_ids as $project_id) {
        $project_related_issue_ids = $specmanagement_database_api->get_bugs_by_project($project_id);
        if (!is_null($project_related_issue_ids)) {
            foreach ($project_related_issue_ids as $project_related_issue_id) {
                array_push($reachable_issue_ids, $project_related_issue_id);
            }
        }
    }
    return $reachable_issue_ids;
}
<?php

require_once SPECMANAGEMENT_CORE_URI . 'specmanagement_database_api.php';
auth_reauthenticate();
$specmanagement_database_api = new specmanagement_database_api();
$version_id = gpc_get_int('version_id');
$version = version_get($version_id);
access_ensure_project_level(config_get('manage_project_threshold'), $version->project_id);
helper_ensure_confirmed(lang_get('version_delete_sure') . '<br/>' . lang_get('word_separator') . string_display_line($version->version), lang_get('delete_version_button'));
$plugin_version_row = $specmanagement_database_api->get_plugin_version_row_by_version_id($version_id);
$p_version_id = $plugin_version_row[0];
$specmanagement_database_api->update_source_version_set_null($p_version_id);
$specmanagement_database_api->delete_version_row($version_id);
version_remove($version_id);
print_successful_redirect(plugin_page('manage_versions', true));
 /**
  * Prints the specific plugin fields in the bug-report user interface
  */
 public function printBugReportFields()
 {
     echo '<link rel="stylesheet" href="' . SPECMANAGEMENT_PLUGIN_URL . 'files/specmanagement_tooltip.css">';
     $specmanagement_database_api = new specmanagement_database_api();
     $work_packages = $specmanagement_database_api->get_project_spec_workpackages();
     if (substr(MANTIS_VERSION, 0, 4) == '1.2.') {
         $this->printRow();
         echo '<td class="category">';
         echo '<label><span>';
         echo plugin_lang_get('bug_view_specification_wpg') . '<br />';
         $this->print_workpackage_description_field();
         echo '</span></label>';
         echo '</td>';
         echo '<td>';
         echo '<span class="input">';
         echo '<input type="text" id="work_package" name="work_package" list="work_packages" style="min-width:650px;"/>';
         echo '<button type="button" onClick="document.getElementById(\'work_package\').value=\'\';">X</button>';
         echo '<datalist id="work_packages">';
         if (!empty($work_packages)) {
             foreach ($work_packages as $existing_work_package) {
                 echo '<option value="' . $existing_work_package . '">';
             }
         }
         echo '</datalist>';
         echo '</span>';
         echo '</td>';
         echo '</tr>';
         $this->printRow();
         echo '<td class="category" > ';
         echo '<label ><span > ' . plugin_lang_get('bug_view_planned_time') . ' ( ' . plugin_lang_get('editor_duration_unit') . ')' . ' </span ></label > ';
         echo '</td > ';
         echo '<td > ';
         echo '<span class="input" > ';
         echo '<input ' . helper_get_tab_index() . ' type = "text" id = "ptime" name = "ptime" size = "50" maxlength = "50" value = "" />';
         echo '</span > ';
         echo '<span class="label-style" ></span > ';
         echo '</td > ';
         echo '</tr > ';
     } else {
         echo '<div class="field-container" > ';
         echo '<label><span >';
         echo plugin_lang_get('bug_view_specification_wpg') . '<br />';
         $this->print_workpackage_description_field();
         echo ' </span ></label > ';
         echo '<span class="input" > ';
         echo '<input type = "text" id = "work_package" name = "work_package" list = "work_packages" />';
         echo '<button type = "button" onClick = "document.getElementById(\'work_package\').value=\'\';" > X</button > ';
         echo '<datalist id = "work_packages" > ';
         if (!empty($work_packages)) {
             foreach ($work_packages as $existing_work_package) {
                 echo '<option value = "' . $existing_work_package . '" > ';
             }
         }
         echo '</datalist > ';
         echo '</span > ';
         echo '<span class="label-style" ></span > ';
         echo '</div > ';
         echo '<div class="field-container" > ';
         echo '<label ><span > ' . plugin_lang_get('bug_view_planned_time') . ' ( ' . plugin_lang_get('editor_duration_unit') . ')' . ' </span ></label > ';
         echo '<span class="input" > ';
         echo '<input ' . helper_get_tab_index() . ' type = "text" id = "ptime" name = "ptime" size = "50" maxlength = "50" value = "" />';
         echo '</span > ';
         echo '<span class="label-style" ></span > ';
         echo '</div > ';
     }
 }
 /**
  * @param $p_version_id
  * @param $work_package
  * @param $chapter_prefix
  * @param $chapter_suffix
  * @param $option_show_duration
  * @param $detail_flag
  * @param $print_flag
  */
 public function process_chapter($p_version_id, $work_package, $chapter_prefix, $chapter_suffix, $option_show_duration, $detail_flag, $print_flag)
 {
     $specmanagement_database_api = new specmanagement_database_api();
     if ($detail_flag) {
         $chapter_duration = $specmanagement_database_api->get_workpackage_duration($p_version_id, $work_package);
         $this->print_chapter_document($chapter_prefix, $chapter_suffix, $option_show_duration, $chapter_duration);
     } else {
         $this->print_chapter_directory($print_flag, $chapter_suffix, $chapter_prefix, null, null, true);
     }
 }
<?php

auth_reauthenticate();
access_ensure_global_level(config_get('AccessLevel'));
form_security_validate('plugin_SpecManagement_config_update');
require_once SPECMANAGEMENT_CORE_URI . 'specmanagement_constant_api.php';
require_once SPECMANAGEMENT_CORE_URI . 'specmanagement_database_api.php';
require_once SPECMANAGEMENT_CORE_URI . 'specmanagement_config_api.php';
$specmanagement_database_api = new specmanagement_database_api();
$specmanagement_config_api = new specmanagement_config_api();
$option_change = gpc_get_bool('change', false);
$option_reset = gpc_get_bool('reset', false);
$option_addtype = gpc_get_bool('addtype', false);
$option_deltype = gpc_get_bool('deletetype', false);
$option_changetype = gpc_get_bool('changetype', false);
$option_manage_doc_types = gpc_get_bool('manage_doc_types', false);
/**
 * Submit configuration changes
 */
if ($option_change) {
    $specmanagement_config_api->updateValue('AccessLevel', ADMINISTRATOR);
    $specmanagement_config_api->updateValue('ReadAccessLevel', REPORTER);
    $specmanagement_config_api->updateValue('WriteAccessLevel', DEVELOPER);
    $specmanagement_config_api->updateButton('ShowInFooter');
    $specmanagement_config_api->updateButton('ShowFields');
    $specmanagement_config_api->updateButton('ShowMenu');
    $specmanagement_config_api->updateButton('ShowSpecStatCols');
    $col_amount = gpc_get_int('CAmount', PLUGINS_SPECMANAGEMENT_COLUMN_AMOUNT);
    if (plugin_config_get('CAmount') != $col_amount && plugin_config_get('CAmount') != '' && $col_amount <= PLUGINS_SPECMANAGEMENT_MAX_COLUMNS) {
        plugin_config_set('CAmount', $col_amount);
    } elseif (plugin_config_get('CAmount') == '') {
/**
 * @param $print_flag
 */
function calculate_page_content($print_flag)
{
    $specmanagement_database_api = new specmanagement_database_api();
    $specmanagement_print_api = new specmanagement_print_api();
    $specmanagement_editor_api = new specmanagement_editor_api();
    $version_id = $_POST['version_id'];
    $version_spec_bug_ids = $specmanagement_database_api->get_version_spec_bugs(version_get_field($version_id, 'version'));
    if (!is_null($version_spec_bug_ids)) {
        /** get bug and work package data */
        $plugin_version_obj = $specmanagement_database_api->get_plugin_version_row_by_version_id($version_id);
        $p_version_id = $plugin_version_obj[0];
        foreach ($version_spec_bug_ids as $version_spec_bug_id) {
            $p_source_row = $specmanagement_database_api->get_source_row($version_spec_bug_id);
            if (is_null($p_source_row[2])) {
                $specmanagement_database_api->update_source_row($version_spec_bug_id, $p_version_id, '');
            }
        }
        $work_packages = $specmanagement_database_api->get_document_spec_workpackages($p_version_id);
        asort($work_packages);
        $no_work_package_bug_ids = $specmanagement_database_api->get_workpackage_spec_bugs($p_version_id, '');
        /** get type options */
        $type_string = $specmanagement_database_api->get_type_string($specmanagement_database_api->get_type_by_version($version_id));
        $type_id = $specmanagement_database_api->get_type_id($type_string);
        $type_row = $specmanagement_database_api->get_type_row($type_id);
        $type_options = explode(';', $type_row[2]);
        /** generate and print page content */
        $specmanagement_editor_api->print_document_head($type_string, $version_id, $version_spec_bug_ids, $print_flag);
        if ($type_options[2] == '1') {
            $specmanagement_editor_api->print_directory($p_version_id, $work_packages, $no_work_package_bug_ids, $type_options[0], $print_flag);
        }
        $specmanagement_editor_api->print_editor_table_head($print_flag);
        $specmanagement_editor_api->generate_content($p_version_id, $work_packages, $no_work_package_bug_ids, $type_options[0], true, $print_flag);
        echo '</table>';
        if ($type_options[1] == '1') {
            $specmanagement_editor_api->print_expenses_overview($work_packages, $p_version_id, $print_flag, $no_work_package_bug_ids);
        }
    } else {
        echo '<br/>';
        $specmanagement_editor_api->print_editor_table_head($print_flag);
        echo '<tr><td class="center">';
        echo plugin_lang_get('editor_no_issues');
        echo '</td></tr>';
        $specmanagement_print_api->printTableFoot();
    }
}
<?php

require_once SPECMANAGEMENT_CORE_URI . 'specmanagement_constant_api.php';
require_once SPECMANAGEMENT_CORE_URI . 'specmanagement_database_api.php';
require_once SPECMANAGEMENT_CORE_URI . 'specmanagement_print_api.php';
$specmanagement_database_api = new specmanagement_database_api();
$specmanagement_print_api = new specmanagement_print_api();
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>';
<?php

auth_reauthenticate();
require_once SPECMANAGEMENT_CORE_URI . 'specmanagement_database_api.php';
$specmanagement_database_api = new specmanagement_database_api();
$update = gpc_get_bool('update', false);
/**
 * Change all existing types
 */
if ($update && isset($_POST['type_ids'])) {
    $type_ids = $_POST['type_ids'];
    for ($type_index = 0; $type_index < count($type_ids); $type_index++) {
        $project_id = helper_get_current_project();
        $type_id = $type_ids[$type_index];
        /* initialize option array */
        $type_options = array();
        /* initialize option values */
        $show_pt = null;
        $show_eo = null;
        $show_dy = null;
        /* get informations about changes */
        if (isset($_POST['showpt' . $type_index])) {
            $show_pt = $_POST['showpt' . $type_index];
            if ($show_pt == 'on') {
                $show_pt = 1;
            }
        }
        if (isset($_POST['showeo' . $type_index])) {
            $show_eo = $_POST['showeo' . $type_index];
            if ($show_eo == 'on') {
                $show_eo = 1;
/**
 * @param PDF $pdf
 * @param $type_string
 * @param $version_id
 * @param $version_spec_bug_ids
 * @return PDF
 */
function generate_document_head(PDF $pdf, $type_string, $version_id, $version_spec_bug_ids)
{
    $specmanagement_database_api = new specmanagement_database_api();
    $specmanagement_editor_api = new specmanagement_editor_api();
    $project_id = helper_get_current_project();
    $parent_project_id = $specmanagement_database_api->get_main_project_by_hierarchy($project_id);
    $head_project_id = $project_id;
    if ($parent_project_id == 0) {
        $parent_project_id = version_get_field($version_id, 'project_id');
        $head_project_id = version_get_field($version_id, 'project_id');
    }
    $table_column_widths = array(95, 95);
    $pdf->Cell(array_sum($table_column_widths), 0, '', 'T');
    $pdf->Ln();
    generate_document_head_row($pdf, 'head_version', version_get_field($version_id, 'version'));
    generate_document_head_row($pdf, 'manversions_thdoctype', $type_string);
    generate_document_head_row($pdf, 'head_customer', project_get_name($parent_project_id));
    generate_document_head_row($pdf, 'head_project', project_get_name($head_project_id));
    generate_document_head_row($pdf, 'head_date', date('d\\.m\\.Y'));
    generate_document_head_row($pdf, 'head_person_in_charge', $specmanagement_editor_api->calculate_person_in_charge($version_id));
    if (!is_null($version_spec_bug_ids)) {
        $process = $specmanagement_editor_api->get_process($version_spec_bug_ids);
        if (is_array($process)) {
            $sum_pt_all = $process[0];
            $sum_pt_bug = $process[1];
            $pt_process = 0;
            if ($sum_pt_all != 0) {
                $pt_process = round($sum_pt_bug * 100 / $sum_pt_all, 2);
            }
            $process_string = $sum_pt_bug . '/' . $sum_pt_all . ' ' . plugin_lang_get('editor_duration_unit') . ' (' . $pt_process . ' %)';
        } else {
            $process_string = $process . ' %';
        }
        generate_document_head_row($pdf, 'head_process', $process_string);
    }
    return $pdf;
}