-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleMaker_Setup.php
More file actions
674 lines (546 loc) · 29.7 KB
/
ModuleMaker_Setup.php
File metadata and controls
674 lines (546 loc) · 29.7 KB
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
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
<?php
# ModuleMaker_Setup.php
#
# Created 2025/05/23 by Dave Henderson ([email protected])
# Updated 2025/09/27 by Dave Henderson ([email protected])
#
# Unless a valid Cliquesoft Private License (CPLv1) has been purchased for your
# device, this software is licensed under the Cliquesoft Public License (CPLv2)
# as found on the Cliquesoft website at www.cliquesoft.org.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the appropriate Cliquesoft License for details.
# Gloabl Variable Definitions
function ModuleMaker_Install_Files($sMODULE) {
# the function that performs the installation of the module files
# sMODULE this is the modules name in proper format (e.g. 'Application Settings')
global $__sInfo;
$sModule = str_replace(' ', '', $sMODULE); # convert the module name into CamelCase
# change into the staging directory
$__sInfo['error'] = "The 'temp/install/software' directory does not exist.";
$__sInfo['command'] = "chdir('../../temp/install/software')";
$__sInfo['values'] = 'None';
@chdir('../temp/install/software');
# copy the module scripts
$__sInfo['error'] = "The 'code' directory does not exist.";
$__sInfo['command'] = "opendir('code')";
$__sInfo['values'] = 'None';
$dir = @opendir('code');
$dst = '../../../code';
while (($file = @readdir($dir)) !== false) {
# skip processing the special directory values, this file, and any sub-directories
if ($file == '.' || $file == '..' || $file == basename(__FILE__) || is_dir($file)) { continue; }
$__sInfo['error'] = "The 'code/".$file."' file can not be copied to '".$dst."/".$file."'.";
$__sInfo['command'] = "copy('code/".$file."', '".$dst."/".$file."')";
$__sInfo['values'] = 'None';
@copy('code/'.$file, $dst.'/'.$file);
}
closedir($dir);
# copy the module user interface files
$__sInfo['error'] = "The 'look/default' directory does not exist.";
$__sInfo['command'] = "opendir('look/default')";
$__sInfo['values'] = 'None';
$dir = @opendir('look/default');
$dst = '../../../look/default';
while (($file = @readdir($dir)) !== false) {
# skip processing the special directory values and any sub-directories
if ($file == '.' || $file == '..' || is_dir($file)) { continue; }
$__sInfo['error'] = "The 'look/default/".$file."' file can not be copied to '".$dst."/".$file."'.";
$__sInfo['command'] = "copy('look/".$file."', '".$dst."/".$file."')";
$__sInfo['values'] = 'None';
@copy('look/default/'.$file, $dst.'/'.$file);
}
closedir($dir);
# copy the module image files
$__sInfo['error'] = "The 'imgs/default' directory does not exist.";
$__sInfo['command'] = "opendir('imgs/default')";
$__sInfo['values'] = 'None';
$dir = @opendir('imgs/default');
$dst = '../../../imgs/default';
while (($file = @readdir($dir)) !== false) {
# skip processing the special directory values and any sub-directories
if ($file == '.' || $file == '..' || is_dir($file)) { continue; }
$__sInfo['error'] = "The 'imgs/default/".$file."' file can not be copied to '".$dst."/".$file."'.";
$__sInfo['command'] = "copy('imgs/default/".$file."', '".$dst."/".$file."')";
$__sInfo['values'] = 'None';
@copy('imgs/default/'.$file, $dst.'/'.$file);
}
closedir($dir);
# create the modules' data directory and copy the setup.php file in it
if (! file_exists('../../../data/_modules/'.$sModule)) {
$__sInfo['error'] = "The '../../../data/_modules/".$sModule."' directory can not be created.";
$__sInfo['command'] = "mkdir('../../../data/_modules/".$sModule."', 0775, true)";
$__sInfo['values'] = 'None';
@mkdir('../../../data/_modules/'.$sModule, 0775, true);
}
$__sInfo['error'] = "The 'code/".basename(__FILE__)."' file can not be copied to '../../../data/_modules/".$sModule."/".basename(__FILE__)."'.";
$__sInfo['command'] = "copy('code/".basename(__FILE__)."', '../../../data/_modules/".$sModule."/".basename(__FILE__)."')";
$__sInfo['values'] = 'None';
@copy('code/'.basename(__FILE__), '../../../data/_modules/'.$sModule.'/'.basename(__FILE__));
# copy the MD5 file to the modules data directory (preferred)
if (file_exists('../../install/'.$sModule.'.md5')) {
$__sInfo['error'] = "The '../../install/".$sModule.".md5' file can not be copied to '../../../data/_modules/".$sModule."/hash'.";
$__sInfo['command'] = "copy('../../install/".$sModule.".md5', '../../../data/_modules/".$sModule."/hash')";
$__sInfo['values'] = 'None';
@copy('../../install/'.$sModule.'.md5', '../../../data/_modules/'.$sModule.'/hash');
} else if (file_exists('../../update/'.$sModule.'.md5')) {
$__sInfo['error'] = "The '../../update/".$sModule.".md5' file can not be copied to '../../../data/_modules/".$sModule."/hash'.";
$__sInfo['command'] = "copy('../../update/".$sModule.".md5', '../../../data/_modules/".$sModule."/hash')";
$__sInfo['values'] = 'None';
@copy('../../update/'.$sModule.'.md5', '../../../data/_modules/'.$sModule.'/hash');
# copy the version file to the modules data directory (auxillary, if the hash file doesn't exist for some reason)
} else if (file_exists('data/_modules/'.$sModule.'/version')) {
$__sInfo['error'] = "The 'data/_modules/".$sModule."/version' file can not be copied to '../../../data/_modules/".$sModule."/version'.";
$__sInfo['command'] = "copy('data/_modules/".$sModule."/version', '../../../data/_modules/".$sModule."/version')";
$__sInfo['values'] = 'None';
@copy('data/_modules/'.$sModule.'/version', '../../../data/_modules/'.$sModule.'/version');
}
# change back into the prior directory (so everything that follows maintains the correct relative paths)
$__sInfo['error'] = "The '../../../code' directory does not exist.";
$__sInfo['command'] = "chdir('../../../code')";
$__sInfo['values'] = 'None';
@chdir('../../../code');
return true;
}
function ModuleMaker_Install() {
# this function performs the initial (database) installation of the module
# NOTES this function assumes the file has already been decompressed and in the '../temp/install' directory
# there is no need to cleanup in this script as the calling script will perform that
global $__sInfo,$_LinkDB,$_sInterface,$__sMsgs;
$sMODULE = trim(file_get_contents('../temp/install/software/MODULE')); # store the modules name in proper format (e.g. 'Application Settings')
$sModule = str_replace(' ', '', $sMODULE); # convert the module name into CamelCase
# first, install the files associated with the module
ModuleMaker_Install_Files($sMODULE);
# obtain the users info!
$__sInfo['error'] = "The users information can not be obtained from the database.";
$__sInfo['command'] = "SELECT id,username,name FROM ".DB_PRFX."Employees WHERE username='".$_POST['sUsername']."' LIMIT 1";
$__sInfo['values'] = 'None';
$User = $_LinkDB->query($__sInfo['command']);
$user = $User->fetch_assoc();
# check if the database tables already exist in the DB
$__sInfo['error'] = "The 'ModuleMaker_Modules' table can not be added to the database.";
$__sInfo['command'] = "CREATE TABLE IF NOT EXISTS ".DB_PRFX."ModuleMaker_Modules (
id BIGINT PRIMARY KEY NOT NULL AUTO_INCREMENT UNIQUE,
bDisabled TINYINT(1) NOT NULL DEFAULT '0',
fkCode_HeaderJS BIGINT NOT NULL DEFAULT '0',
fkCode_HeaderPHP BIGINT NOT NULL DEFAULT '0',
sName VARCHAR(24) NOT NULL UNIQUE
)";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "The 'ModuleMaker_Tabs' table can not be added to the database.";
$__sInfo['command'] = "CREATE TABLE IF NOT EXISTS ".DB_PRFX."ModuleMaker_Tabs (
id BIGINT PRIMARY KEY NOT NULL AUTO_INCREMENT UNIQUE,
fkModules BIGINT NOT NULL,
bDisabled TINYINT(1) NOT NULL DEFAULT '0',
sName VARCHAR(24) NOT NULL
)";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "The 'ModuleMaker_Groups' table can not be added to the database.";
$__sInfo['command'] = "CREATE TABLE IF NOT EXISTS ".DB_PRFX."ModuleMaker_Groups (
id BIGINT PRIMARY KEY NOT NULL AUTO_INCREMENT UNIQUE,
fkTabs BIGINT NOT NULL,
bDisabled TINYINT(1) NOT NULL DEFAULT '0',
sName VARCHAR(24) NOT NULL
)";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "The 'ModuleMaker_Objects' table can not be added to the database.";
$__sInfo['command'] = "CREATE TABLE IF NOT EXISTS ".DB_PRFX."ModuleMaker_Objects (
id BIGINT PRIMARY KEY NOT NULL AUTO_INCREMENT UNIQUE,
fkGroups BIGINT NOT NULL,
bDisabled TINYINT(1) NOT NULL DEFAULT '0',
nLine TINYINT NOT NULL DEFAULT '0',
nIndex TINYINT NOT NULL,
sName VARCHAR(32) NOT NULL,
sVisibility CHAR(1) NOT NULL DEFAULT 'a',
bMandatory TINYINT(1) NOT NULL DEFAULT '0',
nParent BIGINT NOT NULL DEFAULT '0',
sType CHAR(1) NOT NULL DEFAULT 's',
bEncrypted TINYINT(1) NOT NULL DEFAULT '0',
sValue VARCHAR(128) NOT NULL,
nMaxLength SMALLINT NOT NULL,
sValidate VARCHAR(48),
sListing CHAR(1) NOT NULL DEFAULT 'n',
sTag VARCHAR(64)
)";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "The 'ModuleMaker_Languages' table can not be added to the database.";
$__sInfo['command'] = "CREATE TABLE IF NOT EXISTS ".DB_PRFX."ModuleMaker_Languages (
id BIGINT PRIMARY KEY NOT NULL AUTO_INCREMENT UNIQUE,
fkObjects BIGINT NOT NULL,
bDisabled TINYINT(1) NOT NULL DEFAULT '0',
sLanguage CHAR(2) NOT NULL DEFAULT 'en',
sPlaceholder VARCHAR(32) NOT NULL,
sLabel VARCHAR(24) NOT NULL,
sTooltip VARCHAR(128) NOT NULL,
sDescription VARCHAR(24) NOT NULL
)";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "The 'ModuleMaker_Actions' table can not be added to the database.";
$__sInfo['command'] = "CREATE TABLE IF NOT EXISTS ".DB_PRFX."ModuleMaker_Actions (
id BIGINT PRIMARY KEY NOT NULL AUTO_INCREMENT UNIQUE,
fkModules BIGINT NOT NULL DEFAULT '0',
fkObjects BIGINT NOT NULL DEFAULT '0',
fkCode_EventJS BIGINT NOT NULL DEFAULT '0',
fkCode_HeaderJS BIGINT NOT NULL DEFAULT '0',
fkCode_HeaderPHP BIGINT NOT NULL DEFAULT '0',
bDisabled TINYINT(1) NOT NULL DEFAULT '0',
sName VARCHAR(24) NOT NULL
)";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "The 'ModuleMaker_Code' table can not be added to the database.";
$__sInfo['command'] = "CREATE TABLE IF NOT EXISTS ".DB_PRFX."ModuleMaker_Code (
id BIGINT PRIMARY KEY NOT NULL AUTO_INCREMENT UNIQUE,
sCode TEXT NOT NULL
)";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "The 'ModuleMaker_Parameters' table can not be added to the database.";
$__sInfo['command'] = "CREATE TABLE IF NOT EXISTS ".DB_PRFX."ModuleMaker_Parameters (
id BIGINT PRIMARY KEY NOT NULL AUTO_INCREMENT UNIQUE,
fkActions BIGINT NOT NULL,
bDisabled TINYINT(1) NOT NULL DEFAULT '0',
nIndex TINYINT NOT NULL,
sName VARCHAR(24) NOT NULL,
sDataType CHAR(1) NOT NULL,
sDefault VARCHAR(32) DEFAULT ''
)";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "The 'ModuleMaker_Operations' table can not be added to the database.";
$__sInfo['command'] = "CREATE TABLE IF NOT EXISTS ".DB_PRFX."ModuleMaker_Operations (
id BIGINT PRIMARY KEY NOT NULL AUTO_INCREMENT UNIQUE,
fkActions_Parent BIGINT NOT NULL,
fkActions BIGINT NOT NULL DEFAULT '0',
fkCode BIGINT NOT NULL DEFAULT '0',
bDisabled TINYINT(1) NOT NULL DEFAULT '0',
sScript VARCHAR(3) NOT NULL DEFAULT 'JS',
nIndex TINYINT NOT NULL,
bInline TINYINT NOT NULL DEFAULT '0'
)";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "The 'ModuleMaker_Values' table can not be added to the database.";
$__sInfo['command'] = "CREATE TABLE IF NOT EXISTS ".DB_PRFX."ModuleMaker_Values (
id BIGINT PRIMARY KEY NOT NULL AUTO_INCREMENT UNIQUE,
fkOperations BIGINT NOT NULL,
fkParameters BIGINT NOT NULL,
fkObjects BIGINT NOT NULL DEFAULT '0',
sValue VARCHAR(32) DEFAULT ''
)";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "The 'ModuleMaker_Themes' table can not be added to the database.";
$__sInfo['command'] = "CREATE TABLE IF NOT EXISTS ".DB_PRFX."ModuleMaker_Themes (
id BIGINT PRIMARY KEY NOT NULL AUTO_INCREMENT UNIQUE,
bDisabled TINYINT(1) NOT NULL DEFAULT '0',
sName VARCHAR(32) NOT NULL UNIQUE
)";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "The 'ModuleMaker_Theming' table can not be added to the database.";
$__sInfo['command'] = "CREATE TABLE IF NOT EXISTS ".DB_PRFX."ModuleMaker_Theming (
id BIGINT PRIMARY KEY NOT NULL AUTO_INCREMENT UNIQUE,
fkThemes BIGINT NOT NULL,
fkStyles BIGINT NOT NULL DEFAULT '0',
fkObjects BIGINT NOT NULL DEFAULT '0',
fkCode BIGINT NOT NULL
)";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "The 'ModuleMaker_Styles' table can not be added to the database.";
$__sInfo['command'] = "CREATE TABLE IF NOT EXISTS ".DB_PRFX."ModuleMaker_Styles (
id BIGINT PRIMARY KEY NOT NULL AUTO_INCREMENT UNIQUE,
bDisabled TINYINT(1) NOT NULL DEFAULT '0',
sName VARCHAR(32) NOT NULL UNIQUE
)";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "The 'ModuleMaker_Styling' table can not be added to the database.";
$__sInfo['command'] = "CREATE TABLE IF NOT EXISTS ".DB_PRFX."ModuleMaker_Styling (
id BIGINT PRIMARY KEY NOT NULL AUTO_INCREMENT UNIQUE,
fkObjects BIGINT NOT NULL,
fkStyles BIGINT NOT NULL,
bDisabled TINYINT(1) NOT NULL DEFAULT '0'
)";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "The 'ModuleMaker_Layout' table can not be added to the database.";
$__sInfo['command'] = "CREATE TABLE IF NOT EXISTS ".DB_PRFX."ModuleMaker_Layout (
id BIGINT PRIMARY KEY NOT NULL AUTO_INCREMENT UNIQUE,
fkTabs BIGINT NOT NULL,
fkGroups BIGINT NOT NULL,
bDisabled TINYINT(1) NOT NULL DEFAULT '0',
nIndex TINYINT NOT NULL
)";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
# Create the default table values
$__sInfo['error'] = "The default theme can not be added to the database.";
$__sInfo['command'] = "INSERT IGNORE INTO ".DB_PRFX."ModuleMaker_Themes (id,sName) VALUES ('1','default')";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
# Create the additional table values based on existing installed modules
# Create the group and module table values
$__sInfo['error'] = "Failed to find the installed modules in the database."; # find if the module has already been added to the listing (for a subsequent install after a failure)
$__sInfo['command'] = "SELECT id FROM ".DB_PRFX."ApplicationSettings_Modules WHERE name=\"".$sMODULE."\"";
$__sInfo['values'] = 'None';
$Module = $_LinkDB->query($__sInfo['command']);
if ($Module->num_rows === 0) {
$__sInfo['error'] = "Failed to add the \"".$sMODULE."\" to the list of installed modules in the database.";
$__sInfo['command'] = "INSERT INTO ".DB_PRFX."ApplicationSettings_Modules (name,icon) VALUES (\"".$sMODULE."\",'".$sModule.".png')";
$__sInfo['values'] = 'None';
$Module = $_LinkDB->query($__sInfo['command']);
$module['id'] = $_LinkDB->insert_id; # https://stackoverflow.com/questions/19336346/insert-id-not-getting-the-current-id
$__sInfo['id'] = $module['id']; # store so the calling script can have access to this value
} else { $module = $Module->fetch_assoc(); }
$__sInfo['error'] = "Failed to find the employees access table in the database.";
$__sInfo['command'] = "SELECT * FROM ".DB_PRFX."Employees_Access WHERE employeeID='".$user['id']."' AND moduleID='".$module['id']."' LIMIT 1";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt->num_rows === 0) {
$__sInfo['error'] = "Failed to add the admin account access for the \"".$sMODULE."\" module.";
$__sInfo['command'] = "INSERT INTO ".DB_PRFX."Employees_Access (employeeID,moduleID,`read`,`write`,`add`,`del`) VALUES ('1','".$module['id']."','1','1','1','1')";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($user['id'] != 1) { # if the current employee is not the admin, then add it to the listing too
$__sInfo['error'] = "Failed to add the current employee account access for the \"".$sMODULE."\" module.";
$__sInfo['command'] = "INSERT INTO ".DB_PRFX."Employees_Access (employeeID,moduleID,`read`,`write`,`add`,`del`) VALUES ('".$user['id']."','".$module['id']."','1','1','1','1')";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
}
}
# NOTE: this is last on purpose in case the user configured the groups differently and can be informed appropriately
$__sInfo['error'] = "Failed to find the grouped modules in the database."; # check if the module is already added to any groups
$__sInfo['command'] = "SELECT * FROM ".DB_PRFX."ApplicationSettings_Grouped WHERE moduleID='".$module['id']."'";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt->num_rows === 0) {
if ($_sInterface == 'pro') { # if the user selected a "Professional" operation, then...
$__sInfo['error'] = "Failed to find the configured groups in the database.";
$__sInfo['command'] = "SELECT id FROM ".DB_PRFX."ApplicationSettings_Groups WHERE name=\"Productivity\"";
$__sInfo['values'] = 'None';
$Group = $_LinkDB->query($__sInfo['command']);
if ($Group->num_rows === 0) {
$__sMsgs[0] = "However, the 'Productivity' group could not be located, so use 'Application Settings' to add this module to and existing group so it can be accessed by your employees.";
return true;
} else { $group = $Group->fetch_assoc(); }
$__sInfo['error'] = "Failed to add the \"".$sMODULE."\" module to the \"Productivity\" group.";
$__sInfo['command'] = "INSERT INTO ".DB_PRFX."ApplicationSettings_Grouped (groupID,moduleID) VALUES ('".$group['id']."','".$module['id']."')";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
} else { # otherwise, the program is setup to run as "Enterprise", so...
$__sInfo['error'] = "Failed to find the configured groups in the database.";
$__sInfo['command'] = "SELECT id FROM ".DB_PRFX."ApplicationSettings_Groups WHERE name=\"Departments\"";
$__sInfo['values'] = 'None';
$Group = $_LinkDB->query($__sInfo['command']);
if ($Group->num_rows === 0) {
$__sMsgs[0] = "However, the 'Departments' group could not be located, so use 'Application Settings' to add this module to and existing group so it can be accessed by your employees.";
return true;
} else { $group = $Group->fetch_assoc(); }
$__sInfo['error'] = "Failed to add the \"".$sMODULE."\" module to the \"Departments\" group.";
$__sInfo['command'] = "INSERT INTO ".DB_PRFX."ApplicationSettings_Grouped (groupID,moduleID) VALUES ('".$group['id']."','".$module['id']."')";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
}
}
return true;
}
function ModuleMaker_Update() {
# this function performs the update from prior versions
# NOTE this function MUST store any error messages in $__sMsgs - do NOT output them!!!
global $__sInfo,$_LinkDB;
$sMODULE = trim(file_get_contents('../temp/install/software/MODULE')); # store the modules name in proper format (e.g. 'Application Settings')
$sModule = str_replace(' ', '', $sMODULE); # convert the module name into CamelCase
# first, install the files associated with the module
ModuleMaker_Install_Files($sMODULE);
# get the current hash of the installed module
$sHash = '';
if (file_exists('../data/_modules/'.$sModule.'/hash')) {
$__sInfo['error'] = "Failed to find the hash for the \"".$sMODULE."\" module.";
$__sInfo['command'] = "file_get_contents('../data/_modules/".$sModule."/hash')";
$__sInfo['values'] = 'None';
$sHash = file_get_contents('../data/_modules/'.$sModule.'/hash'); # obtain the entire hash file contents
$sHash = substr($sHash, 0, strpos($sHash, ' ')); # isolate just the hash string
} else if (file_exists('../data/_modules/'.$sModule.'/version')) {
$__sInfo['error'] = "Failed to find the version for the \"".$sMODULE."\" module.";
$__sInfo['command'] = "file_get_contents('../data/_modules/".$sModule."/version')";
$__sInfo['values'] = 'None';
$sHash = trim(file_get_contents('../data/_modules/'.$sModule.'/version')); # obtain the module version as a last resort
}
if ($sHash == '') { # if we couldn't find the hash of the module, then...
echo "<f><msg>The module's hash nor version could not be located during the update.</msg></f>";
return false;
}
# apply any specific updates (to files or DB) starting at the current version, up to the most current!
# NOTE: there are no 'break;' calls below so the user can have no issues updating from their current version to the latest!
switch ($sHash) {
case '2025.05.29.0':
case '3d7cc12b2a5b327ce7e45a4eec0084c5': # initial release 2025-06-01
# no changes are required
#case '':
break;
}
return true;
}
function ModuleMaker_Uninstall() {
# this function performs the uninstallation of the module
# WARNING: remember that the uninstall will run from the 'code/' directory!
global $__sInfo,$_LinkDB;
$sMODULE = $_POST['sModule']; # store the modules name in proper format (e.g. 'Application Settings')
$sModule = str_replace(' ', '', $sMODULE); # convert the module name into CamelCase
# delete the module files where they need to reside
$__sInfo['error'] = "The 'code/".$sModule.".php' file can not be deleted.";
$__sInfo['command'] = "unlink('".$sModule.".php')";
$__sInfo['values'] = 'None';
if (file_exists($sModule.'.php')) { @unlink($sModule.'.php'); }
$__sInfo['error'] = "The 'code/".$sModule.".js' file can not be deleted.";
$__sInfo['command'] = "unlink('".$sModule.".js')";
$__sInfo['values'] = 'None';
if (file_exists($sModule.'.js')) { @unlink($sModule.'.js'); }
$__sInfo['error'] = "The 'look/default/".$sModule.".html' file can not be deleted.";
$__sInfo['command'] = "unlink('../look/default/".$sModule.".html')";
$__sInfo['values'] = 'None';
if (file_exists('../look/default/'.$sModule.'.html')) { @unlink('../look/default/'.$sModule.'.html'); }
$__sInfo['error'] = "The 'look/default/".$sModule.".css' file can not be deleted.";
$__sInfo['command'] = "unlink('../look/default/".$sModule.".css')";
$__sInfo['values'] = 'None';
if (file_exists('../look/default/'.$sModule.'.css')) { @unlink('../look/default/'.$sModule.'.css'); }
$__sInfo['error'] = "The 'imgs/default/".$sModule.".png' file can not be deleted.";
$__sInfo['command'] = "unlink('../imgs/default/".$sModule.".png')";
$__sInfo['values'] = 'None';
if (file_exists('../imgs/default/'.$sModule.'.png')) { @unlink('../imgs/default/'.$sModule.'.png'); }
# if the module data does NOT want to be retained, then...
if (! $_POST['bRetainData']) {
$__sInfo['error'] = "The 'ModuleMaker_Modules' table can not be deleted from the database.";
$__sInfo['command'] = "DROP TABLE IF EXISTS ".DB_PRFX."ModuleMaker_Modules";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "The 'ModuleMaker_Tabs' table can not be deleted from the database.";
$__sInfo['command'] = "DROP TABLE IF EXISTS ".DB_PRFX."ModuleMaker_Tabs";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "The 'ModuleMaker_Groups' table can not be deleted from the database.";
$__sInfo['command'] = "DROP TABLE IF EXISTS ".DB_PRFX."ModuleMaker_Groups";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "The 'ModuleMaker_Objects' table can not be deleted from the database.";
$__sInfo['command'] = "DROP TABLE IF EXISTS ".DB_PRFX."ModuleMaker_Objects";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "The 'ModuleMaker_Languages' table can not be deleted from the database.";
$__sInfo['command'] = "DROP TABLE IF EXISTS ".DB_PRFX."ModuleMaker_Languages";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "The 'ModuleMaker_Actions' table can not be deleted from the database.";
$__sInfo['command'] = "DROP TABLE IF EXISTS ".DB_PRFX."ModuleMaker_Actions";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "The 'ModuleMaker_Code' table can not be deleted from the database.";
$__sInfo['command'] = "DROP TABLE IF EXISTS ".DB_PRFX."ModuleMaker_Code";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "The 'ModuleMaker_Parameters' table can not be deleted from the database.";
$__sInfo['command'] = "DROP TABLE IF EXISTS ".DB_PRFX."ModuleMaker_Parameters";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "The 'ModuleMaker_Operations' table can not be deleted from the database.";
$__sInfo['command'] = "DROP TABLE IF EXISTS ".DB_PRFX."ModuleMaker_Operations";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "The 'ModuleMaker_Values' table can not be deleted from the database.";
$__sInfo['command'] = "DROP TABLE IF EXISTS ".DB_PRFX."ModuleMaker_Values";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "The 'ModuleMaker_Themes' table can not be deleted from the database.";
$__sInfo['command'] = "DROP TABLE IF EXISTS ".DB_PRFX."ModuleMaker_Themes";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "The 'ModuleMaker_Styles' table can not be deleted from the database.";
$__sInfo['command'] = "DROP TABLE IF EXISTS ".DB_PRFX."ModuleMaker_Styles";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "The 'ModuleMaker_Styling' table can not be deleted from the database.";
$__sInfo['command'] = "DROP TABLE IF EXISTS ".DB_PRFX."ModuleMaker_Styling";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "The 'ModuleMaker_Layout' table can not be deleted from the database.";
$__sInfo['command'] = "DROP TABLE IF EXISTS ".DB_PRFX."ModuleMaker_Layout";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
delTree('../data/_modules/'.$sModule);
# otherwise, just remove the following two files
} else {
$__sInfo['error'] = "The 'data/_modules/".$sModule."/version' file can not be deleted.";
$__sInfo['command'] = "unlink('../data/_modules/".$sModule."/version')";
$__sInfo['values'] = 'None';
if (file_exists('../data/_modules/'.$sModule.'/version')) { @unlink('../data/_modules/'.$sModule.'/version'); }
$__sInfo['error'] = "The 'data/_modules/".$sModule."/hash' file can not be deleted.";
$__sInfo['command'] = "unlink('../data/_modules/".$sModule."/hash')";
$__sInfo['values'] = 'None';
if (file_exists('../data/_modules/'.$sModule.'/hash')) { @unlink('../data/_modules/'.$sModule.'/hash'); }
}
# Delete the group and module table values
# WARNING: this MUST come last in case any errors occur above, this script can be re-run
$__sInfo['error'] = "Failed to find the installed modules in the database."; # find if the module has already been added to the listing (for a subsequent install after a failure)
$__sInfo['command'] = "SELECT id FROM ".DB_PRFX."ApplicationSettings_Modules WHERE name=\"".$sMODULE."\"";
$__sInfo['values'] = 'None';
$Module = $_LinkDB->query($__sInfo['command']);
if ($Module->num_rows === 0) {
echo "<f><msg>The module could not be found in the database.</msg></f>";
return false;
} else { $module = $Module->fetch_assoc(); }
$__sInfo['error'] = "Failed to delete the 'Inventory' from the list of installed modules in the database.";
$__sInfo['command'] = "DELETE FROM ".DB_PRFX."ApplicationSettings_Grouped WHERE moduleID='".$module['id']."'";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "Failed to delete the 'Inventory' from the list of installed modules in the database.";
$__sInfo['command'] = "DELETE FROM ".DB_PRFX."ApplicationSettings_Modules WHERE name='".$sMODULE."' LIMIT 1";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
$__sInfo['error'] = "Failed to delete the admin module access for the 'Inventory' module.";
$__sInfo['command'] = "DELETE FROM ".DB_PRFX."Employees_Access WHERE moduleID='".$module['id']."'";
$__sInfo['values'] = 'None';
$stmt = $_LinkDB->query($__sInfo['command']);
if ($stmt === FALSE) { return false; }
return true;
}
?>