5 * Copyright 2005, Raphaƫl Hertzog
6 * Copyright 2006-2009, Roland Mas
7 * Copyright 2009-2010, Alain Peyrat
8 * Copyright 2010, Franck Villaume - Capgemini
9 * Copyright (C) 2010 Alain Peyrat - Alcatel-Lucent
10 * http://fusionforge.org/
12 * This file is part of FusionForge.
14 * FusionForge 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 * FusionForge 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 along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 require_once ('../../../www/env.inc.php');
30 require_once $gfcommon.'include/pre.php';
31 require_once $gfwww.'project/admin/project_admin_utils.php';
33 $group_id = getIntFromRequest ('group_id') ;
34 $index = getIntFromRequest ('index') ;
36 $tab_name = htmlspecialchars(trim(getStringFromRequest('tab_name')));
37 $tab_rename = htmlspecialchars(trim(getStringFromRequest('tab_rename')));
38 $tab_url = htmlspecialchars(trim(getStringFromRequest('tab_url', 'http://')));
39 $tab_new_url = htmlspecialchars(trim(getStringFromRequest('tab_new_url')));
40 $type = getIntFromRequest('type', 0);
41 $new_type = getIntFromRequest('new_type', -1);
43 session_require_perm('project_admin', $group_id) ;
45 // get current information
46 $group = group_get_object($group_id);
47 if (!$group || !is_object($group)) {
49 } elseif ($group->isError()) {
50 exit_error($group->getErrorMessage(), 'home');
55 // Calculate new index field
56 $res = db_query_params('SELECT COUNT(*) as c FROM plugin_extratabs_main WHERE group_id = $1',
58 $row = db_fetch_array($res);
59 $newid = $row['c'] + 1;
61 $selected = 0; // No item selected by default
63 // Do work before displaying so that the result is immediately visible
64 if (getStringFromRequest('addtab') != '') {
65 if ($tab_name == '' || $tab_url == '' || $tab_url == 'http://') {
66 $error_msg = _('ERROR: Missing Name or URL for the new tab');
67 } else if (!util_check_url($tab_url)) {
68 $error_msg = _('ERROR: Malformed URL (only http, https and ftp allowed)');
70 $res = db_query_params('SELECT * FROM plugin_extratabs_main WHERE group_id=$1 AND tab_name=$2',
71 array($group_id, $tab_name));
72 if ($res && db_numrows($res) > 0) {
73 $error_msg = _('ERROR: Name for tab is already used.');
75 $res = db_query_params('INSERT INTO plugin_extratabs_main (group_id, index, tab_name, tab_url, type) VALUES ($1,$2,$3,$4,$5)',
81 if (!$res || db_affected_rows($res) < 1) {
82 $error_msg = sprintf(_('Cannot insert new tab entry: %s'),
87 $feedback = _('Tab successfully added');
91 } elseif (getStringFromRequest('delete') != '') {
92 $res = db_query_params('DELETE FROM plugin_extratabs_main WHERE group_id=$1 AND index=$2',
93 array($group_id, $index));
94 if (!$res || db_affected_rows($res) < 1) {
95 $error_msg = sprintf(_('Cannot delete tab entry: %s'), db_error());
97 $res = db_query_params('SELECT index FROM plugin_extratabs_main WHERE group_id=$1 AND index > $2 ORDER BY index ASC',
98 array($group_id, $index));
99 if (db_numrows($res) > 0) {
101 while ($row = db_fetch_array($res)) {
102 $todo[] = $row['index'];
104 foreach ($todo as $i) {
105 $res = db_query_params('UPDATE plugin_extratabs_main SET index = index - 1 WHERE group_id = $1 AND index = $2',
106 array($group_id, $i));
110 $feedback = _('Tab successfully deleted');
112 $error_msg = sprintf(_('Cannot delete tab entry: %s'), db_error());
115 } elseif (getStringFromRequest ('up') != '') {
117 $previous = $index - 1;
118 $res = db_query_params('UPDATE plugin_extratabs_main SET index=0 WHERE group_id=$1 AND index=$2',
119 array ($group_id, $index));
120 $res = db_query_params('UPDATE plugin_extratabs_main SET index=$1 WHERE group_id=$2 AND index=$3',
124 $res = db_query_params('UPDATE plugin_extratabs_main SET index=$1 WHERE group_id=$2 AND index=0',
127 $selected = $previous;
128 $feedback = _('Tab successfully moved');
130 $warning_msg = _('Tab not moved, already at first position');
133 } elseif (getStringFromRequest ('down') != '') {
134 if ($index < $newid - 1) {
136 $res = db_query_params('UPDATE plugin_extratabs_main SET index=0 WHERE group_id=$1 AND index=$2',
139 $res = db_query_params('UPDATE plugin_extratabs_main SET index=$1 WHERE group_id=$2 AND index=$3',
143 $res = db_query_params('UPDATE plugin_extratabs_main SET index=$1 WHERE group_id=$2 AND index=0',
146 $feedback = _('Tab successfully moved');
149 $warning_msg = _('Tab not moved, already at last position');
152 } elseif (getStringFromRequest ('modify') != '') {
155 $res = db_query_params ('UPDATE plugin_extratabs_main SET tab_name=$1 WHERE group_id=$2 AND index=$3',
159 if (!$res || db_affected_rows($res) < 1) {
160 $error_msg = sprintf (_('Cannot rename the tab: %s'), db_error());
162 $feedback .= ($feedback ? '. ' : '') . _('Tab successfully renamed');
166 if ($tab_new_url && $tab_new_url != 'http://') {
167 if (!util_check_url($tab_new_url)) {
168 $error_msg = _('ERROR: Malformed URL (only http, https and ftp allowed)');
170 $res = db_query_params ('UPDATE plugin_extratabs_main SET tab_url=$1 WHERE group_id=$2 AND index=$3',
174 if (!$res || db_affected_rows($res) < 1) {
175 $error_msg .= ($error_msg ? '. ' : '') . sprintf (_('Cannot change URL: %s'), db_error());
177 $feedback .= ($feedback ? '. ' : '') . _('URL successfully changed');
182 if ($new_type != -1) {
183 $res = db_query_params ('UPDATE plugin_extratabs_main SET type=$1 WHERE group_id=$2 AND index=$3',
187 if (!$res || db_affected_rows($res) < 1) {
188 $error_msg .= ($error_msg ? '. ' : '') . sprintf (_('Cannot set type: %s'), db_error());
190 $feedback .= ($feedback ? '. ' : '') . _('Type successfully changed');
194 if (!$error_msg && !$done) {
195 $warning_msg .= ($warning_msg ? '. ' : '') . _('Nothing done');
204 $adminheadertitle = sprintf(_('Manage extra tabs for project %1$s'), $group->getPublicName());
205 project_admin_header(array('title'=>$adminheadertitle, 'group'=>$group->getID()));
208 <h2><?php echo _('Add new tab'); ?></h2>
210 <p><?php echo _('You can add your own tabs in the menu bar with the form below.') ?></p>
212 <form name="new_tab" action="<?php echo util_make_uri ('/plugins/extratabs/'); ?>" method="post">
214 <legend><?php echo _('Add new tab'); ?></legend>
216 <input type="hidden" name="group_id" value="<?php echo $group->getID() ?>" />
217 <input type="hidden" name="addtab" value="1" />
218 <strong><?php echo _('Name of the tab:') ?></strong><?php echo utils_requiredField(); ?>
220 <input type="text" required="required" size="20" maxlength="20" name="tab_name" value="<?php echo $tab_name ?>" /><br />
223 <strong><?php echo _('URL of the tab:') ?></strong><?php echo utils_requiredField(); ?>
225 <input type="text" required="required" size="60" name="tab_url" value="<?php echo $tab_url ?>" /><br/>
228 <input type="radio" name="type" value="0" checked="checked"/><?php echo _('Link') ?>
229 <input type="radio" name="type" value="1" /><?php echo _('Iframe') ?>
232 <input type="submit" value="<?php echo _('Add tab') ?>" />
238 $res = db_query_params('SELECT * FROM plugin_extratabs_main WHERE group_id=$1 ORDER BY index ASC', array($group_id));
239 $nbtabs = db_numrows($res);
244 <h2><?php echo _('Modify extra tabs'); ?></h2>
246 <?php echo _('You can modify the tabs that you already added.');
250 <form name="modify_tab" action="<?php echo util_make_uri('/plugins/extratabs/'); ?>" method="post">
252 <legend><?php echo _('Modify tab'); ?></legend>
254 <input type="hidden" name="group_id" value="<?php echo $group->getID() ?>" />
255 <?php echo _('Tab to modify:') ?> <select name="index">
258 while ($row = db_fetch_array($res)) {
259 if ($row['index'] == $selected) {
260 $options .= "<option selected=\"selected\" value='" . $row['index'] . "'>" . $row['tab_name'] . "</option>";
262 $options .= "<option value='" . $row['index'] . "'>" . $row['tab_name'] . "</option>";
270 <?php echo _('Rename to:'); ?> <input type="text" size="20" maxlength="20" name="tab_rename" value="" />
273 <?php echo _('New URL:'); ?> <input type="text" size="60" name="tab_new_url" value="http://" />
276 <input type="radio" name="new_type" value="0" /><?php echo _('Link') ?>
277 <input type="radio" name="new_type" value="1" /><?php echo _('Iframe') ?>
280 <input type="submit" name="modify" value="<?php echo _('Modify tab') ?>" />
285 <h2><?php echo _('Move or delete extra tabs') ;?></h2>
287 <?php echo _('You can move and delete the tabs that you already added. Please note that those extra tabs can only appear after the standard tabs. And you can only move them inside the set of extra tabs.');
291 <form name="change_tab" action="<?php echo util_make_uri('/plugins/extratabs/'); ?>" method="post">
293 <legend><?php echo _('Move or delete tab'); ?></legend>
295 <input type="hidden" name="group_id" value="<?php echo $group->getID() ?>" />
297 echo _('Tab to modify:')
299 <select name="index">
306 <?php if ($nbtabs > 1) { ?>
307 <input type="submit" name="up" value="<?php echo _('Move tab before') ?>" />
308 <input type="submit" name="down" value="<?php echo _('Move tab after') ?>" />
310 <input type="submit" name="delete" value="<?php echo _('Delete tab') ?>" />
317 project_admin_footer(array());
321 // c-file-style: "bsd"