/
mod_cookies.php
180 lines (147 loc) · 5.8 KB
/
mod_cookies.php
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?
require_once("common.php");
function make_cookies(){
global $stylestatus; global $css_file;
global $layoutstatus; global $layout;
global $languageChoice;
$DEFAULT_STYLE = "css/galapagos.css";
if(isset($_REQUEST['chosenstyle']))
$styleselect = $_REQUEST['chosenstyle'];
if(isset($_REQUEST['chosenlayout']))
$layoutselect= $_REQUEST['chosenlayout'];
if(isset($_REQUEST['languageChoice']))
$languageChoice = $_REQUEST['languageChoice'];
// A cookie exists
if(isset($_COOKIE['calcuttagutta'])){
$cookie_contents = explode("-", $_COOKIE['calcuttagutta']);
if(isset($styleselect)){
$new_cookie = $_REQUEST['chosenstyle'] . "-";
$css_file = $_REQUEST['chosenstyle'];
addDebug("Ny stil: " . $_REQUEST['chosenstyle']);
}else{
addDebug("Gammel stil: " . $cookie_contents[0]);
$css_file = $cookie_contents[0];
$new_cookie = $cookie_contents[0] . "-";
}
if(isset($layoutselect)){
$layoutstatus .= "Ny layout: " . $_REQUEST['chosenlayout'];
addDebug("Ny layout: " . $_REQUEST['chosenlayout']);
$new_cookie .= $_REQUEST['chosenlayout'] . "-";
$layout = $_REQUEST['chosenlayout'];
}else{
$layoutstatus .= "Gammel layout: " . $cookie_contents[1] . " hele cookie: ";
addDebug("Gammel layout: " . $cookie_contents[1] . " hele cookie: ");
foreach($cookie_contents as $innhold){
$layoutstatus .= $innhold;
}
$layout = $cookie_contents[1];
// Must handle old cookies, which say "weblog" instead of "1"
if ($layout == "weblog"){
$layout = "1";
}
$new_cookie .= $layout . "-";
}
// Check for language preference
if(isset($_REQUEST['languageChoice'])){
$layoutstatus .= "--had cookie, had choice in request--";
addDebug("--had cookie, had choice in request--");
// If a new is specified - use that one and add it to cookie
$languageChoice = $_REQUEST['languageChoice'];
} else {
// No specified - try to get from cookie
$languageChoice = $cookie_contents[2];
if($languageChoice == null){
$layoutstatus .= "--had cookie, had no language set--";
addDebug("--had cookie, had no language set--");
// Set blank if cookie didn't have any goodies
$languageChoice = "-1";
} else {
$layoutstatus .= "--had cookie, had language set in it to " . $languageChoice . "--";
addDebug("--had cookie, had language set in it to " . $languageChoice . "--");
}
}
addDebug("Adding languageChoice " . $languageChoice . " to cookie");
$new_cookie .= $languageChoice . "-";
addDebug("Old cookie updated contents: " . $new_cookie);
setcookie ("calcuttagutta",$new_cookie, time()+60*60*24*30);
}else{
// There's no cookie, create one
if(isset($styleselect)){
$stylestatus .= "Ny stil og cookie: " . $_REQUEST['chosenstyle'];
$new_cookie = $_REQUEST['chosenstyle'] . "-";
$css_file = $_REQUEST['chosenstyle'];
}else{
$new_cookie = $DEFAULT_STYLE . "-";
//$stylestatus .= "Default stil: " . $_REQUEST['chosenstyle'];
$css_file = $DEFAULT_STYLE;
}
if(isset($layoutselect)){
$layoutstatus .= "Ny layout og cookie: " . $_REQUEST['chosenlayout'];
$new_cookie .= $_REQUEST['chosenlayout'] . "-";
$layout = $_REQUEST['chosenlayout'];
}else{
$new_cookie .= "1" . "-";
//$layoutstatus .= "Default layout: " . $_REQUEST['chosenlayout'];
$layout = "1";
}
if(isset($_REQUEST['languageChoice'])){
$languageChoice = isset($_REQUEST['languageChoice']);
$new_cookie .= $_REQUEST['languageChoice'];
} else {
$languageChoice = '-1';
$new_cookie .= '-1';
}
addDebug("Brand new cookie contents: " . $new_cookie);
setcookie ("calcuttagutta",$new_cookie, time()+60*60*24*30);
}
}
function mod_pick_style(){
$styles = array("Standardstil" => "css/aviscms.css",
"Thormod" => "http://www.stud.ntnu.no/~nordram/thorstyle.css",
"Heimegut" => "http://www.festsiden.org/_tore/heimegut.css",
"Blogspot" => "http://www.festsiden.org/_tore/blogspot.css",
"Galápagos" => "css/galapagos.css");
global $stylestatus, $layout, $css_file, $languageChoice;
echo '<div class="options"><div class="optionsheader">Stilvelger</div>';
form_start_get();
echo '<select name="chosenstyle">';
foreach ($styles as $stylename => $stylefile){
if($stylefile == $css_file){
echo '<option value="' . $stylefile . '" selected="selected">' . $stylename . '</option>';
}else{
echo '<option value="' . $stylefile. '">' . $stylename . '</option>';
}
}
echo "</select>";
form_hidden("module_right_2", "mod_pick_style");
form_hidden("styleselect", "styleselect");
echo "<br/>";echo "<br/>";
echo '<div class="optionsheader">Velg layout</div>';
?>
<select name="chosenlayout">
<?
echo '<option value="1">En kolonne</option>';
echo '<option value="2">To kolonner</option>';
echo '<option value="3">Tre kolonner</option>';
echo '<option value="4">Fire kolonne</option>';
?>
</select>
<?
form_hidden("redirect", "true");
form_hidden("module_right_2", "mod_pick_style");
form_hidden("layoutselect", "layoutselect");
echo "<br/>";echo "<br/>";
echo '<div class="optionsheader">Velg språk</div>';
$arrayWithAllLanguageIds = getAllLanguageIds();
$arrayWithAllLanguageNames = getAllLanguageNames();
// Add a choice for viewing articles in all languages
array_unshift($arrayWithAllLanguageIds, "-1");
array_unshift($arrayWithAllLanguageNames, "Alle språk");
debug("fra cookie..:" . $languageChoice . "!");
debug("fra cookie..:" . $_REQUEST['languageChoice'] . "!");
form_dropdown("languageChoice", $arrayWithAllLanguageIds, $arrayWithAllLanguageNames, $languageChoice + 1);
echo "<br/>";echo "<br/>";
form_submit("submitlayout", "Endre");
form_end();
echo "</div>";
}