コード例 #1
0
ファイル: function_delete.php プロジェクト: NaturalWill/UCQA
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;
}
コード例 #2
0
function deletepics($picids)
{
    global $_SGLOBAL, $_SC;
    $delpics = $albumnums = $newids = $sizes = $auids = $spaces = array();
    $allowmanage = checkperm('managealbum');
    $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']]++;
            }
            $spaces[$value['uid']]++;
        }
    }
    if (empty($delpics)) {
        return array();
    }
    $pic_credit = creditrule('pay', 'pic');
    foreach ($spaces as $uid => $picnum) {
        $attachsize = intval($sizes[$uid]);
        $setsql = $pic_credit ? ",credit=credit-" . $picnum * $pic_credit : "";
        $_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('report') . " 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;
}