61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
|
# File 'lib/args-handler.rb', line 61
def self.input(args)
if args.key?(:value)
if args[:value].is_a?(Array) and (args[:value].first.is_a?(NilClass) or args[:value].first == false)
value = nil
elsif args[:value].is_a?(Array)
if !args[:value][2] or args[:value][2] == :key
value = args[:value].first[args[:value][1]]
elsif args[:value][2] == :callb
value = args[:value].first.send(args[:value][1])
else
value = args[:value]
end
elsif args[:value].is_a?(String) or args[:value].is_a?(Integer)
value = args[:value].to_s
else
value = args[:value]
end
end
args[:value_default] = args[:default] if args[:default]
if value.is_a?(NilClass) and args[:value_default]
value = args[:value_default]
elsif value.is_a?(NilClass)
value = ""
end
if value and args.key?(:value_func) and args[:value_func]
cback = args[:value_func]
if cback.is_a?(Method)
value = cback.call(value)
elsif cback.is_a?(Array)
value = Php4r.call_user_func(args[:value_func], value)
elsif cback.is_a?(Proc)
value = cback.call(value)
else
raise "Unknown class: #{cback.class.name}."
end
end
value = args[:values] if args[:values]
args[:id] = args[:name] if !args[:id]
if !args[:type]
if args[:opts]
args[:type] = :select
elsif args[:name] and args[:name].to_s[0..2] == "che"
args[:type] = :checkbox
elsif args[:name] and args[:name].to_s[0..3] == "file"
args[:type] = :file
else
args[:type] = :text
end
else
args[:type] = args[:type].to_sym
end
attr = {
"name" => args[:name],
"id" => args[:id],
"type" => args[:type],
"class" => "input_#{args[:type]}"
}
attr.merge!(args[:attr]) if args[:attr]
attr["disabled"] = "disabled" if args[:disabled]
attr["maxlength"] = args[:maxlength] if args.key?(:maxlength)
raise "No name given to the ArgsHandler::input()-method." if !args[:name] and args[:type] != :info and args[:type] != :textshow and args[:type] != :plain and args[:type] != :spacer and args[:type] != :headline
css = {}
css["text-align"] = args[:align] if args.key?(:align)
css.merge!(args[:css]) if args.key?(:css)
attr_keys = [:onchange]
attr_keys.each do |tag|
if args.key?(tag)
attr[tag] = args[tag]
end
end
classes_tr = []
classes_tr += args[:classes_tr] if args[:classes_tr]
tr_attrs = {}
label_attrs = {}
td_attrs = {
:class => :tdc
}
if !args[:id].to_s.empty?
tr_attrs[:id] = "#{args[:id]}_tr"
td_attrs[:id] = "#{args[:id]}_content"
label_attrs[:for] = args[:id]
end
if !classes_tr.empty?
classes_tr_html = " class=\"#{classes_tr.join(" ")}\""
else
classes_tr_html = ""
end
if args.key?(:title)
title_html = html_escape(args[:title])
elsif args.key?(:title_html)
title_html = args[:title_html]
end
html = ""
classes = ["input_#{args[:type]}"]
classes = classes | args[:classes] if args.key?(:classes)
attr["class"] = classes.join(" ")
if args[:type] == :checkbox
attr["value"] = args[:value_active] if args.key?(:value_active)
attr["checked"] = "checked" if value.is_a?(String) and value == "1" or value.to_s == "1" or value.to_s == "on" or value.to_s == "true"
attr["checked"] = "checked" if value.is_a?(TrueClass)
html << "<tr#{classes_tr_html}>"
html << "<td colspan=\"2\" class=\"tdcheck\">"
html << "<input#{self.attr_html(attr)} />"
html << "<label#{attr_html(label_attrs)}\">#{title_html}</label>"
html << "</td>"
html << "</tr>"
elsif args[:type] == :headline
html << "<tr#{classes_tr_html}><td colspan=\"2\"><h2 class=\"input_headline\">#{title_html}</h2></td></tr>"
elsif args[:type] == :spacer
html << "<tr#{classes_tr_html}><td colspan=\"2\"> </td></tr>"
else
html << "<tr#{classes_tr_html}#{attr_html(tr_attrs)}>"
html << "<td class=\"tdt\" id=\"#{html_escape("#{args[:id]}_label")}\"><div><label>"
html << title_html
html << "</label></div></td>"
html << "<td#{self.style_html(css)}#{attr_html(td_attrs)}><div>"
if args[:type] == :textarea
if args.key?(:height)
if (Float(args[:height]) rescue false)
css["height"] = "#{args[:height]}px"
else
css["height"] = args[:height]
end
end
attr["class"] = "input_textarea"
attr["name" ] = args[:name]
attr["id"] = args[:id]
attr.delete("type")
html << "<textarea#{self.style_html(css)}#{self.attr_html(attr)}>#{value}</textarea>"
elsif args[:type] == :fckeditor
args[:height] = 400 if !args[:height]
require "/usr/share/fckeditor/fckeditor.rb" if !Kernel.const_defined?(:FCKeditor)
fck = FCKeditor.new(args[:name])
fck.Height = args[:height].to_i
fck.Value = value
html << fck.CreateHtml
elsif args[:type] == :ckeditor
args[:height] = 400 if !args[:height]
require "ckeditor4ruby" if !Kernel.const_defined?(:CKEditor)
ck = CKEditor.new
ck.return_output = true
html << ck.editor(args[:name], value)
elsif args[:type] == :select
attr[:multiple] = "multiple" if args[:multiple]
attr[:size] = args[:size] if args[:size]
html << "<select#{self.attr_html(attr)}>"
html << ArgsHandler.opts(args[:opts], value, args[:opts_args])
html << "</select>"
if args[:moveable]
html << "<div style=\"padding-top: 3px;\">"
html << "<input type=\"button\" value=\"#{_("Up")}\" onclick=\"select_moveup($('##{args[:id]}'));\" />"
html << "<input type=\"button\" value=\"#{_("Down")}\" onclick=\"select_movedown($('##{args[:id]}'));\" />"
html << "</div>"
end
elsif args[:type] == :imageupload
html << "<table class=\"designtable\"><tr#{classes_tr_html}><td style=\"width: 100%;\">"
html << "<input type=\"file\" name=\"#{args[:name].html}\" class=\"input_file\" />"
html << "</td><td style=\"padding-left: 5px;\">"
raise "No path given for imageupload-input." if !args.key?(:path)
raise "No value given in arguments for imageupload-input." if !args.key?(:value)
path = args[:path].gsub("%value%", value.to_s).untaint
if File.exists?(path)
html << "<img src=\"image.rhtml?path=#{html_escape(self.urlenc(path))}&smartsize=100&rounded_corners=10&border_color=black&force=true&ts=#{Time.new.to_f}\" alt=\"Image\" />"
if args[:dellink]
dellink = args[:dellink].gsub("%value%", value.to_s)
html << "<div style=\"text-align: center;\">(<a href=\"javascript: if (confirm('#{_("Do you want to delete the image?")}')){location.href='#{dellink}';}\">#{_("delete")}</a>)</div>"
end
end
html << "</td></tr></table>"
elsif args[:type] == :file
attr["type"] = args[:type]
attr["class"] = "input_#{args[:type]}"
attr["name"] = args[:name]
html << "<input#{self.attr_html(attr)} />"
elsif args[:type] == :textshow or args[:type] == :info
html << value.to_s
elsif args[:type] == :plain
html << "#{Php4r.nl2br(html_escape(value))}"
elsif args[:type] == :editarea
css["width"] = "100%"
css["height"] = args[:height] if args.key?(:height)
attr["id"] = args[:id]
attr["name"] = args[:name]
html << "<textarea#{self.attr_html(attr)}#{self.style_html(css)}>#{value}</textarea>"
jshash = {
"id" => args[:id],
"start_highlight" => true
}
pos_keys = [:skip_init, :allow_toggle, :replace_tab_by_spaces, :toolbar, :syntax]
pos_keys.each do |key|
jshash[key.to_s] = args[key] if args.key?(key)
end
html << "<script type=\"text/javascript\">"
html << "function knj_web_init_#{args[:name]}(){"
html << "editAreaLoader.init(#{Php4r.json_encode(jshash)});"
html << "}"
html << "</script>"
elsif args[:type] == :numeric
attr[:type] = :text
attr[:value] = value
html << "<input#{self.attr_html(attr)} />"
else
attr[:value] = value
html << "<input#{self.attr_html(attr)} />"
end
html << "</div></td></tr>"
end
html << "<tr#{classes_tr_html}><td colspan=\"2\" class=\"tdd\">#{args[:descr]}</td></tr>" if args[:descr]
html = html.html_safe if html.respond_to?(:html_safe)
return html
end
|