Advertisement:

Author Topic: [SOLVED]Show user type in admin panel  (Read 2199 times)

BerniBCN

  • Jr. Member
  • **
  • Posts: 86
[SOLVED]Show user type in admin panel
« on: May 14, 2015, 01:14:22 am »
I would like to display in the users section in the admin panel an extra column for the user type, so i can see there fast if they are dealers or normal users or whatever without needing to click in each user 1 by 1...

I guess i will need to modify one core file (or maybe some)

Any idea?

Thanks in advance
« Last Edit: May 19, 2015, 01:17:46 am by BerniBCN »

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Show user type in admin panel
« Reply #1 on: May 14, 2015, 01:27:17 am »
Hi,

No, it can be done with no core modification, let me get back to you tomorrow.

Regards

itcafeonline

  • Full Member
  • ***
  • Posts: 243
Re: Show user type in admin panel
« Reply #2 on: May 14, 2015, 05:40:56 am »
following....

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Show user type in admin panel
« Reply #3 on: May 14, 2015, 01:21:35 pm »
Add this at the very bottom of your theme functions.php (take care not to leave blank lines after this):

Code: [Select]
<?php
function cust_admin_user_type_header($table) {

    
$table->addColumn('user_type''<span>User type</span>'); 
}

function 
cust_admin_user_type_data($row$aRow) {

    
$row['user_type'] = ($aRow['b_company'] ? 'Company' 'Individual') ;
    return 
$row ;
}

osc_add_hook('admin_users_table''cust_admin_user_type_header');
osc_add_filter("users_processing_row""cust_admin_user_type_data");
?>

To extend this, take into account that "users_processing_row" filter receives two arrays (that you may read and/or alter inside your custom function and return):

$aRow contains the user data as retrieved from the database (read-only)

$row contains already the data that will be printed in each column. These you can alter them, maybe you don't need another column just for User Type, alternatively you can append data to and already existent column, for instance:

Code: [Select]
$row['username'] += " (" . ($aRow['b_company'] ? 'Company' : 'Individual') . ")" ;
And add style:

Code: [Select]
$row['username'] += ' <span style="color: ' . ($aRow['b_company'] ? 'blue;">Company' : 'brown">Individual') . "</span>" ;
If you choose this way you don't need to use cust_admin_user_type_header($table) function, that adds a new global column.

Regards

BerniBCN

  • Jr. Member
  • **
  • Posts: 86
Re: Show user type in admin panel
« Reply #4 on: May 19, 2015, 12:39:22 am »
i tried first solution and it works perfect.

although I need to play a little with the code because i created some new user types. (like explained here: http://forums.osclass.org/general-help/how-add-new-user-type/msg74988/#msg74988)

Is there any code that display all  kinds of users not just individual or companies?

I mean, with this instructions it seems that the code just returns this 2 types, is there any way that the code "just takes from the database" wich user type the user is and shows it" I tried to write the new created usertypes like following but it doesnt works...

Code: [Select]
$row['user_type'] = ($aRow['b_company'] ? 'Company' : 'Individual' : 'X' : 'XX' : 'XXX');
Regards

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Show user type in admin panel
« Reply #5 on: May 19, 2015, 12:53:24 am »
No problem, if you're still using b_company field, $aRow['b_company'] will have your user type code, then:

Code: [Select]
if ($aRow['b_company'] == 0) $row['user_type'] = 'Individual';
elseif ($aRow['b_company'] == 1) $row['user_type'] = 'Company';
elseif ($aRow['b_company'] == 2) $row['user_type'] = 'Other';

Regards

BerniBCN

  • Jr. Member
  • **
  • Posts: 86
Re: Show user type in admin panel
« Reply #6 on: May 19, 2015, 01:17:30 am »
No problem, if you're still using b_company field, $aRow['b_company'] will have your user type code, then:

Code: [Select]
if ($aRow['b_company'] == 0) $row['user_type'] = 'Individual';
elseif ($aRow['b_company'] == 1) $row['user_type'] = 'Company';
elseif ($aRow['b_company'] == 2) $row['user_type'] = 'Other';

Regards

Thats working perfect!

Thanks again Teseo!

yellow53

  • Full Member
  • ***
  • Posts: 141
Re: [SOLVED]Show user type in admin panel
« Reply #7 on: November 01, 2017, 08:13:19 pm »
Hi Teseo,

I have a question, if i want to add the same user type info on the "manage listings" page, should i only add this ? :

osc_add_hook('admin_items_table', 'cust_admin_user_type_header');
osc_add_filter('items_processing_row', 'cust_admin_user_type_data');

It's showing user everywhere...when it should also show company for some...do you know why ?

many thanks
Vincent

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: [SOLVED]Show user type in admin panel
« Reply #8 on: November 02, 2017, 04:18:03 pm »
Hi,

Not much default information about User on Items list, so you need to retrieve that info first:

Add this at the very bottom of your theme functions.php:
Notes:
1.- Take care not to leave blank lines after this.
2.- If your theme functions.php doesn't end with ?> skip first line of my code.

Code: [Select]
<?php
function cust_admin_listings_user_type_header($table) {
    
$table->addColumn('user_type''<span>User type</span>');
}

function 
cust_admin_listings_user_type_data($row$aRow) {
    
$user User::newInstance()->findByPrimaryKey($aRow['fk_i_user_id']);
    
    
$row['user_type'] = ($user['b_company'] ? 'Company' 'Individual') ;
    return 
$row ;
}

osc_add_hook('admin_items_table''cust_admin_listings_user_type_header');
osc_add_filter("items_processing_row""cust_admin_listings_user_type_data");
?>


Regards

yellow53

  • Full Member
  • ***
  • Posts: 141
Re: [SOLVED]Show user type in admin panel
« Reply #9 on: November 02, 2017, 09:59:45 pm »
working great !! many thanks !

Same question on the email template, any idea how to send this variable ? I tried {USER_TYPE} but not working :(

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: [SOLVED]Show user type in admin panel
« Reply #10 on: November 03, 2017, 02:51:05 pm »
You're welcome :)

I've found this thread of yours (more specific request) and I've answered there:

https://forums.osclass.org/general-help/email-template-show-user-type

Regards

Resta

  • Sr. Member
  • ****
  • Posts: 273
Re: [SOLVED]Show user type in admin panel
« Reply #11 on: January 27, 2018, 01:38:02 pm »
Hi Teseo,

Thanks Teseo - solved below.

TIA!
« Last Edit: January 28, 2018, 02:44:48 am by Resta »

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: [SOLVED]Show user type in admin panel
« Reply #12 on: January 27, 2018, 05:48:04 pm »
Hi,

For Items page you can find a specific function in this message:

https://forums.osclass.org/general-help/show-user-type-in-admin-panel/msg157534/#msg157534

Regards