Mysql_AdminPrivileges_Db.object
上传用户:xiao730204
上传日期:2007-01-04
资源大小:141k
文件大小:7k
源码类别:
WEB邮件程序
开发平台:
PHP
- <?php
- class Mysql_AdminPrivileges_Db extends BaseObject {
- var $debug;
- var $admin_privileges_db;
- Function Mysql_AdminPrivileges_Db( $db_config = '' ) {
- $this->BaseObject( 'Mysql_AdminPrivileges_Db' );
- $this->admin_privileges_db = new Mysql_Db;
- if ( is_object( $db_config ) ) {
- $this->admin_privileges_db->db = $db_config;
- }
- $this->debug = new Debug;
- $this->autocreate_user = false;
- $this->debug->prefix = 'Mysql_Db::Admin_Privileges_Db';
- $this->debug->Off();
- } /* END Mysql_AdminPrivileges_Db() */
- Function InitDbConnection() {
- /* Make sure the database handle is available ( if not try to open it ) */
- if ( $this->admin_privileges_db->connection_init == false) {
- $retuns = $this->admin_privileges_db->CreateConnection();
- }
- /* Oh no we failed to open the connection */
- if ( $this->admin_privileges_db->connection_init == false ) {
- return array( false, 'Database connection failed' );
- }
- return array( true );
- }
- Function ListAll() {
- /* Init the database connection and bubble up errors */
- $this->debug->Message( 'Init connection' );
- list( $ret_val, $reason ) = $this->InitDbConnection();
- if ( $ret_val == false ) {
- $this->debug->Message( 'connect failed' );
- return array( $ret_val, $reason );
- }
- $select_all_privileges = $this->admin_privileges_db->PrepareSql(
- '
- SELECT
- user_id, add_users, edit_users, delete_users
- FROM
- admin_privileges_table
- ORDER BY
- user_id
- ');
- $i = 0;
- $ResultArray = array();
- $ResultObj = new AdminPrivileges();
- $select_all_privileges->Exec();
- while(
- list( $user_id, $add_users, $edit_users, $delete_users )
- = $select_all_privileges->FetchRow()
- ) {
- /* Loop through the output and build the array */
- $ResultObj = new AdminPrivileges;
- $ResultObj->user_id = $user_id;
- $ResultObj->add_users = $add_users;
- $ResultObj->edit_users = $edit_users;
- $ResultObj->delete_users = $delete_users;
- $ResultArray[ $i ] = $ResultObj;
- $i++;
- }
- return array( true, $i, $ResultArray );
- } /* END List All */
- Function Add( $ThisPrivilege ) {
- /* Sanity check on input */
- if ( $ThisPrivilege->user_id == '' ) {
- return array( false, 'NO user id provided' );
- }
- /* Make sure the database handle is available */
- /* Init the database connection and bubble up errors */
- $this->debug->Message( 'Init connection' );
- list( $ret_val, $reason ) = $this->InitDbConnection();
- if ( $ret_val == false ) {
- $this->debug->Message( 'connect failed' );
- return array( $ret_val, $reason );
- }
- $ThisPrivilege->BinaryTrueFalse();
- $insert_privilege = $this->admin_privileges_db->PrepareSql( '
- INSERT INTO
- admin_privileges_table
- ( user_id, add_users, edit_users, delete_users )
- VALUES ( ' .
- $ThisPrivilege->user_id . ', ' .
- $ThisPrivilege->add_users . ', ' .
- $ThisPrivilege->edit_users . ', ' .
- $ThisPrivilege->delete_users . ' ' .
- ' )'
- );
- list( $ret_val, $reason ) = $insert_privilege->Exec();
- if ( ! $ret_val ) {
- return array( false, 'Insert to table failed.' );
- } else {
- return array( true, $ThisPrivilege );
- }
- } /* END Add() */
- Function Delete( $user_id ) {
- /* Make sure the database handle is available */
- /* Init the database connection and bubble up errors */
- $this->debug->Message( 'Init connection' );
- list( $ret_val, $reason ) = $this->InitDbConnection();
- if ( $ret_val == false ) {
- $this->debug->Message( 'connect failed' );
- return array( $ret_val, $reason );
- }
- $delete_user = $this->admin_privileges_db->PrepareSql( 'DELETE FROM admin_privileges_table WHERE user_id = ' . $user_id );
- list( $ret_val, $reason ) = $delete_user->Exec();
- if ( ! $ret_val ) {
- return array( false, 'Failed to delete uid : ' . $user_id );
- } else {
- return array( true, $user_id );
- }
- } /* END Delete */
- Function Get( $user_id ) {
- /* Make sure the database handle is available */
- /* Init the database connection and bubble up errors */
- $this->debug->Message( 'Init connection' );
- list( $ret_val, $reason ) = $this->InitDbConnection();
- if ( $ret_val == false ) {
- $this->debug->Message( 'connect failed : ' . $reason );
- return array( $ret_val, $reason );
- }
- /* Build up the query string */
- $query_string = '';
- $query_string .= '
- SELECT
- user_id, add_users, edit_users, delete_users
- FROM
- admin_privileges_table
- WHERE
- user_id = ' . $user_id;
- $query_string .= ';';
- $get_user_info
- = $this->admin_privileges_db->PrepareSql( $query_string );
- /* $get_user_info->Exec(); */
- if ( ! (
- list( $user_id, $add_users, $edit_users, $delete_users )
- = $get_user_info->FetchRow()
- ) ){
- $this->debug->Message( 'No match found!' );
- return array( false, 'NO Match found.' );
- }
- $ResultObject = new AdminPrivileges;
- $ResultObject->user_id = $user_id;
- $ResultObject->add_users = $add_users;
- $ResultObject->edit_users = $edit_users;
- $ResultObject->delete_users = $delete_users;
- $this->debug->Message(
- 'User Id : ' . $ResultObject->user_id
- );
- $this->debug->Message(
- 'Add Users : ' . $ResultObject->add_users
- );
- $this->debug->Message(
- 'Edit Users : ' . $ResultObject->edit_users
- );
- $this->debug->Message(
- 'Delete Users : ' . $ResultObject->delete_users
- );
- $this->debug->Message( 'Ret true' );
- return array( true, $ResultObject );
- } /* END Get() */
- Function Modify( $user_id, $ThisPrivileges ) {
- if ( $user_id == '' ) {
- return array( false, 'Please provide a user id.');
- }
- /* Make sure the database handle is available */
- /* Init the database connection and bubble up errors */
- $this->debug->Message( 'Init connection' );
- list( $ret_val, $reason ) = $this->InitDbConnection();
- if ( $ret_val == false ) {
- $this->debug->Message( 'connect failed' );
- return array( $ret_val, $reason );
- }
- $ThisPrivileges->BinaryTrueFalse();
- $query_string = '';
- $query_string =
- '
- UPDATE
- admin_privileges_table
- SET ';
- $more_than_one = false;
- if ( $ThisPrivileges->add_users != '' ) {
- $more_than_one = true;
- $query_string .= 'add_users = ' . $ThisPrivileges->add_users . ' ';
- }
- if ( $ThisPrivileges->edit_users != '' ) {
- if ( $more_than_one ) {
- $query_string .= ' , ';
- }
- $more_than_one = true;
- $query_string .= 'edit_users = ' . $ThisPrivileges->edit_users . ' ';
- }
- if ( $ThisPrivileges->delete_users != '' ) {
- if ( $more_than_one ) {
- $query_string .= ' , ';
- }
- $more_than_one = true;
- $query_string .= 'delete_users = ' . $ThisPrivileges->delete_users . ' ';
- }
- $query_string .= 'where user_id = ' . $user_id
- ;
- $mod_user_info = $this->admin_privileges_db->PrepareSql( $query_string );
- return array( true, $mod_user_info->Exec() );
- } /* END Modify */
- }
- ?>