annotate msite.inc.php @ 143:20893a5442b7

Move some functions to site module, and use them.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 23 Oct 2013 01:21:12 +0300
parents 75cf14ee99a7
children c030c3cf0d80
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 <?
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 //
9
fa9b66f596bb More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
3 // FAPWEB - Demo Party Website System System
33
5bf22431176c Modularize.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
4 // Generic and miscellaneous site support code
9
fa9b66f596bb More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
5 // (C) Copyright 2012 Matti 'ccr' Hamalainen <ccr@tnsp.org>
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 //
9
fa9b66f596bb More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
7
fa9b66f596bb More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
8 // Globals and definitions
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 $errorSet = FALSE;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 $errorMsg = "";
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
12 define("VT_STR", 1);
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
13 define("VT_INT", 2);
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
14 define("VT_BOOL", 3);
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
15 define("VT_TEXT", 4);
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
16
51
7bdf89601ba0 Work on session stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
17 define("SESS_USER", "user");
7bdf89601ba0 Work on session stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
18 define("SESS_ADMIN", "admin");
7bdf89601ba0 Work on session stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
19
139
75cf14ee99a7 More work on party information system.
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
20 define("SMODE_ROTATE", 1);
75cf14ee99a7 More work on party information system.
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
21 define("SMODE_COMPO", 2);
75cf14ee99a7 More work on party information system.
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
22
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
23
94
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
24 //
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
25 // Different voting modes
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
26 //
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
27 // VOTE_FREELY - Vote keys are not tied to attendees, and do not need to be activated
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
28 define("VOTE_FREELY", 0);
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
29
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
30 // VOTE_ACTIVATE - Vote keys are not tied to attendees, but require manual activation.
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
31 define("VOTE_ACTIVATE", 1);
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
32
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
33 // VOTE_ASSIGN - Keys are tied to attendees, activated by assigning the key to attendee.
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
34 define("VOTE_ASSIGN", 2);
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
35
6edd7d623eab Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
36
32
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
37 if (function_exists("ini_set"))
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
38 {
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
39 // Use cookies to store the session ID on the client side
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
40 @ini_set("session.use_only_cookies", 1);
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
41
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
42 // Disable transparent Session ID support
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
43 @ini_set("session.use_trans_sid", 0);
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
44 }
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
45
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
46
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 function stError($msg)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 global $errorSet, $errorMsg;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 $errorSet = TRUE;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 $errorMsg .= "<li>".$msg."</li>\n";
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 function stCheckHTTPS()
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 return isset($_SERVER["HTTPS"]) && ($_SERVER["HTTPS"] != "" && $_SERVER["HTTPS"] != "off");
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
61 function stSetupCacheControl()
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
62 {
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
63 header("Cache-Control: must-revalidate, no-store, private");
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
64 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
65 }
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
66
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
67
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
68 function stReloadSettings()
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
69 {
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
70 global $siteSettings;
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
71 $res = stExecSQL("SELECT * FROM settings");
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
72 if ($res !== FALSE)
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
73 {
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
74 foreach ($res as $row)
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
75 {
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
76 switch ($row["vtype"])
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
77 {
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
78 case VT_INT: $val = intval($row["vint"]); break;
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
79 case VT_BOOL: $val = intval($row["vint"]) ? true : false; break;
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
80 case VT_STR: $val = $row["vstr"]; break;
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
81 case VT_TEXT: $val = $row["vtext"]; break;
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
82 }
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
83 $siteSettings[$row["key"]] = $val;
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
84 }
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
85 }
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
86 else
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
87 die("Error fetching site settings.");
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
88 }
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
89
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
90
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
91 function stGetSetting($name)
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 {
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
93 global $siteSettings;
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 if (isset($siteSettings[$name]))
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 return $siteSettings[$name];
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 else
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
97 die("No config value for '".$name."'.\n");
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 function stChkSetting($name)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 global $siteSettings;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 return isset($siteSettings[$name]) && $siteSettings[$name];
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107
143
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
108 function stReloadDisplayVars()
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
109 {
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
110 global $displayVars, $displayVarsChanged;
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
111
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
112 $displayVars = array();
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
113 $displayVarsChanged = array();
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
114
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
115 if (($res = stExecSQL("SELECT * FROM displayVars")) !== FALSE)
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
116 {
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
117 foreach ($res as $row)
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
118 {
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
119 switch ($row["vtype"])
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
120 {
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
121 case VT_INT: $val = intval($row["vint"]); break;
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
122 case VT_BOOL: $val = intval($row["vint"]) ? true : false; break;
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
123 case VT_STR: $val = $row["vstr"]; break;
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
124 case VT_TEXT: $val = $row["vtext"]; break;
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
125 }
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
126 $displayVars[$row["key"]] = $val;
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
127 }
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
128 }
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
129 }
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
130
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
131
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
132 function stSaveDisplayVars()
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
133 {
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
134 global $displayVars, $displayVarsChanged;
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
135
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
136 foreach (stExecSQL("SELECT * FROM displayVars") as $item)
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
137 if (isset($displayVarsChanged[$item["key"]]))
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
138 {
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
139 $val = $displayVars[$item["key"]];
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
140 switch ($item["vtype"])
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
141 {
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
142 case VT_INT: $vsql = stPrepareSQL("vint=%d", $val); break;
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
143 case VT_BOOL: $vsql = stPrepareSQL("vint=%d", $val ? 1 : 0); break;
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
144 case VT_STR: $vsql = stPrepareSQL("vstr=%s", $val); break;
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
145 case VT_TEXT: $vsql = stPrepareSQL("vtext=%s", $val); break;
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
146 }
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
147
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
148 $sql = "UPDATE displayVars SET ".$vsql." WHERE key=".$db->quote($item["key"]);
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
149 stExecSQL($sql);
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
150 }
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
151 }
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
152
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
153
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
154 function stGetDisplayVar($name)
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
155 {
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
156 global $displayVars;
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
157 if (isset($displayVars[$name]))
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
158 return $displayVars[$name];
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
159 else
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
160 die("No display var for '".$name."'.\n");
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
161 }
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
162
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
163
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
164 function stSetDisplayVar($name, $value)
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
165 {
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
166 global $displayVars, $displayVarsChanged;
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
167 if (isset($displayVars[$name]))
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
168 {
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
169 $displayVars[$name] = $value;
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
170 $displayVarsChanged[$name] = true;
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
171 }
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
172 else
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
173 die("No display var for '".$name."'.\n");
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
174 }
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
175
20893a5442b7 Move some functions to site module, and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
176
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 function dhentities($str)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 return str_replace(array("&lt;","&gt;"), array("<", ">"), htmlentities($str, ENT_NOQUOTES, "UTF-8"));
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 function chentities($str)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 return htmlentities($str, ENT_NOQUOTES, "UTF-8");
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188
12
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
189 function stGetIDName($name, $id, $prefix = "")
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
190 {
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
191 return
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
192 ($id != "" ? "id=\"".$prefix.$name.$id."\" " : "").
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
193 ($name != "" ? "name=\"".$prefix.$name.$id."\" " : "");
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
194 }
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
195
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
196
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 function stGetFormCheckBoxInput($name, $id, $prefix, $checked, $label, $extra = "")
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 return
12
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
200 "<input ".$extra." type=\"checkbox\" ".stGetIDName($name, $id, $prefix).
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
201 ($checked ? "checked=\"checked\" " : "")." />".
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
202 ($label != "" ? "<label for=\"".$name."\">".$label."</label>" : "");
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205
26
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
206 function stGetFormRadioButtonInput($name, $id, $prefix, $value, $checked, $label, $extra = "")
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
207 {
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
208 return
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
209 "<input ".$extra." type=\"radio\" ".stGetIDName($name, $id, $prefix).
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
210 ($checked ? "checked=\"checked\" " : "")." value=\"".$value."\" />".
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
211 ($label != "" ? "<label for=\"".$name."\">".$label."</label>" : "");
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
212 }
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
213
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
214
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 function stGetFormButtonInput($name, $id, $prefix, $label, $onclick = "")
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 return
12
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
218 "<input type=\"button\" ".stGetIDName($name, $id, $prefix).
26
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
219 "value=\" ".chentities($label)." \" ".
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220 ($onclick != "" ? "onClick=\"".$onclick."\"" : "")." />";
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 function stGetFormTextArea($rows, $cols, $name, $id, $prefix, $value, $extra = "")
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 return
12
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
227 "<textarea ".$extra." ".stGetIDName($name, $id, $prefix).
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
228 "rows=\"".$rows."\" cols=\"".$cols."\">".
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 (isset($value) ? chentities($value) : "").
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230 "</textarea>";
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 function stGetFormTextInput($size, $len, $name, $id, $prefix, $value, $extra = "")
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236 return
12
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
237 "<input ".$extra." type=\"text\" ".stGetIDName($name, $id, $prefix).
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
238 "size=\"".$size."\" maxlength=\"".$len."\"".
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 (isset($value) ? " value=\"".chentities($value)."\"" : "").
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 " />";
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 function stGetFormPasswordInput($name, $id, $prefix)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 return
13
cb4af708e295 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
247 "<input type=\"password\" ".stGetIDName($name, $id, $prefix)." />";
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250
26
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
251 function stGetFormSubmitInput($name, $label, $onclick = "")
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
252 {
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
253 return
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
254 "<input type=\"submit\" name=\"".$name.
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
255 "\" value=\" ".chentities($label)." \" ".
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
256 ($onclick != "" ? "onClick=\"".$onclick."\"" : "")." />";
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
257 }
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
258
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
259
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260 function stGetFormHiddenInput($name, $value)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 {
12
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
262 return
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
263 "<input type=\"hidden\" name=\"".$name.
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
264 "\" value=\"".chentities($value)."\" />";
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267
26
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
268 function stGetFormStart($name, $action = "", $method = "post")
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
269 {
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
270 return
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
271 "<form name=\"".$name."\" action=\"".
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
272 ($action != "" ? $action : $name).
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
273 "\" method=\"".$method."\">\n";
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
274 }
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
275
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
276
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 function stGetTDEditTextItem($edit, $size, $len, $name, $id, $prefix, $value, $extra = "")
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279 return
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 "<td class=\"".$name."\">".
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 ($edit ? stGetFormTextInput($size, $len, $name, $id, $prefix, $value, $extra) : chentities($value)).
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 "</td>";
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286 function stPrintFormTextInput($text1, $text2, $size, $len, $name, $extra="")
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288 echo " <tr><th>".chentities($text1)."</th><td>".
15
ea0f98a0bed8 Fix some issues and bugs caused by recent changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 13
diff changeset
289 stGetFormTextInput($size, $len, $name, "", "", stGetRequestItem($name), $extra).
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290 "</td><td>".chentities($text2)."</td></tr>\n";
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294 function stPrintFormHiddenInput($name, $value)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 echo " ".stGetFormHiddenInput($name, $value)."\n";
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300 function stChkDataItem($name)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302 return !isset($_REQUEST[$name]) || strlen(trim($_REQUEST[$name])) < 1;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
303 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 function stChkRequestItem($name)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308 return isset($_REQUEST[$name]);
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312 function stGetRequestItem($name, $default = "")
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
313 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
314 return isset($_REQUEST[$name]) ? trim($_REQUEST[$name]) : $default;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318 function stGetDRequestItem($name, $default = "")
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320 return trim(urldecode(stGetRequestItem($name, $default)));
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324 function stLogSQLError($sql)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326 global $db;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327 error_log("SQL error ".implode("; ", $db->errorInfo())." in statement \"".$sql."\"");
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
330
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331 function stConnectSQLDB()
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333 global $db;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
334 try {
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
335 $db = new PDO(stGetSetting("sqlDB"));
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 catch (PDOException $e) {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338 error_log("Could not connect to SQL database: ".$e->getMessage().".");
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339 return FALSE;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
340 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341 return TRUE;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
345 function stGetSQLParam($type, $value)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
347 global $db;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
348 switch ($type)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
349 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
350 case "d":
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
351 return intval($value);
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
352
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
353 case "s":
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
354 return $db->quote($value);
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355
72
63a6caf59e5c Fix creation of boolean settings, and add '%b' formatter into stPrepareSQL().
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
356 case "b":
63a6caf59e5c Fix creation of boolean settings, and add '%b' formatter into stPrepareSQL().
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
357 return intval($value) ? 1 : 0;
63a6caf59e5c Fix creation of boolean settings, and add '%b' formatter into stPrepareSQL().
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
358
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
359 case "D":
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
360 return intval(stGetRequestItem($value));
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362 case "S":
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363 return $db->quote(stGetDRequestItem($value));
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365 case "Q":
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366 return $db->quote(stripslashes(stGetDRequestItem($value)));
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368 case "B":
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
369 return intval(stGetRequestItem($value)) ? 1 : 0;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
370 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
371 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
372
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
374 function stPrepareSQL()
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
375 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376 $argc = func_num_args();
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377 $argv = func_get_args();
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
378 if ($argc < 1)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
379 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
380 error_log("Invalid stPrepareSQL() call, no arguments!");
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
381 return FALSE;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382 }
87
3da47d3e6a3c Remove a function, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
383
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384 $fmt = $argv[0];
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
385 $len = strlen($fmt);
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
386 $sql = "";
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
387 $argn = 1;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
388 $pos = 0;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
389 while ($pos < $len)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391 if ($fmt[$pos] == "%")
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
393 if ($argn < $argc)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
394 $sql .= stGetSQLParam($fmt[++$pos], $argv[$argn++]);
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395 else
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
396 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
397 error_log("Invalid SQL statement format string '".$fmt.
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
398 "', not enough parameters specified (".$argn." of ".$argc.")");
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
399 return FALSE;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
400 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
401 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
402 else
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
403 $sql .= $fmt[$pos];
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
404 $pos++;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
405 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
406
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
407 return $sql;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
408 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
409
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
410
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
411 function stPrepareSQLUpdate($table, $cond, $pairs)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
412 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
413 $sql = array();
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
414 foreach ($pairs as $name => $attr)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
415 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
416 $sql[] = $name."=".stGetSQLParam($attr, $name);
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418 return
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419 "UPDATE ".$table." SET ".implode(",", $sql).
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420 ($cond != "" ? " ".$cond : "");
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
422
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
423
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
424 function stExecSQL($sql)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
425 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
426 global $db;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
427 if (($res = $db->query($sql)) !== FALSE)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
428 return $res;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429 else
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
431 stLogSQLError($sql);
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
432 stError("Oh noes! SQL error #23!");
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
433 return FALSE;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
434 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
435 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
436
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
437
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
438 function stFetchSQL($sql)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
439 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
440 global $db;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441 if (($res = $db->query($sql)) !== FALSE)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
442 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
443 return $res->fetch();
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
444 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
445 else
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
446 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
447 stLogSQLError($sql);
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
448 stError("Oh noes! SQL error #31!");
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
449 return FALSE;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
450 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
451 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
452
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
453
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
454 function stFetchSQLColumn($sql, $column = 0)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
455 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
456 global $db;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
457 if (($res = $db->query($sql)) !== FALSE)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
458 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
459 return $res->fetchColumn($column);
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
460 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
461 else
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
462 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
463 stLogSQLError($sql);
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
464 stError("Oh noes! SQL error #81!");
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
465 return FALSE;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
466 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
467 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
468
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
469
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
470 //
37
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
471 // Site-specific common functions .. these should be elsewhere
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
472 //
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
473 function stPrintAttendee($item, $row, $edit, $eclass = "")
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
474 {
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
475 $id = $item["id"];
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
476 $prefix = "at";
71
d74fb8cf0062 Adjust attendee output again, we're separating vote keys from there once more. Durr.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
477 echo " <tr class=\"".($row % 2 == 1 ? "rodd" : "reven")."\" id=\"attendee".$id."\">";
53
71256605546b More work on admin interface.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
478
71
d74fb8cf0062 Adjust attendee output again, we're separating vote keys from there once more. Durr.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
479 echo
37
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
480 stGetTDEditTextItem(FALSE, 20, 40, "name", $id, $prefix, $item["name"]).
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
481 stGetTDEditTextItem(FALSE, 20, 40, "groups", $id, $prefix, $item["groups"]).
71
d74fb8cf0062 Adjust attendee output again, we're separating vote keys from there once more. Durr.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
482 "<td class=\"regtime\">".date("d.m. H:i", $item["regtime"])."</td>".
37
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
483 stGetTDEditTextItem($edit, 30, 64, "oneliner", $id, $prefix, $item["oneliner"], "autocomplete=\"off\"");
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
484
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
485 if ($edit)
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
486 {
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
487 echo
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
488 stGetTDEditTextItem($edit, 20, 40, "email", $id, $prefix, $item["email"], "autocomplete=\"off\"").
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
489 "<td>".
71
d74fb8cf0062 Adjust attendee output again, we're separating vote keys from there once more. Durr.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
490 "<button class=\"button\" id=\"atupd".$id."\" type=\"button\" onclick=\"updateAttendee(".$id.")\"> Upd </button>".
d74fb8cf0062 Adjust attendee output again, we're separating vote keys from there once more. Durr.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
491 "<button class=\"button\" id=\"atdel".$id."\" type=\"button\" onclick=\"deleteAttendee(".$id.")\"> Del </button>".
d74fb8cf0062 Adjust attendee output again, we're separating vote keys from there once more. Durr.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
492 "</td>";
37
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
493 }
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
494
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
495 echo "</tr>\n";
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
496 }
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
497
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
498
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
499 function stPrintNewsItem($item, $edit = "")
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
500 {
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
501 echo
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
502 "<div class=\"newsitem\" id=\"news".$item["id"]."\">\n".
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
503 " <h2>".chentities($item["title"])."</h2>\n".
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
504 " <div class=\"text\">".dhentities($item["text"])."</div>\n".
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
505 " <div class=\"sig\">-- ".chentities($item["author"])."<br />".
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
506 date("d M Y / H:i", $item["utime"]).
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
507 $edit."</div>\n".
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
508 "</div>\n";
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
509 }
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
510
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
511
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
512 function stGetCompoList($fvisible, $fvoting = FALSE)
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
513 {
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
514 global $compos;
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
515
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
516 // Get entries and competitions into an array structure
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
517 $sql = "SELECT * FROM compos";
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
518 if ($fvisible || $fvoting)
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
519 {
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
520 $sql .= " WHERE ".implode(" AND ", array($fvisible ? "visible<>0" : "", $fvoting ? "voting<>0" : ""));
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
521 }
121
73608dc4123f Add a tiny weeny comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
522
73608dc4123f Add a tiny weeny comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
523 // Get the data
37
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
524 foreach (stExecSQL($sql) as $compo)
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
525 {
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
526 $id = $compo["id"];
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
527
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
528 $compos[$compo["id"]] = array(
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
529 "name" => $compo["name"],
109
9a3f0ba4d72b Add showAuthors to collected compo data set by stGetCompoList().
Matti Hamalainen <ccr@tnsp.org>
parents: 103
diff changeset
530 "showAuthors" => $compo["showAuthors"],
37
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
531 "entries" => array()
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
532 );
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
533
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
534 $sql = stPrepareSQL("SELECT * FROM entries WHERE compo_id=%d", $id);
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
535 foreach (stExecSQL($sql) as $entry)
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
536 {
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
537 $compos[$id]["entries"][$entry["id"]] = $entry;
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
538 }
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
539 }
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
540 }
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
541
238c73840b61 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
542
69
30a4420e85ab stGenerateUserKey() simply returns a generated key now (string) or FALSE if
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
543 function stGenerateUserKey()
65
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
544 {
69
30a4420e85ab stGenerateUserKey() simply returns a generated key now (string) or FALSE if
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
545 global $db;
99
2169c3177f47 Limit the vote key character space even more.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
546 $keyChars = "abdefghjkmnpqrstwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789";
65
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
547
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
548 while (TRUE)
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
549 {
69
30a4420e85ab stGenerateUserKey() simply returns a generated key now (string) or FALSE if
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
550 // Generate one randomized keycode
65
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
551 $key = "";
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
552 for ($n = 0; $n < stGetSetting("userKeyLength"); $n++)
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
553 $key .= $keyChars[rand() % strlen($keyChars)];
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
554
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
555 // Check if it already exists, to avoid duplicates
69
30a4420e85ab stGenerateUserKey() simply returns a generated key now (string) or FALSE if
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
556 // We need custom query code here, because stFetchSQLColumn()
30a4420e85ab stGenerateUserKey() simply returns a generated key now (string) or FALSE if
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
557 // won't work due to it returning FALSE in error cases.
87
3da47d3e6a3c Remove a function, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
558 $sql = stPrepareSQL("SELECT * FROM votekeys WHERE key=%s", $key);
65
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
559 if (($res = @$db->query($sql)) !== FALSE)
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
560 {
69
30a4420e85ab stGenerateUserKey() simply returns a generated key now (string) or FALSE if
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
561 // Did we get results?
65
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
562 if ($res->fetchColumn() === FALSE)
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
563 {
69
30a4420e85ab stGenerateUserKey() simply returns a generated key now (string) or FALSE if
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
564 // Nope, return key
30a4420e85ab stGenerateUserKey() simply returns a generated key now (string) or FALSE if
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
565 return $key;
65
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
566 }
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
567 }
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
568 else
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
569 {
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
570 stLogSQLError($sql);
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
571 return FALSE;
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
572 }
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
573 }
72b22729ae7e Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
574 }
66
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
575
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
576
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
577 function stSetStatus($val, $msg)
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
578 {
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
579 global $statusSet;
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
580 if (!$statusSet)
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
581 {
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
582 header("Status: ".$val." ".$msg);
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
583 }
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
584 $statusSet = TRUE;
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
585 }
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
586
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
587
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
588 function stExecSQLCond($sql, $okmsg)
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
589 {
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
590 if (($res = stExecSQL($sql)) !== FALSE)
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
591 {
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
592 if ($okmsg != "")
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
593 stSetStatus(200, $okmsg);
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
594 return $res;
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
595 }
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
596 else
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
597 {
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
598 stSetStatus(900, "Error in SQL execution.");
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
599 return FALSE;
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
600 }
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
601 }
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
602
230aacc22cb4 Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
603
103
c6b9041078ec Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
604 function stCheckRegistrationAvailable()
c6b9041078ec Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
605 {
c6b9041078ec Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
606 global $maxAttendeesHard, $maxAttendeesSoft, $numAttendees;
c6b9041078ec Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
607
c6b9041078ec Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
608 $maxAttendeesHard = stGetSetting("maxAttendeesHard");
c6b9041078ec Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
609 $maxAttendeesSoft = stGetSetting("maxAttendeesSoft");
c6b9041078ec Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
610 if (($numAttendees = stFetchSQLColumn("SELECT COUNT(*) FROM attendees")) === FALSE)
c6b9041078ec Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
611 $numAttendees = 0;
c6b9041078ec Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
612
c6b9041078ec Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
613 return stChkSetting("allowRegister") && ($maxAttendeesHard <= 0 || $numAttendees < $maxAttendeesHard);
c6b9041078ec Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
614 }
135
eecac02579c4 Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
615
eecac02579c4 Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
616
eecac02579c4 Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
617 function stStrChop($str, $len)
eecac02579c4 Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
618 {
eecac02579c4 Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
619 if (strlen($str) > $len)
eecac02579c4 Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
620 $s = substr($str, 0, $len - 3)."...";
eecac02579c4 Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
621 else
eecac02579c4 Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
622 $s = $str;
eecac02579c4 Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
623 return sprintf("%-".$len."s", $s);
eecac02579c4 Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
624 }
eecac02579c4 Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
625
eecac02579c4 Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
626
eecac02579c4 Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
627
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
628 ?>