public function fetch_all_for_manage($tableid, $inforum = '', $authorid = 0, $filename = '', $keyword = '', $sizeless = 0, $sizemore = 0, $dlcountless = 0, $dlcountmore = 0, $daysold = 0, $count = 0, $start = 0, $limit = 0) { $sql = "1"; if (!is_numeric($tableid) || $tableid < 0 || $tableid > 9) { return; } if ($inforum) { $sql .= is_numeric($inforum) ? " AND t.fid=" . XDB::quote($inforum) : ''; $sql .= $inforum == 'isgroup' ? ' AND t.isgroup=\'1\'' : ' AND t.isgroup=\'0\''; } if ($authorid) { $sql .= " AND a.uid=" . XDB::quote($authorid); } if ($filename) { $sql .= " AND a.filename LIKE " . XDB::quote('%' . $filename . '%'); } if ($keyword) { $sqlkeywords = $or = ''; foreach (explode(',', str_replace(' ', '', $keyword)) as $keyword) { $sqlkeywords .= " {$or} a.description LIKE " . XDB::quote('%' . $keyword . '%'); $or = 'OR'; } $sql .= " AND ({$sqlkeywords})"; } $sql .= $sizeless ? " AND a.filesize>'{$sizeless}'" : ''; $sql .= $sizemore ? " AND a.filesize<'{$sizemore}' " : ''; $sql .= $dlcountless ? " AND ai.downloads<'{$dlcountless}'" : ''; $sql .= $dlcountmore ? " AND ai.downloads>'{$dlcountmore}'" : ''; $sql .= $daysold ? " AND a.dateline<'" . (TIMESTAMP - intval($daysold) * 86400) . "'" : ''; if ($count) { return XDB::result_first("SELECT COUNT(*)\n\t\t\t\tFROM " . XDB::table('forum_attachment_' . $tableid) . " a\n\t\t\t\tINNER JOIN " . XDB::table('forum_attachment') . " ai USING(aid)\n\t\t\t\tINNER JOIN " . XDB::table('forum_thread') . " t\n\t\t\t\tINNER JOIN " . XDB::table('forum_forum') . " f\n\t\t\t\tWHERE t.tid=a.tid AND f.fid=t.fid AND t.displayorder>='0' AND {$sql}"); } return XDB::fetch_all("SELECT a.*, ai.downloads, t.fid, t.tid, t.subject, f.name AS fname\n\t\t\t\tFROM " . XDB::table('forum_attachment_' . $tableid) . " a\n\t\t\t\tINNER JOIN " . XDB::table('forum_attachment') . " ai USING(aid)\n\t\t\t\tINNER JOIN " . XDB::table('forum_thread') . " t\n\t\t\t\tINNER JOIN " . XDB::table('forum_forum') . " f\n\t\t\t\tWHERE t.tid=a.tid AND f.fid=t.fid AND t.displayorder>='0' AND {$sql} ORDER BY a.aid DESC " . XDB::limit($start, $limit)); }