3 * Code Snippets Repository
5 * Copyright 1999-2001 (c) VA Linux Systems
6 * Copyright 2013, Franck Villaume - TrivialDev
7 * http://fusionforge.org
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 require_once '../env.inc.php';
26 require_once $gfcommon.'include/pre.php';
27 require_once $gfwww.'snippet/snippet_utils.php';
30 * createSnippetQuery - Creates the SQL query for loading data about snippets
32 * @param string $clause - the last part of the where clause
35 function createSnippetQuery($clause) {
36 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;
40 * createPackageQuery - Creates the SQL query for loading data about packages
42 * @param string $clause - the last part of the where clause
45 function createPackageQuery($clause) {
46 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;
49 snippet_header(array('title'=>_('Snippet Library'), 'header'=>''));
51 $by = getStringFromRequest('by');
53 $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 ') ;
54 $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 ') ;
57 $lang = getStringFromRequest('lang');
59 $qpa = db_construct_qpa ($qpa, ' AND snippet.language=$1', array ($lang)) ;
60 $qpa2 = db_construct_qpa ($qpa2, ' AND snippet_package.language=$1', array ($lang)) ;
62 echo '<h2>' .sprintf(_('Snippets by language: %1$s'), $SCRIPT_LANGUAGE[$lang]).'</h2>';
63 } elseif ($by=='cat') {
64 $cat = getStringFromRequest('cat');
66 $qpa = db_construct_qpa ($qpa, ' AND snippet.category=$1', array ($cat)) ;
67 $qpa2 = db_construct_qpa ($qpa2, ' AND snippet_package.category=$1', array ($cat)) ;
69 echo '<h2>' .sprintf(_('Snippets by category: %1$s'), $SCRIPT_CATEGORY[$cat]).'</h2>';
71 exit_error(_('Error: bad url?'));
74 $result = db_query_qpa ($qpa) ;
75 $rows=db_numrows($result);
76 $result2 = db_query_qpa ($qpa2) ;
77 $rows2=db_numrows($result2);
79 if ((!$result || $rows < 1) && (!$result2 || $rows2 < 1)) {
80 echo '<p class="information">' ._('No snippets found.').'</p>';
84 $title_arr[]= _('Snippet ID');
85 $title_arr[]= _('Title');
86 $title_arr[]= _('Creator');
88 echo $GLOBALS['HTML']->listTableTop ($title_arr);
90 // List packages if there are any
93 <tr class="tableheading"><td colspan="3">' ._('Packages Of Snippets').'<td>';
95 for ($i=0; $i<$rows2; $i++) {
97 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'><td rowspan="2">'.
98 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>'.
99 db_result($result2,$i,'name').'</td><td>'.
100 util_make_link_u (db_result($result2, $i, 'user_name'), db_result($result2, $i, 'user_id'), db_result($result2, $i, 'realname')).'</td></tr>';
102 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'><td colspan="2">'.util_make_links(nl2br(db_result($result2,$i,'description'))).'</td></tr>';
105 // List snippets if there are any
108 <tr class="tableheading"><td colspan="3">' ._('Snippets').'</td>';
110 for ($i=0; $i<$rows; $i++) {
112 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'><td rowspan="2">'.
113 util_make_link ('/snippet/detail.php?type=snippet&id='.db_result($result,$i,'snippet_id'),'<strong>'.db_result($result,$i,'snippet_id').'</strong>').
115 util_make_link ('/snippet/detail.php?type=snippet&id='.db_result($result,$i,'snippet_id'),db_result($result,$i,'name')).
116 '</strong></td><td>'.
117 util_make_link_u (db_result($result, $i, 'user_name'), db_result($result, $i, 'user_id'), db_result($result, $i, 'realname')).'</td></tr>';
119 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'><td colspan="2">'.util_make_links(nl2br(db_result($result,$i,'description'))).'</td></tr>';
121 echo $GLOBALS['HTML']->listTableBottom();
123 snippet_footer(array());