<?php
if(!defined('R_P')) exit('Access Denied');
$limit  = 20;
$maxpage = 30;
$maxtotal = $maxpage * $limit;
$pageno = min($maxpage, intval($_GET['pageno']) > 0 ? intval($_GET['pageno']) : 1);
$offset = ($pageno - 1) * $limit;
$type = trim($_GET['type']);
$name = urldecode(trim($_GET['name']));
$_GET['name'] = $name;
$data = array(
	'total'=>0,
	'data'=>array()
);

if($type == 'actor'){
	$ids = array();
	$temp = qdb::fetchAll("select id from ".TABLEPRE."movie_actor_mapping where name = '{$name}' and channelid = '{$channelid}' ");
	foreach($temp as $val){
		$ids[] = $val['id'];
	}
	$data['total'] = min($maxtotal, count($ids));
	$ids = array_slice($ids, $offset, $limit);

	if(!empty($ids)){
		$ids_string = implode(",", $ids);
		$tmp = cmsQuery("channelid={$channelid}&ids={$ids_string}");
		$data['data'] = &$tmp['data'];
	}
	$data['pager'] = qbase::page($data['total'] , $pageno, $limit, 1);
	$search_title = "ËÑË÷ÑÝÔ±£º" . $name;
}else if($type == 'area'){
	$data['total'] = qdb::queryAlone("select count(*) as num from ". TABLEPRE ."movie_4 where play_area = '{$name}' ");
	$data['total'] = min($maxtotal, $data['total']);
	if($data['total'] > 0){
		$data['data'] = qdb::fetchAll("select * from ". TABLEPRE ."movie_4 where play_area = '{$name}' order by id desc limit {$offset},{$limit}");
		foreach($data['data'] as $key=>&$val){
			if(false === ($val = cmsFormatItem($val))){
				unset($data['data'][$key]);
			}
		}
		unset($val);
	}else{
		$data['data'] = array();
	}
	$data['pager'] = qbase::page($data['total'] , $pageno, $limit, 1);
	$search_title = "ËÑË÷µØÇø£º" . $name;
}else{
	$where = " where subject like '%{$name}%' or play_leader like '%{$name}%' or  play_actor like '%{$name}%' ";
	$data['total'] = qdb::queryAlone("select count(*) as num from ".TABLEPRE."movie_{$channelid} {$where} ");
	$data['total'] = min($maxtotal, $data['total']);
	if($data['total'] > 0){
		$data['data'] = qdb::fetchAll("select * from ".TABLEPRE."movie_{$channelid} {$where} order by id desc limit {$offset},{$limit} ");
		foreach($data['data'] as $key=>&$val){
			if(false === ($val = cmsFormatItem($val))){
				unset($data['data'][$key]);
			}
		}
		unset($val);
	}else{
		$data['data'] = array();
	}
	$data['pager'] = qbase::page($data['total'] , $pageno, $limit, 1);
	$search_title = "ËÑË÷¹Ø¼ü´Ê£º" . $name;
}

include qbase::template($skin . "/movie/search");
?>