Skip to content

Commit

Permalink
I started playing with the custom field stuff tonight and these are t…
Browse files Browse the repository at this point in the history
…he fixes I had to make to get it working. I also cleaned up the manage_* pages a little.

---

* manage_proj_custom_field_add_existing.php:
  + use gpc_* to get form fields
  + custom_field_bind() errors if there's a problem so there's no need to display our own error
* manage_proj_custom_field_add_new.php:
  + use gpc_* to get form fields
  + use is_blank() instead of ==''
  + add $t_ prefix to $duplicate
* manage_proj_custom_field_delete.php:
  + use gpc_* to get form fields
  + remove unneeded use of $t_affected_projects
  + we can't print $query since such a variable doesn't exist.  Also custom_field_delete() errors itself.
* manage_proj_custom_field_edit_page.php:
  + use gpc_* to get form fields
  + correct spelling of sequence as 'seqence'
* manage_proj_custom_field_remove.php:
  + use gpc_* to get form fields
  + custom_field_remove() errors if there's a problem so there's no need to display our own error
* manage_proj_custom_field_update.php:
  + use gpc_get_bool() to get f_advanced
  + correct spelling of sequence as 'seqence'
  + custom_field_update() errors if there's a problem so there's no need to display our own error
* core/custom_field_api.php
  (custom_field_ensure_name_unique): new function that call custom_field_is_name_unique() and errors if it returns false
  (custom_field_create): make sure the name is unique before creating a new field
  (custom_field_bind): move db_prepare_* calls to top of function for clarity
  (custom_field_update): use db_prepare_bool() for the advanced field
* lang/strings_english.txt
  (s_custom_field_seqence): correct spelling of sequence as 'seqence' (in variable name and contents)
  (s_custom_field_type_enum_string): correct spelling of enumeration as 'enummeration'
* lang/strings_german.txt
  (s_custom_field_seqence): rename to s_custom_field_sequence (spelling error)


git-svn-id: http://mantisbt.svn.sourceforge.net/svnroot/mantisbt/trunk@1646 f5dc347c-c33d-0410-90a0-b07cc1902cb9
  • Loading branch information
Julian Fitzell committed Dec 5, 2002
1 parent 4b3fcb7 commit ff5b7fa
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 79 deletions.
25 changes: 19 additions & 6 deletions core/custom_field_api.php
Expand Up @@ -5,7 +5,7 @@
# See the files README and LICENSE for details

# --------------------------------------------------------
# $Id: custom_field_api.php,v 1.5 2002-12-05 07:23:30 jfitzell Exp $
# $Id: custom_field_api.php,v 1.6 2002-12-05 09:07:43 jfitzell Exp $
# --------------------------------------------------------

###########################################################################
Expand Down Expand Up @@ -140,6 +140,17 @@ function custom_field_is_name_unique( $p_name ) {
}
}

# --------------------
# Check to see whether the name is unique
# return true if the name has not been used, error otherwise
function custom_field_ensure_name_unique( $p_name ) {
if ( custom_field_is_name_unique( $p_name ) ) {
return true;
} else {
trigger_error( ERROR_CUSTOM_FIELD_NAME_NOT_UNIQUE, ERROR );
}
}

# --------------------
# Return true if the user can read the value of the field for the given bug,
# false otherwise.
Expand Down Expand Up @@ -185,6 +196,8 @@ function custom_field_has_write_access( $p_field_id, $p_bug_id, $p_user_id ) {
function custom_field_create( $p_name ) {
$c_name = db_prepare_string( $p_name );

custom_field_ensure_name_unique( $p_name );

$t_custom_field_table = config_get( 'mantis_custom_field_table' );
$query = "INSERT INTO
$t_custom_field_table
Expand All @@ -203,15 +216,15 @@ function custom_field_create( $p_name ) {
# return true on success
# return false if an error occures (e.g. non existing id)
function custom_field_bind( $p_field_id, $p_project_id ) {
$c_field_id = db_prepare_int( $p_field_id );
$c_project_id = db_prepare_int( $p_project_id );

custom_field_ensure_exists( $p_field_id );
project_ensure_exists( $p_project_id );

if( custom_field_in_project( $p_field_id, $p_project_id ) ) {
return false;
}
$c_field_id = db_prepare_int( $p_field_id );
$c_project_id = db_prepare_int( $p_project_id );

$t_custom_field_project_table = config_get( 'mantis_custom_field_project_table' );
$query = "INSERT INTO
$t_custom_field_project_table
Expand All @@ -230,7 +243,7 @@ function custom_field_bind( $p_field_id, $p_project_id ) {
# return true on success, false on failure
function custom_field_update( $p_field_id, $p_def_array ) {
$c_field_id = db_prepare_int( $p_field_id );
$c_name = db_prepare_string( $p_def_array['name'] );
$c_name = db_prepare_string( $p_def_array['name'] );
$c_type = db_prepare_int( $p_def_array['type'] );
$c_possible_values = db_prepare_string( $p_def_array['possible_values'] );
$c_default_value = db_prepare_string( $p_def_array['default_value'] );
Expand All @@ -239,7 +252,7 @@ function custom_field_update( $p_field_id, $p_def_array ) {
$c_access_level_rw = db_prepare_int( $p_def_array['access_level_rw'] );
$c_length_min = db_prepare_int( $p_def_array['length_min'] );
$c_length_max = db_prepare_int( $p_def_array['length_max'] );
$c_advanced = db_prepare_int( $p_def_array['advanced'] );
$c_advanced = db_prepare_bool( $p_def_array['advanced'] );
$c_sequence = db_prepare_int( $p_def_array['sequence'] );

$query = "UPDATE " .
Expand Down
10 changes: 5 additions & 5 deletions lang/strings_english.txt
Expand Up @@ -9,11 +9,11 @@
###########################################################################
# English strings for Mantis
# -------------------------------------------------
# $Revision: 1.92 $
# $Revision: 1.93 $
# $Author: jfitzell $
# $Date: 2002-12-04 08:05:48 $
# $Date: 2002-12-05 09:07:43 $
#
# $Id: strings_english.txt,v 1.92 2002-12-04 08:05:48 jfitzell Exp $
# $Id: strings_english.txt,v 1.93 2002-12-05 09:07:43 jfitzell Exp $
###########################################################################
?>
<?php
Expand Down Expand Up @@ -818,6 +818,6 @@
$s_custom_field_length_min = 'min. length';
$s_custom_field_length_max = 'max. length';
$s_custom_field_advanced = 'advanced';
$s_custom_field_seqence = 'seqence';
$s_custom_field_type_enum_string = '0:String,1:Numeric,2:Float,3:Enummeration,4:Email';
$s_custom_field_sequence = 'sequence';
$s_custom_field_type_enum_string = '0:String,1:Numeric,2:Float,3:Enumeration,4:Email';
?>
8 changes: 4 additions & 4 deletions lang/strings_german.txt
Expand Up @@ -10,11 +10,11 @@
# German: Stefan Meier, Stefan.Meier@cimsource.com
# German: Matthias Bauer, mantis-de@moeffju.de
# -------------------------------------------------
# $Revision: 1.45 $
# $Revision: 1.46 $
# $Author: jfitzell $
# $Date: 2002-12-04 08:05:48 $
# $Date: 2002-12-05 09:07:44 $
#
# $Id: strings_german.txt,v 1.45 2002-12-04 08:05:48 jfitzell Exp $
# $Id: strings_german.txt,v 1.46 2002-12-05 09:07:44 jfitzell Exp $
###########################################################################
?>
<?php
Expand Down Expand Up @@ -767,6 +767,6 @@
$s_custom_field_length_min = 'Mindestl&auml;nge';
$s_custom_field_length_max = 'Maximale L&auml;nge';
$s_custom_field_advanced = 'Erweitert';
$s_custom_field_seqence = 'Reihenfolge';
$s_custom_field_sequence = 'Reihenfolge';
$s_custom_field_type_enum_string = '0:Text,1:Zahlen,2:Gleitkomma Zahlen,3:Aufz&auml;hlung,4:EMail';
?>
21 changes: 6 additions & 15 deletions manage_proj_custom_field_add_existing.php
Expand Up @@ -10,32 +10,23 @@
<?php
check_access( MANAGER );

if ( empty( $f_field_id ) || empty( $f_project_id ) ) {
print_mantis_error( ERROR_EMPTY_FIELD );
}
$f_field_id = gpc_get_int( 'f_field_id' );
$f_project_id = gpc_get_int( 'f_project_id' );

$result = custom_field_bind( $f_field_id, $f_project_id );
custom_field_bind( $f_field_id, $f_project_id );

$t_redirect_url = 'manage_proj_edit_page.php?f_project_id='.$f_project_id;
$t_redirect_url = 'manage_proj_edit_page.php?f_project_id=' . $f_project_id;
?>
<?php print_page_top1() ?>
<?php
if ( $result ) {
print_meta_redirect( $t_redirect_url );
}
print_meta_redirect( $t_redirect_url );
?>
<?php print_page_top2() ?>

<br />
<div align="center">
<?php
if ( $result ) { # SUCCESS
echo lang_get( 'operation_successful' ).'<br />';
} else if ( $duplicate ) { # DUPLICATE
echo $MANTIS_ERROR[ERROR_CUSTOM_FIELD_NAME_NOT_UNIQUE].'<br />';
} else { # FAILURE
print_sql_error( $query );
}
echo lang_get( 'operation_successful' ).'<br />';

print_bracket_link( $t_redirect_url, lang_get( 'proceed' ) );
?>
Expand Down
18 changes: 8 additions & 10 deletions manage_proj_custom_field_add_new.php
Expand Up @@ -10,29 +10,27 @@
<?php
check_access( MANAGER );

if ( empty( $f_name ) ) {
print_mantis_error( ERROR_EMPTY_FIELD );
}
$f_name = gpc_get_string( 'f_name' );
$f_project_id = gpc_get_int( 'f_project_id' );

$t_names_array = explode( '|', $f_name );
$t_count = count( $t_names_array );
$duplicate = false;
$t_duplicate = false;

foreach ( $t_names_array as $t_name ) {
$t_name = trim( $t_name );
if ( $t_name == '') {
if ( is_blank( $t_name ) ) {
continue;
}

if ( custom_field_is_name_unique( $t_name ) ) {
$t_generated_id = custom_field_create( $t_name );
custom_field_bind( $t_generated_id, $f_project_id );
} else {
$duplicate = true;
$t_duplicate = true;
}
}

$t_redirect_url = 'manage_proj_edit_page.php?f_project_id='.$f_project_id;
$t_redirect_url = 'manage_proj_edit_page.php?f_project_id=' . $f_project_id;
?>
<?php print_page_top1() ?>
<?php
Expand All @@ -43,8 +41,8 @@
<br />
<div align="center">
<?php
if ( $duplicate ) { # DUPLICATE
echo $MANTIS_ERROR[ERROR_CUSTOM_FIELD_NAME_NOT_UNIQUE].'<br />';
if ( $t_duplicate ) { # DUPLICATE
echo $MANTIS_ERROR[ERROR_CUSTOM_FIELD_NAME_NOT_UNIQUE] . '<br />';
}

print_bracket_link( $t_redirect_url, lang_get( 'proceed' ) );
Expand Down
18 changes: 6 additions & 12 deletions manage_proj_custom_field_delete.php
Expand Up @@ -10,20 +10,16 @@
<?php
check_access( MANAGER );

if ( empty( $f_field_id ) || empty( $f_project_id ) ) {
print_mantis_error( ERROR_EMPTY_FIELD );
}

$t_affected_projects = false;
$f_field_id = gpc_get_int( 'f_field_id' );
$f_project_id = gpc_get_int( 'f_project_id' );

if( 0 == count( custom_field_get_project_ids( $f_field_id ) ) ) {
$result = custom_field_delete( $f_field_id );
} else {
$result = false;
$t_affected_projects = true;
}

$t_redirect_url = 'manage_proj_edit_page.php?f_project_id='.$f_project_id;
$t_redirect_url = 'manage_proj_edit_page.php?f_project_id=' . $f_project_id;
?>
<?php print_page_top1() ?>
<?php
Expand All @@ -37,11 +33,9 @@
<div align="center">
<?php
if ( $result ) { # SUCCESS
echo lang_get( 'operation_successful' ).'<br />';
} else if ( $t_affected_projects ) {
echo $MANTIS_ERROR[ERROR_CUSTOM_FIELD_IN_USE].'<br />';
} else { # FAILURE
print_sql_error( $query );
echo lang_get( 'operation_successful' ) . '<br />';
} else {
echo $MANTIS_ERROR[ERROR_CUSTOM_FIELD_IN_USE] . '<br />';
}

print_bracket_link( $t_redirect_url, lang_get( 'proceed' ) );
Expand Down
7 changes: 5 additions & 2 deletions manage_proj_custom_field_edit_page.php
Expand Up @@ -9,6 +9,9 @@
<?php login_cookie_check() ?>
<?php
check_access( MANAGER );

$f_field_id = gpc_get_int( 'f_field_id' );
$f_project_id = gpc_get_int( 'f_project_id' );
?>
<?php print_page_top1() ?>
<?php print_page_top2() ?>
Expand Down Expand Up @@ -120,10 +123,10 @@
</tr>
<tr <?php echo helper_alternate_class() ?>>
<td class="category">
<?php echo lang_get( 'custom_field_seqence' ) ?>
<?php echo lang_get( 'custom_field_sequence' ) ?>
</td>
<td>
<input type="text" name="f_seqence" size="32" maxlength="64" value="<?php echo $t_definition['seqence'] ?>" />
<input type="text" name="f_sequence" size="32" maxlength="64" value="<?php echo $t_definition['sequence'] ?>" />
</td>
</tr>
<tr>
Expand Down
19 changes: 6 additions & 13 deletions manage_proj_custom_field_remove.php
Expand Up @@ -10,30 +10,23 @@
<?php
check_access( MANAGER );

if ( empty( $f_field_id ) || empty( $f_project_id ) ) {
print_mantis_error( ERROR_EMPTY_FIELD );
}
$f_field_id = gpc_get_int( 'f_field_id' );
$f_project_id = gpc_get_int( 'f_project_id' );

$result = custom_field_remove( $f_field_id, $f_project_id );
custom_field_remove( $f_field_id, $f_project_id );

$t_redirect_url = 'manage_proj_edit_page.php?f_project_id='.$f_project_id;
$t_redirect_url = 'manage_proj_edit_page.php?f_project_id=' . $f_project_id;
?>
<?php print_page_top1() ?>
<?php
if ( $result ) {
print_meta_redirect( $t_redirect_url );
}
print_meta_redirect( $t_redirect_url );
?>
<?php print_page_top2() ?>

<br />
<div align="center">
<?php
if ( $result ) { # SUCCESS
echo lang_get( 'operation_successful' ).'<br />';
} else { # FAILURE
print_sql_error( $query );
}
echo lang_get( 'operation_successful' ).'<br />';

print_bracket_link( $t_redirect_url, lang_get( 'proceed' ) );
?>
Expand Down
18 changes: 6 additions & 12 deletions manage_proj_custom_field_update.php
Expand Up @@ -21,29 +21,23 @@
$t_values['access_level_rw'] = gpc_get_int( 'f_access_level_rw' );
$t_values['length_min'] = gpc_get_int( 'f_length_min' );
$t_values['length_max'] = gpc_get_int( 'f_length_max' );
$t_values['advanced'] = gpc_get_int( 'f_advanced', 0 );
$t_values['seqence'] = gpc_get_int( 'f_seqence' );
$t_values['advanced'] = gpc_get_bool( 'f_advanced' );
$t_values['sequence'] = gpc_get_int( 'f_sequence' );

$result = custom_field_update( $f_field_id, $t_values );
custom_field_update( $f_field_id, $t_values );

$t_redirect_url = 'manage_proj_edit_page.php?f_project_id='.$f_project_id;
$t_redirect_url = 'manage_proj_edit_page.php?f_project_id=' . $f_project_id;
?>
<?php print_page_top1() ?>
<?php
if ( $result ) {
print_meta_redirect( $t_redirect_url );
}
print_meta_redirect( $t_redirect_url );
?>
<?php print_page_top2() ?>

<br />
<div align="center">
<?php
if ( $result ) { # SUCCESS
echo lang_get( 'operation_successful' ).'<br />';
} else { # FAILURE
print_sql_error( $query );
}
echo lang_get( 'operation_successful' ).'<br />';

print_bracket_link( $t_redirect_url, lang_get( 'proceed' ) );
?>
Expand Down

0 comments on commit ff5b7fa

Please sign in to comment.