3 * Project Admin: Edit Releases of Packages
5 * Copyright 1999-2001 (c) VA Linux Systems
6 * The rest Copyright 2002-2004 (c) GForge Team
9 * This file is part of GForge.
11 * GForge is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * GForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with GForge; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 require_once('../../env.inc.php');
28 require_once $gfcommon.'include/pre.php';
29 require_once $gfcommon.'frs/FRSPackage.class.php';
30 require_once $gfcommon.'frs/FRSRelease.class.php';
31 require_once $gfcommon.'frs/FRSFile.class.php';
32 require_once $gfwww.'frs/include/frs_utils.php';
34 $group_id = getIntFromRequest('group_id');
35 $package_id = getIntFromRequest('package_id');
36 $release_id = getIntFromRequest('release_id');
40 if (!$package_id || !$release_id) {
41 header("Location: /frs/admin/?group_id=$group_id");
45 $group=group_get_object($group_id);
46 if (!$group || !is_object($group)) {
48 } elseif ($group->isError()) {
49 exit_error('Error', $group->getErrorMessage());
51 session_require_perm ('frs', $group_id, 'write') ;
56 $frsp = new FRSPackage($group,$package_id);
57 if (!$frsp || !is_object($frsp)) {
58 exit_error('Error','Could Not Get FRSPackage');
59 } elseif ($frsp->isError()) {
60 exit_error('Error',$frsp->getErrorMessage());
66 $frsr = new FRSRelease($frsp,$release_id);
67 if (!$frsr || !is_object($frsr)) {
68 exit_error('Error','Could Not Get FRSRelease');
69 } elseif ($frsr->isError()) {
70 exit_error('Error',$frsr->getErrorMessage());
73 $upload_dir = forge_get_config('ftp_upload_dir') . "/" . $g->getUnixName();
77 * Here's where we do the dirty work based on the step the user has chosen
81 if (getStringFromRequest('step1')) {
82 $release_date = getStringFromRequest('release_date');
83 $release_name = getStringFromRequest('release_name');
84 $status_id = getIntFromRequest('status_id');
85 $uploaded_notes = getUploadedFile('uploaded_notes');
86 $uploaded_changes = getUploadedFile('uploaded_changes');
87 $release_notes = getStringFromRequest('release_notes');
88 $release_changes = getStringFromRequest('release_changes');
89 $preformatted = getStringFromRequest('preformatted');
92 // Check for uploaded release notes
93 if ($uploaded_notes["tmp_name"]) {
94 if (!is_uploaded_file($uploaded_notes['tmp_name'])) {
95 exit_error('Error','Attempted File Upload Attack');
97 if ($uploaded_notes['type'] !== 'text/plain') {
98 $error_msg .= _('Release Notes Are not in Text').'<br />';
99 $exec_changes = false;
101 $notes = addslashes(fread(fopen($uploaded_notes['tmp_name'],'r'),$uploaded_notes['size']));
102 if (strlen($notes) < 20) {
103 $error_msg .= _('Release Notes Are Too Small').'<br />';
104 $exec_changes = false;
108 $notes = $release_notes;
111 // Check for uploaded change logs
112 if ($uploaded_changes['tmp_name']) {
113 if (!is_uploaded_file($uploaded_changes['tmp_name'])) {
114 exit_error('Error','Attempted File Upload Attack');
116 if ($uploaded_changes['type'] !== 'text/plain') {
117 $error_msg .= _('Change Log Is not in Text').'<br />';
118 $exec_changes = false;
120 $changes = addslashes(fread(fopen($uploaded_changes['tmp_name'],'r'), $uploaded_changes['size']));
121 if (strlen($changes) < 20) {
122 $error_msg .= _('Change Log Is Too Small').'<br />';
123 $exec_changes = false;
127 $changes = $release_changes;
130 // If we haven't encountered any problems so far then save the changes
131 if ($exec_changes == true) {
132 //$date_list = split('[- :]',$release_date,5);
133 //$release_date = mktime($date_list[3],$date_list[4],0,$date_list[1],$date_list[2],$date_list[0]);
134 $release_date = strtotime($release_date);
135 if (!$frsr->update($status_id,$release_name,$notes,$changes,$preformatted,$release_date)) {
136 exit_error('Error',$frsr->getErrorMessage());
138 $feedback .= _('Data Saved');
143 // Add file(s) to the release
144 if (getStringFromRequest('step2')) {
145 $userfile = getUploadedFile('userfile');
146 $userfile_name = $userfile['name'];
147 $type_id = getIntFromRequest('type_id');
148 $release_date = getStringFromRequest('release_date');
149 // Build a Unix time value from the supplied Y-m-d value
150 $release_date = strtotime($release_date);
151 $processor_id = getStringFromRequest('processor_id');
152 $group_unix_name=group_getunixname($group_id);
153 $ftp_filename = getStringFromRequest('ftp_filename');
154 $manual_filename = getStringFromRequest('manual_filename');
156 $ret = frs_add_file_from_form ($frsr, $type_id, $processor_id, $release_date,
157 $userfile, $ftp_filename, $manual_filename) ;
159 $feedback = _('File Released') ;
166 // Edit/Delete files in a release
167 if (getStringFromRequest('step3')) {
168 $step3 = getStringFromRequest('step3');
169 $file_id = getIntFromRequest('file_id');
170 $processor_id = getIntFromRequest('processor_id');
171 $type_id = getIntFromRequest('type_id');
172 $new_release_id = getIntFromRequest('new_release_id');
173 $release_time = getStringFromRequest('release_time');
174 $group_id = getIntFromRequest('group_id');
175 $release_id = getIntFromRequest('release_id');
176 $package_id = getIntFromRequest('package_id');
177 $file_id = getIntFromRequest('file_id');
178 $im_sure = getStringFromRequest('im_sure');
180 // If the user chose to delete the file and he's sure then delete the file
181 if( $step3 == "Delete File" ) {
183 $frsf = new FRSFile($frsr,$file_id);
184 if (!$frsf || !is_object($frsf)) {
185 exit_error('Error','Could Not Get FRSFile');
186 } elseif ($frsf->isError()) {
187 exit_error('Error',$frsf->getErrorMessage());
189 if (!$frsf->delete()) {
190 exit_error('Error',$frsf->getErrorMessage());
192 $feedback .= _('File Deleted');
196 $error_msg .= _('File not deleted: you did not check "I\'m Sure"');
198 // Otherwise update the file information
200 $frsf = new FRSFile($frsr,$file_id);
201 if (!$frsf || !is_object($frsf)) {
202 exit_error('Error','Could Not Get FRSFile');
203 } elseif ($frsf->isError()) {
204 exit_error('Error',$frsf->getErrorMessage());
206 //$date_list = split('[- :]',$release_time,5);
207 //$release_time = mktime($date_list[3],$date_list[4],0,$date_list[1],$date_list[2],$date_list[0]);
208 $release_time = strtotime($release_time);
209 if (!$frsf->update($type_id,$processor_id,$release_time,$new_release_id)) {
210 exit_error('Error',$frsf->getErrorMessage());
212 $feedback .= _('File Updated');
218 frs_admin_header(array('title'=>_('Edit Releases'),'group'=>$group_id));
220 * Show the forms for each step
224 <h2><?php echo _('Step 1: Edit Release') ?></h2>
226 <form enctype="multipart/form-data" method="post" action="<?php echo getStringFromServer('PHP_SELF')."?group_id=$group_id&release_id=$release_id&package_id=$package_id"; ?>">
227 <input type="hidden" name="step1" value="1" />
228 <table border="0" cellpadding="1" cellspacing="1">
230 <td width="10%"><strong><?php echo _('Release date') ?>:</strong></td>
231 <td><input type="text" name="release_date" value="<?php echo date('Y-m-d H:i',$frsr->getReleaseDate()) ?>" size="16" maxlength="16" /></td>
234 <td><strong><?php echo _('Release name') ?>:</strong></td>
235 <td><input type="text" name="release_name" value="<?php echo htmlspecialchars($frsr->getName()); ?>" /></td>
238 <td><strong><?php echo _('Status') ?></strong></td>
241 echo frs_show_status_popup('status_id',$frsr->getStatus());
248 <?php echo _('Edit the Release Notes or Change Log for this release of this package. These changes will apply to all files attached to this release.<br />You can either upload the release notes and change log individually, or paste them in together below.') ?>
252 <td><strong><?php echo _('Upload Release Notes') ?>:</strong></td>
253 <td><input type="file" name="uploaded_notes" size="30" /></td>
256 <td><strong><?php echo _('Upload Change Log') ?>:</strong></td>
257 <td><input type="file" name="uploaded_changes" size="30" /></td>
261 <strong><?php echo _('Paste The Notes In') ?>:</strong><br />
262 <textarea name="release_notes" rows="10" cols="60"><?php echo $frsr->getNotes(); ?></textarea>
267 <strong><?php echo _('Paste The Change Log In') ?>:</strong><br />
268 <textarea name="release_changes" rows="10" cols="60"><?php echo $frsr->getChanges(); ?></textarea>
274 <input type="checkbox" name="preformatted" value="1" <?php echo (($frsr->getPreformatted())?'checked="checked"':''); ?> /> <?php echo _('Preserve my pre-formatted text.') ?>
276 <input type="submit" name="submit" value="<?php echo _('Submit/Refresh') ?>"/>
284 <h2><?php echo _('Step 2: Add Files To This Release') ?></h2>
285 <p><?php echo _('Now, choose a file to upload into the system.') ?></p>
287 <form enctype="multipart/form-data" method="post" action="<?php echo getStringFromServer('PHP_SELF')."?group_id=$group_id&release_id=$release_id&package_id=$package_id"; ?>">
288 <input type="hidden" name="step2" value="1" />
289 <fieldset><legend><strong><?php echo _("File Name") ?></strong></legend>
290 <?php echo _("Upload a new file") ?>: <input type="file" name="userfile" size="30" />
291 <?php if (forge_get_config('use_ftp_uploads')) {
293 printf(_('Alternatively, you can use FTP to upload a new file at %1$s.'), forge_get_config('ftp_upload_host'));
295 echo _('Choose an already uploaded file:').'<br />';
296 $ftp_files_arr=ls($upload_dir,true);
297 echo html_build_select_box_from_arrays($ftp_files_arr,$ftp_files_arr,'ftp_filename',''); ?>
301 <?php if (forge_get_config('use_manual_uploads')) {
302 $incoming = forge_get_config('groupdir_prefix')."/".$g->getUnixName()."/incoming" ;
305 printf(_('Alternatively, you can use a file you already uploaded (by SFTP or SCP) to the <a href="%2$s">project\'s incoming directory</a> (%1$s).'),
306 $incoming, "sftp://" . forge_get_config ('web_host') . $incoming . "/");
307 echo ' ' . _('This direct <tt>sftp://</tt> link only works with some browsers, such as Konqueror.') . '<br />';
308 echo _('Choose an already uploaded file:').'<br />';
309 $manual_files_arr=ls($incoming,true);
310 echo html_build_select_box_from_arrays($manual_files_arr,$manual_files_arr,'manual_filename',''); ?>
317 <strong><?php echo _('File Type') ?>:</strong>
319 print frs_show_filetype_popup ('type_id');
323 <strong><?php echo _('Processor Type') ?>:</strong>
325 print frs_show_processor_popup ('processor_id');
331 <input type="submit" name="submit" value="<?php echo _('Add This File') ?>" /></p>
334 <h2><?php echo _('Step 3: Edit Files In This Release') ?></h2>
337 // Get a list of files associated with this release
338 $res=db_query_params ('SELECT * FROM frs_file WHERE release_id=$1',
340 $rows=db_numrows($res);
342 print("<span class=\"error\">"._('No Files In This Release')."</span>\n");
344 print(_('Once you have added files to this release you <strong>must</strong> update each of these files with the correct information or they will not appear on your download summary page.')."\n");
345 $title_arr[]=_('Filename<br />Release').'<br />';
346 $title_arr[]=_('Processor<br />Release Date').'<br />';
347 $title_arr[]=_('File Type<br />Update').'<br />';
349 echo $GLOBALS['HTML']->listTableTop ($title_arr);
351 for($x=0; $x<$rows; $x++) {
353 <form action="<?php echo getStringFromServer('PHP_SELF')."?group_id=$group_id&release_id=$release_id&package_id=$package_id"; ?>" method="post">
354 <input type="hidden" name="file_id" value="<?php echo db_result($res,$x,'file_id'); ?>" />
355 <input type="hidden" name="step3" value="1" />
356 <tr <?php echo $HTML->boxGetAltRowStyle($x); ?>>
357 <td style="white-space: nowrap;"><?php echo db_result($res,$x,'filename'); ?></td>
358 <td><?php echo frs_show_processor_popup ('processor_id', db_result($res,$x,'processor_id')); ?></td>
359 <td><?php echo frs_show_filetype_popup ('type_id', db_result($res,$x,'type_id')); ?></td>
361 <tr <?php echo $HTML->boxGetAltRowStyle($x); ?>>
364 <?php echo frs_show_release_popup ($group_id, $name='new_release_id',db_result($res,$x,'release_id')); ?>
369 <input type="text" name="release_time" value="<?php echo date('Y-m-d',db_result($res,$x,'release_time')); ?>" size="10" maxlength="10" />
372 <td><input type="submit" name="submit" value="<?php echo _('Update/Refresh') ?> " /></td>
376 <form action="<?php echo getStringFromServer('PHP_SELF'); ?>" method="post">
377 <input type="hidden" name="group_id" value="<?php echo $group_id; ?>" />
378 <input type="hidden" name="release_id" value="<?php echo $release_id; ?>" />
379 <input type="hidden" name="package_id" value="<?php echo $package_id; ?>" />
380 <input type="hidden" name="file_id" value="<?php echo db_result($res,$x,'file_id'); ?>" />
381 <input type="hidden" name="step3" value="Delete File" />
382 <tr <?php echo $HTML->boxGetAltRowStyle($x); ?>>
387 <input type="submit" name="submit" value="<?php echo _('Delete File') ?> " /> <input type="checkbox" name="im_sure" value="1" /> <?php echo _('I\'m Sure') ?>
394 echo $GLOBALS['HTML']->listTableBottom();
397 echo '<p>' . sprintf(ngettext('There is %1$s user monitoring this package.', 'There are %1$s users monitoring this package.', $frsp->getMonitorCount()), $frsp->getMonitorCount()) . '</p>';
404 // c-file-style: "bsd"