<?php
/**
* @author moufer<moufer@163.com>
* @copyright www.modoer.com
* @version $Id 3 2008-08-25 18:35 $
*/
!defined('IN_MUDDER') && exit('Access Denied');

if(!check_submit('mysubmit')) {

    $from = "{$dbpre}favorites a LEFT JOIN {$dbpre}shops b ON(a.shopid=b.sid)";
    $where = "a.uid='{$user->uid}'";
    $total = $db->get_value("SELECT COUNT(*) FROM {$dbpre}favorites WHERE uid='{$user->uid}'");
    if($total > 0) {
        $query = $db->query("SELECT a.*,FROM_UNIXTIME(a.addtime,'%Y-%m-%d %H:%i:%s')as addtime,b.shopname,b.subname,b.reviews FROM $from WHERE $where ORDER BY a.addtime DESC LIMIT $limit");
        while($row = $db->fetch_array($query)) {
            $row['shopname'] .= $row['subname'] ? "({$row['subname']})" : '';
            $favorites[] = $row;
        }
        $multipage = multi($total, $offset, $page, "index.php?ac=$ac");
    }

} else {

    if(!is_array($favoriteIds)||count($favoriteIds)<=0){
        redirect("未选择删除项。");
    }else{
        foreach($favoriteIds as $favoriteId){
            $db->update("DELETE FROM {$dbpre}favorites WHERE fid='$favoriteId' AND uid='{$user->uid}'");
        }
        redirect('删除完毕！',"index.php?ac=$ac");
    }

}
?>