Diff -- /var/www/vhosts/3dshawn.com/affiliate.3dshawn.com/messages_pending.cgi
Diff

/var/www/vhosts/3dshawn.com/affiliate.3dshawn.com/messages_pending.cgi

added on local at 2026-07-01 13:47:25

Added
+54
lines
Removed
-0
lines
Context
0
unchanged
Blobs
from
to 6a40be17c2bd
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# AffSoft -- topbar Messages pill live-poll data feed.
4#
5# Returns JSON { "n": <count> } of unread support threads:
6# - For admins: support_threads with admin_unread > 0.
7# - For regular users: their own support_threads with
8# customer_unread > 0.
9#
10# Polled every ~20s by the wrapper template so the pill blinks
11# without a page refresh.
12#======================================================================
13use strict;
14use warnings;
15
16use lib '/var/www/vhosts/3dshawn.com/affiliate.3dshawn.com';
17use CGI;
18use MODS::Login;
19use MODS::DBConnect;
20use MODS::AffSoft::Config;
21
22my $auth = MODS::Login->new;
23my $userinfo = $auth->login_verify();
24
25my $n = 0;
26if ($userinfo && $userinfo->{user_id}) {
27 my $uid = $userinfo->{user_id};
28 $uid =~ s/[^0-9]//g;
29 my $is_admin = $userinfo->{is_admin} || $userinfo->{_admin_is_admin} || 0;
30 my $db = MODS::DBConnect->new;
31 my $cfg = MODS::AffSoft::Config->new;
32 my $DB = $cfg->settings('database_name');
33 my $dbh = $db->db_connect();
34 if ($dbh) {
35 # support_threads (guarded against pre-migration deploys)
36 my $have_st = $db->db_readwrite($dbh, qq~
37 SELECT COUNT(*) AS n FROM information_schema.tables
38 WHERE table_schema='$DB' AND table_name='support_threads'
39 ~, $ENV{SCRIPT_NAME}, __LINE__);
40 if ($have_st && $have_st->{n}) {
41 my $sql = $is_admin
42 ? qq~SELECT COUNT(*) AS n FROM `${DB}`.support_threads WHERE admin_unread > 0~
43 : qq~SELECT COUNT(*) AS n FROM `${DB}`.support_threads WHERE customer_user_id='$uid' AND customer_unread > 0~;
44 my $r = $db->db_readwrite($dbh, $sql, $ENV{SCRIPT_NAME}, __LINE__);
45 $n += ($r && $r->{n}) ? $r->{n} : 0;
46 }
47 $db->db_disconnect($dbh);
48 }
49}
50
51print "Content-Type: application/json; charset=utf-8\n";
52print "Cache-Control: no-store, max-age=0\n";
53print "\n";
54print qq~{"n":$n}\n~;
Keyboard: j next diff k previous diff g top G bottom r restore c compile-check ? help