| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
<span class="code-comment"> * function_selects.php |
|---|
| 4 |
* ------------------- |
|---|
| 5 |
* begin : Saturday, Feb 13, 2001 |
|---|
| 6 |
* copyright : (C) 2001 The phpBB Group |
|---|
| 7 |
* email : support@phpbb.com |
|---|
| 8 |
* |
|---|
| 9 |
* $Id: functions_selects.php,v 1.3.2.5 2005/05/06 20:50:11 acydburn Exp $ |
|---|
| 10 |
* |
|---|
| 11 |
* |
|---|
| 12 |
***************************************************************************/ |
|---|
| 13 |
|
|---|
| 14 |
/*************************************************************************** |
|---|
| 15 |
* |
|---|
| 16 |
* This program is free software; you can redistribute it and/or modify |
|---|
| 17 |
* it under the terms of the GNU General Public License as published by |
|---|
| 18 |
* the Free Software Foundation; either version 2 of the License, or |
|---|
| 19 |
* (at your option) any later version. |
|---|
| 20 |
* |
|---|
| 21 |
* |
|---|
| 22 |
***************************************************************************/ |
|---|
| 23 |
|
|---|
| 24 |
// |
|---|
| 25 |
// Pick a language, any language ... |
|---|
| 26 |
// |
|---|
| 27 |
function language_select($default, $select_name = "language", $dirname="languages")</span> |
|---|
| 28 |
<span class="code-keyword">{ |
|---|
| 29 |
global $phpEx, $root_path; |
|---|
| 30 |
|
|---|
| 31 |
$dir = opendir($root_path . $dirname); |
|---|
| 32 |
|
|---|
| 33 |
$lang = array(); |
|---|
| 34 |
while ( $file = readdir($dir) ) |
|---|
| 35 |
{ |
|---|
| 36 |
if (preg_match('#^lang_#i', $file) && !is_file(@realpath($root_path . $dirname . '/' . $file)) && !is_link(@realpath($root_path . $dirname . '/' . $file))) |
|---|
| 37 |
{ |
|---|
| 38 |
$filename = trim(str_replace("lang_", "", $file)); |
|---|
| 39 |
$displayname = preg_replace("/^(.*?)_(.*)$/", "\\1 [ \\2 ]", $filename); |
|---|
| 40 |
$displayname = preg_replace("/\[(.*?)_(.*)\]/", "[ \\1 - \\2 ]", $displayname); |
|---|
| 41 |
$lang[$displayname] = $filename; |
|---|
| 42 |
} |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
closedir($dir); |
|---|
| 46 |
|
|---|
| 47 |
@asort($lang); |
|---|
| 48 |
@reset($lang); |
|---|
| 49 |
|
|---|
| 50 |
$lang_select = '<select name="' . $select_name . '" id="' . $select_name . '">'; |
|---|
| 51 |
while ( list($displayname, $filename) = @each($lang) ) |
|---|
| 52 |
{ |
|---|
| 53 |
$selected = ( utf_strtolower($default) == utf_strtolower($filename) ) ? ' selected="selected"' : ''; |
|---|
| 54 |
$lang_select .= '<option value="' . $filename . '"' . $selected . '>' . ucwords($displayname) . '</option>'; |
|---|
| 55 |
} |
|---|
| 56 |
$lang_select .= '</select>'; |
|---|
| 57 |
|
|---|
| 58 |
return $lang_select; |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
<span class="code-comment">// Pick a template/theme combo, |
|---|
| 63 |
// |
|---|
| 64 |
function style_select($default_style, $select_name = "style", $dirname = "templates")</span> |
|---|
| 65 |
<span class="code-keyword">{ |
|---|
| 66 |
global $db; |
|---|
| 67 |
|
|---|
| 68 |
$sql = "SELECT themes_id, style_name |
|---|
| 69 |
FROM " . THEMES_TABLE . " |
|---|
| 70 |
ORDER BY template_name, themes_id"; |
|---|
| 71 |
$result = $db->sql_query($sql); |
|---|
| 72 |
|
|---|
| 73 |
$style_select = '<select name="' . $select_name . '">'; |
|---|
| 74 |
while ( $row = $db->sql_fetchrow($result) ) |
|---|
| 75 |
{ |
|---|
| 76 |
$selected = ( $row['themes_id'] == $default_style ) ? ' selected="selected"' : ''; |
|---|
| 77 |
|
|---|
| 78 |
$style_select .= '<option value="' . $row['themes_id'] . '"' . $selected . '>' . $row['style_name'] . '</option>'; |
|---|
| 79 |
} |
|---|
| 80 |
$style_select .= "</select>"; |
|---|
| 81 |
|
|---|
| 82 |
return $style_select; |
|---|
| 83 |
} |
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
<span class="code-comment">// Pick a timezone |
|---|
| 87 |
// |
|---|
| 88 |
function tz_select($default, $select_name = 'timezone')</span> |
|---|
| 89 |
<span class="code-keyword">{ |
|---|
| 90 |
global $config, $lang; |
|---|
| 91 |
|
|---|
| 92 |
if ( !isset($default) ) |
|---|
| 93 |
{ |
|---|
| 94 |
$default == doubleval($config['board_timezone']); |
|---|
| 95 |
} |
|---|
| 96 |
$tz_select = '<select name="' . $select_name . '" id="' . $select_name . '">'; |
|---|
| 97 |
|
|---|
| 98 |
foreach ( $lang['tz'] AS $offset => $zone ) |
|---|
| 99 |
{ |
|---|
| 100 |
$selected = ( $offset == $default ) ? ' selected="selected"' : ''; |
|---|
| 101 |
$tz_select .= '<option value="' . $offset . '"' . $selected . '>' . $zone . '</option>'; |
|---|
| 102 |
} |
|---|
| 103 |
$tz_select .= '</select>'; |
|---|
| 104 |
|
|---|
| 105 |
return $tz_select; |
|---|
| 106 |
} |
|---|
| 107 |
|
|---|
| 108 |
function generate_internet_speed( $default = 0, $select_name = '' ) { |
|---|
| 109 |
global $lang; |
|---|
| 110 |
|
|---|
| 111 |
$l_kilobits = utf_ucfirst(utf_strtolower($lang['kilobytes'])); |
|---|
| 112 |
$l_megabits = utf_ucfirst(utf_strtolower($lang['megabytes'])); |
|---|
| 113 |
|
|---|
| 114 |
$up_sp_select = '<select name="' . $select_name . '" id="' . $select_name . '">'; |
|---|
| 115 |
|
|---|
| 116 |
if ( !$default ) { |
|---|
| 117 |
$up_sp_select .= '<option value="">' . $lang['choose'] . '</option>'; |
|---|
| 118 |
} |
|---|
| 119 |
for ( $i = 64; $i <= 960; $i +=64 ) { |
|---|
| 120 |
$n = $i * 1024; |
|---|
| 121 |
$value = $i . ' ' . $l_kilobits . '/' . $lang['seconds_short']; |
|---|
| 122 |
$up_sp_select .= '<option value="' . $n . '"' . ( $default == $n ? ' selected="selected"' : '' ) . '>' . $value . '</option>'; |
|---|
| 123 |
|
|---|
| 124 |
} |
|---|
| 125 |
for ( $i = 1; $i < 101; ++$i ) { |
|---|
| 126 |
if ( $i > 10 ) { |
|---|
| 127 |
$i += 1; |
|---|
| 128 |
} |
|---|
| 129 |
if ( $i > 30 ) { |
|---|
| 130 |
$i += 3; |
|---|
| 131 |
} |
|---|
| 132 |
$n = $i * 1024 * 1024; |
|---|
| 133 |
$value = $i . ' ' . $l_megabits . '/' . $lang['seconds_short']; |
|---|
| 134 |
$up_sp_select .= '<option value="' . $n . '"' . ( $default == $n ? ' selected="selected"' : '' ) . '>' . $value . '</option>'; |
|---|
| 135 |
} |
|---|
| 136 |
$up_sp_select .= '</select>'; |
|---|
| 137 |
|
|---|
| 138 |
return $up_sp_select; |
|---|
| 139 |
} |
|---|
| 140 |
|
|---|
| 141 |
function countries_select ( $default = 0, $select_name = 'country' ) { |
|---|
| 142 |
global $db, $lang; |
|---|
| 143 |
$countries_select = '<select name="' . $select_name . '" id="' . $select_name . '">'; |
|---|
| 144 |
|
|---|
| 145 |
if ( !$default ) { |
|---|
| 146 |
$countries_select .= '<option value="">' . $lang['choose'] . '</option>'; |
|---|
| 147 |
} |
|---|
| 148 |
|
|---|
| 149 |
$sql = 'SELECT id, name FROM ' . COUNTRIES_TABLE . ' ORDER BY name'; |
|---|
| 150 |
$result = $db->sql_query($sql); |
|---|
| 151 |
|
|---|
| 152 |
while ($row = $db->sql_fetchrow($result)) { |
|---|
| 153 |
$countries_select .= '<option value="' . $row['id'] . '"' . ($default == $row['id'] ? ' selected="selected"' : '') . '>' . $row['name'] . '</option>'; |
|---|
| 154 |
} |
|---|
| 155 |
|
|---|
| 156 |
$countries_select .= '</select>'; |
|---|
| 157 |
|
|---|
| 158 |
return $countries_select; |
|---|
| 159 |
} |
|---|
| 160 |
|
|---|
| 161 |
function birthday_select ( $default_year = 0, $default_month = 0, $default_day = 0, $select_name_year = 'year', $select_name_month = 'month', $select_name_day = 'day' ) { |
|---|
| 162 |
global $lang; |
|---|
| 163 |
$year = '<select name="' . $select_name_year . '" id="' . $select_name_year . '">'; |
|---|
| 164 |
if ( !$default_year ) { |
|---|
| 165 |
$year .= '<option value="">---</option>'; |
|---|
| 166 |
} |
|---|
| 167 |
for ( $i = 1920; $i <= (date('Y',time())-13); ++$i ) { |
|---|
| 168 |
$year .= '<option' . ($i == $default_year ?' selected="selected"':'') . '>' . $i . '</option>'; |
|---|
| 169 |
} |
|---|
| 170 |
$year .= '</select>'; |
|---|
| 171 |
|
|---|
| 172 |
$months = array($lang['datetime']['January'], |
|---|
| 173 |
$lang['datetime']['February'], |
|---|
| 174 |
$lang['datetime']['March'], |
|---|
| 175 |
$lang['datetime']['April'], |
|---|
| 176 |
$lang['datetime']['May'], |
|---|
| 177 |
$lang['datetime']['June'], |
|---|
| 178 |
$lang['datetime']['July'], |
|---|
| 179 |
$lang['datetime']['August'], |
|---|
| 180 |
$lang['datetime']['September'], |
|---|
| 181 |
$lang['datetime']['October'], |
|---|
| 182 |
$lang['datetime']['November'], |
|---|
| 183 |
$lang['datetime']['December'] |
|---|
| 184 |
); |
|---|
| 185 |
$month = '<select name="' . $select_name_month . '" id="' . $select_name_month . '">'; |
|---|
| 186 |
if ( !$default_month ) { |
|---|
| 187 |
$month .= '<option value="">---</option>'; |
|---|
| 188 |
} |
|---|
| 189 |
for ( $i = 1; $i <= 12; ++$i ) { |
|---|
| 190 |
$month .= '<option value="'. ( $i < 10 ? '0' . $i : $i ) . '"' . ($i == $default_month ? ' selected="selected"':'') . '>' . ( $months[$i - 1] ) . '</option>'; |
|---|
| 191 |
} |
|---|
| 192 |
$month .= '</select>'; |
|---|
| 193 |
|
|---|
| 194 |
$day = '<select name="' . $select_name_day . '" id="' . $select_name_day . '">'; |
|---|
| 195 |
if ( !$default_day ) { |
|---|
| 196 |
$day .= '<option value="">---</option>'; |
|---|
| 197 |
} |
|---|
| 198 |
for ( $i = 1; $i <= 31; ++$i ) { |
|---|
| 199 |
$day .= '<option' . ($i == $default_day ? ' selected="selected"':'') . '>' . ( $i < 10 ? '0' . $i : $i ) . '</option>'; |
|---|
| 200 |
} |
|---|
| 201 |
$day .='</select>'; |
|---|
| 202 |
|
|---|
| 203 |
return $year . $month . $day; |
|---|
| 204 |
} |
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
function user_class_select ($default = '-', $select_name = 'class', $max_class = UC_SYSOP) {</span> |
|---|
| 208 |
<span class="code-keyword"> global $lang; |
|---|
| 209 |
|
|---|
| 210 |
$select = '<select name="' . $select_name . '" id="' . $select_name . '">'; |
|---|
| 211 |
if ( $default == '-' ) { |
|---|
| 212 |
$select .= '<option value="-">(' . $lang['choose'] . ')</option>'; |
|---|
| 213 |
} |
|---|
| 214 |
$i = 0; |
|---|
| 215 |
while ($c = get_user_class_name($i)) { |
|---|
| 216 |
$select .= '<option value="' . $i . '"' . ( $i == $default ? ' selected="selected"':'' ) . '>' . $c . '</option>'; |
|---|
| 217 |
if ( $i == $max_class ) { |
|---|
| 218 |
break; |
|---|
| 219 |
} |
|---|
| 220 |
++$i; |
|---|
| 221 |
} |
|---|
| 222 |
$select .= '</select>'; |
|---|
| 223 |
|
|---|
| 224 |
return $select; |
|---|
| 225 |
} |
|---|
| 226 |
|
|---|
| 227 |
function categories_select ($default, $select_name = 'category', $ins_empty = false, $hide_not_allowed = false) { |
|---|
| 228 |
global $db, $lang; |
|---|
| 229 |
|
|---|
| 230 |
$select = '<select name="' . $select_name . '" id="' . $select_name . '">'; |
|---|
| 231 |
|
|---|
| 232 |
$sql = 'SELECT * FROM ' . CATEGORIES_TABLE . ' ORDER BY cat_parent_id, name'; |
|---|
| 233 |
$result = $db->sql_query($sql, 30 * 60); |
|---|
| 234 |
|
|---|
| 235 |
if ( $ins_empty ) { |
|---|
| 236 |
$select .= '<option value="0">(' . $lang['choose'] . ')</option>'; |
|---|
| 237 |
} |
|---|
| 238 |
|
|---|
| 239 |
$cats = array(); |
|---|
| 240 |
while( $row = $db->sql_fetchrow($result) ){ |
|---|
| 241 |
$parent_cat_id = ( $row['cat_parent_id'] ? $row['cat_parent_id'] : $row['id'] ); |
|---|
| 242 |
$cats[$parent_cat_id][$row['id']] = $row; |
|---|
| 243 |
} |
|---|
| 244 |
|
|---|
| 245 |
foreach ( $cats AS $cat_parent_id => $ary ) { |
|---|
| 246 |
$main_cat_name = $ary[$cat_parent_id]['name']; |
|---|
| 247 |
|
|---|
| 248 |
$selected = ( $cat_parent_id == $default ) ? ' selected="selected"' : ''; |
|---|
| 249 |
if ( $hide_not_allowed && !$ary[$cat_parent_id]['allow_upload'] ) { |
|---|
| 250 |
$select .= '<optgroup label="' . $main_cat_name . '"' . $selected . '>' . $cat_parent_id . '</optgroup>'; |
|---|
| 251 |
} |
|---|
| 252 |
else { |
|---|
| 253 |
$select .= '<option value="' . $cat_parent_id . '"' . $selected . ' style="font-weight:bold">' . $main_cat_name . '</option>'; |
|---|
| 254 |
} |
|---|
| 255 |
|
|---|
| 256 |
|
|---|
| 257 |
unset($ary[$cat_parent_id]); |
|---|
| 258 |
if ( $count = sizeof($ary) ) { |
|---|
| 259 |
$value = ''; |
|---|
| 260 |
foreach( $ary AS $key => $value ) { |
|---|
| 261 |
$selected = ( $key == $default ) ? ' selected="selected"' : ''; |
|---|
| 262 |
if ( $hide_not_allowed && !$value['allow_upload'] ) { |
|---|
| 263 |
$select .= '<optgroup label=" --> ' . $value['name'] . '"' . $selected . '>' . $key . '</optgroup>'; |
|---|
| 264 |
} |
|---|
| 265 |
else { |
|---|
| 266 |
$select .= '<option value="' . $key . '"' . $selected . '> --> ' . $value['name'] . '</option>'; |
|---|
| 267 |
} |
|---|
| 268 |
} |
|---|
| 269 |
} |
|---|
| 270 |
} |
|---|
| 271 |
|
|---|
| 272 |
$select .= '</select>'; |
|---|
| 273 |
|
|---|
| 274 |
return $select; |
|---|
| 275 |
} |
|---|
| 276 |
|
|---|
| 277 |
?> |
|---|