arteman (arteman) wrote in changelog,
arteman
arteman
changelog

[livejournal] r22222: LJSV-1484 Hardcoded support forum notifi...

Committer: azateev
LJSV-1484 Hardcoded support forum notifications via email for end-user
U   trunk/cgi-bin/supportlib.pl
Modified: trunk/cgi-bin/supportlib.pl
===================================================================
--- trunk/cgi-bin/supportlib.pl	2012-06-09 11:22:01 UTC (rev 22221)
+++ trunk/cgi-bin/supportlib.pl	2012-06-09 12:12:43 UTC (rev 22222)
@@ -486,10 +486,12 @@
     my $log = { 'uniq' => $o->{'uniq'},
                 'email' => $email };
     my $userid = 0;
+    my $html;
+    my $u;
 
     unless ($email) {
         if ($o->{'reqtype'} eq "user") {
-            my $u = LJ::load_userid($o->{'requserid'});
+            $u = LJ::load_userid($o->{'requserid'});
             $userid = $u->{'userid'};
 
             $log->{'user'} = $u->user;
@@ -504,6 +506,7 @@
             }
 
             $email = $u->email_raw || $o->{'reqemail'};
+            $html  = $u->receives_html_emails;
         }
     }
 
@@ -532,6 +535,15 @@
 
     if (@$errors) { return 0; }
 
+    my ($lang, $username, $ljuser);
+    if ($userid) {
+         $lang     = $u->prop('browselang') ||
+                     $o->{'language'} ||
+                     $LJ::DEFAULT_LANG;
+         $username = $u->{user};
+         $ljuser   = $u->ljuser_display;
+    }
+
     if (LJ::is_enabled("support_request_language")) {
         $o->{'language'} = undef unless grep { $o->{'language'} eq $_ } (@LJ::LANGS, "xx");
         $reqsubject = "[$o->{'language'}] $reqsubject" if $o->{'language'} && $o->{'language'} !~ /^en_/;
@@ -569,7 +581,7 @@
         }
     }
 
-    my ($urlauth, $url, $spid);  # used at the bottom
+    my ($urlauth, $url, $spid, $closeurl);  # used at the bottom
 
     my $sql = "INSERT INTO support (spid, reqtype, requserid, reqname, reqemail, state, authcode, spcatid, subject, timecreate, timetouched, timeclosed, timelasthelp) VALUES (NULL, $qreqtype, $qrequserid, $qreqname, $qreqemail, 'open', $qauthcode, $qspcatid, $qsubject, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 0, 0)";
     $sth = $dbh->prepare($sql);
@@ -615,30 +627,86 @@
         LJ::ContentFlag->set_supportid($o->{flagid}, $spid);
     }
 
-    my $body;
     my $miniauth = mini_auth({ 'authcode' => $authcode });
     $url = "$LJ::SITEROOT/support/see_request.bml?id=$spid";
     $urlauth = "$url&auth=$miniauth";
+    $closeurl = "$LJ::SITEROOT/support/act.bml?close;$spid;$authcode";
 
-    $body = "Your $LJ::SITENAME support request regarding \"$o->{'subject'}\" has been filed and will be answered as soon as possible.  Your request tracking number is $spid.\n\n";
-    $body .= "You can track your request's progress or add information here:\n\n  ";
-    $body .= $urlauth . "\n\n";
+    # disable auto-replies for the entire category, or per request
+    if (! $scat->{'no_autoreply'} && ! $o->{'no_autoreply'}) {
 
-    if ($scat->{user_closeable}) {
-        $body .= "If you figure out the problem before somebody gets back to you, please cancel your request by clicking this:\n\n  ";
-        $body .= "$LJ::SITEROOT/support/act.bml?close;$spid;$authcode";
-    }
+        my $closeable = sub {
+            return "" unless $scat->{user_closeable};
+            my $text =  LJ::Lang::get_text (
+                            $lang,
+                            'notification.support.submit.request.closeable',
+                            undef,
+                            { closeurl => $closeurl }
+                        );
+            if ($html) {
+                $text =~ s/\n/<br \/>/g;
+            }
+            return $text;
+        };
 
-    # disable auto-replies for the entire category, or per request
-    unless ($scat->{'no_autoreply'} || $o->{'no_autoreply'}) {
-        LJ::send_mail({
-            'to' => $email,
-            'from' => $LJ::BOGUS_EMAIL,
-            'fromname' => "$LJ::SITENAME Support",
-            'charset' => 'utf-8',
-            'subject' => "Support Request \#$spid",
-            'body' => $body
+        my $subject = LJ::Lang::get_text (
+                        $lang,
+                        'notification.support.submit.request.subject',
+                        undef,
+                        { request_id => $spid }
+                    );
+        my $body = LJ::Lang::get_text (
+                        $lang,
+                        'notification.support.submit.request.body.plain',
+                        undef,
+                        {
+                            username    => $username ||
+                                           $o->{'reqname'} ||
+                                           'User',
+                            subject     => $o->{'subject'},
+                            request_id  => $spid,
+                            urlauth     => $urlauth,
+                            close_it    => $closeable->(),
+                            sitename    => $LJ::SITENAMESHORT,
+                            siteroot    => $LJ::SITEROOT,
+                        }
+                );
+        if ($html) {
+            my $html_body = LJ::Lang::get_text (
+                                $lang,
+                                'notification.support.submit.request.body.html',
+                                undef,
+                                {
+                                    username    => $ljuser ||
+                                                   $o->{'reqname'} ||
+                                                   'User',
+                                    subject     => $o->{'subject'},
+                                    request_id  => $spid,
+                                    urlauth     => $urlauth,
+                                    close_it    => $closeable->(),
+                                    sitename    => $LJ::SITENAMESHORT,
+                                    siteroot    => $LJ::SITEROOT,
+                                }
+                            );
+            LJ::send_mail({
+                to          => $email,
+                from        => $LJ::BOGUS_EMAIL,
+                fromname    => "$LJ::SITENAME Support",
+                charset     => 'utf-8',
+                subject     => $subject,
+                body        => $body,
+                html        => $html_body,
             });
+        } else {
+            LJ::send_mail({
+                to          => $email,
+                from        => $LJ::BOGUS_EMAIL,
+                fromname    => "$LJ::SITENAME Support",
+                charset     => 'utf-8',
+                subject     => $subject,
+                body        => $body,
+            });
+        }
     }
 
     support_notify({ spid => $spid, type => 'new' });

Tags: arteman, azateev, livejournal, pl
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 1 comment