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 * Copyright 2013, Franck Villaume - TrivialDev
10 * http://fusionforge.org/
12 * This file is part of FusionForge. FusionForge is free software;
13 * you can redistribute it and/or modify it under the terms of the
14 * GNU General Public License as published by the Free Software
15 * Foundation; either version 2 of the Licence, or (at your option)
18 * FusionForge 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 along
24 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 Standard header to be used on all /project/admin/* pages
32 function frs_admin_header($params) {
38 if (!session_loggedin()) {
42 $project = group_get_object($group_id);
43 if (!$project || !is_object($project)) {
47 session_require_perm('frs', $group_id, 'write');
52 function frs_admin_footer() {
53 site_project_footer(array());
56 function frs_header($params) {
57 global $group_id,$HTML;
60 Does this site use FRS?
62 if (!forge_get_config('use_frs')) {
63 exit_disabled('home');
66 $project = group_get_object($group_id);
67 if (!$project || !is_object($project)) {
71 $params['toptab'] = 'frs';
72 $params['group'] = $group_id;
74 if (forge_check_perm('frs', $group_id, 'write')) {
75 $params['submenu'] = $HTML->subMenu(
77 _('View File Releases'),
82 '/frs/?group_id='.$group_id,
83 '/frs/reporting/downloads.php?group_id='.$group_id,
84 '/frs/admin/?group_id='.$group_id
93 site_project_header($params);
96 function frs_footer() {
97 site_project_footer(array());
101 The following functions are for the FRS (File Release System)
105 pop-up box of public / private frs statuses
108 function frs_show_public_popup($name='is_public', $checked_val="xzxz") {
110 return a pop-up select box of statuses
112 $FRS_PUBLIC_RES = array('private', 'public');
113 return html_build_select_box_from_array($FRS_PUBLIC_RES, $name, $checked_val, false);
117 pop-up box of supported frs statuses
120 function frs_show_status_popup($name='status_id', $checked_val="xzxz") {
122 return a pop-up select box of statuses
124 global $FRS_STATUS_RES;
125 if (!isset($FRS_STATUS_RES)) {
126 $FRS_STATUS_RES=db_query_params('SELECT * FROM frs_status',
129 return html_build_select_box($FRS_STATUS_RES, $name, $checked_val, false);
133 pop-up box of supported frs filetypes
136 function frs_show_filetype_popup ($name='type_id', $checked_val="xzxz") {
138 return a pop-up select box of the available filetypes
140 global $FRS_FILETYPE_RES;
141 if (!isset($FRS_FILETYPE_RES)) {
142 $FRS_FILETYPE_RES=db_query_params('SELECT * FROM frs_filetype ORDER BY type_id',
145 return html_build_select_box($FRS_FILETYPE_RES, $name, $checked_val, false);
149 pop-up box of supported frs processor options
152 function frs_show_processor_popup($name='processor_id', $checked_val="xzxz") {
154 return a pop-up select box of the available processors
156 global $FRS_PROCESSOR_RES;
157 if (!isset($FRS_PROCESSOR_RES)) {
158 $FRS_PROCESSOR_RES=db_query_params ('SELECT * FROM frs_processor ORDER BY processor_id',
161 return html_build_select_box ($FRS_PROCESSOR_RES, $name, $checked_val, false);
165 pop-up box of packages:releases for this group
168 function frs_show_release_popup ($group_id, $name='release_id', $checked_val="xzxz") {
170 return a pop-up select box of releases for the project
172 global $FRS_RELEASE_RES;
175 return _('Error: group id required');
177 if (!isset($FRS_RELEASE_RES)) {
178 $FRS_RELEASE_RES = db_query_params("SELECT frs_release.release_id,(frs_package.name || ' : ' || frs_release.name) FROM frs_release,frs_package
179 WHERE frs_package.group_id=$1
180 AND frs_release.package_id=frs_package.package_id",
184 return html_build_select_box($FRS_RELEASE_RES,$name,$checked_val,false);
188 pop-up box of packages for this group
191 function frs_show_package_popup ($group_id, $name='package_id', $checked_val="xzxz") {
193 return a pop-up select box of packages for this project
195 global $FRS_PACKAGE_RES;
197 return _('Error: group id required');
199 if (!isset($FRS_PACKAGE_RES)) {
200 $FRS_PACKAGE_RES=db_query_params ('SELECT package_id,name
201 FROM frs_package WHERE group_id=$1',
205 return html_build_select_box ($FRS_PACKAGE_RES,$name,$checked_val,false);
208 function frs_add_file_from_form ($release, $type_id, $processor_id, $release_date,
209 $userfile, $ftp_filename, $manual_filename) {
211 $group_unix_name = $release->getFRSPackage()->getGroup()->getUnixName() ;
212 $incoming = forge_get_config('groupdir_prefix')."/$group_unix_name/incoming" ;
214 $filechecks = false ;
216 if ($userfile && is_uploaded_file($userfile['tmp_name']) && util_is_valid_filename($userfile['name'])) {
217 $infile = $userfile['tmp_name'] ;
218 $fname = $userfile['name'] ;
221 } elseif ($userfile && $userfile['error'] != UPLOAD_ERR_OK && $userfile['error'] != UPLOAD_ERR_NO_FILE) {
222 switch ($userfile['error']) {
223 case UPLOAD_ERR_INI_SIZE:
224 case UPLOAD_ERR_FORM_SIZE:
225 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).') ;
227 case UPLOAD_ERR_PARTIAL:
228 return _('The uploaded file was only partially uploaded.') ;
231 return _('Unknown file upload error.') ;
234 } elseif (forge_get_config('use_ftp_uploads') && $ftp_filename && util_is_valid_filename($ftp_filename) && is_file($upload_dir.'/'.$ftp_filename)) {
235 $infile = $upload_dir.'/'.$ftp_filename;
236 $fname = $ftp_filename ;
239 } elseif (forge_get_config('use_manual_uploads') && $manual_filename && util_is_valid_filename($manual_filename) && is_file($incoming.'/'.$manual_filename)) {
240 $infile = $incoming.'/'.$manual_filename ;
241 $fname = $manual_filename ;
244 } elseif ($userfile && $userfile['error'] == UPLOAD_ERR_NO_FILE) {
245 return _('Must select a file.') ;
249 if (strlen($fname) < 3)
250 exit_error('Error',_('Name is too short. It must be at least 3 characters.'));
252 $tmp = tempnam ('', '') ;
253 copy ($infile, $tmp) ;
256 $frsf = new FRSFile($release);
257 if (!$frsf || !is_object($frsf)) {
258 exit_error(_('Could Not Get FRSFile'),'frs');
259 } elseif ($frsf->isError()) {
260 exit_error($frsf->getErrorMessage(),'frs');
262 if (!$frsf->create($fname,$infile,$type_id,$processor_id,$release_date)) {
264 exit_error($frsf->getErrorMessage(),'frs');
269 return _('Unknown file upload error.') ;
273 /* filter utils.php:&ls() output for additional constraints from FRS */
274 function frs_filterfiles($in) {
276 for ($i = 0; $i < count($in); $i++) {
277 if (strlen($in[$i]) < 3)
286 // c-file-style: "bsd"