<?php
/*
[UCenter Home] (C) 2007-2008 Comsenz Inc.
$Id: function_delete.php 13001 2009-08-05 06:18:06Z zhengqingpeng $
*/
if(!defined('IN_UCHOME')) {
exit('Access Denied');
}
//ɾ³ýÆÀÂÛ
function deletecomments($cids) {
global $_SGLOBAL;
$deductcredit = array();
$blognums = $spaces = $newcids = $dels = array();
$allowmanage = checkperm('managecomment');
$managebatch = checkperm('managebatch');
$delnum = 0;
$reward = getreward('delcomment', 0);
$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('comment')." WHERE cid IN (".simplode($cids).")");
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
if($allowmanage || $value['authorid'] == $_SGLOBAL['supe_uid'] || $value['uid'] == $_SGLOBAL['supe_uid']) {
$dels[] = $value;
if(!$managebatch && $value['authorid'] != $_SGLOBAL['supe_uid']) {
$delnum++;
}
}
}
if(empty($dels) || (!$managebatch && $delnum > 1)) return array();
foreach($dels as $key => $value) {
$newcids[] = $value['cid'];
if($value['idtype'] == 'blogid') {
$blognums[$value['id']]++;
}
if($allowmanage && $value['authorid'] != $value['supe_uid']) {
//¿Û³ý»ý·Ö
$_SGLOBAL['db']->query("UPDATE ".tname('space')." SET credit=credit-$reward[credit], experience=experience-$reward[experience] WHERE uid='$value[authorid]'");
}
}
//Êý¾Ýɾ³ý
$_SGLOBAL['db']->query("DELETE FROM ".tname('comment')." WHERE cid IN (".simplode($newcids).")");
//ͳ¼ÆÊý¾Ý
$nums = renum($blognums);
foreach ($nums[0] as $num) {
$_SGLOBAL['db']->query("UPDATE ".tname('blog')." SET replynum=replynum-$num WHERE blogid IN (".simplode($nums[1][$num]).")");
}
return $dels;
}
//ɾ³ý²©¿Í
function deleteblogs($blogids) {
global $_SGLOBAL;
//»ñÈ¡»ý·Ö
$reward = getreward('delblog', 0);
//»ñÈ¡²©¿ÍÐÅÏ¢
$spaces = $blogs = $newblogids = array();
$allowmanage = checkperm('manageblog');
$managebatch = checkperm('managebatch');
$delnum = 0;
$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('blog')." WHERE blogid IN (".simplode($blogids).")");
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
if($allowmanage || $value['uid'] == $_SGLOBAL['supe_uid']) {
$blogs[] = $value;
if(!$managebatch && $value['uid'] != $_SGLOBAL['supe_uid']) {
$delnum++;
}
}
}
if(empty($blogs) || (!$managebatch && $delnum > 1)) return array();
foreach($blogs as $key => $value) {
$newblogids[] = $value['blogid'];
if($allowmanage && $value['uid'] != $_SGLOBAL['supe_uid']) {
//¿Û³ý»ý·Ö
$_SGLOBAL['db']->query("UPDATE ".tname('space')." SET credit=credit-$reward[credit], experience=experience-$reward[experience] WHERE uid='$value[uid]'");
}
//tag
$tags = array();
$subquery = $_SGLOBAL['db']->query("SELECT tagid, blogid FROM ".tname('tagblog')." WHERE blogid='$value[blogid]'");
while ($tag = $_SGLOBAL['db']->fetch_array($subquery)) {
$tags[] = $tag['tagid'];
}
if($tags) {
$_SGLOBAL['db']->query("UPDATE ".tname('tag')." SET blognum=blognum-1 WHERE tagid IN (".simplode($tags).")");
$_SGLOBAL['db']->query("DELETE FROM ".tname('tagblog')." WHERE blogid='$value[blogid]'");
}
}
//Êý¾Ýɾ³ý
$_SGLOBAL['db']->query("DELETE FROM ".tname('blog')." WHERE blogid IN (".simplode($newblogids).")");
$_SGLOBAL['db']->query("DELETE FROM ".tname('blogfield')." WHERE blogid IN (".simplode($newblogids).")");
//ÆÀÂÛ
$_SGLOBAL['db']->query("DELETE FROM ".tname('comment')." WHERE id IN (".simplode($newblogids).") AND idtype='blogid'");
//ɾ³ý¾Ù±¨
$_SGLOBAL['db']->query("DELETE FROM ".tname('report')." WHERE id IN (".simplode($newblogids).") AND idtype='blogid'");
//ɾ³ýfeed
$_SGLOBAL['db']->query("DELETE FROM ".tname('feed')." WHERE id IN (".simplode($newblogids).") AND idtype='blogid'");
//ɾ³ý½ÅÓ¡
$_SGLOBAL['db']->query("DELETE FROM ".tname('clickuser')." WHERE id IN (".simplode($newblogids).") AND idtype='blogid'");
return $blogs;
}
//ɾ³ýʼþ
function deletefeeds($feedids) {
global $_SGLOBAL;
$allowmanage = checkperm('managefeed');
$managebatch = checkperm('managebatch');
$delnum = 0;
$feeds = $newfeedids = array();
$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('feed')." WHERE feedid IN (".simplode($feedids).")");
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
if($allowmanage || $value['uid'] == $_SGLOBAL['supe_uid']) {//¹ÜÀíÔ±/×÷Õß
$newfeedids[] = $value['feedid'];
if(!$managebatch && $value['uid'] != $_SGLOBAL['supe_uid']) {
$delnum++;
}
$feeds[] = $value;
}
}
if(empty($newfeedids) || (!$managebatch && $delnum > 1)) return array();
$_SGLOBAL['db']->query("DELETE FROM ".tname('feed')." WHERE feedid IN (".simplode($newfeedids).")");
return $feeds;
}
//ɾ³ý·ÖÏí
function deleteshares($sids) {
global $_SGLOBAL;
$allowmanage = checkperm('manageshare');
$managebatch = checkperm('managebatch');
$delnum = 0;
//»ñÈ¡»ý·Ö
$reward = getreward('delshare', 0);
$spaces = $shares = $newsids = array();
$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('share')." WHERE sid IN (".simplode($sids).")");
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
if($allowmanage || $value['uid'] == $_SGLOBAL['supe_uid']) {//¹ÜÀíÔ±/×÷Õß
$shares[] = $value;
if(!$managebatch && $value['uid'] != $_SGLOBAL['supe_uid']) {
$delnum++;
}
}
}
if(empty($shares) || (!$managebatch && $delnum > 1)) return array();
foreach($shares as $key => $value) {
$newsids[] = $value['sid'];
if($allowmanage && $value['uid'] != $_SGLOBAL['supe_uid']) {
//¿Û³ý»ý·Ö
$_SGLOBAL['db']->query("UPDATE ".tname('space')." SET credit=credit-$reward[credit], experience=experience-$reward[experience] WHERE uid='$value[uid]'");
}
}
$_SGLOBAL['db']->query("DELETE FROM ".tname('share')." WHERE sid IN (".simplode($newsids).")");
//ÆÀÂÛ
$_SGLOBAL['db']->query("DELETE FROM ".tname('comment')." WHERE id IN (".simplode($newsids).") AND idtype='sid'");
//ɾ³ýfeed
$_SGLOBAL['db']->query("DELETE FROM ".tname('feed')." WHERE id IN (".simplode($newsids).") AND idtype='sid'");
//ɾ³ý¾Ù±¨
$_SGLOBAL['db']->query("DELETE FROM ".tname('report')." WHERE id IN (".simplode($newsids).") AND idtype='sid'");
return $shares;
}
//ɾ³ý¼Ç¼
function deletedoings($ids) {
global $_SGLOBAL;
$allowmanage = checkperm('managedoing');
$managebatch = checkperm('managebatch');
$delnum = 0;
//»ñÈ¡»ý·Ö
$reward = getreward('deldoing', 0);
$spaces = $doings = $newdoids = array();
$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('doing')." WHERE doid IN (".simplode($ids).")");
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
if($allowmanage || $value['uid'] == $_SGLOBAL['supe_uid']) {//¹ÜÀíÔ±/×÷Õß
$doings[] = $value;
if(!$managebatch && $value['uid'] != $_SGLOBAL['supe_uid']) {
$delnum++;
}
}
}
if(empty($doings) || (!$managebatch && $delnum > 1)) return array();
foreach($doings as $key => $value) {
$newdoids[] = $value['doid'];
if($allowmanage && $value['uid'] != $_SGLOBAL['supe_uid']) {
//¿Û³ý»ý·Ö
$_SGLOBAL['db']->query("UPDATE ".tname('space')." SET credit=credit-$reward[credit], experience=experience-$reward[experience] WHERE uid='$value[uid]'");
}
}
$_SGLOBAL['db']->query("DELETE FROM ".tname('doing')." WHERE doid IN (".simplode($newdoids).")");
//ɾ³ýÆÀÂÛ
$_SGLOBAL['db']->query("DELETE FROM ".tname('docomment')." WHERE doid IN (".simplode($newdoids).")");
//ɾ³ýfeed
$_SGLOBAL['db']->query("DELETE FROM ".tname('feed')." WHERE id IN (".simplode($newdoids).") AND idtype='doid'");
return $doings;
}
//ɾ³ý»°Ìâ
function deletethreads($tagid, $tids) {
global $_SGLOBAL;
$tnums = $pnums = $delthreads = $newids = $spaces = array();
$ismanager = $allowmanage = checkperm('managethread');
$managebatch = checkperm('managebatch');
$delnum = 0;
//ȺÖ÷
$wheresql = '';
if(empty($allowmanage) && $tagid) {
$mtag = getmtag($tagid);
if($mtag['grade'] >=8) {
$allowmanage = 1;
$managebatch = 1;
$wheresql = " AND t.tagid='$tagid'";
}
}
//»ñÈ¡»ý·Ö
$reward = getreward('delthread', 0);
$query = $_SGLOBAL['db']->query("SELECT t.* FROM ".tname('thread')." t WHERE t.tid IN(".simplode($tids).") $wheresql");
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
if($allowmanage || $value['uid'] == $_SGLOBAL['supe_uid']) {
$delthreads[] = $value;
if(!$managebatch && $value['uid'] != $_SGLOBAL['supe_uid']) {
$delnum++;
}
}
}
if(empty($delthreads) || (!$managebatch && $delnum > 1)) return array();
foreach($delthreads as $key => $value) {
$newids[] = $value['tid'];
$value['isthread'] = 1;
if($ismanager && $value['uid'] != $_SGLOBAL['supe_uid']) {
//¿Û³ý»ý·Ö
$_SGLOBAL['db']->query("UPDATE ".tname('space')." SET credit=credit-$reward[credit], experience=experience-$reward[experience] WHERE uid='$value[uid]'");
}
}
//ɾ³ý
$_SGLOBAL['db']->query("DELETE FROM ".tname('thread')." WHERE tid IN(".simplode($newids).")");
$_SGLOBAL['db']->query("DELETE FROM ".tname('post')." WHERE tid IN(".simplode($newids).")");
//ɾ³ýfeed
$_SGLOBAL['db']->query("DELETE FROM ".tname('feed')." WHERE id IN (".simplode($newids).") AND idtype='tid'");
//ɾ³ý¾Ù±¨
$_SGLOBAL['db']->query("DELETE FROM ".tname('report')." WHERE id IN (".simplode($newids).") AND idtype='tid'");
//ɾ³ý½ÅÓ¡
$_SGLOBAL['db']->query("DELETE FROM ".tname('clickuser')." WHERE id IN (".simplode($newids).") AND idtype='tid'");
return $delthreads;
}
//ɾ³ýÌÖÂÛ
function deleteposts($tagid, $pids) {
global $_SGLOBAL;
//ͳ¼Æ
$postnums = $mpostnums = $tids = $delposts = $newids = $spaces = array();
$ismanager = $allowmanage = checkperm('managethread');
$managebatch = checkperm('managebatch');
$delnum = 0;
//ȺÖ÷
$wheresql = '';
if(empty($allowmanage) && $tagid) {
$mtag = getmtag($tagid);
if($mtag['grade'] >=8) {
$allowmanage = 1;
$managebatch = 1;
$wheresql = " AND p.tagid='$tagid'";
}
}
//»ñÈ¡»ý·Ö
$reward = getreward('delcomment', 0);
$query = $_SGLOBAL['db']->query("SELECT p.* FROM ".tname('post')." p WHERE p.pid IN (".simplode($pids).") $wheresql ORDER BY p.isthread DESC");
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
if($allowmanage || $value['uid'] == $_SGLOBAL['supe_uid']) {
if(!$managebatch && $value['uid'] != $_SGLOBAL['supe_uid']) {
$delnum++;
}
$postarr[] = $value;
}
}
if(!$managebatch && $delnum > 1) return array();
foreach($postarr as $key => $value) {
if($value['isthread']) {
$tids[] = $value['tid'];
} else {
if(!in_array($value['tid'], $tids)) {
$newids[] = $value['pid'];
$delposts[] = $value;
$postnums[$value['tid']]++;
if($ismanager && $value['uid'] != $_SGLOBAL['supe_uid']) {
//¿Û³ý»ý·Ö
$_SGLOBAL['db']->query("UPDATE ".tname('space')." SET credit=credit-$reward[credit], experience=experience-$reward[experience] WHERE uid='$value[uid]'");
}
}
}
}
$delthreads = array();
if($tids) {
$delthreads = deletethreads($tagid, $tids);
}
if(empty($delposts)) {
return $delthreads;
}
//ÕûÀí
$nums = renum($postnums);
foreach ($nums[0] as $pnum) {
$_SGLOBAL['db']->query("UPDATE ".tname('thread')." SET replynum=replynum-$pnum WHERE tid IN (".simplode($nums[1][$pnum]).")");
}
//ɾ³ý
$_SGLOBAL['db']->query("DELETE FROM ".tname('post')." WHERE pid IN (".simplode($newids).")");
return $delposts;
}
//ɾ³ý¿Õ¼ä
function deletespace($uid, $force=0) {
global $_SGLOBAL, $_SC, $_SCONFIG;
$delspace = array();
$allowmanage = checkperm('managedelspace');
$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('space')." WHERE uid='$uid'");
if($value = $_SGLOBAL['db']->fetch_array($query)) {
if($force || $allowmanage && $value['uid'] != $_SGLOBAL['supe_uid']) {
$delspace = $value;
//Èç¹û²»ÊÇÇ¿ÖÆÉ¾³ýÔòÈëɾ³ý¼Ç¼±í
if(!$force) {
$setarr = array(
'uid' => $value['uid'],
'username' => saddslashes($value['username']),
'opuid' => $_SGLOBAL['supe_uid'],
'opusername' => $_SGLOBAL['supe_username'],
'flag' => '-1',
'dateline' => $_SGLOBAL['timestamp']
);
inserttable('spacelog', $setarr, 0, true);
}
}
}
if(empty($delspace)) return array();
//ÂĸÇȨÏÞÉèÖÃ
$_SGLOBAL['usergroup'][$_SGLOBAL['member']['groupid']]['managebatch'] = 1;
//space
$_SGLOBAL['db']->query("DELETE FROM ".tname('space')." WHERE uid='$uid'");
//spacefield
$_SGLOBAL['db']->query("DELETE FROM ".tname('spacefield')." WHERE uid='$uid'");
//feed
$_SGLOBAL['db']->query("DELETE FROM ".tname('feed')." WHERE uid='$uid' OR (id='$uid' AND idtype='uid')");
//¼Ç¼
$doids =array();
$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('doing')." WHERE uid='$uid'");
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
$doids[$value['doid']] = $value['doid'];
}
$_SGLOBAL['db']->query("DELETE FROM ".tname('doing')." WHERE uid='$uid'");
//ɾ³ý¼Ç¼»Ø¸´
$_SGLOBAL['db']->query("DELETE FROM ".tname('docomment')." WHERE doid IN (".simplode($doids).") OR uid='$uid'");
//·ÖÏí
$_SGLOBAL['db']->query("DELETE FROM ".tname('share')." WHERE uid='$uid'");
//Êý¾Ý
$_SGLOBAL['db']->query("DELETE FROM ".tname('album')." WHERE uid='$uid'");
//ɾ³ý»ý·Ö¼Ç¼
$_SGLOBAL['db']->query("DELETE FROM ".tname('creditlog')." WHERE uid='$uid'");
//ɾ³ý֪ͨ
$_SGLOBAL['db']->query("DELETE FROM ".tname('notification')." WHERE (uid='$uid' OR authorid='$uid')");
//ɾ³ý´òÕкô
$_SGLOBAL['db']->query("DELETE FROM ".tname('poke')." WHERE (uid='$uid' OR fromuid='$uid')");
//ɾ³ýËû²Ö½¨µÄͶƱ
$pollid = array();
$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('poll')." WHERE uid='$uid'");
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
$pollid[$value['pid']] = $value['pid'];
}
deletepolls($pollid);
//ɾ³ýËû²ÎÓëµÄͶƱ
$pollid = array();
$query = $_SGLOBAL['db']->query("SELECT pid FROM ".tname('polluser')." WHERE uid='$uid'");
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
$pollid[$value['pid']] = $value['pid'];
}
//¿Û³ýͶƱÊý
if($pollid) {
$_SGLOBAL['db']->query("UPDATE ".tname('poll')." SET voternum=voternum-1 WHERE pid IN (".simplode($pollid).")");
}
$_SGLOBAL['db']->query("DELETE FROM ".tname('polluser')." WHERE uid='$uid'");
//»î¶¯
$ids = array();
$query = $_SGLOBAL['db']->query('SELECT eventid FROM '.tname('event')." WHERE uid = '$uid'");
while($value = $_SGLOBAL['db']->fetch_array($query)) {
$ids[] = $value['eventid'];
}
deleteevents($ids);
//ɾ³ýËû²Î¼ÓµÄ»î¶¯
$ids = $ids1 = $ids2 = array();
$query = $_SGLOBAL['db']->query('SELECT * FROM '.tname('userevent')." WHERE uid = '$uid'");
while($value = $_SGLOBAL['db']->fetch_array($query)) {
if($value['status'] == 1) {
$ids1[] = $value['eventid'];//¹Ø×¢
} elseif($value['status'] > 1) {
$ids2[] = $value['eventid'];//²Î¼Ó
}
$ids[] = $value['eventid'];
}
if($ids1) {
$_SGLOBAL['db']->query('UPDATE '.tname('event').' SET follownum = follownum - 1 WHERE eventid IN ('.simplode($ids1).')');
}
if($ids2) {
$_SGLOBAL['db']->query('UPDATE '.tname('event').' SET membernum = membernum - 1 WHERE eventid IN ('.simplode($ids2).')');// to to: ×îºÃ»¹Òª¼ì²é²¢¼õÈ¥ËûЯ´øµÄÈËÊý
}
if($ids) {
$_SGLOBAL['db']->query('DELETE FROM '.tname('userevent').' WHERE eventid IN ('.simplode($ids).") AND uid = '$uid'");
}
//ɾ³ýÏà¹Ø»î¶¯ÑûÇë
$_SGLOBAL['db']->query('DELETE FROM '.tname('eventinvite')." WHERE uid = '$uid' OR touid = '$uid'");
//ɾ³ýÉÏ´«µÄ»î¶¯Í¼Æ¬
$_SGLOBAL['db']->query('DELETE FROM '.tname('eventpic')." WHERE picid = '$uid'");//to do: ×îºÃͬʱ¸üлͼƬÊýºÍ»î¶¯»°ÌâÊý
//µÀ¾ß
$_SGLOBAL['db']->query('DELETE FROM '.tname('usermagic')." WHERE uid = '$uid'");
$_SGLOBAL['db']->query('DELETE FROM '.tname('magicinlog')." WHERE uid = '$uid'");
$_SGLOBAL['db']->query('DELETE FROM '.tname('magicuselog')." WHERE uid = '$uid'");
//pic
//ɾ³ýͼƬ¸½¼þ
$pics = array();
$query = $_SGLOBAL['db']->query("SELECT filepath FROM ".tname('pic')." WHERE uid='$uid'");
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
$pics[] = $value;
}
//Êý¾Ý
$_SGLOBAL['db']->query("DELETE FROM ".tname('pic')." WHERE uid='$uid'");
//blog
$blogids = array();
$query = $_SGLOBAL['db']->query("SELECT blogid FROM ".tname('blog')." WHERE uid='$uid'");
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
$blogids[$value['blogid']] = $value['blogid'];
//tag
$tags = array();
$subquery = $_SGLOBAL['db']->query("SELECT tagid, blogid FROM ".tname('tagblog')." WHERE blogid='$value[blogid]'");
while ($tag = $_SGLOBAL['db']->fetch_array($subquery)) {
$tags[$tag['tagid']] = $tag['tagid'];
}
if($tags) {
$_SGLOBAL['db']->query("UPDATE ".tname('tag')." SET blognum=blognum-1 WHERE tagid IN (".simplode($tags).")");
$_SGLOBAL['db']->query("DELETE FROM ".tname('tagblog')." WHERE blogid='$value[blogid]'");
}
}
//Êý¾Ýɾ³ý
$_SGLOBAL['db']->query("DELETE FROM ".tname('blog')." WHERE uid='$uid'");
$_SGLOBAL['db']->query("DELETE FROM ".tname('blogfield')." WHERE uid='$uid'");
//ÆÀÂÛ
$_SGLOBAL['db']->query("DELETE FROM ".tname('comment')." WHERE (uid='$uid' OR authorid='$uid' OR (id='$uid' AND idtype='uid'))");
//·Ã¿Í
$_SGLOBAL['db']->query("DELETE FROM ".tname('visitor')." WHERE (uid='$uid' OR vuid='$uid')");
//ɾ³ýÈÎÎñ¼Ç¼
$_SGLOBAL['db']->query("DELETE FROM ".tname('usertask')." WHERE uid='$uid'");
//class
$_SGLOBAL['db']->query("DELETE FROM ".tname('class')." WHERE uid='$uid'");
//friend
//ºÃÓÑ
$_SGLOBAL['db']->query("DELETE FROM ".tname('friend')." WHERE (uid='$uid' OR fuid='$uid')");
//member
$_SGLOBAL['db']->query("DELETE FROM ".tname('member')." WHERE uid='$uid'");
//ɾ³ý½ÅÓ¡
$_SGLOBAL['db']->query("DELETE FROM ".tname('clickuser')." WHERE uid='$uid'");
//ɾ³ýºÚÃûµ¥
$_SGLOBAL['db']->query("DELETE FROM ".tname('blacklist')." WHERE (uid='$uid' OR buid='$uid')");
//ɾ³ýÑûÇë¼Ç¼
$_SGLOBAL['db']->query("DELETE FROM ".tname('invite')." WHERE (uid='$uid' OR fuid='$uid')");
//ɾ³ýÓʼþ¶ÓÁÐ
$_SGLOBAL['db']->query("DELETE FROM ".tname('mailcron').", ".tname('mailqueue')." USING ".tname('mailcron').", ".tname('mailqueue')." WHERE ".tname('mailcron').".touid='$uid' AND ".tname('mailcron').".cid=".tname('mailqueue').".cid");
//ÂþÓÎÑûÇë
$_SGLOBAL['db']->query("DELETE FROM ".tname('myinvite')." WHERE (touid='$uid' OR fromuid='$uid')");
$_SGLOBAL['db']->query("DELETE FROM ".tname('userapp')." WHERE uid='$uid'");
$_SGLOBAL['db']->query("DELETE FROM ".tname('userappfield')." WHERE uid='$uid'");
//mtag
//thread
$tids = array();
$query = $_SGLOBAL['db']->query("SELECT tid, tagid FROM ".tname('thread')." WHERE uid='$uid'");
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
$tids[$value['tagid']][] = $value['tid'];
}
foreach ($tids as $tagid => $v_tids) {
deletethreads($tagid, $v_tids);
}
//post
$pids = array();
$query = $_SGLOBAL['db']->query("SELECT pid, tagid FROM ".tname('post')." WHERE uid='$uid'");
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
$pids[$value['tagid']][] = $value['pid'];
}
foreach ($pids as $tagid => $v_pids) {
deleteposts($tagid, $v_pids);
}
$_SGLOBAL['db']->query("DELETE FROM ".tname('thread')." WHERE uid='$uid'");
$_SGLOBAL['db']->query("DELETE FROM ".tname('post')." WHERE uid='$uid'");
//session
$_SGLOBAL['db']->query("DELETE FROM ".tname('session')." WHERE uid='$uid'");
//ÅÅÐаñ
$_SGLOBAL['db']->query("DELETE FROM ".tname('show')." WHERE uid='$uid'");
//Ⱥ×é
$mtagids = array();
$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('tagspace')." WHERE uid='$uid'");
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
$mtagids[$value['tagid']] = $value['tagid'];
}
if($mtagids) {
$_SGLOBAL['db']->query("UPDATE ".tname('mtag')." SET membernum=membernum-1 WHERE tagid IN (".simplode($mtagids).")");
$_SGLOBAL['db']->query("DELETE FROM ".tname('tagspace')." WHERE uid='$uid'");
}
$_SGLOBAL['db']->query("DELETE FROM ".tname('mtaginvite')." WHERE (uid='$uid' OR fromuid='$uid')");
//ɾ³ýͼƬ
deletepicfiles($pics);//ɾ³ýͼƬ
//ɾ³ý¾Ù±¨
$_SGLOBAL['db']->query("DELETE FROM ".tname('report')." WHERE id='$uid' AND idtype='uid'");
//±ä¸ü¼Ç¼
if($_SCONFIG['my_status']) inserttable('userlog', array('uid'=>$uid, 'action'=>'delete', 'dateline'=>$_SGLOBAL['timestamp']), 0, true);
return $delspace;
}
//ɾ³ýͼƬ
function deletepics($picids) {
global $_SGLOBAL, $_SC;
$delpics = $albumnums = $newids = $sizes = $auids = $spaces = array();
$allowmanage = checkperm('managealbum');
$managebatch = checkperm('managebatch');
$delnum = 0;
$pics = array();
$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('pic')." WHERE picid IN (".simplode($picids).")");
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
if($allowmanage || $value['uid'] == $_SGLOBAL['supe_uid']) {
//ɾ³ýÎļþ
$pics[] = $value;
$newids[] = $value['picid'];
$delpics[] = $value;
$allsize = $allsize + $value['size'];
$sizes[$value['uid']] = $sizes[$value['uid']] + $value['size'];
if($value['albumid']) {
$auids[$value['albumid']] = $value['uid'];
$albumnums[$value['albumid']]++;
}
if($value['uid'] != $_SGLOBAL['supe_uid']) {
if(!$managebatch) {
$delnum++;
}
$spaces[$value['uid']]++;
}
}
}
if(empty($delpics) || (!$managebatch && $delnum > 1)) return array();
//»ñÈ¡»ý·Ö
$reward = getreward('delimage', 0);
foreach ($spaces as $uid => $picnum) {
$attachsize = intval($sizes[$uid]);
$setsql = '';
if($allowmanage) {
$setsql = $reward['credit']?(",credit=credit-".($picnum*$reward['credit'])):"";
$setsql .= $reward['experience']?(",experience=experience-".($picnum*$reward['experience'])):"";
}
$_SGLOBAL['db']->query("UPDATE ".tname('space')." SET attachsize=attachsize-$attachsize $setsql WHERE uid='$uid'");
}
if($newids) {
$_SGLOBAL['db']->query("DELETE FROM ".tname('pic')." WHERE picid IN (".simplode($newids).")");
$_SGLOBAL['db']->query("DELETE FROM ".tname('comment')." WHERE id IN (".simplode($newids).") AND idtype='picid'");
$_SGLOBAL['db']->query("DELETE FROM ".tname('feed')." WHERE id IN (".simplode($newids).") AND idtype='picid'");
//ɾ³ý¾Ù±¨
$_SGLOBAL['db']->query("DELETE FROM ".tname('report')." WHERE id IN (".simplode($newids).") AND idtype='picid'");
//ɾ³ý½ÅÓ¡
$_SGLOBAL['db']->query("DELETE FROM ".tname('clickuser')." WHERE id IN (".simplode($newids).") AND idtype='picid'");
}
if($albumnums) {
include_once(S_ROOT.'./source/function_cp.php');
foreach ($albumnums as $id => $num) {
$thepic = getalbumpic($auids[$id], $id);
$_SGLOBAL['db']->query("UPDATE ".tname('album')." SET pic='$thepic', picnum=picnum-$num WHERE albumid='$id'");
}
}
//ɾ³ýͼƬ
deletepicfiles($pics);
return $delpics;
}
//ɾ³ýͼƬÎļþ
function deletepicfiles($pics) {
global $_SGLOBAL, $_SC;
$remotes = array();
foreach ($pics as $pic) {
if($pic['remote']) {
$remotes[] = $pic;
} else {
$file = $_SC['attachdir'].'./'.$pic['filepath'];
if(!@unlink($file)) {
runlog('PIC', "Delete pic file '$file' error.", 0);
}
if($pic['thumb']) {
if(!@unlink($file.'.thumb.jpg')) {
runlog('PIC', "Delete pic file '{$file}.thumb.jpg' error.", 0);
}
}
}
}
//ɾ³ýÔ¶³Ì¸½¼þ
if($remotes) {
include_once(S_ROOT.'./data/data_setting.php');
include_once(S_ROOT.'./source/function_ftp.php');
$ftpconnid = sftp_connect();
foreach ($remotes as $pic) {
$file = $pic['filepath'];
if($ftpconnid) {
if(!sftp_delete($ftpconnid, $file)) {
runlog('FTP', "Delete pic file '$file' error.", 0);
}
if($pic['thumb'] && !sftp_delete($ftpconnid, $file.'.thumb.jpg')) {
runlog('FTP', "Delete pic file '{$file}.thumb.jpg' error.", 0);
}
} else {
runlog('FTP', "Delete pic file '$file' error.", 0);
if($pic['thumb']) {
runlog('FTP', "Delete pic file '{$file}.thumb.jpg' error.", 0);
}
}
}
}
}
//ɾ³ýÏà²á
function deletealbums($albumids) {
global $_SGLOBAL, $_SC;
$dels = $newids = $sizes = $spaces = array();
$allowmanage = checkperm('managealbum');
$managebatch = checkperm('managebatch');
$delnum = 0;
$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('album')." WHERE albumid IN (".simplode($albumids).")");
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
if($allowmanage || $value['uid'] == $_SGLOBAL['supe_uid']) {
$dels[] = $value;
$newids[] = $value['albumid'];
if(!$managebatch && $value['uid'] != $_SGLOBAL['supe_uid']) {
$delnum++;
}
}
}
if(empty($dels) || (!$managebatch && $delnum > 1)) return array();
//»ñÈ¡»ý·Ö
$reward = getreward('delimage', 0);
$pics = array();
$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('pic')." WHERE albumid IN (".simplode($newids).")");
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
$sizes[$value['uid']] = $sizes[$value['uid']] + $value['size'];
$pics[] = $value;
$setsql = '';
if($allowmanage && $value['uid'] != $_SGLOBAL['supe_uid']) {
//¿Û³ý»ý·Ö
$setsql = $reward['credit']?(",credit=credit-$reward[credit]"):"";
$setsql .= $reward['experience']?(",experience=experience-$reward[experience]"):"";
}
$_SGLOBAL['db']->query("UPDATE ".tname('space')." SET attachsize=attachsize-$value[size] $setsql WHERE uid='$value[uid]'");
}
if($sizes) {
$_SGLOBAL['db']->query("DELETE FROM ".tname('pic')." WHERE albumid IN (".simplode($newids).")");
}
$_SGLOBAL['db']->query("DELETE FROM ".tname('album')." WHERE albumid IN (".simplode($newids).")");
$_SGLOBAL['db']->query("DELETE FROM ".tname('feed')." WHERE id IN (".simplode($newids).") AND idtype='albumid'");
//ɾ³ý¾Ù±¨
$_SGLOBAL['db']->query("DELETE FROM ".tname('report')." WHERE id IN (".simplode($newids).") AND idtype='albumid'");
//ɾ³ýͼƬ
if($pics) {
deletepicfiles($pics);//ɾ³ýͼƬ
}
return $dels;
}
//ɾ³ýtag
function deletetags($tagids) {
global $_SGLOBAL;
if(!checkperm('managetag')) return false;
//Êý¾Ý
$_SGLOBAL['db']->query("DELETE FROM ".tname('tagblog')." WHERE tagid IN (".simplode($tagids).")");
$_SGLOBAL['db']->query("DELETE FROM ".tname('tag')." WHERE tagid IN (".simplode($tagids).")");
return true;
}
//ɾ³ýmtag
function deletemtag($tagids) {
global $_SGLOBAL;
if(!checkperm('manageprofield') && !checkperm('managemtag')) return array();
$dels = $newids = array();
$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('mtag')." WHERE tagid IN (".simplode($tagids).")");
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
$newids[] = $value['tagid'];
$dels[] = $value;
}
if(empty($newids)) return array();
//Êý¾Ý
$_SGLOBAL['db']->query("DELETE FROM ".tname('tagspace')." WHERE tagid IN (".simplode($newids).")");
$_SGLOBAL['db']->query("DELETE FROM ".tname('mtag')." WHERE tagid IN (".simplode($newids).")");
$_SGLOBAL['db']->query("DELETE FROM ".tname('thread')." WHERE tagid IN (".simplode($newids).")");
$_SGLOBAL['db']->query("DELETE FROM ".tname('post')." WHERE tagid IN (".simplode($newids).")");
$_SGLOBAL['db']->query("DELETE FROM ".tname('mtaginvite')." WHERE tagid IN (".simplode($newids).")");
//ɾ³ý¾Ù±¨
$_SGLOBAL['db']->query("DELETE FROM ".tname('report')." WHERE id IN (".simplode($newids).") AND idtype='tagid'");
return $dels;
}
//ɾ³ýÓû§À¸Ä¿
function deleteprofilefield($fieldids) {
global $_SGLOBAL;
if(!checkperm('manageprofilefield')) return false;
//ɾ³ýÊý¾Ý
$_SGLOBAL['db']->query("DELETE FROM ".tname('profilefield')." WHERE fieldid IN (".simplode($fieldids).")");
//¸ü¸Ä±í½á¹¹
foreach ($fieldids as $id) {
$_SGLOBAL['db']->query("ALTER TABLE ".tname('spacefield')." DROP `field_$id`", 'SILENT');
}
return true;
}
//ɾ³ýÀ¸Ä¿
function deleteprofield($fieldids, $newfieldid) {
global $_SGLOBAL;
if(!checkperm('manageprofield')) return false;
//ɾ³ýÊý¾Ý
$_SGLOBAL['db']->query("DELETE FROM ".tname('profield')." WHERE fieldid IN (".simplode($fieldids).")");
//¸üÐÂÀ¸Ä¿
$_SGLOBAL['db']->query("UPDATE ".tname('mtag')." SET fieldid='$newfieldid' WHERE fieldid IN (".simplode($fieldids).")");
return true;
}
//¹ã¸æÉ¾³ý
function deleteads($adids) {
global $_SGLOBAL;
if(!checkperm('managead')) return false;
$dels = $newids = array();
$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('ad')." WHERE adid IN (".simplode($adids).")");
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
//ɾ³ýÄ£°åÓëÄ£°å±àÒëÎļþ
$tpl = S_ROOT."./data/adtpl/$value[adid].htm";//Ôʼ
swritefile($tpl, ' ');
$newids[] = $value['adid'];
$dels[] = $value;
}
if(empty($dels)) return array();
//Êý¾Ý
$_SGLOBAL['db']->query("DELETE FROM ".tname('ad')." WHERE adid IN (".simplode($newids).")");
return $dels;
}
//Ä£¿éɾ³ý
function deleteblocks($bids) {
global $_SGLOBAL;
if(!checkperm('managead')) return false;
$dels = $newids = array();
$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('block')." WHERE bid IN (".simplode($bids).")");
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
//ɾ³ýÄ£°åÓëÄ£°å±àÒëÎļþ
$tpl = S_ROOT."./data/blocktpl/$value[bid].htm";//Ôʼ
swritefile($tpl, ' ');
$newids[] = $value['bid'];
$dels[] = $value;
}
if(empty($dels)) return array();
//Êý¾Ý
$_SGLOBAL['db']->query("DELETE FROM ".tname('block')." WHERE bid IN (".simplode($newids).")");
return $dels;
}
//ɾ³ýÈÈÄÖ
function deletetopics($ids) {
global $_SGLOBAL;
//Êý¾Ý
$newids = array();
$managetopic = checkperm('managetopic');
$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('topic')." WHERE topicid IN (".simplode($ids).")");
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
if($managetopic || $value['uid'] == $_SGLOBAL['supe_uid']) {
$newids[] = $value['topicid'];
}
}
if($newids) {
$_SGLOBAL['db']->query("DELETE FROM ".tname('topic')." WHERE topicid IN (".simplode($newids).")");
return true;
} else {
return false;
}
}
//ɾ³ýͶƱ
function deletepolls($pids) {
global $_SGLOBAL;
//»ñȡͶƱÐÅÏ¢
$sparecredit = $spaces = $polls = $newpids = array();
//»ñÈ¡»ý·Ö
$reward = getreward('delpoll', 0);
$allowmanage = checkperm('managepoll');
$managebatch = checkperm('managebatch');
$delnum = 0;
$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('poll')." WHERE pid IN (".simplode($pids).")");
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
if($allowmanage || $value['uid'] == $_SGLOBAL['supe_uid']) {
$polls[] = $value;
if(!$managebatch && $value['uid'] != $_SGLOBAL['supe_uid']) {
$delnum++;
}
}
}
if(empty($polls) || (!$managebatch && $delnum > 1)) return array();
foreach($polls as $key => $value) {
$newpids[] = $value['pid'];
if($allowmanage && $value['uid'] != $_SGLOBAL['supe_uid']) {
//¿Û³ý»ý·Ö
$_SGLOBAL['db']->query("UPDATE ".tname('space')." SET credit=credit-$reward[credit], experience=experience-$reward[experience] WHERE uid='$value[uid]'");
}
//¹é»¹Î´ÐüÉÍÍêµÄ»ý·Ö
if($value['credit'] > 0) {
$sparecredit = intval($value['credit']);
$_SGLOBAL['db']->query("UPDATE ".tname('space')." SET credit=credit+$sparecredit WHERE uid='$value[uid]'");
}
}
//Êý¾Ýɾ³ý
$_SGLOBAL['db']->query("DELETE FROM ".tname('poll')." WHERE pid IN (".simplode($newpids).")");
$_SGLOBAL['db']->query("DELETE FROM ".tname('pollfield')." WHERE pid IN (".simplode($newpids).")");
$_SGLOBAL['db']->query("DELETE FROM ".tname('polloption')." WHERE pid IN (".simplode($newpids).")");
$_SGLOBAL['db']->query("DELETE FROM ".tname('polluser')." WHERE pid IN (".simplode($newpids).")");
//ÆÀÂÛ
$_SGLOBAL['db']->query("DELETE FROM ".tname('comment')." WHERE id IN (".simplode($newpids).") AND idtype='pid'");
$_SGLOBAL['db']->query("DELETE FROM ".tname('feed')." WHERE id IN (".simplode($newpids).") AND idtype='pid'");
//ɾ³ý¾Ù±¨
$_SGLOBAL['db']->query("DELETE FROM ".tname('report')." WHERE id IN (".simplode($newpids).") AND idtype='pid'");
return $polls;
}
// ɾ³ý»î¶¯
function deleteevents($eventids){
global $_SGLOBAL;
$allowmanage = checkperm('manageevent');
$managebatch = checkperm('managebatch');
$delnum = 0;
$eventarr = $neweventids = $note_ids = $note_inserts = array();
//»ñÈ¡»ý·Ö
$reward = getreward('delevent', 0);
$query = $_SGLOBAL['db']->query("SELECT * FROM ". tname("event") . " WHERE eventid IN (" . simplode($eventids).")");
while($value=$_SGLOBAL['db']->fetch_array($query)){
if($allowmanage || $value['uid'] == $_SGLOBAL['supe_uid']){
$eventarr[] = $value;
if(!$managebatch && $value['uid'] != $_SGLOBAL['supe_uid']) {
$delnum++;
}
}
}
if(empty($eventarr) || (!$managebatch && $delnum > 1)) return array();
foreach($eventarr as $key => $value) {
$neweventids[] = $value['eventid'];
// [to do: ¸ø»î¶¯²Î¼ÓÕß·¢Í¨Öª¡£²Ù×÷Á¿Ì«´ó£¬ËùÒÔÓÅÏȼ¶£ºµÍ]
if($value['uid'] != $_SGLOBAL['supe_uid']) {
if($allowmanage) {
//¿Û³ý»ý·Ö
$_SGLOBAL['db']->query("UPDATE ".tname('space')." SET credit=credit-$reward[credit], experience=experience-$reward[experience] WHERE uid='$value[uid]'");
}
$note_ids[] = $value['uid'];
$note_msg = cplang('event_set_delete', array($value['title']));
$note_inserts[] = "('$value[uid]', 'event', '1', '$_SGLOBAL[supe_uid]', '$_SGLOBAL[supe_username]', '".addslashes($note_msg)."', '$_SGLOBAL[timestamp]')";
}
}
//Êý¾Ýɾ³ý
$_SGLOBAL['db']->query("DELETE FROM ".tname('event')." WHERE eventid IN (".simplode($neweventids).")");
$_SGLOBAL['db']->query("DELETE FROM ".tname('eventpic')." WHERE eventid IN (".simplode($neweventids).")");
$_SGLOBAL['db']->query("DELETE FROM ".tname('eventinvite')." WHERE eventid IN (".simplode($neweventids).")");
//»î¶¯Óû§
$_SGLOBAL['db']->query("DELETE FROM ".tname('userevent')." WHERE eventid IN (".simplode($neweventids).")");
//ÆÀÂÛ
$_SGLOBAL['db']->query("DELETE FROM ".tname('comment')." WHERE id IN (".simplode($neweventids).") AND idtype='eventid'");
$_SGLOBAL['db']->query("DELETE FROM ".tname('feed')." WHERE id IN (".simplode($neweventids).") AND idtype='eventid'");
//ɾ³ý¾Ù±¨
$_SGLOBAL['db']->query("DELETE FROM ".tname('report')." WHERE id IN (".simplode($neweventids).") AND idtype='eventid'");
//·¢ËÍ֪ͨ
if($note_inserts){
$_SGLOBAL['db']->query("INSERT INTO ".tname('notification')." (`uid`, `type`, `new`, `authorid`, `author`, `note`, `dateline`) VALUES ".implode(',', $note_inserts));
$_SGLOBAL['db']->query("UPDATE ".tname('space')." SET notenum=notenum+1 WHERE uid IN (".simplode($note_ids).")");
}
return $eventarr;
}
?>