--- /dev/null
+<& elements/browse.html,
+ 'title' => 'My saved searches',
+ 'name' => 'saved searches',
+ 'query' => { 'table' => 'saved_search',
+ 'hashref' => { usernum => $curuser->usernum },
+ },
+ 'count_query' => $count_query,
+ 'header' => [ '#',
+ 'Name',
+ 'Subscription',
+ 'Last sent',
+ 'Format',
+ 'Path',
+ 'Parameters',
+ ],
+ 'sort_fields' => [ 'searchnum',
+ 'searchname',
+ 'freq',
+ 'last_sent',
+ 'format',
+ "path || '?' || 'params'",
+ '',
+ ],
+ 'fields' => [ 'searchnum',
+ 'searchname',
+ 'freq',
+ sub { my $date = shift->get('last_sent');
+ $date ? time2str('%b %o, %Y', $date) : '';
+ },
+ sub { $format_label{ shift->get('format') }
+ },
+ 'path',
+ sub { join('<BR>',
+ sort
+ map { encode_entities(uri_unescape($_)) }
+ split(/[;&]/, shift->get('params') )
+ )
+ },
+ ],
+ 'size' => [ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '-1',
+ ],
+ 'links' => [ '', '' ],
+ 'link_onclicks' => [ '', $edit_popup ],
+# 'disableable' => 1, # currrently unused
+# 'disabled_statuspos' => 2,
+ 'really_disable_download' => 1
+&>
+<%init>
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+my $query = {
+ 'table' => 'saved_search',
+ 'hashref' => { 'usernum' => $curuser->usernum },
+};
+my $count_query = "SELECT COUNT(*) FROM saved_search WHERE usernum = ".
+ $curuser->usernum;
+
+my %format_label = (
+ 'html' => 'webpage',
+ 'csv' => 'CSV',
+ 'xls' => 'spreadsheet',
+);
+
+my $edit_popup = sub {
+ my $searchnum = shift->searchnum;
+ include('/elements/popup_link_onclick.html',
+ 'action' => $fsurl.'/edit/saved_search.html?'.$searchnum,
+ 'actionlabel' => 'Save this search',
+ 'width' => 650,
+ 'height' => 500,
+ );
+};
+
+</%init>
--- /dev/null
+<& elements/process.html,
+ 'table' => 'saved_search',
+ 'popup_reload' => 'Saving',
+ 'post_new_object_callback' => $callback,
+&>
+<%init>
+
+my $callback = sub {
+ my ($cgi, $obj) = @_;
+ $obj->usernum( $FS::CurrentUser::CurrentUser->usernum );
+ # if this would change it from its existing owner, replace_check
+ # will refuse
+};
+
+</%init>
--- /dev/null
+<& 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 => 'hidden', # revisit this later
+# 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;
+
+# 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>
my $curuser = $FS::CurrentUser::CurrentUser;
+# saved searches
+tie my %report_saved_searches, 'Tie::IxHash';
+if ( my @searches = grep { $_->disabled eq '' } $curuser->saved_search ) {
+ foreach my $search (@searches) {
+ $report_saved_searches{ $search->searchname } = [
+ # don't use query_string here; we don't want to override the format
+ $fsurl . $search->path . '?' . $search->params , ''
+ ];
+ }
+ $report_saved_searches{'separator'} = '';
+ $report_saved_searches{'My saved searches'} =
+ [ $fsurl. 'browse/saved_search.html',
+ 'Manage saved searches and subscriptions' ];
+}
+
#XXX Active tickets not assigned to a customer
tie my %report_prospects, 'Tie::IxHash';
|| $curuser->access_right('Configuration');
tie my %report_menu, 'Tie::IxHash';
+$report_menu{'Saved searches'} = [ \%report_saved_searches, 'My saved searches' ]
+ if keys(%report_saved_searches);
$report_menu{'Prospects'} = [ \%report_prospects, 'Prospect reports' ]
if $curuser->access_right('List prospects')
|| $curuser->access_right('List contacts');
my $conf = new FS::Conf;
my $date_format = $opt{'format'} || $conf->config('date_format') || '%m/%d/%Y';
-$opt{'formatted_value'} = time2str($date_format, $value);
+$opt{'formatted_value'} = $value > 0 ? time2str($date_format, $value) : '';
</%init>
--- /dev/null
+% if ( $error ) {
+<& /elements/errorpage-popup.html, $error &>
+% } else {
+<& /elements/header-popup.html, 'Saved search deleted' &>
+ <script type="text/javascript">
+ topreload();
+ </script>
+</body>
+</html>
+% }
+<%init>
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+my($query) = $cgi->keywords;
+$query =~ /^(\d+)$/ || die "Illegal searchnum";
+my $searchnum = $1;
+
+my $search = qsearchs('saved_search', {
+ 'searchnum' => $searchnum,
+ 'usernum' => $curuser->usernum,
+});
+my $error = $search->delete;
+
+</%init>
<TD ALIGN="right" CLASS="noprint">
- <% $opt{'download_label'} || 'Download full results' %><BR>
+ <% $opt{'download_label'} || 'Download results:' %>
% $cgi->param('_type', "$xlsname.xls" );
- as <A HREF="<% "$self_url?". $cgi->query_string %>">Excel spreadsheet</A><BR>
+ <A HREF="<% "$self_url?". $cgi->query_string %>">Spreadsheet</A> |
% $cgi->param('_type', 'csv');
- as <A HREF="<% "$self_url?". $cgi->query_string %>">CSV file</A><BR>
+ <A HREF="<% "$self_url?". $cgi->query_string %>">CSV</A> |
% if ( defined($opt{xml_elements}) ) {
% $cgi->param('_type', 'xml');
- as <A HREF="<% "$self_url?". $cgi->query_string %>">XML file</A><BR>
+ <A HREF="<% "$self_url?". $cgi->query_string %>">XML</A> |
% }
% $cgi->param('_type', 'html-print');
- as <A HREF="<% "$self_url?". $cgi->query_string %>">printable copy</A>
+ <A HREF="<% "$self_url?". $cgi->query_string %>">webpage</A>
+%# "save search" -- for now, obey disable_download and the 'Download
+%# report data' ACL, because saving a search allows the user to receive
+%# copies of the data.
+ <BR>
+%# XXX should do a check here on whether the user already has this
+%# search saved...
+ <& /elements/popup_link.html,
+ 'action' => $fsurl.'/edit/saved_search.html?title='.
+ uri_escape($opt{title}),
+ 'label' => 'Save this search',
+ 'actionlabel' => 'Save this search',
+ 'width' => 650,
+ 'height' => 500,
+ &>
</TD>
% $cgi->param('_type', "html" );
% }
&>
</%doc>
+% # if changing this, also update saved search behavior to match!
% if ( $type eq 'csv' ) {
%
<% include('search-csv.html', header=>$header, rows=>$rows, opt=>\%opt ) %>