fix A/R report
[freeside.git] / httemplate / misc / xmlhttp-template_image.cgi
1 <%doc>
2 Returns JSON encoded array of objects with details about FS::template_image
3 objects.  Attributes in each returned object are imgnum, name, and src.
4
5 Accepts the following options:
6
7 imgnum - only return object for this imgnum
8
9 no_src - do not include the src field
10
11 </%doc>
12 <% encode_json(\@result) %>\
13 <%init>
14 use FS::template_image;
15
16 my $curuser = $FS::CurrentUser::CurrentUser;
17
18 die "access denied"
19   unless $curuser->access_right([ 'View templates', 'View global templates',
20                                   'Edit templates', 'Edit global templates', ]);
21
22 my %arg = $cgi->param('arg');
23
24 my $search = {
25   'table' => 'template_image',
26   'hashref' => {},
27 };
28
29 my $imgnum = $arg{'imgnum'} || '';
30 die "Bad imgnum" unless $imgnum =~ /^\d*$/;
31 $search->{'hashref'}->{'imgnum'} = $imgnum if $imgnum;
32
33 $search->{'select'} = 'imgnum, name' if $arg{'no_src'};
34
35 $search->{'extra_sql'} = ($imgnum ? ' AND ' : ' WHERE ')
36                        . $curuser->agentnums_sql(
37                            'null_right' => ['View global templates','Edit global templates']
38                          );
39
40 my @images = qsearch($search); #needs agent virtualization
41
42 my @result = map { +{
43   'imgnum' => $_->imgnum,
44   'name'   => $_->name,
45   'src'    => $arg{'no_src'} ? '' : $_->src,
46 } } @images;
47
48 </%init>