1#!./tclsh 2# $Id: filtedit.tcl 1204 2009-02-02 19:54:23Z hubert@u.washington.edu $ 3# ======================================================================== 4# Copyright 2006 University of Washington 5# 6# Licensed under the Apache License, Version 2.0 (the "License"); 7# you may not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# ======================================================================== 13 14# filtedit.tcl 15# 16# Purpose: CGI script to generate html form editing of a single filter 17 18# 19# include common filter info 20source filter.tcl 21 22# 23# Input: 24set filtedit_vars { 25 {cid "No cid"} 26 {oncancel "No oncancel"} 27 {onfiltcancel {} ""} 28 {fno {} -1} 29 {add {} 0} 30 {filterrtext {} ""} 31 {filtedit_score {} 0} 32 {filtedit_indexcolor {} 0} 33 {fg {} ""} 34 {bg {} ""} 35} 36 37# Output: 38# 39 40## read vars 41foreach item $filtedit_vars { 42 if {[catch {cgi_import [lindex $item 0].x}]} { 43 if {[catch {eval WPImport $item} result]} { 44 if {[llength $item] > 2} { 45 set [lindex $item 0] [lindex $item 2] 46 } else { 47 error [list _action [lindex $item 1] $result] 48 } 49 } 50 } else { 51 set [lindex $item 0] 1 52 } 53} 54 55if {$filtedit_score} { 56 set filttype score 57 set filttypename Score 58} elseif {$filtedit_indexcolor} { 59 set filttype indexcolor 60 set filttypename "Index Color" 61} else { 62 set filttype filt 63 set filttypename Filter 64} 65 66if {[info exists filtedit_add]} { 67 set add $filtedit_add 68} 69 70if {[info exists filtedit_fno]} { 71 set fno $filtedit_fno 72} 73 74if {[info exists filtedit_onfiltcancel]} { 75 set onfiltcancel $filtedit_onfiltcancel 76} 77 78if {[info exists filtedit_filterrtext]} { 79 set filterrtext $filtedit_filterrtext 80} 81 82set filterr 0 83if {[string length $filterrtext]} { 84 set filterr 1 85} 86 87set filtedit_menu { 88 { 89 {} 90 { 91 { 92 # * * * * OK * * * * 93 #cgi_image_button filt_save=[WPimg but_save] border=0 alt="Save Config" 94 cgi_submit_button "${filttype}_save=Save" 95 } 96 } 97 } 98 { 99 {} 100 { 101 { 102 # * * * * CANCEL * * * * 103 cgi_submit_button filtcancel=Cancel 104 } 105 } 106 } 107 { 108 {} 109 { 110 { 111 # * * * * HELP * * * * 112 cgi_submit_button "${filttype}help=Get Help" 113 } 114 } 115 } 116} 117 118 119proc wpGetVarAs {_var _varas} { 120 upvar $_varas varas 121 122 if {[catch {cgi_import_as $_var varas} result]} { 123 set varas "" 124 } 125} 126 127proc freetext_cell {intro varname varval} { 128 cgi_table_data align=right { 129 cgi_puts [cgi_bold "$intro :[cgi_nbspace][cgi_nbspace]"] 130 } 131 cgi_table_data align=left { 132 cgi_text "$varname=$varval" "style=margin:2" 133 } 134} 135 136 137array set idvarnames $pattern_id 138array set idvarvals {} 139array set patvarnames $pattern_fields 140array set patvarvals {} 141array set actionvarnames $pattern_actions 142array set colvarnames $pattern_colors 143array set scorevarnames $pattern_scores 144 145array set actionvals {} 146 147cgi_http_head { 148 cgi_content_type 149 cgi_pragma no-cache 150} 151 152cgi_html { 153 cgi_head { 154 WPStdHtmlHdr "$filttypename List Configuration" 155 WPStyleSheets 156 } 157 158 if {$add == 0} { 159 if {$filtedit_score} { 160 set actions $pattern_scores 161 set fext [WPCmd PEConfig scoreextended $fno] 162 } elseif {$filtedit_indexcolor} { 163 set actions $pattern_colors 164 set fext [WPCmd PEConfig indexcolorextended $fno] 165 } else { 166 set actions $pattern_actions 167 set fext [WPCmd PEConfig filtextended $fno] 168 } 169 170 foreach fvar $fext { 171 switch -- [lindex $fvar 0] { 172 id { 173 foreach idvar [lindex $fvar 1] { 174 set idname [lindex $idvar 0] 175 if {[info exists idvarnames($idname)]} { 176 set idvarvals($idname) [lindex $idvar 1] 177 } 178 } 179 } 180 pattern { 181 foreach patternvar [lindex $fvar 1] { 182 set patname [lindex $patternvar 0] 183 if {[info exists patvarnames($patname)]} { 184 set patvarvals($patname) [lindex $patternvar 1] 185 } 186 } 187 } 188 filtaction { 189 foreach actionvar [lindex $fvar 1] { 190 set actionname [lindex $actionvar 0] 191 if {[info exists actionvarnames($actionname)]} { 192 set actionvals($actionname) [lindex $actionvar 1] 193 } 194 } 195 } 196 indexcolors { 197 foreach colvar [lindex $fvar 1] { 198 set colname [lindex $colvar 0] 199 if {[info exists colvarnames($colname)]} { 200 set actionvals($colname) [lindex $colvar 1] 201 } 202 } 203 } 204 scores { 205 foreach colvar [lindex $fvar 1] { 206 set actionvals([lindex $colvar 0]) [lindex $colvar 1] 207 } 208 } 209 } 210 } 211 } else { 212 if {$filtedit_score} { 213 set actions $pattern_scores 214 } elseif {$filtedit_indexcolor} { 215 set actions $pattern_colors 216 } else { 217 set actions $pattern_actions 218 } 219 } 220 221 cgi_body BGCOLOR="$_wp(bordercolor)" { 222 cgi_form $_wp(appdir)/$_wp(ui1dir)/wp method=get name=filtconfig target=_top { 223 cgi_text "page=conf_process" type=hidden notab 224 cgi_text "cp_op=${filttype}config" type=hidden notab 225 cgi_text "cid=$cid" type=hidden notab 226 cgi_text "oncancel=$oncancel" type=hidden notab 227 cgi_table border=0 cellspacing=0 cellpadding=0 width="100%" height="100%" { 228 cgi_table_row { 229 # 230 # next comes the menu down the left side 231 # 232 eval { 233 cgi_table_data $_wp(menuargs) rowspan=4 { 234 WPTFCommandMenu filtedit_menu {} 235 } 236 } 237 238 # 239 # In main body of screen goes confg list 240 # 241 cgi_table_data valign=top width="100%" class=dialog { 242 if {[string length $onfiltcancel]} { 243 cgi_text "onfiltcancel=$onfiltcancel" type=hidden notab 244 } 245 cgi_text "fno=$fno" type=hidden notab 246 cgi_text "subop=[expr {$add ? "add" : "edit"}]" type=hidden notab 247 cgi_table border=0 cellspacing=0 cellpadding=0 { 248 # pattern title 249 cgi_table_row { 250 cgi_table_data { 251 cgi_puts "<fieldset>" 252 cgi_puts "<legend style=\"font-weight:bold;font-size:bigger\">$filttypename Identification</legend>" 253 cgi_table { 254 foreach {idname idtype} $pattern_id { 255 if {[info exists idvarvals($idname)]} { 256 set val $idvarvals($idname) 257 } else { 258 wpGetVarAs $idname val 259 } 260 cgi_table_row { 261 freetext_cell "$filttypename [lindex $idtype 0]" $idname $val 262 } 263 } 264 } 265 cgi_puts "</fieldset>" 266 } 267 } 268 269 # Folder Conditions 270 wpGetVarAs folder folder 271 wpGetVarAs ftype ftype 272 cgi_table_row { 273 cgi_table_data colspan=2 { 274 cgi_puts "<fieldset>" 275 cgi_puts "<legend style=\"font-weight:bold;font-size:bigger\">Folder Conditions</legend>" 276 cgi_table { 277 cgi_table_row { 278 cgi_table_data align=right valign=top { 279 cgi_puts [cgi_bold "Current Folder Type :"] 280 } 281 cgi_table_data align=left { 282 cgi_table border=0 cellpadding=0 cellspacing=0 { 283 cgi_table_row { 284 cgi_table_data width=50 { 285 cgi_puts "[cgi_nbspace]" 286 } 287 cgi_table_data { 288 cgi_table border=0 cellpadding=0 cellspacing=0 { 289 foreach type {any news email specific} { 290 cgi_table_row { 291 cgi_table_data { 292 cgi_radio_button ftype=$type [expr {[string compare $ftype $type] == 0 ? "checked" : ""}] style="background-color:$_wp(dialogcolor)" 293 } 294 cgi_table_data { 295 switch -- $type { 296 any - 297 news - 298 email { 299 cgi_puts "[string toupper [string range $type 0 0]][string range $type 1 end]" 300 } 301 specific { 302 cgi_puts "Specific Folder List :" 303 cgi_text "folder=$folder" 304 } 305 } 306 } 307 } 308 } 309 } 310 } 311 } 312 } 313 } 314 } 315 } 316 cgi_puts "</fieldset>" 317 } 318 } 319 320 # Message Conditions 321 322 cgi_table_row { 323 cgi_table_data { 324 cgi_puts "<fieldset>" 325 cgi_puts "<legend style=\"font-weight:bold;font-size:bigger\">Message Conditions</legend>" 326 cgi_table border=0 { 327 foreach {pvarname parvarval} $pattern_fields { 328 329 if {$filterr} { 330 wpGetVarAs $pvarname pvarval 331 } elseif {[info exists patvarvals($pvarname)]} { 332 set pvarval $patvarvals($pvarname) 333 } else { 334 set pvarval "" 335 } 336 337 cgi_table_row { 338 switch -- [lindex $patvarnames($pvarname) 1] { 339 freetext { 340 freetext_cell [lindex $patvarnames($pvarname) 0] $pvarname $pvarval 341 } 342 status { 343 cgi_table_data align=right { 344 cgi_puts "[cgi_bold [lindex $patvarnames($pvarname) 0]] :[cgi_nbspace][cgi_nbspace]" 345 } 346 cgi_table_data align=left { 347 cgi_select $pvarname "style=margin:2" { 348 cgi_option "Don't care, always matches" "value=either" 349 cgi_option "Yes" "value=yes" [expr {[string compare $pvarval "yes"] == 0 ? "selected" : ""}] 350 cgi_option "No" "value=no" [expr {[string compare $pvarval "no"] == 0 ? "selected" : ""}] 351 } 352 } 353 } 354 addrbook { 355 cgi_table_data align=right valign=top { 356 cgi_puts "[cgi_bold [lindex $patvarnames($pvarname) 0]] :[cgi_nbspace][cgi_nbspace]" 357 } 358 cgi_table_data align=left { 359 cgi_select addrbook "style=margin:2" { 360 cgi_option "Don't care, always matches" "value=either" [expr {[string compare $pvarval "either"] == 0 ? "selected" : ""}] 361 cgi_option "Yes, in any address book" "value=yes" [expr {[string compare $pvarval "yes"] == 0 ? "selected" : ""}] 362 cgi_option "No, not in any addressbook" "value=no" [expr {[string compare $pvarval "no"] == 0 ? "selected" : ""}] 363 cgi_option "Yes, in specific address book" "value=yesspecific" [expr {[string compare $pvarval "yesspecific"] == 0 ? "selected" : ""}] 364 cgi_option "No, not in specific address book" "value=nospecific" [expr {[string compare $pvarval "nospecific"] == 0 ? "selected" : ""}] 365 } 366 cgi_br 367 cgi_puts "Specific Addressbook:" 368 cgi_text "specificabook=" "style=margin:4" 369 cgi_br 370 cgi_puts "Types of addresses to check for in address book:" 371 cgi_table style=margin-left:30 { 372 cgi_table_row { 373 cgi_table_data nowrap { 374 cgi_checkbox abookfrom [expr {[string compare $pvarval "no"] == 0 ? "selected" : ""}] 375 cgi_puts "From" 376 } 377 378 cgi_table_data nowrap { 379 cgi_checkbox abookreplyto 380 cgi_puts "Reply-To" 381 } 382 } 383 cgi_table_row { 384 cgi_table_data nowrap { 385 cgi_checkbox abooksender 386 cgi_puts "Sender" 387 } 388 389 cgi_table_data nowrap { 390 cgi_checkbox abookto 391 cgi_puts "To" 392 } 393 } 394 cgi_table_row { 395 cgi_table_data nowrap { 396 cgi_checkbox abookcc 397 cgi_puts "Cc" 398 } 399 } 400 } 401 } 402 } 403 headers { 404 cgi_table_data align=right valign=top { 405 cgi_put "[cgi_bold [lindex $patvarnames($pvarname) 0]] :[cgi_nbspace][cgi_nbspace]" 406 } 407 cgi_table_data align=left { 408 cgi_table { 409 set hdrnum 0 410 411 if {[llength $pvarval] > 0} { 412 for {set n 0} {$n < [llength $pvarval]} {incr n} { 413 cgi_table_row { 414 cgi_table_data align=left nowrap { 415 cgi_text "hdrfld${n}=[lindex [lindex $pvarval $n] 0]" "style=margin:2" 416 cgi_put ":" 417 cgi_text "hdrval${n}=[lindex [lindex $pvarval $n] 1]" "style=margin:2" 418 cgi_submit_button "rmheader${n}=Remove" 419 } 420 } 421 } 422 423 cgi_text "header_total=$n" type=hidden notab 424 } 425 426 cgi_table_row { 427 cgi_table_data align=left nowrap { 428 cgi_submit_button "addheader=Add Header" 429 } 430 } 431 } 432 } 433 } 434 } 435 } 436 } 437 } 438 cgi_puts "</fieldset>" 439 } 440 } 441 442 cgi_table_row { 443 cgi_table_data "style=\"padding-bottom: 40\"" { 444 cgi_puts "<fieldset>" 445 cgi_puts "<legend style=\"font-weight:bold;font-size:bigger\">Filter Actions</legend>" 446 foreach {avarname patval} $actions { 447 switch -- $avarname { 448 indexcolor { 449 set ih [WPIndexLineHeight] 450 set iformat [WPCmd PEMailbox indexformat] 451 set num 0 452 cgi_division "width=100%" align=center "style=\"font-size: bigger; font-weight: bold; margin: 0 0 12 0 \"" { 453 cgi_puts "Choose Index Line Colors" 454 } 455 456 cgi_table width=100% align=center cellpadding=0 cellspacing=0 "style=\"font-family: geneva, arial, sans-serif; height: ${ih}pix; width: 90%; background-color: white ; border: 1px solid black\"" { 457 foreach l [list "Line One" "Sample Message" "Line Three"] { 458 set iclass [lindex {i0 i1} [expr ([incr num] % 2)]] 459 set istyle "" 460 if {$num == 2} { 461 wpGetVarAs fg fg 462 if {[string length $fg] == 0} { 463 if {[info exists actionvals($avarname)]} { 464 set fg [lindex $actionvals($avarname) 0] 465 } 466 } 467 468 cgi_text "fg=$fg" type=hidden notab 469 append istyle "; color: $fg" 470 471 wpGetVarAs bg bg 472 if {[string length $bg] == 0} { 473 if {[info exists actionvals($avarname)]} { 474 set bg [lindex $actionvals($avarname) 1] 475 } 476 } 477 478 cgi_text "bg=$bg" type=hidden notab 479 append istyle "; background-color: $bg" 480 } 481 482 cgi_table_row { 483 if {[WPCmd PEInfo feature enable-aggregate-command-set]} { 484 cgi_table_data height=${ih}pix class=$iclass "style=\"$istyle\"" { 485 cgi_checkbox bogus 486 } 487 } 488 489 foreach fmt $iformat { 490 cgi_table_data height=${ih}pix width=[lindex $fmt 1]% nowrap class=$iclass "style=\"$istyle\"" { 491 switch -regex [string tolower [lindex $fmt 0]] { 492 number { 493 cgi_puts "$num" 494 } 495 status { 496 set n [expr {(int((10 * rand()))) % 5}] 497 cgi_puts [lindex {N D F A { }} $n] 498 } 499 .*size.* { 500 cgi_puts "([expr int((10000 * rand()))])" 501 } 502 from.* { 503 cgi_puts "Some Sender" 504 } 505 subject { 506 cgi_puts $l 507 } 508 date { 509 cgi_puts [clock format [clock seconds] -format "%d %b"] 510 } 511 default { 512 cgi_puts [lindex $fmt 0] 513 } 514 } 515 } 516 } 517 } 518 } 519 } 520 cgi_table width=80% align=center { 521 cgi_table_row { 522 cgi_table_data align=center { 523 cgi_table "style=\"background-color: #ffcc66\"" { 524 wpGetVarAs fgorbg fgorbg 525 cgi_table_row { 526 cgi_table_data { 527 if {[string length $fgorbg] == 0 || [string compare $fgorbg fg] == 0} { 528 set checked checked=1 529 } else { 530 set checked "" 531 } 532 533 cgi_radio_button fgorbg=fg $checked 534 } 535 cgi_table_data "style=\"align: left; padding-left: 12\"" { 536 cgi_puts "Foreground" 537 } 538 } 539 cgi_table_row { 540 cgi_table_data { 541 if {[string length $checked]} { 542 set checked "" 543 } else { 544 set checked checked=1 545 } 546 547 cgi_radio_button fgorbg=bg $checked 548 } 549 cgi_table_data "style=\"align: left; padding-left: 12\"" { 550 cgi_puts "Background" 551 } 552 } 553 } 554 } 555 cgi_table_data align=center { 556 cgi_image_button "colormap=[WPimg nondither10x10]" alt="Color Pattern" "style=\"border: 1px solid black\"" 557 } 558 } 559 } 560 } 561 folder { 562 if {[info exists actionvals(kill)]} { 563 set killit $actionvals(kill) 564 } else { 565 set killit 0 566 } 567 568 if {$filterr} { 569 wpGetVarAs action tval 570 set killit [expr {([string compare $tval "delete"] == 0) ? 1 : 0}] 571 } 572 cgi_table border=0 cellpadding=0 cellspacing=0 { 573 cgi_table_row { 574 cgi_table_data width=50 align=right valign=top { 575 cgi_puts [cgi_bold "Action:[cgi_nbspace]"] 576 } 577 cgi_table_data { 578 cgi_table border=0 cellpadding=0 cellspacing=0 { 579 cgi_table_row { 580 cgi_table_data valign=top { 581 cgi_radio_button action=status [expr {$killit ? "checked" : ""}] style="background-color:$_wp(dialogcolor)" 582 } 583 cgi_table_data { 584 cgi_puts "Set Message Status:" 585 cgi_division "style=\"margin-left: .5in\"" { 586 cgi_select actsetimp { 587 cgi_option "Don't change Important Status" "value=leave" [expr {[string compare $pvarval "either"] == 0 ? "selected" : ""}] 588 cgi_option "Set Important status" "value=set" [expr {[string compare $pvarval "yes"] == 0 ? "selected" : ""}] 589 cgi_option "Clear Important status" "value=clear" [expr {[string compare $pvarval "no"] == 0 ? "selected" : ""}] 590 } 591 592 cgi_br 593 594 cgi_select actsetnew { 595 cgi_option "Don't change New Status" "value=leave" [expr {[string compare $pvarval "either"] == 0 ? "selected" : ""}] 596 cgi_option "Set New status" "value=set" [expr {[string compare $pvarval "yes"] == 0 ? "selected" : ""}] 597 cgi_option "Clear New status" "value=clear" [expr {[string compare $pvarval "no"] == 0 ? "selected" : ""}] 598 } 599 600 cgi_br 601 602 cgi_select actsetdel { 603 cgi_option "Don't change Deleted Status" "value=leave" [expr {[string compare $pvarval "either"] == 0 ? "selected" : ""}] 604 cgi_option "Set Deleted status" "value=set" [expr {[string compare $pvarval "yes"] == 0 ? "selected" : ""}] 605 cgi_option "Clear Deleted status" "value=clear" [expr {[string compare $pvarval "no"] == 0 ? "selected" : ""}] 606 } 607 608 cgi_br 609 610 cgi_select actsetans { 611 cgi_option "Don't change Answered Status" "value=leave" [expr {[string compare $pvarval "either"] == 0 ? "selected" : ""}] 612 cgi_option "Set Answered status" "value=set" [expr {[string compare $pvarval "yes"] == 0 ? "selected" : ""}] 613 cgi_option "Clear Answered status" "value=clear" [expr {[string compare $pvarval "no"] == 0 ? "selected" : ""}] 614 } 615 } 616 } 617 } 618 cgi_table_row { 619 cgi_table_data valign=top { 620 cgi_radio_button action=delete [expr {$killit ? "checked" : ""}] style="background-color:$_wp(dialogcolor)" 621 } 622 cgi_table_data { 623 cgi_puts "Delete" 624 } 625 } 626 cgi_table_row { 627 cgi_table_data valign=top { 628 cgi_radio_button action=move [expr {$killit == 0 ? "checked" : ""}] style="background-color:$_wp(dialogcolor)" 629 } 630 cgi_table_data { 631 cgi_puts "Move to Folder :" 632 if {$filterr} { 633 wpGetVarAs actionfolder tval 634 cgi_text "actionfolder=$tval" 635 } else { 636 if {[info exists actionvals($avarname)]} { 637 set av $actionvals($avarname) 638 } else { 639 set av 0 640 } 641 642 cgi_text "actionfolder=$av" 643 } 644 cgi_br 645 if {$filterr} { 646 wpGetVarAs moind moinval 647 set tval [expr {([string compare $moinval on] == 0) ? "checked" : ""}] 648 } else { 649 if {[info exists actionvals($avarname)] && $actionvals($avarname) == 1} { 650 set tval checked 651 } else { 652 set tval "" 653 } 654 } 655 cgi_checkbox moind $tval 656 cgi_puts "Move only if not deleted." 657 } 658 } 659 } 660 } 661 } 662 cgi_table_row { 663 wpGetVarAs setkeywords setkeywords 664 freetext_cell "Set these Keywords" setkeywords $setkeywords 665 } 666 cgi_table_row { 667 wpGetVarAs clearkeywords clearkeywords 668 freetext_cell "Clear these Keywords" clearkeywords $clearkeywords 669 } 670 } 671 } 672 scores { 673 cgi_table border=0 cellpadding=4 cellspacing=0 align=center { 674 cgi_table_row { 675 wpGetVarAs scoreval scoreval 676 if {[string length $scoreval] == 0} { 677 set scoreval $actionvals(scoreval) 678 } 679 680 freetext_cell "Score Value" scoreval $scoreval 681 } 682 cgi_table_row { 683 wpGetVarAs scorehdr scorehdr 684 if {[string length $scorehdr] == 0} { 685 set scorehdr $actionvals(scorehdr) 686 } 687 688 freetext_cell "Score Header" scorehdr $scorehdr 689 } 690 } 691 } 692 } 693 } 694 695 cgi_puts "</fieldset>" 696 } 697 } 698 } 699 } 700 } 701 } 702 } 703 } 704} 705