45bcce198cdee7f40a198f51c7edde6c8f38967c
[clearscm.git] / maps / bin / exportlist.cgi
1 #!/usr/bin/perl
2 ################################################################################
3 #
4 # File:         $RCSfile: exportlist.cgi,v $
5 # Revision:  $Revision: 1.1 $
6 # Description:  Export an address list
7 # Author:       Andrew@DeFaria.com
8 # Created:      Mon Jan 16 20:25:32 PST 2006
9 # Modified:     $Date: 2013/06/12 14:05:47 $
10 # Language:     perl
11 #
12 # (c) Copyright 2000-2006, Andrew@DeFaria.com, all rights reserved.
13 #
14 ################################################################################
15 use strict;
16
17 use FindBin;
18 local $0 = $FindBin::Script;
19
20 use lib $FindBin::Bin;
21
22 use MAPS;
23 use MAPSWeb;
24
25 use CGI qw/:standard *table/;
26 use CGI::Carp "fatalsToBrowser";
27
28 my $type   =   param ("type");
29 my $userid =   cookie ("MAPSUser");
30    $userid //= $ENV{USER};
31 my $Userid =   ucfirst $userid;
32
33 sub PrintList {
34   my $type = shift;
35
36   my $year = substr ((scalar (localtime)), 20, 4);
37
38   my ($pattern, $domain, $comment, $hit_count, $last_hit);
39   my $sth = FindList $type;
40
41   print "\################################################################################\n";
42   print "\#\n";
43   print "\# MAPS:\t\tMail Authorization and Permission System (MAPS)\n";
44   print "\# $type.list:\t${Userid}'s $type.list file\n";
45   print "\# Exported:\t" . localtime . "\n";
46   print "\#\n";
47   print "\# Copyright 2001-" . $year . ", Andrew\@DeFaria.com, all rights reserved.\n";
48   print "\#\n";
49   print "\################################################################################\n";
50
51   while (($_, $_, $pattern, $domain, $comment, $_, $hit_count, $last_hit) = GetList $sth) {
52     last if !(defined $pattern or defined $domain);
53
54     $pattern //= '';
55     $domain  //= '';
56
57     if ($domain eq '') {
58       print "$pattern,$comment,$hit_count,$last_hit\n";
59     } else {
60       print "$pattern\@$domain,$comment,$hit_count,$last_hit\n";
61     } # if
62   } # while
63
64   return;
65 } # PrintList
66
67 # Main
68 SetContext $userid;
69
70 print header (
71   -type        => "application/octet-stream",
72   -attachment  => "$type.list",
73 );
74
75 PrintList $type;
76
77 exit;