//RZ_Controller.php
<?php
class RZ_Controller extends Controller {
var $user = null;
var $user_id = 1;
var $cfg_path = 'system/application/cfg_page';
function RZ_Controller () {
parent::Controller();
}
function _isAjax() {
return ( isset($_SERVER['HTTP_X_REQUESTED_WITH'] ) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' );
}
function _get_user () {
$this->user = $this->session->userdata( 'user' );
if ( empty( $this->user ) ) {
if ( $this->_isAjax() ) {
$this->_msg( ERROR_USER_NOT_LOGIN );
} else {
redirect( 'User/login/', 'refresh' );
}
}
$this->user_id = $this->user['user_id'];
}
function _json_data () {
$data = array( 'total'=>0, 'rows'=>array() );
if ( empty( $this->user_id ) ) {
echo json_encode( $data );
exit();
}
$conditions = array();
if ( !empty( $_POST['filter_name'] ) and !empty( $_POST['filter_value'] ) ) {
if ( is_string( $_POST['filter_name'] ) ) {
$conditions[$_POST['filter_name'].' LIKE'] = strval( $_POST['filter_value'] );
} else if ( is_int( $_POST['filter_name'] ) ) {
$conditions[$_POST['filter_name']] = intval( $_POST['filter_value'] );
}
}
$pagination = array();
$pagination['page'] = 1;
$pagination['nums'] = 10;
if ( !empty( $_POST['page'] ) ) {
$pagination['page'] = intval( $_POST['page'] );
}
if ( !empty( $_POST['nums'] ) ) {
$pagination['nums'] = intval( $_POST['nums'] );
}
$order = array();
if ( !empty( $_POST['sortname'] ) ) {
if ( !empty( $_POST['sortorder'] ) ) {
$order[$_POST['sortname']] = $_POST['sortorder'];
} else {
$order[$_POST['sortname']] = 'DESC';
}
}
$user_id = $this->user_id;
return array( $user_id, $conditions, $pagination, $order, $data );
}
function _send_email ( $sendto, $subject, $message ) {
$this->load->library( 'email' );
$this->email->from( '444570155@qq.com', 'www.efox1688.com' );
$this->email->to( $sendto );
$this->email->subject( $subject );
$this->email->message( $message );
$this->email->send();
}
function _msg ( $msg, $success = false ) {
$data = array( 'status' => 0, 'msg' => '' );
if ( $success ) {
$data['status'] = 1;
}
$data['msg'] = $msg;
echo json_encode( $data );
exit;
}
function _die ( $msg )
{
header( 'Content-type:text/html;charset=utf-8;' );
echo $msg;exit;
}
function _is_admin () {
return true;
$admin = $this->session->userdata( 'admin' );
if ( empty( $admin ) ) {
redirect( 'Admin/login/', 'refresh' );
} else {
//echo '<pre>';print_r( $admin['permissions'] );echo '</pre>';exit;
if ( 'all' == $admin['permissions'] ) {
return true;
}
$segment = $this->uri->segment_array();
//echo '<pre>';print_r( $segment );echo '</pre>';exit;
if ( in_array( $segment[1], $admin['permissions'] ) ) {
return true;
} else {
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
echo '<div align="center">没有权限</div>';
echo '<div align="center">';
echo '<a href="'.base_url().'index.php/Admin/home">首页</a>';
echo '</div>';
exit;
}
}
return false;
}
function _admin_json_data () {
$data = array( 'total'=>0, 'rows'=>array() );
$this->_is_admin();
$conditions = array();
if ( !empty( $_POST['filter_name'] ) and !empty( $_POST['filter_value'] ) ) {
if ( is_string( $_POST['filter_name'] ) ) {
$conditions[$_POST['filter_name'].' LIKE'] = strval( $_POST['filter_value'] );
} else if ( is_int( $_POST['filter_name'] ) ) {
$conditions[$_POST['filter_name']] = intval( $_POST['filter_value'] );
}
}
$pagination = array();
$pagination['page'] = 1;
$pagination['rows'] = 10;
if ( !empty( $_POST['page'] ) ) {
$pagination['page'] = intval( $_POST['page'] );
}
if ( !empty( $_POST['nums'] ) ) {
$pagination['nums'] = intval( $_POST['nums'] );
}
$order = array();
if ( !empty( $_POST['sortname'] ) ) {
if ( !empty( $_POST['sortorder'] ) ) {
$order[$_POST['sortname']] = $_POST['sortorder'];
} else {
$order[$_POST['sortname']] = 'DESC';
}
}
return array( $conditions, $pagination, $order, $data );
}
function menu_view ( $title, $items ) {
$data = array();
$data['title'] = $title;
$data['items'] = $items;
$this->load->view( 'menu', $data );
}
}
/*
* 兼容PHP4中没有json_encode这个函数
*/
if ( !function_exists('json_encode') ) {
function json_encode( &$data ) {
$ci = & get_instance();
$ci->load->library( 'Services_Json' );
return $ci->services_json->encode( $data );
}
}
/*
* 兼容PHP4中没有json_encode这个函数
*/
if ( !function_exists('json_decode') ) {
function json_decode( &$data ) {
$ci = & get_instance();
$ci->load->library( 'Services_Json' );
return $ci->services_json->decode( $data );
}
}
//Information.php
<?php
class Information extends RZ_Controller
{
function Information ()
{
parent::Controller();
$this->data = array();
$this->data['use_self_menu'] = 'Information/menu';
$this->data['menu'] = $this->_menu();
}
function _menu ()
{
return $this->load->view( 'information/menu', array(), true );
}
function jsondata ( $type = 'company' )
{
list( $user_id, $conditions, $pagination, $order, $data ) = $this->_json_data();
$conditions['disabled'] = 'false';
$conditions['type'] = $type;
$conditions['publish'] = 'true';
$this->load->model( 'Information_model' );
$data['total'] = $this->Information_model->get_total( $conditions );
if ( empty( $data['total'] ) ) {
$data['total'] = 0;
echo json_encode( $data );
exit;
}
$list = $this->Information_model->find( array(
'fields' => array( '*' ),
'conditions' => $conditions
));
$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( 'information/list', $this->data );
}
function activities ()
{
$this->data['type'] = 'activities';
$this->layout->view( 'information/list', $this->data );
}
function new_product ()
{
$this->data['type'] = 'new_product';
$this->layout->view( 'information/list', $this->data );
}
function id ( $id )
{
$id = intval( $id );
$this->load->model( 'Information_model' );
$this->data['information'] = $this->Information_model->get_one( array(
'fields' => array( '*' ),
'conditions' => array( 'id' => $id ),
));
if ( empty( $this->data['information'] ) )
{
$this->_die( INFORMATION_NOT_EXISTS );
}
$data = array();
$data['hit_counter'] = intval( $this->data['information']['hit_counter'] ) + 1;
$this->Information_model->id = $id;
$this->Information_model->update( $data );
$this->layout->view( 'information/view', $this->data );
}
}
//Product.php
<?php
class Product extends RZ_Controller
{
function Product ()
{
parent::Controller();
$this->data = array();
$this->data['use_self_menu'] = 'Product/menu';
$this->data['menu'] = $this->_categories();
}
function index ()
{
$this->load->model( 'Category_model' );
$category = $this->Category_model->get_one( array(
'fields' => array( 'id' ),
'conditions' => array( 'disabled' => 'false' ),
'order' => array( 'order_num' => 'ASC' )
));
if ( empty( $category ) )
{
$this->_die( CATEGORY_NOT_EXISTS );
}
$this->cid( $category['id'] );
}
function _categories ()
{
$this->load->model( 'Category_model' );
$categories = $this->Category_model->find( array(
'fields' => array( 'id', 'parent_id', 'name' )
));
if ( empty( $categories ) )
{
return null;
}
$this->load->library( 'tree' );
$this->tree->build( $categories );
unset( $categories );
$categories = array();
$this->tree->get_list( $categories );
$menu = array( 'items' => array() );
$counter = 0;
foreach ( $categories as $category )
{
if ( !empty( $category['_level'] ) )
{
$menu['items'][$counter] = $category;
$menu['items'][$counter]['url'] = base_url().'Product/cid/'.$category['id'];
$counter++;
}
}
return $menu;
}
//view product
function id ( $product_id )
{
$this->load->model( 'Product_model' );
$product_id = intval( $product_id );
$this->_view( $product_id );
$this->layout->view( 'product/view', $this->data );
}
function cid ( $category_id )
{
$category_id = intval( $category_id );
$this->load->model( 'Category_model' );
$this->load->model( 'Product_model' );
$this->data['category'] = $this->Category_model->get_one( array(
'fields' => array( 'id', 'name', 'media_id' ),
'conditions' => array( 'id' => $category_id )
));
if ( empty( $this->data['category'] ) )
{
$this->_die( CATEGORY_NOT_EXISTS );
}
$this->data['products'] = $this->Product_model->find( array(
'fields' => array( '*' ),
'conditions' => array( 'category_id' => $category_id )
));
$this->load->model( 'Media_model' );
$this->data['media'] = $this->Media_model->get_one( array(
'fields' => array( '*' ),
'conditions' => array( 'id' => $this->data['category']['id'] )
));
$this->layout->view( 'category/view', $this->data );
}
function _view ( $product_id )
{
$this->data['product'] = $this->Product_model->get_one( array(
'fields' => array( '*' ),
'conditions' => array( 'id' => $product_id )
));
$this->data['recommend'] = $this->Product_model->find( array(
'fields' => array( '*' ),
'conditions' => array( 'is_recommend' => 'true' ),
'pagination' => array( 'page' => 1, 'nums' => 3 ),
'order' => array( 'order_num' => 'ASC' )
));
}
}
//Admin_product.php
<?php
class Admin_product extends RZ_Controller
{
var $data;
function Admin_product ()
{
parent::Controller();
$this->layout->setLayout( 'admin' );
$this->data = array();
$this->data['page_title'] = '产品管理';
}
function _categories ()
{
$this->load->model( 'Category_model' );
$categories = $this->Category_model->find( array(
'fields' => array( 'id', 'parent_id', 'name' )
));
if ( empty( $categories ) )
{
return null;
}
$this->load->library( 'tree' );
$this->tree->build( $categories );
unset( $categories );
$categories = array();
$this->tree->get_list( $categories );
$items = array();
$counter = 0;
foreach ( $categories as $category )
{
if ( !empty( $category['_level'] ) )
{
$items[$counter] = $category;
$items[$counter]['url'] = base_url().'Product/cid/'.$category['id'];
$counter++;
}
}
return $items;
}
function jsondata ()
{
list( $conditions, $pagination, $order, $data ) = $this->_admin_json_data();
$this->load->model( 'Product_model' );
$data['total'] = $this->Product_model->get_total( $conditions );
if ( empty( $data['total'] ) ) {
$data['total'] = 0;
echo json_encode( $data );
exit;
}
$data['rows'] = $this->Product_model->find( array(
'fields' => array( '*' )
));
echo json_encode( $data );
exit;
}
function index ()
{
$this->layout->view( 'admin/product/list', $this->data );
}
function add ()
{
if ( !empty( $_POST['data'] ) ) {
//echo '<pre>';print_r($_POST['data']);echo '</pre>';exit;
$this->load->model( 'Product_model' );
$this->Product_model->user_id = $this->user_id;
$data = $_POST['data'];
if ( array_key_exists( 'is_recommend', $data ) )
{
$data['is_recommend'] = 'true';
}
else
{
$data['is_recommend'] = 'false';
}
if ( $this->Product_model->rename_check( array( 'name' =>$data['name'] ) ) )
{
$this->_msg( PRODUCT_NAME_REPEAT );
}
if ( $this->Product_model->add( $data ) )
{
$this->_msg( PRODUCT_ADD_SUCCESS, true );
}
else
{
$this->_msg( PRODUCT_ADD_ERROR );
}
}
$data = array();
$data['categories'] = $this->_categories();
$this->load->view( 'admin/product/add', $data );
}
function edit ( $id = 0 )
{
$id = intval( $id );
if ( !empty( $_POST['data'] ) ) {
$this->load->model( 'Product_model' );
$this->Product_model->user_id = $this->user_id;
$this->Product_model->id = $id;
$data = $_POST['data'];
if ( array_key_exists( 'is_new', $data ) )
{
$data['is_new'] = 'true';
}
else
{
$data['is_new'] = 'false';
}
if ( array_key_exists( 'is_recommend', $data ) )
{
$data['is_recommend'] = 'true';
}
else
{
$data['is_recommend'] = 'false';
}
if ( $this->Product_model->rename_check( array( 'name' =>$data['name'] ), array( 'id' => $id ) ) )
{
$this->_msg( PRODUCT_NAME_REPEAT );
}
if ( $this->Product_model->update( $data ) )
{
$this->_msg( PRODUCT_UPDATE_SUCCESS, true );
}
else
{
$this->_msg( PRODUCT_UPDATE_ERROR );
}
}
$data = $this->_view( $id );
$data['categories'] = $this->_categories();
$this->load->view( 'admin/product/edit', $data );
}
function del ( $id = 0 )
{
$id = intval( $id );
$this->load->model( 'Product_model' );
$this->Product_model->user_id = $this->user_id;
$this->Product_model->id = $id;
if ( $this->Product_model->del() )
{
$this->_msg( PRODUCT_DEL_SUCCESS, true );
}
else
{
$this->_msg( PRODUCT_DEL_ERROR );
}
}
function id ( $id = 0 )
{
$id = intval( $id );
$data = $this->_view( $id );
$this->layout->view( 'admin/product/view', $data );
}
function _view ( $id )
{
$this->load->model( 'Product_model' );
$this->Product_model->user_id = $this->user_id;
$this->Product_model->id = intval( $id );
$data = array();
$data['product'] = $this->Product_model->get_one( array(
'fields' => array( '*' ),
'conditions' => array( 'id' => $this->Product_model->id, 'created_by' => $this->Product_model->user_id )
));
if ( empty( $data['product'] ) )
{
$this->_msg( PRODUCT_NOT_EXISTS );
}
$data['recommend'] = $this->Product_model->find( array(
'fields' => array( '*' ),
'conditions' => array( 'is_recommend' => 'true', 'category_id' => $data['product']['category_id'] ),
'order_by' => array( 'order' => 'asc' ),
'pagination' => array( 'page' => 1, 'nums' => 3 )
));
return $data;
}
}
//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,
disabled enum( 'true', 'false' ) default 'false',
order_num mediumint(8) unsigned not null default 50,
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',
order_num mediumint(8) unsigned not null default 50,
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,
type enum('image','flash','vedio') default 'image',
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";');