More Detail in Admin Logs

Discussion in 'Customization & add-ons' started by press_enterprise, Jun 9, 2009.

  1. press_enterprise

    press_enterprise aMember Pro Customer

    Joined:
    Aug 29, 2006
    Messages:
    26
    [​IMG]

    We needed more detail in our Admin Logs for accountability of record changes, so I made some modifications and we now have this under our admin logs.

    Version: 3.1.8PRO
    Backup your site before making any modifications! :)

    STEP 1 - Generate Extra Message Text Based on Changes
    In /amember/admin/users.php find this function:
    Code:
     function edit_save(){
        global $db, $t;
        global $member_additional_fields, $config;
    
        $vars = get_input_vars();
        $oldm = $db->get_user($vars['member_id']);
    
        $vars['email_verified']     = $oldm['email_verified'];
        $vars['security_code']      = $oldm['security_code'];
        $vars['securitycode_expire'] = $oldm['securitycode_expire'];
    
        ...
    ADD the below code after the above code to look like this (note we have two custom fields in there, phone_number and dsi_account):
    Code:
    function edit_save(){
        global $db, $t;
        global $member_additional_fields, $config;
    
        $vars = get_input_vars();
        $oldm = $db->get_user($vars['member_id']);
        	
    	// Check to see which values are different
    	if( $vars['login'] != $oldm['login'] ){
    		$admin_msg .= "<br>- Login: ".$oldm['login']." -> ".$vars['login'];
    	}
    
    	if( $vars['pass'] != $oldm['pass'] ){
    		$admin_msg .= "<br>- Password: ".$oldm['pass']." -> ".$vars['pass'];
    	}
    
    	if( $vars['email'] != $oldm['email'] ){
    		$admin_msg .= "<br>- Email: ".$oldm['email']." -> ".$vars['email'];
    	}
    	
    	if( $vars['name_f'] != $oldm['name_f'] ){
    		$admin_msg .= "<br>- First Name: ".$oldm['name_f']." -> ".$vars['name_f'];
    	}
    
    	if( $vars['name_l'] != $oldm['name_l'] ){
    		$admin_msg .= "<br>- Last Name: ".$oldm['name_l']." -> ".$vars['name_l'];
    	}
    
    	if( $vars['street'] != $oldm['street'] ){
    		$admin_msg .= "<br>- Street Address: ".$oldm['street']." -> ".$vars['street'];
    	}
    
    	if( $vars['city'] != $oldm['city'] ){
    		$admin_msg .= "<br>- City: ".$oldm['city']." -> ".$vars['city'];
    	}
    
    	if( $vars['state'] != $oldm['state'] ){
    		$admin_msg .= "<br>- State: ".$oldm['state']." -> ".$vars['state'];
    	}
    
    	if( $vars['zip'] != $oldm['zip'] ){
    		$admin_msg .= "<br>- ZIP Code: ".$oldm['zip']." -> ".$vars['zip'];
    	}
    
    	if( $vars['phone_number'] != $oldm['phone_number'] ){
    		$admin_msg .= "<br>- Phone Number: ".$oldm['phone_number']." -> ".$vars['phone_number'];
    	}
    
    	if( $vars['dsi_account'] != $oldm['dsi_account'] ){
    		$admin_msg .= "<br>- DSI Account: ".$oldm['dsi_account']." -> ".$vars['dsi_account'];
    	}
    
    	if( $vars['is_locked'] != $oldm['data']['is_locked'] ){
    		$admin_msg .= "<br>- Lock Status: ".$oldm['data']['is_locked']." -> ".$vars['is_locked'];
    	}
    	
        $vars['email_verified']     = $oldm['email_verified'];
        $vars['security_code']      = $oldm['security_code'];
        $vars['securitycode_expire'] = $oldm['securitycode_expire'];
    STEP 2 - Add Created Text to Admin Log Message
    Then further down, add the $admin_msg variable to this line:
    Code:
    	admin_log("Member record changed ($oldm[login])", 'members', $vars['member_id']);
    So it looks like this:
    Code:
    	admin_log("Member record changed ($oldm[login]) $admin_msg", 'members', $vars['member_id']);
    STEP 3 - Change admin_log template to allow HTML in message field
    In /amember/templates/admin/admin_log.html at line 34, CHANGE:
    Code:
        <td> {$p.message|escape} </td>
    to

    Code:
        <td> {$p.message} </td>
    This will allow HTML in this field to be displayed. I did this for the line returns.
  2. dan_kelly

    dan_kelly New Member

    Joined:
    Aug 29, 2006
    Messages:
    91
    VERY NICE!

    Thanks for the code.

Share This Page