<%args> $email => undef; $ref => undef; $method => 'view'; <%init> if ( ! &valid_email($email) ) { $m->redirect("/PrepManualGeneral.html?error=Please provide a valid email address in order to download the LDS Prep Manual."); } my $folder = "/share/avow/www/LDSPREP"; my $filename = "LDSPrep-V8.pdf"; my $file = "$folder/$filename"; &dbinsert('bl_preplog', { agent => $ENV{HTTP_USER_AGENT}, ip => $ENV{REMOTE_ADDR}, filename => $file, email => $email, referer => $ref } ); my $code = &getPrepCode(); if ( $method eq "view" ) { &sendMessage($email,$code,$ref); $r->content_type("application/pdf"); $r->headers_out->set("Content-Disposition" => "inline; filename=$filename"); open(IN, $file); while() { print; } } elsif ( $method eq "download" ) { &sendMessage($email,$code,$ref); $r->content_type("x-application/pdf"); $r->headers_out->set("Content-Disposition" => "inline; filename=$filename"); open(IN, $file); while() { print; } } elsif ( $method eq "email" ) { &sendMessage($email,$code,$ref,$file); print "An email has been sent to $email with your copy of the LDS Preparedness Manual."; } ################################################################# sub sendMessage { my $email = shift; my $code = shift; my $ref = shift; my $attach = shift; my $body =<', 'Thanks for downloading the LDS Prep Manual', $body, $attach); } ################################################################# sub getPrepCode { my $coupon; while ( ! $coupon ) { $coupon = &randomCode(); my ($result) = &query("SELECT code FROM bl_coupons WHERE code like '$coupon'"); $coupon = '' if ( $result ); } my $discount = "33"; my $discount_type = $d->quote("percent"); my $valid = 1; my $available = 1; my $type = $d->quote("one-time"); my $visible = 0; my $c = "LD$coupon"; $coupon = $d->quote($c); my $description = $d->quote("LDS Prep Manual Discount - 33\% Off"); &query("INSERT INTO bl_coupons (code,description,discount_type,valid,discount,available,type,visible,campaign) values ($coupon,$description,$discount_type,$valid,$discount,$available,$type,$visible,'PREP')"); return($c); } ################################################################# sub randomCode { my $password; my $_rand; my $password_length = 8; my @chars = split(" ","a b c d e f g h j k m n p q r s t u v w x y z 2 3 4 5 6 7 8 9"); srand; for (my $i=0; $i <= $password_length ;$i++) { $_rand = int(rand $#chars); $password .= $chars[$_rand]; } return uc($password); }