1package Newsletter::Html::Templ; 2 3use warnings; 4 5use strict; 6use CGI; 7use Newsletter; 8use File::Path; 9use File::Type; 10 11sub init { 12 my ($self) = @_; 13 $self->{'cgi'} = new CGI; 14} 15 16 17sub forumBegin { 18 my ($self, %param) = @_; 19 $self->_out( $self->{'cgi'}->start_form( -method=> 'GET', %param ) ); 20} 21 22 23sub forumEnd { 24 my ($self) = @_; 25 $self->_out( "</form>" ); 26} 27 28 29sub startpage { 30 my ($self) = @_; 31 32 33 34 $self->forumBegin; 35 $self->_out( qq~ 36 <table cellspacing="1" cellpadding="1" border="0" width="900" height="400"> 37 <tr> 38 <td valign="top" width="300" class="nlTdDarker"> 39 <h2>Email Lists</h2> 40 <table cellspacing="5" cellpadding="0" border="0"> 41 <tr> 42 <td> 43 <h3>Available Lists</h3> 44 <select name="pOpenList" size="10" class="nlSelect"> 45 ~); 46 foreach my $name ( $self->{'nl'}->list( get => "listnames") ) { 47 48 my $memebersCount = $self->{'nl'}->list( count => $name); 49 50 if( exists $self->{'persistent'}->{"pOpenList"} ) { 51 if( $self->{'persistent'}->{"pOpenList"} eq $name ) { 52 $self->_out( qq~ 53 <option value=$name selected>$name [$memebersCount]</option> 54 ~); 55 } else { 56 $self->_out( qq~ 57 <option value=$name>$name [$memebersCount]</option> 58 ~); 59 } 60 } else { 61 $self->_out( qq~ 62 <option value=$name>$name [$memebersCount]</option> 63 ~); 64 } 65 } 66 $self->_out( qq~ 67 </select><br> 68 <input type="radio" name="pSection" value="sendList" checked="checked">Send 69 <input type="radio" name="pSection" value="openList">Edit 70 <br><br> 71 <input type="submit" value="open list" class="nlInput"><br><br> 72 </td> 73 </tr> 74 ~); 75 $self->forumEnd; 76 $self->forumBegin; 77 $self->_out( qq~ 78 <tr> 79 <td> 80 <h3>Create a new Newsletter List</h3> 81 <b>List</b> <input type="text" name="pOpenList"> 82 <input type="hidden" name="pSection" value="openList"> 83 <input type="submit" value="create/load"><br> 84 List name is equal to the "from" field in the email! E.g. a valid list name: foo\@bar.com 85 </td> 86 </tr> 87 </table> 88 </td> 89 ~); 90 $self->forumEnd; 91 92 93 $self->forumBegin; 94 $self->_out( qq~ 95 <td valign="top" width="300" class="nlTdLighter"> 96 <h2>Email Templates</h2> 97 <table cellspacing="5" cellpadding="0" border="0"> 98 <tr> 99 <td> 100 <h3>Schema</h3> 101 <select name="pOpenSchema" size="6" class="nlSelect"> 102 ~); 103 104 my %short = ( 105 +HEADER => 'H', 106 +FOOTER => 'F' 107 ); 108 109 my %already = (); 110 111 foreach my $name ( $self->{'nl'}->template( get => { schema => "*" } ) ) { 112 next if( exists $already{ $name->{'schema'} } ); 113 next if( $name->{'schema'} eq 'undef' ); 114 115 if( exists $self->{'persistent'}->{"pOpenSchema"} ) { 116 if( $self->{'persistent'}->{"pOpenSchema"} eq $name->{'schema'}) { 117 $self->_out( qq~ 118 <option value="$name->{'schema'}" selected> 119 $name->{'schema'} 120 </option> 121 ~); 122 } else { 123 $self->_out( qq~ 124 <option value="$name->{'schema'}"> 125 $name->{'schema'} 126 </option> 127 ~); 128 } 129 } else { 130 $self->_out( qq~ 131 <option value="$name->{'schema'}"> 132 $name->{'schema'} 133 </option> 134 ~); 135 } 136 137 $already{ $name->{'schema'} } = 1; 138 } 139 140 $self->_out( qq~ 141 </select><br> 142 <input type="submit" value="load Schema" class="nlInput"><br> 143 </td> 144 </tr> 145 <tr> 146 <td> 147 <h3>All Files</h3> 148 <select name="plOpenFile" size="6" class="nlSelect" multiple> 149 ~); 150 foreach my $name ( $self->{'nl'}->template( get => {} ) ) { 151 if( exists $self->{'persistent'}->{"plOpenFile"} ) { 152 153 my $found = 0; 154 foreach my $tf ( @{ $self->{'persistent'}->{"plOpenFile"} } ) { 155 if( $tf eq $name->{'filename'}.'-is-'.$name->{'is'} ) { 156 $found = 1; 157 last; 158 } 159 } 160 161 if( $found == 1) { 162 $self->_out( qq~ 163 <option value="$name->{'filename'}-is-$name->{'is'}" selected> 164 [$name->{'filename'}] [$short{$name->{'is'}}] [$name->{'type'}] 165 </option> 166 ~); 167 } else { 168 $self->_out( qq~ 169 <option value="$name->{'filename'}-is-$name->{'is'}"> 170 [$name->{'filename'}] [$short{$name->{'is'}}] [$name->{'type'}] 171 </option> 172 ~); 173 } 174 } else { 175 $self->_out( qq~ 176 <option value="$name->{'filename'}-is-$name->{'is'}"> 177 [$name->{'filename'}] [$short{$name->{'is'}}] [$name->{'type'}] 178 </option> 179 ~); 180 } 181 } 182 183 $self->_out( qq~ 184 </select><br> 185 <input type="hidden" name="pSection" value="home"> 186 <input type="submit" value="load selected" class="nlInput"><br> 187 [H]=Header [F]=Footer<br> 188 ~); 189 $self->forumEnd; 190 191 192 $self->forumBegin; 193 $self->_out( qq~ 194 <input type="hidden" name="pOpenSchema" value=""> 195 <input type="hidden" name="plOpenFile" value=""> 196 <input type="submit" value="unload selected" class="nlInput"><br><br><br> 197 ~); 198 $self->forumEnd; 199 200 201 $self->forumBegin; 202 $self->_out( qq~ 203 <input type="hidden" name="pSection" value="editTmpl"> 204 <input type="submit" value="Edit" class="nlInput"> 205 </td> 206 </tr> 207 </table> 208 </td> 209 ~ ); 210 211 $self->forumEnd; 212 213 $self->_out( qq~ 214 <td valign="top" width="300" class="nlTdDarker"> 215 <h2>Email Archiv</h2> 216 <table cellspacing="5" cellpadding="0" border="0"> 217 <tr> 218 <td> 219 ~ ); 220 my $path = $self->{'nl'}->archiv( get => "archivPath" ); 221 my %mailByTime = $self->{'nl'}->archiv( get => "mails" ); 222 my $countMail = 8; 223 foreach my $mail ( sort {$b cmp $a} keys %mailByTime ) { 224 $mailByTime{ $mail } =~/(.+\d\d\d\d)\_(.*)/; 225 my $mailDate = $1; 226 my $linkName = $2; 227 $self->_out( 228 qq~ <a href="$path/$mailByTime{ $mail }">[$linkName]</a> 229 ~ ); 230 231 if( -e "$path/$mailByTime{ $mail }/explode/file.html") { 232 $self->_out( 233 qq~ <a href="$path/$mailByTime{ $mail }/explode/file.html">[html]</a> 234 ~ ); 235 } 236 237 if( -e "$path/$mailByTime{ $mail }/explode/file.txt") { 238 $self->_out( 239 qq~ <a href="$path/$mailByTime{ $mail }/explode/file.txt">[text]</a> 240 ~ ); 241 } 242 243 $self->_out( 244 qq~ <br>($mailDate)<br> 245 ~ ); 246 247 last if($countMail == 0); 248 $countMail--; 249 } 250 251 252 $self->_out( qq~ 253 <br><br><a href="$path">[ complete archiv ]</a> 254 </td> 255 </tr> 256 </table> 257 </td> 258 </tr> 259 </table> 260 ~ ); 261 262 if( $self->{'nl'}->error ) { 263 $self->_info( $self->{'nl'}->error ); 264 } 265 266} 267 268 269sub openList { 270 my ($self) = @_; 271 272 my $listname = $self->{'persistent'}->{"pOpenList"}; 273 274 $self->forumBegin; 275 $self->_out( qq~ 276 277 <table cellspacing="1" cellpadding="1" border="0" width="600" height="400"> 278 <tr> 279 <td valign="top" width="300" class="nlTdDarker"> 280 <h2>List Members from</h2><b>$listname</b><br> 281 search <input type="text" name="searchList"><br><br> 282 <select name="openListMembers" size="18" class="nlSelect" multiple> 283 ~); 284 285 if( $self->{'cgi'}->param("searchList") ) { 286 my $search = $self->{'cgi'}->param("searchList"); 287 foreach my $name ( $self->{'nl'}->list( get => $listname) ) { 288 last if( ref($name) ne "HASH" ); 289 next if( $name->{'mail'} !~ /$search/ ); 290 $self->_out( qq~ 291 <option>$name->{'mail'}</option> 292 ~); 293 } 294 } else { 295 foreach my $name ( $self->{'nl'}->list( get => $listname) ) { 296 last if( ref($name) ne "HASH" ); 297 $self->_out( qq~ 298 <option>$name->{'mail'}</option> 299 ~); 300 } 301 } 302 303 $self->_out( qq~ 304 </select><br> 305 <input type="radio" name="pSection" value="openList" checked="checked">search 306 <input type="radio" name="pSection" value="delFromList">Selected delete 307 <br><br> 308 <input type="submit" value="Make" class="nlInput"> 309 </td> 310 <td valign="top" class="nlTdLighter"> 311 <table cellspacing="0" cellpadding="0" border="0"> 312 <tr> 313 <td> 314 <h2>Add new members</h2> 315 ~ ); 316 $self->forumEnd; 317 318 $self->forumBegin; 319 for( my $m = 1; $m < 7; $m++ ) { 320 my $formatedNr = sprintf("%04d",$m); 321 $self->_out( qq~ 322 <input type="text" name="newMember$formatedNr" class="nlInput"><br><br> 323 ~); 324 } 325 326 $self->_out( qq~ 327 <input type="hidden" name="pSection" value="addToList"> 328 <input type="submit" value="Add to list" class="nlInput"> 329 ~ ); 330 $self->forumEnd; 331 332 if( $listname ) { 333 $self->forumBegin; 334 $self->_out( qq~ 335 <br><h2>Delete List</h2> 336 Delete:<input type="radio" name="pSection" value="openList" checked="checked">No 337 <input type="radio" name="pSection" value="deleteList">Yes<br><br> 338 <input type="hidden" name="listName" value="$listname"> 339 <input type="hidden" name="pOpenList" value=""> 340 <input type="submit" value="delete [$listname]" class="nlInput"> 341 ~ ); 342 $self->forumEnd; 343 } 344 345 $self->_out( qq~ 346 </td> 347 </tr> 348 </table> 349 </td> 350 </tr> 351 </table> 352 ~ ); 353 354 if( $self->{'nl'}->error ) { 355 $self->_info( $self->{'nl'}->error(1) ); 356 } 357 358} 359 360 361sub editTmpl { 362 my ($self) = @_; 363 364 $self->forumBegin; 365 $self->_out( qq~ 366 367 <table cellspacing="1" cellpadding="1" border="0" width="600" height="400"> 368 <tr> 369 <td valign="top" width="300" class="nlTdDarker"> 370 <h2>All Templates Files</h2> 371 Header Files<br> 372 <select name="tmplFilesHeader" size="6" class="nlSelect" multiple> 373 ~); 374 my %short = ( 375 +HEADER => 'H', 376 +FOOTER => 'F' 377 ); 378 379 380 foreach my $name ( $self->{'nl'}->template( get => {} ) ) { 381 next if( $name->{'is'} eq +FOOTER ); 382 $self->_out( qq~ 383 <option value="$name->{'filename'}"> 384 [$name->{'filename'}] [$name->{'schema'}] [$short{$name->{'is'}}] [$name->{'type'}] 385 </option> 386 ~); 387 } 388 389 $self->_out( qq~ 390 </select><br> 391 Footer Files<br> 392 <select name="tmplFilesFooter" size="6" class="nlSelect" multiple> 393 ~); 394 395 foreach my $name ( $self->{'nl'}->template( get => {} ) ) { 396 next if( $name->{'is'} eq +HEADER ); 397 $self->_out( qq~ 398 <option value="$name->{'filename'}"> 399 [$name->{'filename'}] [$name->{'schema'}] [$short{$name->{'is'}}] [$name->{'type'}] 400 </option> 401 ~); 402 } 403 404 405 $self->_out( qq~ 406 </select><br> 407 [H]=Header [F]=Footer<br><br> 408 <input type="hidden" name="pSection" value="editTmpl"> 409 <input type="radio" name="tmplFilesAction" value="open" checked="checked">open 410 <input type="radio" name="tmplFilesAction" value="delete">delete 411 <br><br> 412 <input type="submit" value="Make" class="nlInput"> 413 </td> 414 ~ ); 415 $self->forumEnd; 416 417 my $html = +HTML_TMPL; 418 my $text = +TEXT_TMPL; 419 my $header = +HEADER; 420 my $footer = +FOOTER; 421 422 $self->forumBegin( -enctype => "multipart/form-data", -method => "post" ); 423 $self->_out( qq~ 424 <td valign="top" class="nlTdLighter"> 425 <table cellspacing="0" cellpadding="0" border="0"> 426 <tr> 427 <td> 428 <h2>Add new Template File</h2> 429 <input name="tmplFileUpload" type="file" accept="text/*" class="nlInput"><br><br> 430 <input type="radio" name="pTmplFileUploadType" value=$html checked="checked">Html 431 <input type="radio" name="pTmplFileUploadType" value=$text>Text<br><br> 432 <input type="radio" name="pTmplFileUploadIs" value=$header checked="checked">Header 433 <input type="radio" name="pTmplFileUploadIs" value=$footer>Footer<br><br> 434 435 Create new Schema<br> 436 <input type="text" name="pTmplFileUploadSchemaNew" class="nlInput"><br><br> 437 Add to existing Schema<br> 438 <select name="pTmplFileUploadSchema" class="nlSelect"> 439 <option value="none">None</option> 440 ~ ); 441 my %already = (); 442 443 foreach my $name ( $self->{'nl'}->template( get => { schema => "*" } ) ) { 444 next if( exists $already{ $name->{'schema'} } ); 445 next if( $name->{'schema'} eq 'undef' ); 446 $self->_out( qq~ 447 <option value="$name->{'schema'}"> 448 $name->{'schema'} 449 </option> 450 ~); 451 $already{ $name->{'schema'} } = 1; 452 } 453 454 $self->_out( qq~ 455 </select><br><br><br> 456 <input type="hidden" name="pSection" value="tmplFileUpload"> 457 <input type="submit" value="Next" class="nlInput"> 458 </td> 459 </tr> 460 </table> 461 ~ ); 462 463 $self->forumEnd; 464 465 $self->_out( qq~ 466 </td> 467 </tr> 468 </table> 469 ~ ); 470 471} 472 473 474sub openTmpl { 475 my ($self, $path, $type) = @_; 476 477 my $nr = int(rand(10000) + 1); 478 479 $self->_out( qq~ 480 <script type="text/javascript"> 481 var win$nr = window.open('', "$path", "width=300,height=400"); 482 ~); 483 484 my $str; 485 open(FILE,"<$path") or warn "$path:$!\n"; 486 while(<FILE>) { 487 $_ =~s/'/\\'/g; 488 $_ =~s/\r//g; 489 chomp; 490 $str .= $_; 491 #$self->_out( qq~ win$nr.document.writeln('$_'); ~); 492 } 493 close(FILE); 494 495 496 $str =~s/<script.+<\/script>//gm; 497 498 $self->_out( qq~ 499 win$nr.document.write( '$str' ); 500 </script> 501 ~); 502} 503 504 505sub fileuploadTmpl { 506 my ($self) = @_; 507 508 my $fileName = $self->fileUpload("tmplFileUpload"); 509 510 $self->forumBegin( -enctype => "multipart/form-data", -method => "post" ); 511 512 $self->_out( qq~ 513 <table cellspacing="1" cellpadding="1" border="0" width="300" height="400"> 514 <tr> 515 <td valign="top" width="300" class="nlTdDarker"> 516 <h2>Add embedded Files</h2> 517 Filename:<b>$fileName</b><br> 518 Is:<b>$self->{'persistent'}->{"pTmplFileUploadIs"}</b><br> 519 Type:<b>$self->{'persistent'}->{"pTmplFileUploadType"}</b><br> 520 Schema: 521 ~); 522 523 if( $self->{'persistent'}->{"pTmplFileUploadSchemaNew"} ) { 524 $self->_out( qq~ 525 <b>$self->{'persistent'}->{"pTmplFileUploadSchemaNew"}</b></br> 526 <input type="hidden" name="tmplSchema" value="$self->{'persistent'}->{"pTmplFileUploadSchemaNew"}"> 527 ~); 528 } 529 elsif( $self->{'persistent'}->{"pTmplFileUploadSchema"} ne "none") { 530 $self->_out( qq~ 531 <b>$self->{'persistent'}->{"pTmplFileUploadSchema"}</b></br> 532 <input type="hidden" name="tmplSchema" value="$self->{'persistent'}->{"pTmplFileUploadSchema"}"> 533 ~); 534 } else { 535 $self->_out( qq~ 536 <b>None</b></br> 537 ~); 538 } 539 540 $self->_out( qq~ 541 <h3>Upload Embedded</h3> 542 ~); 543 544 for(my $a = 0; $a < 10; $a++ ) { 545 $self->_out( qq~ <input name="embFileUpload$a" type="file"><br> ~); 546 } 547 548 $self->_out( qq~ 549 <br><br> 550 <input type="hidden" name="tmplFile" value="$fileName"> 551 <input type="hidden" name="pSection" value="finishTmplFileUpload"> 552 <input type="submit" value="Create" class="nlInput"> 553 </td> 554 </tr> 555 </table> 556 ~); 557 558 $self->forumEnd; 559 560} 561 562 563sub sendList { 564 my ($self) = @_; 565 566 if(! exists $self->{'persistent'}->{"pOpenList"} ) { 567 $self->startpage; 568 $self->_info( "No Mailing List is selected!" ); 569 return; 570 } 571 572 if(! $self->{'persistent'}->{"pOpenList"} ) { 573 $self->startpage; 574 $self->_info( "No Mailing List is selected!" ); 575 return; 576 } 577 578 579 580 $self->forumBegin( -enctype => "multipart/form-data", -method => "post" ); 581 582 583 my %mailType = ( 584 'text' => 'Text', 585 'multipart/related' => 'Html', 586 'multipart/mixed' => 'Html + Text' 587 ); 588 589 $self->_out( qq~ 590 <table cellspacing="1" cellpadding="1" border="0" width="900" height="400"> 591 <tr> 592 593 <td valign="top" width="600" class="nlTdDarker"> 594 <h2>Create Email</h2> 595 <table cellspacing="5" cellpadding="1" border="0" width="100%"> 596 <tr> 597 <td width="80">Mail Type</td> 598 <td> 599 <select name="pMailType" class="nlSelectShort"> 600 ~); 601 if( exists $self->{'persistent'}->{"pMailType"} ) { 602 foreach my $key (keys %mailType ) { 603 if( $self->{'persistent'}->{"pMailType"} eq $key) { 604 $self->_out( qq~ 605 <option value="$key" selected>$mailType{$key}</option> 606 ~); 607 } else { 608 $self->_out( qq~ 609 <option value="$key">$mailType{$key}</option> 610 ~); 611 } 612 } 613 } else { 614 $self->_out( qq~ 615 <option value="text">$mailType{'text'}</option> 616 <option value="multipart/related">$mailType{'multipart/related'}</option> 617 <option value="multipart/mixed" selected>$mailType{'multipart/mixed'}</option> 618 ~); 619 } 620 621 $self->_out( qq~ 622 </select> 623 </td> 624 </tr> 625 <tr> 626 <td>Subject</td> 627 ~); 628 629 630 if( $self->{'persistent'}->{"pMailSubject"} ) { 631 $self->_out( qq~ 632 <td><input type="text" name="pMailSubject" value="$self->{'persistent'}->{"pMailSubject"}" class="nlInputLarge"></td> 633 ~); 634 } else { 635 $self->_out( qq~ <td><input type="text" name="pMailSubject" value="" class="nlInputLarge"></td> ~); 636 } 637 638 $self->_out( qq~ 639 </tr> 640 641 <tr> 642 <td valign="top">Mail from File</td> 643 <td><input name="mailFromFileHtml" type="file"> <b>Html</b> <br> 644 <input name="mailFromFileText" type="file"> <b>Text</b> </td> 645 </tr> 646 647 <tr> 648 <td valign="top">Mail Html Body</td> 649 ~); 650 651 if( $self->{'persistent'}->{"pMailBodyHtml"} ) { 652 $self->_out( qq~ 653 <td><textarea name="pMailBodyHtml" rows="10" class="nlInputLarge">$self->{'persistent'}->{"pMailBodyHtml"}</textarea></td> 654 ~); 655 } else { 656 $self->_out( qq~ <td><textarea name="pMailBodyHtml" rows="10" class="nlInputLarge"></textarea></td> ~); 657 } 658 659 660 $self->_out( qq~ 661 </tr> 662 <tr> 663 <td valign="top">Mail Text Body</td> 664 ~); 665 666 if( $self->{'persistent'}->{"pMailBodyText"} ) { 667 $self->_out( qq~ 668 <td><textarea name="pMailBodyText" rows="10" class="nlInputLarge">$self->{'persistent'}->{"pMailBodyText"}</textarea></td> 669 ~); 670 } else { 671 $self->_out( qq~ <td><textarea name="pMailBodyText" rows="10" class="nlInputLarge"></textarea></td> ~); 672 } 673 674 675 $self->_out( qq~ 676 </tr> 677 678 <tr> 679 <td valign="top">Embedded Files</td> 680 <td> 681 <input name="mailEmbFile1" type="file"><input name="mailEmbFile2" type="file"><br> 682 <input name="mailEmbFile3" type="file"><input name="mailEmbFile4" type="file"><br> 683 <input name="mailEmbFile5" type="file"><input name="mailEmbFile6" type="file"><br> 684 <input name="mailEmbFile7" type="file"><input name="mailEmbFile8" type="file"><br> 685 <input name="mailEmbFile9" type="file"><input name="mailEmbFile10" type="file"> 686 </td> 687 </tr> 688 689 <tr> 690 <td valign="top">Attachments</td> 691 <td> 692 <input name="mailAttFile1" type="file"><input name="mailAttFile2" type="file"><br> 693 <input name="mailAttFile3" type="file"><input name="mailAttFile4" type="file"> 694 </td> 695 </tr> 696 697 <tr> 698 <td colspan="2" align="center"><br> 699 <input type="hidden" name="pSection" value="sendListPreview"> 700 <input type="submit" value="Preview" class="nlInput"> 701 </td> 702 </tr> 703 </table> 704 </td> 705 <td valign="top" width="300" class="nlTdLighter"> 706 ~); 707 $self->forumEnd; 708 709 $self->sendListSetting; 710 711 $self->_out( qq~ 712 </td> 713 </tr> 714 </table> 715 ~); 716} 717 718 719sub sendListSetting { 720 my($self) = @_; 721 722 $self->forumBegin(); 723 $self->_out( qq~ 724 <h3>Settings</h3> 725 <table cellspacing="1" cellpadding="1" border="0" width="100%"> 726 <tr> 727 <td width="80"><b>Maillist</b></td> 728 <td>$self->{'persistent'}->{"pOpenList"}</td> 729 </tr> 730 ~); 731 732 if( $self->{'persistent'}->{"pOpenSchema"} ) { 733 $self->_out( qq~ 734 <tr> 735 <td width="80"><b>Schema</b></td> 736 <td>$self->{'persistent'}->{"pOpenSchema"}</td> 737 </tr> 738 <tr> 739 <td valign="top"><b>Schema Files</b></td> 740 <td> 741 ~); 742 743 744 foreach my $name ( $self->{'nl'}->template( get => { schema => $self->{'persistent'}->{"pOpenSchema"} } ) ) { 745 $self->_out( qq~ 746 $name->{'filename'}<br> 747 ~); 748 } 749 $self->_out( qq~ </td></tr> ~); 750 751 } else { 752 753 if( $self->{'persistent'}->{"plOpenFile"}->[0] ) { 754 $self->_out( qq~ 755 <tr> 756 <td valign="top"><b>Selected Files</b></td> 757 <td> 758 ~); 759 foreach my $tf ( @{ $self->{'persistent'}->{"plOpenFile"} } ) { 760 my @tmp = split(/-is-/,$tf); 761 762 $self->_out( qq~ $tmp[0]<br> ~); 763 } 764 $self->_out( qq~ </td></tr> ~); 765 } 766 767 } 768 769 $self->_out( qq~ 770 <tr><td colspan="2"><br></td></tr> 771 ~); 772 773 if( $self->{'persistent'}->{'pMailFromFileHtml'} ) { 774 $self->_out( qq~ 775 <tr> 776 <td valign="top"><b>Body Html File</b></td> 777 <td> 778 $self->{'persistent'}->{'pMailFromFileHtml'}<br> 779 <input type="hidden" name="delMailFromFileHtml" value="$self->{'persistent'}->{'pMailFromFileHtml'}"> 780 Delete: <input type="radio" name="pMailFromFileHtml" value="$self->{'persistent'}->{'pMailFromFileHtml'}" checked="checked">No 781 <input type="radio" name="pMailFromFileHtml" value="">Yes 782 </td> 783 </tr> 784 ~); 785 } 786 787 788 if( $self->{'persistent'}->{'pMailFromFileText'} ) { 789 $self->_out( qq~ 790 <tr> 791 <td valign="top"><b>Body Text File</b></td> 792 <td> 793 $self->{'persistent'}->{'pMailFromFileText'}<br> 794 <input type="hidden" name="delMailFromFileText" value="$self->{'persistent'}->{'pMailFromFileText'}"> 795 Delete: <input type="radio" name="pMailFromFileText" value="$self->{'persistent'}->{'pMailFromFileText'}" checked="checked">No 796 <input type="radio" name="pMailFromFileText" value="">Yes 797 </td> 798 </tr> 799 ~); 800 } 801 802 803 if( $self->{'persistent'}->{"pMailEmbFile1"} ) { 804 805 $self->_out( qq~ 806 <tr><td valign="top"><b>Embedded</b></td><td> 807 ~); 808 for( my $a = 1; $a < 11; $a++ ) { 809 if( $self->{'persistent'}->{"pMailEmbFile$a"} ) { 810 $self->_out( qq~ 811 $self->{'persistent'}->{"pMailEmbFile$a"} - 812 <input type="hidden" name="delMailEmbFile$a" value=$self->{'persistent'}->{"pMailEmbFile$a"}> 813 Delete <input type="radio" name="pMailEmbFile$a" value=$self->{'persistent'}->{"pMailEmbFile$a"} checked="checked">No 814 <input type="radio" name="pMailEmbFile$a" value="">Yes<br> 815 ~); 816 } 817 } 818 $self->_out( qq~ 819 </td></tr> 820 ~); 821 } 822 823 824 if( $self->{'persistent'}->{"pMailAttFile1"} ) { 825 826 $self->_out( qq~ 827 <tr><td valign="top"><b>Attachments</b></td><td> 828 ~); 829 for( my $a = 1; $a < 5; $a++ ) { 830 if( $self->{'persistent'}->{"pMailAttFile$a"} ) { 831 $self->_out( qq~ 832 $self->{'persistent'}->{"pMailAttFile$a"} - 833 <input type="hidden" name="delMailAttFile$a" value=$self->{'persistent'}->{"pMailAttFile$a"}> 834 Delete <input type="radio" name="pMailAttFile$a" value=$self->{'persistent'}->{"pMailAttFile$a"} checked="checked">No 835 <input type="radio" name="pMailAttFile$a" value="">Yes<br> 836 ~); 837 } 838 } 839 $self->_out( qq~ 840 </td></tr> 841 ~); 842 } 843 844 845 $self->_out( qq~ 846 <tr> 847 <td colspan="2" algin="center"> 848 <br> 849 ~); 850 851 if( $self->{'persistent'}->{"pSection"} eq "sendListEdit" || $self->{'persistent'}->{"pSection"} eq "sendListPreview") { 852 $self->_out( qq~ 853 <input type="radio" name="pSection" value="sendListEdit" checked="checked">Preview 854 <input type="radio" name="pSection" value="sendList">Edit <b>(Go back!)</b><br> 855 ~); 856 } else { 857 $self->_out( qq~ 858 <!-- <input type="radio" name="pSection" value="sendList" checked="checked">Edit<br> --> 859 <input type="hidden" name="pSection" value="sendList"> 860 ~); 861 } 862 863 $self->_out( qq~ 864 <br><input type="submit" value="Update" class="nlInput"> 865 </td> 866 </tr> 867 </table> 868 ~); 869 870 $self->forumEnd; 871} 872 873 874sub sendListFileupload { 875 my($self) = @_; 876 877 if( $self->{'cgi'}->param("mailFromFileHtml") ) { 878 $self->{'persistent'}->{'pMailFromFileHtml'} = $self->fileUpload("mailFromFileHtml"); 879 $self->_out( qq~ 880 <input type="hidden" name="pMailFromFileHtml" value="$self->{'persistent'}->{'pMailFromFileHtml'}"> 881 ~); 882 } 883 884 if( $self->{'cgi'}->param("mailFromFileText") ) { 885 $self->{'persistent'}->{'pMailFromFileText'} = $self->fileUpload("mailFromFileText"); 886 $self->_out( qq~ 887 <input type="hidden" name="pMailFromFileText" value="$self->{'persistent'}->{'pMailFromFileText'}"> 888 ~); 889 } 890 891 892 for( my $a = 1; $a < 11; $a++ ) { 893 if( $self->{'cgi'}->param("mailEmbFile$a") ) { 894 $self->{'persistent'}->{"pMailEmbFile$a"} = $self->fileUpload("mailEmbFile$a"); 895 $self->_out( qq~ 896 <input type="hidden" name="pMailEmbFile$a" value=$self->{'persistent'}->{"pMailEmbFile$a"}> 897 ~); 898 } 899 900 if( $self->{'cgi'}->param("mailAttFile$a") ) { 901 $self->{'persistent'}->{"pMailAttFile$a"} = $self->fileUpload("mailAttFile$a"); 902 $self->_out( qq~ 903 <input type="hidden" name="pMailAttFile$a" value=$self->{'persistent'}->{"pMailAttFile$a"}> 904 ~); 905 } 906 } 907} 908 909 910sub sendListFileDelete { 911 my($self) = @_; 912 913 if( $self->{'cgi'}->param("delMailFromFileHtml") ) { 914 my $file = $self->{'cgi'}->param("delMailFromFileHtml"); 915 $self->_out( qx "rm $self->{'uploadPath'}/$file 2>&1" ); 916 } 917 918 if( $self->{'cgi'}->param("delMailFromFileText") ) { 919 my $file = $self->{'cgi'}->param("delMailFromFileText"); 920 $self->_out( qx "rm $self->{'uploadPath'}/$file 2>&1" ); 921 } 922 923 924 for( my $a = 1; $a < 11; $a++ ) { 925 if( $self->{'cgi'}->param("delMailEmbFile$a") ) { 926 my $file = $self->{'cgi'}->param("delMailEmbFile$a"); 927 $self->_out( qx "rm $self->{'uploadPath'}/$file 2>&1" ); 928 } 929 } 930 931 for( my $a = 1; $a < 5; $a++ ) { 932 if( $self->{'cgi'}->param("delMailAttFile$a") ) { 933 my $file = $self->{'cgi'}->param("delMailAttFile$a"); 934 $self->_out( qx "rm $self->{'uploadPath'}/$file 2>&1" ); 935 } 936 } 937 938} 939 940 941sub sendListPreview { 942 my($self) = @_; 943 944 if(! $self->{'persistent'}->{"pMailSubject"} ) { 945 $self->sendList; 946 $self->_info( "Alert no mail subject!" ); 947 return; 948 } 949 950 951 952 $self->forumBegin( ); 953 $self->sendListFileupload; 954 $self->sendListBuild; 955 956 $self->_out( qq~ 957 <table cellspacing="1" cellpadding="1" border="0" width="900" height="400"> 958 <tr> 959 960 <td valign="top" width="600" class="nlTdDarker"> 961 <h2>Preview Email</h2> 962 <table cellspacing="5" cellpadding="1" border="0" width="100%"> 963 <tr> 964 <td width="80" valign="top">Subject</td> 965 <td><b>$self->{'persistent'}->{"pMailSubject"}</b></td> 966 </tr> 967 ~); 968 969 my $mailFile = $self->{'nl'}->previewMailFile( preview => 1 ); 970 971 if( $mailFile ) { 972 $self->_out( qq~ 973 <tr> 974 <td valign="top">Preview Mail</td> 975 <td valign="top"><a href="$mailFile"><b>[Open Mail]</b></a></td> 976 </tr> 977 ~); 978 979 if( $self->{'nl'}->error ) { 980 $self->_info( $self->{'nl'}->error(1) ); 981 } 982 983 my %explodeFiles; 984 985 my $headers = $self->{'nl'}->previewMailFileExplode( $mailFile ); 986 for my $part ( sort{ $a cmp $b } keys( %{ $headers } ) ) { 987 for my $k ( keys( %{ $headers->{$part} } ) ) { 988 if( $k eq 'content-disposition' ) { 989 if( exists $headers->{$part}->{'content-disposition'}->{'filename'} ) { 990 #warn $headers->{$part}->{'content-disposition'}->{'filename'}; 991 if( !exists $explodeFiles{ $headers->{$part}->{'content-disposition'}->{'filename'} } ) { 992 $explodeFiles{ $headers->{$part}->{'content-disposition'}->{'filename'} } = 1; 993 } 994 } 995 } 996 } 997 } 998 999 1000 my $explodePath = $self->{'nl'}->previewMailFile( getpath => 1 )."/explode"; 1001 1002 # remove attachment files from list! 1003 for( my $a = 1; $a < 5; $a++ ) { 1004 if( $self->{'persistent'}->{"pMailAttFile$a"} ) { 1005 if( exists $explodeFiles{ $self->{'persistent'}->{"pMailAttFile$a"} } ) { 1006 delete $explodeFiles{ $self->{'persistent'}->{"pMailAttFile$a"} }; 1007 } 1008 } 1009 } 1010 1011 foreach my $file ( sort keys %explodeFiles ) { 1012 #warn "[$file]\n"; 1013 if( $file =~ /\.html/) { 1014 $self->_out( qq~ 1015 <tr> 1016 <td valign="top">Preview HTML</td> 1017 <td class="previewTdEmail"> 1018 ~); 1019 open(FILE, "<$explodePath/$file") or die "preview html file:$explodePath/$file:$!\n"; 1020 while( defined( my $line = <FILE>) ) { 1021 $line =~ s/src="cid:/src="$explodePath\//gi; 1022 $self->_out( qq~ $line ~); 1023 } 1024 close(FILE); 1025 $self->_out( qq~ 1026 </td> 1027 </tr> 1028 ~); 1029 } 1030 1031 elsif( $file =~ /\.txt/ || $file !~ /\./ ) { 1032 $self->_out( qq~ 1033 <tr> 1034 <td valign="top">Preview Text</td> 1035 <td class="previewTdEmail"><pre> ~); 1036 1037 open(FILE, "<$explodePath/$file") or warn "preview text file:$explodePath/$file:$!\n"; 1038 while( defined( my $line = <FILE>) ) { 1039 $self->_out( qq~ $line ~); 1040 } 1041 close(FILE); 1042 $self->_out( qq~ 1043 </pre> 1044 </td> 1045 </tr> 1046 ~); 1047 } 1048 } 1049 1050 if( $self->{'nl'}->error ) { 1051 $self->_info( $self->{'nl'}->error ); 1052 } 1053 } else { 1054 if( $self->{'nl'}->error ) { 1055 $self->_info( $self->{'nl'}->error ); 1056 } 1057 } 1058 1059 1060# $self->_out( qq~ 1061# <tr> 1062# <td width="80" valign="top">Mail Source</td> 1063# <td> 1064# <textarea rows="5" class="nlInputLarge"> 1065# ~); 1066# 1067# my $sender = $self->{'nl'}->previewMail(); 1068# if( defined $sender ) { 1069# my $mailBody = $sender->body_as_string; 1070# $self->_out( qq~ $mailBody ~); 1071# } 1072# 1073# if( $self->{'nl'}->error ) { 1074# $self->_info( $self->{'nl'}->error ); 1075# } 1076# 1077# $self->_out( qq~ 1078# </textarea> 1079# </td> 1080# </tr> 1081# ~); 1082 1083 1084 $self->_out( qq~ 1085 <tr> 1086 <td></td> 1087 <td align="center"> 1088 <input type="hidden" name="pSection" value="sendListEmail"> 1089 <input type="submit" value="Send" class="nlInput"> 1090 </td> 1091 </tr> 1092 </table> 1093 </td> 1094 <td valign="top" width="300" class="nlTdLighter"> 1095 ~); 1096 1097 $self->forumEnd; 1098 1099 $self->sendListSetting; 1100 $self->_out( qq~ 1101 </td> 1102 </tr> 1103 </table> 1104 ~); 1105} 1106 1107 1108sub sendListBuild { 1109 my($self) = @_; 1110 1111 # Set Sender type 1112 $self->{'nl'}->sender( 1113 type => $self->{'persistent'}->{"pMailType"} 1114 ); 1115 1116 1117 # Load Footer / Header 1118 if( $self->{'persistent'}->{"pOpenSchema"} ) { 1119 $self->{'nl'}->template( 1120 use => { 1121 schema => $self->{'persistent'}->{"pOpenSchema"} 1122 } 1123 ); 1124 } else { 1125 1126 if( $self->{'persistent'}->{"plOpenFile"}->[0] ) { 1127 foreach my $tf ( @{ $self->{'persistent'}->{"plOpenFile"} } ) { 1128 my @tmp = split(/-is-/,$tf); 1129 1130 $self->{'nl'}->template( 1131 use => { 1132 is => $tmp[1], 1133 filename => $tmp[0] 1134 } 1135 ); 1136 } 1137 } 1138 } 1139 1140 # Load Subject 1141 if( $self->{'persistent'}->{"pMailSubject"} ) { 1142 $self->{'nl'}->body( subject => $self->{'persistent'}->{"pMailSubject"} ); 1143 } 1144 1145 1146 # Load Body Html 1147 my @embHtml = (); 1148 for( my $a = 1; $a < 11; $a++ ) { 1149 if( $self->{'persistent'}->{"pMailEmbFile$a"} ) { 1150 push( @embHtml, $self->{'uploadPath'}.'/'.$self->{'persistent'}->{"pMailEmbFile$a"} ); 1151 } 1152 } 1153 1154 if( exists $self->{'persistent'}->{'pMailFromFileHtml'} ) { 1155 if( $self->{'persistent'}->{'pMailFromFileHtml'} ) { 1156 $self->{'nl'}->body( 1157 file => { 1158 path => $self->{'uploadPath'}.'/'.$self->{'persistent'}->{'pMailFromFileHtml'}, 1159 type => 'html', 1160 embedded => \@embHtml, 1161 } 1162 ); 1163 } else { 1164 $self->{'nl'}->body( 1165 data => { 1166 value => $self->{'persistent'}->{'pMailBodyHtml'}, 1167 type => 'html', 1168 embedded => \@embHtml, 1169 } 1170 ); 1171 } 1172 } else { 1173 $self->{'nl'}->body( 1174 data => { 1175 value => $self->{'persistent'}->{'pMailBodyHtml'}, 1176 type => 'html', 1177 embedded => \@embHtml, 1178 } 1179 ); 1180 } 1181 1182 1183 # Load Body Text 1184 if( exists $self->{'persistent'}->{'pMailFromFileText'} ) { 1185 if( $self->{'persistent'}->{'pMailFromFileText'} ) { 1186 $self->{'nl'}->body( 1187 file => { 1188 path => $self->{'uploadPath'}.'/'.$self->{'persistent'}->{'pMailFromFileText'}, 1189 type => 'text', 1190 } 1191 ); 1192 } else { 1193 $self->{'nl'}->body( 1194 data => { 1195 value => $self->{'persistent'}->{'pMailBodyText'}, 1196 type => 'text', 1197 } 1198 ); 1199 } 1200 } else { 1201 $self->{'nl'}->body( 1202 data => { 1203 value => $self->{'persistent'}->{'pMailBodyText'}, 1204 type => 'text', 1205 } 1206 ); 1207 } 1208 1209 1210 # add attachments 1211 my $msg = $self->{'nl'}->sender; 1212 if( $msg ) { 1213 my $ft = File::Type->new(); 1214 1215 for( my $a = 1; $a < 5; $a++ ) { 1216 if( $self->{'persistent'}->{"pMailAttFile$a"} ) { 1217 1218 # 'file' and 'file.html' not allowed 1219 if( $self->{'persistent'}->{"pMailAttFile$a"} =~ /file/ || 1220 $self->{'persistent'}->{"pMailAttFile$a"} =~ /file\.html/ 1221 ) { 1222 next; 1223 $self->_info( "'file' and 'file.html' not allowed as attachment filenames\n" ); 1224 } 1225 1226 $msg->attach( 1227 Type => $ft->checktype_filename( $self->{'uploadPath'}.'/'.$self->{'persistent'}->{"pMailAttFile$a"} ), 1228 Path => $self->{'uploadPath'}.'/'.$self->{'persistent'}->{"pMailAttFile$a"} 1229 ); 1230 warn "Path => ".$self->{'uploadPath'}.'/'.$self->{'persistent'}->{"pMailAttFile$a"}; 1231 } 1232 } 1233 } 1234 1235 if( $self->{'nl'}->error ) { 1236 $self->_info( $self->{'nl'}->error ); 1237 } 1238} 1239 1240 1241 1242 1243sub sendListMail { 1244 my($self) = @_; 1245 1246 1247 $self->sendListBuild; 1248 1249 # add attachments 1250# my $msg = $self->{'nl'}->sender; 1251# if( $msg ) { 1252# for( my $a = 1; $a < 5; $a++ ) { 1253# if( $self->{'persistent'}->{"pMailAttFile$a"} ) { 1254# 1255# # 'file' and 'file.html' not allowed 1256# if( $self->{'persistent'}->{"pMailAttFile$a"} =~ /file/ || 1257# $self->{'persistent'}->{"pMailAttFile$a"} =~ /file\.html/ 1258# ) { 1259# next; 1260# $self->_info( "'file' and 'file.html' not allowed as attachment filenames\n" ); 1261# } 1262# 1263# $msg->attach( 1264# Path => $self->{'uploadPath'}.'/'.$self->{'persistent'}->{"pMailAttFile$a"} 1265# ); 1266# warn "Path => ".$self->{'uploadPath'}.'/'.$self->{'persistent'}->{"pMailAttFile$a"}; 1267# } 1268# } 1269# } 1270 1271 1272 # open mail list 1273 $self->{'nl'}->list( 1274 list => { name => $self->{'persistent'}->{"pOpenList"} } 1275 ); 1276 1277 1278 if( $self->{'nl'}->error ) { 1279 $self->_info( $self->{'nl'}->error ); 1280 } 1281 1282 # send !!! 1283 print qq~ <pre>~; 1284 $self->{'nl'}->send(1); 1285 print qq~ </pre>~; 1286 1287 1288 if( $self->{'nl'}->error ) { 1289 $self->_info( $self->{'nl'}->error ); 1290 } 1291 1292 # copy to archiv 1293 $self->{'nl'}->archiv( save => 1 ); 1294 1295 if( $self->{'nl'}->error ) { 1296 $self->_info( $self->{'nl'}->error ); 1297 } 1298 1299 # cleanup upload files 1300 $self->sendListClean(); 1301 1302} 1303 1304 1305sub sendListClean { 1306 my($self) = @_; 1307 1308 rmtree $self->{'uploadPath'}; 1309} 1310 1311 1312 1313=head1 NAME 1314 1315Newsletter::Html::Templ - Html parts! 1316 1317=head1 VERSION 1318 1319Version 0.01 1320 1321=cut 1322 1323our $VERSION = '0.01'; 1324 1325=head1 SYNOPSIS 1326 1327The html parts for the newsletter module 1328 1329Perhaps a little code snippet. 1330 1331 use Newsletter::Html::Templ; 1332 1333 my $foo = Newsletter::Html::Templ->new(); 1334 ... 1335 1336=head1 EXPORT 1337 1338A list of functions that can be exported. You can delete this section 1339if you don't export anything, such as for a purely object-oriented module. 1340 1341=head1 FUNCTIONS 1342 1343=head1 AUTHOR 1344 1345Dominik Hochreiter, C<< <dominik at soft.uni-linz.ac.at> >> 1346 1347=head1 BUGS 1348 1349Please report any bugs or feature requests to 1350C<bug-newsletter-html-templ at rt.cpan.org>, or through the web interface at 1351L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Newsletter>. 1352I will be notified, and then you'll automatically be notified of progress on 1353your bug as I make changes. 1354 1355=head1 SUPPORT 1356 1357You can find documentation for this module with the perldoc command. 1358 1359 perldoc Newsletter 1360 1361You can also look for information at: 1362 1363=over 4 1364 1365=item * AnnoCPAN: Annotated CPAN documentation 1366 1367L<http://annocpan.org/dist/Newsletter> 1368 1369=item * CPAN Ratings 1370 1371L<http://cpanratings.perl.org/d/Newsletter> 1372 1373=item * RT: CPAN's request tracker 1374 1375L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Newsletter> 1376 1377=item * Search CPAN 1378 1379L<http://search.cpan.org/dist/Newsletter> 1380 1381=back 1382 1383=head1 ACKNOWLEDGEMENTS 1384 1385=head1 COPYRIGHT & LICENSE 1386 1387Copyright 2006 Dominik Hochreiter, all rights reserved. 1388 1389This program is free software; you can redistribute it and/or modify it 1390under the same terms as Perl itself. 1391 1392=cut 1393 13941; # End of Newsletter::Html::Templ 1395