-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.php
1066 lines (947 loc) · 38 KB
/
index.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
/**
* Copyright (C) 2013-2019 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop 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
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
*/
use Combodo\iTop\Application\Branding;
use Combodo\iTop\Application\UI\Base\Component\Alert\AlertUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Button\Button;
use Combodo\iTop\Application\UI\Base\Component\Button\ButtonUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\FieldSet\FieldSetUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Form\FormUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Html\Html;
use Combodo\iTop\Application\UI\Base\Component\Input\InputUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Panel\PanelUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Layout\TabContainer\TabContainer;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlockUIBlockFactory;
/**
* Welcome the user
*/
function DisplayIndex()
{
$oAlert = AlertUIBlockFactory::MakeForInformation("Welcome, use this toolkit in order to assist you in your iTop customization.","Please keep in mind that this is a developer tool that must never be hosted on your production server.");
$oAlert->AddSubBlock(new Html("Please read carefully <a target='_blank' href='https://www.itophub.io/wiki/page?id=latest%3Acustomization%3Adatamodel&s%5B0%5D=toolkit#using_the_toolkit'>the documentation</a> prior any use!"));
return $oAlert;
}
/**
* Check the consistency
*/
function CheckConsistency()
{
$oBlock = UIContentBlockUIBlockFactory::MakeStandard();
$oAlert = AlertUIBlockFactory::MakeForInformation("Use this page to validate any modification made to the PHP classes that define the 'data model'.","It is advisable to fix any error detected at this stage before applying changes from the itop update tab.");
$oBlock->AddSubBlock($oAlert);
$oDivAction=UIContentBlockUIBlockFactory::MakeStandard("content_php",['ibo-is-html-content']);
$oBlock->AddSubBlock($oDivAction);
$oButton=ButtonUIBlockFactory::MakeForPrimaryAction("Check Consistency","a","b",false,"bt_content_php");
$oButton->SetOnClickJsCode('CheckConsistency(true);');
$oBlock->AddSubBlock($oButton);
return $oBlock;
}
/**
* Check the database schema - renamed "Update Itop" in the GUI!
*/
function CheckDBSchema()
{
$oBlock = UIContentBlockUIBlockFactory::MakeStandard();
$oAlert = AlertUIBlockFactory::MakeForInformation("Use this page to preview the changes in the format of the database, and update iTop."," For example if you add a new field to an object, this new field must be added into the database as well.<br/><b>Note:</b> the current version of the tool does not remove unused fields!");
$oBlock->AddSubBlock($oAlert);
$oFieldSetDB = FieldSetUIBlockFactory::MakeStandard('DB Schema');
$oBlock->AddSubBlock($oFieldSetDB);
$oDivAction=UIContentBlockUIBlockFactory::MakeStandard("content_schema",['ibo-is-visible']);
$oFieldSetDB->AddSubBlock($oDivAction);
$oButtonSchema=ButtonUIBlockFactory::MakeForPrimaryAction("📀 Check DB Schema","a","b",false, "bt_content_schema");
$oButtonSchema->SetOnClickJsCode('CheckDBSchema(true);');
$oDivAction->AddSubBlock($oButtonSchema);
$oFieldSetCompile = FieldSetUIBlockFactory::MakeStandard('Compilation');
$oBlock->AddSubBlock($oFieldSetCompile);
$sSourceDir = MetaModel::GetConfig()->Get('source_dir');
$sSourceDirHtml = htmlentities($sSourceDir, ENT_QUOTES, 'UTF-8');
if (function_exists('symlink'))
{
$oCheckbox = InputUIBlockFactory::MakeForInputWithLabel('Create symbolic links instead of creating a copy in env-production (useful for debugging extensions)', "symlink", 1, "symlink", 'checkbox');
$oCheckbox->SetBeforeInput(false);
$oCheckbox->GetInput()->AddCSSClass('ibo-input-checkbox');
$oFieldSetCompile->AddSubBlock($oCheckbox);
if (defined('\MFCompiler::USE_SYMBOLIC_LINKS_FILE_PATH') && (\MFCompiler::IsUseSymbolicLinksFlagPresent()))
{
/** @var \Combodo\iTop\Application\UI\Base\Component\Input\Input $oCheckboxInput */
$oCheckboxInput = $oCheckbox->GetInput();
$oCheckboxInput->SetIsChecked(true);
}
}
$oDivButton = UIContentBlockUIBlockFactory::MakeStandard("div_bt_compilation",['ibo-is-visible','mt-5','mb-5']);
$oFieldSetCompile->AddSubBlock($oDivButton);
$oButtonCompile=ButtonUIBlockFactory::MakeForPrimaryAction("📄 Update iTop code","Compile from $sSourceDirHtml to env-production","b",false, "bt_content_apply_sql");
$oButtonCompile->SetOnClickJsCode('doApply(false);');
$oDivButton->AddSubBlock($oButtonCompile);
$oFieldSetCompile->AddSubBlock(new Html('<span id="apply_sql_indicator"></span>'));
$oFieldSetCompile->AddSubBlock(UIContentBlockUIBlockFactory::MakeStandard("content_apply_sql",['ibo-is-visible']));
$oFieldQuickSetup = FieldSetUIBlockFactory::MakeStandard('Quick setup tool');
$oBlock->AddSubBlock($oFieldQuickSetup);
$oDivQS = UIContentBlockUIBlockFactory::MakeStandard("content_schema",['ibo-is-visible']);
$oAlert = AlertUIBlockFactory::MakeForInformation("Bookmark this button by dragging it in your bookmarks bar in order to skip every setup steps by clicking on your new bookmarklet with a setup page opened.");
$oDivQS->AddSubBlock($oAlert);
$oCurrentQuickCurrentButton = ButtonUIBlockFactory::MakeLinkNeutral("javascript:(function(){var quicksetup=document.createElement('SCRIPT');quicksetup.type='text/javascript';quicksetup.src='https://cdn.jsdelivr.net/gh/Combodo/itop-toolkit-community@master/js/quick-setup.js';document.getElementsByTagName('head')[0].appendChild(quicksetup);})();","Quick Setup");
$oCurrentQuickCurrentButton->SetOnClickJsCode('javascript:return false;')->SetColor(Button::ENUM_COLOR_SCHEME_PRIMARY);
$oDivQS->AddSubBlock($oCurrentQuickCurrentButton);
$oFieldQuickSetup->AddSubBlock($oDivQS);
return $oBlock;
}
/**
* Check the database schema
*/
function CheckDataIntegrity()
{
$oBlock = UIContentBlockUIBlockFactory::MakeStandard();
$oAlert = AlertUIBlockFactory::MakeForInformation("Use this page to check the integrity of the data in the iTop database.","");
$oBlock->AddSubBlock($oAlert);
$oFieldSetDatasources = FieldSetUIBlockFactory::MakeStandard('Synchronization Data Sources');
$oBlock->AddSubBlock($oFieldSetDatasources);
$oDivDatasources=UIContentBlockUIBlockFactory::MakeStandard("content_datasources",['ibo-is-visible']);
$oFieldSetDatasources->AddSubBlock($oDivDatasources);
$oButtonDatasources=ButtonUIBlockFactory::MakeForPrimaryAction("Check Data Sources","a","b", false, "bt_content_datasources");
$oButtonDatasources->SetOnClickJsCode('CheckDataSources(true);');
$oFieldSetDatasources->AddSubBlock($oButtonDatasources);
$oFieldSetKeys = FieldSetUIBlockFactory::MakeStandard('Hierarchical Keys');
$oBlock->AddSubBlock($oFieldSetKeys);
$oDivKeys=UIContentBlockUIBlockFactory::MakeStandard("content_hk",['ibo-is-html-content']);
$oFieldSetKeys->AddSubBlock($oDivKeys);
$oButtonKeys=ButtonUIBlockFactory::MakeForPrimaryAction("Check Hierarchical Keys","a","b", false, "bt_content_hk");
$oButtonKeys->SetOnClickJsCode('CheckHK(true);');
$oFieldSetKeys->AddSubBlock($oButtonKeys);
return $oBlock;
}
/**
* Check the dictionary definitions
*/
function CheckDictionary()
{
$oTabContainer = UIContentBlockUIBlockFactory::MakeStandard();
//** Tab:tab_dict_0 */
$oTabComplete = FieldSetUIBlockFactory::MakeStandard('Complete existing language');
$oTabContainer->AddSubBlock($oTabComplete);
$oAlert = AlertUIBlockFactory::MakeForInformation("This page lists all the missing items in the 'dictionary' which is used for the display and localization in iTop. ","To fix the issues, edit the output below and paste it into the appropriate dictionary.php file.");
$oTabComplete->AddSubBlock($oAlert);
$oDivAction=UIContentBlockUIBlockFactory::MakeStandard("content_dictionary",['ibo-is-visible']);
$oTabComplete->AddSubBlock($oDivAction);
$oButton=ButtonUIBlockFactory::MakeForPrimaryAction("🌐 Check Dictionary","a","b");
$oButton->SetOnClickJsCode('CheckDictionary(true);');
$oButton->AddCSSClass('mt-5');
$oTabComplete->AddSubBlock($oButton);
//** Tab:tab_dict_1 */
$oTabPrepare = FieldSetUIBlockFactory::MakeStandard('Prepare new language');
$oTabContainer->AddSubBlock($oTabPrepare);
$oAlertPrepare = AlertUIBlockFactory::MakeForInformation("Here you can prepare a zip file containing all dictionary files for a new language. ","They will be filled with english translations appended with \"~~\" to easily find what remains for translation.");
$oAlertPrepare->AddSubBlock(new Html("Check localization guidelines <a href=\"https://wiki.openitop.org/doku.php?id=2_2_0:customization:start#localization\" target=\"_blank\">see here</a>."));
$oTabPrepare->AddSubBlock($oAlertPrepare);
$oFormPrepare = FormUIBlockFactory::MakeStandard("prepare_new_dictionary",['ibo-is-visible']);
$oTabPrepare->AddSubBlock($oFormPrepare);
$oInputCode = InputUIBlockFactory::MakeForInputWithLabel('Language code:', "language_code", "", "language_code", "text");
$oInputCode->GetInput()->AddCSSClass('mb-5');
$oInputCode->GetInput()->SetPlaceholder("eg. FR FR");
$oFormPrepare->AddSubBlock($oInputCode);
$oInputName = InputUIBlockFactory::MakeForInputWithLabel('Language english name:', "language_name", "", "language_name", "text");
$oInputName->GetInput()->AddCSSClass('mb-5');
$oInputName->GetInput()->SetPlaceholder("eg. French");
$oFormPrepare->AddSubBlock($oInputName);
$oInputLocalized = InputUIBlockFactory::MakeForInputWithLabel('Language localized name:', "language_localized_name", "", "language_localized_name", "text");
$oInputLocalized->GetInput()->AddCSSClass('mb-5');
$oInputLocalized->GetInput()->SetPlaceholder("eg. Français");
$oFormPrepare->AddSubBlock($oInputLocalized);
$oButtonGenerate=ButtonUIBlockFactory::MakeForPrimaryAction("Generate","a","b",false, "bt_prepare_new_dictionary");
$oButtonGenerate->SetOnClickJsCode(' PrepareNewDictionary(true);');
$oButtonGenerate->AddCSSClass('mb-5');
$oFormPrepare->AddSubBlock($oButtonGenerate);
$oDivDatasources=UIContentBlockUIBlockFactory::MakeStandard("content_new_dictionary",['ibo-is-visible']);
$oTabPrepare->AddSubBlock($oDivDatasources);
return $oTabContainer;
// $oP->add_ready_script("\n$('#prepare_new_dictionary button[type=\"submit\"]').click(function(oEvent){ oEvent.preventDefault(); PrepareNewDictionary(true); });\n");
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// LEGACY BEFORE 3.0
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Welcome the user
*/
function DisplayIndexLegacy($oP)
{
$oP->add("<div class=\"info\">");
$oP->p("Welcome, use this toolkit in order to assist you in your iTop customization.");
$oP->p("Please keep in mind that this is a developer tool that must never be hosted on your production server.");
$oP->p("");
$oP->p("Please read carefully <a target='_blank' href='https://www.itophub.io/wiki/page?id=latest%3Acustomization%3Adatamodel&s%5B0%5D=toolkit#using_the_toolkit'>the documentation</a> prior any use!");
$oP->add("</div>");
}
/**
* Check the consistency
*/
function CheckConsistencyLegacy($oP)
{
$oP->add("<div class=\"info\">");
$oP->p("Use this page to validate any modification made to the PHP classes that define the 'data model'.");
$oP->p("It is advisable to fix any error detected at this stage before applying changes from the itop update tab.");
$oP->add("</div>");
$oP->add("<div id=\"content_php\"><button onclick='CheckConsistency(true);'>Check Consistency</button></div>\n");
}
/**
* Check the database schema - renamed "Update Itop" in the GUI!
*/
function CheckDBSchemaLegacy($oP)
{
$oP->add("<div class=\"info\">");
$oP->p("Use this page to preview the changes in the format of the database, and update iTop.".
" For example if you add a new field to an object, this new field must be added into the database as well.");
$oP->p("<b>Note:</b> the current version of the tool does not remove unused fields!");
$oP->add("</div>");
$oP->add("<div id=\"content_schema\">
<button onclick='CheckDBSchema(true);'>📀 Check DB Schema</button>
<hr />");
if (function_exists('symlink'))
{
$oP->add("<p><input type=\"checkbox\" id=\"symlink\" value=\"1\"><label for=\"symlink\"> Create symbolic links instead of creating a copy in env-production (useful for debugging extensions)</label></p>\n");
}
$sSourceDir = MetaModel::GetConfig()->Get('source_dir');
$sSourceDirHtml = htmlentities($sSourceDir, ENT_QUOTES, 'UTF-8');
$oP->add("<button onclick=\"doApply(false);\" title=\"Compile from $sSourceDirHtml to env-production\">📄 Update iTop code</button> <span id=\"apply_sql_indicator\"></span>\n");
$oP->add("<div id=\"content_apply_sql\"></div>\n</div>\n");
$oP->add("<hr/>");
$oP->p("Bookmark this button by dragging it in your bookmarks bar in order to skip every setup steps by clicking on your new bookmarklet with a setup page opened");
$oP->add("<a href=\"javascript:(function(){var quicksetup=document.createElement('SCRIPT');quicksetup.type='text/javascript';quicksetup.src='https://cdn.jsdelivr.net/gh/Combodo/itop-toolkit-community@master/js/quick-setup.js';document.getElementsByTagName('head')[0].appendChild(quicksetup);})();\" onclick=\"javascript:return false;\"> Quick Setup Tool</a>");
}
/**
* Check the database schema
*/
function CheckDataIntegrityLegacy($oP)
{
$oP->add("<div class=\"info\">");
$oP->p("Use this page to check the integrity of the data in the iTop database.");
$oP->add("</div>");
$oP->add("<h2>Synchronization Data Sources</h2>");
$oP->add("<div id=\"content_datasources\">");
$oP->add("<button onclick='CheckDataSources(true);'>Check Data Sources</button>");
$oP->add("</div>\n");
$oP->add("<h2>Hierarchical Keys</h2>");
$oP->add("<div id=\"content_hk\">\n");
$oP->add("<button onclick='CheckHK(true);'>Check Hierarchical Keys</button>");
$oP->add("</div>\n");
}
/**
* Check the dictionary definitions
*/
function CheckDictionaryLegacy($oP)
{
$oP->add("<!-- tabs -->\n<div id=\"tabbedContent-dict\" class=\"tabbedContent\" class=\"light\">\n");
$oP->add("<ul>\n");
$oP->add("<li><a href=\"#tab_dict_0\" class=\"tab\"><span>Complete existing language</span></a></li>\n");
$oP->add("<li><a href=\"#tab_dict_1\" class=\"tab\"><span>Prepare new language</span></a></li>\n");
$oP->add("</ul>\n");
$oP->add("<div id=\"tab_dict_0\">");
$oP->add("<div class=\"info\">");
$oP->p("This page lists all the missing items in the 'dictionary' which is used for the display and localization in iTop. To fix the issues, edit the output below and paste it into the appropriate dictionary.php file.");
$oP->add("</div>");
$oP->add("<div id=\"content_dictionary\"><button onclick='CheckDictionary(true);'>🌐 Check Dictionary</button></div>\n");
$oP->add("</div>\n");
$oP->add("<div id=\"tab_dict_1\">");
$oP->add("<div class=\"info\">");
$oP->p("Here you can prepare a zip file containing all dictionary files for a new language. They will be filled with english translations appended with \"~~\" to easily find what remains for translation.");
$oP->p("Check localization guidelines <a href=\"https://wiki.openitop.org/doku.php?id=2_2_0:customization:start#localization\" target=\"_blank\">see here</a>.");
$oP->add("</div>");
$oP->add(
<<<EOF
<div>
<form id="prepare_new_dictionary">
<p><label><span>Language code:</span><input type="text" id="language_code" name="language_code" placeholder="eg. FR FR"/></label></p>
<p><label><span>Language english name:</span><input type="text" id="language_name" name="language_name" placeholder="eg. French"/></label></p>
<p><label><span>Language localized name:</span><input type="text" id="language_localized_name" name="language_localized_name" placeholder="eg. Français"/></label></p>
<p><button type="submit" name="submit">Generate</button></p>
</form>
</div>
EOF
);
$oP->add("<div id=\"content_new_dictionary\"></div>\n");
$oP->add_ready_script("\n$('#prepare_new_dictionary button[type=\"submit\"]').click(function(oEvent){ oEvent.preventDefault(); PrepareNewDictionary(true); });\n");
$oP->add("</div>\n");
$oP->add("</div>\n<!-- end of tabs-->\n");
$oP->add_ready_script(
<<<EOF
// Same stuff as for the main tabs (see below)
var dictTabs = $('#tabbedContent-dict');
dictTabs.tabs();
EOF
);
}
/**
* @param \NiceWebPage $oP
*
* @throws \ConfigException
* @throws \CoreException
*/
function DisplayLegacy(NiceWebPage $oP)
{
$oP->add_script(
<<<JS
function GetAbsoluteUrlAppRoot()
{
return '../';
}
function doApply(bFull)
{
if (bFull)
{
var oMap = { operation: 'update_code_db' };
var bOk = confirm('Are you sure you want to compile the code and patch the database ?');
}
else
{
var oMap = { operation: 'update_code' };
var bOk = confirm('Are you sure you want to compile the code ?');
}
var oUseSymlinks = $('#symlink:checked');
if (oUseSymlinks.length > 0)
{
oMap.symlink = 1;
}
var iCount = 0;
if (bOk)
{
// remove previous results
$("div#content_apply_sql").html("");
var sTitleLoadingPrefix = '⚠️ - ';
var sOriginalTitle = document.title;
$('#apply_sql_indicator').html('<img title=\"loading...\" src=\"../images/indicator.gif\" />');
document.title = sTitleLoadingPrefix + sOriginalTitle;
ajax_request = $.post(GetAbsoluteUrlAppRoot()+'toolkit/ajax.toolkit.php', oMap,
function(data)
{
$('#content_apply_sql').empty();
if (data == '')
{
$('#content_apply_sql').append('Nothing done !');
notifyMe('Nothing done !')
}
else
{
$('#content_apply_sql').append(data);
notifyMe('Update finished')
}
$('#content_apply_sql').slideDown('slow');
$('#apply_sql_indicator').html('');
document.title = sOriginalTitle;
}
);
}
}
function notifyMe(notificationStr) {
if (!("Notification" in window)) {
return;
} else if (Notification.permission === "granted") {
var notification = new Notification(notificationStr);
} else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
if(!('permission' in Notification)) {
Notification.permission = permission;
}
if (permission === "granted") {
var notification = new Notification(notificationStr);
}
});
}
}
function CheckConsistency(bRefresh)
{
$('#content_php').html('<img title=\"loading...\" src=\"../images/indicator.gif\" /> Checking the consistency of the data model definition...');
ajax_request = $.get(GetAbsoluteUrlAppRoot()+'toolkit/ajax.toolkit.php', { 'operation': 'check_model', 'rebuild_toolkit_env': bRefresh },
function(data)
{
$('#content_php').empty();
if (data == '')
{
$('#content_php').append('Ok, no problem detected.');
$('#content_php').append('<p><input type="button" value=" Refresh " onClick="CheckConsistency(true);"/></p>');
}
else
{
$('#content_php').append(data);
$('#content_php>div p>b').each( function() {
var sClassName = $(this).html();
$(this).parent().after('<h2 class="class_name">Class '+sClassName+'</h2>');
}
);
$('#content_php').append('<p><input type="button" value=" Refresh " onClick="CheckConsistency(true);"/></p>');
$('#content_php>div').css( {'background':'transparent'} );
}
}
);
}
function CheckDBSchema(bRefresh)
{
$('#content_schema').html('<img title=\"loading...\" src=\"../images/indicator.gif\" /> Checking database schema...');
ajax_request = $.get(GetAbsoluteUrlAppRoot()+'toolkit/ajax.toolkit.php', { 'operation': 'check_db_schema', 'rebuild_toolkit_env': bRefresh },
function(data)
{
$('#content_schema').empty();
if (data == '')
{
$('#content_schema').append('<p>Ok, no problem detected.</p>');
}
else
{
$('#content_schema').append(data);
}
}
);
}
function CheckDataSources(bRefresh)
{
$('#content_datasources').html('<img title=\"loading...\" src=\"../images/indicator.gif\" /> Checking data sources integrity...');
ajax_request = $.get(GetAbsoluteUrlAppRoot()+'toolkit/ajax.toolkit.php', { 'operation': 'check_datasources', 'rebuild_toolkit_env': false },
function(data)
{
$('#content_datasources').empty();
if (data == '')
{
$('#content_datasources').append('<p>Ok, no problem detected.</p>');
}
else
{
$('#content_datasources').append(data);
}
}
);
}
function FixDataSources()
{
$('#content_datasources').html('<img title=\"loading...\" src=\"../images/indicator.gif\" /> Fixing data sources integrity...');
ajax_request = $.get(GetAbsoluteUrlAppRoot()+'toolkit/ajax.toolkit.php', { 'operation': 'fix_datasources' },
function(data)
{
$('#content_datasources').empty();
if (data == '')
{
$('#content_datasources').append('<p>Ok, no problem detected.</p>');
}
else
{
$('#content_datasources').append(data);
}
}
);
}
function CheckHK(bRefresh)
{
$('#content_hk').html('<img title=\"loading...\" src=\"../images/indicator.gif\" /> Checking hierarchical keys integrity...');
ajax_request = $.get(GetAbsoluteUrlAppRoot()+'toolkit/ajax.toolkit.php', { 'operation': 'check_hk', 'rebuild_toolkit_env': false },
function(data)
{
$('#content_hk').empty();
if (data == '')
{
$('#content_hk').append('<p>Ok, no problem detected.</p>');
}
else
{
$('#content_hk').append(data);
}
}
);
}
function BuildHK(bForce)
{
$('#content_hk').html('<img title=\"loading...\" src=\"../images/indicator.gif\" /> Fixing hierarchical keys integrity...');
ajax_request = $.get(GetAbsoluteUrlAppRoot()+'toolkit/ajax.toolkit.php', { 'operation': 'build_hk', 'force': bForce },
function(data)
{
$('#content_hk').empty();
if (data == '')
{
$('#content_hk').append('<p>Ok, no problem detected.</p>');
}
else
{
$('#content_hk').append(data);
}
}
);
}
function CheckDictionary(bRefresh)
{
var oLang = $('#language');
var sLang = 'EN US';
if (oLang.length > 0)
{
sLang = oLang.val();
}
var oModules = $('#modules');
var sModules = 'bizmodel';
if (oModules.length > 0)
{
sModules = oModules.val();
}
$('#content_dictionary').html('<img title=\"loading...\" src=\"../images/indicator.gif\" /> Searching for missing dictionary items');
ajax_request = $.get(GetAbsoluteUrlAppRoot()+'toolkit/ajax.toolkit.php', { 'operation': 'check_dictionary', 'rebuild_toolkit_env': bRefresh, 'lang': sLang, 'modules': sModules },
function(data)
{
$('#content_dictionary').empty();
$('#content_dictionary').append(data);
}
);
}
function PrepareNewDictionary(bRefresh)
{
var oForm = ('#prepare_new_dictionary');
var sLangCode = $('#language_code').val();
var sLangName = $('#language_name').val();
var sLangLocName = $('#language_localized_name').val();
if(sLangCode === '' || sLangName === '' || sLangLocName === '')
{
alert('Please fill all fields');
return false;
}
$('#content_new_dictionary').html('<img title=\"loading...\" src=\"../images/indicator.gif\" /> Preparing dictionary files for "'+sLangName+'"');
ajax_request = $.get(GetAbsoluteUrlAppRoot()+'toolkit/ajax.toolkit.php', { 'operation': 'prepare_new_dictionary', 'rebuild_toolkit_env': bRefresh, 'lang_code': sLangCode, 'lang_name': sLangName, 'lang_loc_name': sLangLocName },
function(data)
{
$('#content_new_dictionary').empty();
$('#content_new_dictionary').append(data);
}
);
}
JS
);
$oP->add("<h1>Data Model Toolkit</h1>\n");
define('TOOLKITENV', 'toolkit');
$oConfig = new Config(APPCONF.'production/'.ITOP_CONFIG_FILE);
if ($oConfig->Get('source_dir') == '')
{
throw new Exception('Missing entry source_dir from the config file');
}
$oP->add("<!-- tabs -->\n<div id=\"tabbedContent\" class=\"light\">\n");
$oP->add("<ul>\n");
$oP->add("<li><a href=\"#tab_index\" class=\"tab\"><span>Index</span></a></li>\n");
$oP->add("<li><a href=\"#tab_0\" class=\"tab\"><span>Data Model Consistency</span></a></li>\n");
$oP->add("<li><a href=\"#tab_1\" class=\"tab\"><span>iTop update</span></a></li>\n");
$oP->add("<li><a href=\"#tab_2\" class=\"tab\"><span>Data Integrity</span></a></li>\n");
$oP->add("<li><a href=\"#tab_3\" class=\"tab\"><span>Translations / Dictionary</span></a></li>\n");
$oP->add("</ul>\n");
$oP->add("<div id=\"tab_index\">");
DisplayIndexLegacy($oP);
$oP->add("</div>\n");
$oP->add("<div id=\"tab_0\">");
CheckConsistencyLegacy($oP);
$oP->add("</div>\n");
$oP->add("<div id=\"tab_1\">");
CheckDBSchemaLegacy($oP);
$oP->add("</div>\n");
$oP->add("<div id=\"tab_2\">");
CheckDataIntegrityLegacy($oP);
$oP->add("</div>\n");
$oP->add("<div id=\"tab_3\">");
CheckDictionaryLegacy($oP);
$oP->add("</div>\n");
$oP->add("</div>\n<!-- end of tabs-->\n");
$oP->add_ready_script(
<<<JS
// Tabs, using JQuery BBQ to store the history
// The "tab widgets" to handle.
var tabs = $('#tabbedContent');
// Ugly patch for a change in the behavior of jQuery UI:
// Before jQuery UI 1.9, tabs were always considered as "local" (opposed to Ajax)
// when their href was beginning by #. Starting with 1.9, a <base> tag in the page
// is taken into account and causes "local" tabs to be considered as Ajax
// unless their URL is equal to the URL of the page...
$('#tabbedContent ul li a').each(function() {
var sHash = location.hash;
var sCleanLocation = location.href.toString().replace(sHash, '').replace(/#$/, '');
$(this).attr("href", sCleanLocation+$(this).attr("href"));
});
// This selector will be reused when selecting actual tab widget A elements.
var tab_a_selector = 'ul.ui-tabs-nav a';
// Enable tabs on all tab widgets. The `event` property must be overridden so
// that the tabs aren't changed on click, and any custom event name can be
// specified. Note that if you define a callback for the 'select' event, it
// will be executed for the selected tab whenever the hash changes.
tabs.tabs();
JS
);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// END LEGACY BEFORE 3.0
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Main
////////////////////////////////////////////////////////////////////////////////
if (file_exists('../approot.inc.php'))
{
// iTop 1.0.2+
include('../approot.inc.php');
}
else // iTop 1.0 & 1.0.1
{
define('APPROOT', '../');
}
// iTop 2.7.0+
if (file_exists(APPROOT.'/bootstrap.inc.php'))
{
require_once(APPROOT.'/bootstrap.inc.php');
}
require_once(APPROOT."/application/applicationcontext.class.inc.php");
require_once(APPROOT.'application/utils.inc.php');
require_once(APPROOT."setup/runtimeenv.class.inc.php");
if (version_compare(ITOP_DESIGN_LATEST_VERSION , '3.0') < 0) {
require_once(APPROOT.'application/nicewebpage.class.inc.php');
}
if (!file_exists(ITOP_DEFAULT_CONFIG_FILE))
{
echo "<h1>Toolkit</h1>\n";
echo "<p>Please install iTop prior to running the toolkit</p>\n";
exit;
}
require_once(APPROOT.'/application/startup.inc.php');
$oP = new NiceWebPage('Data Model Toolkit');
if (version_compare(ITOP_DESIGN_LATEST_VERSION, "3.2", "<")) {
$oP->add_linked_stylesheet(utils::GetAbsoluteUrlAppRoot().'toolkit/toolkit.css');
} else {
$oP->LinkStylesheetFromAppRoot('toolkit/toolkit.css');
}
/**
* @param \NiceWebPage $oP
*
* @throws \ConfigException
* @throws \CoreException
*/
function Display(NiceWebPage $oP)
{
if (version_compare(ITOP_DESIGN_LATEST_VERSION, "3.2", "<")) {
$oP->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery.ba-bbq.min.js');
} else {
$oP->LinkScriptFromAppRoot('js/jquery.ba-bbq.min.js');
}
$oP->add_script(
<<<JS
function GetAbsoluteUrlAppRoot()
{
return '../';
}
function doApply(bFull)
{
if (bFull)
{
var oMap = { operation: 'update_code_db' };
var bOk = confirm('Are you sure you want to compile the code and patch the database ?');
}
else
{
var oMap = { operation: 'update_code' };
var bOk = confirm('Are you sure you want to compile the code ?');
}
var oUseSymlinks = $('#symlink:checked');
if (oUseSymlinks.length > 0)
{
oMap.symlink = 1;
}
var iCount = 0;
if (bOk)
{
// remove previous results
$("div#content_apply_sql").html("");
var sTitleLoadingPrefix = '⚠️ - ';
var sOriginalTitle = document.title;
$('#apply_sql_indicator').html('<img title=\"loading...\" src=\"../images/indicator.gif\" />');
document.title = sTitleLoadingPrefix + sOriginalTitle;
if (bFull)
{
$('#bt_content_apply_sql').attr("disabled", true);
} else {
$('#bt_up_code_and_db').attr("disabled", true);
}
ajax_request = $.ajax({
url: GetAbsoluteUrlAppRoot()+'toolkit/ajax.toolkit.php',
data: oMap,
success: function(data) {
$('#content_apply_sql').empty();
if (data == '')
{
$('#content_apply_sql').append('Nothing done !');
notifyMe('Nothing done !')
}
else
{
$('#content_apply_sql').append(data);
notifyMe('Update finished')
}
$('#content_apply_sql').slideDown('slow');
$('#apply_sql_indicator').html('');
document.title = sOriginalTitle;
if (bFull)
{
$('#bt_content_apply_sql').attr("disabled", false);
} else {
$('#bt_up_code_and_db').attr("disabled", false);
}
},
error: function() {
$('#content_apply_sql').empty();
$('#content_apply_sql').append('Error !');
notifyMe('Nothing done !')
$('#apply_sql_indicator').html('');
document.title = sOriginalTitle;
$('#content_apply_sql').slideDown('slow');
}
});
}
}
function notifyMe(notificationStr) {
console.warn('notifyMe');
if (!("Notification" in window)) {
return;
} else if (Notification.permission === "granted") {
var notification = new Notification(notificationStr);
} else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
if(!('permission' in Notification)) {
Notification.permission = permission;
}
if (permission === "granted") {
var notification = new Notification(notificationStr);
}
});
}
}
function CheckConsistency(bRefresh)
{
$('#bt_content_php').attr("disabled", true);
$('#content_php').html('<img title=\"loading...\" src=\"../images/indicator.gif\" /> Checking the consistency of the data model definition...');
ajax_request = $.get(GetAbsoluteUrlAppRoot()+'toolkit/ajax.toolkit.php', { 'operation': 'check_model', 'rebuild_toolkit_env': bRefresh },
function(data)
{
$('#content_php').empty();
if (data == '')
{
$('#content_php').append('Ok, no problem detected.');
$('#bt_content_php').attr("disabled", false);
}
else
{
$('#content_php').append(data);
$('#content_php>div p>b').each( function() {
var sClassName = $(this).html();
$(this).parent().after('<h2 class="class_name">Class '+sClassName+'</h2>');
}
);
$('#bt_content_php').attr("disabled", false);
$('#content_php>div').css( {'background':'transparent'} );
}
}
);
}
function CheckDBSchema(bRefresh)
{
$('#bt_content_schema').attr("disabled", true);
$('#content_schema').html('<img title=\"loading...\" src=\"../images/indicator.gif\" /> Checking database schema...');
ajax_request = $.get(GetAbsoluteUrlAppRoot()+'toolkit/ajax.toolkit.php', { 'operation': 'check_db_schema', 'rebuild_toolkit_env': bRefresh },
function(data)
{
$('#content_schema').empty();
if (data == '')
{
$('#content_schema').append('<p>Ok, no problem detected.</p>');
}
else
{
$('#content_schema').append(data);
if($('#bt_up_code_and_db').length > 0){
$("#bt_up_code_and_db").appendTo("#div_bt_compilation");
}
}
}
);
}
function CheckDataSources(bRefresh)
{
console.warn('CheckDataSources');
$('#content_datasources').html('<img title=\"loading...\" src=\"../images/indicator.gif\" /> Checking data sources integrity...');
$('#bt_content_datasources').attr("disabled", true);
ajax_request = $.get(GetAbsoluteUrlAppRoot()+'toolkit/ajax.toolkit.php', { 'operation': 'check_datasources', 'rebuild_toolkit_env': false },
function(data)
{
$('#content_datasources').empty();
if (data == '')
{
$('#content_datasources').append('<p>Ok, no problem detected.</p>');
}
else
{
$('#content_datasources').append(data);
}
$('#bt_content_datasources').attr("disabled", false);
}
);
}
function FixDataSources()
{
console.warn('FixDataSources');
$('#content_datasources').html('<img title=\"loading...\" src=\"../images/indicator.gif\" /> Fixing data sources integrity...');
ajax_request = $.get(GetAbsoluteUrlAppRoot()+'toolkit/ajax.toolkit.php', { 'operation': 'fix_datasources' },
function(data)
{
$('#content_datasources').empty();
if (data == '')
{
$('#content_datasources').append('<p>Ok, no problem detected.</p>');
}
else
{
$('#content_datasources').append(data);
}
}
);
}
function CheckHK(bRefresh)
{
console.warn('CheckHK');
$('#content_hk').html('<img title=\"loading...\" src=\"../images/indicator.gif\" /> Checking hierarchical keys integrity...');
$('#bt_content_hk').attr("disabled", true);
ajax_request = $.get(GetAbsoluteUrlAppRoot()+'toolkit/ajax.toolkit.php', { 'operation': 'check_hk', 'rebuild_toolkit_env': false },
function(data)
{
$('#content_hk').empty();
if (data == '')
{
$('#content_hk').append('<p>Ok, no problem detected.</p>');
}
else
{
$('#content_hk').append(data);
}
$('#bt_content_hk').attr("disabled", false);
}
);
}
function BuildHK(bForce)
{
console.warn('BuildHK');
$('#content_hk').html('<img title=\"loading...\" src=\"../images/indicator.gif\" /> Fixing hierarchical keys integrity...');
ajax_request = $.get(GetAbsoluteUrlAppRoot()+'toolkit/ajax.toolkit.php', { 'operation': 'build_hk', 'force': bForce },
function(data)
{
$('#content_hk').empty();
if (data == '')
{
$('#content_hk').append('<p>Ok, no problem detected.</p>');
}
else
{
$('#content_hk').append(data);
}
}
);
}
function CheckDictionary(bRefresh)
{
console.warn('CheckDictionary');
var oLang = $('#language');
var sLang = 'EN US';
if (oLang.length > 0)
{
sLang = oLang.val();
}
var oModules = $('#modules');
var sModules = 'bizmodel';
if (oModules.length > 0)
{
sModules = oModules.val();
}
$('#content_dictionary').html('<img title=\"loading...\" src=\"../images/indicator.gif\" /> Searching for missing dictionary items');
$('#bt_content_dictionary').attr("disabled", true);
ajax_request = $.get(GetAbsoluteUrlAppRoot()+'toolkit/ajax.toolkit.php', { 'operation': 'check_dictionary', 'rebuild_toolkit_env': bRefresh, 'lang': sLang, 'modules': sModules },
function(data)
{
$('#content_dictionary').empty();
$('#content_dictionary').append(data);
$('#bt_content_dictionary').attr("disabled", false);
}
);
}
function PrepareNewDictionary(bRefresh)
{
console.warn('PrepareNewDictionary');
var oForm = ('#prepare_new_dictionary');
var sLangCode = $('#language_code').val();
var sLangName = $('#language_name').val();
var sLangLocName = $('#language_localized_name').val();
if(sLangCode === '' || sLangName === '' || sLangLocName === '')
{
alert('Please fill all fields');
return false;
}
$('#content_new_dictionary').html('<img title=\"loading...\" src=\"../images/indicator.gif\" /> Preparing dictionary files for "'+sLangName+'"');