I recently had to install mantis 1.0.0 RC2 at a customers site.
There were some feature lacks, that gave you no access to the print_all_bug_options_page.php from print_all_bug_page.php
I had also no access to custom fields from print_all_bug_options_page.php, so that I could not select them to print in print_all_bug_page_excel.php
However, since this functions are essential to my customer, I had to add those features.
In order to do this, I had to do the patches, which are shown below.
If you are interested, you can download the patched files from http://www.123tk.de/downloads/mantis
They are available for free. It would be nice, if those patches could be merged to the RC3.
All changes are documented.
If you have some questions, feel free to mail.
Patches:
Code: Select all
--- Documents/downloads/mantis-1.0.0rc2/print_all_bug_page_excel.php 2005-08-18 17:33:28.000000000 +0200
+++ public_html/cvs_projects/mantis/packages/custom_fields_options_patch/print_all_bug_page_excel.php 2005-10-12 15:07:28.000000000 +0200
@@ -15,13 +15,32 @@
# The IE icon allows to see or directly print the same result
?>
<?php
- require_once( 'core.php' );
+
+ /**
+ * Array which will store the custom field names
+ *
+ * @author Thorsten Körner
+ * @since 12.10.2005
+ */
+ $cappu_field_names = array();
+
+ require_once( 'core.php' );
$t_core_path = config_get( 'core_path' );
require_once( $t_core_path.'current_user_api.php' );
require_once( $t_core_path.'bug_api.php' );
require_once( $t_core_path.'string_api.php' );
+
+
+ /**
+ * Added to give access to the custom fields functions
+ *
+ * @author Thorsten Körner
+ * @since 12.10.2005
+ */
+ require_once( $t_core_path.'custom_field_api.php' );
+
?>
<?php require( 'print_all_bug_options_inc.php' ) ?>
<?php auth_ensure_user_authenticated() ?>
@@ -99,8 +118,28 @@
if ( $f_type_page != 'html' ) {
for ( $i=0 ; $i <$field_name_count ; $i++ ) {
if ( isset( $t_prefs[$i] ) && ( 1 == $t_prefs[$i] ) ) { ?>
- <td class=xl2316681 style='border-left:none'><?php echo lang_get( $t_field_name_arr[$i] ) ?></td>
+ <td class=xl2316681 style='border-left:none'>
+
+ <?php
+ /**
+ * language output set to lang_get_defaulted, because otherwise the names
+ * of custom fields will send a warning
+ *
+ * @author Thorsten Körner
+ * @since 12.10.2005
+ */
+ echo lang_get_defaulted( $t_field_name_arr[$i] )
+ ?></td>
<?php
+
+
+ /**
+ * Now lets store the current custom field name
+ *
+ * @author Thorsten Körner
+ * @since 12.10.2005
+ */
+ array_push($cappu_field_names ,lang_get_defaulted( $t_field_name_arr[$i]));
} //if isset
} //for
} //if
@@ -353,6 +392,7 @@
}# if index
$name_index++;
?>
+
<?php # Bugnotes BEGIN (3 rows) ?>
<td colspan="3">
<?php # print bugnotes
@@ -440,6 +480,34 @@
} # end for bugnote
?>
<?php # Bugnotes END ?>
+</td>
+
+<?php
+ /**
+ * Get custom fields
+ *
+ * Get custom fields for Excel output
+ * Only fields which are selected on printing options will
+ * be sent to output. This step is adopted from an idea by marcg.
+ * This lines should be the last which are called for output.
+ *
+ * @author thorsten Thorsten Körner <t.koerner@123tk.de>
+ * @since version 1.0.0rc2_123tk.de - 12.10.2005
+ * @return array $t_ids array with ids of custom fields
+ */
+ $t_related_custom_field_ids = custom_field_get_linked_ids( $v_project_id );
+ foreach( $t_related_custom_field_ids as $t_id ) {
+ $t_def = custom_field_get_definition( $t_id );
+ if(in_array(lang_get_defaulted( $t_def['name'] ),$cappu_field_names)) {
+ ?>
+ <td class=xl2216681 nowrap style='border-top:none;border-left:none'>
+ <?php print_custom_field_value( $t_def, $t_id, $v_id ); ?>
+ </td>
+ <?php
+ } // if
+ } // foreach
+ ?>
+
</tr>
<?php
##########################################################
##########################################################
##########################################################
--- Documents/downloads/mantis-1.0.0rc2/print_all_bug_page.php 2005-05-25 01:22:48.000000000 +0200
+++ public_html/cvs_projects/mantis/packages/custom_fields_options_patch/print_all_bug_page.php 2005-10-12 15:19:44.000000000 +0200
@@ -115,6 +115,19 @@
<tr>
<td colspan="<?php echo $t_num_of_columns ?>">
+
+ <?php
+ /**
+ * Add a table with two columns and some missing links
+ * to access pages like the printing options page
+ *
+ * @author Thorsten Körner
+ * @since 12.10.2005
+ */
+ ?>
+ <table width="100%" border="0" cellpadding="0" cellspacing="0">
+ <tr>
+ <td width="50%">
<?php
if ( 'DESC' == $f_dir ) {
$t_new_dir = 'ASC';
@@ -141,7 +154,13 @@
'" ' . $t_icon[2] . '>' .
'<img src="' . $t_icon_path . $t_icon[3] . '" border="0" align="absmiddle" alt="' . $t_icon[4] . '"></a> ';
}
+ echo '</td><td width="50%" align="right">';
+ echo ' <a href="my_view_page.php">['.lang_get( 'my_view_link' ).']</a>';
+ echo ' <a href="print_all_bug_options_page.php">['.lang_get( 'printing_options_link' ).']</a>';
+ echo ' <a href="view_all_bug_page.php">['.lang_get( 'view_bugs_link' ).']</a>';
+ echo ' <a href="summary_page.php">['.lang_get( 'summary_link' ).']</a>';
?>
+ </td></tr></table>
</td>
</tr>
<?php #<SQLI> ?>
##########################################################
##########################################################
##########################################################
--- Documents/downloads/mantis-1.0.0rc2/print_all_bug_options_inc.php 2004-08-10 12:46:12.000000000 +0200
+++ public_html/cvs_projects/mantis/packages/custom_fields_options_patch/print_all_bug_options_inc.php 2005-10-12 15:10:12.000000000 +0200
@@ -19,7 +19,7 @@
function get_field_names()
{
#currently 27 fields
- return $t_arr = array (
+ $t_arr = array (
'id',
'category',
'severity',
@@ -47,6 +47,18 @@
'bugnote_title',
'bugnote_date',
'bugnote_description' );
+ /**
+ * Now lets store the current custom field name in the $t_arr array
+ *
+ * @author Thorsten Körner
+ * @since 12.10.2005
+ */
+ $t_related_custom_field_ids = custom_field_get_linked_ids_prefs( $v_project_id );
+ foreach( $t_related_custom_field_ids as $t_id ) {
+ $t_def = custom_field_get_definition( $t_id );
+ array_push($t_arr, $t_def['name']);
+ }
+ return $t_arr;
}
@@ -107,7 +119,6 @@
# putting the query result into an array with the same size as $t_fields_arr
$row = db_fetch_array( $result );
$t_prefs = $row['print_pref'];
-
?>
<?php # Account Preferences Form BEGIN ?>
@@ -115,8 +126,6 @@
<br />
<div align="center">
<form method="post" action="print_all_bug_options_update.php">
-<input type="hidden" name="user_id" value="<?php echo $p_user_id ?>" />
-<input type="hidden" name="redirect_url" value="<?php echo string_attribute( $p_redirect_url ) ?>" />
<table class="width75" cellspacing="1">
<tr>
<td class="form-title">
@@ -134,21 +143,44 @@
?>
<td class="category">
- <?php echo lang_get( $t_field_name_arr[$i] ) ?>
+
+ <?php
+ /**
+ * language output set to lang_get_defaulted, because otherwise the names
+ * of custom fields will send a warning
+ *
+ * @author Thorsten Körner
+ * @since 12.10.2005
+ */
+ echo lang_get_defaulted( $t_field_name_arr[$i] )
+ ?>
</td>
<td>
- <input type="checkbox" name="<?php echo 'print_' . $t_field_name_arr[$i]; ?>"
+ <?php
+ /**
+ * names of all checkboxes set to lowercase without whitespaces
+ * otherwise you will run into trouble when using Uppercase letters
+ * in the names of custom fields
+ *
+ * @author Thorsten Körner
+ * @since 12.10.2005
+ */
+ ?>
+ <input type="checkbox" name="<?php echo 'print_' . strtolower(str_replace(' ', '_', $t_field_name_arr[$i])); ?>"
<?php if ( isset( $t_prefs[$i] ) && ( $t_prefs[$i]==1 ) ) echo 'checked="checked"' ?> />
</td>
</tr>
<?php
}
-?>
+ ?>
+
<tr>
<td> </td>
<td>
- <input type="submit" class="button" value="<?php echo lang_get( 'update_prefs_button' ) ?>" />
+ <input type="hidden" name="user_id" value="<?php echo $p_user_id ?>" />
+ <input type="hidden" name="redirect_url" value="<?php echo string_attribute( $p_redirect_url ) ?>" />
+ <input type="submit" class="button" value="<?php echo lang_get( 'update_prefs_button' ) ?>" />
</td>
</tr>
</table>
##########################################################
##########################################################
##########################################################
--- Documents/downloads/mantis-1.0.0rc2/core/custom_field_api.php 2005-07-19 20:28:50.000000000 +0200
+++ public_html/cvs_projects/mantis/packages/custom_fields_options_patch/core/custom_field_api.php 2005-10-12 14:53:09.000000000 +0200
@@ -594,12 +594,95 @@
return $row['id'];
}
+ # --------------------
+ # Return an array of ids of custom fields bound to the specified project
+ #
+ # The ids will be sorted based on the sequence number associated with the binding
+ function custom_field_get_linked_ids( $p_project_id = ALL_PROJECTS ) {
+ $t_custom_field_table = config_get( 'mantis_custom_field_table' );
+ $t_custom_field_project_table = config_get( 'mantis_custom_field_project_table' );
+
+ if ( ALL_PROJECTS == $p_project_id ) {
+ $t_project_user_list_table = config_get( 'mantis_project_user_list_table' );
+ $t_project_table = config_get( 'mantis_project_table' );
+ $t_user_table = config_get( 'mantis_user_table' );
+ $t_user_id = auth_get_current_user_id();
+ $t_pub = VS_PUBLIC;
+ $t_priv = VS_PRIVATE;
+
+ $t_private_access = config_get( 'private_project_threshold' );
+ if ( is_array( $t_private_access ) ) {
+ if ( 1 == count( $t_private_access ) ) {
+ $t_access_clause = "= " . array_shift( $t_private_access ) . " ";
+ } else {
+ $t_access_clause = "IN (" . implode( ',', $t_private_access ) . ")";
+ }
+ } else {
+ $t_access_clause = ">= $t_private_access ";
+ }
+
+
+ # select only the ids that the user has some access to
+ # e.g., all fields in public projects, or private projects where the user is listed
+ # or private projects where the user is implicitly listed
+ $query = "SELECT cft.id as id, cft.name as name
+ FROM $t_custom_field_table as cft, $t_user_table ut, $t_project_table pt, $t_custom_field_project_table cfpt
+ LEFT JOIN $t_project_user_list_table pult
+ on cfpt.project_id = pult.project_id and pult.user_id = $t_user_id
+ WHERE cft.id = cfpt.field_id AND cfpt.project_id = pt.id AND ut.id = $t_user_id AND
+ ( pt.view_state = $t_pub OR
+ ( pt.view_state = $t_priv and pult.user_id = $t_user_id ) OR
+ ( pult.user_id is null and ut.access_level $t_access_clause ) )
+ GROUP BY cft.id, cft.name
+ ORDER BY cft.name ASC";
+ } else {
+ if ( is_array( $p_project_id ) ) {
+ if ( 1 == count( $p_project_id ) ) {
+ $t_project_clause = "= " . array_shift( $p_project_id ) . " ";
+ } else {
+ $t_project_clause = "IN (" . implode( ',', $p_project_id ) . ")";
+ }
+ } else {
+ $t_project_clause = "= $p_project_id ";
+ }
+ $query = "SELECT cft.id, cft.name, cfpt.sequence
+ FROM $t_custom_field_table cft, $t_custom_field_project_table cfpt
+ WHERE cfpt.project_id $t_project_clause AND
+ cft.id = cfpt.field_id
+ ORDER BY sequence ASC, name ASC";
+ }
+ $result = db_query( $query );
+ $t_row_count = db_num_rows( $result );
+ $t_ids = array();
+
+ for ( $i=0 ; $i < $t_row_count ; $i++ ) {
+ $row = db_fetch_array( $result );
+
+ array_push( $t_ids, $row['id'] );
+ }
+
+ return $t_ids;
+ }
# --------------------
# Return an array of ids of custom fields bound to the specified project
#
- # The ids will be sorted based on the sequence number associated with the binding
- function custom_field_get_linked_ids( $p_project_id = ALL_PROJECTS ) {
+ # The ids will be sorted by id
+
+ /**
+ * Get custom fields
+ *
+ * Get custom fields for reports and printing options page
+ * This function is a copy of custom_field_get_linked_ids except that the
+ * result is ordered by id. This step is required because you will get
+ * wrong printing options when a new custom field is added and it is
+ * is not the last one in alphabetical order.
+ *
+ * @author thorsten Thorsten Körner <t.koerner@123tk.de>
+ * @since 12.10.2005
+ * @return array $t_ids array with ids of custom fields
+ */
+ function custom_field_get_linked_ids_prefs( $p_project_id = ALL_PROJECTS ) {
$t_custom_field_table = config_get( 'mantis_custom_field_table' );
$t_custom_field_project_table = config_get( 'mantis_custom_field_project_table' );
@@ -635,7 +718,7 @@
( pt.view_state = $t_priv and pult.user_id = $t_user_id ) OR
( pult.user_id is null and ut.access_level $t_access_clause ) )
GROUP BY cft.id, cft.name
- ORDER BY cft.name ASC";
+ ORDER BY cft.id ASC";
} else {
if ( is_array( $p_project_id ) ) {
if ( 1 == count( $p_project_id ) ) {
@@ -650,7 +733,7 @@
FROM $t_custom_field_table cft, $t_custom_field_project_table cfpt
WHERE cfpt.project_id $t_project_clause AND
cft.id = cfpt.field_id
- ORDER BY sequence ASC, name ASC";
+ ORDER BY cft.id ASC, sequence ASC, name ASC";
}
$result = db_query( $query );
$t_row_count = db_num_rows( $result );
##########################################################
##########################################################
##########################################################
At last, alter the database table mantis_user_print_pref_table:
ALTER TABLE `mantis_user_print_pref_table` CHANGE `print_pref` `print_pref` VARCHAR( 255 ) NOT NULL
/\/`) Thorsten Körner | e-Commerce-Consulting
/\/_/ t.koerner@123tk.de | http://www.123tk.de
/\/_/ Software-Entwicklung | Qualitäts-Sicherung
\/_/ Service-Providing | Hosting | Beratung
/ Tel.: 0175 / 564 9 564