View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0012518 | mantisbt | code cleanup | public | 2010-11-07 06:25 | 2013-04-27 18:39 |
Reporter | bartik | Assigned To | |||
Priority | normal | Severity | trivial | Reproducibility | always |
Status | acknowledged | Resolution | open | ||
Platform | XAMPP | OS | Windows | OS Version | XP SP3 |
Product Version | 1.2.3 | ||||
Summary | 0012518: Reduced the code ammount in account_prefs_inc.php | ||||
Description | I have reduced the coding in the aforementioned file. Using preset arrays and eval to create the final html code. The advantage is, you have to maintain less code and adding new code is easier (just extend the array with attributes). Someone might say it's a kind of templating. If such coding is acceptable by mantis conventions it might be done in other places too. | ||||
Tags | patch | ||||
Attached Files | 0594-Modified-account_prefs_inc.php-so-the-code-is-now-sm.patch (9,963 bytes)
From a8d110dd123d3321aeccd39fb80eeebc421e4cf0 Mon Sep 17 00:00:00 2001 From: unknown <Peter@.(none)> Date: Sun, 7 Nov 2010 12:13:39 +0100 Subject: [PATCH 594/594] Modified account_prefs_inc.php so the code is now smaller --- account_prefs_inc.php | 168 +++++++++--------------------------------------- 1 files changed, 32 insertions(+), 136 deletions(-) diff --git a/account_prefs_inc.php b/account_prefs_inc.php index c51e5dc..f25a2c1 100644 --- a/account_prefs_inc.php +++ b/account_prefs_inc.php @@ -105,134 +105,43 @@ </td> </tr> <?php + $t_email_settings = array ( + 'email_on_new', + 'email_on_assigned', + 'email_on_feedback', + 'email_on_resolved', + 'email_on_closed', + 'email_on_reopened', + 'email_on_bugnote', + 'email_on_status', + 'email_on_priority', + ); + + $t_email_categories = array ( + 'email_on_bugnote' => 'email_on_bugnote_added', + 'email_on_status' => 'email_on_status_change', + 'email_on_priority' => 'email_on_priority_change', + ); + if ( ON == config_get( 'enable_email_notification' ) ) { + foreach ( $t_email_settings as $t_email_setting ) { + $t_email_category = ( isset($t_email_categories[$t_email_setting]) ) ? $t_email_categories[$t_email_setting] : $t_email_setting; ?> <tr <?php echo helper_alternate_class() ?>> <td class="category"> - <?php echo lang_get( 'email_on_new' ) ?> + <?php echo lang_get( $t_email_category ) ?> </td> <td> - <input type="checkbox" name="email_on_new" <?php check_checked( $t_pref->email_on_new, ON ); ?> /> + <input type="checkbox" name="<?php echo $t_email_setting ?>" <?php check_checked( eval ( 'return $t_pref->'.$t_email_setting.';' ), ON ); ?> /> <?php echo lang_get( 'with_minimum_severity' ) ?> - <select name="email_on_new_min_severity"> + <select name="<?php echo $t_email_setting ?>_min_severity"> <option value="<?php echo OFF ?>"><?php echo lang_get( 'any' ) ?></option> <option disabled="disabled">-----</option> - <?php print_enum_string_option_list( 'severity', $t_pref->email_on_new_min_severity ) ?> - </select> - </td> -</tr> -<tr <?php echo helper_alternate_class() ?>> - <td class="category"> - <?php echo lang_get( 'email_on_assigned' ) ?> - </td> - <td> - <input type="checkbox" name="email_on_assigned" <?php check_checked( $t_pref->email_on_assigned, ON ); ?> /> - <?php echo lang_get( 'with_minimum_severity' ) ?> - <select name="email_on_assigned_min_severity"> - <option value="<?php echo OFF ?>"><?php echo lang_get( 'any' ) ?></option> - <option disabled="disabled">-----</option> - <?php print_enum_string_option_list( 'severity', $t_pref->email_on_assigned_min_severity ) ?> - </select> - </td> -</tr> -<tr <?php echo helper_alternate_class() ?>> - <td class="category"> - <?php echo lang_get( 'email_on_feedback' ) ?> - </td> - <td> - <input type="checkbox" name="email_on_feedback" <?php check_checked( $t_pref->email_on_feedback, ON ); ?> /> - <?php echo lang_get( 'with_minimum_severity' ) ?> - <select name="email_on_feedback_min_severity"> - <option value="<?php echo OFF ?>"><?php echo lang_get( 'any' ) ?></option> - <option disabled="disabled">-----</option> - <?php print_enum_string_option_list( 'severity', $t_pref->email_on_feedback_min_severity ) ?> - </select> - </td> -</tr> -<tr <?php echo helper_alternate_class() ?>> - <td class="category"> - <?php echo lang_get( 'email_on_resolved' ) ?> - </td> - <td> - <input type="checkbox" name="email_on_resolved" <?php check_checked( $t_pref->email_on_resolved, ON ); ?> /> - <?php echo lang_get( 'with_minimum_severity' ) ?> - <select name="email_on_resolved_min_severity"> - <option value="<?php echo OFF ?>"><?php echo lang_get( 'any' ) ?></option> - <option disabled="disabled">-----</option> - <?php print_enum_string_option_list( 'severity', $t_pref->email_on_resolved_min_severity ) ?> - </select> - </td> -</tr> -<tr <?php echo helper_alternate_class() ?>> - <td class="category"> - <?php echo lang_get( 'email_on_closed' ) ?> - </td> - <td> - <input type="checkbox" name="email_on_closed" <?php check_checked( $t_pref->email_on_closed, ON ); ?> /> - <?php echo lang_get( 'with_minimum_severity' ) ?> - <select name="email_on_closed_min_severity"> - <option value="<?php echo OFF ?>"><?php echo lang_get( 'any' ) ?></option> - <option disabled="disabled">-----</option> - <?php print_enum_string_option_list( 'severity', $t_pref->email_on_closed_min_severity ) ?> - </select> - </td> -</tr> -<tr <?php echo helper_alternate_class() ?>> - <td class="category"> - <?php echo lang_get( 'email_on_reopened' ) ?> - </td> - <td> - <input type="checkbox" name="email_on_reopened" <?php check_checked( $t_pref->email_on_reopened, ON ); ?> /> - <?php echo lang_get( 'with_minimum_severity' ) ?> - <select name="email_on_reopened_min_severity"> - <option value="<?php echo OFF ?>"><?php echo lang_get( 'any' ) ?></option> - <option disabled="disabled">-----</option> - <?php print_enum_string_option_list( 'severity', $t_pref->email_on_reopened_min_severity ) ?> - </select> - </td> -</tr> -<tr <?php echo helper_alternate_class() ?>> - <td class="category"> - <?php echo lang_get( 'email_on_bugnote_added' ) ?> - </td> - <td> - <input type="checkbox" name="email_on_bugnote" <?php check_checked( $t_pref->email_on_bugnote, ON ); ?> /> - <?php echo lang_get( 'with_minimum_severity' ) ?> - <select name="email_on_bugnote_min_severity"> - <option value="<?php echo OFF ?>"><?php echo lang_get( 'any' ) ?></option> - <option disabled="disabled">-----</option> - <?php print_enum_string_option_list( 'severity', $t_pref->email_on_bugnote_min_severity ) ?> - </select> - </td> -</tr> -<tr <?php echo helper_alternate_class() ?>> - <td class="category"> - <?php echo lang_get( 'email_on_status_change' ) ?> - </td> - <td> - <input type="checkbox" name="email_on_status" <?php check_checked( $t_pref->email_on_status, ON ); ?> /> - <?php echo lang_get( 'with_minimum_severity' ) ?> - <select name="email_on_status_min_severity"> - <option value="<?php echo OFF ?>"><?php echo lang_get( 'any' ) ?></option> - <option disabled="disabled">-----</option> - <?php print_enum_string_option_list( 'severity', $t_pref->email_on_status_min_severity ) ?> - </select> - </td> -</tr> -<tr <?php echo helper_alternate_class() ?>> - <td class="category"> - <?php echo lang_get( 'email_on_priority_change' ) ?> - </td> - <td> - <input type="checkbox" name="email_on_priority" <?php check_checked( $t_pref->email_on_priority , ON); ?> /> - <?php echo lang_get( 'with_minimum_severity' ) ?> - <select name="email_on_priority_min_severity"> - <option value="<?php echo OFF ?>"><?php echo lang_get( 'any' ) ?></option> - <option disabled="disabled">-----</option> - <?php print_enum_string_option_list( 'severity', $t_pref->email_on_priority_min_severity ) ?> + <?php print_enum_string_option_list( 'severity', eval ( 'return $t_pref->'.$t_email_setting.'_min_severity;' ) ) ?> </select> </td> </tr> +<?php } ?> <tr <?php echo helper_alternate_class() ?>> <td class="category"> <?php echo lang_get( 'email_bugnote_limit' ) ?> @@ -241,27 +150,14 @@ <input type="text" name="email_bugnote_limit" maxlength="2" size="2" value="<?php echo $t_pref->email_bugnote_limit ?>" /> </td> </tr> -<?php } else { ?> - <input type="hidden" name="email_on_new" value="<?php echo $t_pref->email_on_new ?>" /> - <input type="hidden" name="email_on_assigned" value="<?php echo $t_pref->email_on_assigned ?>" /> - <input type="hidden" name="email_on_feedback" value="<?php echo $t_pref->email_on_feedback ?>" /> - <input type="hidden" name="email_on_resolved" value="<?php echo $t_pref->email_on_resolved ?>" /> - <input type="hidden" name="email_on_closed" value="<?php echo $t_pref->email_on_closed ?>" /> - <input type="hidden" name="email_on_reopened" value="<?php echo $t_pref->email_on_reopened ?>" /> - <input type="hidden" name="email_on_bugnote" value="<?php echo $t_pref->email_on_bugnote ?>" /> - <input type="hidden" name="email_on_status" value="<?php echo $t_pref->email_on_status ?>" /> - <input type="hidden" name="email_on_priority" value="<?php echo $t_pref->email_on_priority ?>" /> - <input type="hidden" name="email_on_new_min_severity" value="<?php echo $t_pref->email_on_new_min_severity ?>" /> - <input type="hidden" name="email_on_assigned_min_severity" value="<?php echo $t_pref->email_on_assigned_min_severity ?>" /> - <input type="hidden" name="email_on_feedback_min_severity" value="<?php echo $t_pref->email_on_feedback_min_severity ?>" /> - <input type="hidden" name="email_on_resolved_min_severity" value="<?php echo $t_pref->email_on_resolved_min_severity ?>" /> - <input type="hidden" name="email_on_closed_min_severity" value="<?php echo $t_pref->email_on_closed_min_severity ?>" /> - <input type="hidden" name="email_on_reopened_min_severity" value="<?php echo $t_pref->email_on_reopened_min_severity ?>" /> - <input type="hidden" name="email_on_bugnote_min_severity" value="<?php echo $t_pref->email_on_bugnote_min_severity ?>" /> - <input type="hidden" name="email_on_status_min_severity" value="<?php echo $t_pref->email_on_status_min_severity ?>" /> - <input type="hidden" name="email_on_priority_min_severity" value="<?php echo $t_pref->email_on_priority_min_severity ?>" /> +<?php } else { + foreach ( $t_email_settings as $t_email_setting ) { +?> + <input type="hidden" name="<?php echo $t_email_setting ?>" value="<?php eval ( 'echo $t_pref->'.$t_email_setting.';' ) ?>" /> + <input type="hidden" name="<?php echo $t_email_setting.'_min_severity' ?>" value="<?php eval ( 'echo $t_pref->'.$t_email_setting.';' ) ?>" /> <input type="hidden" name="email_bugnote_limit" value="<?php echo $t_pref->email_bugnote_limit ?>" /> -<?php } ?> +<?php } + } ?> <tr <?php echo helper_alternate_class() ?>> <td class="category"> <?php echo lang_get( 'timezone' ) ?> -- 1.6.2.msysgit.0.186.gf7512 0001-The-hidden-input-for-email_bugnote_limit-was-generat.patch (1,044 bytes)
From 8532559ee6ff2f567b49af42cef2247dd81b075e Mon Sep 17 00:00:00 2001 From: unknown <Peter@.(none)> Date: Tue, 9 Nov 2010 19:49:52 +0100 Subject: [PATCH] The hidden input for email_bugnote_limit was generated excessively --- account_prefs_inc.php | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/account_prefs_inc.php b/account_prefs_inc.php index f25a2c1..36b9b33 100644 --- a/account_prefs_inc.php +++ b/account_prefs_inc.php @@ -155,9 +155,9 @@ ?> <input type="hidden" name="<?php echo $t_email_setting ?>" value="<?php eval ( 'echo $t_pref->'.$t_email_setting.';' ) ?>" /> <input type="hidden" name="<?php echo $t_email_setting.'_min_severity' ?>" value="<?php eval ( 'echo $t_pref->'.$t_email_setting.';' ) ?>" /> +<?php } ?> <input type="hidden" name="email_bugnote_limit" value="<?php echo $t_pref->email_bugnote_limit ?>" /> -<?php } - } ?> +<?php } ?> <tr <?php echo helper_alternate_class() ?>> <td class="category"> <?php echo lang_get( 'timezone' ) ?> -- 1.6.2.msysgit.0.186.gf7512 | ||||
Great patch, thanks for your efforts! I've queued this up for inclusion in 1.3.x. I am just curious as to whether you'd like your name/email on the commit messages? Your patches so far haven't included this information and I wasn't sure if it was intentional. |
|
Well it was not that great after all, the patch I mean. Here is a fix. The hidden input for email_bugnote_limit was generated inside of the foreach loop with each and every email setting. Now it is generated correctly. |
|
The patch no longer applies because of HTML changes we've made across the MantisBT codebase. I was going to port your patch across however I noticed that is requires the use of PHP's eval() function which I don't like. Therefore I'm leaving this issue on the sidelines at the moment. We are planning on redoing MantisBT pages completely with a new templating system so I'm sure the file will be cleaned up/simplified when that occurs. |
|
Removed assignment. dhx will not contribute to this issue in near future. |
|