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