Example #1
0
     } else {
         if (in_array($mname, array('good', 'notice', 'consume', 'album', 'groupbuy'))) {
             // 刪除的時候更新計數
             $shopid_query = DB::query("select * from " . DB::table($mname . 'items') . " where " . $wheresql);
             while ($__item = DB::fetch($shopid_query)) {
                 shop::update_item_num($mname, $__item['shopid'], -1);
             }
             if ($mname == 'album') {
                 $innerjoinsql = '';
                 $frombbs = ' and i.frombbs = 0';
             } else {
                 $innerjoinsql = "INNER JOIN " . tname($mname . 'message') . " m ON i.itemid=m.itemid";
                 $frombbs = '';
             }
         }
         delmitems($wheresql, $mname);
         //刪除信息
         if ($mname == 'shop') {
             updatememberstats();
         }
         //刪除完信息後更新
         $opsql = $wheresql = '';
         cpmsg('message_success', $cookie_referer);
     }
     break;
 case 'pass':
     $opsql .= ' grade=\'3\'';
     break;
 case 'refuse':
     $opsql .= ' grade=\'1\'';
     break;
Example #2
0
function delmitems($wheresql = '', $type = 'shop')
{
    global $_G, $_SGLOBAL, $itemarr, $mname, $_BCACHE;
    if (!empty($wheresql)) {
        $thissql = str_replace(' itemid IN', ' i.itemid IN', $wheresql);
        $itemidsql = $relatedidsql = '';
        if ($mname != 'shop') {
            $itemidsql = 'itemid';
            $relatedidsql = 'relatedid';
        }
        if ($type == 'shop') {
            $subsql = str_replace(' itemid IN', ' shopid IN', $wheresql);
            if ($_POST['opdelete']) {
                //遞歸刪除所有店舖的子元素
                delmitems($subsql, 'good');
                delmitems($subsql, 'consume');
                delmitems($subsql, 'notice');
                delmitems($subsql, 'photo');
                delmitems($subsql, 'album');
                $commquery = DB::query("SELECT cid FROM " . tname("spacecomments") . " WHERE {$wheresql}");
                while ($res = DB::fetch($commquery)) {
                    deletecomment($res['cid']);
                }
                $shop_related_sql = str_replace(' itemid IN', ' shopid IN', $wheresql);
                DB::query("DELETE FROM " . tname('relatedinfo') . " WHERE " . $shop_related_sql);
            }
            $selectsql = ' i.itemid, i.subject, m.banner, m.windowsimg ';
            $joinsql = tname('shopitems') . ' i INNER JOIN ' . tname('shopmessage') . ' m ON i.itemid=m.itemid ';
        } elseif ($type == 'album') {
            $subsql = str_replace(' itemid IN', ' i.albumid IN', $wheresql);
            delmitems($subsql, 'photo');
            $selectsql = ' i.itemid, i.subjectimage ';
            $joinsql = tname($type . 'items') . ' i';
            // 刪除關聯信息
            $related_sql = str_replace(' itemid IN', ' IN', $wheresql);
            DB::query("DELETE FROM " . tname('relatedinfo') . " WHERE relatedtype = 'album' AND {$relatedid} " . $related_sql);
        } elseif ($type == 'photo') {
            $selectsql = ' i.itemid, i.albumid, i.subjectimage ';
            $joinsql = tname($type . 'items') . ' i';
        } else {
            $selectsql = ' i.itemid, i.subjectimage ';
            $joinsql = tname($type . 'items') . ' i';
            $related_sql = str_replace(' itemid IN', ' IN', $wheresql);
            if ($type == 'good' || $type == 'groupbuy') {
                DB::query("DELETE FROM " . tname('relatedinfo') . " WHERE type = '" . $type . "' AND {$itemidsql} " . $related_sql);
            }
            DB::query("DELETE FROM " . tname('relatedinfo') . " WHERE relatedtype = '" . $type . "' AND {$relatedid} " . $related_sql);
        }
        $thisalbumid = 0;
        $query = DB::query('SELECT ' . $selectsql . ' FROM ' . $joinsql . ' WHERE ' . $thissql);
        $filefields = array('subjectimage', 'banner', 'windowsimg');
        //刪除圖片
        while ($value = DB::fetch($query)) {
            foreach ($filefields as $v) {
                if (!empty($value[$v]) && strstr($value[$v], '.jpg')) {
                    @unlink(A_DIR . '/' . $value[$v]);
                    @unlink(A_DIR . '/' . substr($value[$v], 0, -4) . '.thumb.jpg');
                }
            }
            $thisalbumid = $value['albumid'];
        }
        if (in_array($type, array('album', 'photo'))) {
            $query = DB::query('DELETE i FROM ' . tname($type . 'items') . ' i WHERE ' . $thissql);
            //刪除相冊和圖片信息,只有item表
            if ($type == 'photo' && $thisalbumid > 0) {
                $picnums = DB::affected_rows($query);
                $query = DB::query('UPDATE ' . tname('albumitems') . " SET `picnum`=`picnum`-{$picnums} WHERE itemid='{$thisalbumid}'");
                //刪除相冊和圖片信息,只有item表
                if (!empty($thisalbumid)) {
                    require_once B_ROOT . './api/bbs_syncpost.php';
                    syncalbum($thisalbumid);
                }
                if ($_SGLOBAL['panelinfo']['group']['verifyalbum']) {
                    $thisalbumgrade = DB::result_first('SELECT grade FROM ' . tname('albumitems') . ' WHERE itemid=\'' . $thisalbumid . '\'');
                    if ($thisalbumgrade == 1) {
                        DB::query("UPDATE " . tname('albumitems') . " SET grade = 0 WHERE itemid = '{$thisalbumid}'");
                    }
                }
            }
        } elseif ($type == 'shop') {
            foreach ($itemarr as $itemid) {
                updatemyshopid($itemid);
                deletetable('shopitems', array('itemid' => $itemid));
                deletetable('shopmessage', array('itemid' => $itemid));
            }
        } else {
            $query = DB::query('DELETE i, m FROM ' . tname($type . 'items') . ' i INNER JOIN ' . tname($type . 'message') . ' m ON i.itemid=m.itemid WHERE ' . $thissql);
            //刪除信息
        }
    }
}