Add a button on the menu to edit project manage page

General discussion of Mantis.

Moderators: Developer, Contributor

Post Reply
caramelo
Posts: 7
Joined: 28 Jan 2025, 12:39

Add a button on the menu to edit project manage page

Post by caramelo »

I would like to add an extra menu button on the left to open the project manager edit page, for the currently selected project.

I tried to create a new button on config/config_inc.php like this:

Code: Select all

$g_main_menu_custom_options = array(
    array(
        'url' => 'manage_proj_edit_page.php?project_id=' . $project_id,
        'title' => 'Manage Current Project',
        'access_level' => MANAGER,
        'icon' => 'fa-cog'
    )
);
But it says "Project "0" not found." on the URL

Code: Select all

http://mantisbt/mantis/manage_proj_edit_page.php?project_id=
Appreciate any help.

Thanks.
caramelo

MantisBT Version 2.27.0
Database Schema Version 213
PHP Version 8.3.6
OS Information Linux trp-mantis2 6.8.0-51-generic #52-Ubuntu SMP PREEMPT_DYNAMIC Thu Dec 5 13:09:44 UTC 2024 x86_64
Database Driver mysqli
Database Version, Description 8.0.40, 8.0.40-0ubuntu0.24.04.1
atrol
Site Admin
Posts: 8531
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: Add a button on the menu to edit project manage page

Post by atrol »

Code: Select all

'url' => 'manage_proj_edit_page.php?project_id=' . $project_id,
You are referencing variable $project_id but you did not set it before.
Please use Search before posting and read the Manual
caramelo
Posts: 7
Joined: 28 Jan 2025, 12:39

Re: Add a button on the menu to edit project manage page

Post by caramelo »

atrol wrote: 29 Jan 2025, 10:41

Code: Select all

'url' => 'manage_proj_edit_page.php?project_id=' . $project_id,
You are referencing variable $project_id but you did not set it before.
I went and check that maybe I could use $g_project_override and some things I read pointed out to helper_get_current_project() but that maybe it is not available when the config loads. That is why the project_id and g_project_overrrite have the value of 0.

If I could find a variable that hold globally the project ID, maybe I could use it there and the link would work.

Thanks for you help.
caramelo
Posts: 7
Joined: 28 Jan 2025, 12:39

Re: Add a button on the menu to edit project manage page

Post by caramelo »

Code: Select all

$current_project_id = helper_get_current_project();
$g_main_menu_custom_options = array(
    array(
        'url' => 'manage_proj_edit_page.php?project_id=' . $current_project_id,
        'title' => 'Manage Current Project',
        'access_level' => MANAGER,
        'icon' => 'fa-cog'
    )
);
Let me just add this that does not work and the page does not even load. So it has to be a variable that is loaded in or before config_inc.php and has the project_id. Or a button on the page that will only read the project_id when clicked.
cas
Posts: 1768
Joined: 11 Mar 2006, 16:08
Contact:

Re: Add a button on the menu to edit project manage page

Post by cas »

So you only show the page if you have a project_id, something like

Code: Select all

if ( isset( $current_project_id ) ) {
	$g_main_menu_custom_options = array(
	    array(
	        'url' => 'manage_proj_edit_page.php?project_id=' . $current_project_id,
	        'title' => 'Manage Current Project',
	        'access_level' => MANAGER,
	        'icon' => 'fa-cog'
 	   )
	);
}
caramelo
Posts: 7
Joined: 28 Jan 2025, 12:39

Re: Add a button on the menu to edit project manage page

Post by caramelo »

I need somehow to change the value of the current project ID when entering the page or when it changes on the dropdown.

Tried it to set the $current_project_id when I change the project on the dropdown but still get the value of 0 and when it loads config_ins.php that value is probably lost and is set to 0 or not set.

While I don't create this button, I created a button on the right side of the dropdown that says "Edit project" and another on the main project line, as seen on attached picture.
Attachments
Screenshot 2025-01-30 154728.png
Screenshot 2025-01-30 154728.png (11.87 KiB) Viewed 9667 times
cas
Posts: 1768
Joined: 11 Mar 2006, 16:08
Contact:

Re: Add a button on the menu to edit project manage page

Post by cas »

I had to dig since I recallled struggling withthe same issue.
I did not place the code in config_inc.php bur custom_strings_inc.php
The code I used,adapted to your purpose would be:

Code: Select all

if( php_sapi_name() != 'cli' ) {
	$t_cookie_name = config_get_global( 'project_cookie' );
	if ( $_COOKIE[$t_cookie_name] ){
		$t_project_id = $_COOKIE[$t_cookie_name];
	$g_main_menu_custom_options = array(
	    array(
	        'url' => 'manage_proj_edit_page.php?project_id=' . $t_project_id,
	        'title' => 'Manage Current Project',
	        'access_level' => MANAGER,
	        'icon' => 'fa-cog'
 	   )
	);
	}
}
This worked for me, hope it does work for you too!
caramelo
Posts: 7
Joined: 28 Jan 2025, 12:39

Re: Add a button on the menu to edit project manage page

Post by caramelo »

Hi again, just to say it did not work, tried on the config_inc and in custom_strings but nothing. But thank you for the suggestion, I will look at that tip more later.

Since I don't have many time now to learn more about Mantis, the solution I created with the menu on the dropdown it is a nice solution for my problem, so I will keep only that, but I will create a button on the menu on the left, because it's easy to work with.

It takes a little bit of time that I don't have right now, but I like the Mantis code and plugins

Thank you.
Post Reply