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
15 require_once('../env.inc.php');
16 require_once $gfwww.'include/pre.php';
17 require_once $gfwww.'snippet/snippet_utils.php';
19 $suppress_nav = getStringFromRequest('suppress_nav');
21 function handle_add_exit() {
27 snippet_footer(array());
32 if (session_loggedin()) {
33 $snippet_package_version_id = getIntFromRequest('snippet_package_version_id');
34 $snippet_version_id = getIntFromRequest('snippet_version_id');
41 snippet_header(array('title'=>_('Submit A New Snippet')));
44 if (!$snippet_package_version_id) {
45 //make sure the package id was passed in
46 echo '<h1>' ._('Error - snippet_package_version_id missing') .'</h1>';
50 if (getStringFromRequest('post_changes')) {
52 Create a new snippet entry, then create a new snippet version entry
54 if ($snippet_package_version_id && $snippet_version_id) {
56 check to see if they are the creator of this version
58 $result=db_query("SELECT * FROM snippet_package_version ".
59 "WHERE submitted_by='".user_getid()."' AND ".
60 "snippet_package_version_id='$snippet_package_version_id'");
61 if (!$result || db_numrows($result) < 1) {
62 echo '<h1>' ._('Error - Only the creator of a package version can add snippets to it.').'</h1>';
67 make sure the snippet_version_id exists
69 $result=db_query("SELECT * FROM snippet_version WHERE snippet_version_id='$snippet_version_id'");
70 if (!$result || db_numrows($result) < 1) {
71 echo '<h1>' ._('Error - That snippet doesn\'t exist.').'</h1>';
72 echo util_make_link ('/snippet/add_snippet_to_package.php?snippet_package_version_id='.$snippet_package_version_id,_('Back To Add Page'));
77 make sure the snippet_version_id isn't already in this package
79 $result=db_query("SELECT * FROM snippet_package_item ".
80 "WHERE snippet_package_version_id='$snippet_package_version_id' ".
81 "AND snippet_version_id='$snippet_version_id'");
82 if ($result && db_numrows($result) > 0) {
83 echo '<h1>'._('Error - That snippet was already added to this package.').'</h1>';
84 echo util_make_url ('/snippet/add_snippet_to_package.php?snippet_package_version_id='.$snippet_package_version_id,_('Back To Add Page'));
89 create the snippet version
91 $sql="INSERT INTO snippet_package_item (snippet_package_version_id,snippet_version_id) ".
92 "VALUES ('$snippet_package_version_id','$snippet_version_id')";
93 $result=db_query($sql);
96 $feedback .= _('ERROR DOING SNIPPET VERSION INSERT!');
99 $feedback .= _('Snippet Version Added Successfully.');
102 echo '<h1>' ._('Error - Go back and fill in all the information').'</h1>';
103 echo util_make_link ('/snippet/add_snippet_to_package.php?snippet_package_version_id='.$snippet_package_version_id,_('Back To Add Page'));
109 $result=db_query("SELECT snippet_package.name,snippet_package_version.version ".
110 "FROM snippet_package,snippet_package_version ".
111 "WHERE snippet_package.snippet_package_id=snippet_package_version.snippet_package_id ".
112 "AND snippet_package_version.snippet_package_version_id='$snippet_package_version_id'");
116 <strong><?php echo _('Package:'); ?></strong><br />
117 <?php echo db_result($result,0,'name') . ' - ' . db_result($result,0,'version'); ?></p>
118 <p><?php echo _('You can use this form repeatedly to keep adding snippets to your package.</p><p>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>
120 <form action="<?php echo getStringFromServer('PHP_SELF'); ?>" method="post">
121 <input type="hidden" name="post_changes" value="y" />
122 <input type="hidden" name="snippet_package_version_id" value="<?php echo $snippet_package_version_id; ?>" />
123 <input type="hidden" name="suppress_nav" value="<?php echo $suppress_nav; ?>" />
126 <tr><td colspan="2" style="text-align:center">
127 <strong><?php echo _('Add This Snippet Version ID:'); ?></strong><br />
128 <select name="snippet_version_id">
131 $combolistresult=db_query
132 ("SELECT myname,snippet_version.snippet_version_id
133 FROM ( SELECT MAX(post_date) AS
134 mydate,name AS myname,snippet.snippet_id AS myid
136 snippet,snippet_version
138 snippet.snippet_id=snippet_version.snippet_id
140 name,snippet.snippet_id ) AS foo,snippet_version
142 snippet_version.post_date=mydate;");
143 $combolistrows=db_numrows($combolistresult);
144 for ($i=0; $i<$combolistrows; $i++)
146 print '<option value='.db_result($combolistresult,$i,'snippet_version_id').'>'.db_result($combolistresult,$i,'myname').'</option>';
152 <tr><td colspan="2" style="text-align:center">
153 <strong><?php echo _('Make sure all info is complete and accurate'); ?></strong>
155 <input type="submit" name="submit" value="<?php echo _('SUBMIT'); ?>" />
160 Show the snippets in this package
162 $result=db_query("SELECT snippet_package_item.snippet_version_id, snippet_version.version, snippet.name ".
163 "FROM snippet,snippet_version,snippet_package_item ".
164 "WHERE snippet.snippet_id=snippet_version.snippet_id ".
165 "AND snippet_version.snippet_version_id=snippet_package_item.snippet_version_id ".
166 "AND snippet_package_item.snippet_package_version_id='$snippet_package_version_id'");
167 $rows=db_numrows($result);
168 if (!$result || $rows < 1) {
171 <p>' ._('No Snippets Are In This Package Yet').'</p>';
173 echo $HTML->boxTop(_('Snippets In This Package'));
174 for ($i=0; $i<$rows; $i++) {
176 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'><td style="text-align:center">
177 <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).
178 '">' . html_image("ic/trash.png","16","16",array("border"=>"0")) . '</a></td><td width="99%">'.
179 db_result($result,$i,'name').' '.db_result($result,$i,'version')."</td></tr>";
181 $last_group=db_result($result,$i,'group_id');
183 echo $HTML->boxBottom();
190 exit_not_logged_in();