<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */

/**
 * Smarty {textformat}{/textformat} block plugin
 *
 * Type:     block function<br>
 * Name:     textformat<br>
 * Purpose:  format text a certain way with preset styles
 *           or custom wrap/indent settings<br>
 * @link http://smarty.php.net/manual/en/language.function.textformat.php {textformat}
 *       (Smarty online manual)
 * @param array
 * <pre>
 * Params:   style: string (email)
 *           indent: integer (0)
 *           wrap: integer (80)
 *           wrap_char string ("\n")
 *           indent_char: string (" ")
 *           wrap_boundary: boolean (true)
 * </pre>
 * @author Monte Ohrt <monte at ohrt dot com>
 * @param string contents of the block
 * @param Smarty clever simulation of a method
 * @return string string $content re-formatted
 */
function smarty_block_alist($params, $content, &$smarty)
{
    if (is_null($content)) {
        return;
    }
 extract($params); 
 $order = isset($params['inorder']) ? $params['inorder'] : 'lm_id';
 $PageSize = isset($params['insize']) ? $params['insize'] : 10;
 $toid = isset($params['inid']) ? intval($params['inid']) : 0;
 $lm_nmid = isset($_GET['lm_nmid']) ? $_GET['lm_nmid'] :''; 
 $pid = isset($_GET['lm_rjnmid']) ? $_GET['lm_rjnmid'] : $toid; //获取栏目ID号
 $pstring = "&lm_nmid=".$lm_nmid."&lm_rjnmid=".$pid;
if(!is_numeric($pid)){
return '传入的参数错误,请检查传入的变量';
exit();
	}else{
$pid = intval($pid);
}
$nmsql = "select * from limao_nm where lm_id=$pid limit 1";
$nmrs = mysql_query($nmsql) or die('传入参数错误'.mysql_error());
$nmdata = mysql_fetch_object($nmrs);
if(!$nmdata){
return '传入参数错误';
exit();
	}
$nmtype = $nmdata->lm_error;
switch($nmtype){
	case 1:
	$nmtable = 'limao_article';
  $psql = "select * from $nmtable where lm_type=$pid order by $order desc";
  $lm_nmid = $nmdata->lm_nmid;
  $outtable = 'show_article.php';
	break;
  case 2:
  $nmtable = 'limao_shop';
  $psql = "select * from $nmtable where lm_type=$pid order by $order desc";
  $lm_nmid = $nmdata->lm_nmid;
  $outtable = 'show_shop.php';
break;
	}
/*获取当前页，总页数，总记录数*/	
$result = mysql_query($psql);
if(!$result){
return '没有找到符合条件的数据';
}
$amount = mysql_num_rows($result);
$pagecount = ceil($amount / $PageSize);	
$page = (isset($_GET['page']) ? $_GET['page'] : 1);
if(is_numeric($page)){                              	
$page = intval($page);
if($page>=$pagecount){
$page = $pagecount;
        }
 if($page<=0){
$page = 1;
 }
}else{
 $page = 1;
    }
/*返回当前页数据*/
      $limitStr = ' LIMIT '.(($page - 1)* $PageSize).','.$PageSize;
// return $psql.$limitStr;
          $listmrs = mysql_query($psql.$limitStr);
          if($listmrs){         	
  $listcols = mysql_num_fields($listmrs)-1;
	$liststr = '';
	while($listrows=mysql_fetch_array($listmrs)){
			$listtmp = $content;
	 for($m=0;$m<=$listcols;$m++){
	$fieldname = mysql_field_name($listmrs,$m);
	$listtmp = str_replace("[\$field.".$fieldname."]",rinput($listrows[$m]),$listtmp);
	$listtmp = str_replace("[\$field.tourl]",$outtable."?id=".rinput($listrows[0])."&lm_nmid=".rinput($lm_nmid),$listtmp);
	$listtmp = str_replace("[\$field.toimg]",rinput(webupimgurl).rinput($listrows['lm_img']),$listtmp);				
}
 $liststr .= $listtmp;
}
 return $liststr;
        }else{
  return '没有符合条件的数据啊！！';
       	}


  
 }




?>
