<?php 
/*******************************************************************************
* Ourphp - CMS建站系统
* Copyright (C) 2014 ourphp.net
* 开发者：哈尔滨伟成科技有限公司
*******************************************************************************/
include 'ourphp_admin.php';
include 'ourphp_checkadmin.php';

if(isset($_GET["ourphp_cms"]) == ""){
	echo '';
}elseif ($_GET["ourphp_cms"] == "add"){

	$model = $db -> select("id","ourphp_model","where `OP_Modelclass` = '".dowith_sql($_POST["OP_Modelclass"])."' && `OP_Modelfield` = '".dowith_sql($_POST["OP_Modelfield"])."'");
	if($model)
	{
		$ourphp_font = 4;
		$ourphp_content = '模型字段已存在，请换一个！';
		$ourphp_class = 'ourphp_model.php?id=ourphps';
		require 'ourphp_remind.php';
		exit;		
	}

	plugsclass::logs('创建模型',$OP_Adminname);
	$db -> insert("`ourphp_model`","`OP_Modelclass` = '".dowith_sql($_POST["OP_Modelclass"])."',`OP_Modelname` = '".dowith_sql($_POST["OP_Modelname"])."',`OP_Modelfield` = '".strtolower(dowith_sql($_POST["OP_Modelfield"]))."',`OP_Modeltype` = '".str_replace("<span>char</span>","char",dowith_sql($_POST["OP_Modeltype"]))."',`time` = '".date("Y-m-d H:i:s")."'","");
	$ourphp_font = 1;
	$ourphp_class = 'ourphp_model.php?id=ourphps';
	require 'ourphp_remind.php';
			
}elseif ($_GET["ourphp_cms"] == "del"){

	if (strstr($OP_Adminpower,"35")){

		plugsclass::logs('删除模型',$OP_Adminname);
		$db -> del("ourphp_model","where id = ".intval($_GET['id']));
		$ourphp_font = 2;
		$ourphp_class = 'ourphp_model.php?id=ourphps';
		require 'ourphp_remind.php';
	
	}else{
	
		$ourphp_font = 4;
		$ourphp_content = '权限不够，无法删除！';
		$ourphp_class = 'ourphp_model.php?id=ourphps';
		require 'ourphp_remind.php';
	
	}
			
}

function Modellist(){
	global $db;
	$query = $db -> listgo("*","`ourphp_model`","order by id asc");
	$rows=array();
	while($ourphp_rs = $db -> whilego($query)){
		$rows[]=array(
			"id" => $ourphp_rs['id'],
			"class" => $ourphp_rs['OP_Modelclass'],
			"name" => $ourphp_rs['OP_Modelname'],
			"field" => $ourphp_rs['OP_Modelfield'],
			"type" => $ourphp_rs['OP_Modeltype'],
			"time" => $ourphp_rs['time']
		);
	}
	return $rows;
}

Admin_click('模型管理','ourphp_model.php?id=ourphp');
$smarty->assign("Modellist",Modellist());
$smarty->display('ourphp_model.html');
?>