<?
//defined('ROOT_PHPLEFT') or exit('phpleft: Not page');
/*
	phpleftDms Copyright (c) 2011 phpleft.COM
	ÉÌÒµÊÚÈ¨£ºQQ45150208
	
*/
class admin {

function module_install($m){
	global $PL_CFG,$db,$query;
    $query=$db->query("Select * from ".$PL_CFG['tb_pre']."module where module ='$m'");
    while($rs=$db->fetch_array($query)){
    $rss= $rs['moduleinstall'];
	   }
	return $rss;
}

function plugins_install($m){
	global $PL_CFG,$db,$query;
    $query=$db->query("Select * from ".$PL_CFG['tb_pre']."plugins where plugins ='$m'");
    while($rs=$db->fetch_array($query)){
    $rss = $rs['plugins_install'];
	   }
	return $rss;
}
	
function login($username,$userpwd){
global $PL_CFG,$db,$query;
$pwd=md5($userpwd.md5(DMS));
$query=$db->query("Select * from ".$PL_CFG['tb_pre']."admin where username ='$username' and  userpwd ='$pwd'");
while($rs=$db->fetch_array($query)){
$rss= $rs;
	   }
return $rss;	  
}

function update_setting($item, $setting) {
	global $db,$PL_CFG;
	$db->query("DELETE FROM ".$PL_CFG['tb_pre']."setting WHERE item='$item'");
	foreach($setting as $k=>$v) {
		if(is_array($v)) $v = implode(',', $v);
		$db->query("INSERT INTO ".$PL_CFG['tb_pre']."setting (item,item_name,item_value) VALUES ('$item','$k','$v')");
	}
	return true;
}	

function update_cat($setting) {	 
	 global $db,$PL_CFG;
$name = explode("\n", trim($setting['name']));
foreach($name as $i=>$n) {
foreach($setting as $k=>$v) {
	if($k<>"name"){
	$t[$i].=  $k.',';
	$ts[$i].= "'".$v."',";
	}
}
$t[$i].= "name";
$ts[$i].= "'".$n."'";
$db->query("INSERT INTO ".$PL_CFG['tb_pre']."sort (".$t[$i].") VALUES (".$ts[$i].")");
$getID=mysql_insert_id();//
$sets = cache_read("set-".$setting[module].".php",PL_ROOT.$PL_CFG['cache']."/");
$sets['htm_list_urlid'] = $sets['htm_list_urlid'] ? $sets['htm_list_urlid'] : 0;
$linkurl = url($getID,$sets['htm_list_urlid'],'list');
$db->query("update 	".$PL_CFG['tb_pre']."sort set linkurl = '".$linkurl ."',noparent ='$getID'  where id='$getID'");
if ($setting['parent']<>'0') $ids = allparent($setting['parent'],$setting[module],'noparent').$getID;
if ($setting['parent']<>'0') $db->query("update 	".$PL_CFG['tb_pre']."sort set noparent='$ids',child='1' where id='$setting[parent]'");
}
return true;
}

function update_cat_bj($setting,$id) {	 
	 global $db,$PL_CFG;

foreach($setting as $k=>$v) {
	if($k=='is_or'){
	$t.=  $k." = '".$v."'";

	}else{
	$t.=  $k." = '".$v."',";

	}
}
$db->query("update ".$PL_CFG['tb_pre']."sort set ".$t." where id=".$id);
$getID=$id;//
$sets = cache_read("set-".$setting[module].".php",PL_ROOT.$PL_CFG['cache']."/");
$sets['htm_list_urlid'] = $sets['htm_list_urlid'] ? $sets['htm_list_urlid'] : 0;
$linkurl = url($getID,$sets['htm_list_urlid'],'list');
$db->query("update 	".$PL_CFG['tb_pre']."sort set linkurl = '".$linkurl ."',noparent ='$getID'  where id='$getID'");
if ($setting['parent']<>'0') $ids = allparent($setting['parent'],$setting[module],'noparent').$getID;
if ($setting['parent']<>'0') $db->query("update 	".$PL_CFG['tb_pre']."sort set noparent='$ids',child='1' where id='$setting[parent]'");

return true;
}
	
}
?>