& elements/edit.html,
'name' => 'saved search',
'table' => 'saved_search',
'popup' => 1,
'fields' => [
{ field => 'searchname',
type => 'text',
size => 40,
},
{ field => 'freq',
type => 'select',
options => [ '', 'daily', 'weekly', 'monthly' ],
labels => { '' => 'no' },
},
{ field => 'emailaddress',
type => 'fixed',
curr_value_callback => sub {
$curuser->option('email_address')
|| 'no email address configured'
},
},
{ field => 'last_sent',
type => 'fixed-date',
},
{ field => 'format',
type => 'select',
options => [ 'html', 'xls', 'csv' ],
labels => {
'html' => 'webpage',
'xls' => 'spreadsheet',
'csv' => 'CSV',
},
},
{ field => 'disabled', # currently unused
type => 'hidden',
},
{ type => 'tablebreak-tr-title' },
{ field => 'path',
type => 'fixed',
cell_style => 'font-size: small',
},
{ field => 'params',
type => 'fixed',
cell_style => 'font-size: small',
},
],
'labels' => {
'searchnum' => 'Saved search',
'searchname' => 'Name this search',
'path' => 'Search page',
'params' => 'Parameters',
'freq' => 'Subscribe by email',
'last_sent' => 'Last sent on',
'emailaddress' => 'Will be sent to',
'format' => 'Report format',
},
'new_object_callback' => $new_object,
'delete_url' => $fsurl.'misc/delete-saved_search.html',
&>
<%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;
# alternatively, could do all this on the client using window.top.location
my $new_object = sub {
my $cgi = shift;
my $hashref = shift;
my $fields = shift;
for (grep { $_->{field} eq 'last_sent' } @$fields) {
$_->{type} = 'hidden';
}
my $url = $r->header_in('Referer')
or die "no referring page found";
$url = URI->new($url);
my $path = $url->path;
$path =~ s/^$root//; # path should not have a leading slash
my $title = $cgi->param('title');
return FS::saved_search->new({
'usernum' => $curuser->usernum,
'path' => $path,
'params' => $url->query,
'format' => 'html',
'searchname' => $title,
});
};
%init>