]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - wikiadmin.php
Fix directory in Fusionforge
[SourceForge/phpwiki.git] / wikiadmin.php
1 <?php // -*-php-*- $Id$
2 /*
3  * Copyright (C) 2009 Alain Peyrat, Alcatel-Lucent
4  * Copyright (C) 2009-2010 Marc-Etienne Vargenau, Alcatel-Lucent
5  *
6  * This file is part of PhpWiki.
7  *
8  * PhpWiki is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * PhpWiki is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with PhpWiki; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 */
22
23 /*
24  * Standard Alcatel-Lucent disclaimer for contributing to open source
25  *
26  * "The Wiki Configurator ("Contribution") has not been tested and/or
27  * validated for release as or in products, combinations with products or
28  * other commercial use. Any use of the Contribution is entirely made at
29  * the user's own responsibility and the user can not rely on any features,
30  * functionalities or performances Alcatel-Lucent has attributed to the
31  * Contribution.
32  *
33  * THE CONTRIBUTION BY ALCATEL-LUCENT IS PROVIDED AS IS, WITHOUT WARRANTY
34  * OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
35  * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, COMPLIANCE,
36  * NON-INTERFERENCE AND/OR INTERWORKING WITH THE SOFTWARE TO WHICH THE
37  * CONTRIBUTION HAS BEEN MADE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
38  * ALCATEL-LUCENT BE LIABLE FOR ANY DAMAGES OR OTHER LIABLITY, WHETHER IN
39  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
40  * CONTRIBUTION OR THE USE OR OTHER DEALINGS IN THE CONTRIBUTION, WHETHER
41  * TOGETHER WITH THE SOFTWARE TO WHICH THE CONTRIBUTION RELATES OR ON A STAND
42  * ALONE BASIS."
43  */
44
45 require_once dirname(__FILE__)."/../../env.inc.php";
46 require_once $gfcommon.'include/pre.php';
47 require_once forge_get_config('plugins_path').'wiki/common/WikiPlugin.class.php';
48 require_once forge_get_config('plugins_path').'wiki/common/wikiconfig.class.php';
49
50 // the header that displays for the user portion of the plugin
51 function wiki_Project_Header($params) {
52     global $id;
53     $params['toptab']='wiki';
54     $params['group']=$id;
55     /*
56         Show horizontal links
57     */
58     site_project_header($params);
59 }
60
61 $user = session_get_user(); // get the session user
62
63 if (!$user || !is_object($user)) {
64     exit_error(_('Invalid User'),'home');
65 } else if ( $user->isError()) {
66         exit_error($user->getErrorMessage(),'home');
67 } else if ( !$user->isActive()) {
68         exit_error(_('User not active'),'home');
69 }
70
71 $type = getStringFromRequest('type');
72 $id = getIntFromRequest('id');
73 $pluginname = 'wiki';
74 $config = getArrayFromRequest('config');
75
76 if (!$type) {
77     exit_missing_params($_SERVER['HTTP_REFERER'],array(_('No TYPE specified')),'home');
78 } elseif (!$id) {
79     exit_missing_params($_SERVER['HTTP_REFERER'],array(_('No ID specified')),'home');
80 } else {
81     if ($type == 'admin_post') {
82         $group = group_get_object($id);
83         if ( !$group) {
84                         exit_no_group();
85         }
86         if (!($group->usesPlugin($pluginname))) { //check if the group has the wiki plugin active
87                         exit_error(sprintf(_('First activate the %s plugin through the Project\'s Admin Interface'),$pluginname),'home');
88         }
89         $userperm = $group->getPermission($user); //we'll check if the user belongs to the group
90         if ( !$userperm->IsMember()) {
91                         exit_permission_denied(_('You are not a member of this project'),'home');
92         }
93         //only project admin can access here
94         if ( $userperm->isAdmin() ) {
95
96             $wc = new WikiConfig($id);
97
98             foreach ($wc->getWikiConfigNames() as $c) {
99                 if ( ! array_key_exists($c, $config)) {
100                     $config[$c] = 0;
101                 }
102             }
103  
104             foreach ($config as $config_name => $config_value) {
105                 $r = $wc->updateWikiConfig($config_name, $config_value);
106                 if (!$r) exit_error("Error", $wc->getErrorMessage());
107             }
108
109             $type = 'admin';
110             $feedback = _('Configuration saved.');
111         } else {
112             exit_permission_denied(_('You are not a project Admin'),'home');
113         }
114     }
115     if ($type == 'admin') {
116         $group = group_get_object($id);
117         if ( !$group) {
118                         exit_no_group();
119         }
120         if ( ! ($group->usesPlugin ($pluginname)) ) {//check if the group has the plugin active
121                         exit_error(sprintf(_('First activate the %s plugin through the Project\'s Admin Interface'),$pluginname),'home');
122         }
123         $userperm = $group->getPermission($user); //we'll check if the user belongs to the group
124         if ( !$userperm->IsMember()) {
125             exit_permission_denied(_('You are not a member of this project'),'home');
126         }
127         //only project admin can access here
128         if ( $userperm->isAdmin() ) {
129             wiki_Project_Header(array('title'=>"Configuration for your project's Wiki",'pagename'=>"$pluginname",'sectionvals'=>array(group_getname($id))));
130
131             $wc = new WikiConfig($id);
132
133             print "\n<h1>"._("Configuration for your project's Wiki")."</h1>\n";
134
135             print "<table>\n";
136             print "<tr>\n";
137             print "<td>\n";
138             print "<fieldset>\n";
139             print "<legend>"._('Wiki Configuration')."</legend>\n";
140             print "<form action=\"/wiki/wikiadmin.php\" method=\"post\">\n";
141             print "<input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
142             print "<input type=\"hidden\" name=\"pluginname\" value=\"$pluginname\" />\n";
143             print "<input type=\"hidden\" name=\"type\" value=\"admin_post\" />\n";
144
145             print '<table class="listing">';
146             print "\n<thead>\n<tr>\n<th>".
147                     _("Parameter").
148                     "</th>" .
149                     "<th>".
150                     _("Value").
151                     "</th>\n" .
152                     "</tr>\n</thead>\n";
153
154             foreach ($wc->getWikiConfigNames() as $c) {
155                 $checked = $wc->getWikiConfig($c) ? ' checked="checked"' : '';
156                 $desc = $wc->getWikiConfigDescription($c);
157
158                 print "<tr>\n<td>$desc</td>\n" .
159                       "<td align=\"center\">" .
160                       "<input type=\"checkbox\" name=\"config[$c]\" value=\"1\"$checked /></td>\n" .
161                       "</tr>\n";
162             }
163             print "</table>\n";
164             print "<p align=\"right\"><input type=\"submit\" value=\"" .
165                             _("Save Configuration").
166                             "\" /></p>";
167             print "</form>\n";
168             print "</fieldset>\n";
169             print "</td>\n";
170             print "</tr>\n";
171             print "</table>\n";
172         } else {
173             exit_permission_denied(_('You are not a project Admin'),'home');
174         }
175     }
176 }
177
178 site_project_footer(array());
179
180 ?>