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',
26 type => 'hidden', # revisit this later
28 # options => [ 'html', 'xls', 'csv' ],
30 # 'html' => 'webpage',
31 # 'xls' => 'spreadsheet',
35 { field => 'disabled', # currently unused
38 { type => 'tablebreak-tr-title' },
41 cell_style => 'font-size: small',
45 cell_style => 'font-size: small',
49 'searchnum' => 'Saved search',
50 'searchname' => 'Name this search',
51 'path' => 'Search page',
52 'params' => 'Parameters',
53 'freq' => 'Subscribe by email',
54 'last_sent' => 'Last sent on',
55 'emailaddress' => 'Will be sent to',
56 'format' => 'Report format',
58 'new_object_callback' => $new_object,
59 'delete_url' => $fsurl.'misc/delete-saved_search.html',
63 my $curuser = $FS::CurrentUser::CurrentUser;
64 # remember the user's rooturl() when accessing the UI. this will be the
65 # base URL for sending email reports to that user so that links work.
66 my $rooturl_pref = qsearchs('access_user_pref', {
67 usernum => $curuser->usernum,
68 prefname => 'rooturl',
72 if ($rooturl_pref->prefvalue ne rooturl()) {
73 $rooturl_pref->set('prefvalue', rooturl());
74 $error = $rooturl_pref->replace;
75 } # else don't update it
77 $rooturl_pref = FS::access_user_pref->new({
78 usernum => $curuser->usernum,
79 prefname => 'rooturl',
80 prefvalue => rooturl(),
82 $error = $rooturl_pref->insert;
85 warn "error updating rooturl pref: $error" if $error;
87 # prefix to the freeside document root (usually '/freeside/')
88 my $root = URI->new($fsurl)->path;
90 # alternatively, could do all this on the client using window.top.location
91 my $new_object = sub {
95 for (grep { $_->{field} eq 'last_sent' } @$fields) {
96 $_->{type} = 'hidden';
98 my $url = $r->header_in('Referer')
99 or die "no referring page found";
100 $url = URI->new($url);
101 my $path = $url->path;
102 $path =~ s/^$root//; # path should not have a leading slash
103 my $title = $cgi->param('title');
104 return FS::saved_search->new({
105 'usernum' => $curuser->usernum,
107 'params' => $url->query,
109 'searchname' => $title,