Mercurial > hg > fapweb
annotate msite.inc.php @ 135:eecac02579c4
Move stChop() to site module and rename it to stStrChop().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 22 Oct 2013 21:55:12 +0300 |
parents | 73608dc4123f |
children | 75cf14ee99a7 |
rev | line source |
---|---|
0 | 1 <? |
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 | 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 | 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 | 9 $errorSet = FALSE; |
10 $errorMsg = ""; | |
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 | 17 define("SESS_USER", "user"); |
18 define("SESS_ADMIN", "admin"); | |
19 | |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
20 |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
21 // |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
22 // Different voting modes |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
23 // |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
24 // 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
|
25 define("VOTE_FREELY", 0); |
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_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
|
28 define("VOTE_ACTIVATE", 1); |
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_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
|
31 define("VOTE_ASSIGN", 2); |
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 |
32 | 34 if (function_exists("ini_set")) |
35 { | |
36 // Use cookies to store the session ID on the client side | |
37 @ini_set("session.use_only_cookies", 1); | |
38 | |
39 // Disable transparent Session ID support | |
40 @ini_set("session.use_trans_sid", 0); | |
41 } | |
42 | |
43 | |
0 | 44 function stError($msg) |
45 { | |
46 global $errorSet, $errorMsg; | |
47 $errorSet = TRUE; | |
48 $errorMsg .= "<li>".$msg."</li>\n"; | |
49 } | |
50 | |
51 | |
52 function stCheckHTTPS() | |
53 { | |
54 return isset($_SERVER["HTTPS"]) && ($_SERVER["HTTPS"] != "" && $_SERVER["HTTPS"] != "off"); | |
55 } | |
56 | |
57 | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
58 function stSetupCacheControl() |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
59 { |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
60 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
|
61 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
|
62 } |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
63 |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
64 |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
65 function stReloadSettings() |
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 global $siteSettings; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
68 $res = stExecSQL("SELECT * FROM settings"); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
69 if ($res !== FALSE) |
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 foreach ($res as $row) |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
72 { |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
73 switch ($row["vtype"]) |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
74 { |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
75 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
|
76 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
|
77 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
|
78 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
|
79 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
80 $siteSettings[$row["key"]] = $val; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
81 } |
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 else |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
84 die("Error fetching site settings."); |
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 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
87 |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
88 function stGetSetting($name) |
0 | 89 { |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
90 global $siteSettings; |
0 | 91 if (isset($siteSettings[$name])) |
92 return $siteSettings[$name]; | |
93 else | |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
94 die("No config value for '".$name."'.\n"); |
0 | 95 } |
96 | |
97 | |
98 function stChkSetting($name) | |
99 { | |
100 global $siteSettings; | |
101 return isset($siteSettings[$name]) && $siteSettings[$name]; | |
102 } | |
103 | |
104 | |
105 function dhentities($str) | |
106 { | |
107 return str_replace(array("<",">"), array("<", ">"), htmlentities($str, ENT_NOQUOTES, "UTF-8")); | |
108 } | |
109 | |
110 | |
111 function chentities($str) | |
112 { | |
113 return htmlentities($str, ENT_NOQUOTES, "UTF-8"); | |
114 } | |
115 | |
116 | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
117 function stGetIDName($name, $id, $prefix = "") |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
118 { |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
119 return |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
120 ($id != "" ? "id=\"".$prefix.$name.$id."\" " : ""). |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
121 ($name != "" ? "name=\"".$prefix.$name.$id."\" " : ""); |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
122 } |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
123 |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
124 |
0 | 125 function stGetFormCheckBoxInput($name, $id, $prefix, $checked, $label, $extra = "") |
126 { | |
127 return | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
128 "<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
|
129 ($checked ? "checked=\"checked\" " : "")." />". |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
130 ($label != "" ? "<label for=\"".$name."\">".$label."</label>" : ""); |
0 | 131 } |
132 | |
133 | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
134 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
|
135 { |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
136 return |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
137 "<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
|
138 ($checked ? "checked=\"checked\" " : "")." value=\"".$value."\" />". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
139 ($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
|
140 } |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
141 |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
142 |
0 | 143 function stGetFormButtonInput($name, $id, $prefix, $label, $onclick = "") |
144 { | |
145 return | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
146 "<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
|
147 "value=\" ".chentities($label)." \" ". |
0 | 148 ($onclick != "" ? "onClick=\"".$onclick."\"" : "")." />"; |
149 } | |
150 | |
151 | |
152 function stGetFormTextArea($rows, $cols, $name, $id, $prefix, $value, $extra = "") | |
153 { | |
154 return | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
155 "<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
|
156 "rows=\"".$rows."\" cols=\"".$cols."\">". |
0 | 157 (isset($value) ? chentities($value) : ""). |
158 "</textarea>"; | |
159 } | |
160 | |
161 | |
162 function stGetFormTextInput($size, $len, $name, $id, $prefix, $value, $extra = "") | |
163 { | |
164 return | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
165 "<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
|
166 "size=\"".$size."\" maxlength=\"".$len."\"". |
0 | 167 (isset($value) ? " value=\"".chentities($value)."\"" : ""). |
168 " />"; | |
169 } | |
170 | |
171 | |
172 function stGetFormPasswordInput($name, $id, $prefix) | |
173 { | |
174 return | |
13 | 175 "<input type=\"password\" ".stGetIDName($name, $id, $prefix)." />"; |
0 | 176 } |
177 | |
178 | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
179 function stGetFormSubmitInput($name, $label, $onclick = "") |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
180 { |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
181 return |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
182 "<input type=\"submit\" name=\"".$name. |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
183 "\" value=\" ".chentities($label)." \" ". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
184 ($onclick != "" ? "onClick=\"".$onclick."\"" : "")." />"; |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
185 } |
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 |
0 | 188 function stGetFormHiddenInput($name, $value) |
189 { | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
190 return |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
191 "<input type=\"hidden\" name=\"".$name. |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
192 "\" value=\"".chentities($value)."\" />"; |
0 | 193 } |
194 | |
195 | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
196 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
|
197 { |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
198 return |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
199 "<form name=\"".$name."\" action=\"". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
200 ($action != "" ? $action : $name). |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
201 "\" method=\"".$method."\">\n"; |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
202 } |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
203 |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
204 |
0 | 205 function stGetTDEditTextItem($edit, $size, $len, $name, $id, $prefix, $value, $extra = "") |
206 { | |
207 return | |
208 "<td class=\"".$name."\">". | |
209 ($edit ? stGetFormTextInput($size, $len, $name, $id, $prefix, $value, $extra) : chentities($value)). | |
210 "</td>"; | |
211 } | |
212 | |
213 | |
214 function stPrintFormTextInput($text1, $text2, $size, $len, $name, $extra="") | |
215 { | |
216 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
|
217 stGetFormTextInput($size, $len, $name, "", "", stGetRequestItem($name), $extra). |
0 | 218 "</td><td>".chentities($text2)."</td></tr>\n"; |
219 } | |
220 | |
221 | |
222 function stPrintFormHiddenInput($name, $value) | |
223 { | |
224 echo " ".stGetFormHiddenInput($name, $value)."\n"; | |
225 } | |
226 | |
227 | |
228 function stChkDataItem($name) | |
229 { | |
230 return !isset($_REQUEST[$name]) || strlen(trim($_REQUEST[$name])) < 1; | |
231 } | |
232 | |
233 | |
234 function stChkRequestItem($name) | |
235 { | |
236 return isset($_REQUEST[$name]); | |
237 } | |
238 | |
239 | |
240 function stGetRequestItem($name, $default = "") | |
241 { | |
242 return isset($_REQUEST[$name]) ? trim($_REQUEST[$name]) : $default; | |
243 } | |
244 | |
245 | |
246 function stGetDRequestItem($name, $default = "") | |
247 { | |
248 return trim(urldecode(stGetRequestItem($name, $default))); | |
249 } | |
250 | |
251 | |
252 function stLogSQLError($sql) | |
253 { | |
254 global $db; | |
255 error_log("SQL error ".implode("; ", $db->errorInfo())." in statement \"".$sql."\""); | |
256 } | |
257 | |
258 | |
259 function stConnectSQLDB() | |
260 { | |
261 global $db; | |
262 try { | |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
263 $db = new PDO(stGetSetting("sqlDB")); |
0 | 264 } |
265 catch (PDOException $e) { | |
266 error_log("Could not connect to SQL database: ".$e->getMessage()."."); | |
267 return FALSE; | |
268 } | |
269 return TRUE; | |
270 } | |
271 | |
272 | |
273 function stGetSQLParam($type, $value) | |
274 { | |
275 global $db; | |
276 switch ($type) | |
277 { | |
278 case "d": | |
279 return intval($value); | |
280 | |
281 case "s": | |
282 return $db->quote($value); | |
283 | |
72
63a6caf59e5c
Fix creation of boolean settings, and add '%b' formatter into stPrepareSQL().
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
284 case "b": |
63a6caf59e5c
Fix creation of boolean settings, and add '%b' formatter into stPrepareSQL().
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
285 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
|
286 |
0 | 287 case "D": |
288 return intval(stGetRequestItem($value)); | |
289 | |
290 case "S": | |
291 return $db->quote(stGetDRequestItem($value)); | |
292 | |
293 case "Q": | |
294 return $db->quote(stripslashes(stGetDRequestItem($value))); | |
295 | |
296 case "B": | |
297 return intval(stGetRequestItem($value)) ? 1 : 0; | |
298 } | |
299 } | |
300 | |
301 | |
302 function stPrepareSQL() | |
303 { | |
304 $argc = func_num_args(); | |
305 $argv = func_get_args(); | |
306 if ($argc < 1) | |
307 { | |
308 error_log("Invalid stPrepareSQL() call, no arguments!"); | |
309 return FALSE; | |
310 } | |
87 | 311 |
0 | 312 $fmt = $argv[0]; |
313 $len = strlen($fmt); | |
314 $sql = ""; | |
315 $argn = 1; | |
316 $pos = 0; | |
317 while ($pos < $len) | |
318 { | |
319 if ($fmt[$pos] == "%") | |
320 { | |
321 if ($argn < $argc) | |
322 $sql .= stGetSQLParam($fmt[++$pos], $argv[$argn++]); | |
323 else | |
324 { | |
325 error_log("Invalid SQL statement format string '".$fmt. | |
326 "', not enough parameters specified (".$argn." of ".$argc.")"); | |
327 return FALSE; | |
328 } | |
329 } | |
330 else | |
331 $sql .= $fmt[$pos]; | |
332 $pos++; | |
333 } | |
334 | |
335 return $sql; | |
336 } | |
337 | |
338 | |
339 function stPrepareSQLUpdate($table, $cond, $pairs) | |
340 { | |
341 $sql = array(); | |
342 foreach ($pairs as $name => $attr) | |
343 { | |
344 $sql[] = $name."=".stGetSQLParam($attr, $name); | |
345 } | |
346 return | |
347 "UPDATE ".$table." SET ".implode(",", $sql). | |
348 ($cond != "" ? " ".$cond : ""); | |
349 } | |
350 | |
351 | |
352 function stExecSQL($sql) | |
353 { | |
354 global $db; | |
355 if (($res = $db->query($sql)) !== FALSE) | |
356 return $res; | |
357 else | |
358 { | |
359 stLogSQLError($sql); | |
360 stError("Oh noes! SQL error #23!"); | |
361 return FALSE; | |
362 } | |
363 } | |
364 | |
365 | |
366 function stFetchSQL($sql) | |
367 { | |
368 global $db; | |
369 if (($res = $db->query($sql)) !== FALSE) | |
370 { | |
371 return $res->fetch(); | |
372 } | |
373 else | |
374 { | |
375 stLogSQLError($sql); | |
376 stError("Oh noes! SQL error #31!"); | |
377 return FALSE; | |
378 } | |
379 } | |
380 | |
381 | |
382 function stFetchSQLColumn($sql, $column = 0) | |
383 { | |
384 global $db; | |
385 if (($res = $db->query($sql)) !== FALSE) | |
386 { | |
387 return $res->fetchColumn($column); | |
388 } | |
389 else | |
390 { | |
391 stLogSQLError($sql); | |
392 stError("Oh noes! SQL error #81!"); | |
393 return FALSE; | |
394 } | |
395 } | |
396 | |
397 | |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
398 // |
37 | 399 // Site-specific common functions .. these should be elsewhere |
400 // | |
401 function stPrintAttendee($item, $row, $edit, $eclass = "") | |
402 { | |
403 $id = $item["id"]; | |
404 $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
|
405 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
|
406 |
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
|
407 echo |
37 | 408 stGetTDEditTextItem(FALSE, 20, 40, "name", $id, $prefix, $item["name"]). |
409 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
|
410 "<td class=\"regtime\">".date("d.m. H:i", $item["regtime"])."</td>". |
37 | 411 stGetTDEditTextItem($edit, 30, 64, "oneliner", $id, $prefix, $item["oneliner"], "autocomplete=\"off\""); |
412 | |
413 if ($edit) | |
414 { | |
415 echo | |
416 stGetTDEditTextItem($edit, 20, 40, "email", $id, $prefix, $item["email"], "autocomplete=\"off\""). | |
417 "<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
|
418 "<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
|
419 "<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
|
420 "</td>"; |
37 | 421 } |
422 | |
423 echo "</tr>\n"; | |
424 } | |
425 | |
426 | |
427 function stPrintNewsItem($item, $edit = "") | |
428 { | |
429 echo | |
430 "<div class=\"newsitem\" id=\"news".$item["id"]."\">\n". | |
431 " <h2>".chentities($item["title"])."</h2>\n". | |
432 " <div class=\"text\">".dhentities($item["text"])."</div>\n". | |
433 " <div class=\"sig\">-- ".chentities($item["author"])."<br />". | |
434 date("d M Y / H:i", $item["utime"]). | |
435 $edit."</div>\n". | |
436 "</div>\n"; | |
437 } | |
438 | |
439 | |
440 function stGetCompoList($fvisible, $fvoting = FALSE) | |
441 { | |
442 global $compos; | |
443 | |
444 // Get entries and competitions into an array structure | |
445 $sql = "SELECT * FROM compos"; | |
446 if ($fvisible || $fvoting) | |
447 { | |
448 $sql .= " WHERE ".implode(" AND ", array($fvisible ? "visible<>0" : "", $fvoting ? "voting<>0" : "")); | |
449 } | |
121 | 450 |
451 // Get the data | |
37 | 452 foreach (stExecSQL($sql) as $compo) |
453 { | |
454 $id = $compo["id"]; | |
455 | |
456 $compos[$compo["id"]] = array( | |
457 "name" => $compo["name"], | |
109
9a3f0ba4d72b
Add showAuthors to collected compo data set by stGetCompoList().
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
458 "showAuthors" => $compo["showAuthors"], |
37 | 459 "entries" => array() |
460 ); | |
461 | |
462 $sql = stPrepareSQL("SELECT * FROM entries WHERE compo_id=%d", $id); | |
463 foreach (stExecSQL($sql) as $entry) | |
464 { | |
465 $compos[$id]["entries"][$entry["id"]] = $entry; | |
466 } | |
467 } | |
468 } | |
469 | |
470 | |
69
30a4420e85ab
stGenerateUserKey() simply returns a generated key now (string) or FALSE if
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
471 function stGenerateUserKey() |
65
72b22729ae7e
Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
472 { |
69
30a4420e85ab
stGenerateUserKey() simply returns a generated key now (string) or FALSE if
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
473 global $db; |
99
2169c3177f47
Limit the vote key character space even more.
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
474 $keyChars = "abdefghjkmnpqrstwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789"; |
65
72b22729ae7e
Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
475 |
72b22729ae7e
Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
476 while (TRUE) |
72b22729ae7e
Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
477 { |
69
30a4420e85ab
stGenerateUserKey() simply returns a generated key now (string) or FALSE if
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
478 // Generate one randomized keycode |
65
72b22729ae7e
Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
479 $key = ""; |
72b22729ae7e
Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
480 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
|
481 $key .= $keyChars[rand() % strlen($keyChars)]; |
72b22729ae7e
Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
482 |
72b22729ae7e
Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
483 // 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
|
484 // 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
|
485 // won't work due to it returning FALSE in error cases. |
87 | 486 $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
|
487 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
|
488 { |
69
30a4420e85ab
stGenerateUserKey() simply returns a generated key now (string) or FALSE if
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
489 // Did we get results? |
65
72b22729ae7e
Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
490 if ($res->fetchColumn() === FALSE) |
72b22729ae7e
Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
491 { |
69
30a4420e85ab
stGenerateUserKey() simply returns a generated key now (string) or FALSE if
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
492 // Nope, return key |
30a4420e85ab
stGenerateUserKey() simply returns a generated key now (string) or FALSE if
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
493 return $key; |
65
72b22729ae7e
Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
494 } |
72b22729ae7e
Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
495 } |
72b22729ae7e
Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
496 else |
72b22729ae7e
Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
497 { |
72b22729ae7e
Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
498 stLogSQLError($sql); |
72b22729ae7e
Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
499 return FALSE; |
72b22729ae7e
Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
500 } |
72b22729ae7e
Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
501 } |
72b22729ae7e
Add function for generating vote keys into site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
502 } |
66
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
503 |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
504 |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
505 function stSetStatus($val, $msg) |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
506 { |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
507 global $statusSet; |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
508 if (!$statusSet) |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
509 { |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
510 header("Status: ".$val." ".$msg); |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
511 } |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
512 $statusSet = TRUE; |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
513 } |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
514 |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
515 |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
516 function stExecSQLCond($sql, $okmsg) |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
517 { |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
518 if (($res = stExecSQL($sql)) !== FALSE) |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
519 { |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
520 if ($okmsg != "") |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
521 stSetStatus(200, $okmsg); |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
522 return $res; |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
523 } |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
524 else |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
525 { |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
526 stSetStatus(900, "Error in SQL execution."); |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
527 return FALSE; |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
528 } |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
529 } |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
530 |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
531 |
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
|
532 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
|
533 { |
c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
534 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
|
535 |
c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
536 $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
|
537 $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
|
538 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
|
539 $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
|
540 |
c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
541 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
|
542 } |
135
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
543 |
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
544 |
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
545 function stStrChop($str, $len) |
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
546 { |
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
547 if (strlen($str) > $len) |
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
548 $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
|
549 else |
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
550 $s = $str; |
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
551 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
|
552 } |
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
553 |
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
554 |
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
555 |
0 | 556 ?> |