www.gusucode.com > 08CMS空白站群系统 3.3 繁体 UTF-8 > upload/adminm/search.inc.php
<?php !defined('M_COM') && exit('No Permission'); include_once M_ROOT."./include/fields.cls.php"; include_once M_ROOT."./include/fields.fun.php"; load_cache('acatalogs,channels,cotypes'); $catalogs = &$acatalogs; !$curuser->check_allow('searchpermit') && mcmessage(lang('belong usergroup nohave search permission')); $chid = empty($chid) ? 0 : $chid; $viewdetail = empty($viewdetail) ? 0 : $viewdetail; $page = empty($page) ? 1 : max(1, intval($page)); $search_max && $page = min($page,@ceil($search_max / $mrowpp)); $searchword = empty($searchword) ? '' : trim($searchword); $searchword = empty($searchword) ? '' : cutstr(trim($searchword),50,''); $searchmode = empty($searchmode) ? 'subject' : trim($searchmode); $caid = empty($caid) ? 0 : $caid; $indays = empty($indays) ? '' : max(0,intval($indays)); $outdays = empty($outdays) ? '' : max(0,intval($outdays)); $orderby = empty($orderby) ? 'createdate' : $orderby; $ordermode = empty($ordermode) ? 0 : $ordermode; foreach($cotypes as $coid => $cotype){ if(!$chid || !$cotype['chids'] || !in_array($chid,explode(',',$cotype['chids']))){ ${"ccid$coid"} = !empty(${"ccid$coid"}) ? ${"ccid$coid"} : 0; } } $searchmodearr = array('subject' => lang('title'),'keywords' => lang('keyword'),'mname' => lang('member'),); $caidsarr = array('0' => lang('all catalog')) + caidsarr(); $orderbyarr = array( 'createdate' => lang('add time'), 'clicks' => lang('clicks'), 'comments' => lang('comments'), ); m_guide(17); tabheader(($chid ? $channels[$chid]['cname'] : lang('all archive')).' '.lang('search setting')." <input class=\"checkbox\" type=\"checkbox\" name=\"viewdetail\" value=\"1\" onclick=\"alterview('tbodyfilter')\"".($viewdetail ? ' checked' : '').">".lang('viewdetail'),'search',"adminm.php?action=search&chid=$chid"); trbasic(lang('search mode1'),'searchmode',makeoption($searchmodearr,$searchmode),'select'); trbasic(lang('search keyword'),'searchword',$searchword); trbasic(lang('belong catalog'),'caid',makeoption($caidsarr,$caid),'select'); $omodestr = " <input class=\"checkbox\" type=\"checkbox\" name=\"ordermode\" value=\"1\"".(empty($ordermode) ? '' : ' checked').">".lang('asc'); trbasic(lang('order type').$omodestr,'orderby',makeoption($orderbyarr,$orderby),'select'); echo "<tbody id=\"tbodyfilter\" style=\"display:".($viewdetail ? '' : 'none').";\">"; foreach($cotypes as $coid => $cotype){ if(!$chid || !$cotype['chids'] || !in_array($chid,explode(',',$cotype['chids']))){ $ccidsarr = array('0' => lang('nolimit')); $ccidsarr = $ccidsarr + ccidsarr($coid); trbasic("$cotype[cname]","ccid$coid",makeoption($ccidsarr,${"ccid$coid"}),'select'); } } if($chid){ $a_field = new cls_field; $fields = read_cache('fields',$chid); foreach($fields as $k => $field){ if($field['available'] && $field['issearch']){ $a_field->init(); $a_field->field = read_cache('field',$chid,$k); $a_field->trsearch(); } } unset($a_field); } trbasic(lang('indays'),'indays',$indays); trbasic(lang('outdays'),'outdays',$outdays); echo "</tbody>"; tabfooter('search',lang('search')); $filterstr = ''; if($viewdetail) $filterstr .= ($filterstr ? '&' : '')."viewdetail=$viewdetail"; $wherestr = ''; $fromstr = "FROM {$tblprefix}archives AS a"; if($searchword){ $filterstr .= ($filterstr ? '&' : '')."searchword=".rawurlencode(stripslashes($searchword)); $searchmode != 'subject' && $filterstr .= ($filterstr ? '&' : '')."searchmode=$searchmode"; $searchword = str_replace(array(' ','*'),'%',addcslashes($searchword, '%_')); $wherestr .= ($wherestr ? ' AND ' : '')."a.$searchmode LIKE '%$searchword%'"; } if($caid){ $filterstr .= ($filterstr ? '&' : '')."caid=$caid"; $caids = array($caid); $tempids = array(); $tempids = son_ids($catalogs,$caid,$tempids); $caids = array_merge($caids,$tempids); $wherestr .= ($wherestr ? ' AND ' : '')."a.caid IN (".mimplode($caids).")"; } foreach($cotypes as $coid => $cotype){ if(!$chid || !$cotype['chids'] || !in_array($chid,explode(',',$cotype['chids']))){ if(${"ccid$coid"}){ $filterstr .= ($filterstr ? '&' : '')."ccid$coid=".${"ccid$coid"}; $ccids = array(${"ccid$coid"}); $tempids = array(); $coclasses = read_cache('coclasses',$coid); $tempids = son_ids($coclasses,${"ccid$coid"},$tempids); $ccids = array_merge($ccids,$tempids); if(empty($cotype['self_reg'])){ $wherestr .= ($wherestr ? ' AND ' : '')."a.cotype$coid IN (".mimplode($ccids).")"; }else{ $tempstr = self_sqlstr($coid,$ccids,'a.'); $tempstr && $wherestr .= (!$wherestr ? '' : ' AND ').$tempstr; unset($tempstr); } } } } if($chid){ $customtable = "archives_$chid"; $fromstr .= " LEFT JOIN {$tblprefix}$customtable AS c ON a.aid=c.aid"; $wherestr .= ($wherestr ? ' AND ' : '')."a.chid='$chid'"; $a_field = new cls_field; $fields = read_cache('fields',$chid); foreach($fields as $k => $field){ if($field['available'] && $field['issearch']){ $a_field->init(); $a_field->field = read_cache('field',$chid,$k); $a_field->deal_search(); $wherestr .= ($wherestr && $a_field->searchstr ? ' AND ' : '').$a_field->searchstr; $a_field->filterstr && $filterstr .= ($filterstr ? '&' : '').$a_field->filterstr; } } unset($a_field); } if(!empty($indays)){ $filterstr .= ($filterstr ? '&' : '')."indays=$indays"; $wherestr .= ($wherestr ? ' AND ' : '')."a.createdate>'".($timestamp - 86400 * $indays)."'"; } if(!empty($outdays)){ $filterstr .= ($filterstr ? '&' : '')."outdays=$outdays"; $wherestr .= ($wherestr ? ' AND ' : '')."a.createdate<'".($timestamp - 86400 * $outdays)."'"; } $wherestr = "WHERE a.checked='1'".($wherestr ? ' AND ' : '').$wherestr; $orderstr = "ORDER BY a.$orderby ".($ordermode ? 'ASC' : 'DESC'); $orderby != 'createdate' && $filterstr .= ($filterstr ? '&' : '')."orderby=$orderby"; $ordermode && $filterstr .= ($filterstr ? '&' : '')."ordermode=$ordermode"; if(submitcheck('search')){ if($search_repeat){ empty($m_cookie['cms_search_time']) ? msetcookie('cms_search_time','1',$search_repeat) : mcmessage(lang('search overquick')); } $pagetmp = $page; do{ $query = $db->query("SELECT a.* $fromstr $wherestr $orderstr LIMIT ".(($pagetmp - 1) * $mrowpp).",$mrowpp"); $pagetmp--; }while(!$db->num_rows($query) && $pagetmp); $itemarchive = ''; $no = $pagetmp * $mrowpp; while($archive = $db->fetch_array($query)){ $no ++; $archive['arcurl'] = view_arcurl($archive); $archive['subject'] = "<a href=\"$archive[arcurl]\" target=\"_blank\">".mhtmlspecialchars($archive['subject'])."</a>"; $archive['catalog'] = $catalogs[$archive['caid']]['title']; $archive['createdate'] = date("$dateformat $timeformat", $archive['createdate']); $itemarchive .= "<tr><td align=\"center\" class=\"item1\" width=\"40\">$no</td>\n". "<td class=\"item2\">$archive[subject]</td>\n". "<td align=\"center\" class=\"item1\">$archive[catalog]</td>\n". "<td align=\"center\" class=\"item2\">$archive[mname]</td>\n". "<td align=\"center\" class=\"item1\" width=\"120\">$archive[createdate]</td></tr>\n"; } $archivecount = $db->result_one("SELECT count(*) $fromstr $wherestr"); $search_max && $archivecount = min($archivecount,$search_max); $multi = multi($archivecount,$mrowpp,$page,"adminm.php?action=search&chid=$chid&$filterstr&search=1"); tabheader(lang('search result list'),'','',9); trcategory(array(lang('sn'),lang('title'),lang('catalog'),lang('member'),lang('add time'))); echo $itemarchive; tabfooter(); echo $multi; } ?>