5 * Copyright 2005, Raphaƫl Hertzog
6 * Copyright 2006-2009, Roland Mas
7 * Copyright 2009-2010, Alain Peyrat
10 require_once ('../../../www/env.inc.php');
11 require_once $gfwww.'include/pre.php';
12 require_once $gfwww.'project/admin/project_admin_utils.php';
14 $group_id = getIntFromRequest ('group_id') ;
15 $index = getIntFromRequest ('index') ;
17 $tab_name = htmlspecialchars(trim(getStringFromRequest ('tab_name')));
18 $tab_url = htmlspecialchars(trim(getStringFromRequest ('tab_url', 'http://')));
20 session_require(array('group'=>$group_id,'admin_flags'=>'A'));
22 // get current information
23 $group =& group_get_object($group_id);
24 if (!$group || !is_object($group)) {
25 exit_error('Error','Could Not Get Group');
26 } elseif ($group->isError()) {
27 exit_error('Error',$group->getErrorMessage());
32 // Calculate new index field
33 $res = db_query_params ('SELECT COUNT(*) as c FROM plugin_extratabs_main WHERE group_id = $1',
35 $row = db_fetch_array($res);
36 $newid = $row['c'] + 1;
38 $selected = 0; // No item selected by default
40 // Do work before displaying so that the result is immediately visible
41 if (getStringFromRequest ('addtab') != '') {
42 if ($tab_name == '' || $tab_url == '' || $tab_url == 'http://') {
43 $error_msg = _('ERROR: Missing Name or URL for the new tab');
44 } else if (!util_check_url($tab_url)) {
45 $error_msg = _('ERROR: Malformed URL (only http, https and ftp allowed)');
47 $res = db_query_params('SELECT * FROM plugin_extratabs_main WHERE group_id=$1 AND tab_name=$2',
48 array($group_id, $tab_name));
49 if ($res && db_numrows($res) > 0) {
50 $error_msg = _('ERROR: Name for tab is already used.');
52 $res = db_query_params ('INSERT INTO plugin_extratabs_main (group_id, index, tab_name, tab_url) VALUES ($1,$2,$3,$4)',
57 if (!$res || db_affected_rows($res) < 1) {
58 $feedback = sprintf (_('Cannot insert new tab entry: %s'),
63 $feedback = _('Tab successfully added');
67 } elseif (getStringFromRequest ('delete') != '') {
68 $res = db_query_params ('DELETE FROM plugin_extratabs_main WHERE group_id=$1 AND index=$2',
71 if (!$res || db_affected_rows($res) < 1) {
72 $error_msg = sprintf (_('Cannot delete tab entry: %s'), db_error());
74 $res = db_query_params ('UPDATE plugin_extratabs_main SET index=index-1 WHERE group_id=$1 AND index > $2',
78 $feedback = _('Tab successfully deleted');
80 $error_msg = sprintf (_('Cannot delete tab entry: %s'), db_error());
83 } elseif (getStringFromRequest ('up') != '') {
85 $previous = $index - 1;
86 $res = db_query_params('UPDATE plugin_extratabs_main SET index=0 WHERE group_id=$1 AND index=$2',
89 $res = db_query_params('UPDATE plugin_extratabs_main SET index=$1 WHERE group_id=$2 AND index=$3',
93 $res = db_query_params('UPDATE plugin_extratabs_main SET index=$1 WHERE group_id=$2 AND index=0',
96 $selected = $previous;
97 $feedback = _('Tab successfully moved');
99 $warning_msg = _('Tab not moved, already at first position');
102 } elseif (getStringFromRequest ('down') != '') {
103 if ($index < $newid - 1) {
105 $res = db_query_params('UPDATE plugin_extratabs_main SET index=0 WHERE group_id=$1 AND index=$2',
108 $res = db_query_params('UPDATE plugin_extratabs_main SET index=$1 WHERE group_id=$2 AND index=$3',
112 $res = db_query_params('UPDATE plugin_extratabs_main SET index=$1 WHERE group_id=$2 AND index=0',
115 $feedback = _('Tab successfully moved');
118 $warning_msg = _('Tab not moved, already at last position');
128 $adminheadertitle=sprintf(_('Project Admin: %1$s'), $group->getPublicName() );
129 project_admin_header(array('title'=>$adminheadertitle, 'group'=>$group->getID()));
133 <h1><?php echo _('Manage extra tabs') ;?></h1>
135 <h2><?php echo _('Add new tab'); ?></h2>
137 <p><?php echo _('You can add your own tabs in the menu bar with the form below.') ?></p>
139 <form name="new_tab" action="<?php echo util_make_url ('/plugins/extratabs/'); ?>" method="post">
141 <legend>Add new tab</legend>
143 <input type="hidden" name="group_id" value="<?php echo $group->getID() ?>" />
144 <input type="hidden" name="addtab" value="1" />
145 <strong><?php echo _('Name of the tab:') ?></strong>
146 <?php echo utils_requiredField(); ?><br/>
147 <input type="text" size="20" maxlength="255" name="tab_name" value="<?php echo $tab_name ?>" /><br />
148 <strong><?php echo _('URL of the tab:') ?></strong>
149 <?php echo utils_requiredField(); ?><br/>
150 <input type="text" size="60" name="tab_url" value="<?php echo $tab_url ?>" />
153 <input type="submit" value="<?php echo _('Add tab') ?>" />
159 $res = db_query_params ('SELECT * FROM plugin_extratabs_main WHERE group_id=$1 ORDER BY index ASC', array ($group_id)) ;
160 $nbtabs = db_numrows($res) ;
165 <h2><?php echo _('Move or delete extra tabs') ;?></h2>
167 <?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.') ;
172 <form name="change_tab" action="<?php echo util_make_url ('/plugins/extratabs/'); ?>" method="post">
174 <legend>Move or delete tab</legend>
176 <input type="hidden" name="group_id" value="<?php echo $group->getID() ?>" />
178 echo _('Tab to modify:')
180 <select name="index">
182 while ($row = db_fetch_array($res)) {
183 if ($row['index'] == $selected) {
184 echo "<option selected=\"selected\" value='" . $row['index'] . "'>" . $row['tab_name'] . "</option>";
186 echo "<option value='" . $row['index'] . "'>" . $row['tab_name'] . "</option>";
192 <?php if ($nbtabs > 1) { ?>
193 <input type="submit" name="up" value="<?php echo _('Move tab before') ?>" />
194 <input type="submit" name="down" value="<?php echo _('Move tab after') ?>" />
196 <input type="submit" name="delete" value="<?php echo _('Delete tab') ?>" />
203 project_admin_footer(array());
207 // c-file-style: "bsd"