File: //www/wwwroot/bs.kntsleep.com/system/admin/models/field.class.php
<?php
/*
* Copyright (c) Huyin Information Technology Co., Ltd. All Rights Reserved.
* BOSSCMS Content Management System (https://www.bosscms.net/)
*/
defined('IS_OK') or exit('Access Forbidden');
into::basic_class('admin');
class field extends admin
{
public function init()
{
global $G;
$G['cover'] = $this->cover('models','R');
if($parent = $G['get']['parent']){
$data = mysql::select_all('*','field',"parent='{$parent}'","sort DESC,id ASC");
echo $this->theme('models/field', $data);
}else{
alert('无提交信息');
}
}
public function modify()
{
global $G;
$this->cover('models','M');
if(isset($G['post']['id'])){
/* BOSS=CMS */
$error=array();
foreach($G['post']['id'] as $id){
if(isset($G['post']['sort'.$id])){
$data = array('sort'=>$G['post']['sort'.$id]);
}else if(isset($G['post']['display'.$id])){
$data = array('display'=>$G['post']['display'.$id]);
}
if(!is_numeric(mysql::update($data,"field","id='{$id}'"))){
$error[]=$id;
}
}
into::basic_json('option',true,false);
into::basic_json('pass',true,false);
if($error){
alert('ID为'.implode(',',$error).'修改失败');
}else{
alert('修改成功', url::mpf('models','field','init'));
}
}else{
alert('没有提交信息');
}
}
public function edit()
{
global $G;
$this->cover('models','R');
$G['style'] = array();
foreach($G['option']['style'] as $k=>$v){
if(!preg_match('/^(14|15|21|22|23|30|31)$/',$k)){
$G['style'][$k] = $v;
}
}
if(isset($G['get']['id'])){
$data = mysql::select_one('*','field',"id='{$G['get']['id']}'");
$attribute = json::decode($data['attribute']);
switch($data['style']){
case 0:
preg_match('/"width(\d+)"/',$data['attribute'],$mat);
$attribute['width'] = $mat[1]*10;
break;
case 1:
preg_match('/"width(\d+)"/',$data['attribute'],$mat);
$attribute['width'] = $mat[1]*10;
preg_match('/"height(\d+)"/',$data['attribute'],$mat);
$attribute['height'] = $mat[1];
break;
case 2:
$attribute['width'] = str_replace('%','',$attribute['width']);
$attribute['euheight'] = $attribute['height'];
break;
case 10:
case 11:
$attribute['width'] = str_replace('%','',$attribute['width']);
break;
case 12:
$attribute['hexcolor'] = in_array('hexcolor',$attribute)?1:0;
break;
case 5:
case 20:
$attribute['width'] = str_replace('%','',$attribute['width']);
$attribute['multiple'] = in_array('multiple',$attribute)?1:0;
break;
case 32:
$attribute['width'] = str_replace('%','',$attribute['width']);
break;
}
$data['attribute'] = $attribute;
}
echo $this->theme('models/ctrl', $data);
}
public function add()
{
global $G;
$id = $G['get']['id'];
$this->cover('models',$id?'M':'A');
if(isset($G['post']) && $mds=mysql::select_one('*','models',"id='{$G['get']['parent']}'")){
$data = array(
'parent' => $mds['id'],
'style' => $G['post']['style'],
'title' => $G['post']['title'],
'description' => $G['post']['description'],
'param' => $G['post']['param'],
'value' => $G['post']['value'],
'type' => $G['post']['type'],
'sort' => $G['post']['sort'],
'display' => $G['post']['display']
);
$patt = $G['post']['attribute'];
$attribute = array();
switch($data['style']){
case 0:
$attribute[] = 'width'.(is_numeric($patt['width'])?floor($patt['width']/10):9);
$attribute['type'] = $patt['type'];
break;
case 1:
$attribute[] = 'width'.(is_numeric($patt['width'])?floor($patt['width']/10):9);
$attribute[] = 'height'.$patt['height'];
break;
case 2:
$attribute['width'] = $patt['width'].'%';
$attribute['height'] = $patt['euheight'];
break;
case 10:
case 11:
$attribute['width'] = $patt['width'].'%';
break;
case 12:
if($patt['hexcolor']){
$attribute[] = 'hexcolor';
}
break;
case 5:
case 20:
$attribute['width'] = $patt['width'].'%';
if($patt['multiple']){
$attribute[] = 'multiple';
}
break;
case 32:
$attribute['width'] = $patt['width'].'%';
$attribute['tight'] = $patt['tight'];
break;
}
$data['attribute'] = json::enfilter($attribute);
if($id){
if($result = mysql::select_one('id','field',"id='{$id}'")){
mysql::update($data,"field","id='{$id}'");
}
}else{
$data['name'] = $G['post']['name'];
if(!preg_match('/^[a-zA-Z]\w*$/',$data['name'])){
alert('字段名只能使用英文或英文加数字');
}else if(preg_match('/^(tc)$/',$data['name']) || $G['database']['model_'.$mds['sign']][$data['name']] || $G['database']['model_'.$mds['sign'].'_content'][$data['name']]){
alert('字段名已存在或不可用');
}
$id = mysql::insert($data,"field");
}
into::basic_json('database',true,false);
into::load_class('admin','update','update','new')->database(
array(
'model_'.$mds['sign']=>$G['database']['model_'.$mds['sign']],
'model_'.$mds['sign'].'_content'=>$G['database']['model_'.$mds['sign'].'_content']
)
);
alert('操作成功', url::mpf('models','field','edit',array('id'=>$id,'success'=>'ok')));
}else{
alert('没有提交信息!');
}
}
public function delete()
{
global $G;
$this->cover('models','D');
if(isset($G['post']['url']) && isset($G['get']['id']) && $mds=mysql::select_one('*','models',"id='{$G['get']['parent']}'")){
$del = array();
$arr = explode(',',$G['get']['id']);
foreach($arr as $id){
if(is_numeric($id)){
$del[$id] = $id;
}
}
if($del){
$error=array();
foreach($del as $id=>$name){
if(is_numeric(mysql::delete("field","id='{$id}' AND parent='{$mds['id']}'"))){
}else{
$error[]=$id;
}
}
if($error){
alert('ID为'.implode(',',$error).'删除失败');
}else{
into::basic_json('database',true,false);
into::load_class('admin','update','update','new')->database(array('model_'.$mds['sign'].'_content'=>$G['database']['model_'.$mds['sign'].'_content']));
alert('删除成功',url::mpf('models','field','init',array('id'=>null)));
}
}else{
alert('没有删除对象id!');
}
}
alert('没有提交信息!');
}
}
?>