3 * Project Admin: Edit Releases of Packages
5 * Copyright 1999-2001 (c) VA Linux Systems
6 * Copyright 2002-2004 (c) GForge Team
7 * Copyright 2012-2014, Franck Villaume - TrivialDev
8 * http://fusionforge.org/
10 * This file is part of FusionForge. FusionForge is free software;
11 * you can redistribute it and/or modify it under the terms of the
12 * GNU General Public License as published by the Free Software
13 * Foundation; either version 2 of the Licence, or (at your option)
16 * FusionForge 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 along
22 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 require_once '../../env.inc.php';
27 require_once $gfcommon.'include/pre.php';
28 require_once $gfcommon.'frs/FRSPackage.class.php';
29 require_once $gfcommon.'frs/FRSRelease.class.php';
30 require_once $gfcommon.'frs/FRSFile.class.php';
31 require_once $gfcommon.'frs/include/frs_utils.php';
33 $group_id = getIntFromRequest('group_id');
34 $package_id = getIntFromRequest('package_id');
35 $release_id = getIntFromRequest('release_id');
39 if (!$package_id || !$release_id) {
40 session_redirect('/frs/admin/?group_id='.$group_id);
43 $group = group_get_object($group_id);
44 if (!$group || !is_object($group)) {
46 } elseif ($group->isError()) {
47 exit_error($group->getErrorMessage(),'frs');
49 session_require_perm ('frs', $group_id, 'write') ;
54 $frsp = new FRSPackage($group,$package_id);
55 if (!$frsp || !is_object($frsp)) {
56 exit_error(_('Could Not Get FRS Package'),'frs');
57 } elseif ($frsp->isError()) {
58 exit_error($frsp->getErrorMessage(),'frs');
64 $frsr = new FRSRelease($frsp,$release_id);
65 if (!$frsr || !is_object($frsr)) {
66 exit_error(_('Could Not Get FRS Release'),'frs');
67 } elseif ($frsr->isError()) {
68 exit_error($frsr->getErrorMessage(),'frs');
71 $upload_dir = forge_get_config('ftp_upload_dir') . "/" . $group->getUnixName();
74 * Here's where we do the dirty work based on the step the user has chosen
78 if (getStringFromRequest('step1')) {
79 $release_date = getStringFromRequest('release_date');
80 $release_name = getStringFromRequest('release_name');
81 $status_id = getIntFromRequest('status_id');
82 $uploaded_notes = getUploadedFile('uploaded_notes');
83 $uploaded_changes = getUploadedFile('uploaded_changes');
84 $release_notes = getStringFromRequest('release_notes');
85 $release_changes = getStringFromRequest('release_changes');
86 $preformatted = getStringFromRequest('preformatted');
89 // Check for uploaded release notes
90 if ($uploaded_notes["tmp_name"]) {
91 if (!is_uploaded_file($uploaded_notes['tmp_name'])) {
92 exit_error(_('Attempted File Upload Attack'),'frs');
94 if ($uploaded_notes['type'] !== 'text/plain') {
95 $error_msg .= _('Release Notes Are not in Text').'<br />';
96 $exec_changes = false;
98 $notes = fread(fopen($uploaded_notes['tmp_name'],'r'),$uploaded_notes['size']);
99 if (strlen($notes) < 20) {
100 $error_msg .= _('Release Notes Are Too Small').'<br />';
101 $exec_changes = false;
105 $notes = $release_notes;
108 // Check for uploaded change logs
109 if ($uploaded_changes['tmp_name']) {
110 if (!is_uploaded_file($uploaded_changes['tmp_name'])) {
111 exit_error(_('Attempted File Upload Attack'),'frs');
113 if ($uploaded_changes['type'] !== 'text/plain') {
114 $error_msg .= _('Change Log Is not in Text').'<br />';
115 $exec_changes = false;
117 $changes = fread(fopen($uploaded_changes['tmp_name'],'r'), $uploaded_changes['size']);
118 if (strlen($changes) < 20) {
119 $error_msg .= _('Change Log Is Too Small').'<br />';
120 $exec_changes = false;
124 $changes = $release_changes;
127 // If we haven't encountered any problems so far then save the changes
128 if ($exec_changes == true) {
129 //$date_list = split('[- :]',$release_date,5);
130 //$release_date = mktime($date_list[3],$date_list[4],0,$date_list[1],$date_list[2],$date_list[0]);
131 $release_date = strtotime($release_date);
132 if (!$frsr->update($status_id,$release_name,$notes,$changes,$preformatted,$release_date)) {
133 exit_error($frsr->getErrorMessage(),'frs');
135 $feedback .= _('Data Saved');
140 // Add file(s) to the release
141 if (getStringFromRequest('step2')) {
142 $userfile = getUploadedFile('userfile');
143 $userfile_name = $userfile['name'];
144 $type_id = getIntFromRequest('type_id');
145 $release_date = getStringFromRequest('release_date');
146 // Build a Unix time value from the supplied Y-m-d value
147 $release_date = strtotime($release_date);
148 $processor_id = getIntFromRequest('processor_id');
149 $group_unix_name=group_getunixname($group_id);
150 $ftp_filename = getStringFromRequest('ftp_filename');
151 $manual_filename = getStringFromRequest('manual_filename');
153 $ret = frs_add_file_from_form ($frsr, $type_id, $processor_id, $release_date,
154 $userfile, $ftp_filename, $manual_filename) ;
156 $feedback = _('File Released') ;
162 // Edit/Delete files in a release
163 if (getStringFromRequest('step3')) {
164 $step3 = getStringFromRequest('step3');
165 $file_id = getIntFromRequest('file_id');
166 $processor_id = getIntFromRequest('processor_id');
167 $type_id = getIntFromRequest('type_id');
168 $new_release_id = getIntFromRequest('new_release_id');
169 $release_time = getStringFromRequest('release_time');
170 $group_id = getIntFromRequest('group_id');
171 $release_id = getIntFromRequest('release_id');
172 $package_id = getIntFromRequest('package_id');
173 $file_id = getIntFromRequest('file_id');
174 $im_sure = getStringFromRequest('im_sure');
176 // If the user chose to delete the file and he's sure then delete the file
177 if( $step3 == "Delete File" ) {
179 $frsf = new FRSFile($frsr,$file_id);
180 if (!$frsf || !is_object($frsf)) {
181 exit_error(_('Could Not Get FRSFile'),'frs');
182 } elseif ($frsf->isError()) {
183 exit_error($frsf->getErrorMessage(),'frs');
185 if (!$frsf->delete()) {
186 exit_error($frsf->getErrorMessage(),'frs');
188 $feedback .= _('File Deleted');
192 $error_msg .= _('File not deleted: you did not check “I am Sure”');
194 // Otherwise update the file information
196 $frsf = new FRSFile($frsr,$file_id);
197 if (!$frsf || !is_object($frsf)) {
198 exit_error(_('Could Not Get FRSFile'),'frs');
199 } elseif ($frsf->isError()) {
200 exit_error($frsf->getErrorMessage(),'frs');
202 //$date_list = split('[- :]',$release_time,5);
203 //$release_time = mktime($date_list[3],$date_list[4],0,$date_list[1],$date_list[2],$date_list[0]);
204 $release_time = strtotime($release_time);
205 if (!$frsf->update($type_id,$processor_id,$release_time,$new_release_id)) {
206 exit_error($frsf->getErrorMessage(),'frs');
208 $feedback .= _('File Updated');
214 frs_admin_header(array('title'=>_('Edit Releases'),'group'=>$group_id));
216 * Show the forms for each step
220 <h2><?php echo _('Edit Release') ?></h2>
222 <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"; ?>">
223 <input type="hidden" name="step1" value="1" />
226 <td><strong><?php echo _('Release Date')._(':'); ?></strong></td>
227 <td><input type="text" name="release_date" value="<?php echo date('Y-m-d H:i',$frsr->getReleaseDate()) ?>" size="16" maxlength="16" /></td>
230 <td><strong><?php echo _('Release Name')._(':').utils_requiredField(); ?></strong></td>
231 <td><input type="text" name="release_name" value="<?php echo $frsr->getName(); ?>" required="required" pattern=".{3,}" title="<?php echo _('At least 3 characters') ?>"/></td>
234 <td><strong><?php echo _('Status')._(':'); ?></strong></td>
237 echo frs_show_status_popup('status_id',$frsr->getStatus());
244 <?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.') ?>
246 <?php echo _('You can either upload the release notes and change log individually, or paste them in together below.') ?>
250 <td colspan="2"><strong><?php echo _('Upload Release Notes')._(':'); ?></strong>
251 <?php echo('('._('max upload size: '.human_readable_bytes(util_get_maxuploadfilesize())).')') ?></td>
254 <td><input type="file" name="uploaded_notes" size="30" /></td>
257 <td colspan="2"><strong><?php echo _('Upload Change Log')._(':'); ?></strong>
258 <?php echo('('._('max upload size: '.human_readable_bytes(util_get_maxuploadfilesize())).')') ?></td>
261 <td><input type="file" name="uploaded_changes" size="30" /></td>
265 <strong><?php echo _('Paste The Notes In')._(':'); ?></strong><br />
266 <textarea name="release_notes" rows="10" cols="60"><?php echo $frsr->getNotes(); ?></textarea>
271 <strong><?php echo _('Paste The Change Log In')._(':'); ?></strong><br />
272 <textarea name="release_changes" rows="10" cols="60"><?php echo $frsr->getChanges(); ?></textarea>
278 <input type="checkbox" name="preformatted" value="1" <?php echo (($frsr->getPreformatted())?'checked="checked"':''); ?> /> <?php echo _('Preserve my pre-formatted text') ?>
280 <input type="submit" name="submit" value="<?php echo _('Submit/Refresh') ?>"/>
288 <h2><?php echo _('Add Files To This Release') ?></h2>
289 <p><?php echo _('Now, choose a file to upload into the system.') ?></p>
291 <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"; ?>">
292 <input type="hidden" name="step2" value="1" />
293 <fieldset><legend><strong><?php echo _("File Name") ?></strong></legend>
294 <?php echo _("Upload a new file") ?>: <input type="file" name="userfile" size="30" /> <?php echo('('._('max upload size: '.human_readable_bytes(util_get_maxuploadfilesize())).')') ?>
296 if (forge_get_config('use_ftp_uploads')) {
298 printf(_('Alternatively, you can use FTP to upload a new file at %s.'), forge_get_config('ftp_upload_host'));
300 echo _('Choose an already uploaded file:').'<br />';
301 $ftp_files_arr=frs_filterfiles(ls($upload_dir,true));
302 echo html_build_select_box_from_arrays($ftp_files_arr,$ftp_files_arr,'ftp_filename','');
306 if (forge_get_config('use_manual_uploads')) {
307 $incoming = forge_get_config('groupdir_prefix')."/".$group->getUnixName()."/incoming" ;
309 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).'),
310 $incoming, "sftp://" . forge_get_config ('web_host') . $incoming . "/");
311 echo ' ' . _('This direct <tt>sftp://</tt> link only works with some browsers, such as Konqueror.') . '<br />';
312 echo _('Choose an already uploaded file:').'<br />';
313 $manual_files_arr=frs_filterfiles(ls($incoming,true));
314 echo html_build_select_box_from_arrays($manual_files_arr,$manual_files_arr,'manual_filename','');
322 <strong><?php echo _('File Type')._(':'); ?></strong>
324 print frs_show_filetype_popup ('type_id');
328 <strong><?php echo _('Processor Type')._(':'); ?></strong>
330 print frs_show_processor_popup ('processor_id');
336 <input type="submit" name="submit" value="<?php echo _('Add This File') ?>" /></p>
340 // Get a list of files associated with this release
341 $res=db_query_params ('SELECT * FROM frs_file WHERE release_id=$1',
343 $rows=db_numrows($res);
346 echo '<h2>'._('Edit Files In This Release').'</h2>';
347 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");
348 $title_arr[]=_('File Name').'<br />'._('Release').'<br />';
349 $title_arr[]=_('Processor').'<br />'._('Release Date').'<br />';
350 $title_arr[]=_('File Type').'<br />'._('Update').'<br />';
352 echo $GLOBALS['HTML']->listTableTop ($title_arr);
354 for($x=0; $x<$rows; $x++) {
356 <form action="<?php echo getStringFromServer('PHP_SELF')."?group_id=$group_id&release_id=$release_id&package_id=$package_id"; ?>" method="post">
357 <input type="hidden" name="file_id" value="<?php echo db_result($res,$x,'file_id'); ?>" />
358 <input type="hidden" name="step3" value="1" />
359 <tr <?php echo $HTML->boxGetAltRowStyle($x); ?>>
360 <td style="white-space: nowrap;"><?php echo db_result($res,$x,'filename'); ?></td>
361 <td><?php echo frs_show_processor_popup ('processor_id', db_result($res,$x,'processor_id')); ?></td>
362 <td><?php echo frs_show_filetype_popup ('type_id', db_result($res,$x,'type_id')); ?></td>
364 <tr <?php echo $HTML->boxGetAltRowStyle($x); ?>>
366 <?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" />
371 <td><input type="submit" name="submit" value="<?php echo _('Update/Refresh') ?> " /></td>
375 <form action="<?php echo getStringFromServer('PHP_SELF'); ?>" method="post">
376 <input type="hidden" name="group_id" value="<?php echo $group_id; ?>" />
377 <input type="hidden" name="release_id" value="<?php echo $release_id; ?>" />
378 <input type="hidden" name="package_id" value="<?php echo $package_id; ?>" />
379 <input type="hidden" name="file_id" value="<?php echo db_result($res,$x,'file_id'); ?>" />
380 <input type="hidden" name="step3" value="Delete File" />
381 <tr <?php echo $HTML->boxGetAltRowStyle($x); ?>>
385 <input type="submit" name="submit" value="<?php echo _('Delete File') ?> " /> <input type="checkbox" name="im_sure" value="1" /> <?php echo _('I am Sure') ?>
391 echo $GLOBALS['HTML']->listTableBottom();
394 echo '<p>' . sprintf(ngettext('There is %s user monitoring this package.', 'There are %s users monitoring this package.', $frsp->getMonitorCount()), $frsp->getMonitorCount()) . '</p>';
400 // c-file-style: "bsd"