3 # Copyright (c) STMicroelectronics, 2005. All Rights Reserved.
5 # Originally written by Jean-Philippe Giola, 2005
7 # This file is a part of codendi.
9 # codendi is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # codendi is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along
20 # with this program; if not, write to the Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 require_once 'env.inc.php';
26 require_once 'pre.php';
27 require_once 'preplugins.php';
28 require_once 'mailman/include/MailmanList.class.php';
29 require_once 'mailman/www/mailman_utils.php';
30 require_once(dirname(__FILE__).'/../include/ForumML_Attachment.class.php');
32 $plugin_manager = PluginManager::instance();
33 $p = $plugin_manager->getPluginByName('forumml');
34 if ($p && $plugin_manager->isPluginAvailable($p) && $p->isAllowed()) {
35 $request = HTTPRequest::instance();
36 $current_user=UserManager::instance()->getCurrentUser();
37 $groupId = $request->getValidated('group_id', 'UInt', 0);
39 $vList = new Valid_UInt('list');
41 // Checks 'list' parameter
42 if (! $request->valid($vList)) {
43 exit_error('Error','No list specified');
45 $list_id = $request->get('list');
46 $list = new MailmanList($groupId,$list_id);
47 if (!isLogged() || ($list->isPublic()!=1 && !$current_user->isMember($groupId))) {
48 exit_error(_('Error'),_('You are not allowed to access this page'));
50 if ($list->getStatus() !=3) {
51 exit_error(_('Error'),_('This list is not active'));
56 $vTopic = new Valid_UInt('topic');
58 if ($request->valid($vTopic)) {
59 $topic = $request->get('topic');
63 $attchmentId = $request->getValidated('id', 'UInt', 0);
65 $fmlAttch = new ForumML_Attachment();
66 $attch = $fmlAttch->getById($attchmentId);
67 echo $attch['file_path'];
68 if ( file_exists($attch['file_path'])) {
70 header('Content-disposition: filename="'.$attch['file_name'].'"');
71 header("Content-Type: ".$attch['type']);
72 header("Content-Transfer-Encoding: ".$attch['type']);
73 if ($attch['file_size'] > 0) {
74 header("Content-Length: ".$attch['file_size']);
76 header("Pragma: no-cache");
77 header("Cache-Control: must-revalidate, post-check=0, pre-check=0, public");
79 readfile($attch['file_path']);
82 $feedback.= _('Error: Attachment not found');
85 $feedback.= _('Error: Missing parameter');
87 htmlRedirect('/plugins/forumml/message.php?group_id='.$groupId.'&list='.$list_id.'&topic='.$topic);
89 header('Location: '.get_server_url());