copytheme.pl
Copying Source is Forbidden
132 lines of code
1
#!/usr/local/bin/perl
2
3
# must have's!
4
use strict;
5
use warnings;
6
use CGI::Carp qw(fatalsToBrowser);
7
use DBI;
8
use URI::Escape;
9
10
use lib "/var/www/html/Pm";
11
12
use Html qw(pre_html_header header);
13
use Bc_chef qw(cookie_get);
14
use Bc_misc qw(get_param);
15
use Bc_sql qw(get_constant
16
sql_execute
17
user_exists
18
$QUERY_PAGE
19
$QUERY_UID
20
$LOGGEDIN
21
theme_exists
22
get_theme_data
23
new_tid
24
25
$DB
26
);
27
use Security qw(banned get_login);
28
use Redir qw(error_redir notice_redir);
29
use User qw(isUserAdmin $USER_DATA);
30
31
32
my $DEBUG = 0;
33
if (not user_exists($LOGGEDIN) or
34
banned($LOGGEDIN) or
35
not isUserAdmin($LOGGEDIN)) {
36
my $msg = "Access Denied";
37
if ($DEBUG) { $msg .= " (copytheme.pl)"; }
38
print error_redir("/", $msg);
39
40
exit 1;
41
}
42
43
my $tid = get_param("tid");
44
my $output = "";
45
46
if ($DEBUG) {
47
$output = pre_html_header();
48
$output .= header("Copy Theme", 0, 0, 0, "Copies a theme"); # this is JUST a placeholder
49
$output .= "<button class=yellow_button type=button onclick='document.location.reload();'>R</button><hr>\n";
50
}
51
52
if (theme_exists($tid)) {
53
# okay, the theme exists
54
# now grab its data
55
# generate a new TID
56
# rename the theme to the new TID value
57
# and save it!
58
my $td = get_theme_data($tid);
59
60
if ($DEBUG) {
61
# print out the orig theme data
62
$output .= int(keys %$td) . " keys <small>\n";
63
foreach my $key (sort keys %$td) {
64
$output .= "$key = $td->{$key}, \n";
65
}
66
$output .= "</small><hr>\n";
67
}
68
69
$td->{ID} = new_tid();
70
$td->{name} = "{EDITOR}" . $td->{ID};
71
72
my $sql = "insert into themes values(";
73
$sql .= $DB->quote($td->{ID}) . ", ";
74
$sql .= $DB->quote($td->{name}) . ", ";
75
$sql .= $DB->quote($td->{bg_clr}) . ", ";
76
$sql .= $DB->quote($td->{body_clr_dark}) . ", ";
77
$sql .= $DB->quote($td->{body_clr}) . ", ";
78
$sql .= $DB->quote($td->{gradient_light}) . ", ";
79
$sql .= $DB->quote($td->{gradient_dark}) . ", ";
80
$sql .= $DB->quote($td->{link_clr}) . ", ";
81
$sql .= $DB->quote($td->{title_clr}) . ", ";
82
$sql .= $DB->quote($td->{subtitle_clr}) . ", ";
83
$sql .= $DB->quote($td->{select_bg}) . ", ";
84
$sql .= $DB->quote($td->{select_clr}) . ", ";
85
$sql .= $DB->quote($td->{input_bg}) . ", ";
86
$sql .= $DB->quote($td->{input_clr}) . ", ";
87
$sql .= $DB->quote($td->{bg_image}) . ", ";
88
$sql .= $DB->quote($td->{bold_clr}) . ", ";
89
$sql .= $DB->quote($td->{borders_clr}) . ", ";
90
$sql .= $DB->quote($td->{button_bg}) . ", ";
91
$sql .= $DB->quote($td->{button_clr}) . ", ";
92
$sql .= $DB->quote($td->{connect_SUBTITLE_TITLE}) . ", ";
93
$sql .= $DB->quote($td->{connect_SUBTITLE_TITLE_SHADOWS}) . ", ";
94
$sql .= $DB->quote($td->{premium}) . ", ";
95
$sql .= $DB->quote($td->{title_shadow_clr}) . ", ";
96
$sql .= $DB->quote($td->{subtitle_shadow_clr}) . ", ";
97
$sql .= $DB->quote($td->{input_box_shadow_clr}) . ", ";
98
$sql .= $DB->quote($td->{input_text_shadow_clr}) . ", ";
99
$sql .= $DB->quote($td->{bold_shadow_clr}) . ", ";
100
$sql .= $DB->quote($td->{italic_shadow_clr}) . ", ";
101
$sql .= $DB->quote($td->{cost_dollars}) . ", ";
102
$sql .= $DB->quote($td->{cost_coins});
103
$sql .= ")";
104
105
if ($DEBUG) {
106
$output .= "tid $tid is valid<br>\n";
107
$output .= "new tid: $td->{ID}<br>\n";
108
$output .= "new name: $td->{name}<br>\n";
109
$output .= "sql: $sql<br>\n";
110
$output .= "<hr>\n";
111
$output .= "now this is where we'd normally update the database<br>\n";
112
$output .= "but we're debugging, so updates are NOT performed<br>\n";
113
} else {
114
# insert the new theme data
115
my $success = sql_execute($sql, "copytheme.pl");
116
if ($success)
117
{ $output = notice_redir("theme_editor.pl?tid=$td->{ID}", "Theme copied"); } else
118
{ $output = error_redir("theme_editor.pl?tid=$tid", "Invalid theme ID"); }
119
}
120
} else {
121
# theme theme does not exist!
122
if ($DEBUG)
123
{ $output .= "tid $tid does not exist<br>\n"; } else
124
{ $output = error_redir("theme_editor.pl?tid=$tid", "Invalid theme ID");
125
}
126
}
127
128
if ($DEBUG) { $output .= "</body>\n</html>\n"; }
129
130
print $output;
131
132
exit 1;