3 * FusionForge globalsearch plugin
5 * Copyright 1999-2001, VA Linux Systems, Inc.
6 * Copyright 2003-2004, GForge, LLC
7 * Copyright 2007-2009, Roland Mas
8 * Copyright 2016, Franck Villaume - TrivialDev
10 * This file is part of FusionForge.
12 * FusionForge is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published
14 * by the Free Software Foundation; either version 2 of the License,
15 * or (at your option) any later version.
17 * FusionForge is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 * globalsearch_admin_table_add() - present a form for adding a record to the specified table
30 function globalsearch_admin_table_add() {
32 echo _('Create a new associated forge below');
33 echo $HTML->openForm(array('name' => 'add', 'action' => '/plugins/globalsearch/edit_assoc_sites.php?function=postadd', 'method' => 'post'));
35 echo '<tr><td><strong>'._('Title').'</strong></td><td><input type="text" name="title" required="required" /></td></tr>';
36 echo '<tr><td><strong>'._('Link').'</strong></td><td><input type="text" name="link" required="required" /></td></tr>';
37 echo '<tr><td><strong>'._('Software only').'</strong></td><td><input type="checkbox" checked name="onlysw" value="t"/></td></tr>';
38 echo '<tr><td><strong>'._('Enabled').'</strong></td><td><input type="checkbox" checked name="enabled" value="t"/></td></tr>';
39 echo '<tr><td><strong>'._('Rank').'</strong></td><td><input type="text" name="rank" /></td></tr>';
40 echo '</table><input type="submit" value="'._('Submit new associated forge').'" />
41 <input type="reset" value="'._('Cancel').'" />';
42 echo $HTML->closeForm();
46 * globalsearch_admin_table_postadd() - update the database based on a submitted change
48 function globalsearch_admin_table_postadd () {
49 $new_title = getStringFromRequest ('title');
50 $new_link = getStringFromRequest ('link');
51 $new_onlysw = getStringFromRequest ('onlysw');
52 $new_enabled = getStringFromRequest ('enabled');
53 $new_rank = getIntFromRequest ('rank', 1);
54 if ($new_onlysw != 't' and $new_onlysw != 'f') {
57 if ($new_enabled != 't' and $new_enabled != 'f') {
61 if (db_query_params ('INSERT INTO plugin_globalsearch_assoc_site (title, link, onlysw, enabled, rank)
62 VALUES ($1, $2, $3, $4, $5)',
68 echo _('Associated Forge successfully added.');
75 * globalsearch_admin_table_confirmdelete() - present a form to confirm requested record deletion
77 * @param $id - the id of the record to act on
79 function globalsearch_admin_table_confirmdelete ($id) {
82 $result = db_query_params ('SELECT * FROM plugin_globalsearch_assoc_site WHERE assoc_site_id=$1',
84 if ($result and db_numrows($result) == 1) {
85 $title = db_result ($result, 0, 'title');
86 $link = db_result ($result, 0, 'link');
87 $onlysw = db_result ($result, 0, 'onlysw');
88 $enabled = db_result ($result, 0, 'enabled');
89 $rank = db_result ($result, 0, 'rank');
91 echo _('Are you sure you want to delete this associated forge?') ;
93 echo '<tr><td><strong>'._('Title').'</strong></td><td>'.$title.'</td></tr>';
94 echo '<tr><td><strong>'._('Link').'</strong></td><td>'.$link.'</td></tr>';
95 echo '<tr><td><strong>'._('Software only').'</strong></td><td>'.(($onlysw == 't')?_('Yes'):_('No')) .'</td></tr>';
96 echo '<tr><td><strong>'._('Enabled').'</strong></td><td>'.(($enabled == 't')?_('Yes'):_('No')) .'</td></tr>';
97 echo '<tr><td><strong>'._('Rank').'</strong></td><td>'.$rank.'</td></tr>';
99 echo $HTML->openForm(array('name' => 'delete', 'action' => '/plugins/globalsearch/edit_assoc_sites.php?function=delete&id='.$id, 'method' => 'post'));
100 echo '<input type="submit" value="'._('Delete').'" />';
101 echo util_make_link('/plugins/globalsearch/edit_assoc_sites.php', '<input type="button" value="'._('Cancel').'" />');
102 echo $HTML->closeForm();
109 * globalsearch_admin_table_delete() - delete a record from the database after confirmation
111 * @param $id - the id of the record to act on
113 function globalsearch_admin_table_delete ($id) {
114 if (db_query_params ('DELETE FROM plugin_globalsearch_assoc_site WHERE assoc_site_id=$1',
116 echo _('Associated Forge successfully deleted.');
123 * globalsearch_admin_table_edit() - present a form for editing a record in the specified table
125 * @param $id - the id of the record to act on
127 function globalsearch_admin_table_edit ($id) {
130 $result = db_query_params ('SELECT * FROM plugin_globalsearch_assoc_site WHERE assoc_site_id=$1',
132 if ($result and db_numrows($result) == 1) {
133 $old_title = db_result ($result, 0, 'title');
134 $old_link = db_result ($result, 0, 'link');
135 $old_onlysw = db_result ($result, 0, 'onlysw');
136 $old_enabled = db_result ($result, 0, 'enabled');
137 $old_rank = db_result ($result, 0, 'rank');
139 echo _('Modify the associated forge below');
140 echo $HTML->openForm(array('name' => 'edit', 'action' => '/plugins/globalsearch/edit_assoc_sites.php?function=postedit&id='.$id, 'method' => 'post'));
143 echo '<tr><td><strong>'._('Title').'</strong></td><td><input type="text" name="title" value="'.$old_title.'"/></td></tr>';
144 echo '<tr><td><strong>'._('Link').'</strong></td><td><input type="text" name="link" value="'.$old_link.'"/></td></tr>';
145 echo '<tr><td><strong>'._('Software only').'</strong></td><td><input type="checkbox" '.(($old_onlysw == 't')?'checked':'') .' name="onlysw" value="t"/></td></tr>';
146 echo '<tr><td><strong>'._('Enabled').'</strong></td><td><input type="checkbox" '.(($old_enabled == 't')?'checked':'') .' name="enabled" value="t"/></td></tr>';
147 echo '<tr><td><strong>'._('Rank').'</strong></td><td><input type="text" name="rank" value="'.$old_rank.'"/></td></tr>';
149 echo '</table><input type="submit" value="'._('Submit Changes').'" />';
150 echo $HTML->closeForm();
151 echo util_make_link('/plugins/globalsearch/edit_assoc_sites.php', '<input type="button" value="'._('Cancel').'" />');
158 * globalsearch_admin_table_postedit() - update the database to reflect submitted modifications to a record
160 * @param $id - the id of the record to act on
162 function globalsearch_admin_table_postedit ($id) {
163 $new_title = getStringFromRequest ('title');
164 $new_link = getStringFromRequest ('link');
165 $new_onlysw = getStringFromRequest ('onlysw');
166 $new_enabled = getStringFromRequest ('enabled');
167 $new_rank = getIntFromRequest ('rank', 999);
168 if ($new_onlysw != 't' and $new_onlysw != 'f') {
171 if ($new_enabled != 't' and $new_enabled != 'f') {
175 if (db_query_params ('UPDATE plugin_globalsearch_assoc_site SET title=$1, link=$2, onlysw=$3, enabled=$4, rank=$5 WHERE assoc_site_id=$6',
182 echo _('Associated Forge successfully modified.');
189 * globalsearch_admin_table_show() - display the specified table, sorted by the primary key, with links to add, edit, and delete
191 function globalsearch_admin_table_show () {
194 $result = db_query_params ('SELECT * FROM plugin_globalsearch_assoc_site ORDER BY assoc_site_id',
197 $rows = db_numrows($result);
200 $cell_data[]=array(ngettext('Associated Forge','Associated Forges',$rows).' '.util_make_link(getStringFromServer('PHP_SELF').'?function=add', '['._('add new').']'),
203 echo '<table border="0" width="100%">';
204 echo $HTML->multiTableRow(array(),$cell_data, TRUE);
207 echo '<td style="width:5%;"></td>';
208 echo '<td><strong>'._('Forge ID').'</strong></td>';
209 echo '<td><strong>'._('Title').'</strong></td>';
210 echo '<td><strong>'._('Link').'</strong></td>';
211 echo '<td><strong>'._('Software only').'</strong></td>';
212 echo '<td><strong>'._('Enabled').'</strong></td>';
213 echo '<td><strong>'._('Status').'</strong></td>';
214 echo '<td><strong>'._('Rank').'</strong></td>';
217 for ($j = 0; $j < $rows; $j++) {
220 $id = db_result($result,$j,0);
221 echo '<td>'.util_make_link(getStringFromServer('PHP_SELF').'?function=edit&id='.$id, '['._('edit').']');
222 echo util_make_link(getStringFromServer('PHP_SELF').'?function=confirmdelete&id='.$id, '['._('delete').']').'</td>';
224 echo '<td><strong>'.db_result ($result, $j, 'assoc_site_id').'</strong></td>';
225 echo '<td><strong>'.db_result ($result, $j, 'title').'</strong></td>';
226 echo '<td><strong>'.db_result ($result, $j, 'link').'</strong></td>';
227 echo '<td><strong>'.((db_result ($result, $j, 'onlysw') == 't')?_('Yes'):_('No')).'</strong></td>';
228 echo '<td><strong>'.((db_result ($result, $j, 'enabled') == 't')?_('Yes'):_('No')).'</strong></td>';
229 echo '<td><strong>'.globalsearch_status_name (db_result ($result, $j, 'status_id')).'</strong></td>';
230 echo '<td><strong>'.db_result ($result, $j, 'rank').'</strong></td>';
239 function globalsearch_status_name ($status_id) {
240 switch ($status_id) {
241 case 1: return _('New'); break;
242 case 2: return _('OK'); break;
243 case 3: return _('Error fetching data'); break;
244 case 4: return _('Error parsing data'); break;
245 default: return _('Unknown status ID');
251 // c-file-style: "bsd"