3 * Code Snippets Repository
5 * Copyright 1999-2001 (c) VA Linux Systems
6 * http://fusionforge.org
8 * This file is part of FusionForge. FusionForge is free software;
9 * you can redistribute it and/or modify it under the terms of the
10 * GNU General Public License as published by the Free Software
11 * Foundation; either version 2 of the Licence, or (at your option)
14 * FusionForge 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.
19 * You should have received a copy of the GNU General Public License along
20 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 require_once '../env.inc.php';
25 require_once $gfcommon.'include/pre.php';
26 require_once $gfwww.'snippet/snippet_utils.php';
29 * createSnippetQuery - Creates the SQL query for loading data about snippets
31 * @param string clause - the last part of the where clause
34 function createSnippetQuery($clause) {
35 return "SELECT users.realname,users.user_name,snippet.description,snippet.snippet_id,snippet.name FROM snippet,users WHERE users.user_id=snippet.created_by AND ".$clause;
39 * createPackageQuery - Creates the SQL query for loading data about packages
41 * @param string clause - the last part of the where clause
44 function createPackageQuery($clause) {
45 return "SELECT users.realname,users.user_name,users.user_id,snippet_package.description,snippet_package.snippet_package_id,snippet_package.name FROM snippet_package,users WHERE users.user_id=snippet_package.created_by AND ".$clause;
48 snippet_header(array('title'=>_('Snippet Library'), 'header'=>''));
50 $by = getStringFromRequest('by');
52 $qpa = db_construct_qpa (false, 'SELECT users.realname,users.user_name,snippet.description,snippet.snippet_id,snippet.name FROM snippet,users WHERE users.user_id=snippet.created_by ') ;
53 $qpa2 = db_construct_qpa (false, 'SELECT users.realname,users.user_name,users.user_id,snippet_package.description,snippet_package.snippet_package_id,snippet_package.name FROM snippet_package,users WHERE users.user_id=snippet_package.created_by ') ;
56 $lang = getStringFromRequest('lang');
58 $qpa = db_construct_qpa ($qpa, ' AND snippet.language=$1', array ($lang)) ;
59 $qpa2 = db_construct_qpa ($qpa2, ' AND snippet_package.language=$1', array ($lang)) ;
61 echo '<h2>' .sprintf(_('Snippets by language: %1$s'), $SCRIPT_LANGUAGE[$lang]).'</h2>';
62 } elseif ($by=='cat') {
63 $cat = getStringFromRequest('cat');
65 $qpa = db_construct_qpa ($qpa, ' AND snippet.category=$1', array ($cat)) ;
66 $qpa2 = db_construct_qpa ($qpa2, ' AND snippet_package.category=$1', array ($cat)) ;
68 echo '<h2>' .sprintf(_('Snippets by category: %1$s'), $SCRIPT_CATEGORY[$cat]).'</h2>';
70 exit_error(_('Error: bad url?'));
73 $result = db_query_qpa ($qpa) ;
74 $rows=db_numrows($result);
75 $result2 = db_query_qpa ($qpa2) ;
76 $rows2=db_numrows($result2);
78 if ((!$result || $rows < 1) && (!$result2 || $rows2 < 1)) {
79 echo '<h2>' ._('No snippets found').'</h2>';
83 $title_arr[]= _('Snippet ID');
84 $title_arr[]= _('Title');
85 $title_arr[]= _('Creator');
87 echo $GLOBALS['HTML']->listTableTop ($title_arr);
89 // List packages if there are any
92 <tr class="tableheading"><td colspan="3">' ._('Packages Of Snippets').'<td>';
94 for ($i=0; $i<$rows2; $i++) {
96 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'><td rowspan="2">'.
97 util_make_link ('/snippet/detail.php?type=package&id='.db_result($result2,$i,'snippet_package_id'),'<strong>'.db_result($result2,$i,'snippet_package_id').'</strong>').'</td><td><strong>'.
98 db_result($result2,$i,'name').'</td><td>'.
99 util_make_link_u (db_result($result2, $i, 'user_name'), db_result($result2, $i, 'user_id'), db_result($result2, $i, 'realname')).'</td></tr>';
101 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'><td colspan="2">'.util_make_links(nl2br(db_result($result2,$i,'description'))).'</td></tr>';
104 // List snippets if there are any
107 <tr class="tableheading"><td colspan="3">' ._('Snippets').'</td>';
109 for ($i=0; $i<$rows; $i++) {
111 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'><td rowspan="2">'.
112 util_make_link ('/snippet/detail.php?type=snippet&id='.db_result($result,$i,'snippet_id'),'<strong>'.db_result($result,$i,'snippet_id').'</strong>').
114 util_make_link ('/snippet/detail.php?type=snippet&id='.db_result($result,$i,'snippet_id'),db_result($result,$i,'name')).
115 '</strong></td><td>'.
116 util_make_link_u (db_result($result, $i, 'user_name'), db_result($result, $i, 'user_id'), db_result($result, $i, 'realname')).'</td></tr>';
118 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'><td colspan="2">'.util_make_links(nl2br(db_result($result,$i,'description'))).'</td></tr>';
120 echo $GLOBALS['HTML']->listTableBottom();
122 snippet_footer(array());