-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocument.cgi
More file actions
executable file
·116 lines (94 loc) · 2.32 KB
/
document.cgi
File metadata and controls
executable file
·116 lines (94 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/perl -w
# Copyright(c) 2003-2007 Robert L. Brown. This is licensed software
# only to be used with an explicit right-to-use license from the
# copyright holder.
use strict;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard *table *ol *ul *Tr *td *li *img *p -nosticky);
require "globals.pl";
use ParamTable;
use Layout;
use Login;
use Database;
use Application;
use Utility;
use Document;
Application::Init();
# In must-log-in mode, make sure we're logged in
my $mustLogIn = Param::getValueByName('must-log-in');
if ( $mustLogIn && ref $mustLogIn ) {
$mustLogIn = $mustLogIn->{'value'};
}
if ( $mustLogIn && !isLoggedIn() ) {
doMustLogin(url(-absolute => 1, -query=>1));;
}
if ( param("op") ) {
my $op = param("op");
SWITCH: {
$op eq "go" and do {
doGo();
last SWITCH;
};
};
} else {
doFirstPage();
}
exit(0);
sub doFirstPage
{
ConnectToDatabase();
my $id = param("id");
if ( !$id ) {
print doDocumentError("Error: Cannot call document.cgi without a document id", 1);
return;
}
## Validate that the candidate is not hidden
my $document = Document::getRecord($id);
if ( !$document ) {
print doDocumentError("Document #$id does not exist.", 1);
return;
}
my $candidate = Candidate::getRecord($$document{'candidate_id'});
if ( !$candidate ) {
print doDocumentError("The candidate for document #$id does not exist.");
return;
}
if ( $$candidate{'hide'} && !isAdmin() ) {
print header;
Layout::doAccessDenied();
return;
}
## Document exists
## Candidate exists
## Candidate's document can be viewed
## Therefore, deliver the document
my $header;
if ( $$document{'filename'} =~ /.*\.pdf/ ) {
$header = header({
-type=>"application/pdf",
});
} else {
$header = header({
-type=>"application/x-download",
-attachment=>$$document{'filename'},
});
}
print $header, $$document{'data'};
return;
}
sub doDocumentError
{
my ($str,$needHeader) = (@_);
my $result = "";
if ( $needHeader ) {
$result .= header;
}
$result .= start_html;
$result .= p($str);
$result .= end_html;
return $result;
}
#sub doGo
#{
# print header;
#}