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 $gfwww.'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 $g =& group_get_object($group_id);
46 if (!$g || $g->isError()) {
47 exit_error('Error',$g->getErrorMessage());
49 $perm =& $g->getPermission(session_get_user());
50 if (!$perm->isReleaseTechnician()) {
51 exit_permission_denied();
57 $frsp = new FRSPackage($g,$package_id);
58 if (!$frsp || !is_object($frsp)) {
59 exit_error('Error','Could Not Get FRSPackage');
60 } elseif ($frsp->isError()) {
61 exit_error('Error',$frsp->getErrorMessage());
67 $frsr = new FRSRelease($frsp,$release_id);
68 if (!$frsr || !is_object($frsr)) {
69 exit_error('Error','Could Not Get FRSRelease');
70 } elseif ($frsr->isError()) {
71 exit_error('Error',$frsr->getErrorMessage());
74 //we make sure we are not receiving $sys_ftp_upload_dir by POST or GET, to prevent security problems
75 global $sys_ftp_upload_dir;
76 if (!$sys_ftp_upload_dir) {
77 exit_error('Error','External sys_ftp_upload_dir detected');
79 $upload_dir = $sys_ftp_upload_dir . "/" . $g->getUnixName();
83 * Here's where we do the dirty work based on the step the user has chosen
87 if (getStringFromRequest('step1')) {
88 $release_date = getStringFromRequest('release_date');
89 $release_name = getStringFromRequest('release_name');
90 $status_id = getIntFromRequest('status_id');
91 $uploaded_notes = getUploadedFile('uploaded_notes');
92 $uploaded_changes = getUploadedFile('uploaded_changes');
93 $release_notes = getStringFromRequest('release_notes');
94 $release_changes = getStringFromRequest('release_changes');
95 $preformatted = getStringFromRequest('preformatted');
98 // Check for uploaded release notes
99 if ($uploaded_notes["tmp_name"]) {
100 if (!is_uploaded_file($uploaded_notes['tmp_name'])) {
101 exit_error('Error','Attempted File Upload Attack');
103 if ($uploaded_notes['type'] !== 'text/plain') {
104 $feedback .= _('Release Notes Are not in Text');
105 $exec_changes = false;
107 $notes = addslashes(fread(fopen($uploaded_notes['tmp_name'],'r'),$uploaded_notes['size']));
108 if (strlen($notes) < 20) {
109 $feedback .= _('Release Notes Are Too Small');
110 $exec_changes = false;
114 $notes = $release_notes;
117 // Check for uploaded change logs
118 if ($uploaded_changes['tmp_name']) {
119 if (!is_uploaded_file($uploaded_changes['tmp_name'])) {
120 exit_error('Error','Attempted File Upload Attack');
122 if ($uploaded_changes['type'] !== 'text/plain') {
123 $feedback .= _('Change Log Is not in Text');
124 $exec_changes = false;
126 $changes = addslashes(fread(fopen($uploaded_changes['tmp_name'],'r'), $uploaded_changes['size']));
127 if (strlen($changes) < 20) {
128 $feedback .= _('Change Log Is Too Small');
129 $exec_changes = false;
133 $changes = $release_changes;
136 // If we haven't encountered any problems so far then save the changes
137 if ($exec_changes == true) {
138 //$date_list = split('[- :]',$release_date,5);
139 //$release_date = mktime($date_list[3],$date_list[4],0,$date_list[1],$date_list[2],$date_list[0]);
140 $release_date = strtotime($release_date);
141 if (!$frsr->update($status_id,$release_name,$notes,$changes,$preformatted,$release_date)) {
142 exit_error('Error',$frsr->getErrorMessage());
144 $feedback .= _('Data Saved');
149 // Add file(s) to the release
150 if (getStringFromRequest('step2')) {
151 $userfile = getUploadedFile('userfile');
152 $userfile_name = $userfile['name'];
153 $type_id = getIntFromRequest('type_id');
154 $release_date = getStringFromRequest('release_date');
155 $release_date = strtotime($release_date);
156 $processor_id = getStringFromRequest('processor_id');
157 // Build a Unix time value from the supplied Y-m-d value
158 $group_unix_name=group_getunixname($group_id);
159 $ftp_filename = getStringFromRequest('ftp_filename');
161 if (($userfile && is_uploaded_file($userfile['tmp_name'])) || ($sys_use_ftpuploads && $ftp_filename)){
162 if ($sys_use_ftpuploads && $ftp_filename && util_is_valid_filename($ftp_filename) && is_file($upload_dir.'/'.$ftp_filename)) {
163 //file was uploaded already via ftp
164 //use setuid prog to chown it
165 //$cmd = escapeshellcmd("$sys_ftp_upload_chowner $ftp_filename");
166 //exec($cmd,$output);
167 $userfile_name=$ftp_filename;
168 $userfile=$upload_dir.'/'.$ftp_filename;
169 //echo $cmd.'***'.$output.'***'.$userfile;
172 // Now create the new FRSFile in the db
174 $frsf = new FRSFile($frsr);
175 if (!$frsf || !is_object($frsf)) {
176 exit_error('Error','Could Not Get FRSFile');
177 } elseif ($frsf->isError()) {
178 exit_error('Error',$frsf->getErrorMessage());
180 if (!$frsf->create($userfile_name,$userfile['tmp_name'],$type_id,$processor_id,$release_date)) {
182 exit_error('Error',$frsf->getErrorMessage());
184 $feedback=_('File Released');
189 // Edit/Delete files in a release
190 if (getStringFromRequest('step3')) {
191 $step3 = getStringFromRequest('step3');
192 $file_id = getIntFromRequest('file_id');
193 $processor_id = getIntFromRequest('processor_id');
194 $type_id = getIntFromRequest('type_id');
195 $new_release_id = getIntFromRequest('new_release_id');
196 $release_time = getStringFromRequest('release_time');
197 $group_id = getIntFromRequest('group_id');
198 $release_id = getIntFromRequest('release_id');
199 $package_id = getIntFromRequest('package_id');
200 $file_id = getIntFromRequest('file_id');
201 $im_sure = getStringFromRequest('im_sure');
203 // If the user chose to delete the file and he's sure then delete the file
204 if( $step3 == "Delete File" ) {
206 $frsf = new FRSFile($frsr,$file_id);
207 if (!$frsf || !is_object($frsf)) {
208 exit_error('Error','Could Not Get FRSFile');
209 } elseif ($frsf->isError()) {
210 exit_error('Error',$frsf->getErrorMessage());
212 if (!$frsf->delete()) {
213 exit_error('Error',$frsf->getErrorMessage());
215 $feedback .= _('File Deleted');
219 exit_error('Error',_('Missing Parameters'));
221 // Otherwise update the file information
223 $frsf = new FRSFile($frsr,$file_id);
224 if (!$frsf || !is_object($frsf)) {
225 exit_error('Error','Could Not Get FRSFile');
226 } elseif ($frsf->isError()) {
227 exit_error('Error',$frsf->getErrorMessage());
229 //$date_list = split('[- :]',$release_time,5);
230 //$release_time = mktime($date_list[3],$date_list[4],0,$date_list[1],$date_list[2],$date_list[0]);
231 $release_time = strtotime($release_time);
232 if (!$frsf->update($type_id,$processor_id,$release_time,$new_release_id)) {
233 exit_error('Error',$frsf->getErrorMessage());
235 $feedback .= _('File Updated');
241 frs_admin_header(array('title'=>_('Edit Releases'),'group'=>$group_id));
243 * Show the forms for each step
247 <h3><?php echo _('Step 1: Edit Release') ?></h3>
249 <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"; ?>">
250 <input type="hidden" name="step1" value="1" />
251 <table border="0" cellpadding="1" cellspacing="1">
253 <td width="10%"><strong><?php echo _('Release date') ?>:</strong></td>
254 <td><input type="text" name="release_date" value="<?php echo date('Y-m-d H:i',$frsr->getReleaseDate()) ?>" size="16" maxlength="16" /></td>
257 <td><strong><?php echo _('Release name') ?>:</strong></td>
258 <td><input type="text" name="release_name" value="<?php echo htmlspecialchars($frsr->getName()); ?>" /></td>
261 <td><strong><?php echo _('Status') ?></strong></td>
264 echo frs_show_status_popup('status_id',$frsr->getStatus());
271 <?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.') ?>
275 <td><strong><?php echo _('Upload Release Notes') ?>:</strong></td>
276 <td><input type="file" name="uploaded_notes" size="30" /></td>
279 <td><strong><?php echo _('Upload Change Log') ?>:</strong></td>
280 <td><input type="file" name="uploaded_changes" size="30" /></td>
284 <strong><?php echo _('Paste The Notes In') ?>:</strong><br />
285 <textarea name="release_notes" rows="10" cols="60"><?php echo $frsr->getNotes(); ?></textarea>
290 <strong><?php echo _('Paste The Change Log In') ?>:</strong><br />
291 <textarea name="release_changes" rows="10" cols="60"><?php echo $frsr->getChanges(); ?></textarea>
297 <input type="checkbox" name="preformatted" value="1" <?php echo (($frsr->getPreformatted())?'checked="checked"':''); ?> /> <?php echo _('Preserve my pre-formatted text.') ?>
299 <input type="submit" name="submit" value="<?php echo _('Submit/Refresh') ?>"/></p>
307 <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>
309 <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"; ?>">
310 <input type="hidden" name="step2" value="1" />
311 <span class="important">
312 <?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>
314 <?php echo _('Upload a new file') ?>: <input type="file" name="userfile" size="30" />
315 <?php if ($sys_use_ftpuploads) {
318 printf(_('Alternatively, you can use FTP to upload a new file at %1$s'), $sys_ftp_upload_host).'<br />';
319 echo _('Choose an FTP file instead of uploading:').'<br />';
321 $ftp_files_arr=array_merge($arr,ls($upload_dir,true));
322 echo html_build_select_box_from_arrays($ftp_files_arr,$ftp_files_arr,'ftp_filename','',false); ?>
328 <strong><?php echo _('File Type') ?>:</strong>
330 print frs_show_filetype_popup ('type_id');
334 <strong><?php echo _('Processor Type') ?>:</strong>
336 print frs_show_processor_popup ('processor_id');
342 <input type="submit" name="submit" value="<?php echo _('Add This File') ?>" /></p>
345 <h3><?php echo _('Step 3: Edit Files In This Release') ?></h3>
348 // Get a list of files associated with this release
349 $res=db_query_params ('SELECT * FROM frs_file WHERE release_id=$1',
351 $rows=db_numrows($res);
353 print("<span class=\"error\">"._('No Files In This Release')."</span>\n");
355 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");
356 $title_arr[]=_('Filename<br />Release').'<br />';
357 $title_arr[]=_('Processor<br />Release Date').'<br />';
358 $title_arr[]=_('File Type<br />Update').'<br />';
360 echo $GLOBALS['HTML']->listTableTop ($title_arr);
362 for($x=0; $x<$rows; $x++) {
364 <form action="<?php echo getStringFromServer('PHP_SELF')."?group_id=$group_id&release_id=$release_id&package_id=$package_id"; ?>" method="post">
365 <input type="hidden" name="file_id" value="<?php echo db_result($res,$x,'file_id'); ?>" />
366 <input type="hidden" name="step3" value="1" />
367 <tr <?php echo $HTML->boxGetAltRowStyle($x); ?>>
368 <td style="white-space: nowrap;"><?php echo db_result($res,$x,'filename'); ?></td>
369 <td><?php echo frs_show_processor_popup ('processor_id', db_result($res,$x,'processor_id')); ?></td>
370 <td><?php echo frs_show_filetype_popup ('type_id', db_result($res,$x,'type_id')); ?></td>
372 <tr <?php echo $HTML->boxGetAltRowStyle($x); ?>>
375 <?php echo frs_show_release_popup ($group_id, $name='new_release_id',db_result($res,$x,'release_id')); ?>
380 <input type="text" name="release_time" value="<?php echo date('Y-m-d',db_result($res,$x,'release_time')); ?>" size="10" maxlength="10" />
383 <td><input type="submit" name="submit" value="<?php echo _('Update/Refresh') ?> " /></td>
387 <form action="<?php echo getStringFromServer('PHP_SELF'); ?>" method="post">
388 <input type="hidden" name="group_id" value="<?php echo $group_id; ?>" />
389 <input type="hidden" name="release_id" value="<?php echo $release_id; ?>" />
390 <input type="hidden" name="package_id" value="<?php echo $package_id; ?>" />
391 <input type="hidden" name="file_id" value="<?php echo db_result($res,$x,'file_id'); ?>" />
392 <input type="hidden" name="step3" value="Delete File" />
393 <tr <?php echo $HTML->boxGetAltRowStyle($x); ?>>
398 <input type="submit" name="submit" value="<?php echo _('Delete File') ?> " /> <input type="checkbox" name="im_sure" value="1" /> <?php echo _('I\'m Sure') ?>
405 echo $GLOBALS['HTML']->listTableBottom();
408 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>';
415 // c-file-style: "bsd"