fix UI links and CSS in searches delivered by email, #72101
authorMark Wells <mark@freeside.biz>
Thu, 8 Sep 2016 18:05:26 +0000 (11:05 -0700)
committerMark Wells <mark@freeside.biz>
Thu, 8 Sep 2016 18:05:26 +0000 (11:05 -0700)
FS/FS/saved_search.pm
httemplate/edit/saved_search.html
httemplate/elements/header-popup.html

index 252dc71..caaf7fe 100644 (file)
@@ -219,11 +219,10 @@ sub render {
 
   local $FS::CurrentUser::CurrentUser = $self->access_user;
   local $FS::Mason::Request::QUERY_STRING = $self->query_string;
 
   local $FS::CurrentUser::CurrentUser = $self->access_user;
   local $FS::Mason::Request::QUERY_STRING = $self->query_string;
-  local $FS::Mason::Request::FSURL = ''; #?
-#  local $ENV{SERVER_NAME} = 'localhost'; #?
-#  local $ENV{SCRIPT_NAME} = '/freeside'. $self->path;
+  local $FS::Mason::Request::FSURL = $self->access_user->option('rooturl');
 
   my $mason_request = $fs_interp->make_request(comp => '/' . $self->path);
 
   my $mason_request = $fs_interp->make_request(comp => '/' . $self->path);
+  $mason_request->notes('inline_stylesheet', 1);
 
   local $@;
   eval { $mason_request->exec(); };
 
   local $@;
   eval { $mason_request->exec(); };
index 3039aed..cb6aa45 100644 (file)
 <%init>
 
 my $curuser = $FS::CurrentUser::CurrentUser;
 <%init>
 
 my $curuser = $FS::CurrentUser::CurrentUser;
+# remember the user's rooturl() when accessing the UI. this will be the
+# base URL for sending email reports to that user so that links work.
+my $rooturl_pref = qsearchs('access_user_pref', {
+  usernum   => $curuser->usernum,
+  prefname  => 'rooturl',
+});
+my $error;
+if ($rooturl_pref) {
+  if ($rooturl_pref->prefvalue ne rooturl()) {
+    $rooturl_pref->set('prefvalue', rooturl());
+    $error = $rooturl_pref->replace;
+  } # else don't update it
+} else {
+  $rooturl_pref = FS::access_user_pref->new({
+    usernum   => $curuser->usernum,
+    prefname  => 'rooturl',
+    prefvalue => rooturl(),
+  });
+  $error = $rooturl_pref->insert;
+}
+
+warn "error updating rooturl pref: $error" if $error;
 
 # prefix to the freeside document root (usually '/freeside/')
 my $root = URI->new($fsurl)->path;
 
 # prefix to the freeside document root (usually '/freeside/')
 my $root = URI->new($fsurl)->path;
index 839a636..327673b 100644 (file)
@@ -38,7 +38,13 @@ Example:
     <% $head |n %>
   </HEAD>
   <BODY <% $etc |n %>>
     <% $head |n %>
   </HEAD>
   <BODY <% $etc |n %>>
+%   if ($m->notes('inline_stylesheet')) { # for email delivery
+    <style type="text/css">
+    <& /elements/freeside.css &>
+    </style>
+%   } else {
     <link href="<%$fsurl%>elements/freeside.css" type="text/css" rel="stylesheet">
     <link href="<%$fsurl%>elements/freeside.css" type="text/css" rel="stylesheet">
+%   }
 % if ( $title || $title_noescape ) {
     <FONT SIZE=6>
       <CENTER><% encode_entities($title) || $title_noescape |n %></CENTER>
 % if ( $title || $title_noescape ) {
     <FONT SIZE=6>
       <CENTER><% encode_entities($title) || $title_noescape |n %></CENTER>