aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/functions/functions.php
blob: 0e5341d2e66938ffc6b1b240c81b33c546e06e04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<?php
/***************************************************************************  
 *                               functions.php
 *                            -------------------                         
 *   begin                : Saturday, Feb 13, 2001 
 *   copyright            : (C) 2001 The phpBB Group        
 *   email                : support@phpbb.com                           
 *                                                          
 *   $Id$
 *                                                            
 * 
 ***************************************************************************/ 


/***************************************************************************  
 *                                                     
 *   This program is free software; you can redistribute it and/or modify    
 *   it under the terms of the GNU General Public License as published by   
 *   the Free Software Foundation; either version 2 of the License, or  
 *   (at your option) any later version.                      
 *                                                          
 * 
 ***************************************************************************/ 

function get_db_stat($db, $mode) 
{
	switch($mode){
		case 'postcount':
			$sql = 'SELECT count(*) AS total FROM '.POSTS_TABLE;
		break;

		case 'usercount':
			$sql = 'SELECT count(*) AS total 
						FROM '. USERS_TABLE .' 
						WHERE user_id != '.ANONYMOUS.'
						AND user_level != '.DELETED;
		break;

		case 'newestuser':
			$sql = 'SELECT user_id, username
						FROM '.USERS_TABLE.'
						WHERE user_id != ' . ANONYMOUS. '
						AND user_level != '. DELETED .'
						ORDER BY user_id DESC LIMIT 1';
		break;
	}

	
	if(!$result = $db->sql_query($sql))
	{
		return 'ERROR';
	}
	else
	{
		$row = $db->sql_fetchrow($result);
		if($mode == 'newestuser')
		{
			return($row);
		}
		else
		{
			return($row['total']);
		}
	}
}


function make_jumpbox($db)
{
	$sql = 'SELECT cat_id, cat_title FROM '.CATEGORIES_TABLE.' ORDER BY cat_order';
	
	$boxstring = '';
	if($result = $db->sql_query($sql))
	{
		if($total_cats = $db->sql_numrows($result))
		{
			$cat_rows = $db->sql_fetchrowset($result);
			for($x = 0; $x < $total_cats; $x++)
			{
				$boxstring .= "<option value=\"-1\">&nbsp;</option>\n";
				$boxstring .= "<option value=\"-1\">".stripslashes($cat_rows[$x]["cat_title"])."</OPTION>\n";
				$boxstring .= "<option value=\"-1\">----------------</OPTION>\n";

				$f_sql = "SELECT forum_name, forum_id FROM ".FORUMS_TABLE."
					WHERE cat_id = ". $cat_rows[$x]["cat_id"] . " ORDER BY forum_id";
				
				if($f_result = $db->sql_query($f_sql))
				{
					if($total_forums = $db->sql_numrows($f_result)) 
					{
						$f_rows = $db->sql_fetchrowset($f_result);
						
						for($y = 0; $y < $total_forums; $y++)
						{
							$name = stripslashes($f_rows[$y]["forum_name"]);
							$boxstring .=  "<option value=\"".$f_rows[$y]["forum_id"]."\">$name</OPTION>\n";
						}
					}
				}
				else 
				{
					$boxstring .= "<option value=\"-1\">Error!</option>\n";
				}

			}
		}
		else
		{
			$boxstring .= "<option value=\"-1\">No Forums to Jump to</option>\n";
		}
	}
	else
	{
		$boxstring .= "<option value=\"-1\">Cat Error</option>\n";
	}

	return($boxstring);
}

function language_select($default, $name="language", $dirname="language/")
{
	global $phpEx;
	$dir = opendir($dirname);
	$lang_select = "<select name=\"$name\">\n";
	while ($file = readdir($dir)) 
	{
		if (ereg("^lang_", $file)) 
		{
			$file = str_replace("lang_", "", $file);
			$file = str_replace(".$phpEx", "", $file);
			$file == $default ? $selected = " SELECTED" : $selected = "";
			$lang_select .= "  <option$selected>$file\n";
		}
	}
	$lang_select .= "</select>\n";
	closedir($dir);
	return $lang_select;
}

function theme_select($default, $db)
{
	$sql = "SELECT theme_id, theme_name FROM ".THEMES_TABLE." ORDER BY theme_name";
	if($result = $db->sql_query($sql))
	{
		$num = $db->sql_numrows($result);
		$rowset = $db->sql_fetchrowset($result);
		$theme_select = "<select name=\"theme\">\n";
		for($i = 0; $i < $num; $i++)
		{
			if((stripslashes($rowset[$i]["theme_name"]) == $default) || ($rowset[$i]["theme_id"] == $default))
			{
				$selected = " SELECTED";
			}
			else
			{
				$selected = "";
			}
			$theme_select .= "\t<option value=\"".$rowset[$i]["theme_id"]."\"$selected>".stripslashes($rowset[$i]["theme_name"])."</option>\n";
		}
		$theme_select .= "</select>\n";
	}
	else
	{
		$theme_select = "<select name=\"theme\"><option value=\"-1\">Error in theme_select</option></select>";
	}
	return($theme_select);
}

function tz_select($default)
{
	global $board_tz;
	if(!isset($default))
	{
		$default == $board_tz;
	}
	$tz_select = "<select name=\"timezone\">";
	$tz_array = array(
			"-12" => "(GMT -12:00 hours) Eniwetok, Kwajalein",
			"-11" => "(GMT -11:00 hours) Midway Island, Samoa",
			"-10" => "(GMT -10:00 hours) Hawaii",
			"-9" => "(GMT -9:00 hours) Alaska",
			"-8" => "(GMT -8:00 hours) Pacific Time (US & Canada)",
			"-7" => "(GMT -7:00 hours) Mountain Time (US & Canada)",
			"-6" => "(GMT -6:00 hours) Central Time (US & Canada), Mexico City",
			"-5" => "(GMT -5:00 hours) Eastern Time (US & Canada), Bogota, Lima, Quito",
			"-4" => "(GMT -4:00 hours) Atlantic Time (Canada), Caracas, La Paz",
			"-3.5" => "(GMT -3:30 hours) Newfoundland",
			"-3" => "(GMT -3:00 hours) Brazil, Buenos Aires, Georgetown",
			"-2" => "(GMT -2:00 hours) Mid-Atlantic",
			"-1" => "(GMT -1:00 hours) Azores, Cape Verde Islands",
			"0"  => "(GMT) Western Europe Time, London, Lisbon, Casablanca, Monrovia",
			"+1" => "(GMT +1:00 hours) CET(Central Europe Time), Brussels, Copenhagen, Madrid, Paris",
			"+2" => "(GMT +2:00 hours) EET(Eastern Europe Time), Kaliningrad, South Africa",
			"+3" => "(GMT +3:00 hours) Baghdad, Kuwait, Riyadh, Moscow, St. Petersburg, Volgograd, Nairobi",
			"+3.5" => "(GMT +3:30 hours) Tehran",
			"+4" => "(GMT +4:00 hours) Abu Dhabi, Muscat, Baku, Tbilisi",
			"+4.5" => "(GMT +4:30 hours) Kabul",
			"+5" => "(GMT +5:00 hours) Ekaterinburg, Islamabad, Karachi, Tashkent",
			"+5.5" => "(GMT +5:30 hours) Bombay, Calcutta, Madras, New Delhi",
			"+6" => "(GMT +6:00 hours) Almaty, Dhaka, Colombo",
			"+7" => "(GMT +7:00 hours) Bangkok, Hanoi, Jakarta",
			"+8" => "(GMT +8:00 hours) Beijing, Perth, Singapore, Hong Kong, Chongqing, Urumqi, Taipei",
			"+9" => "(GMT +9:00 hours) Tokyo, Seoul, Osaka, Sapporo, Yakutsk",
			"+9.5" => "(GMT +9:30 hours) Adelaide, Darwin",
			"+10" => "(GMT +10:00 hours) EAST(East Australian Standard), Guam, Papua New Guinea, Vladivostok",
			"+11" => "(GMT +11:00 hours) Magadan, Solomon Islands, New Caledonia",
			"+12" => "(GMT +12:00 hours) Auckland, Wellington, Fiji, Kamchatka, Marshall Island");
	
	while(list($offset, $zone) = each($tz_array))
	{
		if($offset == $default)
		{
			$selected = " SELECTED";
		}
		else
		{
			$selected = "";
		}
		$tz_select .= "\t<option value=\"$offset\"$selected>$zone</option>\n";
	}
	$tz_select .= "</select>\n";
	return($tz_select);
}

function validate_username(&$username, $db)
{
	$username = trim($username);
	$username = strip_tags($username);
	$username = htmlspecialchars($username);
	if(empty($username))
	{
		return(FALSE);
	}
	
	$valid_name = TRUE;
	$sql = "SELECT LOWER(username) FROM ".USERS_TABLE." WHERE username = '$username'";
	if($result = $db->sql_query($sql))
	{
		if( ($numrows = $db->sql_numrows($result) ) > 0)
		{
			$valid_name = FALSE;
		}
	}
	
	$sql = "SELECT disallow_username FROM ".DISALLOW_TABLE." WHERE disallow_username = '$username'";
	if($result = $db->sql_query($sql))
	{
		if(($numrows = $db->sql_numrows($result)) > 0)
		{
			$valid_name = FALSE;
		}
	}
	
	return($valid_name);
}
function generate_activation_key()
{
	$chars = array( 
		  "a","A","b","B","c","C","d","D","e","E","f","F","g","G","h","H","i","I","j","J",
		  "k","K","l","L","m","M","n","N","o","O","p","P","q","Q","r","R","s","S","t","T",
		  "u","U","v","V","w","W","x","X","y","Y","z","Z","1","2","3","4","5","6","7","8",
		  "9","0"
		  );
   $max_elements = count($chars) - 1;
   srand((double)microtime()*1000000);
   $act_key = $chars[rand(0,$max_elements)];
   $act_key .= $chars[rand(0,$max_elements)];
   $act_key .= $chars[rand(0,$max_elements)];  
   $act_key .= $chars[rand(0,$max_elements)]; 
   $act_key .= $chars[rand(0,$max_elements)]; 
   $act_key .= $chars[rand(0,$max_elements)]; 
   $act_key .= $chars[rand(0,$max_elements)]; 
   $act_key .= $chars[rand(0,$max_elements)];
   $act_key_md = md5($act_key);
   
   return($act_key_md);
}
?>