From 694424eb86b3ddc1ec7352f560618c21ced176bf Mon Sep 17 00:00:00 2001 From: Frank Rodgers Date: Fri, 27 Mar 2009 13:34:19 -0400 Subject: [PATCH] Fix #10026: implemented tag management page. Signed-off-by: John Reese --- config_defaults_inc.php | 9 ++ core/html_api.php | 7 ++ core/tag_api.php | 1 + lang/strings_english.txt | 3 + manage_tags_page.php | 235 +++++++++++++++++++++++++++++++++++++++ tag_create.php | 49 ++++++++ 6 files changed, 304 insertions(+) create mode 100644 manage_tags_page.php create mode 100644 tag_create.php diff --git a/config_defaults_inc.php b/config_defaults_inc.php index ba33739e41..d551adc86f 100644 --- a/config_defaults_inc.php +++ b/config_defaults_inc.php @@ -2328,6 +2328,15 @@ */ $g_default_manage_user_prefix = 'ALL'; + /** + * Default tag prefix used to filter the list of tags in + * manage_tags_page.php. Change this to 'A' (or any other + * letter) if you have a lot of tags in the system and loading + * the manage tags page takes a long time. + * @global string $g_default_manage_tag_prefix + */ + $g_default_manage_tag_prefix = 'ALL'; + /** * CSV Export * Set the csv separator diff --git a/core/html_api.php b/core/html_api.php index e60deae405..8549c5eb44 100644 --- a/core/html_api.php +++ b/core/html_api.php @@ -777,6 +777,7 @@ function print_manage_menu( $p_page = '' ) { $t_manage_plugin_page = 'manage_plugin_page.php'; $t_manage_config_page = 'adm_config_report.php'; $t_manage_prof_menu_page = 'manage_prof_menu_page.php'; + $t_manage_tags_page = 'manage_tags_page.php'; switch( $p_page ) { case $t_manage_user_page: @@ -797,6 +798,9 @@ function print_manage_menu( $p_page = '' ) { case $t_manage_prof_menu_page: $t_manage_prof_menu_page = ''; break; + case $t_manage_tags_page: + $t_manage_tags_page = ''; + break; } echo '

'; @@ -806,6 +810,9 @@ function print_manage_menu( $p_page = '' ) { if( access_has_project_level( config_get( 'manage_project_threshold' ) ) ) { print_bracket_link( helper_mantis_url( $t_manage_project_menu_page ), lang_get( 'manage_projects_link' ) ); } + if( access_has_project_level( config_get( 'tag_edit_threshold' ) ) ) { + print_bracket_link( helper_mantis_url( $t_manage_tags_page ), lang_get( 'manage_tags_link' ) ); + } if( access_has_global_level( config_get( 'manage_custom_fields_threshold' ) ) ) { print_bracket_link( helper_mantis_url( $t_manage_custom_field_page ), lang_get( 'manage_custom_field_link' ) ); } diff --git a/core/tag_api.php b/core/tag_api.php index 2a8e5a508f..d49ade890b 100644 --- a/core/tag_api.php +++ b/core/tag_api.php @@ -764,3 +764,4 @@ function tag_stats_related( $p_tag_id, $p_limit = 5 ) { return $t_tags; } + diff --git a/lang/strings_english.txt b/lang/strings_english.txt index d5204aefab..66b66b95cd 100644 --- a/lang/strings_english.txt +++ b/lang/strings_english.txt @@ -759,6 +759,7 @@ $s_manage_config_link = 'Manage Configuration'; $s_manage_threshold_config = 'Workflow Thresholds'; $s_manage_email_config = 'E-mail Notifications'; $s_manage_workflow_config = 'Workflow Transitions'; +$s_manage_tags_link = 'Manage Tags'; $s_create_new_account_link = 'Create New Account'; $s_projects_link = 'Projects'; $s_documentation_link = 'Documentation'; @@ -1492,6 +1493,8 @@ $s_tag_history_renamed = 'Tag Renamed'; $s_tag_related = 'Related Tags'; $s_tag_related_issues = 'Shared Issues (%1$s)'; $s_tag_stats_attached = 'Issues attached: %1$s'; +$s_tag_create = 'Create Tag'; +$s_show_all_tags = 'ALL'; # Time Tracking $s_time_tracking_billing_link = 'Billing'; diff --git a/manage_tags_page.php b/manage_tags_page.php new file mode 100644 index 0000000000..2a052c62a5 --- /dev/null +++ b/manage_tags_page.php @@ -0,0 +1,235 @@ +. + +/** + * @package MantisBT + * @copyright Copyright (C) 2002 - 2009 MantisBT Team - mantisbt-dev@lists.sourceforge.net + * @link http://www.mantisbt.org + */ + /** + * MantisBT Core API's + */ + +require_once( 'core.php' ); + +$t_core_path = config_get( 'core_path' ); + +/** + * requires tag_api + */ +require_once( $t_core_path . 'tag_api.php' ); +require_once( $t_core_path . 'user_pref_api.php' ); +require_once( $t_core_path . 'form_api.php' ); + +access_ensure_global_level( config_get( 'tag_view_threshold' ) ); + +compress_enable(); + +html_page_top1( lang_get( 'manage_tags_link' ) ); +html_page_top2(); + +print_manage_menu(); + +$t_can_edit = access_has_global_level( config_get( 'tag_edit_threshold' ) ); +$f_filter = strtoupper( gpc_get_string( 'filter', config_get( 'default_manage_tag_prefix' ) ) ); +$f_page_number = gpc_get_int( 'page_number', 1 ); +$t_tag_table = db_get_table( 'mantis_tag_table' ); + +# Start Index Menu +$t_prefix_array = array( 'ALL' ); + +for ( $i = 'A'; $i != 'AA'; $i++ ) { + $t_prefix_array[] = $i; +} + +for ( $i = 0; $i <= 9; $i++ ) { + $t_prefix_array[] = "$i"; +} + +echo '
'; + +foreach ( $t_prefix_array as $t_prefix ) { + if ( $t_prefix === 'ALL' ) { + $t_caption = lang_get( 'show_all_tags' ); + } else { + $t_caption = $t_prefix; + } + + if ( $t_prefix == $f_filter ) { + $t_link = "$t_caption"; + } else { + $t_link = '' . $t_caption . ''; + } + + echo ''; +} + +echo '
' . $t_link . '
'; + +$t_where_params = array(); + +if ( $f_filter === 'ALL' ) { + $t_where = '1'; +} else { + $t_where_params[] = db_prepare_string( $f_filter . '%' ); + $t_where = db_helper_like( 'name' ); +} + +# Set the number of Tags per page. +$t_per_page = 20; +$t_offset = (( $f_page_number - 1 ) * $t_per_page ); + +# Determine number of tags in tag table +$t_total_tag_count = 0; +$t_result = ''; +$t_query = "SELECT count(*) + FROM $t_tag_table + WHERE $t_where"; + +$t_result = db_query_bound( $t_query, $t_where_params ); +$t_row = db_fetch_array( $t_result ); +$t_total_tag_count = (int)db_result( $t_result ); + +#Number of pages from result +$t_page_count = ceil( $t_total_tag_count / $t_per_page ); + +if ( $t_page_count < 1 ) { + $t_page_count = 1; +} + +# Make sure $p_page_number isn't past the last page. +if ( $f_page_number > $t_page_count ) { + $f_page_number = $t_page_count; +} + +# Make sure $p_page_number isn't before the first page +if ( $f_page_number < 1 ) { + $f_page_number = 1; +} + +# Retrive Tags from tag table +$t_query = "SELECT * + FROM $t_tag_table + WHERE " . $t_where . + ' ORDER BY name'; + +$t_result = db_query_bound( $t_query, $t_where_params, $t_per_page, $t_offset ); + +?> + +
+ + + + + + + + + + + + + + + > + + + + + + + + + + + + + + +
+ [] + +
+ + + +
+ + + +
+ + + + +

+ + + + + + + + + + + + + + + + + + + + + + +
+ +
+ * + + + + +
+ + +
+ * + + +
+ + +. + +/** + * @package MantisBT + * @copyright Copyright (C) 2002 - 2009 MantisBT Team - mantisbt-dev@lists.sourceforge.net + * @link http://www.mantisbt.org + */ + /** + * MantisBT Core API's + */ +require_once( 'core.php' ); +$t_core_path = config_get( 'core_path' ); +require_once ( $t_core_path . 'html_api.php' ); +require_once ( $t_core_path . 'form_api.php' ); +require_once( $t_core_path . 'tag_api.php' ); + +form_security_validate( 'tag_create' ); + +$f_tag_name = gpc_get_string( 'name' ); +$f_tag_description = gpc_get_string( 'description' ); + +$t_tag_user = auth_get_current_user_id(); + +if ( !is_null( $f_tag_name )) { + $t_tags = tag_parse_string( $f_tag_name ); + foreach ( $t_tags as $t_tag_row ) { + if ( -1 == $t_tag_row['id'] ) { + tag_create( $t_tag_row['name'], $t_tag_user, $f_tag_description ); + } + } +} + +form_security_purge( 'tag_create' ); +print_successful_redirect( 'manage_tags_page.php' ); +