7 * This file is part of FusionForge.
9 * GForge is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * GForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with GForge; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 forge_define_config_item ('server', 'mantis', 'mantis') ;
25 forge_define_config_item ('db_name', 'mantis', 'mantis') ;
26 forge_define_config_item ('db_host', 'mantis', 'localhost') ;
27 forge_define_config_item ('db_passwd', 'mantis', 'secret') ;
28 forge_define_config_item ('db_user', 'mantis', 'GForge') ;
30 class MantisPlugin extends Plugin {
31 function MantisPlugin () {
33 $this->name = "mantis" ;
34 $this->text = "Mantis" ; // To show in the tabs, use...
35 $this->hooks[] = "user_personal_links";//to make a link to the user's personal part of the plugin
36 $this->hooks[] = "usermenu" ;
37 $this->hooks[] = "groupmenu" ; // To put into the project tabs
38 $this->hooks[] = "groupisactivecheckbox" ; // The "use ..." checkbox in editgroupinfo
39 $this->hooks[] = "groupisactivecheckboxpost" ; //
40 $this->hooks[] = "userisactivecheckbox" ; // The "use ..." checkbox in user account
41 $this->hooks[] = "userisactivecheckboxpost" ; //
42 $this->hooks[] = "project_admin_plugins"; // to show up in the admin page fro group
45 function CallHook ($hookname, $params) {
46 global $use_mantisplugin,$G_SESSION,$HTML;
47 if ($hookname == "usermenu") {
48 $text = $this->text; // this is what shows in the tab
49 if ($G_SESSION->usesPlugin("mantis")) {
50 $param = '?type=user&id=' . $G_SESSION->getId() . "&pluginname=" . $this->name; // we indicate the part we're calling is the user one
51 echo ' | ' . $HTML->PrintSubMenu (array ($text),
52 array ('/plugins/mantis/index.php' . $param ));
54 } elseif ($hookname == "groupmenu") {
55 $group_id=$params['group'];
56 $project = &group_get_object($group_id);
57 if (!$project || !is_object($project)) {
60 if ($project->isError()) {
63 if (!$project->isProject()) {
66 if ( $project->usesPlugin ( $this->name ) ) {
67 $params['TITLES'][]=$this->text;
68 $params['DIRS'][]=util_make_url ('/plugins/mantis/index.php?type=group&id=' . $group_id . "&pluginname=" . $this->name) ; // we indicate the part we're calling is the project one
70 $params['TITLES'][]=$this->text." is [Off]";
73 (($params['toptab'] == $this->name) ? $params['selected']=(count($params['TITLES'])-1) : '' );
74 } elseif ($hookname == "groupisactivecheckbox") {
75 //Check if the group is active
76 // this code creates the checkbox in the project edit public info page to activate/deactivate the plugin
77 $group_id=$params['group'];
78 $group = &group_get_object($group_id);
81 echo ' <input type="checkbox" name="use_mantisplugin" value="1" ';
82 // checked or unchecked?
83 if ( $group->usesPlugin ( $this->name ) ) {
89 echo "<strong>Use ".$this->text." Plugin</strong>";
92 } elseif ($hookname == "groupisactivecheckboxpost") {
93 // this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page
94 $group_id=$params['group'];
95 $group = &group_get_object($group_id);
96 $use_mantisplugin = getStringFromRequest('use_mantisplugin');
97 if ( $use_mantisplugin == 1 ) {
98 $group->setPluginUse ( $this->name );
100 $group->setPluginUse ( $this->name, false );
102 } elseif ($hookname == "user_personal_links") {
103 // this displays the link in the user's profile page to it's personal Mantis (if you want other sto access it, youll have to change the permissions in the index.php
104 $userid = $params['user_id'];
105 $user = user_get_object($userid);
106 $text = $params['text'];
107 //check if the user has the plugin activated
108 if ($user->usesPlugin($this->name)) {
110 <a href="'.forge_get_config('url_prefix').'/plugins/mantis/index.php?id=' . $userid . '&type=user&pluginname=' . $this->name . '">' . _('View Mantis') .'</a></p>';
112 } elseif ($hookname == "project_admin_plugins") {
113 // this displays the link in the project admin options page to it's Mantis administration
114 $group_id = $params['group_id'];
115 $group = &group_get_object($group_id);
116 if ( $group->usesPlugin ( $this->name ) ) {
117 echo '<a href="'.forge_get_config('url_prefix').'/plugins/mantis/index.php?id=' . $group->getID() . '&type=admin&pluginname=' . $this->name . '">' . _('Mantis admin') . '</a><br />';
120 elseif ($hookname == "blahblahblah") {
128 // c-file-style: "bsd"