phpcmsv9内容模型筛选功能
在phpcmslibsfunctionsextention.func.php添加函数
//显示结合项筛选选项
function ShowFieldandChange($catid = '',$notxt='不限',$getarr=array()){
//------- 函数参数设置开始 -----
$where = '';
if(!$catid) $catid = $_GET['catid'];
$category = getcache('category_content_1','commons');
$modelid_cache = getcache('model_field_'.$category[$catid]['modelid'],'model');
if($category[$catid]['child']) {
$catids_str = $category[$catid]['arrchildid'];
$pos = strpos($catids_str,',')+1;
$catids_str = substr($catids_str, $pos);
$where = "status=99 AND catid IN ($catids_str)";
} else {
$where = "status=99 AND catid='$catid'";
}
foreach($modelid_cache as $key=>$r){
$r['setting'] = string2array($r['setting']);
if(($r['formtype']=='box'||$r['formtype']=='linkage')&&$r['setting']['filtertype']=="1"){
$field[$key]['name'] = $r['name'];
$getvalue = isset($_GET[$key])&&trim($_GET[$key]) ? (int)$_GET[$key] : NULL;
$field[$key]['value'][] = array($notxt,NULL,screenget(array($key,NULL),$getarr),FALSE);
if($r['formtype']=='box'){
$options = explode("\n",$r['options']);
foreach($options as $_k) {
$optionsarr = explode("|",$_k);
$linkurl = screenget(array($key,$optionsarr[1]),$getarr);
if($getvalue!==NULL&&$getvalue==$optionsarr[1]){
$field[$key]['value'][] = array_merge($optionsarr,array($linkurl,TRUE));
}
else{
$field[$key]['value'][] = array_merge($optionsarr,array($linkurl,FALSE));
}
}
if($getvalue!==NULL){
switch($r['boxtype']) {
case 'radio':
$where .= " AND `$key`='$getvalue'";
break;
case 'checkbox':
$where .= " AND `$key` LIKE '%,$getvalue,%'";
break;
case 'select':
$where .= " AND `$key`='$getvalue'";
break;
case 'multiple':
$where .= " AND `$key` LIKE '%,$getvalue,%'";
break;
}
}
}
elseif($r['formtype']=='linkage'){
if($r['setting']['linkageid']!=1){
$linkagearr = getcache($r['setting']['linkageid'],'linkage');
}
else{
if(!defined('LINKAGEDIQU_1')) {
define('LINKAGEDIQU_1', 1);
$diqu = getcache('1','linkage');
}
$linkagearr = $diqu;
}
$linkagearr = $linkagearr['data'];
foreach($linkagearr as $l){
if(!$l['parentid']){
$optionsarr = array($l['name'],$l['linkageid']);
$linkurl = screenget(array($key,$optionsarr[1]),$getarr);
$linktag = FALSE;
$flinkid = $optionsarr[1];
while($flinkid){
if($getvalue==$flinkid){
$linktag = TRUE;
break;
}
$flinkid = $linkagearr[$flinkid]['parentid'];
}
if($getvalue!==NULL&&$linktag){
$field[$key]['value'][] = array_merge($optionsarr,array($linkurl,TRUE));
}
else{
$field[$key]['value'][] = array_merge($optionsarr,array($linkurl,FALSE));
}
}
}
if($getvalue!==NULL&&$linkagearr[$getvalue]){
if($linkagearr[$getvalue]['child']){
$where .= " AND `$key` IN (".$linkagearr[$getvalue]['arrchildid'].")";
}
else{
$where .= " AND `$key` = '$getvalue'";
}
}
}
}
}
return array('field'=>$field,'sql'=>$where);
}
function screenget($data,$getarr=array()){
$urlarr = $_GET ? $_GET : $getarr;
if($data[1]===NULL){
if(isset($urlarr[$data[0]])){
unset($urlarr[$data[0]]);
}
}
else{
$urlarr[$data[0]] = $data[1];
}
foreach($urlarr as $key=>$r){
$url .= $url ? "&$key=$r" : "$key=$r";
}
return $url;
}
调用代码
{php $screenarr = ShowFieldandChange('list',$catid);}
{loop $screenarr[field] $key $r}
<b>{$r['name']}:</b>
{loop $r[value] $_r}
<a href="{APP_PATH}index.php?{$_r[2]}" {if $_r[3]}style="color:#F00"{/if}>{$_r[0]}</a>
{/loop}
<br />
{/loop}
{$screenarr[sql]}