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

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

added on local at 2026-07-01 21:47:08

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