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);
189 pop-up box of packages for this group
192 function frs_show_package_popup ($group_id, $name='package_id', $checked_val="xzxz") {
194 return a pop-up select box of packages for this project
196 global $FRS_PACKAGE_RES;
198 return _('Error: GROUP ID REQUIRED');
200 if (!isset($FRS_PACKAGE_RES)) {
201 $FRS_PACKAGE_RES=db_query_params ('SELECT package_id,name
202 FROM frs_package WHERE group_id=$1',
206 return html_build_select_box ($FRS_PACKAGE_RES,$name,$checked_val,false);
210 function frs_add_file_from_form ($release, $type_id, $processor_id, $release_date,
211 $userfile, $ftp_filename, $manual_filename) {
213 $group_unix_name = $release->getFRSPackage()->getGroup()->getUnixName() ;
214 $incoming = forge_get_config('groupdir_prefix')."/$group_unix_name/incoming" ;
216 $filechecks = false ;
218 if ($userfile && is_uploaded_file($userfile['tmp_name']) && util_is_valid_filename($userfile['name'])) {
219 $infile = $userfile['tmp_name'] ;
220 $fname = $userfile['name'] ;
223 } elseif ($userfile && $userfile['error'] != UPLOAD_ERR_OK && $userfile['error'] != UPLOAD_ERR_NO_FILE) {
224 switch ($userfile['error']) {
225 case UPLOAD_ERR_INI_SIZE:
226 case UPLOAD_ERR_FORM_SIZE:
227 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).') ;
229 case UPLOAD_ERR_PARTIAL:
230 return _('The uploaded file was only partially uploaded.') ;
233 return _('Unknown file upload error.') ;
236 } elseif (forge_get_config('use_ftp_uploads') && $ftp_filename && util_is_valid_filename($ftp_filename) && is_file($upload_dir.'/'.$ftp_filename)) {
237 $infile = $upload_dir.'/'.$ftp_filename;
238 $fname = $ftp_filename ;
241 } elseif (forge_get_config('use_manual_uploads') && $manual_filename && util_is_valid_filename($manual_filename) && is_file($incoming.'/'.$manual_filename)) {
242 $infile = $incoming.'/'.$manual_filename ;
243 $fname = $manual_filename ;
246 } elseif ($userfile && $userfile['error'] == UPLOAD_ERR_NO_FILE) {
247 return _('Must select a file.') ;
251 if (strlen($fname) < 3)
252 exit_error('Error',_('Name is too short. It must be at least 3 characters.'));
254 $tmp = tempnam ('', '') ;
255 copy ($infile, $tmp) ;
258 $frsf = new FRSFile($release);
259 if (!$frsf || !is_object($frsf)) {
260 exit_error(_('Could Not Get FRSFile'),'frs');
261 } elseif ($frsf->isError()) {
262 exit_error($frsf->getErrorMessage(),'frs');
264 if (!$frsf->create($fname,$infile,$type_id,$processor_id,$release_date)) {
266 exit_error($frsf->getErrorMessage(),'frs');
271 return _('Unknown file upload error.') ;
275 /* filter utils.php:&ls() output for additional constraints from FRS */
276 function frs_filterfiles($in) {
278 for ($i = 0; $i < count($in); $i++) {
279 if (strlen($in[$i]) < 3)
288 // c-file-style: "bsd"