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 Show a detail page for either a snippet or a package
30 or a specific version of a package
33 $type = getStringFromRequest('type');
34 $id = getIntFromRequest('id');
36 if ($type=='snippet') {
38 View a snippet and show its versions
39 Expand and show the code for the latest version
42 snippet_header(array('title'=>_('Snippet Library')));
44 snippet_show_snippet_details($id);
47 Get all the versions of this snippet
49 $result=db_query_params("SELECT users.realname,users.user_name,users.user_id,snippet_version.snippet_version_id,snippet_version.version,snippet_version.post_date,snippet_version.changes
50 FROM snippet_version,users
51 WHERE users.user_id=snippet_version.submitted_by AND snippet_id=$1
52 ORDER BY snippet_version.snippet_version_id DESC", array($id));
54 $rows=db_numrows($result);
55 if (!$result || $rows < 1) {
56 echo '<div class="error">' ._('Error - no versions found').'</div>';
59 <h3>' ._('Versions Of This Snippet:').'</h3>
62 $title_arr[]= _('Snippet ID');
63 $title_arr[]= _('Download Version');
64 $title_arr[]= _('Date Posted');
65 $title_arr[]= _('Author');
66 $title_arr[]= _('Delete');
68 echo $GLOBALS['HTML']->listTableTop ($title_arr);
71 get the newest version of this snippet, so we can display its code
73 $newest_version=db_result($result,0,'snippet_version_id');
75 for ($i=0; $i<$rows; $i++) {
77 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'><td>'.db_result($result,$i,'snippet_version_id').
79 util_make_link ('/snippet/download.php?type=snippet&id='.db_result($result,$i,'snippet_version_id'),'<strong>'. db_result($result,$i,'version').'</strong>').'</td><td>'.
80 date(_('Y-m-d H:i'),db_result($result,$i,'post_date')).'</td><td>'.
81 util_make_link_u (db_result($result, $i, 'user_name'), db_result($result, $i, 'user_id'),db_result($result, $i, 'realname')).'</td>'.
82 '<td style="text-align:center"><a href="'.util_make_url ('/snippet/delete.php?type=snippet&snippet_version_id='.db_result($result,$i,'snippet_version_id')).'">' . html_image("ic/trash.png","16","16",array("border"=>"0")) . '</a></td></tr>';
84 if ($i != ($rows - 1)) {
86 <tr'.$row_color.'><td colspan="5">' ._('Changes since last version:').'<br />'.
87 nl2br(db_result($result,$i,'changes')).'</td></tr>';
91 echo $GLOBALS['HTML']->listTableBottom();
94 </p><p>'._('Download a raw-text version of this code by clicking on "<strong>Download Version</strong>"').'
97 show the latest version of this snippet's code
99 $result=db_query_params ('SELECT code,version FROM snippet_version WHERE snippet_version_id=$1',
100 array($newest_version));
105 <h2>'._('Latest Snippet Version: ').db_result($result,0,'version').'</h2>
107 <span class="snippet-detail">'. db_result($result,0,'code') .'
111 Show a link so you can add a new version of this snippet
114 <h3><a href="'.util_make_url ('/snippet/addversion.php?type=snippet&id='.htmlspecialchars($id)).'"><span class="important">'._('Submit a new version').'</span></a></h3>
115 <p>' ._('You can submit a new version of this snippet if you have modified it and you feel it is appropriate to share with others.').'.</p>';
118 snippet_footer(array());
120 } else if ($type=='package') {
124 View a package and show its versions
125 Expand and show the snippets for the latest version
130 snippet_header(array('title'=>_('Snippet Library')));
132 snippet_show_package_details($id);
135 Get all the versions of this package
137 $result = db_query_params ('SELECT users.realname,users.user_name,users.user_id,snippet_package_version.snippet_package_version_id,
138 snippet_package_version.version,snippet_package_version.post_date
139 FROM snippet_package_version,users
140 WHERE users.user_id=snippet_package_version.submitted_by AND snippet_package_id=$1
141 ORDER BY snippet_package_version.snippet_package_version_id DESC',
144 $rows=db_numrows($result);
145 if (!$result || $rows < 1) {
146 echo '<div class="error">' ._('Error - no versions found').'</div>';
149 <h3>' ._('Versions Of This Package:').'</h3>
152 $title_arr[]= _('Package Version');
153 $title_arr[]= _('Date Posted');
154 $title_arr[]= _('Author');
155 $title_arr[]= _('Edit/Del');
157 echo $GLOBALS['HTML']->listTableTop ($title_arr);
160 determine the newest version of this package,
161 so we can display the snippets that it contains
163 $newest_version=db_result($result,0,'snippet_package_version_id');
165 for ($i=0; $i<$rows; $i++) {
167 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'><td>'.
168 util_make_link ('/snippet/detail.php?type=packagever&id='.db_result($result,$i,'snippet_package_version_id'),'<strong>'.db_result($result,$i,'version').'</strong>').'</td><td>'.
169 date(_('Y-m-d H:i'),db_result($result,$i,'post_date')).'</td><td>'.
170 util_make_link_u (db_result($result, $i, 'user_name'), db_result($result, $i, 'user_id'),db_result($result, $i, 'realname')).'</td>'.
171 '<td style="text-align:center"><a href="'.util_make_url ('/snippet/add_snippet_to_package.php?snippet_package_version_id='.db_result($result,$i,'snippet_package_version_id')).
172 '">' . html_image("ic/pencil.png","20","25") .
173 '</a> <a href="'.
174 util_make_url ('/snippet/delete.php?type=package&snippet_package_version_id='.db_result($result,$i,'snippet_package_version_id')).
175 '">' . html_image("ic/trash.png","16","16") . '</a></td></tr>';
178 echo $GLOBALS['HTML']->listTableBottom();
181 </p><p>' ._('Download a raw-text version of this code by clicking on "<strong>Download Version</strong>"').'
185 show the latest version of the package
192 <h2>' ._('Latest Package Version: ').db_result($result,0,'version').'</h2>
195 snippet_show_package_snippets($newest_version);
198 Show a form so you can add a new version of this package
201 <h3><a href="'.util_make_url ('/snippet/addversion.php?type=package&id='.$id).'"><span class="important">' ._('Submit a new version').'</span></a></h3>
202 <p>' ._('You can submit a new version of this package if you have modified it and you feel it is appropriate to share with others.').'.</p>';
205 snippet_footer(array());
207 } else if ($type=='packagever') {
209 Show a specific version of a package and its specific snippet versions
212 snippet_header(array('title'=>_('Snippet Library')));
214 snippet_show_package_details($id);
216 snippet_show_package_snippets($id);
218 snippet_footer(array());
222 exit_error(_('Error - was the URL mangled?'));