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';
28 if (session_loggedin()) {
29 $type = getStringFromRequest('type');
30 $id = getIntFromRequest('id');
32 if ($type=='snippet') {
34 See if the snippet exists first
36 $result=db_query_params ('SELECT * FROM snippet WHERE snippet_id=$1',
38 if (!$result || db_numrows($result) < 1) {
39 exit_error(_('Error - snippet doesn\'t exist'));
43 handle inserting a new version of a snippet
45 if (getStringFromRequest('post_changes')) {
46 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
47 exit_form_double_submit();
50 $snippet_id = getIntFromRequest('snippet_id');
51 $changes = getStringFromRequest('changes');
52 $version = getStringFromRequest('version');
53 $code = getStringFromRequest('code');
56 Create a new snippet entry, then create a new snippet version entry
58 if ($changes && $version && $code) {
61 create the snippet version
63 $result = db_query_params ('INSERT INTO snippet_version (snippet_id,changes,version,submitted_by,post_date,code) VALUES ($1,$2,$3,$4,$5,$6)',
65 htmlspecialchars($changes),
66 htmlspecialchars($version),
69 htmlspecialchars($code)));
71 $error_msg .= _('ERROR DOING SNIPPET VERSION INSERT! ').db_error();
73 form_release_key(getStringFromRequest("form_key"));
74 $feedback .= _('Snippet Version Added Successfully.');
77 exit_error(_('Error - Go back and fill in all the information'));
81 snippet_header(array('title'=>_('New snippet version')));
84 <p><?php echo _('If you have modified a version of a snippet and you feel it is significant enough to share with others, please do so.'); ?></p>
86 <form action="<?php echo getStringFromServer('PHP_SELF'); ?>" method="post">
87 <input type="hidden" name="form_key" value="<?php echo form_generate_key(); ?>">
88 <input type="hidden" name="post_changes" value="y" />
89 <input type="hidden" name="type" value="snippet" />
90 <input type="hidden" name="snippet_id" value="<?php echo $id; ?>" />
91 <input type="hidden" name="id" value="<?php echo $id; ?>" />
94 <tr><td colspan="2"><strong><?php echo _('Version:'); ?></strong><br />
95 <input type="text" name="version" size="10" maxlength="15" />
98 <tr><td colspan="2"><strong><?php echo _('Changes:'); ?></strong><br />
99 <textarea name="changes" rows="5" cols="45"></textarea>
102 <tr><td colspan="2"><strong><?php echo _('Paste the Code Here:'); ?></strong><br />
103 <textarea name="code" rows="30" cols="85"></textarea>
106 <tr><td colspan="2" style="text-align:center">
107 <strong><?php echo _('Make sure all info is complete and accurate'); ?></strong>
109 <input type="submit" name="submit" value="<?php echo _('SUBMIT'); ?>" />
114 snippet_footer(array());
116 } else if ($type=='package') {
118 Handle insertion of a new package version
122 See if the package exists first
124 $result=db_query_params ('SELECT * FROM snippet_package WHERE snippet_package_id=$1',
126 if (!$result || db_numrows($result) < 1) {
127 exit_error(_('Error - snippet_package doesn\'t exist'));
130 if (getStringFromRequest('post_changes')) {
131 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
132 exit_form_double_submit();
135 $snippet_package_id = getIntFromRequest('snippet_package_id');
136 $changes = getStringFromRequest('changes');
137 $version = getStringFromRequest('version');
140 Create a new snippet entry, then create a new snippet version entry
142 if ($changes && $snippet_package_id) {
144 create the snippet package version
146 $result = db_query_params ('INSERT INTO snippet_package_version (snippet_package_id,changes,version,submitted_by,post_date) VALUES ($1,$2,$3,$4,$5)',
147 array ($snippet_package_id,
148 htmlspecialchars($changes),
149 htmlspecialchars($version),
154 $error_msg .= _('ERROR DOING SNIPPET PACKAGE VERSION INSERT! ').db_error();
155 snippet_header(array('title'=>_('New snippet package')));
156 snippet_footer(array());
159 //so far so good - now add snippets to the package
160 $feedback .= _('Snippet Package Version Added Successfully.');
162 //id for this snippet_package_version
163 $snippet_package_version_id=
164 db_insertid($result,'snippet_package_version','snippet_package_version_id');
165 snippet_header(array('title'=>_('Add snippet to package')));
168 This raw HTML allows the user to add snippets to the package
172 <script type="text/javascript">
174 function show_add_snippet_box() {
175 newWindow = open("","occursDialog","height=500,width=300,scrollbars=yes,resizable=yes");
176 newWindow.location=('/snippet/add_snippet_to_package.php?snippet_package_version_id=<?php
177 echo $snippet_package_version_id; ?>');
181 <body onLoad="show_add_snippet_box()">
183 <p><span class="important"><?php echo _('IMPORTANT!'); ?></span></p>
185 <?php echo _('If a new window opened, use it to add snippets to your package. If a new window did not open, use the following link to add to your package BEFORE you leave this page.'); ?>
188 <?php echo util_make_url ('/snippet/add_snippet_to_package.php?snippet_package_version_id='.$snippet_package_version_id,_('Add snippets to package'),array('target'=>'_blank')); ?></p>
189 <p><?php echo _('<strong>Browse the library</strong> to find the snippets you want to add, then add them using the new window link shown above.'); ?></p>
194 snippet_footer(array());
199 form_release_key(getStringFromRequest("form_key"));
200 exit_error( _('Error - Go back and fill in all the information'));
204 snippet_header(array('title'=>_('New snippet version')));
209 <?php echo _('If you have modified a version of a package and you feel it is significant enough to share with others, please do so.'); ?></p>
211 <form action="<?php echo getStringFromServer('PHP_SELF'); ?>" method="post">
212 <input type="hidden" name="form_key" value="<?php echo form_generate_key(); ?>">
213 <input type="hidden" name="post_changes" value="y" />
214 <input type="hidden" name="type" value="package" />
215 <input type="hidden" name="snippet_package_id" value="<?php echo $id; ?>" />
216 <input type="hidden" name="id" value="<?php echo $id; ?>" />
219 <tr><td colspan="2"><strong><?php echo _('Version:'); ?></strong><br />
220 <input type="text" name="version" size="10" maxlength="15" />
223 <tr><td colspan="2"><strong><?php echo _('Changes:'); ?></strong><br />
224 <textarea name="changes" rows="5" cols="45"></textarea>
227 <tr><td colspan="2" style="text-align:center">
228 <strong><?php echo _('Make sure all info is complete and accurate'); ?></strong>
230 <input type="submit" name="submit" value="<?php echo _('SUBMIT'); ?>" />
235 snippet_footer(array());
239 exit_error(_('Error - was the URL or form mangled??'));
244 exit_not_logged_in();
250 // c-file-style: "bsd"