-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathnusystemupdatelibs.php
377 lines (299 loc) · 11.3 KB
/
nusystemupdatelibs.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
<?php
function nuCopySystemFiles() {
$t = nuSystemList();
$sql = "DROP VIEW IF EXISTS zzzzsys_report_data";
nuRunQuery($sql);
$sql = "DROP VIEW IF EXISTS zzzzsys_run_list";
nuRunQuery($sql);
for($i = 0 ; $i < count($t) ; $i++){
$table = $t[$i];
$sql = "DROP TABLE IF EXISTS sys_$table";
nuRunQuery($sql);
$sql = "CREATE TABLE sys_$table SELECT * FROM $table";
nuRunQuery($sql);
if($table != 'zzzzsys_debug'){
$sql= "DROP TABLE IF EXISTS $table";
nuRunQuery($sql);
}
}
}
function nuImportSystemFiles() {
try{
$file = realpath(dirname(__FILE__))."/nubuilder4.sql";
@$handle = fopen($file, "r");
$temp = "";
if ( $handle ) {
nuRunQuery("DROP TABLE IF EXISTS zzzzsys_debug");
while(($line = fgets($handle)) !== false){
if($line[0] != "-" AND $line[0] != "/" AND $line[0] != "\n"){
$line = trim($line);
$temp .= $line;
if(substr($line, -1) == ";"){
$temp = rtrim($temp,';');
$temp = str_replace('ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER','', $temp);
nuRunQuery($temp);
$temp = "";
}
}
}
}else{
throw new nuInstallException("error opening the file: $file");
}
}catch (Throwable $e) {
nuInstallException($e);
}catch (Exception $e) {
nuInstallException($e);
}
}
function nuInstallException($e){
$ce = $_POST['nuProcedureEval'];
$se = $_POST['nuSystemEval'];
print "$ce $se<br>" . $e->getFile() .'<i>' . $e->getMessage() . '</i>' . '<br><b><i>Traced from...</i></b><br>';
$a = $e->getTrace();
$t = array_reverse($a);
for($i = 0 ; $i < count($t) ; $i++){
$m = '(line:<i>' . $t[$i]['line'] . '</i>) ' . $t[$i]['file'] . ' <b> - ' . $t[$i]['function'] . '<b>';
print $m . '<br>';
}
}
//-- after zzzzsys files have been imported
function nuUpdateSystemRecords(){
$ts = nuBuildTableSchema();
$t = nuListSystemTables();
for($i = 0 ; $i < count($t) ; $i++){
$table = $t[$i];
$new = $ts["$table"]['names'];
$old = $ts["sys_$table"]['names'];
//-- remove unused fields from old
for($c = 0 ; $c < count($old) ; $c++){
$field = $old[$c];
if(!in_array($field, $new)){
$sql= "ALTER TABLE sys_$table DROP COLUMN $field";
nuRunQuery($sql);
}
}
}
$ts = nuBuildTableSchema();
for($i = 0 ; $i < count($t) ; $i++){
$table = $t[$i];
$lfield = 'FIRST';
//-- insert extra new fields into old
for($c = 0 ; $c < count($new) ; $c++){
$new = $ts["$table"]['names'];
$newt = $ts["$table"]['types'];
$old = $ts["sys_$table"]['names'];
$oldt = $ts["sys_$table"]['types'];
$ofield = $old[$c];
$nfield = $new[$c];
$otype = $oldt[$c];
$ntype = $newt[$c];
if($ofield != $nfield){
$sql= "ALTER TABLE sys_$table ADD COLUMN $nfield $ntype $lfield";
nuRunQuery($sql);
$ts = nuBuildTableSchema();
//-- start from the beginning again
$c = -1;
}else if($otype != $ntype){
$sql= "ALTER TABLE sys_$table MODIFY COLUMN $nfield $ntype";
nuRunQuery($sql);
}
if($ofield == ''){
$lfield = '';
}else{
$lfield = "AFTER $ofield";
}
}
}
}
function nuAddNewSystemTables(){
$ts = nuBuildTableSchema();
foreach ($ts as $k => $v) {
if(substr($k,0,8) == 'zzzzsys_'){
$v = $ts["sys_$k"]['valid'];
if($v == ''){
$sql = "CREATE TABLE sys_$k SELECT * FROM $k";
nuRunQuery($sql);
}
}
}
nuRunQuery("ALTER TABLE `zzzzsys_object` CHANGE `sob_input_count` `sob_input_count` BIGINT(20) NULL DEFAULT '0';");
nuRunQuery("ALTER TABLE `zzzzsys_object` CHANGE `sob_all_order` `sob_all_order` INT(11) NULL DEFAULT '0';");
}
function nuJustNuRecords(){
$s = "DELETE FROM zzzzsys_event WHERE zzzzsys_event_id NOT LIKE 'nu%'";
nuRunQuery($s);
$s = "DELETE FROM zzzzsys_file WHERE zzzzsys_file_id NOT LIKE 'nu%'";
nuRunQuery($s);
$s = "DELETE FROM zzzzsys_format WHERE zzzzsys_format_id NOT LIKE 'nu%'";
nuRunQuery($s);
//-- delete records that start with ids starting with 'nu' or linked to forms starting with 'nu'
$s = "DELETE FROM zzzzsys_php WHERE sph_zzzzsys_form_id NOT LIKE 'nu%' AND zzzzsys_php_id NOT LIKE 'nu%' ";
nuRunQuery($s);
$s = "DELETE FROM zzzzsys_setup";
nuRunQuery($s);
//-- delete tabs with forms starting with 'nu'
$s = "DELETE FROM zzzzsys_tab WHERE syt_zzzzsys_form_id NOT LIKE 'nu%' OR syt_zzzzsys_form_id = 'nuuserhome'";
nuRunQuery($s);
}
function nuRemoveNuRecords(){
$O = nuTT();
//-- delete if attached to objects on forms with ids starting with 'nu'
$s = "DELETE FROM sys_zzzzsys_event WHERE zzzzsys_event_id LIKE 'nu%'";
nuRunQuery($s);
$s = "DELETE FROM sys_zzzzsys_file WHERE zzzzsys_file_id LIKE 'nu%'";
nuRunQuery($s);
$s = "DELETE FROM sys_zzzzsys_format WHERE zzzzsys_format_id LIKE 'nu%'";
nuRunQuery($s);
//-- delete all objects on forms with ids that start with 'nu'
$s = "DELETE FROM sys_zzzzsys_object WHERE sob_all_zzzzsys_form_id LIKE 'nu%' AND sob_all_zzzzsys_form_id != 'nuuserhome'";
nuRunQuery($s);
//-- delete all objects on forms with ids that start with 'nu'
$s = "DELETE FROM sys_zzzzsys_tab WHERE syt_zzzzsys_form_id LIKE 'nu%' AND syt_zzzzsys_form_id != 'nuuserhome'";
nuRunQuery($s);
//-- delete all objects on forms with ids that start with 'nu'
$s = "DELETE FROM sys_zzzzsys_form WHERE zzzzsys_form_id LIKE 'nu%' ";
nuRunQuery($s);
//-- delete records that start with ids starting with 'nu' or linked to forms starting with 'nu'
$s = "DELETE FROM sys_zzzzsys_php WHERE zzzzsys_php_id LIKE 'nu%' AND zzzzsys_php_id != 'nuuserhome_BE'";
nuRunQuery($s);
//-- KEEP BROWSEs from FORMs with ids that start with 'nu'
$s = "DELETE FROM sys_zzzzsys_browse WHERE sbr_zzzzsys_form_id LIKE 'nu%'";
nuRunQuery($s);
//-- KEEP BROWSEs from FORMs with ids that start with 'nu'
$s = "DELETE FROM sys_zzzzsys_translate WHERE zzzzsys_translate_id LIKE 'nu%'";
nuRunQuery($s);
//-- delete all timezones
$s = "DELETE FROM sys_zzzzsys_timezone";
nuRunQuery($s);
}
function nuAppendToSystemTables(){
try{
$t = nuSystemList();
for($i = 0 ; $i < count($t) ; $i++){
$table = $t[$i];
//-- if duplicate records, use latest record from zzzzsys_object
if($table == 'zzzzsys_object'){
nuRunQuery("REPLACE INTO sys_zzzzsys_object SELECT * FROM zzzzsys_object");
nuRunQuery("DELETE FROM zzzzsys_object");
}
nuRunQuery("REPLACE INTO $table SELECT * FROM sys_$table");
nuRunQuery("DROP TABLE sys_$table");
}
$s = "DROP TABLE sys_zzzzsys_report_data";
nuRunQuery($s);
$s = "DROP TABLE sys_zzzzsys_run_list";
nuRunQuery($s);
$s = "UPDATE zzzzsys_setup SET set_denied = '1'";
nuRunQuery($s);
}catch (Throwable $e) {
nuInstallException($e);
}catch (Exception $e) {
nuInstallException($e);
}
}
function nuSystemList(){
$t = [];
$t[] = 'zzzzsys_access';
$t[] = 'zzzzsys_access_form';
$t[] = 'zzzzsys_access_php';
$t[] = 'zzzzsys_access_report';
$t[] = 'zzzzsys_browse';
$t[] = 'zzzzsys_debug';
$t[] = 'zzzzsys_event';
$t[] = 'zzzzsys_file';
$t[] = 'zzzzsys_form';
$t[] = 'zzzzsys_format';
$t[] = 'zzzzsys_object';
$t[] = 'zzzzsys_php';
$t[] = 'zzzzsys_report';
$t[] = 'zzzzsys_select';
$t[] = 'zzzzsys_select_clause';
$t[] = 'zzzzsys_session';
$t[] = 'zzzzsys_setup';
$t[] = 'zzzzsys_tab';
$t[] = 'zzzzsys_table';
$t[] = 'zzzzsys_timezone';
$t[] = 'zzzzsys_translate';
$t[] = 'zzzzsys_user';
return $t;
}
function nuSetCollation(){
$tbls = nuRunQuery("SHOW FULL Tables WHERE Table_type = 'BASE TABLE'");
$db = nuRunQuery("SELECT DATABASE()");
$dbname = db_fetch_row($db)[0];
nuRunQuery("ALTER DATABASE $dbname CHARACTER SET utf8 COLLATE utf8_general_ci");
while($row = db_fetch_row($tbls)){
$tab = $row[0];
if(substr($tab, 0, 8) == 'zzzzsys_'){
nuRunQuery("ALTER TABLE $tab ENGINE = MyISAM");
nuRunQuery("ALTER TABLE $tab DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci");
nuRunQuery("ALTER TABLE $tab CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci");
}
}
}
function nuMigrateSQL() {
$set = "nuStartDatabaseAdmin();";
$where = 'nu5bad6cb37966261';;
$values = array($set,$where);
$sql = "UPDATE `zzzzsys_event` SET `sev_javascript` = ? WHERE `zzzzsys_event_id` = ? ";
nuRunQuery($sql, $values);
$set = "<iframe id='sqlframe' src='nuselect.php' style='height:180px;width:700px'></iframe>";
$where = 'nu5bad6cb359e7a1a';
$values = array($set,$where);
$sql = "UPDATE `zzzzsys_object` SET `sob_html_code` = ? WHERE `zzzzsys_object_id` = ? ";
nuRunQuery($sql, $values);
$set = 'window.open(\'nureportdesigner.php?tt=\' + $("#sre_zzzzsys_php_id").val() + \'&launch=\' + $("#sre_zzzzsys_form_id").val());';
$where = 'nu5bad6cb3797b0a7';
$values = array($set,$where);
$sql = "UPDATE `zzzzsys_event` SET `sev_javascript` = ? WHERE `zzzzsys_event_id` = ?";
nuRunQuery($sql, $values);
$set = '$s = "CREATE TABLE #TABLE_ID# SELECT zzzzsys_object_id AS theid FROM zzzzsys_object WHERE ";';
$set .= "\n";
$set .= '$w = "1";';
$set .= "\n";
$set .= 'if ( $GLOBALS[\'nuSetup\']->set_denied == 1 ) { ';
$set .= "\n";
$set .= '$w = "sob_all_zzzzsys_form_id NOT LIKE \'nu%\' OR sob_all_zzzzsys_form_id = \'nuuserhome\'"; ';
$set .= "\n";
$set .= '}';
$set .= "\n";
$set .= 'nuRunQuery("$s$w");';
$set .= "\n";
$where = 'nuobject_BB';
$values = array($set,$where);
$sql = "UPDATE `zzzzsys_php` SET `sph_php` = ? WHERE `zzzzsys_php_id` = ?";
nuRunQuery($sql, $values);
$set = '$s = "CREATE TABLE #TABLE_ID# SELECT zzzzsys_form_id AS theid FROM zzzzsys_form WHERE ";';
$set .= "\n";
$set .= '$w = "1";';
$set .= "\n";
$set .= 'if ( $GLOBALS[\'nuSetup\']->set_denied == 1 ) { ';
$set .= "\n";
$set .= '$w = "zzzzsys_form_id NOT LIKE \'nu%\' OR zzzzsys_form_id = \'nuuserhome\'"; ';
$set .= "\n";
$set .= '}';
$set .= "\n";
$set .= 'nuRunQuery("$s$w");';
$set .= "\n";
$where = 'nuform_BB';
$values = array($set,$where);
$sql = "UPDATE `zzzzsys_php` SET `sph_php` = ? WHERE `zzzzsys_php_id` = ?";
nuRunQuery($sql, $values);
$set = '$s = "CREATE TABLE #TABLE_ID# SELECT zzzzsys_form_id AS theid FROM zzzzsys_form WHERE ";';
$set .= "\n";
$set .= '$w = "1";';
$set .= "\n";
$set .= 'if ( $GLOBALS[\'nuSetup\']->set_denied == 1 ) { ';
$set .= "\n";
$set .= '$w = "zzzzsys_form_id NOT LIKE \'nu%\' OR zzzzsys_form_id = \'nuuserhome\'"; ';
$set .= "\n";
$set .= '}';
$set .= "\n";
$set .= 'nuRunQuery("$s$w");';
$set .= "\n";
$where = 'nutablookup_BB';
$values = array($set,$where);
$sql = "UPDATE `zzzzsys_php` SET `sph_php` = ? WHERE `zzzzsys_php_id` = ?";
nuRunQuery($sql, $values);
}
?>