3 * FusionForge globalsearch plugin
5 * Copyright 1999-2001, VA Linux Systems, Inc.
6 * Copyright 2003-2004, GForge, LLC
7 * Copyright 2007-2009, Roland Mas
9 * This file is part of FusionForge.
11 * FusionForge is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published
13 * by the Free Software Foundation; either version 2 of the License,
14 * or (at your option) any later version.
16 * FusionForge is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * globalsearch_admin_table_add() - present a form for adding a record to the specified table
29 function globalsearch_admin_table_add () {
32 echo _('Create a new associated forge below');
33 echo '<form name="add" action="'.$PHP_SELF.'?function=postadd" method="post">
36 echo '<tr><td><strong>'._('Title').'</strong></td><td><input type="text" name="title" /></td></tr>';
37 echo '<tr><td><strong>'._('Link').'</strong></td><td><input type="text" name="link" /></td></tr>';
38 echo '<tr><td><strong>'._('Software only').'</strong></td><td><input type="checkbox" checked name="onlysw" value="t"/></td></tr>';
39 echo '<tr><td><strong>'._('Enabled').'</strong></td><td><input type="checkbox" checked name="enabled" value="t"/></td></tr>';
40 echo '<tr><td><strong>'._('Rank').'</strong></td><td><input type="text" name="rank" /></td></tr>';
42 echo '</table><input type="submit" value="'._('Submit new associated forge').'" /></form>
43 <form name="cancel" action="'.$PHP_SELF.'" method="post">
44 <input type="submit" value="Cancel" />
49 * globalsearch_admin_table_postadd() - update the database based on a submitted change
51 function globalsearch_admin_table_postadd () {
52 $new_title = getStringFromRequest ('title');
53 $new_link = getStringFromRequest ('link');
54 $new_onlysw = getStringFromRequest ('onlysw');
55 $new_enabled = getStringFromRequest ('enabled');
56 $new_rank = getIntFromRequest ('rank', 1);
57 if ($new_onlysw != 't' and $new_onlysw != 'f') {
60 if ($new_enabled != 't' and $new_enabled != 'f') {
64 if (db_query_params ('INSERT INTO plugin_globalsearch_assoc_site (title, link, onlysw, enabled, rank)
65 VALUES ($1, $2, $3, $4, $5)',
71 echo _('Associated forge successfully added.');
78 * globalsearch_admin_table_confirmdelete() - present a form to confirm requested record deletion
80 * @param $id - the id of the record to act on
82 function globalsearch_admin_table_confirmdelete ($id) {
85 $result = db_query_params ('SELECT * FROM plugin_globalsearch_assoc_site WHERE assoc_site_id=$1',
87 if ($result and db_numrows($result) == 1) {
88 $title = db_result ($result, 0, 'title');
89 $link = db_result ($result, 0, 'link');
90 $onlysw = db_result ($result, 0, 'onlysw');
91 $enabled = db_result ($result, 0, 'enabled');
92 $rank = db_result ($result, 0, 'rank', 1);
94 echo _('Are you sure you want to delete this associated forge?') ;
96 echo '<tr><td><strong>'._('Title').'</strong></td><td>'.$title.'</td></tr>';
97 echo '<tr><td><strong>'._('Link').'</strong></td><td>'.$link.'</td></tr>';
98 echo '<tr><td><strong>'._('Software only').'</strong></td><td>'.(($onlysw == 't')?_('Yes'):_('No')) .'</td></tr>';
99 echo '<tr><td><strong>'._('Enabled').'</strong></td><td>'.(($enabled == 't')?_('Yes'):_('No')) .'</td></tr>';
100 echo '<tr><td><strong>'._('Rank').'</strong></td><td>'.$rank.'</td></tr>';
102 echo '<form name="delete" action="'.$PHP_SELF.'?function=delete&id='.$id.'" method="post">
103 <input type="submit" value="'._('Delete').'" />
105 <form name="cancel" action="'.$PHP_SELF.'" method="post">
106 <input type="submit" value="'._('Cancel').'" />
114 * globalsearch_admin_table_delete() - delete a record from the database after confirmation
116 * @param $id - the id of the record to act on
118 function globalsearch_admin_table_delete ($id) {
119 if (db_query_params ('DELETE FROM plugin_globalsearch_assoc_site WHERE assoc_site_id=$1',
121 echo _('Associated forge successfully deleted.');
128 * globalsearch_admin_table_edit() - present a form for editing a record in the specified table
130 * @param $id - the id of the record to act on
132 function globalsearch_admin_table_edit ($id) {
135 $result = db_query_params ('SELECT * FROM plugin_globalsearch_assoc_site WHERE assoc_site_id=$1',
137 if ($result and db_numrows($result) == 1) {
138 $old_title = db_result ($result, 0, 'title');
139 $old_link = db_result ($result, 0, 'link');
140 $old_onlysw = db_result ($result, 0, 'onlysw');
141 $old_enabled = db_result ($result, 0, 'enabled');
142 $old_rank = db_result ($result, 0, 'rank', 1);
144 echo _('Modify the associated forge below');
145 echo '<form name="edit" action="'.$PHP_SELF.'?function=postedit&id='.$id.'" method="post">
148 echo '<tr><td><strong>'._('Title').'</strong></td><td><input type="text" name="title" value="'.$old_title.'"/></td></tr>';
149 echo '<tr><td><strong>'._('Link').'</strong></td><td><input type="text" name="link" value="'.$old_link.'"/></td></tr>';
150 echo '<tr><td><strong>'._('Software only').'</strong></td><td><input type="checkbox" '.(($old_onlysw == 't')?'checked':'') .' name="onlysw" value="t"/></td></tr>';
151 echo '<tr><td><strong>'._('Enabled').'</strong></td><td><input type="checkbox" '.(($old_enabled == 't')?'checked':'') .' name="enabled" value="t"/></td></tr>';
152 echo '<tr><td><strong>'._('Rank').'</strong></td><td><input type="text" name="rank" value="'.$old_rank.'"/></td></tr>';
154 echo '</table><input type="submit" value="'._('Submit changes').'" /></form>
155 <form name="cancel" action="'.$PHP_SELF.'" method="post">
156 <input type="submit" value="'._('Cancel').'" />
164 * globalsearch_admin_table_postedit() - update the database to reflect submitted modifications to a record
166 * @param $id - the id of the record to act on
168 function globalsearch_admin_table_postedit ($id) {
169 $new_title = getStringFromRequest ('title');
170 $new_link = getStringFromRequest ('link');
171 $new_onlysw = getStringFromRequest ('onlysw');
172 $new_enabled = getStringFromRequest ('enabled');
173 $new_rank = getIntFromRequest ('rank', 999);
174 if ($new_onlysw != 't' and $new_onlysw != 'f') {
177 if ($new_enabled != 't' and $new_enabled != 'f') {
181 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',
188 echo _('Associated forge successfully modified.');
195 * globalsearch_admin_table_show() - display the specified table, sorted by the primary key, with links to add, edit, and delete
197 function globalsearch_admin_table_show () {
198 global $HTML, $PHP_SELF;
200 $result = db_query_params ('SELECT * FROM plugin_globalsearch_assoc_site ORDER BY assoc_site_id',
203 $rows = db_numrows($result);
206 $cell_data[]=array(ngettext('Associated forge','Associated forges',$rows).' <a href="'.$PHP_SELF.'?function=add">'._('[add new]').'</a>',
209 echo '<table border="0" width="100%">';
210 echo $HTML->multiTableRow('',$cell_data, TRUE);
212 echo '<td width="5%"></td>';
213 echo '<td><strong>'._('Forge ID').'</strong></td>';
214 echo '<td><strong>'._('Title').'</strong></td>';
215 echo '<td><strong>'._('Link').'</strong></td>';
216 echo '<td><strong>'._('Software only').'</strong></td>';
217 echo '<td><strong>'._('Enabled').'</strong></td>';
218 echo '<td><strong>'._('Status').'</strong></td>';
219 echo '<td><strong>'._('Rank').'</strong></td>';
222 for ($j = 0; $j < $rows; $j++) {
223 echo '<tr '. $HTML->boxGetAltRowStyle($j) . '>';
225 $id = db_result($result,$j,0);
226 echo '<td><a href="'.$PHP_SELF.'?function=edit&id='.$id.'">'._('[edit]').'</a> ';
227 echo '<a href="'.$PHP_SELF.'?function=confirmdelete&id='.$id.'">'._('[delete]').'</a> </td>';
229 echo '<td><strong>'.db_result ($result, $j, 'assoc_site_id').'</strong></td>';
230 echo '<td><strong>'.db_result ($result, $j, 'title').'</strong></td>';
231 echo '<td><strong>'.db_result ($result, $j, 'link').'</strong></td>';
232 echo '<td><strong>'.((db_result ($result, $j, 'onlysw') == 't')?_('Yes'):_('No')).'</strong></td>';
233 echo '<td><strong>'.((db_result ($result, $j, 'enabled') == 't')?_('Yes'):_('No')).'</strong></td>';
234 echo '<td><strong>'.globalsearch_status_name (db_result ($result, $j, 'status_id')).'</strong></td>';
235 echo '<td><strong>'.db_result ($result, $j, 'rank').'</strong></td>';
244 function globalsearch_status_name ($status_id) {
245 switch ($status_id) {
246 case 1: return _('New'); break;
247 case 2: return _('OK'); break;
248 case 3: return _('Error fetching data'); break;
249 case 4: return _('Error parsing data'); break;
250 default: return _('Unknown status ID');
256 // c-file-style: "bsd"