Initial commit
[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 $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 my $Userid      = ucfirst $userid;
31
32 sub PrintList {
33   my $type = shift;
34
35   my $year = substr ((scalar (localtime)), 20, 4);
36
37   my ($pattern, $domain, $comment, $hit_count, $last_hit);
38   my $sth = FindList $type;
39
40   print "\################################################################################\n";
41   print "\#\n";
42   print "\# MAPS:\t\tMail Authorization and Permission System (MAPS)\n";
43   print "\# $type.list:\t${Userid}'s $type.list file\n";
44   print "\# Exported:\t" . localtime . "\n";
45   print "\#\n";
46   print "\# Copyright 2001-" . $year . ", Andrew\@DeFaria.com, all rights reserved.\n";
47   print "\#\n";
48   print "\################################################################################\n";
49
50   while (($_, $_, $pattern, $domain, $comment, $_, $hit_count, $last_hit) = GetList $sth) {
51     last if !(defined $pattern or defined $domain);
52     $pattern    = !defined $pattern     ? "" : $pattern;
53     $domain     = !defined $domain      ? "" : $domain;
54     if ($domain eq "") {
55       print "$pattern,$comment,$hit_count,$last_hit\n";
56     } else {
57       print "$pattern\@$domain,$comment,$hit_count,$last_hit\n";
58     } # if
59   } # while
60 } # PrintList
61
62 # Main
63 SetContext $userid;
64
65 print header (-type             => "application/octet-stream",
66               -attachment       => "$type.list");
67 PrintList $type;
68 exit;