//Admin_information.php
<?php
class Admin_information extends RZ_Controller
{
var $data;
function Admin_information ()
{
parent::Controller();
$this->layout->setLayout( 'admin' );
$this->data = array();
$this->data['page_title'] = '资讯管理';
}
function jsondata ( $type = 'company' )
{
list( $conditions, $pagination, $order, $data ) = $this->_admin_json_data();
$conditions['disabled'] = 'false';
$this->load->model( 'Information' );
$data['total'] = $this->Information->get_total( $conditions );
if ( empty( $data['total'] ) ) {
$data['total'] = 0;
echo json_encode( $data );
exit;
}
$list = $this->Information->find( array(
'fields' => array( '*' ),
'conditions' => array( 'disabled' => 'false', 'type' => $type )
));
$i = 0;
foreach ( $list as $v )
{
$data['rows'][$i] = $v;
$data['rows'][$i]['publish_date'] = date( 'Y-m-d H:i:s', $v['publish_time'] );
$data['rows'][$i]['create_date'] = date( 'Y-m-d H:i:s', $v['createtime'] );
$i++;
}
echo json_encode( $data );
exit;
}
function index ()
{
$this->company();
}
function company ()
{
$this->data['type'] = 'company';
$this->layout->view( 'admin/information/list', $this->data );
}
function activities ()
{
$this->data['type'] = 'activities';
$this->layout->view( 'admin/information/list', $this->data );
}
function new_product ()
{
$this->data['type'] = 'new_product';
$this->layout->view( 'admin/information/list', $this->data );
}
function add ( $type = '' )
{
if ( !empty( $_POST['data'] ) ) {
//echo '<pre>';print_r($_POST['data']);echo '</pre>';exit;
$this->load->model( 'Information' );
$this->Infomation->user_id = $this->user_id;
$data = $_POST['data'];
if ( array_key_exists( 'publish', $data ) )
{
$data['publish'] = 'true';
$data['publish_time'] = time();
}
else
{
$data['publish'] = 'false';
}
if ( $this->Information->add( $data ) )
{
$this->_msg( INFORMATION_ADD_SUCCESS, true );
} else {
$this->_msg( '' );
}
}
if ( 'company' != $type and 'activities' != $type and 'new_product' != $type )
{
exit;
}
$this->data['type'] = $type;
$this->load->view( 'admin/information/add', $this->data );
}
function edit ( $id = 0 )
{
$id = intval( $id );
if ( !empty( $_POST['data'] ) ) {
$this->load->model( 'Information' );
$this->Information->user_id = $this->user_id;
$this->Information->id = $id;
$data = $_POST['data'];
if ( array_key_exists( 'publish', $data ) )
{
$data['publish'] = 'true';
$data['publish_time'] = time();
}
else
{
$data['publish'] = 'false';
}
if ( $this->Information->update( $data ) )
{
$this->_msg( INFORMATION_UPDATE_SUCCESS, true );
}
else
{
$this->_msg( INFORMATION_UPDATE_ERROR );
}
}
$data = $this->_view( $id );
$this->load->view( 'admin/information/edit', $data );
}
function del ( $id = 0 )
{
$id = intval( $id );
$this->load->model( 'Information' );
$this->Information->user_id = $this->user_id;
$this->Information->id = $id;
$data = array( 'disabled' => 'true' );
if ( $this->Information->update( $data ) )
{
$this->_msg( INFORMATION_DEL_SUCCESS, true );
}
else
{
$this->_msg( INFORMATION_DEL_ERROR );
}
}
function id ( $id = 0 )
{
$id = intval( $id );
$data = $this->_view( $id );
$this->layout->view( 'admin/information/view', $data );
}
function _view ( $id )
{
$this->load->model( 'Information' );
$this->Information->user_id = $this->user_id;
$this->Information->id = intval( $id );
$data = array();
$data['information'] = $this->Information->get_one( array(
'fields' => array( '*' ),
'conditions' => array( 'id' => $this->Information->id, 'created_by' => $this->Information->user_id )
));
return $data;
}
}
//models/information.php
<?php
class Information extends RZ_Model
{
var $table = 'dfbc_informations';
function Information ()
{
parent::Model();
}
}
//Upload.php
<?php
class Upload extends RZ_Controller {
function Upload () {
parent::Controller();
$this->load->helper( array( 'form', 'url' ) );
$this->_is_admin();
}
function index () {
$this->load->view('upload/image_form', array('error' => ' ' ));
}
function do_upload () {
$user_id = $this->user_id;
$ret = array( 'status'=>0, 'msg'=>'' );
if ( empty( $user_id ) ) {
$ret['msg'] = 'Please Login before upload!';
echo json_encode( $ret );
exit();
}
//$upload_path = $_SERVER['DOCUMENT_ROOT'].'uploads/';
$upload_path = 'userfiles/';
if ( !is_dir( $upload_path ) ) {
mkdir( $upload_path );
}
$upload_path .= $user_id.'/';
if ( !is_dir( $upload_path ) ) {
mkdir( $upload_path );
}
$upload_path .= 'image/';
if ( !is_dir( $upload_path ) ) {
mkdir( $upload_path );
}
if ( !is_dir( $upload_path.'/thumb' ) ) {
mkdir( $upload_path.'/thumb' );
}
$ret = array( 'status' => 0, 'msg' => '' );
$this->_check_image();
$images = $this->_move_image( $upload_path );
$ret['status'] = 1;
$ret['img'] = array();
$i = 0;
$this->load->library( 'image_lib' );
foreach ( $images as $image )
{
chmod( $image['source_image'], 0644 );
$config['image_library'] = 'gd2';
$config['source_image'] = $image['source_image'];
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 200;
$config['height'] = 100;
$this->image_lib->initialize($config);
$this->image_lib->resize();
$thumb = $upload_path.'/'.$image['raw_name'].'_thumb.'.$image['file_ext'];
$logo = $upload_path.'/thumb/'.$image['file_name'];
if ( !file_exists( $logo ) ) {
rename( $thumb, $logo );
} else {
unlink( $thumb );
}
$ret['img'] = $logo;
}
echo json_encode( $ret );
exit();
}
function _check_image () {
$file_maxsize = 3 * 1024 * 1024;//3M
$file_ext = array( 'jpg', 'jpeg', 'bmp', 'gif', 'png' );
foreach ( $_FILES as $file ) {
if ( $file['size'] > $file_maxsize ) {
$this->_msg( $file['name'].' '.IMAGE_SIZE_EXCEED );
}
$type = strtolower( $file['type'] );
$arr = explode( '/', $type );
if ( count( $arr ) < 2 or 'image' != $arr[0] or !in_array( $arr[1], $file_ext ) ) {
$this->_msg( IMAGE_TYPE_ERROR );
}
}
}
//suppliers/userfiles/1/albums
function _move_image ( $dir ) {
$images = array();
$counter = 0;
foreach ( $_FILES as $file ) {
if ( 0 == $file['error'] ) {
$ext = explode( '.', $file['name'] );
$len = count( $ext );
if ( $len < 2 ) {
continue;
}
if ( preg_match( "/[".chr(0xa1)."-".chr(0xff)."]+/", $file['name'] ) ) {
$name = time().$counter.'.'.$ext[$len-1];
} else {
$name = str_replace( ' ', '_', $file['name'] );
}
$ext = explode( '.', $name );
$len = count( $ext );
if ( $len < 2 ) {
continue;
}
if ( move_uploaded_file( $file['tmp_name'], $dir.'/'.$name ) ) {
$images[$counter]['file_name'] = $name;
$images[$counter]['file_ext'] = $ext[$len-1];
$images[$counter]['source_image'] = $dir.'/'.$name;
unset( $ext[$len-1] );
$images[$counter]['raw_name'] = implode( '.', $ext );
}
$counter++;
}
}
return $images;
}
}
//views/admin/information/list.php
<div style="margin-top:20px;margin-bottom:10px;"></div>
<div id="tabs">
<ul>
<li>
<a href="#tabs-1">
公司活动
<input type="hidden" value="company">
</a>
</li>
<li>
<a href="#tabs-2">
市场活动
<input type="hidden" value="activities">
</a>
</li>
<li>
<a href="#tabs-3">
新品上市
<input type="hidden" value="new_product">
</a>
</li>
</ul>
<div id="tabs-1">
<div>
<a href="javascript:void(0)" οnclick="add_information('company')">添加</a>
</div>
<div id="list_1"></div>
</div>
<div id="tabs-2">
<div>
<a href="javascript:void(0)" οnclick="add_information('activities')">添加</a>
</div>
<div id="list_2"></div>
</div>
<div id="tabs-3">
<div>
<a href="javascript:void(0)" οnclick="add_information('new_product')">添加</a>
</div>
<div id="list_3"></div>
</div>
</div>
<div id="information_dialog">
<div id="information_container"></div>
</div>
<script type="text/javascript">
$( function(){
$( '#slt_information_type' ).change( function(){
$( '#list' ).jsonsearch( 'type', $(this).val() );
});
$('.btn, ul#icons li').hover(
function() { $(this).addClass('ui-state-hover'); },
function() { $(this).removeClass('ui-state-hover'); }
);
var $tabs = $( '#tabs' ).tabs({
add: function( event, ui ) {
},
select: function ( event, ui ) {
var arrURL = $( ui.tab ).find( 'input' );
if ( arrURL.length > 0 ) {
list( arrURL.eq(0).val(), ui.index + 1 );
arrURL.eq(0).remove();
} else {
reload( ui.index + 1 );
}
},
ajaxOptions:{async: true}
});
$( '#information_dialog' ).dialog({
autoOpen: false,
modal: true,
buttons: {
'确定': function(){
save_information();
},
'关闭': function(){
$(this).dialog( 'close' );
}
},
width: '1010px',
position: 'top'
});
$tabs.tabs( 'select', '1' );
list( 'company', 1 );
});
</script>
<script type="text/javascript">
function list ( type, tab_index ) {
$( '#list_' + tab_index ).jsontable({
mtype : 'POST',
url : base_url + 'index.php/Admin_information/jsondata/' + type,
datatype : 'json',
page : 1,
nums : 20,
colNames : [' ','标题', '点击率', '状态', '发布日期', '创建日期', '操作'],
rowList : [20,30,40]
});
}
function reload ( tab_index )
{
$( '#list_' + tab_index ).loaddata();
}
function format_json_data_for_table ( jsondata ) {
var rows = '';
$.each( jsondata, function ( i, n ) {
var tr = '<tr>';
tr += '<td><input type="checkbox" value="' + n.id + '"></td>';
//标题
tr += '<td><span>' + n.title + '</span></td>';
//点击率
tr += '<td><span>' + n.hit_counter + '</span></td>';
if ( 'true' == n.publish )
{
tr += '<td><span>已发布</span></td>';
}
else
{
tr += '<td><span>未发布</span></td>';
}
//发布日期
tr += '<td><span>' + n.publish_date + '</span></td>';
//创建日期
tr += '<td><span>' + n.create_date + '</span></td>';
//操作
tr += '<td><span>';
tr += '[<a href="javascript:void(0)" οnclick="edit_information( ' + n.id + ' )">详细</a>]';
tr += '</span></td>';
tr += '</tr>';
rows += tr;
});
return rows;
}
function add_information ( type )
{
waiting( true );
var url = base_url + 'index.php/Admin_information/add/' + type;
$.get( url, {}, function( html ){
$( '#information_container' ).html( html );
waiting( false );
$( '#information_dialog' ).dialog( 'open' );
});
}
function edit_information ( id )
{
waiting( true );
var url = base_url + 'index.php/Admin_information/edit/' + id;
$.get( url, {}, function( html ){
$( '#information_container' ).html( html );
waiting( false );
$( '#information_dialog' ).dialog( 'open' );
});
}
function save_information ()
{
waiting( true );
$( '#f_information' ).ajaxSubmit( function( data ){
var json = format_jsondata( data );
if ( '1' == json.status )
{
waiting( false );
$( '#information_dialog' ).dialog( 'close' );
reload(1);
reload(2);
reload(3);
}
else
{
alert( json.msg );
}
});
}
function upload_image ()
{
waiting( true );
$( '#f_image' ).ajaxSubmit( function( data ){
var json = format_jsondata( data );
if ( '1' == json.status )
{
waiting( false );
var html = '<input type="hidden" value="' + json.img + '" name="data[thumb_image]">';
html += '<img src="' + base_url + json.img + '">';
$( '#div_thumb_image' ).html( html );
}
else
{
alert( json.msg );
}
});
}
</script>
//view/admin/information/add.php
<form enctype="multipart/form-data" action="<?php echo base_url()?>index.php/Upload/do_upload" method="post" id="f_image">
<div>
活动预览
<div>
<input type="file" name="thumb_image">
<input type="button" value="上传" οnclick="upload_image()">
<input type="button" value="在图片库中选择" οnclick="select_image()">
</div>
</div>
</form>
<form method="post" action="<?php echo base_url()?>index.php/Admin_information/add" id="f_information">
<input type="hidden" value="<?php echo $type;?>" name="data[type]">
<div id="div_thumb_image">
</div>
<div>
标题
<div><input type="text" name="data[title]"></div>
</div>
<div>
内容
<div><textarea name="data[content]"></textarea></div>
</div>
<div>
是否发布
<div><input type="checkbox" name="data[publish]" value="1"></div>
</div>
</form>
//views/admin/information/edit.php
<form enctype="multipart/form-data" action="<?php echo base_url()?>index.php/Upload/do_upload" method="post" id="f_image">
<div>
活动预览
<div>
<input type="file" name="thumb_image">
<input type="button" value="上传" οnclick="upload_image()">
<input type="button" value="在图片库中选择" οnclick="select_image()">
</div>
</div>
</form>
<form method="post" action="<?php echo base_url()?>index.php/Admin_information/edit/<?php echo $information['id']?>" id="f_information">
<div id="div_thumb_image">
<?php if ( !empty( $information['thumb_image'] ) ) :?>
<img src="<?php echo base_url().$information['thumb_image']?>">
<?php endif;?>
</div>
<div>
标题 :<input type="text" name="data[title]" value="<?php echo $information['title']?>">
</div>
<div>
内容 :<textarea name="data[content]"><?php echo $information['content']?></textarea>
</div>
<div>
是否发布:<input type="checkbox" name="data[publish]" value="1" <?php echo ( 'true' == $information['publish'] )?'checked="checked"':'';?>>
</div>
</form>
//consts.php
<?php
define( 'CATEGORY_NAME_REPEAT', '分类名字已被使用' );
define( 'CATEGORY_ADD_SUCCESS', '分类添加成功' );
define( 'CATEGORY_ADD_ERROR', '分类添加失败' );
define( 'CATEGORY_UPDATE_SUCCESS', '分类修改成功' );
define( 'CATEGORY_UPDATE_ERROR', '分类修改失败' );
define( 'CATEGORY_DEL_SUCCESS', '分类删除成功' );
define( 'CATEGORY_DEL_ERROR', '分类删除失败' );
define( 'PRODUCT_NAME_REPEAT', '产品名字已被使用' );
define( 'PRODUCT_ADD_SUCCESS', '产品添加成功' );
define( 'PRODUCT_ADD_ERROR', '产品添加失败' );
define( 'PRODUCT_UPDATE_SUCCESS', '产品修改成功' );
define( 'PRODUCT_UPDATE_ERROR', '产品修改失败' );
define( 'PRODUCT_DEL_SUCCESS', '产品删除成功' );
define( 'PRODUCT_DEL_ERROR', '产品删除失败' );
define( 'INFORMATION_ADD_SUCCESS', '产品添加成功' );
define( 'INFORMATION_ADD_ERROR', '产品添加失败' );
define( 'INFORMATION_UPDATE_SUCCESS', '产品修改成功' );
define( 'INFORMATION_UPDATE_ERROR', '产品修改失败' );
define( 'INFORMATION_DEL_SUCCESS', '产品删除成功' );
define( 'INFORMATION_DEL_ERROR', '产品删除失败' );
define( 'IMAGE_SIZE_EXCEED', '图片大小超出限制' );
define( 'IMAGE_TYPE_ERROR', '图片类型不符合' );
//dfbc.sql
create table dfbc_categories (
id mediumint(8) unsigned not null auto_increment,
parent_id mediumint(8) unsigned not null default 0,
path varchar(255) not null default '0',
name varchar(255) not null,
media_id int(10) not null default 0,
created_by int(10) not null default 0,
createtime int(10) not null default 0,
primary key(id)
)ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
create table dfbc_products (
id mediumint(8) unsigned not null auto_increment,
name varchar(255) not null,
en_name varchar(255) not null default '',
category_id mediumint(8) unsigned not null default 0,
is_new enum( 'true', 'false' ) default 'true',
is_recommend enum( 'true', 'false' ) default 'false',
selling_point varchar(255) not null default '',
components varchar(255) not null default '',
specifications varchar(255) not null default '',
image varchar(255) not null default '',
effect text,
created_by int(10) not null default 0,
createtime int(10) not null default 0,
primary key(id)
)ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
create table dfbc_informations (
id mediumint(8) unsigned not null auto_increment,
title varchar(255) not null,
type enum( 'company', 'activities', 'new_product' ) default 'company',
created_by int(10) not null default 0,
createtime int(10) not null default 0,
publish enum( 'true', 'false' ) default 'false',
publish_time int(10) not null default 0,
hit_counter int(10) not null default 0,
thumb_image varchar(255) not null default '',
disabled enum( 'true', 'false' ) default 'false',
content longtext,
primary key(id)
)ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
create table dfbc_medias (
id mediumint(8) unsigned not null auto_increment,
name varchar(255) not null,
path varchar(255) not null default '',
created_by int(10) not null default 0,
createtime int(10) not null default 0,
primary key(id)
)ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
create table dfbc_faq (
id mediumint(8) unsigned not null auto_increment,
is_answer enum( 'true', 'false' ) default 'false',
username varchar(255) not null default '',
contact varchar(255) not null default '',
content text,
primary key(id)
)ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
CREATE TABLE IF NOT EXISTS `dfbc_admins` (
`admin_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`group_name` varchar(255) NOT NULL,
`editabled` enum('true','false') DEFAULT 'false',
`username` varchar(50) NOT NULL,
`password` varchar(50) NOT NULL,
`permissions` longtext,
PRIMARY KEY (`admin_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
INSERT INTO `dfbc_admins` (`admin_id`, `group_name`, `editabled`, `username`, `password`, `permissions`) VALUES
(1, 'Suppler Admin', 'false', 'dfbc@root.admin', '1d22bec34fbb6a311b5555482b32909e', 's:3:"all";');