summaryrefslogtreecommitdiff
path: root/web/cgi/alpine/2.0/conduit/flag.tcl
blob: a20225cd2bf271301015497ffc698fb3bad3fa34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!./tclsh
# $Id: flag.tcl 1204 2009-02-02 19:54:23Z hubert@u.washington.edu $
# ========================================================================
# Copyright 2008 University of Washington
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# ========================================================================

#  flag
#
#  Purpose:  CGI script generating response to xmlHttpRequest
#
#  Input:    
#            
set flag_args {
  {u	{}	""}
  {f	{}	""}
  {s	{}	""}
}

# inherit global config
source ../alpine.tcl

WPEval $flag_args {
  cgi_body {
    switch -- $f {
      {new} -
      {imp} {
	set flag $f
      }
      default {
      }
    }

    switch -- $s {
      ton -
      not {
	set state $s
      }
      default {
      }
    }

    if {[info exists flag] && [info exists state]} {
      regsub -all {,} $u { } u
      if {[regexp {^[ 0123456789]*$} $u]} {
	switch $state {
	  ton { set state 1 }
	  not { set state 0 }
	}
	switch $flag {
	  imp { set flag important }
	}

	foreach eu $u {
	  if {[catch {WPCmd PEMessage $eu flag $flag $state} result]} {
	    set result "FAILURE: setting $eu to $setting : $result"
	    break
	  }
	}
      } elseif {0 == [string compare $u all]} {
	if {[catch {WPCmd PEMailbox flag $state $flag} result]} {
	  set result "FAILURE: flag $state $flag : $result"
	}
      }
    } else {
      set result "FAILURE: unknown flag ($f) or state ($s)"
    }

    cgi_puts $result
  }
}