4 * SourceForge Code Snippets Repository
6 * SourceForge: Breaking Down the Barriers to Open Source Development
7 * Copyright 1999-2001 (c) VA Linux Systems
8 * http://sourceforge.net
13 require_once('../env.inc.php');
14 require_once $gfwww.'include/pre.php';
15 require_once $gfwww.'snippet/snippet_utils.php';
17 if (session_loggedin()) {
18 $type = getStringFromRequest('type');
19 $id = getIntFromRequest('id');
21 if ($type=='snippet') {
23 See if the snippet exists first
25 $result=db_query("SELECT * FROM snippet WHERE snippet_id='$id'");
26 if (!$result || db_numrows($result) < 1) {
27 exit_error(_('Error - snippet doesn\'t exist'));
31 handle inserting a new version of a snippet
33 if (getStringFromRequest('post_changes')) {
34 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
35 exit_form_double_submit();
38 $snippet_id = getStringFromRequest('snippet_id');
39 $changes = getStringFromRequest('changes');
40 $version = getStringFromRequest('version');
41 $code = getStringFromRequest('code');
44 Create a new snippet entry, then create a new snippet version entry
46 if ($changes && $version && $code) {
49 create the snippet version
51 $sql="INSERT INTO snippet_version (snippet_id,changes,version,submitted_by,post_date,code) ".
52 "VALUES ('$snippet_id','".htmlspecialchars($changes)."','".
53 htmlspecialchars($version)."','".user_getid()."','".
54 time()."','".htmlspecialchars($code)."')";
55 $result=db_query($sql);
57 $feedback .= _('ERROR DOING SNIPPET VERSION INSERT!');
60 form_release_key(getStringFromRequest("form_key"));
61 $feedback .= _('Snippet Version Added Successfully.');
64 exit_error(_('Error'),_('Error - Go back and fill in all the information'));
68 snippet_header(array('title'=>_('New snippet version')));
71 <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>
73 <form action="<?php echo getStringFromServer('PHP_SELF'); ?>" method="post">
74 <input type="hidden" name="form_key" value="<?php echo form_generate_key(); ?>">
75 <input type="hidden" name="post_changes" value="y" />
76 <input type="hidden" name="type" value="snippet" />
77 <input type="hidden" name="snippet_id" value="<?php echo $id; ?>" />
78 <input type="hidden" name="id" value="<?php echo $id; ?>" />
81 <tr><td colspan="2"><strong><?php echo _('Version:'); ?></strong><br />
82 <input type="text" name="version" size="10" maxlength="15" />
85 <tr><td colspan="2"><strong><?php echo _('Changes:'); ?></strong><br />
86 <textarea name="changes" rows="5" cols="45"></textarea>
89 <tr><td colspan="2"><strong><?php echo _('Paste the Code Here:'); ?></strong><br />
90 <textarea name="code" rows="30" cols="85" wrap="soft"></textarea>
93 <tr><td colspan="2" style="text-align:center">
94 <strong><?php echo _('Make sure all info is complete and accurate'); ?></strong>
96 <input type="submit" name="submit" value="<?php echo _('SUBMIT'); ?>" />
101 snippet_footer(array());
103 } else if ($type=='package') {
105 Handle insertion of a new package version
109 See if the package exists first
111 $result=db_query("SELECT * FROM snippet_package WHERE snippet_package_id='$id'");
112 if (!$result || db_numrows($result) < 1) {
113 exit_error(_('Error - snippet_package doesn\'t exist'));
116 if (getStringFromRequest('post_changes')) {
117 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
118 exit_form_double_submit();
121 $snippet_package_id = getIntFromRequest('snippet_package_id');
122 $changes = getStringFromRequest('changes');
123 $version = getStringFromRequest('version');
126 Create a new snippet entry, then create a new snippet version entry
128 if ($changes && $snippet_package_id) {
130 create the snippet package version
132 $sql="INSERT INTO snippet_package_version ".
133 "(snippet_package_id,changes,version,submitted_by,post_date) ".
134 "VALUES ('$snippet_package_id','".htmlspecialchars($changes)."','".
135 htmlspecialchars($version)."','".user_getid()."','".time()."')";
136 $result=db_query($sql);
139 $feedback .= _('ERROR DOING SNIPPET PACKAGE VERSION INSERT!');
140 snippet_header(array('title'=>_('New snippet package')));
142 snippet_footer(array());
145 //so far so good - now add snippets to the package
146 $feedback .= _('Snippet Package Version Added Successfully.');
148 //id for this snippet_package_version
149 $snippet_package_version_id=
150 db_insertid($result,'snippet_package_version','snippet_package_version_id');
151 snippet_header(array('title'=>_('Add snippet to package')));
154 This raw HTML allows the user to add snippets to the package
158 <script type="text/javascript">
160 function show_add_snippet_box() {
161 newWindow = open("","occursDialog","height=500,width=300,scrollbars=yes,resizable=yes");
162 newWindow.location=('/snippet/add_snippet_to_package.php?snippet_package_version_id=<?php
163 echo $snippet_package_version_id; ?>');
167 <body onLoad="show_add_snippet_box()">
169 <p><span class="important"><?php echo _('IMPORTANT!'); ?></span></p>
171 <?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.'); ?>
174 <?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>
175 <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>
180 snippet_footer(array());
185 form_release_key(getStringFromRequest("form_key"));
186 exit_error( _('Error - Go back and fill in all the information'));
190 snippet_header(array('title'=>_('New snippet version')));
195 <?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>
197 <form action="<?php echo getStringFromServer('PHP_SELF'); ?>" method="post">
198 <input type="hidden" name="form_key" value="<?php echo form_generate_key(); ?>">
199 <input type="hidden" name="post_changes" value="y" />
200 <input type="hidden" name="type" value="package" />
201 <input type="hidden" name="snippet_package_id" value="<?php echo $id; ?>" />
202 <input type="hidden" name="id" value="<?php echo $id; ?>" />
205 <tr><td colspan="2"><strong><?php echo _('Version:'); ?></strong><br />
206 <input type="text" name="version" size="10" maxlength="15" />
209 <tr><td colspan="2"><strong><?php echo _('Changes:'); ?></strong><br />
210 <textarea name="changes" rows="5" cols="45"></textarea>
213 <tr><td colspan="2" style="text-align:center">
214 <strong><?php echo _('Make sure all info is complete and accurate'); ?></strong>
216 <input type="submit" name="submit" value="<?php echo _('SUBMIT'); ?>" />
221 snippet_footer(array());
225 exit_error(_('Error - was the URL or form mangled??'));
230 exit_not_logged_in();
236 // c-file-style: "bsd"