diff options
author | Ivan Kohler <ivan@freeside.biz> | 2015-10-13 10:10:40 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2015-10-13 10:10:40 -0700 |
commit | 2b2dd969f3c18751afc583ad1e836ab8e6f73b5d (patch) | |
tree | 72ad19092f9d3a5118add9a55067b8a97c168f46 /httemplate/misc/xmlhttp-template_image.cgi | |
parent | d31d59c63c8f4dfd52ca19a02ffcf32fcf49f497 (diff) | |
parent | cd468ecb9a321ca96254b7204f6dc193b11cd903 (diff) |
Merge branch 'master' of git.freeside.biz:/home/git/freeside
Diffstat (limited to 'httemplate/misc/xmlhttp-template_image.cgi')
-rw-r--r-- | httemplate/misc/xmlhttp-template_image.cgi | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/httemplate/misc/xmlhttp-template_image.cgi b/httemplate/misc/xmlhttp-template_image.cgi new file mode 100644 index 000000000..a8c50edf0 --- /dev/null +++ b/httemplate/misc/xmlhttp-template_image.cgi @@ -0,0 +1,48 @@ +<%doc> +Returns JSON encoded array of objects with details about FS::template_image +objects. Attributes in each returned object are imgnum, name, and src. + +Accepts the following options: + +imgnum - only return object for this imgnum + +no_src - do not include the src field + +</%doc> +<% encode_json(\@result) %>\ +<%init> +use FS::template_image; + +my $curuser = $FS::CurrentUser::CurrentUser; + +die "access denied" + unless $curuser->access_right([ 'View templates', 'View global templates', + 'Edit templates', 'Edit global templates', ]); + +my %arg = $cgi->param('arg'); + +my $search = { + 'table' => 'template_image', + 'hashref' => {}, +}; + +my $imgnum = $arg{'imgnum'} || ''; +die "Bad imgnum" unless $imgnum =~ /^\d*$/; +$search->{'hashref'}->{'imgnum'} = $imgnum if $imgnum; + +$search->{'select'} = 'imgnum, name' if $arg{'no_src'}; + +$search->{'extra_sql'} = ($imgnum ? ' AND ' : ' WHERE ') + . $curuser->agentnums_sql( + 'null_right' => ['View global templates','Edit global templates'] + ); + +my @images = qsearch($search); #needs agent virtualization + +my @result = map { +{ + 'imgnum' => $_->imgnum, + 'name' => $_->name, + 'src' => $arg{'no_src'} ? '' : $_->src, +} } @images; + +</%init> |