Code

Updated locales. Fixed small typos
[gosa.git] / html / get_attachment.php
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2003  Cajus Pollmeier
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
21 /* Basic setup, remove eventually registered sessions */
22 @require_once ("../include/php_setup.inc");
23 @require_once ("functions.inc");
24 @require_once ("class_glpi.inc");
25 session_start ();
27 /* Logged in? Simple security check */
28 if (!isset($_SESSION['ui'])){
29   gosa_log ("Error: get_attachment.php called without session");
30   header ("Location: ../index.php");
31   exit;
32 }
33 $ui= $_SESSION["ui"];
35 $config = $_SESSION['config'];
36 /* Abort class construction, if no db is defined */
37 if(!isset($config->data['SERVERS']['GLPI'])){
38   return;
39 }
42 // Get informations about databse connection
43 $data = $config->data['SERVERS']['GLPI'];
45 // Abort if mysql extension is missing
46 if(!is_callable("mysql_connect")){
47   print _("Can't connect to glpi database, there is no mysl extension available in your php setup.");
48   return;
49 }
51 // Create handle of glpi class, and check if database connection is established
52 $handle = new glpiDB($data['SERVER'],$data['LOGIN'],$data['PASSWORD'],$data['DB']);
54 if(!$handle->is_connected){
55   print _("Can't connect to specified database, please check your glpi configuration.");
56   return;
57 }
59 $att =array();
60 $atts = $handle->getAttachments();
61 $att = $atts[$_GET['id']];
63 if(count($att)== 0){
64   print _("Can't get specified attachment file, there is no entry with this id.");
65   return;
66 }
68 if(!is_readable("/etc/gosa/glpi/".$att['filename'])){
69   print sprintf(_("Can't open file '%s'."),"/etc/gosa/glpi/".$att['filename']);
70 }
71 $data = file_get_contents("/etc/gosa/glpi/".$att['filename']);
73 /* force download dialog */
74 header("Content-type: ".$att['mime']."\n");
75 if (preg_match('/MSIE 5.5/', $HTTP_USER_AGENT) ||
76     preg_match('/MSIE 6.0/', $HTTP_USER_AGENT)) {
77   header('Content-Disposition: filename="'.$att['filename'].'"');
78 } else {
79   header('Content-Disposition: attachment; filename="'.$att['filename'].'"');
80 }
82 header("Content-transfer-encoding: binary\n");
83 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
84 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
85 header("Cache-Control: no-cache");
86 header("Pragma: no-cache");
87 header("Cache-Control: post-check=0, pre-check=0");
90 /* print the tiff image and close the connection */
91 echo "$data";
93 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
94 ?>