*      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: spacecp_index.php 22814 2011-05-24 05:42:54Z zhangguosheng $
 */
if (!defined('IN_DISCUZ')) {
    exit('Access Denied');
}
$op = in_array($_GET['op'], array('start', 'layout', 'block', 'style', 'diy', 'image', 'getblock', 'edit', 'setmusic', 'getspaceinfo', 'savespaceinfo', 'editnv', 'getpersonalnv')) ? $_GET['op'] : 'start';
require_once libfile('function/space');
require_once libfile('function/portalcp');
if ($op == 'start') {
} elseif ($op == 'layout') {
    $layoutarr = getlayout();
} elseif ($op == 'style') {
    $themes = gettheme('space');
} elseif ($op == 'block') {
    $block = getblockdata();
} elseif ($op == 'diy' || $op == 'image') {
    $albumid = empty($_GET['albumid']) ? 0 : intval($_GET['albumid']);
    $page = empty($_GET['page']) ? 1 : intval($_GET['page']);
    if ($page < 1) {
        $page = 1;
    }
    $perpage = 6;
    $perpage = mob_perpage($perpage);
    $start = ($page - 1) * $perpage;
    ckstart($start, $perpage);
    $albumlist = array();
    $query = DB::query("SELECT * FROM " . DB::table('home_album') . " WHERE uid='{$space['uid']}' ORDER BY updatetime DESC");
    while ($value = DB::fetch($query)) {
                    updatecache('diytemplatename');
                }
            }
        }
    }
    $tourl = empty($_POST['gobackurl']) || strpos($_POST['gobackurl'], 'op=add') != false || strpos($_POST['gobackurl'], '&diy=yes') != false ? str_replace('&diy=yes', '', $_SERVER['HTTP_REFERER']) : $_POST['gobackurl'];
    $tourl = preg_replace('/[\\?|&]preview=yes/', '', $tourl);
    showmessage('do_success', $tourl, array('rejs' => $_POST['rejs']));
}
if ($op == 'blockclass') {
    loadcache('blockclass');
} elseif ($op == 'style') {
    if (!$_G['group']['allowmanagetopic'] && !$_G['group']['allowdiy'] && !$_G['group']['allowaddtopic']) {
        showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
    }
    $themes = gettheme('topic');
} elseif ($op == 'diy' || $op == 'image') {
    $topicid = intval($_GET['topicid']);
    $topic = C::t('portal_topic')->fetch($topicid);
    topic_checkperm($topic);
    $perpage = 6;
    $page = max(1, intval($_GET['page']));
    $start = ($page - 1) * $perpage;
    $list = array();
    if ($topicid) {
        $count = C::t('portal_topic_pic')->count_by_topicid($topicid);
        if (!empty($count)) {
            foreach (C::t('portal_topic_pic')->fetch_all_by_topicid($topicid, $start, $perpage) as $value) {
                $value['pic'] = pic_get($value['filepath'], 'portal', $value['thumb'], $value['remote']);
                $list[] = $value;
            }