3 * GForge Plugin Activate / Deactivate Page
8 * Copyright 2005 GForge, LLC
12 * This file is part of GForge.
14 * GForge is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * GForge is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with GForge; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 require_once('../env.inc.php');
31 require_once $gfwww.'include/pre.php';
32 require_once $gfwww.'admin/admin_utils.php';
34 // Skip non compatible plugins.
35 $plugins_disabled = array('webcalendar', 'scmccase');
37 site_admin_header(array('title'=>_('Site admin')));
41 <script type="text/javascript">
43 function change(url,plugin)
45 field = document.theform.elements[plugin];
47 window.location=(url + "&init=yes");
49 window.location=(url);
55 <form name="theform" action="<?php echo getStringFromServer('PHP_SELF'); ?>" method="get">
58 $pm = plugin_manager_get_object();
60 if (getStringFromRequest('update')) {
61 $pluginname = getStringFromRequest('update');
63 if ((getStringFromRequest('action')=='deactivate')) {
64 if (getStringFromRequest('delusers')) {
66 $res = db_query_params ('DELETE FROM user_plugin WHERE plugin_id = (SELECT plugin_id FROM plugins WHERE plugin_name = $1)',
69 exit_error("SQL ERROR",db_error());
71 $feedback .= sprintf(ngettext('%d user detached from plugin.', '%d users detached from plugin.', db_affected_rows($res)), db_affected_rows($res));
74 if (getStringFromRequest('delgroups')) {
76 $res = db_query_params ('DELETE FROM group_plugin WHERE plugin_id = (SELECT plugin_id FROM plugins WHERE plugin_name = $1)',
79 exit_error("SQL ERROR",db_error());
81 $feedback .= sprintf(ngettext('%d project detached from plugin.', '%d projects detached from plugin.', db_affected_rows($res)), db_affected_rows($res));
84 $res = $pm->deactivate($pluginname);
86 exit_error("SQL ERROR",db_error());
88 $feedback = sprintf(_('Plugin %1$s updated Successfully'), $pluginname);
90 // Load the plugin and now get information from it.
91 $plugin = $pm->GetPluginObject($pluginname);
92 $installdir = $plugin->getInstallDir();
94 // Remove the symbolic links made if plugin has a www.
95 if (is_dir(forge_get_config('plugins_path') . '/' . $pluginname . '/www')) { // if the plugin has a www dir delete the link to it
96 if (file_exists('../'.$installdir)) {
97 $result = unlink('../'.$installdir);
99 $feedback .= _('<br />Soft link wasn\'t removed in www/plugins folder, please do so manually.');
104 if (file_exists($sys_etc_path. '/plugins/'.$pluginname)) {
105 $result = unlink($sys_etc_path. '/plugins/'.$pluginname); // the apache group or user should have write perms in $sys_etc_path/plugins folder...
107 $feedback .= _('Success, config not deleted');
114 $res = $pm->activate($pluginname);
116 exit_error("SQL ERROR",db_error());
118 $feedback = sprintf(_('Plugin %1$s updated Successfully'), $pluginname);
120 // Load the plugin and now get information from it.
121 $pm = plugin_manager_get_object();
122 $pm->LoadPlugin($pluginname);
123 $plugin = $pm->GetPluginObject($pluginname);
124 $installdir = $plugin->getInstallDir();
126 // Create a symbolic links to plugins/<plugin>/www (if directory exists).
127 if (is_dir(forge_get_config('plugins_path') . '/' . $pluginname . '/www')) { // if the plugin has a www dir make a link to it
128 // The apache group or user should have write perms the www/plugins folder...
129 if (!is_link('../'.$installdir)) {
130 $code = symlink(forge_get_config('plugins_path') . '/' . $pluginname . '/www', '../'.$installdir);
132 $feedback .= '<br />['.'../'.$installdir.'->'.forge_get_config('plugins_path') . '/' . $pluginname . '/www]';
133 $feedback .= _('<br />Soft link to www couldn\'t be created. Check the write permissions for apache in gforge www/plugins dir or create the link manually.');
138 // Create a symbolic links to plugins/<plugin>/etc/plugins/<plugin> (if directory exists).
139 if (is_dir(forge_get_config('plugins_path') . '/' . $pluginname . '/etc/plugins/' . $pluginname)) {
140 // The apache group or user should have write perms in /etc/gforge/plugins folder...
141 $code = symlink(forge_get_config('plugins_path') . '/' . $pluginname . '/etc/plugins/' . $pluginname, $sys_etc_path. '/plugins/'.$pluginname);
143 $feedback .= '<br />['.$sys_etc_path. '/plugins/'.$pluginname.'->'.forge_get_config('plugins_path') . '/' . $pluginname . '/etc/plugins/' . $pluginname . ']';
144 $feedback .= sprintf(_('<br />Config file could not be linked to etc/gforge/plugins/%1$s. Check the write permissions for apache in /etc/gforge/plugins or create the link manually.'), $pluginname);
148 if (getStringFromRequest('init')) {
149 // now we're going to check if there's a XX-init.sql file and run it
150 $db_init = forge_get_config('plugins_path') . '/' . $pluginname . '/db/' . $pluginname . '-init-pgsql.sql';
151 if (!is_file($db_init)) {
152 $db_init = forge_get_config('plugins_path') . '/' . $pluginname . '/db/' . $pluginname . '-init.sql';
153 if (!is_file($db_init)) {
159 $res = db_query_from_file($db_init);
163 db_free_result($res);
164 $res = db_next_result();
167 $feedback .= _('Initialisation error<br />Database said: ').db_error();
170 //we check for a php script
171 if (is_file(forge_get_config('plugins_path') . '/' . $pluginname . '/script/' . $pluginname . '-init.php')) {
172 include(forge_get_config('plugins_path') . '/' . $pluginname . '/script/' . $pluginname . '-init.php');
181 if ($feedback) echo '<div class="feedback">' . $feedback . '</div>';
182 echo _('Here you can activate / deactivate site-wide plugins which are in the plugins/ folder. Then, you should activate them also per project, per user or whatever the plugin specifically applies to.<br /><span class="important">Be careful because some groups/users can be using the plugin. Deactivating it will remove the plugin from all users/groups.<br />Be <strong>extra</strong> careful not to run the init-script again when the plugin is reactivated, because some scripts have DROP TABLE statements.</span><br /><br />');
183 $title_arr = array( _('Plugin Name'),
186 _('Run Init Script?'),
188 _('Groups Using it'),);
189 echo $HTML->listTableTop($title_arr);
191 // Get the activated plugins.
192 $pm = plugin_manager_get_object();
194 // Simple hack to disable dependent plugins.
195 if (!$pm->PluginIsInstalled('scmsvn')) {
196 $plugins_disabled[] = 'svncommitemail';
197 $plugins_disabled[] = 'svntracker';
199 if (!$pm->PluginIsInstalled('scmcvs')) {
200 $plugins_disabled[] = 'cvssyncmail';
201 $plugins_disabled[] = 'cvstracker';
204 //get the directories from the plugins dir
206 $handle = opendir(forge_get_config('plugins_path'));
208 while (($filename = readdir($handle)) !== false) {
209 if ($filename!='..' && $filename!='.' && $filename!=".svn" && $filename!="CVS" &&
210 is_dir(forge_get_config('plugins_path').'/'.$filename) &&
211 !in_array($filename, $plugins_disabled)) {
213 $filelist[] = $filename;
222 foreach ($filelist as $filename) {
223 if ($pm->PluginIsInstalled($filename)) {
226 $link = "<a href=\"javascript:change('" . getStringFromServer('PHP_SELF') . "?update=$filename&action=deactivate";
228 $res = db_query_params ('SELECT u.user_name FROM plugins p, user_plugin up, users u WHERE p.plugin_name = $1 and up.user_id = u.user_id and p.plugin_id = up.plugin_id',
231 if (db_numrows($res)>0) {
232 // tell the form to delete the users, so that we don't re-do the query
233 $link .= "&delusers=1";
235 for($i=0;$i<db_numrows($res);$i++) {
236 $users .= db_result($res,$i,0) . " | ";
238 $users = substr($users,0,strlen($users) - 3); //remove the last |
244 $res = db_query_params ('SELECT g.group_name FROM plugins p, group_plugin gp, groups g WHERE plugin_name = $1 and gp.group_id = g.group_id and p.plugin_id = gp.plugin_id',
247 if (db_numrows($res)>0) {
248 // tell the form to delete the groups, so that we don't re-do the query
249 $link .= "&delgroups=1";
251 for($i=0;$i<db_numrows($res);$i++) {
252 $groups .= db_result($res,$i,0) . " | ";
254 $groups = substr($groups,0,strlen($groups) - 3); //remove the last |
259 $link .= "','$filename');" . '">' . _('Deactivate') . "</a>";
260 $init = '<input id="'.$filename.'" type="checkbox" disabled name="script[]" value="'.$filename.'" />';
262 $msg = _('Inactive');
263 $status = "inactive";
264 $link = "<a href=\"javascript:change('" . getStringFromServer('PHP_SELF') . "?update=$filename&action=activate','$filename');" . '">' . _('Activate') . "</a>";
265 $init = '<input id="'.$filename.'" type="checkbox" name="script[]" value="'.$filename.'" />';
270 echo '<tr '. $HTML->boxGetAltRowStyle($j+1) .'>'.
271 '<td>'. $filename.'</td>'.
272 '<td class="'.$status.'" style="text-align:center">'. $msg .'</td>'.
273 '<td><div align="center">'. $link .'</div></td>'.
274 '<td><div align="center">'. $init .'</div></td>'.
275 '<td><div align="left">'. $users .'</div></td>'.
276 '<td><div align="left">'. $groups .'</div></td></tr>'."\n";
281 echo $HTML->listTableBottom();
290 site_admin_footer(array());
294 // c-file-style: "bsd"