4 * ProjectImportPlugin Class
6 * This file is part of FusionForge. FusionForge is free software;
7 * you can redistribute it and/or modify it under the terms of the
8 * GNU General Public License as published by the Free Software
9 * Foundation; either version 2 of the Licence, or (at your option)
12 * FusionForge is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 forge_define_config_item('storage_base','projectimport-plugin','$core/data_path/plugins/projectimport/');
23 forge_define_config_item('libmagic_db','projectimport-plugin','/usr/share/misc/magic.mgc');
25 class ProjectImportPlugin extends Plugin {
26 function ProjectImportPlugin () {
28 $this->name = "projectimport" ;
29 $this->text = "Project import" ; // To show in the tabs, use...
30 $this->hooks[] = "groupmenu" ; // To put into the project tabs
32 $this->hooks[] = "user_personal_links";//to make a link to the user's personal part of the plugin
33 $this->hooks[] = "usermenu" ;
34 $this->hooks[] = "groupisactivecheckbox" ; // The "use ..." checkbox in editgroupinfo
35 $this->hooks[] = "groupisactivecheckboxpost" ; //
36 $this->hooks[] = "userisactivecheckbox" ; // The "use ..." checkbox in user account
37 $this->hooks[] = "userisactivecheckboxpost" ; //
38 $this->hooks[] = "project_admin_plugins"; // to show up in the admin page fro group
40 // The plugin has a link added to the Project administration part of site admin
41 $this->hooks[] = "site_admin_project_maintenance_hook";
42 $this->hooks[] = "site_admin_user_maintenance_hook";
45 function CallHook ($hookname, &$params) {
46 global $use_projectimportplugin,$G_SESSION,$HTML;
47 /*if ($hookname == "usermenu") {
48 $text = $this->text; // this is what shows in the tab
49 if ($G_SESSION->usesPlugin("projectimport")) {
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/projectimport/index.php' . $param ));
54 } else */ if ($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/projectimport/index.php?type=group&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_projectimportplugin" 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_projectimportplugin = getStringFromRequest('use_projectimportplugin');
97 if ( $use_projectimportplugin == 1 ) {
98 $group->setPluginUse ( $this->name );
100 $group->setPluginUse ( $this->name, false );
102 } elseif ($hookname == "userisactivecheckbox") {
103 //check if user is active
104 // this code creates the checkbox in the user account manteinance page to activate/deactivate the plugin
105 $user = $params['user'];
108 echo ' <input type="checkbox" name="use_projectimportplugin" value="1" ';
109 // checked or unchecked?
110 if ( $user->usesPlugin ( $this->name ) ) {
113 echo " /> Use ".$this->text." Plugin";
116 } elseif ($hookname == "userisactivecheckboxpost") {
117 // this code actually activates/deactivates the plugin after the form was submitted in the user account manteinance page
118 $user = $params['user'];
119 $use_projectimportplugin = getStringFromRequest('use_projectimportplugin');
120 if ( $use_projectimportplugin == 1 ) {
121 $user->setPluginUse ( $this->name );
123 $user->setPluginUse ( $this->name, false );
127 echo ' <input type="checkbox" name="use_projectimportplugin" value="1" ';
128 // checked or unchecked?
129 if ( $user->usesPlugin ( $this->name ) ) {
132 echo " /> Use ".$this->text." Plugin";
135 } elseif ($hookname == "user_personal_links") {
136 // this displays the link in the user's profile page to it's personal ProjectImport (if you want other sto access it, youll have to change the permissions in the index.php
137 $userid = $params['user_id'];
138 $user = user_get_object($userid);
139 $text = $params['text'];
140 //check if the user has the plugin activated
141 if ($user->usesPlugin($this->name)) {
143 echo util_make_link ("/plugins/projectimport/index.php?id=$userid&type=user&pluginname=".$this->name,
144 _('View Personal ProjectImport')
148 } elseif ($hookname == "project_admin_plugins") {
149 // this displays the link in the project admin options page to it's ProjectImport administration
150 $group_id = $params['group_id'];
151 $group = &group_get_object($group_id);
152 if ( $group->usesPlugin ( $this->name ) ) {
153 echo util_make_link ("/plugins/projectimport/index.php?id=".$group->getID().'&type=admin&pluginname='.$this->name,
154 _('View the ProjectImport Administration')).'<br />';
157 elseif ($hookname == "blahblahblah") {
164 * Displays the link in the Project Maintenance part of the Site Admin ('site_admin_project_maintenance_hook' plugin_hook_by_reference() -style hook)
165 * @param array $params for concatenating return value in ['results']
167 function site_admin_project_maintenance_hook (&$params) {
168 $html = $params['result'];
170 util_make_link ('/plugins/'.$this->name.'/projectsimport.php',
171 _("Import projects"). ' [' . _('Project import plugin') . ']') .'</li>';
172 $params['result'] = $html;
176 * Displays the link in the User Maintenance part of the Site Admin ('site_admin_user_maintenance_hook' plugin_hook_by_reference() -style hook)
177 * @param array $params for concatenating return value in ['results']
179 function site_admin_user_maintenance_hook (&$params) {
180 $html = $params['result'];
182 util_make_link ('/plugins/'.$this->name.'/usersimport.php',
183 _("Import users"). ' [' . _('Project import plugin') . ']') .'</li>';
184 $params['result'] = $html;
192 // c-file-style: "bsd"