<?php
/*
		[FuShow.cn] (C) 2013-2014 HXWY Inc.
		FuShow Friend V3.0				Id: uump_live.php
		Email <service@fushow.cn>		http://fushow.cn/
*/

if(!defined('IN_FUSHOW')) {
	exit('Access Denied');
}

//检查信息
$liveid = empty($_GET['liveid'])?0:intval($_GET['liveid']);
$op = empty($_GET['op'])?'':$_GET['op'];
$live = array();
if($liveid) {
	$query = $_SGLOBAL['db']->query("SELECT bf.*, b.* FROM ".tname('live')." b 
		LEFT JOIN ".tname('livefield')." bf ON bf.liveid=b.liveid 
		WHERE b.liveid='$liveid'");
	$live = $_SGLOBAL['db']->fetch_array($query);
	/*
	$mquery = $_SGLOBAL['db']->query("SELECT mm.*, b.* FROM ".tname('live')." b 
		LEFT JOIN ".tname('major_manager')." mm ON mm.id=b.work 
		WHERE b.liveid='$blogid'");
	$live = $_SGLOBAL['db']->fetch_array($mquery);
	*/
}

//获取专业列表-start
$livework = array();
    $lquery = $_SGLOBAL['db']->query("SELECT * FROM ".tname('major_manager'), 'SILENT');
	while ($pro = $_SGLOBAL['db']->fetch_array($lquery)) {
			$livework[]= $pro;	
}

//权限检查
if(empty($live)) {
	if(!checkperm('allowlive')) {
		ckspacelog();
		showmessage('no_authority_to_add_live');
	}
	
	//实名认证
	ckrealname('blog');
	
	//视频认证
	ckvideophoto('blog');
	
	//新用户见习
	cknewuser();
	
	//判断是否发布太快
	$waittime = interval_check('post');
	if($waittime > 0) {
		showmessage('operating_too_fast','',1,array($waittime));
	}
	
	//接收外部标题
	$live['subject'] = empty($_GET['subject'])?'':getstr($_GET['subject'], 80, 1, 0);
	$live['message'] = empty($_GET['message'])?'':getstr($_GET['message'], 220, 1, 0);
	
} else {
	if($_SGLOBAL['supe_uid'] != $live['uid'] && !checkperm('manageblog')) {
		showmessage('no_authority_operation_of_the_live');
	}
}

//添加编辑操作
if(submitcheck('blogsubmit')) {

	if(empty($live['liveid'])) {
		$live = array();
	} else {
		if(!checkperm('allowlive')) {
			ckspacelog();
			showmessage('no_authority_to_add_live');
		}
	}
	
	//验证码
	if(checkperm('seccode') && !ckseccode($_POST['seccode'])) {
		showmessage('incorrect_code');
	}
	
	include_once(S_ROOT.'./source/function_live.php');
	if($newlive = blog_post($_POST, $live)) {
		if(empty($live) && $newlive['topicid']) {
			$url = 'fushow.php?do=topic&topicid='.$newlive['topicid'].'&view=live';
		} else {
			$url = 'fushow.php?uid='.$newlive['uid'].'&do=live&id='.$newlive['liveid'];
		}
		showmessage('do_success', $url, 0);
	} else {
		showmessage('that_should_at_least_write_things');
	}
}

if($_GET['op'] == 'delete') {
	//删除
	if(submitcheck('deletesubmit')) {
		include_once(S_ROOT.'./source/function_delete.php');
		if(deletelives(array($liveid))) {
			showmessage('do_success', "fushow.php?uid=$live[uid]&do=live&view=me");
		} else {
			showmessage('failed_to_delete_operation');
		}
	}
	
} elseif($_GET['op'] == 'goto') {
	
	$id = intval($_GET['id']);
	$uid = $id?getcount('live', array('liveid'=>$id), 'uid'):0;

	showmessage('do_success', "fushow.php?uid=$uid&do=live&id=$id", 0);
	
} elseif($_GET['op'] == 'edithot') {
	//权限
	if(!checkperm('manageblog')) {
		showmessage('no_privilege');
	}
	
	if(submitcheck('hotsubmit')) {
		$_POST['hot'] = intval($_POST['hot']);
		updatetable('live', array('hot'=>$_POST['hot']), array('liveid'=>$live['liveid']));
		if($_POST['hot']>0) {
			include_once(S_ROOT.'./source/function_feed.php');
			feed_publish($live['liveid'], 'liveid');
		} else {
			updatetable('feed', array('hot'=>$_POST['hot']), array('id'=>$live['liveid'], 'idtype'=>'liveid'));
		}
		
		showmessage('do_success', "fushow.php?uid=$live[uid]&do=live&id=$live[liveid]", 0);
	}

}else {
	//添加编辑
	//获取个人分类
	$classarr = $live['uid']?getclassarr($live['uid']):getclassarr($_SGLOBAL['supe_uid']);
	//获取相册
	$albums = getalbums($_SGLOBAL['supe_uid']);
	$tags = empty($live['tag'])?array():unserialize($live['tag']);
	$live['tag'] = implode(' ', $tags);
	
	$live['target_names'] = '';
	
	$friendarr = array($live['friend'] => ' selected');
	
	$passwordstyle = $selectgroupstyle = 'display:none';
	if($live['friend'] == 4) {
		$passwordstyle = '';
	} elseif($live['friend'] == 2) {
		$selectgroupstyle = '';
		if($live['target_ids']) {
			$names = array();
			$query = $_SGLOBAL['db']->query("SELECT username FROM ".tname('space')." WHERE uid IN ($live[target_ids])");
			while ($value = $_SGLOBAL['db']->fetch_array($query)) {
				$names[] = $value['username'];
			}
			$live['target_names'] = implode(' ', $names);
		}
	}
	
	
	$live['message'] = str_replace('&amp;', '&amp;amp;', $live['message']);
	$live['message'] = shtmlspecialchars($live['message']);
	
	$allowhtml = checkperm('allowhtml');
	
	//好友组
	$groups = getfriendgroup();
	
	//参与热点
	$topic = array();
	$topicid = $_GET['topicid'] = intval($_GET['topicid']);
	if($topicid) {
		$topic = topic_get($topicid);
	}
	if($topic) {
		$actives = array('live' => ' class="active"');
	}
	
	//菜单激活
	$menuactives = array('space'=>' class="active"');
}

include_once template("uump_live");
?>