-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathnubuilders.php
423 lines (282 loc) · 9.59 KB
/
nubuilders.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
<?php
function nuBuildFastReport(){
if($_SESSION['IsDemo']){
nuDisplayError('Not available in the Demo...');
return;
}
$t = nuRunQuery("SELECT COUNT(*) AS fastreports FROM zzzzsys_report WHERE sre_code like 'FR%'");
$fr = db_fetch_object($t)->fastreports;
$i = nuID();
$c = "FR$fr";
$d = "Fast Report $fr";
$g = "Fast Report";
$j = str_replace('\"', '"', nuHash()['fieldlist']);
$t = nuHash()['table'];
$f = 'nublank';
$s = "
INSERT INTO zzzzsys_report
(
zzzzsys_report_id,
sre_code,
sre_description,
sre_group,
sre_zzzzsys_php_id,
sre_zzzzsys_form_id,
sre_layout
)
VALUES
(
?,
?,
?,
?,
?,
?,
?
)
";
nuRunQuery($s, [$i, $c, $d, $g, $t, $f, $j]);
$js = "
var m1 = '<h1>A Fast Report has been created!</h1>';
var m2 = '<p>(There is now a Report with a Code of <b>$c</b> found in <b>Reports</b>)';
nuMessage([m1, m2]);
$('#nunuRunPHPHiddenButton').remove();
";
nuJavascriptCallback($js);
}
function nuBuildFastForm($table, $form_type){
if($_SESSION['IsDemo']){
nuDisplayError('Not available in the Demo...');
return;
}
$form_id = nuID();
$PK = $table . '_id';
$newT = $form_type != 'launch';
if($form_type == 'launch'){
$table = 'Launch Form ' . nuFastForms();
}
$q = nuRunQuery("SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = DATABASE()");
while($tableSchemaOBJ = db_fetch_object($q)){
if($table == $tableSchemaOBJ->table_name){
$_POST['tableSchema'] = nuBuildTableSchema();
$PK = $_POST['tableSchema'][$table]['primary_key'][0];
$newT = false;
}
}
$TT = nuTT();
$SF = nuSubformObject('obj_sf');
$tab_id = nuID();
$t = nuRunQuery("SELECT COUNT(*) FROM zzzzsys_form WHERE SUBSTRING(sfo_code, 1, 2) = 'FF'");
$r = db_fetch_row($t);
$form_code = 'FF' . $r[0];
$form_desc = 'Fast Form ' . $r[0];
$s = Array();
//----------add tab--------------------
$sql = "
INSERT
INTO zzzzsys_tab
(zzzzsys_tab_id,
syt_zzzzsys_form_id,
syt_title,
syt_order)
VALUES
(?, ?, ?, ?)
";
$array = Array($tab_id, $form_id, 'Main', 10);
nuRunQuery($sql, $array);
//----------add form--------------------
$sql = "
INSERT
INTO zzzzsys_form
(zzzzsys_form_id,
sfo_type,
sfo_code,
sfo_description,
sfo_table,
sfo_primary_key,
sfo_browse_sql)
VALUES
(?, ?, ?, ?, ?, ?, ?)
";
$array = Array($form_id, $form_type, $form_code, ucfirst($form_desc), $form_type=='launch'?'':$table, $form_type=='launch'?'':$PK, "SELECT * FROM $table");
nuRunQuery($sql, $array);
$sql = "CREATE TABLE $TT SELECT * FROM zzzzsys_object WHERE false";
nuRunQuery($sql);
for($i = 0 ; $i < count($SF->rows) ; $i++){
if($SF->rows[$i][5] == 0){ //-- not ticked as deleted
$r = $SF->rows[$i][3];
$newid = nuID();
$SF->rows[$i][3] = $newid;
$sql = "INSERT INTO $TT SELECT * FROM zzzzsys_object WHERE zzzzsys_object_id = '$r'";
nuRunQuery($sql);
$sql = "UPDATE $TT SET zzzzsys_object_id = '$newid' WHERE zzzzsys_object_id = '$r'";
nuRunQuery($sql);
}
}
$sql = "
UPDATE $TT
SET
sob_all_id = ?,
sob_all_label = ?,
sob_all_order = ?,
sob_all_top = ?,
sob_all_left = ?,
sob_all_table = ?,
sob_all_zzzzsys_form_id = ?,
sob_all_zzzzsys_tab_id = ?,
zzzzsys_object_id = ?
WHERE
zzzzsys_object_id = ?
";
$top = 10;
for($i = 0 ; $i < count($SF->rows) ; $i++){
if($SF->rows[$i][5] == 0){ //-- not ticked as deleted
$newid = nuID();
$label = $SF->rows[$i][1];
$field = $SF->rows[$i][2];
$oldid = $SF->rows[$i][3];
$array = Array($field, $label, $i * 5, $top, 150, $table, $form_id, $tab_id, $newid, $oldid);
nuRunQuery($sql, $array);
$OT = nuRunQuery("SELECT * FROM $TT WHERE zzzzsys_object_id = ? ", [$newid]);
$top = $top + db_fetch_object($OT)->sob_all_height + 10;
}
}
if($form_type == 'browse'){
nuRunQuery("DELETE FROM $TT WHERE 1");
}
$t = nuRunQuery("SELECT * FROM $TT");
$a = Array();
$n = 'number date';
while($r = db_fetch_object($t)){
$y = $r->sob_all_type;
$i = $r->sob_input_type;
$id = $r->sob_all_id;
$date = ($i == 'date' || $i == 'nuDate');
$norm = ($y == 'input' && $i != 'date' && $i != 'nuDate' && $i != 'nuNumber' && $i != 'number' && $i != 'file');
if($y == 'lookup'){ $a[] = Array('name'=>$id, 'type'=>'id');}
if($y == 'select'){ $a[] = Array('name'=>$id, 'type'=>'varchar');}
if($y == 'calc'){ $a[] = Array('name'=>$id, 'type'=>'decimal');}
if($y == 'textarea'){ $a[] = Array('name'=>$id, 'type'=>'textarea');}
if($y == 'input' && $norm){ $a[] = Array('name'=>$id, 'type'=>'varchar');}
if($y == 'input' && $date){ $a[] = Array('name'=>$id, 'type'=>'date');}
if($y == 'input' && $i == 'number'){ $a[] = Array('name'=>$id, 'type'=>'int');}
if($y == 'input' && $i == 'nuNumber'){ $a[] = Array('name'=>$id, 'type'=>'decimal');}
if($y == 'input' && $i == 'file'){ $a[] = Array('name'=>$id, 'type'=>'longtext');}
}
if($newT){
$mess = 'Table and Form have';
$create = nuBuildNewTable($table, $a, $newT);
nuRunQuery($create);
nuRunQuery("ALTER TABLE $table ENGINE = MyISAM;");
nuRunQuery("ALTER TABLE $table CONVERT TO CHARACTER SET UTF8 COLLATE utf8_general_ci");
}else{
$mess = 'Form has';
}
for($i = 0 ; $i < count($SF->rows) ; $i++){
if($SF->rows[$i][4] == 1 and $SF->rows[$i][5] == 0){ //-- not ticked as deleted
$lab = $SF->rows[$i][1];
$id = $SF->rows[$i][2];
$sql = "
INSERT
INTO zzzzsys_browse
(zzzzsys_browse_id,
sbr_zzzzsys_form_id,
sbr_title,
sbr_display,
sbr_align,
sbr_format,
sbr_order,
sbr_width)
VALUES
(?, ?, ?, ?, ?, ?, ?, ?)
";
$array = Array(nuID(), $form_id, $lab, $id, 'l', '', ($i+1) * 10, 250);
nuRunQuery($sql, $array);
}
}
if($form_type == 'subform' || $form_type == 'browse'){
$js = "
var m1 = '<h1>A $mess been created!</h1>';
var m2 = '<p>(There is now a Form with a Code of <b>$form_code</b> found in <b>Forms</b>)';
nuMessage([m1, m2]);
$('#nunuRunPHPHiddenButton').remove();
";
nuJavascriptCallback($js);
}else{
//----------make sure button has a tab--------------------
$sql = "REPLACE INTO zzzzsys_tab (zzzzsys_tab_id, syt_zzzzsys_form_id, syt_title, syt_order) VALUES ('nufastforms', 'nuuserhome', 'Fast Forms', -1);";
nuRunQuery($sql);
//----------add run button--------------------
$sql = "
INSERT
INTO $TT
(zzzzsys_object_id,
sob_all_zzzzsys_form_id,
sob_all_zzzzsys_tab_id,
sob_all_id,
sob_all_label,
sob_all_table,
sob_all_order,
sob_all_top,
sob_all_left,
sob_all_width,
sob_all_height,
sob_run_zzzzsys_form_id,
sob_run_id,
sob_run_method,
sob_all_cloneable,
sob_all_validate,
sob_all_access,
sob_all_align,
sob_all_type)
VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
";
$form_count = nuFastForms() * 50;
$record_id = substr($form_type, 0, 6) == 'browse' ? '' : '-1';
$array = Array(nuID(), 'nuuserhome', 'nufastforms', "ff$form_id", ucfirst($table), $table, 11, 50 + $form_count, $form_count, 150, 30, $form_id, $record_id, 'b', 0, 0, 0, 'center', 'run');
nuRunQuery($sql, $array);
$js = "
var m1 = '<h1>A $mess been created!</h1>';
var m2 = '<p>(There is now a Button called <b>$table</b> on the <b>Fast Forms</b> tab of the <b>User Home</b> Form)</p>';
nuMessage([m1, m2]);
$('#nunuRunPHPHiddenButton').remove();
";
nuJavascriptCallback($js);
}
nuRunQuery("INSERT INTO zzzzsys_object SELECT * FROM $TT");
nuRunQuery("DROP TABLE $TT");
nuSetJSONData('clientFormSchema', nuBuildFormSchema());
}
function nuFastForms(){
$s = 'SELECT COUNT(*) AS ff FROM zzzzsys_object WHERE sob_all_zzzzsys_tab_id = "nufastforms"';
$t = nuRunQuery($s);
$r = db_fetch_object($t);
return $r->ff;
}
function nuBuildNewTable($tab, $array, $newT){
$id = $tab . '_id';
$start = "CREATE TABLE $tab";
$a = Array();
$a[] = "$id VARCHAR(25) NOT NULL";
$ff_type = nuHash()['fastform_type'];
$ff_fk = nuHash()['fastform_fk'];
if($ff_type == 'subform' && $newT){
$a[] = "$ff_fk VARCHAR(25) DEFAULT NULL";
}
for($i = 0 ; $i < count($array) ; $i++){
$f = $array[$i]['name'];
$t = $array[$i]['type'];
if($t == 'id'){ $a[] = "$f VARCHAR(25) DEFAULT NULL";}
if($t == 'varchar'){ $a[] = "$f VARCHAR(1000) DEFAULT NULL";}
if($t == 'int'){ $a[] = "$f INT DEFAULT NULL";}
if($t == 'textarea'){ $a[] = "$f TEXT DEFAULT NULL";}
if($t == 'decimal'){ $a[] = "$f DECIMAL(12,4) DEFAULT NULL";}
if($t == 'date'){ $a[] = "$f DATE DEFAULT NULL";}
if($t == 'longtext'){ $a[] = "$f LONGTEXT DEFAULT NULL";}
}
$a[] = "PRIMARY KEY ($id)";
$im = implode(',', $a);
return "$start ($im)";
}
?>