5 * Copyright 2010-2011, Franck Villaume - Capgemini
6 * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
7 * http://fusionforge.org
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 require_once '../../env.inc.php';
28 require_once $gfcommon.'include/pre.php';
29 require_once $gfconfig.'plugins/mantisbt/config.php';
31 $arr=explode('/',getStringFromServer('REQUEST_URI'));
33 $idAttachment=$arr[5];
35 if (!session_loggedin()) {
38 $user = session_get_user(); // get the session user
40 if (!$user || !is_object($user)) {
41 exit_error(_('Invalid User'), 'mantisbt');
42 } elseif ( $user->isError() ) {
43 exit_error($user->isError(), 'mantisbt');
44 } elseif ( !$user->isActive()) {
45 exit_error(_('Invalid User not active'), 'mantisbt');
48 $group = group_get_object($group_id);
49 $mantisbt = plugin_get_object('mantisbt');
54 if (!$group->usesPlugin($mantisbt->name)) {//check if the group has the MantisBT plugin active
55 exit_error(sprintf(_('First activate the %s plugin through the Project\'s Admin Interface'), $mantisbt->name), 'home');
57 if ( $group->isError()) {
58 $error_msg .= $group->getErrorMessage();
61 $userperm = $group->getPermission();//we'll check if the user belongs to the group (optional)
62 if ( !$userperm->IsMember()) {
63 exit_permission_denied(_('You are not a member of this project'), 'home');
66 $mantisbtConf = $mantisbt->getMantisBTConf($group_id);
68 $mantisbtUserConf = $mantisbt->getUserConf($user->getID());
69 if ($mantisbtUserConf) {
70 $username = $mantisbtUserConf['user'];
71 $password = $mantisbtUserConf['password'];
74 // no user init ? we shoud force this user to init his account
75 if (!isset($username) || !isset($password)) {
76 $warning_msg = _('Your mantisbt user is not initialized.');
77 session_redirect('/plugins/'.$mantisbt->name.'/?type=user&group_id='.$group_id.'&pluginname='.$mantisbt->name.'&view=inituser&warning_msg='.urlencode($warning_msg));
82 $clientSOAP = new SoapClient($mantisbtConf['url']."/api/soap/mantisconnect.php?wsdl", array('trace'=>true, 'exceptions'=>true));
83 $content = $clientSOAP->__soapCall('mc_issue_attachment_get', array("username" => $username, "password" => $password, "issue_attachment_id" => $idAttachment));
84 } catch (SoapFault $soapFault) {
85 session_redirect('plugins/mantisbt/?type=group&group_id='.$group_id.'&pluginname=mantisbt&error_msg='.urlencode($soapFault->faultstring));
88 header( 'Content-Disposition: filename="'.urlencode($arr[6]).'"' );
89 // filetype is missing.... now.... so we force application/binary
90 header('Content-type: application/binary');
93 exit_missing_param($_SERVER['HTTP_REFERER'], array(_('No idAttachment')), 'mantisbt');