annotate msite.inc.php @ 35:c969f9e8264a

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 02 Jan 2013 04:37:31 +0200
parents 5bf22431176c
children 238c73840b61
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
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
17
32
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
18 if (function_exists("ini_set"))
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
19 {
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
20 // Use cookies to store the session ID on the client side
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
21 @ini_set("session.use_only_cookies", 1);
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
22
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
23 // Disable transparent Session ID support
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
24 @ini_set("session.use_trans_sid", 0);
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
25 }
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
26
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
27
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 function stError($msg)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 global $errorSet, $errorMsg;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 $errorSet = TRUE;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 $errorMsg .= "<li>".$msg."</li>\n";
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 function stCheckHTTPS()
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 return isset($_SERVER["HTTPS"]) && ($_SERVER["HTTPS"] != "" && $_SERVER["HTTPS"] != "off");
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
42 function stSetupCacheControl()
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
43 {
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
44 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
45 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
46 }
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
47
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
48
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
49 function stReloadSettings()
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
50 {
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
51 global $siteSettings;
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
52 $res = stExecSQL("SELECT * FROM settings");
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
53 if ($res !== FALSE)
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
54 {
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
55 foreach ($res as $row)
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
56 {
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
57 switch ($row["vtype"])
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
58 {
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
59 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
60 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
61 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
62 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
63 }
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
64 $siteSettings[$row["key"]] = $val;
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
65 }
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
66 }
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
67 else
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
68 die("Error fetching site settings.");
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
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
71
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
72 function stGetSetting($name)
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 {
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
74 global $siteSettings;
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 if (isset($siteSettings[$name]))
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 return $siteSettings[$name];
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 else
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
78 die("No config value for '".$name."'.\n");
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 function stChkSetting($name)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 global $siteSettings;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 return isset($siteSettings[$name]) && $siteSettings[$name];
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 function dhentities($str)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 return str_replace(array("&lt;","&gt;"), array("<", ">"), htmlentities($str, ENT_NOQUOTES, "UTF-8"));
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 function chentities($str)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 return htmlentities($str, ENT_NOQUOTES, "UTF-8");
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
12
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
101 function stGetIDName($name, $id, $prefix = "")
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
102 {
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
103 return
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
104 ($id != "" ? "id=\"".$prefix.$name.$id."\" " : "").
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
105 ($name != "" ? "name=\"".$prefix.$name.$id."\" " : "");
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
106 }
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
107
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
108
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 function stGetFormCheckBoxInput($name, $id, $prefix, $checked, $label, $extra = "")
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 return
12
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
112 "<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
113 ($checked ? "checked=\"checked\" " : "")." />".
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
114 ($label != "" ? "<label for=\"".$name."\">".$label."</label>" : "");
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117
26
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
118 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
119 {
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
120 return
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
121 "<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
122 ($checked ? "checked=\"checked\" " : "")." value=\"".$value."\" />".
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
123 ($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
124 }
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
125
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
126
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 function stGetFormButtonInput($name, $id, $prefix, $label, $onclick = "")
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 return
12
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
130 "<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
131 "value=\" ".chentities($label)." \" ".
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 ($onclick != "" ? "onClick=\"".$onclick."\"" : "")." />";
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 function stGetFormTextArea($rows, $cols, $name, $id, $prefix, $value, $extra = "")
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 return
12
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
139 "<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
140 "rows=\"".$rows."\" cols=\"".$cols."\">".
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 (isset($value) ? chentities($value) : "").
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 "</textarea>";
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 function stGetFormTextInput($size, $len, $name, $id, $prefix, $value, $extra = "")
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 return
12
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
149 "<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
150 "size=\"".$size."\" maxlength=\"".$len."\"".
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 (isset($value) ? " value=\"".chentities($value)."\"" : "").
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 " />";
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 function stGetFormPasswordInput($name, $id, $prefix)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 return
13
cb4af708e295 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
159 "<input type=\"password\" ".stGetIDName($name, $id, $prefix)." />";
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162
26
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
163 function stGetFormSubmitInput($name, $label, $onclick = "")
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
164 {
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
165 return
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
166 "<input type=\"submit\" name=\"".$name.
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
167 "\" value=\" ".chentities($label)." \" ".
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
168 ($onclick != "" ? "onClick=\"".$onclick."\"" : "")." />";
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
169 }
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
170
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
171
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 function stGetFormHiddenInput($name, $value)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 {
12
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
174 return
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
175 "<input type=\"hidden\" name=\"".$name.
358534308c61 Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
176 "\" value=\"".chentities($value)."\" />";
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179
26
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
180 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
181 {
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
182 return
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
183 "<form name=\"".$name."\" action=\"".
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
184 ($action != "" ? $action : $name).
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
185 "\" method=\"".$method."\">\n";
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
186 }
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
187
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
188
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 function stGetTDEditTextItem($edit, $size, $len, $name, $id, $prefix, $value, $extra = "")
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 return
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 "<td class=\"".$name."\">".
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 ($edit ? stGetFormTextInput($size, $len, $name, $id, $prefix, $value, $extra) : chentities($value)).
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 "</td>";
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 function stPrintFormTextInput($text1, $text2, $size, $len, $name, $extra="")
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 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
201 stGetFormTextInput($size, $len, $name, "", "", stGetRequestItem($name), $extra).
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 "</td><td>".chentities($text2)."</td></tr>\n";
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
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 function stPrintFormHiddenInput($name, $value)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 echo " ".stGetFormHiddenInput($name, $value)."\n";
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 function stPrintAttendee($item, $row, $edit, $eclass = "")
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 $id = $item["id"];
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 $prefix = "at";
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 echo " ".
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 "<tr class=\"".($row % 2 == 1 ? "rodd" : "reven").$eclass."\" id=\"attendee".$id."\">".
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 stGetTDEditTextItem(FALSE, 20, 40, "name", $id, $prefix, $item["name"]).
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 stGetTDEditTextItem(FALSE, 20, 40, "groups", $id, $prefix, $item["groups"]).
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220 "<td class=\"regtime\">".date("d M Y / H:i", $item["regtime"])."</td>".
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 stGetTDEditTextItem($edit, 30, 64, "oneliner", $id, $prefix, $item["oneliner"], "autocomplete=\"off\"");
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 if ($edit)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 echo
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 stGetTDEditTextItem($edit, 20, 40, "email", $id, $prefix, $item["email"], "autocomplete=\"off\"").
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 "<td>".
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 "<button class=\"button\" id=\"atupd".$id."\" type=\"button\" onclick=\"updateAttendee(".$id.")\">Update</button>".
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 "<button class=\"button\" id=\"atdel".$id."\" type=\"button\" onclick=\"deleteAttendee(".$id.")\">Delete</button>".
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230 "</td>";
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 echo "</tr>\n";
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 function stPrintNewsItem($item, $edit = "")
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 echo
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 "<div class=\"newsitem\" id=\"news".$item["id"]."\">\n".
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241 " <h2>".chentities($item["title"])."</h2>\n".
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 " <div class=\"text\">".dhentities($item["text"])."</div>\n".
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 " <div class=\"sig\">-- ".chentities($item["author"])."<br />".
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 date("d M Y / H:i", $item["utime"]).
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 $edit."</div>\n".
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 "</div>\n";
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247 }
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 function stChkDataItem($name)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 return !isset($_REQUEST[$name]) || strlen(trim($_REQUEST[$name])) < 1;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256 function stChkRequestItem($name)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 return isset($_REQUEST[$name]);
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 function stGetRequestItem($name, $default = "")
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264 return isset($_REQUEST[$name]) ? trim($_REQUEST[$name]) : $default;
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
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 function stGetDRequestItem($name, $default = "")
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270 return trim(urldecode(stGetRequestItem($name, $default)));
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
273
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274 function stLogSQLError($sql)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 global $db;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 error_log("SQL error ".implode("; ", $db->errorInfo())." in statement \"".$sql."\"");
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 function stConnectSQLDB()
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283 global $db;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 try {
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
285 $db = new PDO(stGetSetting("sqlDB"));
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287 catch (PDOException $e) {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288 error_log("Could not connect to SQL database: ".$e->getMessage().".");
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289 return FALSE;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291 return TRUE;
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
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295 function stGetSQLParam($type, $value)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297 global $db;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298 switch ($type)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300 case "d":
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301 return intval($value);
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
303 case "s":
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304 return $db->quote($value);
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 case "D":
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307 return intval(stGetRequestItem($value));
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309 case "S":
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 return $db->quote(stGetDRequestItem($value));
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312 case "Q":
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
313 return $db->quote(stripslashes(stGetDRequestItem($value)));
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
314
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315 case "B":
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316 return intval(stGetRequestItem($value)) ? 1 : 0;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321 function stPrepareSQL()
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323 $argc = func_num_args();
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324 $argv = func_get_args();
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325 if ($argc < 1)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327 error_log("Invalid stPrepareSQL() call, no arguments!");
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 return FALSE;
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 $fmt = $argv[0];
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332 $len = strlen($fmt);
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333 $sql = "";
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
334 $argn = 1;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335 $pos = 0;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 while ($pos < $len)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338 if ($fmt[$pos] == "%")
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
340 if ($argn < $argc)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341 $sql .= stGetSQLParam($fmt[++$pos], $argv[$argn++]);
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342 else
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 error_log("Invalid SQL statement format string '".$fmt.
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
345 "', not enough parameters specified (".$argn." of ".$argc.")");
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346 return FALSE;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
347 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
348 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
349 else
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
350 $sql .= $fmt[$pos];
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
351 $pos++;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
352 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
353
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
354 return $sql;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
356
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
357
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358 function stPrepareSQLUpdate($table, $cond, $pairs)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
359 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
360 $sql = array();
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361 foreach ($pairs as $name => $attr)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363 $sql[] = $name."=".stGetSQLParam($attr, $name);
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365 return
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366 "UPDATE ".$table." SET ".implode(",", $sql).
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367 ($cond != "" ? " ".$cond : "");
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
369
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
370
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
371 function stExecSQL($sql)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
372 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373 global $db;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
374 if (($res = $db->query($sql)) !== FALSE)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
375 return $res;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376 else
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
378 stLogSQLError($sql);
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
379 stError("Oh noes! SQL error #23!");
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
380 return FALSE;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
381 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
383
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
385 function stFetchSQL($sql)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
386 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
387 global $db;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
388 if (($res = $db->query($sql)) !== FALSE)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
389 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390 return $res->fetch();
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 else
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
393 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
394 stLogSQLError($sql);
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395 stError("Oh noes! SQL error #31!");
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
396 return FALSE;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
397 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
398 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
399
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
400
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
401 function stFetchSQLColumn($sql, $column = 0)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
402 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
403 global $db;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
404 if (($res = $db->query($sql)) !== FALSE)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
405 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
406 return $res->fetchColumn($column);
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
407 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
408 else
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
409 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
410 stLogSQLError($sql);
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
411 stError("Oh noes! SQL error #81!");
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
412 return FALSE;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
413 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
414 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
415
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
416
24
5bc8bd5c7ecc Make voting toggle for individual compos.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
417 function stGetCompoList($fvisible, $fvoting = FALSE)
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419 global $compos;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421 // Get entries and competitions into an array structure
24
5bc8bd5c7ecc Make voting toggle for individual compos.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
422 $sql = "SELECT * FROM compos";
5bc8bd5c7ecc Make voting toggle for individual compos.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
423 if ($fvisible || $fvoting)
5bc8bd5c7ecc Make voting toggle for individual compos.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
424 {
5bc8bd5c7ecc Make voting toggle for individual compos.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
425 $sql .= " WHERE ".implode(" AND ", array($fvisible ? "visible<>0" : "", $fvoting ? "voting<>0" : ""));
5bc8bd5c7ecc Make voting toggle for individual compos.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
426 }
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
427 foreach (stExecSQL($sql) as $compo)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
428 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429 $id = $compo["id"];
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
431 $compos[$compo["id"]] = array(
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
432 "name" => $compo["name"],
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
433 "entries" => array()
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 $sql = stPrepareSQL("SELECT * FROM entries WHERE compo_id=%d", $id);
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
437 foreach (stExecSQL($sql) as $entry)
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
438 {
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
439 $compos[$id]["entries"][$entry["id"]] = $entry;
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
440 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
442 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
443
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
444
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
445 //
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
446 // CLI utility helper functions
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
447 //
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
448 function stCArg($index)
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
449 {
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
450 global $argc, $argv;
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
451 if ($index < $argc)
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
452 return $argv[$index];
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
453 else
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
454 return FALSE;
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
455 }
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
456
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
457 function stCArgLC($index)
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
458 {
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
459 global $argc, $argv;
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
460 if ($index < $argc)
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
461 return strtolower($argv[$index]);
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
462 else
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
463 return FALSE;
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
464 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
465
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
466
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
467 function stCSQLError($sql)
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
468 {
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
469 global $db;
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
470 die("Error executing SQL query: ".implode("; ", $db->errorInfo())." in statement \"".$sql."\"\n");
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
471 exit;
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
472 }
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
473
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
474
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
475 function stCheckCLIOrDie()
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
476 {
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
477 if (php_sapi_name() != "cli" || !empty($_SERVER["REMOTE_ADDR"]))
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
478 {
8
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
479 header("Status: 404 Not Found");
4c5f651aa107 Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
480 die();
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
481 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
482 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
483
32
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
484
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
485 ?>