timoh
committed
on 14 Dec 05
fixed typo
/lib/glossar-portlet-list.tcl (+35 -37)
1 1 # packages/glossar/lib/glossar-portlet-list.tcl
2 2 #
3 3 # Creates a list of all glossars that belong to this Customer, direct and indirect (Etat)
4 4 #
5 5 # @author Bjoern Kiesbye (bjoern_kiesbye@web.de)
6 6 # @creation-date 2005-07-29
7 7 # @arch-tag: 4324b14c-cb5d-4512-b56d-0e0ab10ff025
8 8 # @cvs-id $Id$
9 9
10   foreach required_param {owner_ids} {
  10 foreach required_param {owner_id} {
11 11     if {![info exists $required_param]} {
12 12         return -code error "$required_param is a required parameter."
13 13     }
14 14 }
15   foreach optional_param {gl_format gl_customer_id gl_orderby} {
  15 foreach optional_param {gl_format gl_orderby} {
16 16     if {![info exists $optional_param]} {
17 17         set $optional_param {}
18 18     }
19 19 }
20 20
21 21
22 22 set base_url [dotlrn_community::get_community_url \
23 23                   [dotlrn_community::get_community_id_from_url] \
24 24                  ]
25 25
26   set glossar_id "0"
27  
28   set gl_translation_p 0
29 26 set page_size 100
30 27 set base_url "glossar"
  28 set user_id [ad_conn user_id]
31 29
32   if [empty_string_p "[ad_conn user_id]"] {
  30 if {[empty_string_p $user_id]} {
33 31     ad_redirect_for_registration
34 32 }
35 33
36   set customer_id [lindex  $owner_ids 0]
37   set where_etat_ids [join [lrange $owner_ids 1 [llength $owner_ids]] "','" ]
38   set actions ""
39   ns_log notice "WHERE $where_etat_ids , owner $customer_id "
  34 if {[goup::member_p -user_id $user_id -group_name Customer]} {
  35     # owner is customer
  36     set customer_id $owner_id
  37     set query_name gl_glossar_portlet_customer
  38 } else {
  39     # owner is etat
  40     set etat_id $owner_id
  41     set query_name gl_glossar_portlet_etat
  42 }
40 43
41   # We check if the owner_id is an relation, if it is, the real_owner_id
  44 # We check if the owner_id is a relation, if it is, the real_owner_id
42 45 # becomes the eta_id stored in gl_glossars, else it becomes the
43 46 # owner_id which can be a customer_id or a etat_id.
44 47 # We still pass on the owner_id to check permission.
45 48 # Only if the owner_id is an relation we have two id's an etat_id
46 49 # (glossar owner) and an extra custommer_id which is stored in
47 50 # gl_glossar_terms to indicate which terms of a glossar , owned by a
48 51 # etat,  belong to a specific customer.
49   # This results into thre possible displays.
  52 # This results into three possible displays.
50 53 # 1. owner_id is a customer_id (all glossars , owned by customer_id,
51 54 #    with all terms will be displayed)
52 55 #
53 56 # 2. owner_id is a etat_id (all glossars, owened by etat_id, with all
54 57 #    terms will be displayed, while each term indicates to which
55 58 #    customer(_id) it belongs (happens if the term was added by a
56 59 #    relation), none if it belongs to the etat directly (happens if the
57 60 #    term was added by a etat) )
58 61 #
59 62 # 3. owner_id is a relation_id (all glossars, owned by the etat_id
60 63 #    which is stored in the relations object_id_one column, with all
61 64 #    terms having a customer_id, equal to the relations object_id_two.    
62   #    Question: Should it be possible to to display all glossars
63   #    owned by the relations object_id_two (custommer_id) including all
  65 #    Question: Should it be possible to display all glossars
  66 #    owned by the relations object_id_two (customer_id) including all
64 67 #    terms as well?
65 68
66 69
67 70   
68 71 # This lib file deals with 1. and 2. only.
69 72
70 73 # No actions just a list of glossars
71 74
72   #set actions [list "[_ glossar.New_Lecture]" [export_vars -base "${base_url}/glossar-add" {owner_id gl_translation_p }] "[_ glossar.New_Lecture]"]
  75 set actions [list "[_ glossar.New_Lecture]" [export_vars -base "${base_url}/glossar-add" {owner_id gl_translation_p }] "[_ glossar.New_Lecture]"]
73 76
74   set gl_translation_p 1
  77 lappend actions "[_ glossar.New_Translation]" [export_vars -base "${base_url}/glossar-add" {owner_id gl_translation_p }] "[_ glossar.Add_New_Translation]"
75 78
76   #lappend actions "[_ glossar.New_Translation]" [export_vars -base "${base_url}/glossar-add" {owner_id gl_translation_p }] "[_ glossar.Add_New_Translation]"
77 79
  80 set row_list [list name {} title {} description {} source_category {} target_category {} glossar_edit {} glossar_files {}]
78 81
79   set row_list [list name title description source_category target_category glossar_edit glossar_files]
80  
81 82 # Just check permission on the first owner_id (the current customer)
82 83 set no_perm_p 0
83 84
84   if [permission::permission_p -object_id $customer_id -privilege admin] {
  85 if [permission::permission_p -object_id $owner_id -privilege admin] {
85 86
86   } elseif {[permission::permission_p -object_id $customer_id -privilege create]} {
  87 } elseif {[permission::permission_p -object_id $owner_id -privilege create]} {
87 88
88 89     set user_perm create
89 90
90   } elseif {[permission::permission_p -object_id $customer_id -privilege read]} {
  91 } elseif {[permission::permission_p -object_id $owner_id -privilege read]} {
91 92
92 93     set actions ""
93       set row_list [list name title description source_category target_category]
  94     set row_list [list name {} title {} description {} source_category {} target_category {}]
94 95
95 96 } else {
96 97
97 98     set no_perm_p 1
98 99     set no_perm  "You don't have Permission to read Glossars !"
99 100
100 101
101 102 }
102 103
103   set owner_id 0
104 104 if {$no_perm_p == 0} {
105 105
106 106 template::list::create \
107 107     -name gl_glossar_portlet \
108 108     -key glossar_id \
109 109     -no_data "[_ glossar.None]" \
110 110     -selected_format $gl_format \
111       -pass_properties {customer_id owner_ids edit_link } \
  111     -pass_properties {owner_id edit_link } \
112 112     -elements {
113 113         name {
114 114             label {[_ glossar.Organization_Name]}
115 115             display_template "<a href=\"@gl_glossar_portlet.new_glossar@\">@gl_glossar_portlet.name@</a>"
116 116         }
117 117         title {
118 118             label {[_ glossar.Title]}
119 119             display_template "<a href=\"@gl_glossar_portlet.title_url@\">@gl_glossar_portlet.title@</a>"
120 120         }
121 121         description {
122 122             label {[_ glossar.glossar_description]}
123 123         }
124 124         source_category {
125 125             label {[_ glossar.glossar_source_category_header]}
126 126         }
127 127         target_category {
128 128             label {[_ glossar.glossar_target_category]}
129 129         }
130 130         glossar_edit {
131               display_template "<a href=\"@gl_glossar_portlet.edit_url@\">[_ acs-kernel.common_Edit]</a>"
  131             display_template {<a href="@gl_glossar_portlet.edit_url@"><img border="0" src="/shared/images/Edit16.gif" alt="#acs-kernel.common_Edit#" /></a>}
132 132         }       
133 133         glossar_files {
134 134             display_template "<a href=\"@gl_glossar_portlet.files_url@\">[_ glossar.Files]</a>"
135 135         }       
136 136
137 137     } -actions $actions -sub_class narrow \
138 138     -orderby {
139 139         default_value title
140 140         glossar_id {
141 141             label {[_ glossar.glossar_id]}
142 142             orderby_desc {sort_key asc , glossar_id desc}
143 143             orderby_asc {sort_key asc , glossar_id asc}
144 144             default_direction desc
145 145         }
146 146         title {
147 147             label {[_ glossar.glossar_title]}
148               orderby_desc {sort_key asc , title desc}
149               orderby_asc {sort_key asc , title asc}
  148             orderby_desc {sort_key asc, lower(title) desc}
  149             orderby_asc {sort_key asc, lower(title) asc}
150 150             default_direction asc
151 151         }
152 152     }  -orderby_name orderby \
153 153     -filters {
154           customer_id {}
  154         owner_id {}
155 155         edit_link {}
156 156     } \
157 157     -formats {
158 158         normal {
159 159             label "[_ acs-templating.Table]"
160 160             layout table
161 161             elements $row_list
162 162         }
163 163         csv {
164 164             label "[_ acs-templating.CSV]"
165 165             output csv
166 166             page_size 0
167 167             row
168 168         }
169 169     }
170 170
171 171
172   set static_customer_id $customer_id
173  
174   db_multirow -extend {source_category target_category gl_translation_p glossar_edit glossar_files files_url edit_url title_url new_glossar} gl_glossar_portlet gl_glossar_portlet  {} {
  172 db_multirow -extend {source_category target_category gl_translation_p glossar_edit glossar_files files_url edit_url title_url new_glossar} gl_glossar_portlet $query_name  {} {
175 173     if {![empty_string_p $target_category_id]} {
176 174         set gl_translation_p 1
177 175     } else {
178 176         set gl_translation_p 0
179 177     }
180 178     set glossar_edit "[_ glossar.glossar_Edit]"
181 179     set glossar_files "[_ glossar.files]"
182 180     set source_category "[category::get_name $source_category_id]"
183 181     set target_category "[category::get_name $target_category_id]"
184       set title_url "[export_vars -base "${base_url}/glossar-term-list" {glossar_id gl_translation_p customer_id owner_id}]"
  182     set title_url "[export_vars -base "${base_url}/glossar-term-list" {glossar_id gl_translation_p owner_id}]"
185 183     set edit_url "[export_vars -base "${base_url}/glossar-add" {owner_id glossar_id gl_translation_p }]"
186 184     set files_url "[export_vars -base "${base_url}/glossar-file-upload" {glossar_id}]"
187       if {$customer_id == $owner_id} {
  185     if {$gl_owner_id == $owner_id} {
188 186         set new_glossar "[export_vars -base "${base_url}/index" {owner_id}]"
189 187     } else {
190           set new_glossar "[export_vars -base "${base_url}/index" {owner_id customer_id}]"
  188         set new_glossar "[export_vars -base "${base_url}/index" {owner_id {customer_id $gl_owner_id}}]"
191 189     }
192 190 } if_no_rows {
193 191
194 192
195 193 }
196 194
197 195 }