CMS  Version 3.9
show.inc
Go to the documentation of this file.
1 <?
2 /**************************************************************
3 
4  Copyright (c) 2010 Sonjara, Inc
5 
6  Permission is hereby granted, free of charge, to any person
7  obtaining a copy of this software and associated documentation
8  files (the "Software"), to deal in the Software without
9  restriction, including without limitation the rights to use,
10  copy, modify, merge, publish, distribute, sublicense, and/or sell
11  copies of the Software, and to permit persons to whom the
12  Software is furnished to do so, subject to the following
13  conditions:
14 
15  The above copyright notice and this permission notice shall be
16  included in all copies or substantial portions of the Software.
17 
18  Except as contained in this notice, the name(s) of the above
19  copyright holders shall not be used in advertising or otherwise
20  to promote the sale, use or other dealings in this Software
21  without prior written authorization.
22 
23  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
25  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30  OTHER DEALINGS IN THE SOFTWARE.
31 
32 *****************************************************************/
33 
34 Fakoli::using("document", "user", "fileshare");
35 
36 $document_id = checkNumeric($_GET["document_id"]);
37 
39 
40 $library = $document->DocumentLibrary();
41 
42 if (!checkRole($library->allow_access) && !$library->allowAccess())
43 {
44  if (!$user || !$user->user_id)
45  {
47  }
48  else
49  {
50  Fakoli::end("Access Denied");
51  }
52 }
53 
54 if (!checkRole($document->allow_access))
55 {
56  if (!$user || !$user->user_id)
57  {
59  }
60  else
61  {
62  Fakoli::end("Access Denied");
63  }
64 }
65 
67 $d->document_id = $document_id;
68 $d->user_id = ($user) ? $user->user_id : 0;
69 $d->save();
70 
71 //TODO: Folder level security
72 
73 trace("Download: document filename to download {$document->file}", 3);
74 
75 $filepath = sanitizePath($library->getLibraryDirectory() . DIRECTORY_SEPARATOR . $document->file);
76 
77 $mimeType = DocumentHandler::getDocMimeType($document->file);
78 
79 trace("Download: opening document with filepath {$filepath} and mimeType {$mimeType}", 3);
80 
81 trace("Download: opened document {$document_id}", 3);
82 
83 header("Pragma: private");
84 header("Content-Disposition: inline;filename=\"" . basename($document->file) . "\"");
85 header("Cache-Control: must-revalidate");
86 header("Content-Type: $mimeType");
87 
89 {
90  header("X-SendFile: $filepath");
91  return;
92 }
93 else
94 {
95  $f = fopen($filepath, "r");
96 
97  $size = filesize($filepath);
98  header("Content-Length: $size");
99 
100  fpassthru($f);
101  fclose($f);
102 }
103 
104 session_write_close();
105 ?>
$f
Definition: download.inc:46
This class maps the publication table.
Definition: document.inc:43
static detectXSendFileSupport()
Determines whether the mod_xsendfile extension is present, when running under Apache.
Definition: core.inc:834
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
static end($message="")
Use this method to terminate execution of a script instead of using the php keywords exit() or die().
Definition: core.inc:1149
static redirectToLogin()
Redirect the user to the login page.
Definition: login.inc:526
global $user
$filepath
Definition: show.inc:75
$document_id
Definition: show.inc:36
$document
Definition: show.inc:38
$mimeType
Definition: show.inc:77
if(!checkRole($library->allow_access) &&! $library->allowAccess()) if(!checkRole($document->allow_access)) $d
Definition: show.inc:66
$size
Definition: show.inc:97
$library
Definition: show.inc:40