summaryrefslogtreecommitdiff
path: root/cgi-bin/sketchbook.pl
blob: 8103bd4bcce5e599a9a43f63db24761fc06d3424 (plain)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/perl

$|=1;

srand;

use strict;

use Apache::Request;
use Apache::Constants qw(REDIRECT);
use Benchmark::Timer;
use HTML::Template;
use MIME::Base64 qw(encode_base64 decode_base64);
use Compose::local_lib;
use Compose::db_connection;

my $r = Apache::Request->new(Apache->request);

my $local_lib = new Compose::local_lib();

my $dbh_aes = new Compose::db_connection('localhost','aes','apache','webconnect');
my $dbh = new Compose::db_connection('localhost','designer','apache','webconnect');

my $form;
foreach my $key (sort $r->param) {
        $form->{$key} = $local_lib->fix_spaces($r->param($key));
}

my %cookiejar = Apache::Cookie->new($r)->parse;
my $newcookie = Apache::Cookie->new($r);
my ($user, $password, %user_info, $qry, %user_info, %cookie_hash);

##################################################
#
unless ($cookiejar{'Site'}) {
        print "Content-type: text/html\n";
        print "Status: 403\n";
	exit(0);
##################################################
#
} elsif ( $cookiejar{'Site'} ) {

       	my @values = $cookiejar{'Site'}->value;

	for (my $i=0;$i<scalar(@values);$i+=2) {
            #print qq($values[$i] : $values[$i+1] <br>);
        	$cookie_hash{$values[$i]} = $values[$i+1];
	}

	($user, $password) = split /:/, decode_base64($cookie_hash{'Cookie'}), 2;

	$qry = qq(select * from admin_user_info where user_name="$user");

	%user_info = $dbh_aes->queryRawDB($qry);

	if ($user_info{'0'}{'id'} eq "") {
		print "Content-type: text/html\n";
                print "Status: 403\n";
                exit(0);
        } 
}



##################################################
#
if ($r->method() eq "GET") {

	$qry = qq(select * from sketchbook where user_id="$user_info{'0'}{'id'}");
	
	my %data = $dbh->queryRawDB($qry);

	if ($data{'0'}{'sketchbook_data'} eq "") {
		if ($form->{'interactive'} ne "false") {
			$r->send_http_header('text/html');
			print qq{
				<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
				<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
					<head>
						<title>Logged In</title>
						<style type="text/css">
							\@import url('http://www.santoprene.com/siteflow2/styles/designer.css');
							\@import url('http://materialexperience.santoprene.com/specialcases.css');
						</style>
					</head>

					<body>
						<h1>Logged In</h1>
						<p>Thanks for logging in. You can close this card now.</p>
					</body>
				</html><div style="display: none">
			};
		} else {
			print "Status: 404\n";
			print "Content-type: text/html\n";		
		}
		
	    exit(0);
	} else {
		if ($form->{'interactive'} ne "false") {
			$r->send_http_header('text/html');
			print qq{
				<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
				<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
					<head>
						<title>Logged In</title>
						<style type="text/css">
							\@import url('http://www.santoprene.com/siteflow2/styles/designer.css');
							\@import url('http://materialexperience.santoprene.com/specialcases.css');
						</style>
					</head>

					<body>
						<h1>Logged In</h1>
						<p>Thanks for logging in. You can close this card now.</p>
					</body>
				</html><div style="display: none">
			};
		} else {
			$r->send_http_header('text/javascript');
			print "$data{'0'}{'sketchbook_data'}\n";
		}
	}

##################################################
#
} else {

	if ($form->{'sketchbook_data'} ne "") {
		my $upd = qq(delete from sketchbook where user_id="$user_info{'0'}{'id'}");
        $dbh->updateDB($upd);

		$form->{'sketchbook_data'} =~ s/"/\\"/g;

		my $upd = qq(insert into sketchbook (sketchbook_data,user_id) values ("$form->{'sketchbook_data'}","$user_info{'0'}{'id'}"));
		my %data = $dbh->queryRawDB($upd);
	}

	print "Content-type: text/html\n\n";

}