3 * Code Snippets Repository
5 * Copyright 1999-2001 (c) VA Linux Systems
6 * Copyright (C) 2010 Alain Peyrat - Alcatel-Lucent
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';
29 $suppress_nav = getStringFromRequest('suppress_nav');
31 function handle_add_exit() {
37 snippet_footer(array());
42 if (session_loggedin()) {
43 $snippet_package_version_id = getIntFromRequest('snippet_package_version_id');
44 $snippet_version_id = getIntFromRequest('snippet_version_id');
51 snippet_header(array('title'=>_('Submit A New Snippet')));
54 if (!$snippet_package_version_id) {
55 //make sure the package id was passed in
56 echo '<p class="error">' ._('Error - snippet_package_version_id missing') .'</p>';
60 if (getStringFromRequest('post_changes')) {
62 Create a new snippet entry, then create a new snippet version entry
64 if ($snippet_package_version_id && $snippet_version_id) {
66 check to see if they are the creator of this version
68 $result=db_query_params("SELECT * FROM snippet_package_version ".
69 "WHERE submitted_by=$1 AND ".
70 "snippet_package_version_id=$2", array(user_getid(), $snippet_package_version_id));
71 if (!$result || db_numrows($result) < 1) {
72 echo '<p class="error">' ._('Error - Only the creator of a package version can add snippets to it.').'</p>';
77 make sure the snippet_version_id exists
79 $result=db_query_params ('SELECT * FROM snippet_version WHERE snippet_version_id=$1',
80 array($snippet_version_id));
81 if (!$result || db_numrows($result) < 1) {
82 echo '<p class="error">' ._('Error - That snippet doesn\'t exist.').'</p>';
83 echo util_make_link ('/snippet/add_snippet_to_package.php?snippet_package_version_id='.$snippet_package_version_id,_('Back To Add Page'));
88 make sure the snippet_version_id isn't already in this package
90 $result=db_query_params ('SELECT * FROM snippet_package_item
91 WHERE snippet_package_version_id=$1
92 AND snippet_version_id=$2',
93 array($snippet_package_version_id,
94 $snippet_version_id));
95 if ($result && db_numrows($result) > 0) {
96 echo '<p class="error">'._('Error - That snippet was already added to this package.').'</p>';
97 echo util_make_url ('/snippet/add_snippet_to_package.php?snippet_package_version_id='.$snippet_package_version_id,_('Back To Add Page'));
102 create the snippet version
104 $result=db_query_params("INSERT INTO snippet_package_item (snippet_package_version_id,snippet_version_id)
105 VALUES ($1, $2)", array($snippet_package_version_id, $snippet_version_id));
108 $feedback .= _('ERROR DOING SNIPPET VERSION INSERT!');
111 $feedback .= _('Snippet Version Added Successfully.');
114 echo '<p class="error">' ._('Error - Go back and fill in all the information').'</p>';
115 echo util_make_link ('/snippet/add_snippet_to_package.php?snippet_package_version_id='.$snippet_package_version_id,_('Back To Add Page'));
121 $result=db_query_params ('SELECT snippet_package.name,snippet_package_version.version
122 FROM snippet_package,snippet_package_version
123 WHERE snippet_package.snippet_package_id=snippet_package_version.snippet_package_id
124 AND snippet_package_version.snippet_package_version_id=$1',
125 array($snippet_package_version_id));
129 <strong><?php echo _('Package:'); ?></strong><br />
130 <?php echo db_result($result,0,'name') . ' - ' . db_result($result,0,'version'); ?></p>
131 <p><?php echo _('You can use this form repeatedly to keep adding snippets to your package.'); ?></p>
132 <p><?php echo _('The "Snippet Version ID" is the unique ID number that is shown next to a specific version of a snippet on the browse pages.'); ?></p>
134 <form action="<?php echo getStringFromServer('PHP_SELF'); ?>" method="post">
135 <input type="hidden" name="post_changes" value="y" />
136 <input type="hidden" name="snippet_package_version_id" value="<?php echo $snippet_package_version_id; ?>" />
137 <input type="hidden" name="suppress_nav" value="<?php echo $suppress_nav; ?>" />
140 <tr><td colspan="2" class="align-center">
141 <strong><?php echo _('Add This Snippet Version ID:'); ?></strong><br />
142 <select name="snippet_version_id">
145 $combolistresult = db_query_params ('SELECT myname,snippet_version.snippet_version_id
146 FROM ( SELECT MAX(post_date) AS
147 mydate,name AS myname,snippet.snippet_id AS myid
149 snippet,snippet_version
151 snippet.snippet_id=snippet_version.snippet_id
153 name,snippet.snippet_id ) AS foo,snippet_version
155 snippet_version.post_date=mydate',array());
156 $combolistrows=db_numrows($combolistresult);
157 for ($i=0; $i<$combolistrows; $i++)
159 print '<option value='.db_result($combolistresult,$i,'snippet_version_id').'>'.db_result($combolistresult,$i,'myname').'</option>';
165 <tr><td colspan="2" class="align-center">
166 <strong><?php echo _('Make sure all info is complete and accurate'); ?></strong>
168 <input type="submit" name="submit" value="<?php echo _('SUBMIT'); ?>" />
173 Show the snippets in this package
175 $result=db_query_params ('SELECT snippet_package_item.snippet_version_id, snippet_version.version, snippet.name
176 FROM snippet,snippet_version,snippet_package_item
177 WHERE snippet.snippet_id=snippet_version.snippet_id
178 AND snippet_version.snippet_version_id=snippet_package_item.snippet_version_id
179 AND snippet_package_item.snippet_package_version_id=$1',
180 array($snippet_package_version_id));
181 $rows=db_numrows($result);
182 if (!$result || $rows < 1) {
185 <p>' ._('No Snippets Are In This Package Yet').'</p>';
187 echo $HTML->boxTop(_('Snippets In This Package'));
188 for ($i=0; $i<$rows; $i++) {
190 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'><td class="align-center">
191 <a href="'.util_make_url ('/snippet/delete.php?type=frompackage&snippet_version_id='.db_result($result,$i,'snippet_version_id').'&snippet_package_version_id='.$snippet_package_version_id).
192 '">' . html_image("ic/trash.png","16","16") . '</a></td><td width="99%">'.
193 db_result($result,$i,'name').' '.db_result($result,$i,'version')."</td></tr>";
195 $last_group=db_result($result,$i,'group_id');
197 echo $HTML->boxBottom();
204 exit_not_logged_in();