3 * Project Admin: Edit Releases of Packages
5 * Copyright 1999-2001 (c) VA Linux Systems
6 * The rest Copyright 2002-2004 (c) GForge Team
11 * This file is part of GForge.
13 * GForge is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * GForge is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with GForge; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 require_once('../../env.inc.php');
30 require_once('pre.php');
31 require_once('common/frs/FRSPackage.class.php');
32 require_once('common/frs/FRSRelease.class.php');
33 require_once('common/frs/FRSFile.class.php');
34 require_once('www/frs/include/frs_utils.php');
36 $group_id = getIntFromRequest('group_id');
37 $package_id = getIntFromRequest('package_id');
38 $release_id = getIntFromRequest('release_id');
42 if (!$package_id || !$release_id) {
43 header("Location: /frs/admin/?group_id=$group_id");
47 $g =& group_get_object($group_id);
48 if (!$g || $g->isError()) {
49 exit_error('Error',$g->getErrorMessage());
51 $perm =& $g->getPermission(session_get_user());
52 if (!$perm->isReleaseTechnician()) {
53 exit_permission_denied();
59 $frsp = new FRSPackage($g,$package_id);
60 if (!$frsp || !is_object($frsp)) {
61 exit_error('Error','Could Not Get FRSPackage');
62 } elseif ($frsp->isError()) {
63 exit_error('Error',$frsp->getErrorMessage());
69 $frsr = new FRSRelease($frsp,$release_id);
70 if (!$frsr || !is_object($frsr)) {
71 exit_error('Error','Could Not Get FRSRelease');
72 } elseif ($frsr->isError()) {
73 exit_error('Error',$frsr->getErrorMessage());
76 //we make sure we are not receiving $sys_ftp_upload_dir by POST or GET, to prevent security problems
77 global $sys_ftp_upload_dir;
78 if (!$sys_ftp_upload_dir) {
79 exit_error('Error','External sys_ftp_upload_dir detected');
81 $upload_dir = $sys_ftp_upload_dir . "/" . $g->getUnixName();
85 * Here's where we do the dirty work based on the step the user has chosen
89 if (getStringFromRequest('step1')) {
90 $release_date = getStringFromRequest('release_date');
91 $release_name = getStringFromRequest('release_name');
92 $status_id = getIntFromRequest('status_id');
93 $uploaded_notes = getUploadedFile('uploaded_notes');
94 $uploaded_changes = getUploadedFile('uploaded_changes');
95 $release_notes = getStringFromRequest('release_notes');
96 $release_changes = getStringFromRequest('release_changes');
97 $preformatted = getStringFromRequest('preformatted');
100 // Check for uploaded release notes
101 if ($uploaded_notes["tmp_name"]) {
102 if (!is_uploaded_file($uploaded_notes['tmp_name'])) {
103 exit_error('Error','Attempted File Upload Attack');
105 $notes = addslashes(fread(fopen($uploaded_notes['tmp_name'],'r'),$uploaded_notes['size']));
106 if (strlen($notes) < 20) {
107 $feedback .= _('Release Notes Are Too Small');
108 $exec_changes = false;
111 $notes = $release_notes;
114 // Check for uploaded change logs
115 if ($uploaded_changes['tmp_name']) {
116 if (!is_uploaded_file($uploaded_changes['tmp_name'])) {
117 exit_error('Error','Attempted File Upload Attack');
119 $changes = addslashes(fread(fopen($uploaded_changes['tmp_name'],'r'), $uploaded_changes['size']));
120 if (strlen($changes) < 20) {
121 $feedback .= _('Change Log Is Too Small');
122 $exec_changes = false;
125 $changes = $release_changes;
128 // If we haven't encountered any problems so far then save the changes
129 if ($exec_changes == true) {
130 //$date_list = split('[- :]',$release_date,5);
131 //$release_date = mktime($date_list[3],$date_list[4],0,$date_list[1],$date_list[2],$date_list[0]);
132 $release_date = strtotime($release_date);
133 if (!$frsr->update($status_id,$release_name,$notes,$changes,$preformatted,$release_date)) {
134 exit_error('Error',$frsr->getErrorMessage());
136 $feedback .= _('Data Saved');
141 // Add file(s) to the release
142 if (getStringFromRequest('step2')) {
143 $userfile = getUploadedFile('userfile');
144 $userfile_name = $userfile['name'];
145 $type_id = getIntFromRequest('type_id');
146 $processor_id = getStringFromRequest('processor_id');
147 // Build a Unix time value from the supplied Y-m-d value
148 $group_unix_name=group_getunixname($group_id);
149 $ftp_filename = getStringFromRequest('ftp_filename');
151 if (($userfile && is_uploaded_file($userfile['tmp_name'])) || ($sys_use_ftpuploads && $ftp_filename)){
152 if ($sys_use_ftpuploads && $ftp_filename && util_is_valid_filename($ftp_filename) && is_file($upload_dir.'/'.$ftp_filename)) {
153 //file was uploaded already via ftp
154 //use setuid prog to chown it
155 //$cmd = escapeshellcmd("$sys_ftp_upload_chowner $ftp_filename");
156 //exec($cmd,$output);
157 $userfile_name=$ftp_filename;
158 $userfile=$upload_dir.'/'.$ftp_filename;
159 //echo $cmd.'***'.$output.'***'.$userfile;
162 // Now create the new FRSFile in the db
164 $frsf = new FRSFile($frsr);
165 if (!$frsf || !is_object($frsf)) {
166 exit_error('Error','Could Not Get FRSFile');
167 } elseif ($frsf->isError()) {
168 exit_error('Error',$frsf->getErrorMessage());
170 if (!$frsf->create($userfile_name,$userfile['tmp_name'],$type_id,$processor_id,$release_date)) {
172 exit_error('Error',$frsf->getErrorMessage());
174 $feedback=_('File Released');
179 // Edit/Delete files in a release
180 if (getStringFromRequest('step3')) {
181 $step3 = getStringFromRequest('step3');
182 $file_id = getIntFromRequest('file_id');
183 $processor_id = getIntFromRequest('processor_id');
184 $type_id = getIntFromRequest('type_id');
185 $new_release_id = getIntFromRequest('new_release_id');
186 $release_time = getStringFromRequest('release_time');
187 $group_id = getIntFromRequest('group_id');
188 $release_id = getIntFromRequest('release_id');
189 $package_id = getIntFromRequest('package_id');
190 $file_id = getIntFromRequest('file_id');
191 $im_sure = getStringFromRequest('im_sure');
193 // If the user chose to delete the file and he's sure then delete the file
194 if( $step3 == "Delete File" ) {
196 $frsf = new FRSFile($frsr,$file_id);
197 if (!$frsf || !is_object($frsf)) {
198 exit_error('Error','Could Not Get FRSFile');
199 } elseif ($frsf->isError()) {
200 exit_error('Error',$frsf->getErrorMessage());
202 if (!$frsf->delete()) {
203 exit_error('Error',$frsf->getErrorMessage());
205 $feedback .= _('File Deleted');
209 exit_error('Error',_('Missing Parameters'));
211 // Otherwise update the file information
213 $frsf = new FRSFile($frsr,$file_id);
214 if (!$frsf || !is_object($frsf)) {
215 exit_error('Error','Could Not Get FRSFile');
216 } elseif ($frsf->isError()) {
217 exit_error('Error',$frsf->getErrorMessage());
219 //$date_list = split('[- :]',$release_time,5);
220 //$release_time = mktime($date_list[3],$date_list[4],0,$date_list[1],$date_list[2],$date_list[0]);
221 $release_time = strtotime($release_time);
222 if (!$frsf->update($type_id,$processor_id,$release_time,$new_release_id)) {
223 exit_error('Error',$frsf->getErrorMessage());
225 $feedback .= _('File Updated');
231 frs_admin_header(array('title'=>_('Edit Releases'),'group'=>$group_id));
233 * Show the forms for each step
237 <h3><?php echo _('Step 1: Edit Release') ?></h3>
239 <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"; ?>">
240 <input type="hidden" name="step1" value="1" />
241 <table border="0" cellpadding="1" cellspacing="1">
243 <td width="10%"><strong><?php echo _('Release date') ?>:<strong></td>
244 <td><input type="text" name="release_date" value="<?php echo date('Y-m-d H:i',$frsr->getReleaseDate()) ?>" size="16" maxlength="16" /></td>
247 <td><strong><?php echo _('Release name') ?>:<strong></td>
248 <td><input type="text" name="release_name" value="<?php echo htmlspecialchars($frsr->getName()); ?>" /></td>
251 <td><strong><?php echo _('Status') ?>:</strong></td>
254 echo frs_show_status_popup('status_id',$frsr->getStatus());
261 <?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.') ?>
265 <td><strong><?php echo _('Upload Release Notes') ?>:</strong></td>
266 <td><input type="file" name="uploaded_notes" size="30" /></td>
269 <td><strong><?php echo _('Upload Change Log') ?>:</strong></td>
270 <td><input type="file" name="uploaded_changes" size="30" /></td>
274 <strong><?php echo _('Paste The Notes In') ?>:</strong><br />
275 <textarea name="release_notes" rows="10" cols="60" wrap="soft"><?php echo $frsr->getNotes(); ?></textarea>
280 <strong><?php echo _('Paste The Change Log In') ?>:</strong><br />
281 <textarea name="release_changes" rows="10" cols="60" wrap="soft"><?php echo $frsr->getChanges(); ?></textarea>
287 <input type="checkbox" name="preformatted" value="1" <?php echo (($frsr->getPreformatted())?'checked="checked"':''); ?> /> <?php echo _('Preserve my pre-formatted text.') ?>
289 <input type="submit" name="submit" value="<?php echo _('Submit/Refresh') ?>"/></p>
296 <h3><?php echo _('Step 2: Add Files To This Release</h3><p>Now, choose a file to upload into the system. The maximum file size is determined by the site administrator, but defaults to 2MB. If you need to upload large files, contact your site administrator.</p>') ?></h3>
298 <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"; ?>">
299 <input type="hidden" name="step2" value="1" />
300 <span class="important">
301 <?php echo _('NOTE: In some browsers you must select the file in the file-upload dialog and click "OK". Double-clicking doesn\'t register the file.') ?></span>
303 <?php echo _('Upload a new file') ?>: <input type="file" name="userfile" size="30" />
304 <?php if ($sys_use_ftpuploads) {
307 printf(_('Alternatively, you can use FTP to upload a new file at %1$s'), $sys_ftp_upload_host).'<br />';
308 echo _('Choose an FTP file instead of uploading:').'<br />';
310 $ftp_files_arr=array_merge($arr,ls($upload_dir,true));
311 echo html_build_select_box_from_arrays($ftp_files_arr,$ftp_files_arr,'ftp_filename','',false); ?>
317 <h4><?php echo _('File Type') ?>:</h4>
319 print frs_show_filetype_popup ('type_id');
323 <h4><?php echo _('Processor Type') ?>:</h4>
325 print frs_show_processor_popup ('processor_id');
331 <input type="submit" name="submit" value="<?php echo _('Add This File') ?>" /></p>
336 <h3><?php echo _('Step 3: Edit Files In This Release') ?></h3>
339 // Get a list of files associated with this release
340 $res=db_query("SELECT * FROM frs_file WHERE release_id='$release_id'");
341 $rows=db_numrows($res);
343 print("<span class=\"error\">"._('No Files In This Release')."</span>\n");
345 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");
346 $title_arr[]=_('Filename<br />Release').'<br />';
347 $title_arr[]=_('Processor<br />Release Date').'<br />';
348 $title_arr[]=_('File Type<br />Update').'<br />';
350 echo $GLOBALS['HTML']->listTableTop ($title_arr);
352 for($x=0; $x<$rows; $x++) {
354 <form action="<?php echo getStringFromServer('PHP_SELF')."?group_id=$group_id&release_id=$release_id&package_id=$package_id"; ?>" method="post">
355 <input type="hidden" name="file_id" value="<?php echo db_result($res,$x,'file_id'); ?>" />
356 <input type="hidden" name="step3" value="1" />
357 <tr <?php echo $HTML->boxGetAltRowStyle($x); ?>>
358 <td nowrap="nowrap"><?php echo db_result($res,$x,'filename'); ?></td>
359 <td><?php echo frs_show_processor_popup ('processor_id', db_result($res,$x,'processor_id')); ?></td>
360 <td><?php echo frs_show_filetype_popup ('type_id', db_result($res,$x,'type_id')); ?></td>
362 <tr <?php echo $HTML->boxGetAltRowStyle($x); ?>>
363 file:///usr/share/ubuntu-artwork/home/index.html <td>
365 <?php echo frs_show_release_popup ($group_id, $name='new_release_id',db_result($res,$x,'release_id')); ?>
370 <input type="text" name="release_time" value="<?php echo date('Y-m-d',db_result($res,$x,'release_time')); ?>" size="10" maxlength="10" />
373 <td><input type="submit" name="submit" value="<?php echo _('Update/Refresh') ?> " /></td>
377 <form action="<?php echo getStringFromServer('PHP_SELF'); ?>" method="post">
378 <input type="hidden" name="group_id" value="<?php echo $group_id; ?>" />
379 <input type="hidden" name="release_id" value="<?php echo $release_id; ?>" />
380 <input type="hidden" name="package_id" value="<?php echo $package_id; ?>" />
381 <input type="hidden" name="file_id" value="<?php echo db_result($res,$x,'file_id'); ?>" />
382 <input type="hidden" name="step3" value="Delete File" />
383 <tr <?php echo $HTML->boxGetAltRowStyle($x); ?>>
388 <input type="submit" name="submit" value="<?php echo _('Delete File') ?> " /> <input type="checkbox" name="im_sure" value="1" /> <?php echo _('I\'m Sure') ?>
395 echo $GLOBALS['HTML']->listTableBottom();
398 echo '<br />'.sprintf(_('There are %1$s users monitoring this package.'), $frsp->getMonitorCount());
405 // c-file-style: "bsd"