<?
defined('ROOT_PHPLEFT') or exit('phpleft: Not page');
/*
	phpleftDms Copyright (c) 2011 phpleft.COM
	商业授权：QQ45150208
	
*/
if ($post<>''){
switch($post) {
	case 'url':
	if ($style=='catid'){
	$page = $page?$page:0;
	$file = "catid_".$menuid.".php";
	$sets = cache_read("set-".$menuid.".php",PL_ROOT.$PL_CFG['cache']."/");
    $sets['htm_list_urlid'] = $sets['htm_list_urlid'] ? $sets['htm_list_urlid'] : 0;
	$list = sql_cache("table=sort&cache=id&where=module=".$menuid."&order=keylist asc,id asc");
	$nlist = count($list);
	$inpagen = floor($nlist/$input);
	if ($nlist == '0')  msg('没有数据需要更新', 'phpleft.php?file=data&menuid='.$menuid,0,1,1,'n');
	$dn = $page*$input;
	$i = 0;
	foreach($list as $k=>$v) {
	$i=$i+1;
	$menushow[$i] = $v[id];
	}
	$pages =$page+1;
	$dninput = $dn+$input;
     if ($page<$inpagen){

		for ($t=$dn;$t<$dninput;$t++){
		$id = $menushow[$t];
        $linkurl = url($id,$sets['htm_list_urlid'],'list');
        $db->query("update 	".$PL_CFG['tb_pre']."sort set linkurl = '".$linkurl ."'  where id='".$id."'");
		}

	msg('正在更新'.$dn.'-'.$dninput.'条', 'phpleft.php?file=data&post=url&style=catid&input='.$input.'&page='.$pages.'&menuid='.$menuid); 
		 
	 }else{
	for ($t=$dn;$t<$nlist+1;$t++){
		$id = $menushow[$t];
        $linkurl = url($id,$sets['htm_list_urlid'],'list');
        $db->query("update 	".$PL_CFG['tb_pre']."sort set linkurl = '".$linkurl ."'  where id='".$id."'");

	}
	$menut = sql_cache("table=sort&cache=id&where=module=".$menuid."&order=keylist asc,id asc");
    $pathcach = PL_ROOT.$PL_CFG['cache']."/";
    cache_write($file, $menut, $pathcach);
	msg($dn.'-'.$dninput.'更新成功！', 'phpleft.php?file=data&menuid='.$menuid); 
	}
	}else{
	$htm = $htm?$htm:'show';
	$page = $page?$page:0;
	$file = "catid_".$menuid.".php";
	$sets = cache_read("set-".$menuid.".php",PL_ROOT.$PL_CFG['cache']."/");
    $sets['htm_show_urlid'] = $sets['htm_show_urlid'] ? $sets['htm_show_urlid'] : 0;
	$list = sql_cache("moduleid=".$menuid);
	$nlist = count($list);
	$inpagen = floor($nlist/$input);
	if ($nlist == '0')  msg('没有数据需要更新', 'phpleft.php?file=data&menuid='.$menuid,0,1,1,'n');
	$dn = $page*$input;
	$i = 0;
	foreach($list as $k=>$v) {
	$i=$i+1;
	$menushow[$i] = $v[id];
	}
	$pages =$page+1;
	$dninput = $dn+$input;
     if ($page<$inpagen){

		for ($t=$dn;$t<$dninput;$t++){
		$id = $menushow[$t];
        $linkurl = url($id,$sets['htm_show_urlid'],$htm);
        $db->query("update 	".$PL_CFG['tb_pre'].modname($menuid)."_".$menuid." set linkurl = '".$linkurl ."'  where id='".$id."'");
		}

	msg('正在更新'.$dn.'-'.$dninput.'条', 'phpleft.php?file=data&htm='.$htm.'&post=url&style=html&input='.$input.'&page='.$pages.'&menuid='.$menuid); 
		 
	 }else{
	for ($t=$dn;$t<$nlist+1;$t++){
		$id = $menushow[$t];
        $linkurl = url($id,$sets['htm_show_urlid'],$htm);
        $db->query("update 	".$PL_CFG['tb_pre'].modname($menuid)."_".$menuid." set linkurl = '".$linkurl ."'  where id='".$id."'");
	}
	msg($dn.'-'.$nlist.'<br>更新成功！', 'phpleft.php?file=data&menuid='.$menuid); 
	}	

	}
	break;
	
}
}else{
include MTemplate(ThisFile,modname($menuid));
}
?>