2 'name' => 'saved search',
3 'table' => 'saved_search',
6 { field => 'searchname',
12 options => [ '', 'daily', 'weekly', 'monthly' ],
13 labels => { '' => 'no' },
15 { field => 'emailaddress',
17 curr_value_callback => sub {
18 $curuser->option('email_address')
19 || 'no email address configured'
22 { field => 'last_sent',
27 options => [ 'html', 'xls', 'csv' ],
30 'xls' => 'spreadsheet',
34 { field => 'disabled', # currently unused
37 { type => 'tablebreak-tr-title' },
40 cell_style => 'font-size: small',
44 cell_style => 'font-size: small',
48 'searchnum' => 'Saved search',
49 'searchname' => 'Name this search',
50 'path' => 'Search page',
51 'params' => 'Parameters',
52 'freq' => 'Subscribe by email',
53 'last_sent' => 'Last sent on',
54 'emailaddress' => 'Will be sent to',
55 'format' => 'Report format',
57 'new_object_callback' => $new_object,
58 'delete_url' => $fsurl.'misc/delete-saved_search.html',
62 my $curuser = $FS::CurrentUser::CurrentUser;
63 # remember the user's rooturl() when accessing the UI. this will be the
64 # base URL for sending email reports to that user so that links work.
65 my $rooturl_pref = qsearchs('access_user_pref', {
66 usernum => $curuser->usernum,
67 prefname => 'rooturl',
71 if ($rooturl_pref->prefvalue ne rooturl()) {
72 $rooturl_pref->set('prefvalue', rooturl());
73 $error = $rooturl_pref->replace;
74 } # else don't update it
76 $rooturl_pref = FS::access_user_pref->new({
77 usernum => $curuser->usernum,
78 prefname => 'rooturl',
79 prefvalue => rooturl(),
81 $error = $rooturl_pref->insert;
84 warn "error updating rooturl pref: $error" if $error;
86 # prefix to the freeside document root (usually '/freeside/')
87 my $root = URI->new($fsurl)->path;
89 # alternatively, could do all this on the client using window.top.location
90 my $new_object = sub {
94 for (grep { $_->{field} eq 'last_sent' } @$fields) {
95 $_->{type} = 'hidden';
97 my $url = $r->header_in('Referer')
98 or die "no referring page found";
99 $url = URI->new($url);
100 my $path = $url->path;
101 $path =~ s/^$root//; # path should not have a leading slash
102 my $title = $cgi->param('title');
103 return FS::saved_search->new({
104 'usernum' => $curuser->usernum,
106 'params' => $url->query,
108 'searchname' => $title,