-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform_chsetdom.php
454 lines (310 loc) · 16.4 KB
/
form_chsetdom.php
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
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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
<?php
//form charset
$form_chset = new MyFormDom($htd->get_dom(), "form_chset", $_SERVER['REQUEST_URI']);
$form_chset->set_get_string('charset');
$form_chset->add_text_element('h2', 'Specify the character set:');
$form_chset->add_text("Choose: ");
$form_chset->add_br();
$form_chset->add_br();
//space choice part...
$space_chbox = $form_chset->add_input_element("checkbox", "space_chbox");
$space_chbox->setAttribute("value", "spaceok");
//not checked by default
$space_chbox->setAttribute("onchange", "disableSend(this)"); //send not available when changed
$form_chset->add_text(" include space (not recomended)");
$form_chset->add_br();
$form_chset->add_br();
//littles choice part...
$littles_chbox = $form_chset->add_input_element("checkbox", "littles_chbox");
$littles_chbox->setAttribute("value", "littleseok");
$form_chset->set_attr_novalue("littles_chbox", "checked");
//checked by default
$littles_chbox->setAttribute("onclick", "chbox_sel_checked(this)");
$littles_chbox->setAttribute("onchange", "disableSend(this)"); //send not available when changed
$form_chset->add_text(" include small letters - from ");
$ls = $_SESSION['CG']->chsbuilder->give_littles();
$littles_first_select = $form_chset->add_sametype_element("select", "l_first_sel");
$form_chset->add_children_from_array("l_first_sel", "option", $ls);
$littles_first_select->setAttribute("onchange", "disableSend(this);checkOrder(this);"); //send not available when changed
$form_chset->add_text(" to ");
$littles_last_select = $form_chset->add_sametype_element("select", "l_last_sel");
$form_chset->add_children_from_array("l_last_sel", "option", $ls);
$form_chset->set_child_attr_by_chindex("l_last_sel", "option", 25, "selected", "selected");
//25 - z - 26 from 0
$littles_last_select->setAttribute("onchange", "disableSend(this);checkOrder(this);"); //send not available when changed
$form_chset->add_br();
$form_chset->add_br();
//CAPS choice part...
$caps_chbox = $form_chset->add_input_element("checkbox", "caps_chbox");
$caps_chbox->setAttribute("value", "capsok");
$form_chset->set_attr_novalue("caps_chbox", "checked");
//checked by default
$caps_chbox->setAttribute("onclick", "chbox_sel_checked(this)");
$caps_chbox->setAttribute("onchange", "disableSend(this)"); //send not available when changed
$form_chset->add_text(" include CAPITAL letters - from ");
$cs = $_SESSION['CG']->chsbuilder->give_CAPS();
$caps_first_select = $form_chset->add_sametype_element("select", "c_first_sel");
$form_chset->add_children_from_array("c_first_sel", "option", $cs);
$caps_first_select->setAttribute("onchange", "disableSend(this);checkOrder(this);"); //send not available when changed
$form_chset->add_text(" to ");
$caps_last_select = $form_chset->add_sametype_element("select", "c_last_sel");
$form_chset->add_children_from_array("c_last_sel", "option", $cs);
$form_chset->set_child_attr_by_chindex("c_last_sel", "option", 25, "selected", "selected");
//25 - Z - 26 from 0
$caps_last_select->setAttribute("onchange", "disableSend(this);checkOrder(this);"); //send not available when changed
$form_chset->add_br();
$form_chset->add_br();
//digits choice part...
$digits_chbox = $form_chset->add_input_element("checkbox", "digits_chbox");
$digits_chbox->setAttribute("value", "digitsok");
$form_chset->set_attr_novalue("digits_chbox", "checked");
//checked by default
$digits_chbox->setAttribute("onchange", "disableSend(this)"); //send not available when changed
$form_chset->add_text(" include digits ");
$form_chset->add_entity_ref('ensp'); //bigger than nbsp; html4/5
//specials choice part...
$specials_chbox = $form_chset->add_input_element("checkbox", "specials_chbox");
$specials_chbox->setAttribute("value", "specialsok");
$form_chset->set_attr_novalue("specials_chbox", "checked");
//checked by default
$specials_chbox->setAttribute("onchange", "disableSend(this)"); //send not available when changed
$form_chset->add_text(" include special characters ");
//help link
$space_span = $form_chset->add_text_element("span", " ");
$space_span->setAttribute("style", "letter-spacing: 200px;");
//omitting setVar...
$help_link = $form_chset->add_text_element('a', ' Help ');
$help_link->setAttribute('href', '');
$help_link->setAttribute('onclick', "helpOpen(allhelpurl); return false;");
$help_link->setAttribute("style", "position:relative; left:155px; font-style:italic;font-weight:bold;font-size:125%;");
$form_chset->add_br();
$form_chset->add_br();
//excluded choice part...
$form_chset->add_text("exclude: ");
$excluded_edit = $form_chset->add_input_element("text", "excluded_edit");
$excluded_edit->setAttribute("size", "95");
$excluded_edit->setAttribute("oninput", "disableSend(this)"); //send not available when input (oninput)
$form_chset->add_br();
$form_chset->add_br();
setVar('charsetInputs', '["space_chbox", "littles_chbox", "l_first_sel", "l_last_sel", "caps_chbox", "c_first_sel", "c_last_sel", "digits_chbox", "specials_chbox", "excluded_edit"]');
setVar('chboxes_selects', '{"littles_chbox": ["l_first_sel", "l_last_sel"], "caps_chbox": ["c_first_sel", "c_last_sel"]}');
//preview submit...
$form_chset->add_entity_ref('ensp');
$preview_submit = $form_chset->add_input_element("submit", "previewchset"); //needs a callable
$preview_submit->setAttribute("value", "Preview it");
//dialog jquery
$pdiv = $form_chset->add_sametype_element("div", "pdialog");
$pdiv_text = $form_chset->add_text_element("p", "Paste or type your character set...");
$pdiv->appendChild($pdiv_text);
$pdiv_memo = $form_chset->add_sametype_element("textarea", "pdiv_memo");
$pdiv_memo->setAttribute("cols", "60");
$pdiv_memo->setAttribute("rows", "10");
$pdiv->appendChild($pdiv_memo);
//d jq
//remains of dialog...
$your_chset_button = $form_chset->add_input_element("button", "yourchsetbutton");
$your_chset_button->setAttribute("value","Type or paste your character set");
//$your_chset_button->setAttribute("onclick", "dialogOpn()");
$form_chset->add_br();
//r o d
$form_chset->add_br();
$form_chset->add_br();
//preview memo...
$form_chset->add_text("Preview of your choice: ");
$ccharset_memo = $form_chset->add_sametype_element("textarea", "ccharset_memo");
$ccharset_memo->setAttribute("cols", "60");
$ccharset_memo->setAttribute("rows", "10");
$form_chset->set_attr_novalue("ccharset_memo", "readonly");
//shuffle submit
$shuffle_submit = $form_chset->add_input_element("submit", "shufflechset"); //needs a callable...
$shuffle_submit->setAttribute("value", "Shuffle the character set...");
$form_chset->add_br();
$form_chset->add_br();
//send button
$form_chset->add_entity_ref('ensp');
$send_button = $form_chset->add_input_element("button", "sendbtn");
$send_button->setAttribute("value", "Send");
$req_scheme = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
$send_button->setAttribute("onclick", "window.location.href='" . "$req_scheme://${_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}?form=generate" . "'");
//callables..
//helpers
$form_set_needs_controls = function($form) { //it means controls to needs
//setting needs controls
if (!$_SESSION['CG']->chsbuilder->check_needs_empty()) return; //only space and/or excluded
filelog("IN F_CHSet_INIT: before setting needs controls: " . print_r($_SESSION['CG']->chsbuilder->show_needs(), true));
//space
if ($_SESSION['CG']->chsbuilder->get_a_need('space'))
$form->set_attr_novalue("space_chbox", "checked");
else
$form->get_dom()->getElementByID("space_chbox")->removeAttribute("checked");
//littles
if ($need_littles = $_SESSION['CG']->chsbuilder->get_a_need('littles')) {
$form->set_attr_novalue("littles_chbox", "checked");
//phpAlert('before set selected');
$form->set_child_attr_by_chvalattr("l_first_sel", "option", $need_littles[0], "selected", "selected");
$form->get_dom()->getElementByID("l_first_sel")->removeAttribute("disabled");
$form->set_child_attr_by_chvalattr("l_last_sel", "option", $need_littles[-1], "selected", "selected");
$form->get_dom()->getElementByID("l_last_sel")->removeAttribute("disabled");
//phpAlert('end of set selected');
}
else {
$form->get_dom()->getElementByID("littles_chbox")->removeAttribute("checked");
$form->set_attr_novalue("l_first_sel", "disabled");
$form->set_attr_novalue("l_last_sel", "disabled");
filelog("IN F_CHSet_INIT: after setting trying to uncheck littles...");
}
//CAPS
if ($need_CAPS = $_SESSION['CG']->chsbuilder->get_a_need('CAPS')) {
$form->set_attr_novalue("caps_chbox", "checked");
$form->set_child_attr_by_chvalattr("c_first_sel", "option", $need_CAPS[0], "selected", "selected");
$form->get_dom()->getElementByID("c_first_sel")->removeAttribute("disabled");
$form->set_child_attr_by_chvalattr("c_last_sel", "option", $need_CAPS[-1], "selected", "selected");
$form->get_dom()->getElementByID("c_last_sel")->removeAttribute("disabled");
}
else {
$form->get_dom()->getElementByID("caps_chbox")->removeAttribute("checked");
$form->set_attr_novalue("c_first_sel", "disabled");
$form->set_attr_novalue("c_last_sel", "disabled");
filelog("IN F_CHSet_INIT: after setting trying to uncheck caps...");
}
//digits
if ($_SESSION['CG']->chsbuilder->get_a_need('digits'))
$form->set_attr_novalue("digits_chbox", "checked");
else
$form->get_dom()->getElementByID("digits_chbox")->removeAttribute("checked");
//specials
if ($_SESSION['CG']->chsbuilder->get_a_need('specials'))
$form->set_attr_novalue("specials_chbox", "checked");
else
$form->get_dom()->getElementByID("specials_chbox")->removeAttribute("checked");
//exclude
$need_exclude = $_SESSION['CG']->chsbuilder->get_a_need('exclude');
if (strlen($need_exclude))
$form->get_dom()->getElementByID("excluded_edit")->setAttribute("value", $need_exclude);
else
$form->get_dom()->getElementByID("excluded_edit")->setAttribute("value", "");
}; //closure form_set_needs_controls
$form_chset->add_helper_callable('setneedscontrols', $form_set_needs_controls); //it means controls to needs
$form_set_needs2current_controls = function($form) { //it means needs to current controls
//literary copied from preview_call (indent too)
if ($_SESSION['CG']->chsbuilder->sniff_charsetstr()) $_SESSION['CG']->chsbuilder->reset_charsetstr();
//building charset in chsbuilder & setting needs
try {
//space
if (isset($_POST['space_chbox'])) {
$_SESSION['CG']->chsbuilder->set_a_need('space', true);
}
else $_SESSION['CG']->chsbuilder->set_a_need('space', false);
//littles
if (isset($_POST['littles_chbox'])) {
$form->get_dom()->getElementByID("l_first_sel")->removeAttribute("disabled");
$form->get_dom()->getElementByID("l_last_sel")->removeAttribute("disabled");
//selects are important to be enabled when the chbox is on and nonsense otherwise
$_SESSION['CG']->chsbuilder->set_a_need('littles', implode([$_POST['l_first_sel'], $_POST['l_last_sel']]));
}
else {
$form->set_attr_novalue("l_first_sel", "disabled");
$form->set_attr_novalue("l_last_sel", "disabled"); //see above
$_SESSION['CG']->chsbuilder->set_a_need('littles', false);
}
//CAPS
if (isset($_POST['caps_chbox'])) {
$form->get_dom()->getElementByID("c_first_sel")->removeAttribute("disabled");
$form->get_dom()->getElementByID("c_last_sel")->removeAttribute("disabled");
//see littles
$_SESSION['CG']->chsbuilder->set_a_need('CAPS', implode([$_POST['c_first_sel'], $_POST['c_last_sel']]));
}
else {
$form->set_attr_novalue("c_first_sel", "disabled");
$form->set_attr_novalue("c_last_sel", "disabled");
$_SESSION['CG']->chsbuilder->set_a_need('CAPS', false);
}
//digits
if (isset($_POST['digits_chbox'])) {
$_SESSION['CG']->chsbuilder->set_a_need('digits', true);
}
else $_SESSION['CG']->chsbuilder->set_a_need('digits', false);
//specials
if (isset($_POST['specials_chbox'])) {
$_SESSION['CG']->chsbuilder->set_a_need('specials', true);
}
else $_SESSION['CG']->chsbuilder->set_a_need('specials', false);
//excluded
if (strlen($_POST['excluded_edit'])) {
$_SESSION['CG']->chsbuilder->set_a_need('exclude', $_POST['excluded_edit']);
}
else $_SESSION['CG']->chsbuilder->set_a_need('exclude', "");
//building...
$_SESSION['CG']->chsbuilder->build_from_needs();
}
catch (Exception $e) {
phpAlert($e->getMessage());
$form->reset_all(); //1.1
phpAlert('you must not see this');
return;
}
//end of lit. cp.
}; //closure form_set_needs2current_controls
$form_chset->add_helper_callable('setneeds2currentcontr', $form_set_needs2current_controls); //it means set needs to current controls
//preview_callable...
$preview_call = function($form) {
$form->helper_call('setneeds2currentcontr');
filelog("IN PREVIEWCALL _POST: ". print_r($_POST, true));
filelog("IN PREVIEWCALL _POST, only for NEEDS: ". print_r($_SESSION['CG']->chsbuilder->show_needs(), true));
filelog("in previewcall chsbuilderSNIFF: " . $_SESSION['CG']->chsbuilder->sniff_charsetstr());
$form->set_value_by_id("ccharset_memo", $_SESSION['CG']->chsbuilder->sniff_charsetstr());
$form->get_dom()->getElementByID("sendbtn")->removeAttribute("disabled");
$form->get_dom()->getElementByID("shufflechset")->removeAttribute("disabled");
}; //preview_call
$form_chset->add_submit_callable('previewchset', $preview_call);
//shuffle callable
$shuffle_call = function($form) {
try {
$form->helper_call('setneeds2currentcontr');
$_SESSION['CG']->conform_reqs_toneeds(); //1.1 ?
filelog("IN SHUFFLECALL _POST:: ". print_r($_POST, true));
filelog("IN SHUFFLECALL _POST, only for NEEDS: ". print_r($_SESSION['CG']->chsbuilder->show_needs(), true));
filelog("in shufflecall chsbuilderSNIFF: " . $_SESSION['CG']->chsbuilder->sniff_charsetstr());
$_SESSION['CG']->chsbuilder->shuffle_charset();
$form->set_value_by_id("ccharset_memo", $_SESSION['CG']->chsbuilder->sniff_charsetstr());
}
catch (Exception $e) {
phpAlert($e->getMessage());
return;
}
}; //please remember it's closure... (;)
$form_chset->add_submit_callable('shufflechset', $shuffle_call);
//dynamic click...
$processchstext_call = function($form) {
//phpAlert("just trying");
$userstring = $form->get_dom()->getElementById("ccharset_memo")->nodeValue;
$_SESSION['CG']->chsbuilder->set_needs_from_string($userstring);
$form->helper_call('setneedscontrols');
$_SESSION['CG']->conform_reqs_toneeds();
}; //closure
$form_chset->add_submit_callable('processchstext', $processchstext_call);
//despr...
$resetall_call = function($form) { //not necessary without a sybmit button, it is here just for case
$form->reset_all();
};
$form_chset->add_submit_callable('resetall', $resetall_call); //see above
$form_chset_init = function($form) {
$form->add_form_page_title("QComb v1.1 - Character Set");
$_SESSION['CG']->conform_needs_toreqs();
filelog("IN F_CHSet_INIT: AFTER conform needs to reqs: " . print_r($_SESSION['CG']->chsbuilder->show_needs(), true));
try {
if ($_SESSION['CG']->reqs_differ_from_previous()) {
$_SESSION['CG']->chsbuilder->build_from_needs();
}
}
catch (Exception $e) {
phpAlert($e->getMessage());
return;
}
$form->set_inner_text($form->get_dom()->getElementByID("ccharset_memo"), $_SESSION['CG']->chsbuilder->sniff_charsetstr());
filelog("IN F_CHSet_INIT: before conform needs to reqs: " . print_r($_SESSION['CG']->chsbuilder->show_needs(), true));
//now helper
$form->helper_call('setneedscontrols');
}; //closure
$form_chset->set_init_callable($form_chset_init);
?>