<?php
require_once('global.php');
require_once(R_P.'require/forum.php');
include_once(D_P.'data/bbscache/forum_cache.php');
$groupid == 'guest' && Showmsg('not_login');
$fiddb = array();
InitGP(array('action'));
if ($action) {
!$fid && Showmsg('data_error');
$forums = $db->get_one("SELECT f.name,f.forumadmin,f.fupadmin,fe.forumset FROM pw_forums f LEFT JOIN pw_forumsextra fe USING(fid) WHERE f.fid=".pwEscape($fid)." AND f.type!='category'");
!$forums && Showmsg('data_error');
if (!in_array($groupid,array('3','4')) && !admincheck($forums['forumadmin'],$forums['fupadmin'],$windid)) {
Showmsg('not_forumadmin');
}
$forumset = unserialize($forums['forumset']);
$first_admin = $db_adminset && strpos($forums['forumadmin'],",".$windid.",")===0 ? 1 : 0;
} else {
$query = $db->query("SELECT fid,forumadmin,fupadmin FROM pw_forums WHERE cms=0 AND type!='category'");
while ($rt = $db->fetch_array($query)) {
if (in_array($groupid,array('3','4')) || admincheck($rt['forumadmin'],$rt['fupadmin'],$windid)) {
$fiddb[] = $rt['fid'];
}
}
!$fiddb && Showmsg('not_forumadmin');
}
require_once(R_P.'require/header.php');
if (!$action) {
$forum_name = '';
$fids = pwImplode($fiddb);
$froumdb = array();
$query = $db->query("SELECT * FROM pw_forums f LEFT JOIN pw_forumdata fd USING(fid) WHERE f.fid IN($fids)");
while ($rt = $db->fetch_array($query)) {
$forumdb[] = $rt;
}
$i = count($forumdb);
if ($i > 4) {
$j_sum = 4;
$j_wid = '25%';
} else {
$j_sum = $i;
$j_wid = (100/$i).'%';
}
require_once(PrintEot('forumcp'));footer();
} elseif ($action == 'edit') {
$forum_name = $forums['name'];
InitGP(array('type'));
!$type && $type = 'notice';
if ($type == 'notice') {
$annoucedb = array();
$pages = ''; $page = $_GET['page']; (int)$page<1 && $page = 1;
$query = $db->query('SELECT aid,ifopen,vieworder,author,subject,startdate,enddate FROM pw_announce WHERE fid='.pwEscape($fid).' ORDER BY fid,vieworder,startdate DESC '.pwLimit(($page-1)*$db_perpage,$db_perpage));
while ($rt = $db->fetch_array($query)) {
$rt['subject'] = substrs($rt['subject'],30);
$rt['starttime'] = $rt['startdate'] ? get_date($rt['startdate'],'Y-m-d H:i') : '--';
$rt['endtime'] = $rt['enddate'] ? get_date($rt['enddate'],'Y-m-d H:i') : '--';
$annoucedb[] = $rt;
}
$db->free_result($query);
$count = $db->get_value('SELECT COUNT(*) FROM pw_announce WHERE fid='.pwEscape($fid));
if ($count > $db_perpage) {
require_once(R_P.'require/forum.php');
$pages = numofpage($count,$page,ceil($count/$db_perpage), "forumcp.php?action=edit&fid=$fid&type=$type&");
}
require_once(PrintEot('forumcp'));footer();
} elseif ($type == 'n_del') {
PostCheck();
$aid = (int)$_GET['aid'];
$rt = $db->get_one('SELECT aid,fid,ifopen FROM pw_announce WHERE aid='.pwEscape($aid));
(!$rt['aid'] || $rt['fid']!=$fid) && Showmsg('data_error');
$db->update('DELETE FROM pw_announce WHERE aid='.pwEscape($aid));
if ($rt['ifopen']) {
require_once(R_P.'require/updatenotice.php');
updatecache_i($fid);
}
refreshto("forumcp.php?action=edit&fid=$fid",'operate_success');
} elseif ($type == 'n_order') {
PostCheck();
!is_array($vieworder = $_POST['vieworder']) && $vieworder = array();
$updatedb = array();
foreach ($vieworder as $key => $value) {
if (is_numeric($key)) {
$value = (int)$value;
$updatedb[$value] .= ",'$key'";
}
}
foreach ($updatedb as $key => $value) {
$value && $db->update("UPDATE pw_announce SET vieworder='$key' WHERE aid IN (".substr($value,1).')');
}
require_once(R_P.'require/updatenotice.php');
updatecache_i($fid);
refreshto("forumcp.php?action=edit&fid=$fid",'operate_success');
} elseif ($type == 'add' || $type == 'edit') {
InitGP(array('aid'),'GP',2);
if (empty($_POST['step'])) {
$ifopen_Y = 'CHECKED'; $vieworder = (int)$vieworder;
$ifopen_N = $subject = $atc_content = $enddate = '';
$startdate = get_date($timestamp,'Y-m-d H:i');
if ($type == 'edit') {
$db_redundancy = 0;
$rt = $db->get_one('SELECT aid,fid,ifopen,vieworder,startdate,enddate,subject,content FROM pw_announce WHERE aid='.pwEscape($aid));
!$rt['aid'] && Showmsg('data_error');
extract($rt,EXTR_OVERWRITE);
if (!$ifopen) {
$ifopen_Y = '';
$ifopen_N = 'CHECKED';
}
$startdate && $startdate = get_date($startdate,'Y-m-d H:i'); $enddate && $enddate = get_date($enddate,'Y-m-d H:i');
$atc_content = $content;
}
require_once(PrintEot('forumcp'));footer();
} else {
PostCheck();
!$fid && Showmsg('annouce_fid');
InitGP(array('startdate','enddate','atc_title'),'P');
$startdate = $startdate ? PwStrtoTime($startdate) : $timestamp;
$enddate = $enddate ? PwStrtoTime($enddate) : '';
$enddate && $enddate<=$startdate && Showmsg('annouce_time');
InitGP(array('ifopen','vieworder'),'P',2);
$atc_content = trim(Char_cv($_POST['atc_content']));
if ($type == 'add') {
!$atc_title && Showmsg('annouce_title');
!$atc_content && Showmsg('annouce_content');
$pwSQL = pwSqlSingle(array(
'fid' => $fid,
'ifopen' => $ifopen,
'vieworder' => $vieworder,
'author' => $windid,
'startdate' => $startdate,
'enddate' => $enddate,
'url' => $url,
'subject' => $atc_title,
'content' => $atc_content
));
$db->update("INSERT INTO pw_announce SET $pwSQL");
if ($ifopen && (!$enddate || $enddate>=$timestamp)) {
require_once(R_P.'require/updatenotice.php');
updatecache_i($fid);
}
} else {
$rt = $db->get_one('SELECT aid,fid,content FROM pw_announce WHERE aid='.pwEscape($aid));
!$atc_title && Showmsg('annouce_title');
!$atc_content && Showmsg('annouce_content');
(!$rt['aid'] || $rt['fid']!=$fid) && Showmsg('data_error');
$pwSQL = pwSqlSingle(array(
'ifopen' => $ifopen,
'vieworder' => $vieworder,
'startdate' => $startdate,
'enddate' => $enddate,
'url' => $url,
'subject' => $atc_title,
'content' => $atc_content
));
$db->update("UPDATE pw_announce SET $pwSQL WHERE aid=".pwEscape($aid));
require_once(R_P.'require/updatenotice.php');
updatecache_i($fid);
}
refreshto("forumcp.php?action=edit&fid=$fid",'operate_success');
}
} elseif ($type == 'report') {
InitGP(array('page'),'GP',2);
$page < 1 && $page = 1;
$limit = pwLimit(($page-1)*$db_perpage,$db_perpage);
$rt = $db->get_one('SELECT COUNT(*) AS count FROM pw_report r LEFT JOIN pw_threads t ON t.tid=r.tid WHERE t.fid='.pwEscape($fid));
$sum = $rt['count'];
$numofpage = ceil($sum/$db_perpage);
$pages = numofpage($sum,$page,$numofpage,"forumcp.php?action=edit&type=report&fid=$fid&");
$query = $db->query('SELECT r.*,m.username,t.fid FROM pw_report r LEFT JOIN pw_members m ON m.uid=r.uid LEFT JOIN pw_threads t ON t.tid=r.tid WHERE t.fid='.pwEscape($fid).' ORDER BY id '.$limit);
while ($rt = $db->fetch_array($query)) {
$rt['fname'] = $forum[$rt['fid']]['name'];
$reportdb[] = $rt;
}
require_once(PrintEot('forumcp'));footer();
} elseif ($type == 'f_type') {
$rt = $db->get_one('SELECT f.t_type,fe.fid,fe.forumset FROM pw_forums f LEFT JOIN pw_forumsextra fe USING(fid) WHERE f.fid='.pwEscape($fid));
$forumset = unserialize($rt['forumset']);
if (empty($_POST['step'])) {
$forumset['addtpctype'] ? $addtpctype_Y='checked' : $addtpctype_N='checked';
$t_typedb=explode("\t",$rt['t_type']);/*主题分类*/
$t_typedb[0] = (int)$t_typedb[0];
${'t_type_'.$t_typedb[0]}='checked';
require_once(PrintEot('forumcp'));footer();
} else {
PostCheck();
Add_S($forumset);
InitGP(array('t_db','addtpctype'),'P');
$t_type = implode("\t",$t_db)."\t";/*主题分类*/
$t_type = str_replace('"','"',$t_type);
if ($t_type != $rt['t_type']) {
$db