3 * Code Snippets Repository
5 * Copyright 1999-2001 (c) VA Linux Systems
6 * Copyright 2013, French Ministry of National Education
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 Show a detail page for either a snippet or a package
31 or a specific version of a package
34 $type = getStringFromRequest('type');
35 $id = getIntFromRequest('id');
37 if ($type=='snippet') {
39 View a snippet and show its versions
40 Expand and show the code for the latest version
43 snippet_header(array('title'=>_('Snippet Library')));
45 snippet_show_snippet_details($id);
48 Get all the versions of this snippet
50 $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
51 FROM snippet_version,users
52 WHERE users.user_id=snippet_version.submitted_by AND snippet_id=$1
53 ORDER BY snippet_version.snippet_version_id DESC", array($id));
55 $rows=db_numrows($result);
56 if (!$result || $rows < 1) {
57 echo '<div class="error">' ._('Error - no versions found').'</div>';
60 <h3>' ._('Versions Of This Snippet:').'</h3>
63 $title_arr[]= _('Snippet ID');
64 $title_arr[]= _('Download Version');
65 $title_arr[]= _('Date Posted');
66 $title_arr[]= _('Author');
67 $title_arr[]= _('Delete');
69 echo $GLOBALS['HTML']->listTableTop ($title_arr);
72 get the newest version of this snippet, so we can display its code
74 $newest_version=db_result($result,0,'snippet_version_id');
76 for ($i=0; $i<$rows; $i++) {
78 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'><td>'.db_result($result,$i,'snippet_version_id').
80 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>'.
81 date(_('Y-m-d H:i'),db_result($result,$i,'post_date')).'</td><td>'.
82 util_make_link_u (db_result($result, $i, 'user_name'), db_result($result, $i, 'user_id'),db_result($result, $i, 'realname')).'</td>'.
83 '<td class="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>';
85 if ($i != ($rows - 1)) {
87 <tr><td colspan="5">' ._('Changes since last version:').'<br />'.
88 nl2br(db_result($result,$i,'changes')).'</td></tr>';
92 echo $GLOBALS['HTML']->listTableBottom();
95 </p><p>'._('Download a raw-text version of this code by clicking on "<strong>Download Version</strong>"').'
98 show the latest version of this snippet's code
100 $result=db_query_params ('SELECT code,version FROM snippet_version WHERE snippet_version_id=$1',
101 array($newest_version));
106 <h2>'._('Latest Snippet Version: ').db_result($result,0,'version').'</h2>
108 <span class="snippet-detail">'. db_result($result,0,'code') .'
112 Show a link so you can add a new version of this snippet
115 <h3><a href="'.util_make_url ('/snippet/addversion.php?type=snippet&id='.htmlspecialchars($id)).'"><span class="important">'._('Submit a new version').'</span></a></h3>
116 <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>';
119 snippet_footer(array());
121 } elseif ($type=='package') {
125 View a package and show its versions
126 Expand and show the snippets for the latest version
131 snippet_header(array('title'=>_('Snippet Library')));
133 snippet_show_package_details($id);
136 Get all the versions of this package
138 $result = db_query_params ('SELECT users.realname,users.user_name,users.user_id,snippet_package_version.snippet_package_version_id,
139 snippet_package_version.version,snippet_package_version.post_date
140 FROM snippet_package_version,users
141 WHERE users.user_id=snippet_package_version.submitted_by AND snippet_package_id=$1
142 ORDER BY snippet_package_version.snippet_package_version_id DESC',
145 $rows=db_numrows($result);
146 if (!$result || $rows < 1) {
147 echo '<div class="error">' ._('Error - no versions found').'</div>';
150 <h3>' ._('Versions Of This Package:').'</h3>
153 $title_arr[]= _('Package Version');
154 $title_arr[]= _('Date Posted');
155 $title_arr[]= _('Author');
156 $title_arr[]= _('Edit/Del');
158 echo $GLOBALS['HTML']->listTableTop ($title_arr);
161 determine the newest version of this package,
162 so we can display the snippets that it contains
164 $newest_version=db_result($result,0,'snippet_package_version_id');
166 for ($i=0; $i<$rows; $i++) {
168 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'><td>'.
169 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>'.
170 date(_('Y-m-d H:i'),db_result($result,$i,'post_date')).'</td><td>'.
171 util_make_link_u (db_result($result, $i, 'user_name'), db_result($result, $i, 'user_id'),db_result($result, $i, 'realname')).'</td>'.
172 '<td class="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')).
173 '">' . html_image("ic/pencil.png","20","25") .
174 '</a> <a href="'.
175 util_make_url ('/snippet/delete.php?type=package&snippet_package_version_id='.db_result($result,$i,'snippet_package_version_id')).
176 '">' . html_image("ic/trash.png","16","16") . '</a></td></tr>';
179 echo $GLOBALS['HTML']->listTableBottom();
182 </p><p>' ._('Download a raw-text version of this code by clicking on "<strong>Download Version</strong>"').'
186 show the latest version of the package
193 <h2>' ._('Latest Package Version: ').db_result($result,0,'version').'</h2>
196 snippet_show_package_snippets($newest_version);
199 Show a form so you can add a new version of this package
202 <h3><a href="'.util_make_url ('/snippet/addversion.php?type=package&id='.$id).'"><span class="important">' ._('Submit a new version').'</span></a></h3>
203 <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>';
206 snippet_footer(array());
208 } elseif ($type=='packagever') {
210 Show a specific version of a package and its specific snippet versions
213 snippet_header(array('title'=>_('Snippet Library')));
215 snippet_show_package_details($id);
217 snippet_show_package_snippets($id);
219 snippet_footer(array());
223 exit_error(_('Error - was the URL mangled?'));