~ubuntu-branches/debian/stretch/alpine/stretch

« back to all changes in this revision

Viewing changes to web/cgi/alpine/1.0/conf_process.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Asheesh Laroia
  • Date: 2010-10-03 15:31:55 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20101003153155-2exypc96j1e8tw0p
Tags: 2.02-1
* New upstream release, based on re-alpine project
* Updated debian/copyright to reflect this fact
* re-alpine removed the non-free from the tarball, so now
  we do not repack the upstream tarball. (Yay!)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!./tclsh
 
2
# $Id: conf_process.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
#  conf_process.tcl
 
15
#
 
16
#  Purpose:  CGI script to perform various message/mailbox
 
17
#            oriented operations
 
18
 
 
19
source genvars.tcl
 
20
source filter.tcl
 
21
 
 
22
set cfs_vars {
 
23
  {cid          "Missing Command ID"}
 
24
  {oncancel     "Missing oncancel"}
 
25
  {cp_op       {}      noop}
 
26
  {save         {}      0}
 
27
  {delete       {}      0}
 
28
  {compose      {}      0}
 
29
  {cancel       {}      0}
 
30
  {gtab         {}      0}
 
31
  {mltab        {}      0}
 
32
  {mvtab        {}      0}
 
33
  {ctab         {}      0}
 
34
  {abtab        {}      0}
 
35
  {ftab         {}      0}
 
36
  {rtab         {}      0}
 
37
  {wv           {}      ""}
 
38
  {varlistadd   {}      ""}
 
39
  {newconf      {}      0}
 
40
}
 
41
 
 
42
## read vars
 
43
foreach item $cfs_vars {
 
44
  if {[catch {cgi_import [lindex $item 0].x}]} {
 
45
    if {[catch {eval WPImport $item} result]} {
 
46
      error [list _action "Import Variable" $result]
 
47
    }
 
48
  } else {
 
49
    set [lindex $item 0] 1
 
50
  }
 
51
}
 
52
 
 
53
proc wpGetVar {_var {valid ""}} {
 
54
  upvar $_var var
 
55
 
 
56
  if {[catch {cgi_import_as $_var var} result]} {
 
57
    error [list _action "Import Var  $_var" $result]
 
58
  }
 
59
 
 
60
  if {[string length $valid]} {
 
61
    switch -exact -- $valid {
 
62
      _INTEGER_ {
 
63
        if {[string is integer -strict $var] != 1} {
 
64
          error [list _action "Invalid Input" "Non-Numeric Value for $_var"]
 
65
        }
 
66
      }
 
67
      default {
 
68
        if {[lsearch -exact $valid $var] < 0} {
 
69
          error [list _action "Invalid Input" "Unrecognized Value $var for $_var"]
 
70
        }
 
71
      }
 
72
    }
 
73
  }
 
74
}
 
75
 
 
76
proc wpGetVarAs {_var _varas} {
 
77
  upvar $_varas varas
 
78
 
 
79
  if {[catch {cgi_import_as $_var varas} result]} {
 
80
    set varas ""
 
81
  }
 
82
}
 
83
 
 
84
if {$cid != [WPCmd PEInfo key]} {
 
85
  catch {WPCmd PEInfo statmsg "Invalid Command ID"}
 
86
}
 
87
 
 
88
proc wpGetGoodVars {} {
 
89
  global wv
 
90
  global general_vars msglist_vars composer_vars folder_vars address_vars msgview_vars rule_vars
 
91
 
 
92
  switch -- $wv {
 
93
    msgl {
 
94
      set goodvars $msglist_vars
 
95
    }
 
96
    msgv {
 
97
      set goodvars $msgview_vars
 
98
    }
 
99
    address {
 
100
      set goodvars $address_vars
 
101
    }
 
102
    composer {
 
103
      set goodvars $composer_vars
 
104
    }
 
105
    folder {
 
106
      set goodvars $folder_vars
 
107
    }
 
108
    rule {
 
109
      set goodvars $rule_vars
 
110
    }
 
111
    general {
 
112
      set goodvars $general_vars
 
113
    }
 
114
  }
 
115
  return $goodvars
 
116
}
 
117
 
 
118
proc fieldPos {fmt field} {
 
119
  for {set i 0} {$i < [llength $fmt]} {incr i} {
 
120
    if {[string compare [string toupper [lindex [lindex $fmt $i] 0]] [string toupper $field]] == 0} {
 
121
      return $i
 
122
    }
 
123
  }
 
124
 
 
125
  return -1
 
126
}
 
127
 
 
128
proc numberedVar {nvbase nvtotal} {
 
129
  if {[catch {wpGetVarAs $nvtotal nvtot}] == 0} {
 
130
    for {set i 0} {$i < $nvtot} {incr i} {
 
131
      if {[catch {wpGetVar ${nvbase}${i}} nvval] == 0} {
 
132
        return $i
 
133
      }
 
134
    }
 
135
  }
 
136
 
 
137
  return -1
 
138
}
 
139
 
 
140
set op $cp_op
 
141
if {[catch {WPCmd set conf_page} conftype]} {
 
142
  set conftype general
 
143
}
 
144
if {[string length $wv]} {
 
145
  set conftype $wv
 
146
  set op tab
 
147
}
 
148
if {$save == 1 || [string compare $save Save] == 0} {
 
149
  set op tab
 
150
  set subop save
 
151
} elseif {$newconf} {
 
152
  set op noop
 
153
} elseif {$gtab} {
 
154
  set op "tab"
 
155
  set conftype "general"
 
156
} elseif {$mltab} {
 
157
  set op "tab"
 
158
  set conftype "msgl"
 
159
} elseif {$mvtab} {
 
160
  set op "tab"
 
161
  set conftype "msgv"
 
162
} elseif {$ctab} {
 
163
  set op "tab"
 
164
  set conftype "composer"
 
165
} elseif {$abtab} {
 
166
  set op "tab"
 
167
  set conftype "address"
 
168
} elseif {$ftab} {
 
169
  set op "tab"
 
170
  set conftype "folder"
 
171
} elseif {$rtab} {
 
172
  set op "tab"
 
173
  set conftype "rule"
 
174
} elseif {$cancel == 1 || [string compare $cancel Cancel] == 0} {
 
175
  set op "cancel"
 
176
}
 
177
 
 
178
proc wpGetRulePattern {} {
 
179
    global pattern_fields
 
180
 
 
181
    set patlist {}
 
182
 
 
183
    foreach {patvar patfield} $pattern_fields {
 
184
      wpGetVarAs $patvar tval
 
185
 
 
186
      switch $patvar {
 
187
        headers {
 
188
          # collect header fields/values into "headers"
 
189
          set headers {}
 
190
          if {[catch {wpGetVarAs header_total hcnt} res] == 0} {
 
191
            for {set i 0} {$i < $hcnt} {incr i} {
 
192
              if {[catch {wpGetVarAs hdrfld${i} fld}] == 0
 
193
                  && [catch {wpGetVarAs hdrval${i} val}] == 0} {
 
194
                lappend headers [list $fld $val]
 
195
              }
 
196
            }
 
197
          }
 
198
 
 
199
          lappend patlist [list headers $headers]
 
200
        }
 
201
        default {
 
202
          lappend patlist [list $patvar $tval]
 
203
        }
 
204
      }
 
205
    }
 
206
 
 
207
 
 
208
    return $patlist
 
209
 
 
210
}
 
211
 
 
212
proc wpGetRuleAction {tosave} {
 
213
    set actlist {}
 
214
    wpGetVar action
 
215
    if {$tosave == 1} {
 
216
      lappend actlist [list "action" $action]
 
217
    } else {
 
218
      switch -- $action {
 
219
        move {lappend actlist [list "kill" 0]}
 
220
        delete {lappend actlist [list "kill" 1]}
 
221
      }
 
222
    }
 
223
    wpGetVar actionfolder
 
224
    lappend actlist [list "folder" $actionfolder]
 
225
    wpGetVarAs moind moind
 
226
    if {[string compare $moind "on"] == 0} {
 
227
      lappend actlist [list [expr {$tosave == 1 ? "moind" : "move_only_if_not_deleted"}] "1"]
 
228
    } else {
 
229
      lappend actlist [list [expr {$tosave == 1 ? "moind" : "move_only_if_not_deleted"}] "0"]
 
230
    }
 
231
}
 
232
 
 
233
        #
 
234
        # Meat and potatoes of processing goes on here.
 
235
        # Errors are barfed up as they occur,
 
236
        # otherwise the result is communicated below...
 
237
        #
 
238
        set setfeatures [WPCmd PEConfig featuresettings]
 
239
        set script fr_tconfig.tcl
 
240
        switch -- $op {
 
241
            tab {
 
242
              if {[info exists goodvars] == 0} {
 
243
                set goodvars [wpGetGoodVars]
 
244
              }
 
245
              foreach goodvar $goodvars {
 
246
                set vtypeinp [lindex $goodvar 0]
 
247
                set varname [lindex $goodvar 1]
 
248
                set hlpthisvar 0
 
249
                wpGetVarAs hlp.$varname.x thlp
 
250
                if {[string length $thlp]} {
 
251
                  set hlpthisvar 1
 
252
                  set helpcancelset conf_process
 
253
                }
 
254
                switch -- $vtypeinp {
 
255
                  special {
 
256
                    switch -- $varname {
 
257
                      wp-columns {
 
258
                        if {$hlpthisvar} {
 
259
                          set subop varhelp
 
260
                          set varhelpname wp-columns
 
261
                        } else {
 
262
                          wpGetVar columns
 
263
                          WPCmd PEConfig columns $columns
 
264
                        }
 
265
                      }
 
266
                      left-column-folders {
 
267
                        if {0 == [catch {wpGetVar fcachel}]} {
 
268
                          if {$fcachel <= $_wp(fldr_cache_max)} {
 
269
                            catch {WPSessionState left_column_folders $fcachel}
 
270
                          }
 
271
                        }
 
272
                      }
 
273
                      signature {
 
274
                        wpGetVar signature
 
275
                        set cursig [string trimright [join [WPCmd PEConfig rawsig] "\n"]]
 
276
                        set signature [string trimright $signature]
 
277
                        if {[string compare $cursig $signature]} {
 
278
                          WPCmd PEConfig rawsig [split $signature "\n"]
 
279
                        }
 
280
                      }
 
281
                      filters {
 
282
                        wpGetVarAs $varname-sz sz
 
283
                        wpGetVarAs vla.$varname.x fltadd
 
284
                        wpGetVarAs hlp.$varname.x do_help
 
285
                        if {[string length $do_help]} {
 
286
                          set subop varhelp
 
287
                          set varhelpname filtconf
 
288
                        } elseif {[string length $fltadd]} {
 
289
                          set script "fr_filtedit.tcl"
 
290
                          set filtedit_add 1
 
291
                          set filtedit_onfiltcancel conf_process
 
292
                        } else {
 
293
                          if {[string length $sz] == 0} {
 
294
                            error [list _action "ERROR" "No size given for filters"]
 
295
                          }
 
296
                          for {set i 0} {$i < $sz} {incr i} {
 
297
                            wpGetVarAs vle.$varname.$i.x vle
 
298
                            wpGetVarAs vld.$varname.$i.x vld
 
299
                            wpGetVarAs vlsu.$varname.$i.x vlsu
 
300
                            wpGetVarAs vlsd.$varname.$i.x vlsd
 
301
                            set flt_ret 0
 
302
                            set flt_res ""
 
303
                            if {[string length $vle]} {
 
304
                              set script "fr_filtedit.tcl"
 
305
                              set filtedit_fno $i
 
306
                              set filtedit_onfiltcancel conf_process
 
307
                            } elseif {[string length $vld]} {
 
308
                              set flt_ret [catch {WPCmd PEConfig ruleset filter delete $i} flt_res]
 
309
                            } elseif {[string length $vlsu]} {
 
310
                              set flt_ret [catch {WPCmd PEConfig ruleset filter shuffup $i} flt_res]
 
311
                            } elseif {[string length $vlsd]} {
 
312
                              set flt_ret [catch {WPCmd PEConfig ruleset filter shuffdown $i} flt_res]
 
313
                            }
 
314
                            if {$flt_ret} {
 
315
                              # error
 
316
                            } elseif {[string length $flt_res]} {
 
317
                              # something wrong here
 
318
                            }
 
319
                          }
 
320
                        }
 
321
                      }
 
322
                      scores {
 
323
                        wpGetVarAs $varname-sz sz
 
324
                        wpGetVarAs vla.$varname.x fltadd
 
325
                        wpGetVarAs hlp.$varname.x do_help
 
326
                        if {[string length $do_help]} {
 
327
                          set subop varhelp
 
328
                          set varhelpname filtconf
 
329
                        } elseif {[string length $fltadd]} {
 
330
                          set script "fr_filtedit.tcl"
 
331
                          set filtedit_add 1
 
332
                          set filtedit_score 1
 
333
                          set filtedit_onfiltcancel conf_process
 
334
                        } else {
 
335
                          if {[string length $sz] == 0} {
 
336
                            error [list _action "ERROR" "No size given for scores"]
 
337
                          }
 
338
                          for {set i 0} {$i < $sz} {incr i} {
 
339
                            wpGetVarAs vle.$varname.$i.x vle
 
340
                            wpGetVarAs vld.$varname.$i.x vld
 
341
                            wpGetVarAs vlsu.$varname.$i.x vlsu
 
342
                            wpGetVarAs vlsd.$varname.$i.x vlsd
 
343
                            set flt_ret 0
 
344
                            set flt_res ""
 
345
                            if {[string length $vle]} {
 
346
                              set script "fr_filtedit.tcl"
 
347
                              set filtedit_score 1
 
348
                              set filtedit_fno $i
 
349
                              set filtedit_onfiltcancel conf_process
 
350
                            } elseif {[string length $vld]} {
 
351
                              set flt_ret [catch {WPCmd PEConfig ruleset score delete $i} flt_res]
 
352
                            } elseif {[string length $vlsu]} {
 
353
                              set flt_ret [catch {WPCmd PEConfig ruleset score shuffup $i} flt_res]
 
354
                            } elseif {[string length $vlsd]} {
 
355
                              set flt_ret [catch {WPCmd PEConfig ruleset score shuffdown $i} flt_res]
 
356
                            }
 
357
                            if {$flt_ret} {
 
358
                              # error
 
359
                            } elseif {[string length $flt_res]} {
 
360
                              # something wrong here
 
361
                            }
 
362
                          }
 
363
                        }
 
364
                      }
 
365
                      indexcolor {
 
366
                        wpGetVarAs $varname-sz sz
 
367
                        wpGetVarAs vla.$varname.x fltadd
 
368
                        wpGetVarAs hlp.$varname.x do_help
 
369
                        if {[string length $do_help]} {
 
370
                          set subop varhelp
 
371
                          set varhelpname filtconf
 
372
                        } elseif {[string length $fltadd]} {
 
373
                          set script "fr_filtedit.tcl"
 
374
                          set filtedit_add 1
 
375
                          set filtedit_indexcolor 1
 
376
                          set filtedit_onfiltcancel conf_process
 
377
                        } else {
 
378
                          if {[string length $sz] == 0} {
 
379
                            error [list _action "ERROR" "No size given for index colors"]
 
380
                          }
 
381
                          for {set i 0} {$i < $sz} {incr i} {
 
382
                            wpGetVarAs vle.$varname.$i.x vle
 
383
                            wpGetVarAs vld.$varname.$i.x vld
 
384
                            wpGetVarAs vlsu.$varname.$i.x vlsu
 
385
                            wpGetVarAs vlsd.$varname.$i.x vlsd
 
386
                            set flt_ret 0
 
387
                            set flt_res ""
 
388
                            if {[string length $vle]} {
 
389
                              set script "fr_filtedit.tcl"
 
390
                              set filtedit_indexcolor 1
 
391
                              set filtedit_fno $i
 
392
                              set filtedit_onfiltcancel conf_process
 
393
                            } elseif {[string length $vld]} {
 
394
                              set flt_ret [catch {WPCmd PEConfig ruleset indexcolor delete $i} flt_res]
 
395
                            } elseif {[string length $vlsu]} {
 
396
                              set flt_ret [catch {WPCmd PEConfig ruleset indexcolor shuffup $i} flt_res]
 
397
                            } elseif {[string length $vlsd]} {
 
398
                              set flt_ret [catch {WPCmd PEConfig ruleset indexcolor shuffdown $i} flt_res]
 
399
                            }
 
400
                            if {$flt_ret} {
 
401
                              # error
 
402
                            } elseif {[string length $flt_res]} {
 
403
                              # something wrong here
 
404
                            }
 
405
                          }
 
406
                        }
 
407
                      }
 
408
                      collections {
 
409
                        wpGetVarAs $varname-sz sz
 
410
                        wpGetVarAs vla.$varname.x cladd
 
411
                        if {[string length $cladd]} {
 
412
                          set script "fr_cledit.tcl"
 
413
                          set cledit_add 1
 
414
                          set cledit_onclecancel conf_process
 
415
                        } else {
 
416
                          if {[string length $sz] == 0} {
 
417
                            error [list _action "ERROR" "No size given for collections"]
 
418
                          }
 
419
                          for {set i 0} {$i < $sz} {incr i} {
 
420
                            wpGetVarAs vle.$varname.$i.x vle
 
421
                            wpGetVarAs vld.$varname.$i.x vld
 
422
                            wpGetVarAs vlsu.$varname.$i.x vlsu
 
423
                            wpGetVarAs vlsd.$varname.$i.x vlsd
 
424
                            set cle_ret 0
 
425
                            set cle_res ""
 
426
                            if {[string length $vle]} {
 
427
                              set script "fr_cledit.tcl"
 
428
                              set cledit_cl $i
 
429
                              set cledit_onclecancel conf_process
 
430
                            } elseif {[string length $vld]} {
 
431
                              set cle_ret [catch {WPCmd PEConfig cldel $i} cle_res]
 
432
                            } elseif {[string length $vlsu]} {
 
433
                              set cle_ret [catch {WPCmd PEConfig clshuff up $i} cle_res]
 
434
                            } elseif {[string length $vlsd]} {
 
435
                              set cle_ret [catch {WPCmd PEConfig clshuff down $i} cle_res]
 
436
                            }
 
437
                            if {$cle_ret} {
 
438
                              # error
 
439
                            } elseif {[string length $cle_res]} {
 
440
                              WPCmd PEInfo statmsg $cle_res
 
441
                              # something wrong here
 
442
                            }
 
443
                          }
 
444
                        }
 
445
                      }
 
446
                      index-format {
 
447
                        wpGetVarAs index-format iformat
 
448
 
 
449
                        set varchanged 0
 
450
 
 
451
                        if {$hlpthisvar} {
 
452
                          set subop varhelp
 
453
                          set varhelpname index-format
 
454
                        } elseif {[catch {cgi_import hlp.index_tokens.x} result] == 0} {
 
455
                          set subop secthelp
 
456
                          set topicclass plain
 
457
                          set feathelpname h_index_tokens
 
458
                          set varhelpname h_index_tokens
 
459
                        }
 
460
 
 
461
                        if {[catch {cgi_import indexadd}] == 0
 
462
                            && [string compare "Add Field" $indexadd] == 0
 
463
                            && [catch {cgi_import indexaddfield}] == 0} {
 
464
                          if {[lsearch $iformat $indexaddfield] < 0} {
 
465
                            set iformat [linsert $iformat 0 $indexaddfield]
 
466
                            set varchanged 1
 
467
                          }
 
468
                        } elseif {[catch {cgi_import adjust}] == 0
 
469
                                   && [string compare Change $adjust] == 0
 
470
                                   && [catch {cgi_import iop}] == 0
 
471
                                   && [catch {cgi_import ifield}] == 0
 
472
                                   && [set pos [fieldPos $iformat $ifield]] >= 0} {
 
473
                          switch $iop {
 
474
                            left {
 
475
                              set iformat [lreplace $iformat $pos $pos]
 
476
                              set iformat [linsert $iformat [incr pos -1] $ifield]
 
477
                              set varchanged 1
 
478
                            }
 
479
                            right {
 
480
                              set iformat [lreplace $iformat $pos $pos]
 
481
                              set iformat [linsert $iformat [incr pos] $ifield]
 
482
                              set varchanged 1
 
483
                            }
 
484
                            widen {
 
485
                              set f [lindex [lindex $iformat $pos] 0]
 
486
                              set w [lindex [lindex $iformat $pos] 1]
 
487
                              set dw [expr {round((100/[llength $iformat]) * [WPTFIndexWidthRatio $iformat $f])}]
 
488
 
 
489
                              if {[regexp {([0123456789]+)[%]} $w dummy w] == 0} {
 
490
                                set w $dw
 
491
                              }
 
492
 
 
493
                              if {$w < 95} {
 
494
                                incr w 5
 
495
                              } else {
 
496
                                set w 99
 
497
                              }
 
498
 
 
499
                              if {$w == $dw} {
 
500
                                set ws ""
 
501
                              } else {
 
502
                                set ws "${w}%"
 
503
                              }
 
504
 
 
505
                              set iformat [lreplace $iformat $pos $pos [list $f $ws]]
 
506
                              set varchanged 1
 
507
                            }
 
508
                            narrow {
 
509
                              set f [lindex [lindex $iformat $pos] 0]
 
510
                              set w [lindex [lindex $iformat $pos] 1]
 
511
                              set dw [expr {round((100/[llength $iformat]) * [WPTFIndexWidthRatio $iformat $f])}]
 
512
 
 
513
                              if {[regexp {([0123456789]+)[%]} $w dummy w] == 0} {
 
514
                                set w $dw
 
515
                              }
 
516
 
 
517
                              if {$w > 5} {
 
518
                                incr w -5
 
519
                              } else {
 
520
                                set w 1
 
521
                              }
 
522
 
 
523
                              if {$w == $dw} {
 
524
                                set ws ""
 
525
                              } else {
 
526
                                set ws "${w}%"
 
527
                              }
 
528
 
 
529
                              set iformat [lreplace $iformat $pos $pos [list $f $ws]]
 
530
                              set varchanged 1
 
531
                            }
 
532
                            remove {
 
533
                              set iformat [lreplace $iformat $pos $pos]
 
534
                              set varchanged 1
 
535
                            }
 
536
                          }
 
537
                        } else {
 
538
                          foreach f $iformat {
 
539
                            if {[catch {cgi_import_as shrm.${f}.x shift} result] == 0} {
 
540
                              if {[set pos [fieldPos $iformat $f]] >= 0} {
 
541
                                set iformat [lreplace $iformat $pos $pos]
 
542
                                set varchanged 1
 
543
                              }
 
544
                            } elseif {[catch {cgi_import_as shlf.${f}.x shift} result] == 0} {
 
545
                              if {[set pos [fieldPos $iformat $f]] > 0} {
 
546
                                set iformat [lreplace $iformat $pos $pos]
 
547
                                set iformat [linsert $iformat [incr pos -1] $f]
 
548
                                set varchanged 1
 
549
                              }
 
550
                            } elseif {[catch {cgi_import_as shrt.${f}.x shift} result] == 0} {
 
551
                              if {[set pos [fieldPos $iformat $f]] >= 0} {
 
552
                                set iformat [lreplace $iformat $pos $pos]
 
553
                                set iformat [linsert $iformat [incr pos] $f]
 
554
                                set varchanged 1
 
555
                              }
 
556
                            }
 
557
                          }
 
558
                        }
 
559
 
 
560
                        if {$varchanged} {
 
561
                          foreach f $iformat {
 
562
                            if {[string length [lindex $f 1]]} {
 
563
                              lappend ifv "[lindex $f 0]([lindex $f 1])"
 
564
                            } else {
 
565
                              lappend ifv [lindex $f 0]
 
566
                            }
 
567
                          }
 
568
 
 
569
                          WPCmd PEConfig varset index-format [list $ifv]
 
570
                        }
 
571
                      }
 
572
                      view-colors {
 
573
                        if {$hlpthisvar} {
 
574
                          set subop varhelp
 
575
                          set varhelpname index-format
 
576
                        } elseif {[catch {cgi_import_as colormap.x colx}] == 0
 
577
                                  && [catch {cgi_import_as colormap.y coly}] == 0} {
 
578
                          set rgbs {"000" "051" "102" "153" "204" "255"}
 
579
                          set xrgbs {"00" "33" "66" "99" "CC" "FF"}
 
580
                          set rgblen [llength $rgbs]
 
581
                          set imappixwidth 10
 
582
 
 
583
                          set colx [expr {${colx} / $imappixwidth}]
 
584
                          set coly [expr {${coly} / $imappixwidth}]
 
585
                          if {($coly >= 0 && $coly < $rgblen)
 
586
                              && ($colx >= 0 && $colx < [expr {$rgblen * $rgblen}])} {
 
587
                            set ired $coly
 
588
                            set igreen [expr {($colx / $rgblen) % $rgblen}]
 
589
                            set iblue [expr {$colx % $rgblen}]
 
590
                            set rgb "[lindex $rgbs $ired],[lindex $rgbs ${igreen}],[lindex $rgbs ${iblue}]"
 
591
                            set xrgb "[lindex $xrgbs $ired][lindex $xrgbs ${igreen}][lindex $xrgbs ${iblue}]"
 
592
 
 
593
                            if {[catch {cgi_import_as text tt}] == 0} {
 
594
                              set type [split $tt .]
 
595
                              catch {WPCmd set config_deftext [lindex $type end]}
 
596
 
 
597
                              if {[catch {cgi_import_as ground ground}] == 0} {
 
598
                                switch $ground {
 
599
                                  f {
 
600
                                    catch {WPCmd set config_defground f}
 
601
                                    set fg $xrgb
 
602
                                  }
 
603
                                  b {
 
604
                                    catch {WPCmd set config_defground b}
 
605
                                    set bg $xrgb
 
606
                                  }
 
607
                                }
 
608
 
 
609
                                if {[info exists fg] || [info exists bg]} {
 
610
                                  switch [lindex $type 0] {
 
611
                                    hdr {
 
612
                                      set type [lindex $type 1]
 
613
                                      if {[catch {cgi_import_as add.${type} foo}] == 0} {
 
614
                                        set colop add
 
615
                                      } elseif {[catch {cgi_import_as hi.${type} hindex}] == 0} {
 
616
                                        set colop change
 
617
                                      }
 
618
 
 
619
                                      if {[info exists colop]} {
 
620
                                        if {![info exists bg] && [catch {cgi_import_as dbg.$type bg} result]} {
 
621
                                          WPCmd PEInfo statmsg "Can't import default background: $result"
 
622
                                        } elseif {![info exists fg] && [catch {cgi_import_as dfg.$type fg} result]} {
 
623
                                          WPCmd PEInfo statmsg "Can't import default foreground: $result"
 
624
                                        }
 
625
 
 
626
                                        switch $colop {
 
627
                                          change {
 
628
                                            if {[catch {WPCmd PEConfig colorset viewer-hdr-colors update [list $hindex $type ""] [list $fg $bg]} result]} {
 
629
                                              WPCmd PEInfo statmsg "Problem changing $type color: $result"
 
630
                                            }
 
631
                                          }
 
632
                                          add {
 
633
                                            if {[catch {WPCmd PEConfig colorset viewer-hdr-colors add [list $type ""] [list $fg $bg]} result]} {
 
634
                                              WPCmd PEInfo statmsg "Problem adding $type color: $result"
 
635
                                            }
 
636
                                          }
 
637
                                        }
 
638
 
 
639
                                      }
 
640
                                    }
 
641
                                    default {
 
642
                                      if {![info exists bg] && [catch {cgi_import_as dbg.$type bg} result]} {
 
643
                                        WPCmd PEInfo statmsg "Can't import default background: $result"
 
644
                                      } elseif {![info exists fg] && [catch {cgi_import_as dfg.$type fg} result]} {
 
645
                                        WPCmd PEInfo statmsg "Can't import default foreground: $result"
 
646
                                      } elseif {[catch {WPCmd PEConfig colorset $type [list $fg $bg]} result]} {
 
647
                                        WPCmd PEInfo statmsg "Can't set $type color: $result"
 
648
                                      }
 
649
                                    }
 
650
                                  }
 
651
                                } else {
 
652
                                    WPCmd PEInfo statmsg "Invalid fore/back ground input!"
 
653
                                }
 
654
                              } else {
 
655
                                WPCmd PEInfo statmsg "Choose foreground or background!"
 
656
                              }
 
657
                            } else {
 
658
                              WPCmd PEInfo statmsg "Choose the type of text to color!"
 
659
                            }
 
660
                          } else {
 
661
                            WPCmd PEInfo statmsg "Invalid RGB Input!"
 
662
                          }
 
663
                        } elseif {[catch {cgi_import addfield}] == 0
 
664
                                  && [string compare "add " [string tolower [string range $addfield 0 3]]] == 0
 
665
                                  && [catch {cgi_import newfield}] == 0
 
666
                                  && [string length [set newfield [string trim $newfield]]]
 
667
                                  && [catch {cgi_import_as dfg.normal dfg}] == 0
 
668
                                  && [catch {cgi_import_as dbg.normal dbg}] == 0} {
 
669
                          if {[catch {WPCmd PEConfig colorset viewer-hdr-colors add [list $newfield ""] [list $dfg $dbg]} result]} {
 
670
                            WPCmd PEInfo statmsg "Problem adding $type color: $result"
 
671
                          }
 
672
                        } elseif {[catch {cgi_import reset}] == 0
 
673
                                  && [string compare "restore " [string tolower [string range $reset 0 7]]] == 0} {
 
674
                          if {[catch {cgi_import_as text tt}] == 0} {
 
675
                            if {[llength [set type [split $tt .]]] == 2 && [string compare [lindex $type 0] hdr] == 0} {
 
676
                              set hdr [lindex $type end]
 
677
                              if {[catch {cgi_import_as hi.$hdr hindex}] == 0} {
 
678
                                if {[catch {WPCmd PEConfig colorset viewer-hdr-colors delete $hindex} result]} {
 
679
                                  # bug: reloads cause this error - need better way to report it
 
680
                                  #WPCmd PEInfo statmsg "Can't reset $hdr ($hindex) text: $result!"
 
681
                                } else {
 
682
                                  catch {WPCmd PEInfo unset config_deftext}
 
683
                                }
 
684
                              }
 
685
                            } elseif {[string compare normal $tt] == 0} {
 
686
                              if {[catch {WPCmd PEConfig varset normal-foreground-color ""} result]
 
687
                                  || [catch {WPCmd PEConfig varset normal-background-color ""} result]} {
 
688
                                WPCmd PEInfo statmsg "Can't reset normal text: $result!"
 
689
                              }
 
690
                            } elseif {[catch {cgi_import_as dfg.normal dfg}] == 0
 
691
                                      && [catch {cgi_import_as dbg.normal dbg}] == 0} {
 
692
                              catch {WPCmd set config_deftext $tt}
 
693
                              if {[catch {WPCmd PEConfig colorset $tt [list $dfg $dbg]} result]} {
 
694
                                WPCmd PEInfo statmsg "Can't reset $tt text: $result!"
 
695
                              }
 
696
                            }
 
697
                          } else {
 
698
                            WPCmd PEInfo statmsg "Choose the type of text to color!"
 
699
                          }
 
700
                        }
 
701
                      }
 
702
                    }
 
703
                  }
 
704
                  var {
 
705
                    wpGetVarAs $varname formval
 
706
                    set varvals [WPCmd PEConfig varget $varname]
 
707
                    set vals [lindex $varvals 0]
 
708
                    set vartype [lindex $varvals 1]
 
709
                    set formvals [split $formval "\n"]
 
710
                    set varchanged 0
 
711
 
 
712
                    if {$hlpthisvar} {
 
713
                      set subop varhelp
 
714
                      set varhelpname $varname
 
715
                    }
 
716
 
 
717
                    if {[string compare $vartype textarea] == 0} {
 
718
                      wpGetVarAs vla.$varname.x vlavar
 
719
                      wpGetVarAs $varname-sz sz
 
720
                      wpGetVarAs $varname-add valadd
 
721
                      if {[string length $vlavar]} {
 
722
                        set fr_tconfig_vlavar $varname
 
723
                      }
 
724
                      set formvals {}
 
725
                      if {[string length $valadd]} {
 
726
                        lappend formvals $valadd
 
727
                      }
 
728
                      if {[string length $sz]} {
 
729
                        set prevwassd 0
 
730
                        for {set i 0} {$i < $sz} {incr i} {
 
731
                          wpGetVarAs vle.$varname.$i fval
 
732
                          wpGetVarAs vld.$varname.$i.x fvaldel
 
733
                          wpGetVarAs vlsu.$varname.$i.x fvalsu
 
734
                          wpGetVarAs vlsd.$varname.$i.x fvalsd
 
735
                          set fed 0
 
736
                          set fdel 0
 
737
                          set fsu 0
 
738
                          set fsd 0
 
739
                          if {[string length $fval]} {
 
740
                            set fed 1
 
741
                          }
 
742
                          if {[string length $fvaldel]} {
 
743
                            set fdel 1
 
744
                          } elseif {[string length $fvalsu]} {
 
745
                            set fsu 1
 
746
                          } elseif {[string length $fvalsd]} {
 
747
                            set fsd 1
 
748
                          }
 
749
                          if {$fed && $fdel == 0 && $prevwassd} {
 
750
                            set prevwassd 0
 
751
                            set formvals [linsert $formvals [expr {[llength $formvals] - 1}] $fval]
 
752
                          } elseif {$fed && $fdel == 0 && $fsu == 0} {
 
753
                            lappend formvals $fval
 
754
                            if {$fsd} {
 
755
                              set prevwassd 1
 
756
                            }
 
757
                          } elseif {$fed && $fdel == 0 && $fsu} {
 
758
                            set fvallen [llength $formvals]
 
759
                            if {$fvallen} {
 
760
                              set formvals [linsert $formvals [expr {$fvallen - 2}] $fval]
 
761
                            } else {
 
762
                              lappend formvals $fval
 
763
                            }
 
764
                          }
 
765
                        }
 
766
                      }
 
767
                      set len [llength $formvals]
 
768
                      if {$len != [llength $vals]} {
 
769
                        set varchanged 1
 
770
                      } else {
 
771
                        for {set i 0} {$i < $len} {incr i} {
 
772
                          if {[string compare [lindex $formvals $i] [lindex $vals $i]]} {
 
773
                            set varchanged 1
 
774
                            break
 
775
                          }
 
776
                        }
 
777
                      }
 
778
                    } elseif {[llength $formvals] != [llength $vals]} {
 
779
                      set varchanged 1
 
780
                    } else {
 
781
                      set valslength [llength $vals]
 
782
                      for {set i 0} {$i < $valslength} {incr i} {
 
783
                        if {[string compare [lindex $vals $i] [lindex $formvals $i]]} {
 
784
                          set varchanged 1
 
785
                          break
 
786
                        }
 
787
                      }
 
788
                    }
 
789
                    if {$varchanged} {
 
790
                      WPCmd PEConfig varset $varname $formvals
 
791
                    }
 
792
                    # what about wp-indexheight?
 
793
                  }
 
794
                  feat {
 
795
                    wpGetVarAs $varname tval
 
796
                    if {$hlpthisvar} {
 
797
                      set subop feathelp
 
798
                      set feathelpname $varname
 
799
                    }
 
800
                    set featset [expr {[lsearch $setfeatures $varname] >= 0}]
 
801
                    set formfeatset [expr {[string compare $tval on] == 0}]
 
802
                    if {$formfeatset != $featset} {
 
803
                      WPCmd PEConfig feature $varname $formfeatset
 
804
                    }
 
805
                  }
 
806
                }
 
807
              }
 
808
              if {[info exists subop]} {
 
809
                switch -- $subop {
 
810
                  varhelp {
 
811
                    catch {WPCmd PEInfo unset help_context}
 
812
                    catch {WPCmd set oncancel $oncancel}
 
813
                    set help_vars [list topic topicclass]
 
814
                    set topic $varhelpname
 
815
                    set _cgi_uservar(topic) $varhelpname
 
816
                    set topicclass variable
 
817
                    set _cgi_uservar(topicclass) variable
 
818
                    set _cgi_uservar(oncancel) conf_process
 
819
                    set script help
 
820
                  }
 
821
                  feathelp {
 
822
                    catch {WPCmd PEInfo unset help_context}
 
823
                    catch {WPCmd set oncancel $oncancel}
 
824
                    set help_vars [list topic topicclass oncancel]
 
825
                    set topic $feathelpname
 
826
                    set _cgi_uservar(topic) $feathelpname
 
827
                    set topicclass feature
 
828
                    set _cgi_uservar(topicclass) feature
 
829
                    set _cgi_uservar(oncancel) conf_process
 
830
                    set script help
 
831
                  }
 
832
                  secthelp {
 
833
                    catch {WPCmd PEInfo unset help_context}
 
834
                    catch {WPCmd set oncancel $oncancel}
 
835
                    set help_vars [list topic topicclass oncancel]
 
836
                    set topic $feathelpname
 
837
                    set _cgi_uservar(topic) $feathelpname
 
838
                    set topicclass $topicclass
 
839
                    set _cgi_uservar(topicclass) $topicclass
 
840
                    set _cgi_uservar(oncancel) conf_process
 
841
                    set script help
 
842
                  }
 
843
                  save {
 
844
                    if {$cid != [WPCmd PEInfo key]} {
 
845
                      error [list _close "Invalid Operation ID"]
 
846
                    }
 
847
                    WPCmd PEConfig saveconf
 
848
                    set script $oncancel
 
849
                    catch {WPCmd PEInfo unset config_deftext}
 
850
                  }
 
851
                }
 
852
              }
 
853
            }
 
854
            filtconfig {
 
855
              wpGetVar fno [list _INTEGER_]
 
856
              wpGetVar subop [list edit add]
 
857
 
 
858
              if {[catch {wpGetVar filtcancel}]} {
 
859
                if {[catch {wpGetVar filthelp}] == 0} {
 
860
                  catch {WPCmd PEInfo unset help_context}
 
861
                  catch {WPCmd set oncancel $oncancel}
 
862
 
 
863
                  set patlist [wpGetRulePattern]
 
864
                  set actlist [wpGetRuleAction 0]
 
865
                  # we have to save this exactly as it would look when getting it from alpined
 
866
                  set ftsadd [expr {[string compare $subop "add"] == 0 ? 1 : 0}]
 
867
                  set ftsform [list [list "pattern" $patlist] [list "filtaction" $actlist]]
 
868
                  catch {WPCmd set filttmpstate [list $ftsadd $fno $ftsform]}
 
869
 
 
870
                  set help_vars [list topic]
 
871
                  set topic filtedit
 
872
                  set _cgi_uservar(topic) filtedit
 
873
 
 
874
                  if {[string compare $subop "edit"] == 0} {
 
875
                    set fakeimg "vle.filters.$fno"
 
876
                    set fakesz [expr {$fno + 1}]
 
877
                  } else {
 
878
                    set fakeimg "vla.filters"
 
879
                    set fakesz 1
 
880
                  }
 
881
 
 
882
                  set _cgi_uservar(oncancel) [WPPercentQuote "conf_process&wv=rule&filters-sz=${fakesz}&${fakeimg}.x=1&${fakeimg}.y=1&oncancel=main.tcl"]
 
883
                  set script help
 
884
                } elseif {[set nv [numberedVar rmheader header_total]] >= 0} {
 
885
 
 
886
                  # load all the rules, process "headers"
 
887
                  foreach pat [wpGetRulePattern] {
 
888
                    set [lindex $pat 0] [lindex $pat 1]
 
889
                    
 
890
                    if {[string compare headers [lindex $pat 0]] == 0} {
 
891
                      if {[llength $headers] > $nv} {
 
892
                        set headers [lreplace $headers $nv $nv]
 
893
                      }
 
894
                    }
 
895
                  }
 
896
 
 
897
                  # load all the actions
 
898
                  foreach act [wpGetRuleAction 0] {
 
899
                    set [lindex $act 0] [lindex $act 1]
 
900
                  }
 
901
 
 
902
                  # load other variables
 
903
                  wpGetVarAs nickname nickname
 
904
                  wpGetVarAs comment comment
 
905
                  wpGetVarAs folder folder
 
906
                  wpGetVarAs ftype ftype
 
907
 
 
908
                  set filterrtext 1
 
909
                  set filtedit_fno $fno
 
910
                  set filtedit_add [expr {[string compare $subop add] == 0 ? 1 : 0}]
 
911
                  set filtedit_onfiltcancel conf_process
 
912
                  set script "fr_filtedit.tcl"
 
913
                } elseif {[catch {wpGetVar addheader}] == 0} {
 
914
 
 
915
                  # load all the rules, process "headers"
 
916
                  foreach pat [wpGetRulePattern] {
 
917
                    set [lindex $pat 0] [lindex $pat 1]
 
918
                    if {[string compare headers [lindex $pat 0]] == 0} {
 
919
                      foreach h [set headers [lindex $pat 1]] {
 
920
                        if {0 == [string length [lindex $h 0]]
 
921
                            && 0 == [string length [lindex $h 1]]} {
 
922
                          set emptyheader 1
 
923
                        }
 
924
                      }
 
925
                      
 
926
                      if {![info exists emptyheader]} {
 
927
                        lappend headers [list {} {}]
 
928
                      }
 
929
                    }
 
930
                  }
 
931
 
 
932
                  # load all the actions
 
933
                  foreach act [wpGetRuleAction 0] {
 
934
                    set [lindex $act 0] [lindex $act 1]
 
935
                  }
 
936
 
 
937
                  # load other variables
 
938
                  wpGetVar nickname
 
939
                  wpGetVar comment
 
940
                  wpGetVarAs folder folder
 
941
                  wpGetVarAs ftype ftype
 
942
 
 
943
                  set filterrtext 1
 
944
                  set filtedit_fno $fno
 
945
                  set filtedit_add [expr {[string compare $subop add] == 0 ? 1 : 0}]
 
946
                  set filtedit_onfiltcancel conf_process
 
947
                  set script "fr_filtedit.tcl"
 
948
                } else {
 
949
                  # load other variables
 
950
                  wpGetVar nickname
 
951
                  wpGetVar comment
 
952
                  wpGetVarAs folder folder
 
953
                  wpGetVarAs ftype ftype
 
954
 
 
955
                  set patlist [wpGetRulePattern]
 
956
                  set actlist [wpGetRuleAction 1]
 
957
 
 
958
                  lappend patlist [list nickname $nickname]
 
959
                  lappend patlist [list comment $comment]
 
960
 
 
961
                  set ret [catch {WPCmd PEConfig ruleset filter $subop $fno $patlist $actlist} res]
 
962
                  if {$ret} {
 
963
                    error [list _action "Filter Set" $res]
 
964
                  } elseif {[string length $res]} {
 
965
                    WPCmd PEInfo statmsg "Filter setting failed: $res"
 
966
 
 
967
                    set filtedit_fno $fno
 
968
                    set filtedit_add [expr {[string compare $subop add] == 0 ? 1 : 0}]
 
969
                    set filtedit_onfiltcancel conf_process
 
970
                    set script "fr_filtedit.tcl"
 
971
                  }
 
972
                }
 
973
              }
 
974
            }
 
975
            scoreconfig {
 
976
              wpGetVar fno [list _INTEGER_]
 
977
              wpGetVar subop [list edit add]
 
978
 
 
979
              if {[catch {wpGetVar filtcancel}]} {
 
980
                if {[catch {wpGetVar filthelp}] == 0} {
 
981
                  catch {WPCmd PEInfo unset help_context}
 
982
                  catch {WPCmd set oncancel $oncancel}
 
983
                  if {[string compare $subop "edit"] == 0 || [string compare $subop "add"] == 0} {
 
984
                    set patlist [wpGetRulePattern]
 
985
 
 
986
                    # we have to save this exactly as it would look when getting it from alpined
 
987
                    set ftsadd [expr {[string compare $subop "add"] == 0 ? 1 : 0}]
 
988
                    set ftsform [list [list "pattern" $patlist] [list "filtaction" $actlist]]
 
989
                    catch {WPCmd set filttmpstate [list $ftsadd $fno $ftsform]}
 
990
                  }
 
991
                  set help_vars [list topic]
 
992
                  set topic scoreedit
 
993
                  set _cgi_uservar(topic) scoreedit
 
994
                  switch -- $subop {
 
995
                    edit {
 
996
                      set fakeimg "vle.scores.$fno"
 
997
                      set fakesz [expr {$fno + 1}]
 
998
                    }
 
999
                    add  {
 
1000
                      set fakeimg "vla.scores"
 
1001
                      set fakesz 1
 
1002
                    }
 
1003
                  }
 
1004
 
 
1005
                  set _cgi_uservar(oncancel) [WPPercentQuote "conf_process&wv=rule&scores-sz=${fakesz}&${fakeimg}.x=1&${fakeimg}.y=1&oncancel=main.tcl"]
 
1006
                  set script help
 
1007
                } elseif {[set nv [numberedVar rmheader header_total]] >= 0} {
 
1008
 
 
1009
                  # load all the rules, process "headers"
 
1010
                  foreach pat [wpGetRulePattern] {
 
1011
                    set [lindex $pat 0] [lindex $pat 1]
 
1012
                    
 
1013
                    if {[string compare headers [lindex $pat 0]] == 0} {
 
1014
                      if {[llength $headers] > $nv} {
 
1015
                        set headers [lreplace $headers $nv $nv]
 
1016
                      }
 
1017
                    }
 
1018
                  }
 
1019
 
 
1020
                  # load other variables
 
1021
                  wpGetVar nickname
 
1022
                  wpGetVar comment
 
1023
                  wpGetVarAs folder folder
 
1024
                  wpGetVarAs ftype ftype
 
1025
 
 
1026
                  set filterrtext 1
 
1027
                  set filtedit_score 1
 
1028
                  set filtedit_fno $fno
 
1029
                  set filtedit_add [expr {[string compare $subop add] == 0 ? 1 : 0}]
 
1030
                  set filtedit_onfiltcancel conf_process
 
1031
                  set script "fr_filtedit.tcl"
 
1032
                } elseif {[catch {wpGetVar addheader}] == 0} {
 
1033
 
 
1034
                  # load all the rules, process "headers"
 
1035
                  foreach pat [wpGetRulePattern] {
 
1036
                    set [lindex $pat 0] [lindex $pat 1]
 
1037
                    if {[string compare headers [lindex $pat 0]] == 0} {
 
1038
                      foreach h [set headers [lindex $pat 1]] {
 
1039
                        if {0 == [string length [lindex $h 0]]
 
1040
                            && 0 == [string length [lindex $h 1]]} {
 
1041
                          set emptyheader 1
 
1042
                        }
 
1043
                      }
 
1044
                      
 
1045
                      if {![info exists emptyheader]} {
 
1046
                        lappend headers [list {} {}]
 
1047
                      }
 
1048
                    }
 
1049
                  }
 
1050
 
 
1051
                  # load other variables
 
1052
                  wpGetVar nickname
 
1053
                  wpGetVar comment
 
1054
                  wpGetVarAs folder folder
 
1055
                  wpGetVarAs ftype ftype
 
1056
 
 
1057
                  set filterrtext 1
 
1058
                  set filtedit_score 1
 
1059
                  set filtedit_fno $fno
 
1060
                  set filtedit_add [expr {[string compare $subop add] == 0 ? 1 : 0}]
 
1061
                  set filtedit_onfiltcancel conf_process
 
1062
                  set script "fr_filtedit.tcl"
 
1063
                } else {
 
1064
                  switch -- $subop {
 
1065
                    edit -
 
1066
                    add {
 
1067
                      # load other variables
 
1068
                      wpGetVar nickname
 
1069
                      wpGetVar comment
 
1070
                      wpGetVarAs folder folder
 
1071
                      wpGetVarAs ftype ftype
 
1072
 
 
1073
                      set patlist [wpGetRulePattern]
 
1074
 
 
1075
                      lappend patlist [list nickname $nickname]
 
1076
                      lappend patlist [list comment $comment]
 
1077
 
 
1078
                      wpGetVar scoreval
 
1079
                      lappend actlist [list "scoreval" $scoreval]
 
1080
 
 
1081
                      wpGetVar scorehdr
 
1082
                      lappend actlist [list "scorehdr" $scorehdr]
 
1083
 
 
1084
                      set ret [catch {WPCmd PEConfig ruleset score $subop $fno $patlist $actlist} res]
 
1085
 
 
1086
                      if {$ret} {
 
1087
                        error [list _action "Score Set" $res]
 
1088
                      } elseif {[string length $res]} {
 
1089
                        WPCmd PEInfo statmsg "Score setting failed: $res"
 
1090
 
 
1091
                        set filtedit_score 1
 
1092
                        set filtedit_fno $fno
 
1093
                        set filtedit_add [expr {[string compare $subop add] == 0 ? 1 : 0}]
 
1094
                        set filtedit_onfiltcancel conf_process
 
1095
                        set script "fr_filtedit.tcl"
 
1096
                      }
 
1097
                    }
 
1098
                  }
 
1099
                }
 
1100
              }
 
1101
            }
 
1102
            indexcolorconfig {
 
1103
              wpGetVar fno [list _INTEGER_]
 
1104
              wpGetVar subop [list edit add]
 
1105
 
 
1106
              if {[catch {wpGetVar filtcancel}]} {
 
1107
                if {[catch {wpGetVar filthelp}] == 0} {
 
1108
                  catch {WPCmd PEInfo unset help_context}
 
1109
                  catch {WPCmd set oncancel $oncancel}
 
1110
                  if {[string compare $subop "edit"] == 0 || [string compare $subop "add"] == 0} {
 
1111
                    set patlist [wpGetRulePattern]
 
1112
 
 
1113
                    # we have to save this exactly as it would look when getting it from alpined
 
1114
                    set ftsadd [expr {[string compare $subop "add"] == 0 ? 1 : 0}]
 
1115
                    set ftsform [list [list "pattern" $patlist] [list "filtaction" $actlist]]
 
1116
                    catch {WPCmd set filttmpstate [list $ftsadd $fno $ftsform]}
 
1117
                  }
 
1118
                  set help_vars [list topic]
 
1119
                  set topic indexcoloredit
 
1120
                  set _cgi_uservar(topic) indexcoloredit
 
1121
                  switch -- $subop {
 
1122
                    edit {
 
1123
                      set fakeimg "vle.indexcolor.$fno"
 
1124
                      set fakesz [expr {$fno + 1}]
 
1125
                    }
 
1126
                    add  {
 
1127
                      set fakeimg "vla.indexcolor"
 
1128
                      set fakesz 1
 
1129
                    }
 
1130
                  }
 
1131
 
 
1132
                  set _cgi_uservar(oncancel) [WPPercentQuote "conf_process&wv=rule&indexcolor-sz=${fakesz}&${fakeimg}.x=1&${fakeimg}.y=1&oncancel=main.tcl"]
 
1133
                  set script help
 
1134
                } elseif {[set nv [numberedVar rmheader header_total]] >= 0} {
 
1135
 
 
1136
                  # load all the rules, process "headers"
 
1137
                  foreach pat [wpGetRulePattern] {
 
1138
                    set [lindex $pat 0] [lindex $pat 1]
 
1139
                    
 
1140
                    if {[string compare headers [lindex $pat 0]] == 0} {
 
1141
                      if {[llength $headers] > $nv} {
 
1142
                        set headers [lreplace $headers $nv $nv]
 
1143
                      }
 
1144
                    }
 
1145
                  }
 
1146
 
 
1147
                  # load other variables
 
1148
                  wpGetVar nickname
 
1149
                  wpGetVar comment
 
1150
                  wpGetVarAs folder folder
 
1151
                  wpGetVarAs ftype ftype
 
1152
 
 
1153
                  set filterrtext 1
 
1154
                  set filtedit_indexcolor 1
 
1155
                  set filtedit_fno $fno
 
1156
                  set filtedit_add [expr {[string compare $subop add] == 0 ? 1 : 0}]
 
1157
                  set filtedit_onfiltcancel conf_process
 
1158
                  set script "fr_filtedit.tcl"
 
1159
                } elseif {[catch {wpGetVar addheader}] == 0} {
 
1160
                  # load all the rules, process "headers"
 
1161
                  foreach pat [wpGetRulePattern] {
 
1162
                    set [lindex $pat 0] [lindex $pat 1]
 
1163
                    if {[string compare headers [lindex $pat 0]] == 0} {
 
1164
                      foreach h [set headers [lindex $pat 1]] {
 
1165
                        if {0 == [string length [lindex $h 0]]
 
1166
                            && 0 == [string length [lindex $h 1]]} {
 
1167
                          set emptyheader 1
 
1168
                        }
 
1169
                      }
 
1170
                      
 
1171
                      if {![info exists emptyheader]} {
 
1172
                        lappend headers [list {} {}]
 
1173
                      }
 
1174
                    }
 
1175
                  }
 
1176
 
 
1177
                  # load other variables
 
1178
                  wpGetVar nickname
 
1179
                  wpGetVar comment
 
1180
                  wpGetVarAs folder folder
 
1181
                  wpGetVarAs ftype ftype
 
1182
 
 
1183
                  set filterrtext 1
 
1184
                  set filtedit_indexcolor 1
 
1185
                  set filtedit_fno $fno
 
1186
                  set filtedit_add [expr {[string compare $subop add] == 0 ? 1 : 0}]
 
1187
                  set filtedit_onfiltcancel conf_process
 
1188
                  set script "fr_filtedit.tcl"
 
1189
                } elseif {[catch {cgi_import_as colormap.x colx}] == 0
 
1190
                          && [catch {cgi_import_as colormap.y coly}] == 0} {
 
1191
                  set rgbs {"000" "051" "102" "153" "204" "255"}
 
1192
                  set xrgbs {"00" "33" "66" "99" "CC" "FF"}
 
1193
                  set rgblen [llength $rgbs]
 
1194
                  set imappixwidth 10
 
1195
 
 
1196
                  set colx [expr {${colx} / $imappixwidth}]
 
1197
                  set coly [expr {${coly} / $imappixwidth}]
 
1198
                  if {($coly >= 0 && $coly < $rgblen)
 
1199
                      && ($colx >= 0 && $colx < [expr {$rgblen * $rgblen}])} {
 
1200
                    set ired $coly
 
1201
                    set igreen [expr {($colx / $rgblen) % $rgblen}]
 
1202
                    set iblue [expr {$colx % $rgblen}]
 
1203
                    set rgb "[lindex $rgbs $ired],[lindex $rgbs ${igreen}],[lindex $rgbs ${iblue}]"
 
1204
                    set xrgb "[lindex $xrgbs $ired][lindex $xrgbs ${igreen}][lindex $xrgbs ${iblue}]"
 
1205
 
 
1206
                    if {[catch {wpGetVar fgorbg [list fg bg]}]} {
 
1207
                      WPCmd PEInfo statmsg "Invalid fore/back ground input!"
 
1208
                      catch {unset xrgb}
 
1209
                    }
 
1210
                  } else {
 
1211
                    WPCmd PEInfo statmsg "Invalid RGB Input!"
 
1212
                  }
 
1213
 
 
1214
                  # relay any other config changes
 
1215
                  wpGetVar nickname
 
1216
                  wpGetVar comment
 
1217
                  wpGetVarAs folder folder
 
1218
                  wpGetVarAs ftype ftype
 
1219
                  foreach pat [wpGetRulePattern] {
 
1220
                    set [lindex $pat 0] [lindex $pat 1]
 
1221
                  }
 
1222
 
 
1223
                  # import previous settings
 
1224
                  wpGetVarAs fg fg
 
1225
                  wpGetVarAs bg bg
 
1226
 
 
1227
                  # set new value
 
1228
                  if {[info exists xrgb]} {
 
1229
                    set $fgorbg $xrgb
 
1230
                  }
 
1231
 
 
1232
                  set filterrtext 1
 
1233
                  set filtedit_indexcolor 1
 
1234
                  set filtedit_fno $fno
 
1235
                  set filtedit_add [expr {[string compare $subop add] == 0 ? 1 : 0}]
 
1236
                  set filtedit_onfiltcancel conf_process
 
1237
                  set script "fr_filtedit.tcl"
 
1238
                } else {
 
1239
                  switch -- $subop {
 
1240
                    edit -
 
1241
                    add {
 
1242
 
 
1243
                      wpGetVar nickname
 
1244
                      wpGetVar comment
 
1245
 
 
1246
                      set patlist [wpGetRulePattern]
 
1247
 
 
1248
                      lappend patlist [list nickname $nickname]
 
1249
                      lappend patlist [list comment $comment]
 
1250
 
 
1251
                      # save config?
 
1252
                      set actlist {}
 
1253
                      if {[catch {wpGetVar fg}] == 0 && [catch {wpGetVar bg}] == 0} {
 
1254
                        lappend actlist [list fg $fg]
 
1255
                        lappend actlist [list bg $bg]
 
1256
 
 
1257
                        # save rule
 
1258
                        set ret [catch {WPCmd PEConfig ruleset indexcolor $subop $fno $patlist $actlist} res]
 
1259
                        if {$ret} {
 
1260
                          error [list _action "Color Set Error" $res]
 
1261
                        } elseif {[string length $res]} {
 
1262
                          WPCmd PEInfo statmsg "Index Color setting failed: $res"
 
1263
 
 
1264
                          set filtedit_indexcolor 1
 
1265
                          set filtedit_fno $fno
 
1266
                          set filtedit_add [expr {[string compare $subop add] == 0 ? 1 : 0}]
 
1267
                          set filtedit_onfiltcancel conf_process
 
1268
                          set script "fr_filtedit.tcl"
 
1269
                        }
 
1270
                      } else {
 
1271
                        error [list _action "Unset FG/BG" "Internal Error: Unset Color Variables"]
 
1272
                      }
 
1273
                    }
 
1274
                  }
 
1275
                }
 
1276
              }
 
1277
            }
 
1278
            clconfig {
 
1279
              wpGetVar cl
 
1280
              wpGetVar nick
 
1281
              wpGetVar server
 
1282
              wpGetVar user
 
1283
              wpGetVar stype
 
1284
              wpGetVar path
 
1285
              wpGetVar view
 
1286
              wpGetVar add
 
1287
              wpGetVarAs cle_cancel.x cle_cancel
 
1288
              wpGetVarAs cle_save.x cle_save
 
1289
 
 
1290
              set cledit_add $add
 
1291
              set cledit_cl $cl
 
1292
              set cledit_onclecancel conf_process
 
1293
              if {[string length $cle_save]} {
 
1294
                if {[catch {cgi_import_as "ssl" sslval}]} {
 
1295
                  set ssl 0
 
1296
                } else {
 
1297
                  if {[string compare $sslval on] == 0} {
 
1298
                    set ssl 1
 
1299
                  } else {
 
1300
                    set ssl 0
 
1301
                  }
 
1302
                }
 
1303
                regexp "\{?(\[^\}\]*)\}?(.*)" $server match serverb serverrem
 
1304
                if {[string length $serverb]} {
 
1305
                  if {$ssl == 1} {
 
1306
                    set serverb "$serverb/ssl"
 
1307
                  }
 
1308
                  if {[string compare "" "$user"]} {
 
1309
                    set serverb "$serverb/user=$user"
 
1310
                  }
 
1311
                  if {[string compare "imap" [string tolower $stype]]} {
 
1312
                    set serverb "$serverb/[string tolower $stype]"
 
1313
                  }
 
1314
                  if {[string compare "nntp" [string tolower $stype]] == 0} {
 
1315
                    regsub -nocase {^(#news\.)?(.*)$} "$path" "#news.\\2" path
 
1316
                    if {[string compare "" $path] == 0} {
 
1317
                      set path "#news."
 
1318
                    }
 
1319
                  }
 
1320
                  set result ""
 
1321
                  set ret 0
 
1322
                  set servera "\{$serverb\}$serverrem"
 
1323
                  if {$add} {
 
1324
                    set ret [catch {WPCmd PEConfig cladd $cl $nick $servera $path $view} result]
 
1325
                  } else {
 
1326
                    set ret [catch {WPCmd PEConfig cledit $cl $nick $servera $path $view} result]
 
1327
                  }
 
1328
                  if {$ret != 0} {
 
1329
                    error [list _action "Collection List Set" $result]
 
1330
                  } elseif {[string compare "" $result]} {
 
1331
                    if {$add} {
 
1332
                      set clerrtext "Add failed: $result"
 
1333
                    } else {
 
1334
                      set clerrtext "Edit failed: $result"
 
1335
                    }
 
1336
                    WPCmd PEInfo statmsg $clerrtext
 
1337
                    set script "fr_cledit.tcl"
 
1338
                  }
 
1339
                } else {
 
1340
                  set clerrtext "Bad data: Nothing defined for Server"
 
1341
                  WPCmd PEInfo statmsg $clerrtext
 
1342
                  set script "fr_cledit.tcl"
 
1343
                }
 
1344
              }
 
1345
            }
 
1346
            noop {
 
1347
                catch {WPCmd PEInfo noop}
 
1348
            }
 
1349
            cancel {
 
1350
              set script $oncancel
 
1351
              catch {WPCmd unset conf_page} res
 
1352
            }
 
1353
            default {
 
1354
                error [list _close "Unknown process operation: $op"]
 
1355
            }
 
1356
        }
 
1357
 
 
1358
source [WPTFScript $script]