-
Notifications
You must be signed in to change notification settings - Fork 0
/
TreeSurv.php
1069 lines (1001 loc) · 37.9 KB
/
TreeSurv.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
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
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* TreeSurv is a mid-level class using a standard branching tree, mostly for Survloop's surveys and pages.
* But it does house some of the core functions to print the whole of a tree.
*
* Survloop - All Our Data Are Belong
* @package rockhopsoft/survloop
* @author Morgan Lesko <rockhoppers@runbox.com>
* @since v0.0.18
*/
namespace RockHopSoft\Survloop\Controllers\Tree;
use DB;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Response;
use App\Models\User;
use App\Models\SLSess;
use App\Models\SLSessLoops;
use App\Models\SLDefinitions;
use App\Models\SLNode;
use App\Models\SLNodeSaves;
use App\Models\SLNodeSavesPage;
use App\Models\SLFields;
use App\Models\SLTokens;
use App\Models\SLUsersActivity;
use App\Models\SLZips;
use App\Models\SLZipAshrae;
use RockHopSoft\Survloop\Controllers\Globals\Globals;
use RockHopSoft\Survloop\Controllers\Globals\Geographs;
use RockHopSoft\Survloop\Controllers\Tree\TreeNodeSurv;
use RockHopSoft\Survloop\Controllers\Tree\TreeSurvLoops;
class TreeSurv extends TreeSurvLoops
{
/**
* Top-level of the algorithm which traverses the branching tree
* which defines the generation of page.
*
* @return string
*/
public function printTreePublic()
{
$ret = '';
$GLOBALS["SL"]->microLog('Start printTreePublic(');
$this->loadTree();
$GLOBALS["SL"]->microLog('printTreePublic( after loadTree()');
if ($GLOBALS["SL"]->treeRow->tree_type == 'Survey'
&& $this->coreID <= 0) {
return $this->redir($GLOBALS["SL"]->getCurrTreeUrl(), true);
}
$ret .= $this->printTreePublicPageWrapOpen()
. $this->printTreeGetCurrNode();
$this->multiRecordCheck();
$GLOBALS["SL"]->microLog('printTreePublic( after multiRecordCheck(');
$this->loadAncestry($this->currNode());
$GLOBALS["SL"]->microLog('printTreePublic( before printNodePublic(');
$ret .= $this->printTreePublicCore($this->v["lastNode"]);
$GLOBALS["SL"]->microLog('printTreePublic( after printNodePublic(');
$ret .= $this->printTreePublicPageWrapClose();
if (!$this->hasAjaxWrapPrinting()) {
$GLOBALS["SL"]->pageJAVA
.= 'if (document.getElementById("dynamicJS")) document.getElementById("dynamicJS").remove();';
$GLOBALS["SL"]->pageAJAX
.= 'if (document.getElementById("maincontentWrap")) '
. '$("#maincontentWrap").fadeIn(50); ';
$ret = $GLOBALS["SL"]->pullPageJsCss($ret, $this->coreID)
. $GLOBALS["SL"]->pageSCRIPTS;
$GLOBALS["SL"]->pageSCRIPTS = '';
}
$GLOBALS["SL"]->microLog('printTreePublic( end');
return $ret;
}
/**
* Runs the core commands which actually print this tree.
*
* @return string
*/
private function printTreePublicCore($lastNode)
{
$this->v["nodeKidFunks"] = '';
$fadeIn = $this->printTreeLoadFadeIn();
$goSkinny = ($GLOBALS["SL"]->treeRow->tree_opts%Globals::TREEOPT_SKINNY == 0);
$goSkinny = (!$this->hasFrameLoad() && $goSkinny);
return $this->loadProgTopTabs() . "\n"
. $this->printTreePublicAnimWrapOpen($fadeIn, $goSkinny)
. ((trim($GLOBALS["errors"]) != '') ? $GLOBALS["errors"] : '')
. $this->nodeSessDump('pageStart')
. $this->printNodePublic($this->currNode(), $this->currNodeSubTier) . "\n"
. $this->loadProgBarBot() . "\n"
// (($this->allNodes[$this->currNode()]->nodeOpts%29 > 0)
// ? $this->loadProgBarBot() : '') // not exit page?
. $this->printCurrRecMgmt() . $this->sessDump($lastNode) . "\n"
. $this->printTreePublicAnimWrapClose($goSkinny);
}
/**
* Generate the start of this page's wrapper.
*
* @return string
*/
private function printTreePublicPageWrapOpen()
{
$ret = '';
$GLOBALS["SL"]->pageJAVA .= view(
'vendor.survloop.js.inc-check-tree-load',
[ "treeID" => $this->treeID ]
)->render();
if ($this->hasAjaxWrapPrinting()) {
$ret .= '<div class="nodeAnchor">'
. '<a name="maincontent" id="maincontent"></a>'
. '</div><div id="ajaxWrap">';
}
if (!$this->isPage) {
$ret .= '<div id="maincontentWrap" style="display: none;">' . "\n";
}
return $ret;
}
/**
* Generate the end of this page's wrapper.
*
* @return string
*/
private function printTreePublicPageWrapClose()
{
$ret = '';
if (!$this->isPage) {
$ret .= '</div> <!-- end maincontentWrap --> ';
}
if ($this->hasAjaxWrapPrinting()) {
$ret .= '</div> <!-- end ajaxWrap --> ';
}
return $ret;
}
/**
* Generate the start of this page's animation wrapper.
*
* @return string
*/
private function printTreePublicAnimWrapOpen($fadeIn, $goSkinny)
{
$dispStyle = 'block';
if ($fadeIn) {
$dispStyle = 'none';
}
$ret = '<div id="pageAnimWrap' . $GLOBALS['SL']->treeID
. '" class="w100" style="display: ' . $dispStyle . ';">';
if ($goSkinny) {
$ret .= '<center><div id="skinnySurv" class="treeWrapForm">';
} elseif (!$this->isPage) {
$ret .= '<div id="wideSurv" class="container">';
}
return $ret;
}
/**
* Generate the end of this page's animation wrapper.
*
* @return string
*/
private function printTreePublicAnimWrapClose($goSkinny)
{
$ret = '';
if ($goSkinny) {
$ret .= '</div><center> <!-- end skinnySurv -->';
} elseif (!$this->isPage) {
$ret .= '</div> <!-- end wideSurv -->';
}
$ret .= '</div> <!-- end pageAnimWrap -->';
if (isset($GLOBALS["SL"]->treeSettings["footer"])
&& isset($GLOBALS["SL"]->treeSettings["footer"][0])
&& trim($GLOBALS["SL"]->treeSettings["footer"][0]) != '') {
$this->v["footOver"] = $GLOBALS["SL"]->treeSettings["footer"][0];
}
if (trim($this->v["nodeKidFunks"]) != '') {
$GLOBALS["SL"]->pageAJAX .= 'function checkAllNodeKids() { '
. $this->v["nodeKidFunks"]
/* . ' if (nodeList && nodeList.length > 0) { for (var i=0; i < nodeList.length; i++) { '
. 'chkNodeParentVisib(nodeList[i]); } } ' */
. ' setTimeout(function() { checkAllNodeKids(); }, 3000); }' // re-check every 3 seconds
. ' setTimeout(function() { checkAllNodeKids(); }, 1);' . "\n";
}
return $ret;
}
/**
* Determine whether or not this page should fade in after loading.
*
* @return boolean
*/
private function printTreeLoadFadeIn()
{
$fadeIn = ($GLOBALS['SL']->treeRow->tree_opts%Globals::TREEOPT_FADEIN == 0);
if ($GLOBALS["SL"]->isPrintView()) {
$fadeIn = false;
}
if ($fadeIn) {
$GLOBALS["SL"]->setTreePageFadeIn($this->setTreePageFadeInDelay());
}
return $fadeIn;
}
/**
* Determine the current node with help from a form submission.
*
* @return boolean
*/
private function printTreeLoadLastNode()
{
if ($this->hasREQ && $GLOBALS["SL"]->REQ->has('node')) {
$nodeIn = intVal($GLOBALS["SL"]->REQ->input('node'));
if ($nodeIn > 0) {
$this->updateCurrNode($nodeIn);
}
}
$this->v["lastNode"] = $this->currNode();
if ($this->hasREQ && $GLOBALS["SL"]->REQ->has('superHardJump')) {
$this->updateCurrNode(intVal($GLOBALS["SL"]->REQ->superHardJump));
}
if (session()->has('redirLoginSurvey') || $GLOBALS["SL"]->REQ->has('test')) {
$next = $this->nextNode($this->currNode(), $this->currNodeSubTier);
$this->updateCurrNodeNB($next);
$this->setNodeIdURL($this->currNode());
session()->forget('redirLoginSurvey');
session()->save();
}
if (!isset($GLOBALS["SL"]->treeRow->tree_root)) {
$GLOBALS["SL"]->loadGlobalTables($this->dbID, $this->treeID, $this->treeID);
}
if ($this->currNode() < 0 || !isset($this->allNodes[$this->currNode()])) {
$this->updateCurrNode($GLOBALS["SL"]->treeRow->tree_root);
//return '<h1>Sorry, Page Not Found.</h1>';
}
// double-check we haven't landed on a mid-page node
if (isset($this->allNodes[$this->currNode()])
&& !$this->allNodes[$this->currNode()]->isPage()
&& !$this->allNodes[$this->currNode()]->isLoopRoot()) {
$this->updateCurrNode($this->allNodes[$this->currNode()]->getParent());
}
return $this->v["lastNode"];
}
/**
* Determines which node the top-level of the algorithm
* should start from.
*
* @return boolean
*/
private function printTreeGetCurrNode()
{
$ret = '';
$this->printTreeLoadLastNode();
$GLOBALS["SL"]->microLog('printTreeGetCurrNode( after redirect checks');
$this->loadAncestry($this->currNode());
$GLOBALS["SL"]->microLog('printTreeGetCurrNode( after loadAncestry(');
if ($this->hasREQ && $GLOBALS["SL"]->REQ->has('step')) {
$GLOBALS["SL"]->microLog('printTreeGetCurrNode( start has posted step');
if (!$this->sessInfo) {
$this->createNewSess();
}
// Process form POST for all nodes, then store the data updates...
if ($this->REQstep == 'autoSave'
&& (!$GLOBALS["SL"]->REQ->has('chgCnt')
|| intVal($GLOBALS["SL"]->REQ->get('chgCnt')) <= 0)) {
return 'No changes found to auto-save. <3';
}
$nodeIn = $GLOBALS["SL"]->REQ->node;
$logTitle = 'PAGE SAVE' . (($this->REQstep == 'autoSave') ? ' AUTO' : '');
$this->sessData->logDataSave($nodeIn, $logTitle, -3, '', '');
$GLOBALS["SL"]->microLog('printTreeGetCurrNode( before postNodePublic');
$ret .= $this->postNodePublic($nodeIn);
$GLOBALS["SL"]->microLog('printTreeGetCurrNode( after postNodePublic');
if ($this->REQstep == 'autoSave') {
return 'Saved!-)';
}
//$this->loadAllSessData();
// refresh should not bedefault, run manually where needed
$GLOBALS["SL"]->microLog('printTreeGetCurrNode( before post-step-redirect');
if (!$this->isPage) {
if ($this->REQstep == 'save') {
if ($GLOBALS["SL"]->REQ->has('popStateUrl')
&& trim($GLOBALS["SL"]->REQ->popStateUrl) != '') {
$url = $GLOBALS["SL"]->REQ->popStateUrl;
$url = str_replace($GLOBALS["SL"]->treeBaseSlug, '', $url);
$this->setNodeURL($url);
$this->pullNewNodeURL();
} else {
$redir1 = $this->printTreeGetCurrNodeCheckJumpRedir();
if ($redir1 != '') {
return $this->redir($redir1, true);
}
}
} else { // REQstep != 'save'
$this->printTreeGetCurrNodeProcessStep($nodeIn);
}
}
$GLOBALS["SL"]->microLog('printTreeGetCurrNode( end has posted step');
} else {
if (trim($this->urlSlug) != '') {
$this->pullNewNodeURL();
if ($this->currNode()
== $GLOBALS["SL"]->treeRow->tree_first_page
&& $GLOBALS["SL"]->REQ->has('start')
&& intVal($GLOBALS["SL"]->REQ->get('start')) == 1) {
$this->runDataManip($GLOBALS["SL"]->treeRow->tree_root);
}
}
$this->checkLoopsLeft($this->currNode());
}
$GLOBALS["SL"]->microLog('printTreeGetCurrNode( start moving currNode');
if (!$this->isStepUpload()) {
$this->printTreeGetCurrNodeStepNormal();
//$this->loadAllSessData();
}
/* if ($this->hasREQ && $GLOBALS["SL"]->REQ->has('step')) {
$newNodeURL = $this->currNodeURL();
if ($newNodeURL != '') {
echo '<script type="text/javascript"> window.location="' . $newNodeURL . '"; </script>';
exit;
}
} */
$GLOBALS["SL"]->microLog('printTreeGetCurrNode( end moving currNode');
if (!$GLOBALS["SL"]->REQ->has('popStateUrl')
|| trim($GLOBALS["SL"]->REQ->popStateUrl) == '') {
$this->pushCurrNodeURL($this->currNode());
}
$GLOBALS["SL"]->x["pageLoadCurrNode"] = $this->currNode();
return $ret;
}
/**
* Determine the current node with help from a form submission.
*
* @return boolean
*/
private function printTreeGetCurrNodeProcessStep($nodeIn)
{
$this->updateCurrNode($nodeIn);
$this->v["lastNode"] = $nodeIn;
// Now figure what comes next.
if (!$this->isStepUpload()) { // if uploading, then don't change nodes yet
$jumpID = $this->jumpToNode($this->currNode());
$jumpArr = ['exitLoop', 'exitLoopBack', 'exitLoopJump'];
if (in_array($this->REQstep, $jumpArr)
&& trim($GLOBALS["SL"]->REQ->input('loop')) != '') {
$this->sessData->logDataSave(
$this->currNode(),
$GLOBALS["SL"]->closestLoop["obj"]->data_loop_table,
$GLOBALS["SL"]->REQ->input('loopItem'),
$this->REQstep,
$GLOBALS["SL"]->REQ->input('loop')
);
$this->leavingTheLoop($GLOBALS["SL"]->REQ->input('loop'));
if ($this->REQstep == 'exitLoop') {
$next = $this->nextNodeSibling($this->currNode());
$this->updateCurrNodeNB($next);
} elseif ($this->REQstep == 'exitLoopBack') {
$prev = $this->prevNode($this->currNode());
$prev = $this->getNextNonBranch($prev, 'prev');
$this->updateCurrNodeNB($prev, 'prev');
} else {
$this->updateCurrNode($jumpID); // exit through jump
}
} elseif ($jumpID > 0) {
$this->updateCurrNode($jumpID);
} else { // no jumps, let's do the old back and forth...
if ($this->REQstep == 'back') {
$prev = $this->prevNode($this->currNode());
$prev = $this->getNextNonBranch($prev, 'prev');
$this->updateCurrNodeNB($prev, 'prev');
} else {
$next = $this->nextNode($this->currNode(), $this->currNodeSubTier);
$this->updateCurrNodeNB($next);
}
}
}
return true;
}
/**
* Determine the redirect URL if a tree jump is needed.
*
* @return string
*/
private function printTreeGetCurrNodeCheckJumpRedir()
{
$redir = '';
if ($GLOBALS["SL"]->REQ->has('jumpTo')) {
$jump = trim($GLOBALS["SL"]->REQ->get('jumpTo'));
if ($jump != '') {
$redir = $jump;
}
}
if ($GLOBALS["SL"]->REQ->has('afterJumpTo')) {
$jump = trim($GLOBALS["SL"]->REQ->get('afterJumpTo'));
if ($jump != '') {
session()->put('redir2', $jump);
session()->save();
}
}
return $redir;
}
/**
* Determine the next node in the normal tree traversal.
*
* @return boolean
*/
private function printTreeGetCurrNodeStepNormal()
{
$this->updateCurrNodeNB($this->currNode());
if ($this->hasREQ && $GLOBALS["SL"]->REQ->has('step')) {
$this->loadAllSessData();
$this->checkLoopsPostProcessing($this->currNode(), $this->v["lastNode"]);
} else {
if (!$this->checkNodeConditions($this->currNode())) {
$next = $this->nextNode($this->currNode(), $this->currNodeSubTier);
$this->updateCurrNode($next);
}
$this->updateCurrNodeNB($this->currNode());
}
return true;
}
public function printTreeNodePublic($nID)
{
$ret = '';
$this->loadTree();
$this->updateCurrNode($nID);
$this->loadAncestry($this->currNode());
return $this->printNodePublic($this->currNode(), $this->currNodeSubTier);
}
/**
* This function is the primary front-facing
* controller for the user experience.
*
* @return string
*/
public function index(Request $request, $type = '', $val = '')
{
$GLOBALS["SL"]->microLog('TreeSurv index(' . $type);
//$this->loadTree($this->treeID, $request);
$this->survloopInit($request, '');
$GLOBALS["SL"]->microLog('TreeSurv index( after survLoopInit');
$chk = $this->checkSystemInit();
if ($chk && trim($chk) != '') {
return $chk;
}
$notes = $this->indexChecks($request, $type);
$this->v["content"] = $this->printTreePublic();
if ($notes != '') {
$this->v["content"] .= '<!-- ' . $notes . ' -->';
}
$this->loadTreePageJava();
if ($request->has('ajax') && $request->ajax == 1) {
// tree form ajax submission
return $this->ajaxContentWrapCustom($this->v["content"]);
}
// Otherwise, Proceed Running Various Index Functions
$this->v["currInReport"] = $this->currInReport();
if ($type == 'testRun') {
return $this->redir('/');
}
$this->v["content"] = $GLOBALS["SL"]->pullPageJsCss(
$this->v["content"],
$this->coreID
);
return $this->indexResponse();
}
/**
* Check, initialize, and log data needed to generate page.
*
* @return string
*/
public function indexChecks(Request $request, $type = '')
{
$this->checkPageViewPerms();
$notes = '';
if (isset($GLOBALS["SL"]->pageView)
&& trim($GLOBALS["SL"]->pageView) != '') {
$notes .= 'pv.' . $GLOBALS["SL"]->pageView
. ' dp.' . $GLOBALS["SL"]->dataPerms;
}
if ($GLOBALS["SL"]->treeRow->tree_opts%Globals::TREEOPT_REPORT == 0) {
$this->fillGlossary(); // is report
}
//if ($this->v["uID"] > 0) $this->loadAllSessData();
if ($type == 'ajaxChecks') {
$this->runAjaxChecks($request);
exit;
}
if (!isset($this->v["javaNodes"])) {
$this->v["javaNodes"] = '';
}
if ($this->v["currPage"][0] != '/' && isset($this->v["uID"])) {
$log = new SLUsersActivity;
$log->user_act_user = $this->v["uID"];
$log->user_act_curr_page = $this->v["currPage"][0] . ' ' . $notes;
$log->save();
}
return $notes;
}
/**
* Determine final formatting options on the generated page.
*
* @return string
*/
public function indexResponse()
{
if ($GLOBALS["SL"]->isPdfView()) {
return $this->v["content"];
}
if ($GLOBALS["SL"]->treeIsAdmin) {
return $GLOBALS["SL"]->swapSessMsg($this->v["content"]);
}
return $GLOBALS["SL"]->swapSessMsg(
view('vendor.survloop.master', $this->v)->render()
);
}
/**
* Load the current tree and page in the Javascript load.
*
* @return boolean
*/
protected function loadTreePageJava()
{
$GLOBALS["SL"]->pageJAVA .= 'currTreeType = "'
. $GLOBALS["SL"]->treeRow->tree_type
. '"; setCurrPage("' . $this->v["currPage"][1] . '", "'
. $this->v["currPage"][0] . '", ' . $this->currNode()
. '); function loadPageNodes() { if (typeof chkNodeVisib === "function") { '
. $this->v["javaNodes"] . ' } else { setTimeout("loadPageNodes()", 500); } '
. 'return true; } setTimeout("loadPageNodes()", 100); ' . "\n";
// Check if search results page
if ($GLOBALS["SL"]->treeRow->tree_opts%31 == 0
&& $GLOBALS["SL"]->REQ->has('s')
&& trim($GLOBALS["SL"]->REQ->get('s')) != '') {
if ($GLOBALS["SL"]->treeRow->tree_opts%3 == 0
|| $GLOBALS["SL"]->treeRow->tree_opts%17 == 0
|| $GLOBALS["SL"]->treeRow->tree_opts%41 == 0
|| $GLOBALS["SL"]->treeRow->tree_opts%43 == 0) {
$GLOBALS["SL"]->pageJAVA .= 'setTimeout(\''
. 'if (document.getElementById("admSrchFld")) '
. 'document.getElementById("admSrchFld").value='
. json_encode(trim($GLOBALS["SL"]->REQ->get('s')))
. '\', 10); ';
} // else check for the main public search field?
}
return true;
}
/**
* Override the default behavior for wrapping a tree which has
* been called through an ajax call.
*
* @return string
*/
protected function ajaxContentWrapCustom($str, $nID = -3)
{
return $str;
}
protected function runCurrNode($nID)
{
//if ($nID == $GLOBALS["SL"]->treeRow->tree_root) $this->runDataManip($nID);
return true;
}
protected function runDataManip($nID, $betweenPages = false)
{
$curr = $this->allNodes[$nID];
if ($curr->isDataManip()) {
$curr->fillNodeRow();
$curr->nID = $nID;
list($curr->tbl, $curr->fld, $newVal) = $curr->getManipUpdate();
if ($curr->nodeType == 'Data Manip: New') {
//$newObj = $this->checkNewDataRecord($tbl, $fld, $newVal);
//if (!$newObj) {
$newObj = $this->sessData->newDataRecord($curr->tbl, $curr->fld, $newVal);
if ($newObj) {
$this->sessData->startTmpDataBranch($curr->tbl, $newObj->getKey());
$this->sessData->currSessData($curr, 'update', $newVal);
$manipUpdates = SLNode::where('node_tree', $this->treeID)
->where('node_type', 'Data Manip: Update')
->where('node_parent_id', $nID)
->get();
if ($manipUpdates->isNotEmpty()) {
foreach ($manipUpdates as $nodeRow) {
$nID2 = $nodeRow->node_id;
$tmp = new TreeNodeSurv($nID2, $nodeRow);
$tmp->nID = $nID2;
$tmp->fillNodeRow();
list($tmp->tbl, $tmp->fld, $newVal) = $tmp->getManipUpdate();
$this->sessData->currSessData($tmp, 'update', $newVal);
}
}
if ($betweenPages) {
$this->sessData->endTmpDataBranch($curr->tbl);
}
}
//}
//$this->loadAllSessData();
} elseif ($this->allNodes[$nID]->nodeType == 'Data Manip: Update') {
$this->sessData->currSessData($curr, 'update', $newVal);
}
}
return true;
}
protected function reverseDataManip($nID)
{
if ($this->allNodes[$nID]->isDataManip()) {
list($tbl, $fld, $newVal) = $this->allNodes[$nID]->getManipUpdate();
if ($this->allNodes[$nID]->nodeType == 'Data Manip: New') {
$this->sessData->deleteDataRecord($tbl, $fld, $newVal);
//$this->loadAllSessData();
}
}
return true;
}
protected function nodeBranchInfo($nID, $curr = NULL)
{
$tbl = $fld = $newVal = '';
if (!$curr) {
$curr = $this->allNodes[$nID];
}
$types = [ 'Data Manip: New', 'Data Manip: Wrap' ];
if (in_array($curr->nodeType, $types)) { // Data Manip: Update
list($tbl, $fld, $newVal) = $curr->getManipUpdate();
if ($curr->nodeType == 'Data Manip: Wrap') {
$tbl = $curr->dataBranch;
}
}
if ($curr->isLoopCycle()) {
$loop = '';
if (isset($curr->nodeRow->node_response_set)
&& strpos($curr->nodeRow->node_response_set, 'LoopItems:') === 0) {
$loop = trim(str_replace('LoopItems:', '', $curr->nodeRow->node_response_set));
}
if ($loop != ''
&& isset($GLOBALS["SL"]->dataLoops[$loop])
&& isset($GLOBALS["SL"]->dataLoops[$loop]->node_loop_table)) {
$tbl = $GLOBALS["SL"]->dataLoops[$loop]->node_loop_table;
} elseif (isset($curr->dataBranch) && trim($curr->dataBranch) != '') {
$tbl = $curr->dataBranch;
}
}
return [ $tbl, $fld, $newVal ];
}
protected function loadManipBranch($nID, $force = false)
{
list($tbl, $fld, $newVal) = $this->nodeBranchInfo($nID);
if ($tbl != '') {
$manipBranchRow = $this->sessData->checkNewDataRecord($tbl, $fld, $newVal, []);
if (!$manipBranchRow && $force) {
$manipBranchRow = $this->sessData->newDataRecord($tbl, $fld, $newVal);
}
if ($manipBranchRow) {
$this->sessData->startTmpDataBranch($tbl, $manipBranchRow->getKey());
}
}
return true;
}
protected function closeManipBranch($nID)
{
list($tbl, $fld, $newVal) = $this->nodeBranchInfo($nID);
if ($tbl != '') {
$this->sessData->endTmpDataBranch($tbl);
}
return true;
}
protected function hasParentDataManip($nID)
{
$found = false;
while ($this->hasNode($nID) && !$found) {
if ($this->allNodes[$nID]->isDataManip()) {
list($tbl, $fld, $newVal) = $this->allNodes[$nID]->getManipUpdate();
if ($this->allNodes[$nID]->nodeType == 'Data Manip: New'
&& $newVal != ''
&& $fld != '') {
$found = true;
}
}
$nID = $this->allNodes[$nID]->getParent();
}
return $found;
}
protected function getAncestorPage($nID)
{
$pageNode = -3;
$parent = -3;
if (isset($this->allNodes[$nID])) {
$parent = $this->allNodes[$nID]->getParent();
while ($parent > 0
&& $pageNode <= 0
&& isset($this->allNodes[$parent])) {
if ($this->allNodes[$parent]->nodeType == 'Page') {
$pageNode = $parent;
}
$parent = $this->allNodes[$parent]->getParent();
}
}
return $pageNode;
}
public function loadNodeURL(Request $request, $nodeSlug = '')
{
$GLOBALS["SL"]->microLog('loadNodeURL(' . $nodeSlug);
if (trim($nodeSlug) != '') {
$this->setNodeURL($nodeSlug);
}
return $this->index($request);
}
public function runAjaxChecksCustom(Request $request, $over = '')
{
return false;
}
public function runAjaxChecks(Request $request, $over = '')
{
$this->runAjaxChecksCustom($request, $over);
if ($request->has('email') && $request->has('password')) {
print_r($request);
$chk = User::where('email', $request->email)
->get();
if ($chk->isNotEmpty()) {
echo 'found';
}
echo 'not found';
exit;
}
}
public function testRun(Request $request)
{
return $this->index($request, 'testRun');
}
public function ajaxChecksCustom(Request $request, $type = '')
{
return '';
}
public function ajaxChecks(Request $request, $type = '')
{
$this->survloopInit($request, '/ajax/' . $type);
$ret = $this->ajaxChecksCustom($request, $type);
if (trim($ret) != '') {
return $ret;
}
$ret = $this->ajaxChecksSL($request, $type);
if (trim($ret) != '') {
return $ret;
}
return $this->index($request, 'ajaxChecks');
}
public function ajaxChecksSL(Request $request, $type = '')
{
$this->survloopInit($request, '/ajadm/' . $type);
$nID = (($request->has('nID')) ? trim($request->get('nID')) : '');
if ($type == 'adm-menu-toggle') {
return $this->ajaxAdmMenuToggle($request);
} elseif ($type == 'my-profile-enable-mfa') {
return $this->ajaxEnableMfaForm($request);
} elseif ($type == 'my-profile-disable-mfa') {
return $this->ajaxDisableMfaForm($request);
} elseif ($type == 'data-set-search-results') {
return $this->printDataSetSearchResultsAjax($request);
} elseif ($type == 'color-pick') {
return $this->ajaxColorPicker($request);
} elseif (substr($type, 0, 4) == 'img-') {
$imgID = (($request->has('imgID')) ? trim($request->get('imgID')) : '');
$presel = (($request->has('presel')) ? trim($request->get('presel')) : '');
if ($type == 'img-sel') {
$newUp = (($request->has('newUp')) ? trim($request->get('newUp')) : '');
return $GLOBALS["SL"]->getImgSelect($nID, $GLOBALS["SL"]->dbID, $presel, $newUp);
} elseif ($type == 'img-deet') {
return $GLOBALS["SL"]->getImgDeet($imgID, $nID);
} elseif ($type == 'img-save') {
return $GLOBALS["SL"]->saveImgDeet($imgID, $nID);
} elseif ($type == 'img-up') {
return $GLOBALS["SL"]->uploadImg($nID, $presel);
}
} elseif ($type == 'log-pro-tip') {
$this->ajaxLogLastProTip($request);
} elseif ($type == 'tbl-add-row') {
$this->ajaxTblAddRow($request);
} elseif ($type == 'get-zip-state-climate') {
$this->ajaxGetZipStateClimate($request);
}
return '';
}
/**
* Print search results across multiple data sets.
*
* @param Illuminate\Http\Request $request
* @return string
*/
private function printDataSetSearchResultsAjax(Request $request)
{
$type = 0;
if ($request->has('type')) {
$type = intVal($request->get('type'));
}
if (sizeof($GLOBALS["SL"]->allCoreTbls) > 0) {
foreach ($GLOBALS["SL"]->allCoreTbls as $tbl) {
if (intVal($type) == intVal($tbl["id"])) {
$ret = $this->printDataSetResultsAjaxCustom($request, $tbl);
if (trim($ret) != '') {
return $ret;
}
return $this->printDataSetResultsAjax($request, $tbl);
}
}
}
return '<!-- no data set search results found -->';
}
/**
* Customize search results from one data sets.
*
* @param Illuminate\Http\Request $request
* @param array $tblInfo
* @return string
*/
private function printDataSetResultsAjax(Request $request, $tblInfo)
{
return '<i>Auto-printing multi-data-set searches coming soon...</i>';
}
/**
* Customize search results from one data sets.
*
* @param Illuminate\Http\Request $request
* @param array $tblInfo
* @return string
*/
protected function printDataSetResultsAjaxCustom(Request $request, $tblInfo)
{
return '';
}
/**
* Customize search results from one data sets.
*
* @param Illuminate\Http\Request $request
* @param array $tblInfo
* @return string
*/
private function printDataSetResultsWrap(Request $request, $tblInfo)
{
return '<h3 class="slBlueDark">' . $tblInfo["name"] . '</h3>
<div id="setSearchResults' . $tblInfo["name"] . '" class="w100"></div>
<script type="text/javascript"> $(document).ready(function(){
setTimeout(function() {
var url = "/ajax/data-set-search-results?type='
. strtolower($tblInfo["name"]) . '";
$("#setSearchResults' . $tblInfo["name"] . '").load(url);
console.log(url);
}, 10);
}); </script>';
}
private function ajaxAdmMenuToggle(Request $request)
{
$open = 0;
if ($request->has('status')
&& strtolower(trim($request->get('status'))) == 'open') {
$open = 1;
}
session()->put('admMenuOpen', $open);
session()->save();
return '';
}
private function ajaxEnableMfaForm(Request $request)
{
return view('vendor.survloop.auth.enable-mfa');
}
private function ajaxDisableMfaForm(Request $request)
{
return view('vendor.survloop.auth.disable-mfa');
}
protected function ajaxColorPicker(Request $request)
{
$fldName = $preSel = '';
if ($request->has('fldName')) {
$fldName = trim($request->get('fldName'));
}
if ($request->has('preSel')) {
$preSel = '#' . trim($request->get('preSel'));
}
if (trim($fldName) != '') {
$sysColors = [];
$sysStyles = SLDefinitions::where('def_database', 1)
->where('def_set', 'Style Settings')
->orderBy('def_order')
->get();
$isCustom = true;
if ($sysStyles->isNotEmpty()) {
foreach ($sysStyles as $i => $sty) {
if (strpos($sty->def_subset, 'color-') !== false
&& !in_array($sty->def_description, $sysColors)) {
$sysColors[] = $sty->def_description;
if ($sty->def_description == $preSel) {
$isCustom = false;
}
}
}
}
return view(
'vendor.survloop.forms.inc-color-picker-ajax',
[
"sysColors" => $sysColors,
"fldName" => $fldName,
"preSel" => $preSel,
"isCustom" => $isCustom
]
);
}
return '';
}
protected function ajaxLogLastProTip(Request $request)
{
if ($request->has('tree')
&& intVal($request->get('tree')) > 0
&& $request->has('tip')
&& intVal($request->get('tip')) > 0) {
$tok = $this->getProTipToken();
$tok->tok_tok_token = intVal($request->get('tip'));
$tok->save();
}
exit;
}
protected function ajaxGetZipStateClimate(Request $request)
{
$ret = ' ';
if ($request->has('zip')
&& strlen(trim($request->get('zip'))) >= 5) {
$GLOBALS["SL"]->loadStates();
$zipIn = trim($request->get('zip'));
$zipRow = $GLOBALS["SL"]->states->getZipRow($zipIn);
if ($zipRow && isset($zipRow->zip_zip)) {
$ashRow = null;
if (isset($zipRow->zip_state) && isset($zipRow->zip_county)) {
$ashRow = SLZipAshrae::where('ashr_state', $zipRow->zip_state)
->where('ashr_county', 'LIKE', $zipRow->zip_county)
->first();
}
$ret = $this->printZipStateClimateDesc($zipRow, $ashRow);
} else {
$ret = ' ? ';
}
}
echo $ret;
exit;
}
protected function printZipStateClimateDesc($zipRow, $ashRow)
{
$ret = '';
if ($ashRow && isset($ashRow->ashr_zone)) {
$ret = $zipRow->zip_state . ', Climate Zone '
. $ashRow->ashr_zone;
$states = new Geographs(true);
$zone = $states->getAshraeZoneLabel($ashRow->ashr_zone);
if ($zone != '') {
$ret .= ', ' . $zone;
}
} else {