@_UI_STD_INIT_@ [value name=mv_data_table set=userdb hide=1] [if-mm !tables] [set ui_error] [L]Not authorized for customer administration. Contact administrator?[/L] [/set] [bounce page="__UI_BASE__/error"] [/if-mm] [set ui_class]Customers[/set] [set page_title][L]Customer mailing[/L][/set] [set help_name]customer.mailing[/set] [set page_perm]mailing[/set] @_UI_STD_HEAD_@
[calc] my @actions = qw/ direct_send download_batch show_email /; my $die = sub { my $msg = shift; $msg = errmsg($msg, @_); for(@actions) { delete $CGI->{$_}; } return "

> $msg

"; }; if($CGI->{mv_action} and ! $Values->{mail_to}) { return $die->("[L]Reset to default.[/L]"); } if($Values->{mail_subject} !~ /\w/) { return $die->("[L]No subject, cannot send.[/L]"); } elsif ($Values->{mail_template} !~ /\w+.*\w+.*\n.*\w+/s) { return $die->("[L]No suitable message to send.[/L]"); } return; [/calc] [form-session-id] [perl tables="userdb __UI_META_TABLE__"] $Config->{NoSearch} = ''; my $ary = $Db{userdb}->query("select distinct mail_list from userdb"); my @lists; for(@$ary) { push @lists, split /[\s,\0]+/, $_->[0]; } my %seen; @lists = sort @lists; @lists = grep !$seen{$_}++ && /\S/, @lists; my $meta = $Tag->meta_record('userdb::mail_list'); my $options; if($meta) { $options = $meta->{options}; } my @out; $options = get_option_hash($options); for(@lists) { next if exists $options->{$_}; $options->{$_} = "$_ (???)"; $options->{$_} =~ s/,/)/g; } @lists = sort { $options->{$a} cmp $options->{$b} } @lists; for(@lists) { push @out, "$_=$options->{$_}"; } $Scratch->{mail_list_options} = join ",", @out; return; [/perl] [if cgi hide_textarea] [if cgi show_close] [/if] [else] [calc] $Values->{mail_to} ||= $Variable->{MAILING_TO} || "{FNAME} {LNAME} <{EMAIL}>"; $Values->{mail_from} ||= $Variable->{MAILING_FROM} || q{__COMPANY__ <__EMAIL_SERVICE__>}; my $burl = $Config->{VendURL}; my $unsub = "{MV_BASE_URL}?list={MV_LIST}&what={MV_EMAIL}&who={USERNAME}"; $Values->{mail_template} =~ s/\s+$//; $Values->{mail_template} =~ s/\r\n/\n/g; $Values->{mail_template} ||= $Variable->{MAILING_TEMPLATE} || qq{Dear {FNAME} {LNAME}, Best Regards, __COMPANY__ Customer Service Note: You subscribed to this list ({MV_LIST}) when you placed an order at our web site at $burl. You can unsubscribe at any time with the URL: $unsub Thanks for your business! }; return; [/calc]

[L]From:[/L] |
[L]To:[/L] |
[L]Subject:[/L] |
[L]Reply-To:[/L] | [L](blank is same as From)[/L]
[value name=mail_template filter=entities keep=1] [L]Mailing List[/L]: [display default="[cgi target_list]" name=target_list type=select options="[scratch mail_list_options]"]

[/else] [/if]
[if cgi mail_template][/if] [if !cgi produce]
[tmpn tmp_seen][/tmpn][tmpn tmp_users][/tmpn] [loop search=" fi=userdb st=db co=yes op=rm ml=1000 tf=email sf=email se=@ sf=mail_list se=[cgi target_list] rf=username,fname,lname,company,email,mail_list "] [loop-sub sent_check] $tmp_url ||= $Tag->area({ href => '__UI_BASE__/customer_view', form => "view=1", }); $tmp_struct ||= $Scratch->{sent_ids} ||= {}; my $stuff = shift; my $row = shift; my $list = $CGI->{target_list}; my $user = $row->[0]; my $email = $row->[4]; $email = lc $email; $email =~ s/^\s+//; $email =~ s/\s+$//; if($user_done{$email}++) { Log("Weeded duplicate $email, user $user."); return; } if (my $s = $tmp_struct->{$user}) { return if $s =~ /\s$list\s/; } $Scratch->{tmp_seen}++; if(! $CGI->{show_members}) { $uary = $Scratch->{tmp_users} ||= []; push @$uary, $user; return; } my $url = $tmp_url . '&' . "customer=$user"; $stuff =~ s/HREF=""/href="$url"/; return $stuff; [/loop-sub][loop-exec sent_check] [loop-param email] -- [loop-param fname] [loop-param lname][if-loop-param company], [loop-param company][/if-loop-param] ([loop-code])
[/loop-exec][/loop] [if scratch tmp_users] {tmp_users}}; [/calc]" type=hidden> [/if] [if !scratch tmp_seen]

> You have already sent email to all users on this list. You should not send more than one message per day at the very top! Once a month is more appropriate. Imagine if someone sent you mail every day!

> You will have to turn off your browser or cancel your session to send mail to this list again. And it be on your head...

[/if]
[if value show_members]

[L]Check all[/L] [L]Uncheck all[/L]

[else] [msg arg.0="[scratch tmp_seen]"]%s users selected.[/msg] [/else] [/if]

[if type=value term=mv_search_match_count op=">" compare="[either]__MAILING_MAX_DIRECT__[or]50[/either]" ][L](too many matches to send directly)[/L] [else] [/else] [/if]

[elsif cgi produce]
[perl] my @list = grep /\S/, split /[\s,\0]+/, $CGI->{produce}; my @messages; my @out; my $list = $CGI->{target_list}; my %done; my $opt = { table => 'userdb', hash => 1}; my $body = $Values->{mail_template}; $body =~ s/\r\n/\n/g; $body =~ s/\r/\n/g; $template = "From: $Values->{mail_from}\n"; $template .= "To: $Values->{mail_to}\n"; $template .= "Subject: $Values->{mail_subject}\n"; $template .= "Reply-To: $Values->{mail_reply}\n" if $Values->{mail_reply} =~ /\w\w+/; $template .= "\n$body"; my $burl = $Variable->{MAILING_UNSUB} || "$Config->{VendURL}/query/unsub"; for my $user (@list) { $opt->{key} = $user; my $record = $Tag->data($opt); next unless $record; next unless $record->{email} =~ /\S/; next if $done{$record->{email}}++; $record->{mv_base_url} = $burl; $record->{mv_email} = $Tag->filter('urlencode', $record->{email}); $record->{mv_list} = $list; my $msg = $Tag->uc_attr_list($record, $template); $msg =~ s/\s*$/\n/; push @messages, [ $user, $msg ]; } my $out; return if ! @messages; if($CGI->{direct_send}) { my $max = $Variable->{MAIL_MAX_DIRECT} || 5; if( scalar(@out) > $max ) { my $msg = errmsg("Too many addresses for direct send, max %s!", $max); return "

> $max

"; } my $s = $Scratch->{sent_ids} ||= {}; for(@messages) { my ($u, $b) = @$_; if( $s->{$u} =~ /\s$list\s/) { push @out, errmsg("Already sent %s email to %s", $list, $u); } else { my $msg = errmsg("Send to %s: ", $u); my $opt = { raw => 1, body => $b }; if( $Tag->email_raw({}, $b) ) { $msg .= errmsg('success'); $s->{$u} ||= ''; $s->{$u} .= " $list "; } else { $msg .= errmsg('FAILED'); } push @out, $msg; } } $out = join "
\n", @out; $Tag->log({ type => 'text', file => 'logs/mailing', body => join("\n", $Tag->time({format => '%c'}), "Sent mailing to list '$list':\n", $template, "\nResults:\n", @out, '####END MAILING ####', ''), }); } elsif($CGI->{download_batch}) { @out = map { $_->[1] } @messages; $out = "#!/bin/sh\n\ncat <{SendMailProgram} -t\n"; $out .= join "EOF\n\ncat <{SendMailProgram} -t\n", @out; $out .= "EOF\n\n"; $Tag->deliver( { body => \$out } ); $Tag->tmpn('delivered_mail_batch'); $Scratch->{delivered_mail_batch} = 1; return; } else { @out = map { $_->[1] } @messages; my $divintro = q{

    };
    			my $divend = qq{

\n}; $out = $divintro; $out .= join "$divend$divintro", @out; $out .= $divend; } return $out; [/perl]
[/elsif] [/if] [if cgi show_close]

[/if]

@_UI_STD_FOOTER_@