<?php
/**
* 用户管理列表
* @desc
* @author [Alone] alonedistian@gmail.com
*/
class CTRL_USER extends CTRL_CONTROLLER
{
public function index()
{
$_o_modUser = new MODEL_USER();
$_o_modUser->table(CORE_CONFIG::get("TABLE_HEAD")."user");
if(!empty($_REQUEST['user_name']))
$_o_modUser->where("`user_name` LIKE '%{$_REQUEST['user_name']}%'" );
$_a_result= $_o_modUser->pageFetch();
//获取一个全新的与该MODEL对应的ORM对象
//关于orm这块现在还真没弄明白呢
$_o_ormAdmin = $_o_modUser->create();
//var_dump($_o_ormAdmin->html());
//设置指定栏目的指定属性的值
//$_o_ormAdmin->setBill( 'role_id', 'enum', $_a_roles);
//var_dump($_o_ormAdmin->html());
//将$_a_result数组中的最后一个元素删除放到page里面去,
$this->assign( 'page', array_pop( $_a_result ) ); //分页信息
$this->assign( 'list', $_a_result ); //列表信息
$this->assign( 'request', $_REQUEST ); //表单请求数据
$this->assign( 'formhtml', $_o_ormAdmin->html() ); //使用当前BILL中的成员生成对应的HTML表单元素
$this->display( 'user/list.tpl' );
}
/**
* 修改/创建 用户信息
*/
public function mod(){
$_o_modUser = new MODEL_USER();
if( !empty( $_REQUEST['user_id'] ) ){ //读取需要编辑的信息
$_s_method = "get{$_REQUEST['user_id']}";
$_o_ormUser = $_o_modUser->$_s_method; //get1(); get2(); get3(); 取得指定用户详细信息
if( !$_o_ormUser )
$this->showMessage( false, 'Account undefined!' );
$_o_ormUser = $_o_ormUser[0];
}else
$_o_ormUser = $_o_modUser->create();
if( $_REQUEST['method'] == 'POST' ){
//这里进行插入操作
$_o_ormUser->input($_REQUEST);
if(intval($_REQUEST['user_id']) >=1)
{
if( !$_o_ormUser->save() ){
$this->showMessage( 0, $this->getLastMsg(), array(), true );
}
}else{
if( !$_o_ormUser->insert() ){
$this->showMessage( 0, $this->getLastMsg(), array(), true );
}
}
$this->showMessage( true, 'Finish', array( 'Back to list' => C("WEBSITE_DOMAIN").'/user', 'continue' => C("WEBSITE_DOMAIN")."/admin/mod/{$_REQUEST['role_id']}" ) );
}else{
$this->assign( 'form_element', $_o_ormUser->html() );
$this->display( 'user/info.tpl' );
}
}//function
/***************************
*
* @删除用户信息
*
* ************************/
public function del()
{
if( empty( $_REQUEST['user_id'] ) )
$this->showMessage( false, "Please select an account" );
$_o_modUser = new MODEL_USER();
$_o_ormUser = $_o_modUser->create();
$_o_ormUser->__set( 'user_id', $_REQUEST['user_id']);
$_void_result = $_o_ormUser->del();
if( !$_void_result ){
$this->showMessage( false, $this->getLastMsg() );
}
$this->redirect( );
}
}
/**
* Finish
* o._.o
*/
?>