<?php
/*************************************************************************
* 427BB - PHP & MySQL Forum *
* Copyright (C) 2003-2006 Ben Brown *
* *
* 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; version 2 of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* A Copy of the GNU General Public License can be found in the file *
* 'liscence.txt' in the root of the forum directory. *
*************************************************************************/
include 'sql_connect.php';
function get_user ($id = NULL) {
if ($id == NULL) { NULL; }
include 'config.php';
$sql = "SELECT UserName FROM {$t_prefix}Personal WHERE ID=$id";
if (!$q = mysql_query($sql)) {
$out['error'] = mysql_error();
return $out;
}
$user = stripslashes(mysql_result($q, 0));
return $user;
}
function get_uid ($user = NULL) {
if ($user == NULL) { return NULL; }
include 'config.php';
$s_user = addslashes($user);
$sql = "SELECT ID FROM {$t_prefix}Personal WHERE UserName='$s_user'";
if (!$q = mysql_query($sql)) {
$out['error'] = mysql_error();
return $out;
}
$id = mysql_result($q, 0);
return $id;
}
function get_limit($type) {
include 'config.php';
include 'func_chk.php';
if ($type == "users" || $type == "g_users") {
return 50;
}
if (isset($username)) {
if ($type == "post") {
$select = "PostViews";
} else if ($type == "thread") {
$select = "ThreadViews";
}
$sql = "SELECT $select FROM " . $t_prefix . "Personal WHERE UserName='$username'";
$res = mysql_query($sql);
$limit = mysql_result($res, 0);
}
if ($limit == 0) {
$limit = 10;
}
return $limit;
}
function total_pages($posts, $type) {
$limit = get_limit($type);
$buff = $posts % $limit;
if ($buff == 0) {
$pages = intval($posts / $limit);
} else {
$pages = intval($posts / $limit) + 1;
}
return $pages;
}
function get_html_forum($posts, $type, $ForumID, $ThreadID, $a_style = NULL) {
$pages = total_pages($posts, $type);
if ($pages > 1) {
if ($pages < 5) {
$end = $pages;
} else {
$end = 5;
}
$out .= "<span class=small>[";
for ($i = 1; $i <= $end; $i++) {
if ($i != 1) {
$out .= " ";
}
$page = $i;
$out .= "<a href=\"showthread.php?ForumID=$ForumID&ThreadID=$ThreadID&page=$page\" $a_style>$page</a>";
}
if ($pages != $end) {
$out .= " ... <a href=\"showthread.php?ForumID=$ForumID&ThreadID=$ThreadID&page=$pages\" $a_style>$pages</a>";
}
$out .= " | <a href=\"showthread.php?ForumID=$ForumID&ThreadID=$ThreadID&page=all\" $a_style>all</a>";
$out .= "]</span>";
}
return $out;
}
function get_html_forum_top ($posts, $type, $ForumID, $page, $ThreadID = NULL) {
$pages = total_pages($posts, $type);
if ($pages <= 1) {
return;
}
if ($page == 0 && $page != "all") {
$page = 1;
}
if ($type == "post") {
$href = "<a href=\"showthread.php?ForumID=$ForumID&ThreadID=$ThreadID&page=";
} else if ($type == "thread") {
$href = "<a href=\"showforum.php?ForumID=$ForumID&page=";
} else {
return;
}
$out .= "<span class=small>pages: ";
if ($page - 10 > 0) {
$start = $page - 10;
} else {
$start = 1;
}
if ($page + 10 < $pages) {
$end = $page + 10;
} else {
$end = $pages;
}
if ($start != 1) {
$out .= $href . "1\">1</a> ... ";
}
for ($i = $start; $i <= $end; $i++) {
if ($i != 1) {
$out .= " ";
}
if ($i != $page) {
$out .= $href . $i . "\">";
}
$out .= "$i";
if ($i != $page) {
$out .= "</a>";
}
}
if ($pages != $end) {
$out .= " ... " . $href . $pages . "\">$pages</a>";
}
$out .= " | ";
if ($page != "all") {
$out .= $href . "all\">all</a>";
} else {
$out .= "all";
}
$out .= "</span>";
return $out;
}
function get_html_admin_users ($posts, $type, $page, $u_type) {
$pages = total_pages($posts, $type);
if ($pages <= 1) {
return;
}
if ($page == 0 && $page != "all") {
$page = 1;
}
if ($type == "g_users") {
$href = "<a href=admin.php?viewgroup=$u_type&u_page=";
} else {
$href = "<a href=admin.php?page=users&type=$u_type&u_page=";
}
$out .= "<span class=small>pages: ";
for ($i = 1; $i <= $pages; $i++) {
if ($i != 1) {
$out .= " | ";
}
if ($i != $page) {
$out .= $href . $i . ">";
}
$out .= "$i";
if ($i != $page) {
$out .= "</a>";
}
}
$out .= " | ";
if ($page != "all") {
$out .= $href . "all>all</a>";
} else {
$out .= "all";
}
$out .= "</span>";
return $out;
}
function get_sql_limit($posts, $type, $page) {
$pages = total_pages($posts, $type);
$limit = get_limit($type);
if ($page == "all") {
return;
}
if ($page == 0) {
$page = 1;
}
$startlimit = ($page - 1) * $limit;
$sql = "LIMIT $startlimit, $limit";
return $sql;
}
function get_groups() {
include 'config.php';
$g_sql = "SELECT Name, Count(*) FROM " . $t_prefix . "Groups GROUP BY Name";
$g_res = mysql_query($g_sql);
$i = 0;
while ($row = mysql_fetch_row($g_res)) {
$groups[$i]['name'] = $row[0];
$groups[$i]['count'] = $row[1];
$i++;
}
if ($i == 0) {
$groups[0]['name'] = "- No Group -";
$groups[0]['count'] = 0;
}
return $groups;
}
function get_access($access) {
if ($access == 6) {
$read = TRUE;
$write = TRUE;
} else if ($access == 4) {
$read = TRUE;
$write = FALSE;
} else if ($access == 0) {
$read = FALSE;
$write = FALSE;
}
$out['read'] = $read;
$out['write'] = $write;
return $out;
}
function get_acc($postid) {
include 'config.php';
include 'func_chk.php';
$sql = "SELECT ThreadID FROM " . $t_prefix . "Posts WHERE ID=$postid";
$res = mysql_query($sql);
$thread_id = mysql_result($res, 0);
$user = $username;
$sql = "SELECT UGroup, GroupRights, OtherRights, ForumID FROM " . $t_prefix . "Threads WHERE ID=$thread_id";
$res = mysql_query($sql);
$row = mysql_fetch_row($res);
$group = $row[0];
$g_acc = $row[1];
$o_acc = $row[2];
$forum_id = $row[3];
if ($g_acc == 0 && $o_acc == 0) {
$sql = "SELECT UGroup, GroupRights, OtherRights FROM " . $t_prefix . "Forums WHERE ForumID=$forum_id";
$res = mysql_query($sql);
$row = mysql_fetch_row($res);
$group = $row[0];
$g_acc = $row[1];
$o_acc = $row[2];
}
$acc = get_user_access($user, $group, $g_acc, $o_acc);
return $acc;
}
function get_user_access($user, $group, $g_acc, $o_acc) {
include 'config.php';
include 'func_chk.php';
if ($user == NULL) {
$access = get_access($o_acc);
return $access;
}
$user = addslashes($user);
$sql = "SELECT p.UserType, g.Name
FROM {$t_prefix}Personal as p
JOIN {$t_prefix}Groups as g ON g.User=p.UserName
WHERE p.UserName='$user'";
$res = mysql_query($sql);
$groups = NULL;
while($row = mysql_fetch_row($res)) {
$type = $row[0];
$groups[] = $row[1];
}
if ($type == "admin") {
$access = get_access(6);
return $access;
}
if (count($groups) == 0) {
$access = get_access($o_acc);
return $access;
}
if (in_array($group, $groups)) {
$access = get_access($g_acc);
return $access;
} else {
$access = get_access($o_acc);
return $access;
}
}
function get_access_html($Gaccess, $Oaccess) {
$group = get_access($Gaccess);
$other = get_access($Oaccess);
$out = "<table width=200>
<tr>
<td align=center>Group</td>
<td align=center>Others</td>
</tr>
<tr>
<td><input type=checkbox name=GroupRead";
if ($group['read'] == TRUE) {
$out .= " checked";
}
$out .= "> Read</td>
<td><input type=checkbox name=OtherRead";
if ($other['read'] == TRUE) {
$out .= " checked";
}
$out .= "> Read</td>
</tr>
<tr>
<td><input type=checkbox name=GroupWrite";
if ($group['write'] == TRUE) {
$out .= " checked";
}
$out .= "> Write</td>
<td><input type=checkbox name=OtherWrite";
if ($other['write'] == TRUE) {
$out .= " checked";
}
$out .= "> Write</td>
</tr>
</table>";
return $out;
}
function get_forum_html($a_page, $refer, $ForumID, $ForumTitle, $ForumComment, $PicURL, $UGroup, $GroupAccess, $OtherAccess) {
$out .= "<form action=$a_page method=post>
<input type=hidden name=refer value=\"$refer\">";
if ($ForumID != "new") {
$out .= "<input type=hidden name=ID value=\"$ForumID\">";
}
$out .= "<table width=100%>
<tr>
<td class=formright width=120>Forum Title:</td>
<td class=formleft><input type=text size=50 name=ForumTitle value=\"$ForumTitle\"></td>
</tr>
<tr>
<td class=formright>Forum Comment:</td>
<td class=formleft><input type=text size=50 name=ForumComment value=\"$ForumComment\"></td>
</tr>
<tr>
<td class=formright>Picture:</td>
<td class=formleft><input type=text size=50 name=newPicURL value=\"$PicURL\"></td>
</tr>
<tr>
<td class=formright>Group:</td>
<td class=formleft><select name=UGroup>";
$groups = get_groups();
$out .= "<option";
if ($UGroup == "- No Group -") {
$out .= " selected";
}
$out .= ">- No Group -</option>";
if ($groups[0]['count'] != 0) {
foreach ($groups as $index => $val) {
$out .= "\n\t\t<option";
if ($val['name'] == $UGroup) {
$out .= " selected";
}
$out .= ">" . $val['name'] . "</option>";
}
}
$out .= "\n\t</select></td>
</tr>
<tr valign=top>
<td class=formright>Access Rights:</td>
<td class=formleft>";
$code = get_access_html($GroupAccess, $OtherAccess);
$out .= $code;
$out .= "</td>
</tr>
<tr>
<td class=formright> </td>
<td class=formleft><input type=checkbox name=set_threads_as_forum> Set all thread permissions to these settings.</td>
</tr>";
if ($ForumID != "new") {
$sub_name = "saveforumchanges";
$del = " <input type=submit name=deleteforum value=\"Delete Forum\">";
} else {
$sub_name = "savenewforum";
$del = "";
}
$out .= "<tr>
<td class=formright> </td>
<td class=formleft><input type=submit name=$sub_name value=\"Save\"> <input type=submit name=cancel value=\"Cancel\">$del</td>
</tr>
</table>
</form>";
return $out;
}
function get_numbers_from_check($read, $write) {
if ($write == "on") {
$out = 6;
} else if ($read == "on") {
$out = 4;
} else {
$out = 0;
}
return $out;
}
function get_styles() {
$cmd = "ls styles";
$output = trim(shell_exec($cmd));
$a_out = preg_split("/\n/", $output);
foreach ($a_out as $val) {
if (preg_match("/\.css$/si", $val)) {
$end = strlen($val) - 4;
$out[] = substr($val, 0, $end);
}
}
return $out;
}
function get_statuses() {
include 'config.php';
$sql = "SELECT Posts, Status FROM " . $t_prefix . "Status ORDER BY Posts";
$res = mysql_query($sql);
$i = 0;
while ($row = mysql_fetch_row($res)) {
$out[$i]['posts'] = $row[0];
$out[$i]['status'] = stripslashes($row[1]);
$i ++;
}
return $out;
}
?>