Diff -- /var/www/vhosts/3dshawn.com/ptmatrix.3dshawn.com/admin_team.cgi

O Operator
Diff

/var/www/vhosts/3dshawn.com/ptmatrix.3dshawn.com/admin_team.cgi

added on local at 2026-07-11 18:33:17

Added
+122
lines
Removed
-0
lines
Context
0
unchanged
Blobs
from
to 7bc2e29423c0
Restore this content →
Unified diff
Naive LCS-based line diff. Additions in emerald, deletions in rose. Both sides decompressed live from BLOB_STORE.
1#!/usr/bin/perl
2
3##################################################################################################################################
4# ______ ____ ____ ______ ______ ____ ___ __ ___ ______ _ __ ____ ____ __ __ _ __ _____ ____
5# / ____// __ \ / __ \ / ____/ / ____// __ \ / | / |/ // ____/| | / // __ \ / __ \ / //_/ | | / /|__ / / __ \
6# / / / / / // / / // __/ / /_ / /_/ // /| | / /|_/ // __/ | | /| / // / / // /_/ // ,< | | / / /_ < / / / /
7# / /___ / /_/ // /_/ // /___ / __/ / _, _// ___ | / / / // /___ | |/ |/ // /_/ // _, _// /| | | |/ / ___/ /_ / /_/ /
8# \____/ \____//_____//_____/ /_/ /_/ |_|/_/ |_|/_/ /_//_____/ |__/|__/ \____//_/ |_|/_/ |_| |___/ /____/(_)\____/
9#
10# - Written by: Shawn Pickering
11# - shawn@shawnpickering.com
12##################################################################################################################################
13use strict;
14use lib '/var/www/vhosts/3dshawn.com/ptmatrix.3dshawn.com';
15
16
17#############################################################
18## Variables
19#############################################################
20
21
22
23############################################################
24# Modules
25############################################################
26#Load the CGI module
27use CGI;
28my $query = new CGI;
29my $form = $query->Vars;
30
31#Load the login module
32use MODS::Login;
33my $login = new MODS::Login;
34
35#Load Urls
36use MODS::PTMatrix::Urls;
37my $getlist = new MODS::PTMatrix::Urls;
38my $url = $getlist->urls();
39
40#Load the template module
41use MODS::Template;
42my $tfile = new MODS::Template;
43
44#Page Wrapper Module
45use MODS::PTMatrix::Wrapper;
46my $load = new MODS::PTMatrix::Wrapper;
47
48#Load the database connect module
49use MODS::DBConnect;
50my $db = new MODS::DBConnect;
51
52#Load the configuration file
53use MODS::PTMatrix::Config;
54my $config = new MODS::PTMatrix::Config;
55my $database_name = $config->settings('database_name');
56
57#Shared PM helpers
58use MODS::PTMatrix::PM;
59
60
61
62#############################################################
63## Get form data
64#############################################################
65#Escapes bad characters
66foreach my $line(keys %$form){
67 $form->{$line} =~ s/[^!-~\s]//g; #Remove non ascii chars
68 $form->{$line} = quotemeta("$form->{$line}");
69}
70
71
72
73############################################################
74# Program Controls
75############################################################
76$|=1;
77my $userinfo = $login->login_verify();
78print qq~Content-type:text/html; Cache-Control:no-cache;\n\n~;
79if(!$userinfo){print qq~<script>window.location="$url->{login}";</script>~;}
80elsif(!($userinfo->{is_super_admin} || $userinfo->{_admin_is_super_admin})){print qq~<script>window.location="$url->{dashboard}";</script>~;}
81else{&admin_team_list;}
82
83
84############################################################
85# Subroutines
86############################################################
87sub admin_team_list{
88 #This is the SUPER-ADMIN "platform team" list - users with is_super_admin or is_admin.
89 #Distinct from admin_users.cgi which lists every user across every customer company.
90
91 my $dbh = $db->db_connect();
92
93 #------------------------------------------------------------------------------------------------------
94 #Pull the platform-admin and super-admin rows + their company
95 my $sql = qq~SELECT u.id, u.email, u.display_name, u.role, u.avatar_color, u.account_status, u.is_super_admin, u.is_admin, u.last_login_at, UNIX_TIMESTAMP(u.last_login_at) AS last_login_epoch, c.id AS company_id, c.name AS company_name, c.brand_color AS company_color FROM `${database_name}`.users u LEFT JOIN `${database_name}`.companies c ON c.id = u.company_id WHERE (u.is_super_admin = 1 OR u.is_admin = 1) ORDER BY u.is_super_admin DESC, u.created_at ASC LIMIT 200~;
96 my @users = $db->db_readwrite_multiple($dbh, $sql, $ENV{SCRIPT_NAME}, __LINE__);
97 #------------------------------------------------------------------------------------------------------
98
99 $db->db_disconnect($dbh);
100
101 my $self_id = MODS::PTMatrix::PM::get_user_id($userinfo);
102 foreach my $usr(@users){
103 $usr->{initials} = MODS::PTMatrix::PM::initials($usr->{display_name});
104 $usr->{display_name} = MODS::PTMatrix::PM::h($usr->{display_name});
105 $usr->{company_name} = MODS::PTMatrix::PM::h($usr->{company_name} || '');
106 $usr->{is_self} = ($usr->{id} == $self_id) ? 1 : 0;
107 }
108
109 #Create all template variables
110 my $tvars;
111 $tvars->{users} = \@users;
112 $tvars->{has_users} = scalar(@users) ? 1 : 0;
113
114 my $body = join('', $tfile->template('tf_admin_team.html', $tvars, $userinfo));
115
116 $load->render({
117 userinfo => $userinfo,
118 page_key => 'admin_team',
119 title => 'Team Members',
120 body => $body,
121 });
122}