1# $Id: ldappick.tcl 1204 2009-02-02 19:54:23Z hubert@u.washington.edu $
2# ========================================================================
3# Copyright 2006 University of Washington
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# ========================================================================
12
13#  ldappick.tcl
14#
15#  Purpose:  CGI script to handle LDAP result choices from the
16#	     via the LDAP result browser generated form
17
18#  Input:
19set pick_vars {
20  {cid		"Missing Command ID"}
21  {field	"Missing Field Name"}
22  {ldapquery	"Missing LDAP Query"}
23  {ldapList	""	""}
24  {addresses	""	""}
25  {addrop	{}	""}
26  {cancel	{}	0}
27}
28
29#  Output:
30#
31
32# read vars
33foreach item $pick_vars {
34  if {[catch {cgi_import [lindex $item 0].x}]} {
35    if {[catch {eval WPImport $item} result]} {
36      error [list _action "Impart Variable" $result]
37    }
38  } else {
39    set [lindex $item 0] 1
40  }
41}
42
43if {$cid != [WPCmd PEInfo key]} {
44  catch {WPCmd PEInfo statmsg "Invalid Command ID"}
45}
46
47if {$cancel != 1 && !([string compare cancel [string tolower $cancel]] == 0 || [string compare cancel [string tolower $addrop]] == 0) && [string length $ldapList] > 0} {
48  set ldapListStr [join $ldapList ","]
49  if {[catch {WPCmd PELdap setaddrs $ldapquery $ldapListStr $addresses 0} newaddrlist]} {
50    WPCmd PEInfo statmsg "LDAP Error: $newaddrlist"
51  } else {
52    regsub -all "'" $newaddrlist "\\'" newaddrs
53
54    if {[catch {WPCmd PEInfo set suspended_composition} msgdata]} {
55      WPCmd PEInfo statmsg "Cannot read message data: $msgdata"
56    } else {
57      if {[info exists newaddrs]} {
58	for {set i 0} {$i < [llength $msgdata]} {incr i} {
59	  set orig_field [lindex [lindex $msgdata $i] 0]
60	  regsub -all -- - [string tolower $orig_field] _ fn
61
62	  if {[string compare $fn $field] == 0} {
63	    set msgdata [lreplace $msgdata $i $i [list $orig_field $newaddrs]]
64	    break
65	  }
66	}
67
68	if {[catch {WPCmd PEInfo set suspended_composition $msgdata} result]} {
69	  WPCmd PEInfo statmsg "Cannot Update $field field: $result"
70	}
71      }
72    }
73  }
74}
75
76source [WPTFScript compose]
77