5 * Copyright 1999-2001 (c) VA Linux Systems
6 * Copyright 2002-2004 (c) GForge Team
7 * Copyright (C) 2011 Alain Peyrat - Alcatel-Lucent
8 * Copyright 2011, Franck Villaume - Capgemini
9 * http://fusionforge.org/
11 * This file is part of FusionForge. FusionForge is free software;
12 * you can redistribute it and/or modify it under the terms of the
13 * GNU General Public License as published by the Free Software
14 * Foundation; either version 2 of the Licence, or (at your option)
17 * FusionForge is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 Standard header to be used on all /project/admin/* pages
31 function frs_admin_header($params) {
37 if (!session_loggedin()) {
41 $project = group_get_object($group_id);
42 if (!$project || !is_object($project)) {
46 session_require_perm('frs', $group_id, 'write');
51 function frs_admin_footer() {
52 site_project_footer(array());
55 function frs_header($params) {
56 global $group_id,$HTML;
59 Does this site use FRS?
61 if (!forge_get_config('use_frs')) {
62 exit_disabled('home');
65 $project = group_get_object($group_id);
66 if (!$project || !is_object($project)) {
70 $params['toptab'] = 'frs';
71 $params['group'] = $group_id;
73 if (forge_check_perm('frs', $group_id, 'write')) {
74 $params['submenu'] = $HTML->subMenu(
76 _('View File Releases'),
81 '/frs/?group_id='.$group_id,
82 '/frs/reporting/downloads.php?group_id='.$group_id,
83 '/frs/admin/?group_id='.$group_id
87 site_project_header($params);
90 function frs_footer() {
91 site_project_footer(array());
96 The following functions are for the FRS (File Release System)
100 pop-up box of public / private frs statuses
103 function frs_show_public_popup($name='is_public', $checked_val="xzxz") {
105 return a pop-up select box of statuses
107 $FRS_PUBLIC_RES = array('private', 'public');
108 return html_build_select_box_from_array($FRS_PUBLIC_RES, $name, $checked_val, false);
112 pop-up box of supported frs statuses
115 function frs_show_status_popup($name='status_id', $checked_val="xzxz") {
117 return a pop-up select box of statuses
119 global $FRS_STATUS_RES;
120 if (!isset($FRS_STATUS_RES)) {
121 $FRS_STATUS_RES=db_query_params('SELECT * FROM frs_status',
124 return html_build_select_box($FRS_STATUS_RES, $name, $checked_val, false);
128 pop-up box of supported frs filetypes
131 function frs_show_filetype_popup ($name='type_id', $checked_val="xzxz") {
133 return a pop-up select box of the available filetypes
135 global $FRS_FILETYPE_RES;
136 if (!isset($FRS_FILETYPE_RES)) {
137 $FRS_FILETYPE_RES=db_query_params('SELECT * FROM frs_filetype ORDER BY type_id',
140 return html_build_select_box($FRS_FILETYPE_RES, $name, $checked_val, true, _('Must Choose One'));
144 pop-up box of supported frs processor options
147 function frs_show_processor_popup($name='processor_id', $checked_val="xzxz") {
149 return a pop-up select box of the available processors
151 global $FRS_PROCESSOR_RES;
152 if (!isset($FRS_PROCESSOR_RES)) {
153 $FRS_PROCESSOR_RES=db_query_params ('SELECT * FROM frs_processor ORDER BY processor_id',
156 return html_build_select_box ($FRS_PROCESSOR_RES,$name,$checked_val,true,_('Must Choose One'));
160 pop-up box of packages:releases for this group
164 function frs_show_release_popup ($group_id, $name='release_id', $checked_val="xzxz") {
166 return a pop-up select box of releases for the project
168 global $FRS_RELEASE_RES;
171 return 'ERROR - GROUP ID REQUIRED';
173 if (!isset($FRS_RELEASE_RES)) {
174 $FRS_RELEASE_RES = db_query_params("SELECT frs_release.release_id,(frs_package.name || ' : ' || frs_release.name) FROM frs_release,frs_package
175 WHERE frs_package.group_id=$1
176 AND frs_release.package_id=frs_package.package_id",
180 return html_build_select_box($FRS_RELEASE_RES,$name,$checked_val,false);
185 pop-up box of packages for this group
188 function frs_show_package_popup ($group_id, $name='package_id', $checked_val="xzxz") {
190 return a pop-up select box of packages for this project
192 global $FRS_PACKAGE_RES;
194 return 'ERROR - GROUP ID REQUIRED';
196 if (!isset($FRS_PACKAGE_RES)) {
197 $FRS_PACKAGE_RES=db_query_params ('SELECT package_id,name
198 FROM frs_package WHERE group_id=$1',
202 return html_build_select_box ($FRS_PACKAGE_RES,$name,$checked_val,false);
206 function frs_add_file_from_form ($release, $type_id, $processor_id, $release_date,
207 $userfile, $ftp_filename, $manual_filename) {
210 $group_unix_name = $release->getFRSPackage()->getGroup()->getUnixName() ;
211 $incoming = forge_get_config('groupdir_prefix')."/$group_unix_name/incoming" ;
213 $filechecks = false ;
215 if ($userfile && is_uploaded_file($userfile['tmp_name']) && util_is_valid_filename($userfile['name'])) {
216 $infile = $userfile['tmp_name'] ;
217 $fname = $userfile['name'] ;
220 } elseif ($userfile && $userfile['error'] != UPLOAD_ERR_OK && $userfile['error'] != UPLOAD_ERR_NO_FILE) {
221 switch ($userfile['error']) {
222 case UPLOAD_ERR_INI_SIZE:
223 case UPLOAD_ERR_FORM_SIZE:
224 return _('The uploaded file exceeds the maximum file size. Contact to the site admin to upload this big file, or use an alternate upload method (if available).') ;
226 case UPLOAD_ERR_PARTIAL:
227 return _('The uploaded file was only partially uploaded.') ;
230 return _('Unknown file upload error.') ;
233 } elseif (forge_get_config('use_ftp_uploads') && $ftp_filename && util_is_valid_filename($ftp_filename) && is_file($upload_dir.'/'.$ftp_filename)) {
234 $infile = $upload_dir.'/'.$ftp_filename;
235 $fname = $ftp_filename ;
238 } elseif (forge_get_config('use_manual_uploads') && $manual_filename && util_is_valid_filename($manual_filename) && is_file($incoming.'/'.$manual_filename)) {
239 $infile = $incoming.'/'.$manual_filename ;
240 $fname = $manual_filename ;
243 } elseif ($userfile && $userfile['error'] == UPLOAD_ERR_NO_FILE) {
244 return _('Must select a file.') ;
248 if (strlen($fname) < 3)
249 exit_error('Error',_('FRSFile Name Must Be At Least 3 Characters'));
251 $tmp = tempnam ('', '') ;
252 copy ($infile, $tmp) ;
255 $frsf = new FRSFile($release);
256 if (!$frsf || !is_object($frsf)) {
257 exit_error(_('Could Not Get FRSFile'),'frs');
258 } elseif ($frsf->isError()) {
259 exit_error($frsf->getErrorMessage(),'frs');
261 if (!$frsf->create($fname,$infile,$type_id,$processor_id,$release_date)) {
263 exit_error($frsf->getErrorMessage(),'frs');
268 return _('Unknown file upload error.') ;
272 /* filter utils.php:&ls() output for additional constraints from FRS */
273 function frs_filterfiles($in) {
275 for ($i = 0; $i < count($in); $i++) {
276 if (strlen($in[$i]) < 3)
285 // c-file-style: "bsd"