davide.cucurnia@vola.it
2024-02-01 555a537e2e5d9220e3777c30b185606823c817f2
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
/**
 * quest' oggetto definisce i metodi XML
 * se is_editable è true la stringa XML verrà modificato dall' update massivo
 * @type {{sso_getWebcustomerInformation: {defaultXML: string, is_editable: boolean, actualXML: string}, sso_getSelectedMSISDNDetails: {defaultXML: string, is_editable: boolean, actualXML: string}, sso_getMSISDNDetails: {defaultXML: string, is_editable: boolean, actualXML: string}, picasso_getWebcustomerInformation: {defaultXML: string, is_editable: boolean, actualXML: string}, sso_getMSISDNList: {defaultXML: string, is_editable: boolean, actualXML: string}, sso_getInfoActivationWSC: {defaultXML: string, is_editable: boolean, actualXML: string}}}
 */
let xmlMethods = {
    'sso_getWebcustomerInformation': {
        'defaultXML': sso_getWebcustomerInformation,
        'actualXML': sso_getWebcustomerInformation, // dopo le modifiche
        'is_editable': true // verrà modificato dalle modifiche massive?
    },
    'sso_getMSISDNDetails': {
        'defaultXML': sso_getMSISDNDetails,
        'actualXML': sso_getMSISDNDetails,
        'is_editable': true
    },
    'sso_getMSISDNList': {
        'defaultXML': sso_getMSISDNList,
        'actualXML': sso_getMSISDNList,
        'is_editable': true
    },
    'sso_getSelectedMSISDNDetails': {
        'defaultXML': sso_getSelectedMSISDNDetails,
        'actualXML': sso_getSelectedMSISDNDetails,
        'is_editable': true
    },
    'sso_getInfoActivationWSC': {
        'defaultXML': sso_getInfoActivationWSC,
        'actualXML': sso_getInfoActivationWSC,
        'is_editable': true
    },
    'picasso_getWebcustomerInformation': {
        'defaultXML': picasso_getWebcustomerInformation,
        'actualXML': picasso_getWebcustomerInformation,
        'is_editable': true
    },
}
 
/**
 * questa è la lista di campi mostrati nella sezione di update massivo
 * per aggiungere un campo è necessario aggiungere un oggetto di questo tipo alla lista
 * @type {({defaultValue: number, inputType: string, requireCheckbox: boolean, inputName: string}|{defaultValue: string, onChangeEditFields: {custcode: {editType: string}}, inputName: string}|{defaultValue: string, inputName: string}|{defaultValue: string, inputName: string}|{defaultValue: string, inputName: string})[]}
 */
let editableFields = [
    {
        'inputName': 'n_sim',
        'inputType': 'number',
        "defaultValue": 1,
        'requireCheckbox': false,
    },
    {
        'inputName': 'profile_user_name',
        "defaultValue": "NAME FAKESSO | DUAL TM9 RIC 5.49275",
        'requireCheckbox': false,
    },
    {
        'inputName': 'Custcode',
        'defaultValue': '5.49275',
        'onChangeEditFields': {
            'custcode': {
                'editType': 'copyMain'
            }
        }
    },
    {
        'inputName': 'EmailAddress',
        'defaultValue': 'pippo@vola.it'
    },
    {
        'inputName': 'Name',
        'defaultValue': 'Paola'
    },
    {
        'inputName': 'ProfileIdentifier',
        'defaultValue': 'BUSINESS_EMPLOYEE'
    },
    {
        'inputName': 'Surname',
        'defaultValue': 'Sandrelli'
    },
    {
        'inputName': 'Username',
        'defaultValue': 'FAKE_SSO_',
        'onChangeEditFields': {
            'username': {
                'editType': 'copyMain'
            },
        }
    },
    {
        'inputName': 'IdPiano',
        'defaultValue': '2491'
    },
    {
        'inputName': 'OMProductId',
        'defaultValue': '2156' // se uno di quelli dual risulto come dual già attivo
    },
    {
        'inputName': 'tmCode',
        'defaultValue': '2491'
    },
    {
        'inputName': 'sim_1',
        'defaultValue': '3464232371',
        'onChangeEditFields': {
            'MSISDN': {
                'editType': 'copyMain'
            },
            'selectedBoID': {
                'editType': 'copyMain'
            }
        }
    }
    // {
    //     'inputName': 'Type_ID',
    // 'defaultValue':'...',
    //     'labelText': 'Type_ID ex. (2)'
    // },
    // {
    //     'inputName': 'providerID',
    // 'defaultValue':'...'
    // },
    // {
    //     'inputName': 'selectedBoId',
    // 'defaultValue':'...'
    // // },
    // {
    //     'inputName': 'selectedBoType',
    // 'defaultValue':'...'
    // },
    // {
    //     'inputName': 'username',
    // 'defaultValue':'...'
    // },
    // {
    //     'inputName': 'productId',
    // 'defaultValue':'...'
    // },
    // {
    //     'inputName': 'productType',
    // 'defaultValue':'...'
    // },
    // {
    //     'inputName': 'offerType',
    // 'defaultValue':'...'
    // },
    // {
    //     'inputName': 'rewardID',
    // 'defaultValue':'...'
    // },
    // {
    //     'inputName': 'groupTypeID',
    // 'defaultValue':'...'
    // }
];
 
$(document).ready(function () {
    addEditableFieldsInputs();
    $.each(xmlMethods, function (method_name) {
        setDefaultXML(method_name);
        if (xmlMethods[method_name]["is_editable"]) {
            $(`input[name="is_editable_${method_name}"]`).prop("checked", true);
        }
    })
    serializeInputAndEditXML(true, true);
    $('input[name="n_sim"]').on('change', displayNInputsForNSims);
    $('input[name^="shouldReplace_"]').on('change', shouldReplaceOption);
    $(document).on('change', '#edit-all input:not([type="checkbox"])', serializeInputAndEditXML);
    $(document).on('click', '#edit-all button', serializeInputAndEditXML);
    $('input[name^="is_editable_"]').on('change', changeEditOption);
    $(document).on('input', 'textarea', validateTextarea);
    $(document).on('click', 'button[id^="set_default_xml_"]', setDefaultXML);
    $(document).on('click', 'button[name="show_result"]', showResult);
    $(document).on('click', 'button[name="copy-result"]', copyToClipboard);
})
 
/**
 * partendo dalla lista di sim aggiungo tutti i tag sim all' xml del metodo getMSISDNList
 * @param sim_list
 */
function editGetMSISDNListXML(sim_list) {
    let jsonMsisdn = $.xml2json(sso_getMSISDNList)
    let MSISDNList = jsonMsisdn["getMDISDNList"]["msisdn_list"]
 
    sim_list.forEach(function (sim_obj) {
        MSISDNList[sim_obj.inputName] = ""
    });
 
    const newXML = $.json2xml(jsonMsisdn)
    let encodingValue = $.parseXML(sso_getMSISDNList)["xmlEncoding"] ?? null;
    const xmlHead = `<?xml version="1.0" encoding="${encodingValue}"?>`;
    xmlMethods.sso_getMSISDNList.actualXML = xmlHead + newXML
    const formattedXML = vkbeautify.xml(xmlMethods.sso_getMSISDNList.actualXML)
    $(`textarea#sso_getMSISDNList`).val(formattedXML)
}
 
/**
 * aggiungo una textarea per ogni sim per il metodo selezionato
 * @param sim_list
 * @param genericMethodName valori tipo -> "sso_getSelectedMSISDNDetails", "sso_getInfoActivationWSC"
 */
function add_N_areatext_sections(sim_list, genericMethodName) {
    let additional_methods_wrapper = $('#' + "additional_methods_" + genericMethodName)
    additional_methods_wrapper.empty()
 
    sim_list.forEach(function (sim_obj) {
            let sim_code = sim_obj.inputName
            let uniqueMethodName = sim_code + "_" + genericMethodName
            xmlMethods[uniqueMethodName] = {
                'defaultXML': xmlMethods.sso_getSelectedMSISDNDetails.defaultXML,
                'actualXML': xmlMethods.sso_getSelectedMSISDNDetails.defaultXML,
                'is_editable': true
            }
            let formattedXML = vkbeautify.xml(xmlMethods[uniqueMethodName]["defaultXML"])
            let additionalMethodArea = `
            <div class="mb-3">
                <label for="${uniqueMethodName}" class="form-label text-danger font-weight-bolder">${uniqueMethodName}</label>
                <label>
                    Questo metodo deve essere modificato dal replace massivo?
                    <input type="checkbox" name="is_editable_${uniqueMethodName}" class="check-control" checked>
                </label>
                <button id="set_default_xml_${uniqueMethodName}" class="btn btn-primary btn-sm m-0 mx-3">
                    DEFAULT XML
                </button>
                <textarea class="form-control" id="${uniqueMethodName}" name="${uniqueMethodName}" rows="10">${formattedXML}</textarea>
                <div id="${uniqueMethodName}_errorBox" class="text-danger font-size-sm"></div>
            </div>`;
            additional_methods_wrapper.append(additionalMethodArea)
        }
    )
}
 
/**
 * questo metodo viene chiamato ogni volta che cambia in numero di sim e:
 *
 * genero gli oggetti input per ogni sim
 * passo la lista di oggetti input a addEditableFieldsInput (aggiunti nella sezione modifica massiva)
 * aggiorno l' xml del metodo getMSISDNList con le nuove sim
 * aggiungo una nuova textarea di editing metodo per ogni sim per i metodi getSelectedMSISDNDetails getInfoActivationWSC
 * @return void
 */
function displayNInputsForNSims() {
    $("[id^=sim_][id$=_wrapper]:not(#sim_1_wrapper)").remove();//rimuovo i vecchi input
    editableFields = editableFields.filter(field => !(field.inputName.startsWith('sim_') && (field.inputName !== "sim_1")));
    let numberOfSim = $(this).val();
 
    if (!(0 < numberOfSim) || !(numberOfSim <= 6)) {
        $(this).val(1)
        numberOfSim = 1
    }
 
    const phone_number_sim_1 = $('input[name="sim_1"]').val()
    let sim_list = [];
    for (let sim_n = 2; sim_n <= numberOfSim; sim_n++) {
        let inputObj = {
            "inputName": "sim_" + sim_n,
            "defaultValue": phone_number_sim_1 + sim_n//qui
        };
        sim_list.push(inputObj)
        editableFields.push(inputObj)
    }
 
    addEditableFieldsInputs(sim_list)
    //cambio actualXML di conseguenza inserendo dove necessario le chiavi aggiuntive di sim_1, sim_2, sim_3...
    // lista di xml che devono essere cambiati:
    // getMSISDNList (deve avere N tag sim_1, sim_2... )
    editGetMSISDNListXML(sim_list)
    // getSelectedMSISDNDetails deve avere N textarea una per ogni sim
    add_N_areatext_sections(sim_list, "sso_getSelectedMSISDNDetails")
    // getInfoActivationWSC deve avere N textarea una per ogni sim
    add_N_areatext_sections(sim_list, "sso_getInfoActivationWSC")
}
 
/**
 * inserisco la lista di input in pagina per l' editing massivo dei campi
 * @param inputList
 */
function addEditableFieldsInputs(inputList = editableFields) {
    let inputWrapper = $('#wrapper-input-list')
 
    inputList.forEach(function (inputObj, index) {
 
        let div = $("<div>", {id: inputObj["inputName"] + "_wrapper", class: "col mb-2"});
        let labelText = inputObj["labelText"] ?? inputObj["inputName"];
        let label = $("<label>", {for: inputObj["inputName"], class: "form-label"}).text(labelText);
 
        let checkbox = ""
        let input = $("<input>", {
            class: "form-control",
            type: inputObj["inputType"] ?? "text",
            value: inputObj["defaultValue"] ?? "",
            name: inputObj["inputName"],
            placeholder: inputObj["inputName"],
            id: inputObj["inputName"]
        });
 
        if (inputObj.requireCheckbox !== false) {
            checkbox = $("<input>", { //necessaria per verificare se l' input corrispondente deve essere modificato
                class: "check-control mx-1",
                type: "checkbox",
                name: "shouldReplace_" + inputObj["inputName"]
            });
        }
 
 
        div.append(label);
        div.append(checkbox);
        div.append(input);
 
        inputWrapper.append(div);
    })
 
}
 
function showError(errorBox = $('#main_errorBox'), msg = "xml non formattato correttamente") {
    errorBox.show()
    const listItem = $('<li>', {
        text: msg
    })
    errorBox.append(listItem)
}
 
/**
 * in questo metodo voglio prendere tutti gli input nella lista editableField (lista degli input edit massivo) parametrizzarli
 * una volta parametrizzati gli input partendo dalla struttura del vecchio xml (oggetto)
 * sostituisco tutte le chiavi che combaciano con i nuovi valori
 * @param alwaysEditable
 * @param updateDefaultXML
 */
function serializeInputAndEditXML(alwaysEditable = false, updateDefaultXML = false) {
    let serializedInputs = $('form#edit-all').serializeArray();
 
    $.each(xmlMethods, function (methodName, methodObj) {
            if ((methodObj.is_editable) || (alwaysEditable === true)) {
                let encodingValue = $.parseXML(methodObj.actualXML)["xmlEncoding"] ?? null;
 
                let oldObj = $.xml2json(methodObj.actualXML)
                let newXML = mergeAndConvertObjInXML(oldObj, serializedInputs)
 
                if (encodingValue !== null) {
                    const xmlHead = `<?xml version="1.0" encoding="${encodingValue}"?>`;
                    methodObj.actualXML = xmlHead + newXML
                } else {
                    methodObj.actualXML = newXML
                }
 
                if (updateDefaultXML === true) {
                    methodObj.defaultXML = newXML
                }
 
                let isValid = $.isXmlValid(newXML)
 
                if (isValid) {
                    const formattedXML = vkbeautify.xml(newXML)
                    $(`textarea#${methodName}`).val(formattedXML.trim())
                } else {
                    $('#main_errorBox').empty()
                    showError($('#' + methodName + '_errorBox'))
                }
            }
        }
    );
}
 
/**
 * faccio merge di tutti i valori in newValues in finalObj mantenendo invariata la struttura di finalObj
 * @param finalObj
 * @param newValues
 * @return {object}
 */
function mergeObjects(finalObj, newValues) {
    let newProperties = newValues[Object.keys(newValues)[0]]
 
    $.each(newProperties, function (name, value) {
        findAndReplaceKeyInObj(finalObj, name, value)
    })
    return finalObj
}
 
/**
 * prendo l' obj passato e cerco all' interno di esso una chiave key (a qualsiasi livello di indentazione)
 * se esiste la sostituisco con newValue
 * @param obj
 * @param key
 * @param newValue
 * @return {object}
 */
function findAndReplaceKeyInObj(obj, key, newValue) {
    if (obj instanceof Object) {
        if (obj.hasOwnProperty(key)) {
            obj[key] = newValue;
            return;
        }
        for (let subKey in obj) {
            if (obj.hasOwnProperty(subKey) && obj[subKey] instanceof Object) {
                findAndReplaceKeyInObj(obj[subKey], key, newValue);
            }
        }
    }
    return obj
}
 
 
/**
 * group -> subEditFunction
 *  prendo il valore del main e do alla subKey lo stesso valore
 */
function copyMain() {
    return (subFields, obj) => {
        const mainName = subFields.inputName
        return obj[mainName] //main value
    }
}
 
/**
 * la lista di metodi aggiuntivi che se presenti in subFields.onChangeEditFields invocano delle funzioni secondarie
 * per il campo che è stato modificato
 *
 * ad esempio copyMain prende il valore del campo modificato e lo passa a tutti i subField
 * quindi nel caso di sim_1 quando viene cambiato il valore viene passato anche a MSISDN selectedBoID perché si trovano sotto il campo principale sim_1 con edit_type copyMain
 * @type {{copyMain: (function(*, *): *)}}
 */
let subEditFunctions = {
    "copyMain": copyMain()
}
 
/**
 * se il campo principale ha delle funzioni onChangeEditFields chiamare le invoca
 * @param subFields
 * @param obj
 * @return {object}
 */
function editSubFields(subFields, obj) {
    const subChanges = subFields.onChangeEditFields
    $.each(subChanges, function (subFieldName, subObj) {
        if (subObj.editType in subEditFunctions) {
            obj[subFieldName] = subEditFunctions[subObj.editType](subFields, obj)
        }
    })
    return obj
}
 
/**
 * prendo un oggetto complesso e lo semplifico mettendo tutte le chiavi sullo stesso livello
 * @param objInputList
 * @param mainKey
 * @return {{object}}
 */
function simplifyObj(objInputList, mainKey = null) {
    let newObj = {};
 
    objInputList.forEach(function (objInput) {
        let editableField = editableFields.find(fields => fields.inputName === objInput.name);
        if (editableField) {
            newObj[objInput.name] = objInput.value;
            if (editableField.onChangeEditFields) {
                newObj = editSubFields(editableField, newObj)
            }
        }
    })
 
    if (typeof mainKey == 'string') {
        return {
            [mainKey]: newObj
        }
    }
 
    return newObj;
}
 
/**
 * prendo i valori del vecchio oggetto xml li sostituisco con quelli nuovi e trasformo nuovamente l' obj xml in una stringa XML
 * @param oldObj
 * @param replacingValuesObj
 * @return {string}
 */
function mergeAndConvertObjInXML(oldObj, replacingValuesObj) {
    const mainKey = Object.keys(oldObj)[0]
    let newObj = simplifyObj(replacingValuesObj, mainKey)
 
    let mergedObj = mergeObjects(oldObj, newObj)
    return $.json2xml(mergedObj)
}
 
/**
 * modifico l' editabiltà massiva di un oggetto in xmlMethods in base al valore della sua checkbox
 * se non è flaggata non modifico il metodo
 */
function changeEditOption() {
    let input_name = $(this).attr('name')
    const isEditable = $(this).is(':checked')
    const methodName = input_name.split("is_editable_")[1] ?? ""
 
    if (xmlMethods[methodName]) {
        xmlMethods[methodName]["is_editable"] = isEditable;
    }
}
 
/**
 * setto i valori di default degli XML e li inserisco nelle rispettive textarea
 * se methodName === null arriva da un input event quindi prendo dinamicamente il nome del metodo a cui settare default XML
 * @param methodName
 */
function setDefaultXML(methodName = null) {
    if (typeof methodName !== 'string') { // il caso in cui venga chiamato da un evento
        let btn_id = $(this).attr('id')
        methodName = btn_id.split("set_default_xml_")[1] ?? ""
    }
 
    if (xmlMethods[methodName]) {
        xmlMethods[methodName]["actualXML"] = xmlMethods[methodName]["defaultXML"]
        const formattedXML = vkbeautify.xml(xmlMethods[methodName]["actualXML"])
        $(`textarea#${methodName}`).val(formattedXML.trim())
 
        let errorBox = $('#' + methodName + '_errorBox');
        errorBox.empty()
    }
}
 
/**
 * abilita e disabilita il singolo input per la modifica massiva
 * se la checkbox è flaggata il campo non verrà modificato
 */
function shouldReplaceOption() {
    let checkbox_name = $(this).attr('name')
    let checkbox_value = $(this).is(':checked')
    const input_name = checkbox_name.split("shouldReplace_")[1] ?? ""
 
    if (checkbox_value) {
        $(`input[name="${input_name}"]`).prop('disabled', true);
    } else {
        $(`input[name="${input_name}"]`).removeAttr('disabled');
    }
}
 
/**
 * verifico la validità di un valore XML nella textarea che invoca l' evento
 */
function validateTextarea() {
    const xml = $(this).val()
    const methodName = $(this).attr('id')
    let errorBox = $('#' + methodName + '_errorBox');
    errorBox.empty()
    if ((typeof xml === 'string') && (xml.trim() !== '')) {
        let isValid = $.isXmlValid(xml);
        if (isValid !== true) {
            showError(errorBox, "errore nella validazione dell' xml " + isValid)
        }
    }
}
 
/**
 * trasformo un oggetto JS in una stringa con sintassi array PHP
 * @param profileObj
 * @return {string}
 */
function buildArrayPHP(profileObj) {
    const newJSON = JSON.stringify(profileObj)
    const prettyJson = vkbeautify.json(newJSON)
    let arrayPHP = prettyJson.replaceAll("{", "[")
    arrayPHP = arrayPHP.replaceAll("}", "]")
    arrayPHP = arrayPHP.replaceAll(":", "=>")
    return '"n" => ' + arrayPHP
}
 
/**
 * partendo dall' oggetto profileObj sostituisco i valori dentro parametri[param] inserendo chiavi valore corrette
 * chiave -> (sim_*) | valore -> (sim_*_method_name["actual"])
 * @param profileObj
 * @param method_name
 * @param param_key
 * @return {*}
 */
function set_dynamic_keys_for_profile_method(profileObj, method_name, param_key) {
 
    profileObj["sso"][method_name]["parametri"][param_key] = {}
 
    const sso_method_name = `sso_${method_name}`
    const main_phone_number = $(`input[name="sim_1"]`).val()
    const XML_sim_1 = xmlMethods[sso_method_name]["actualXML"];
    let encodingValue = $.parseXML(XML_sim_1)["xmlEncoding"] ?? null;
    const xmlHead = `<?xml version="1.0" encoding="${encodingValue}"?>`;
 
    profileObj["sso"][method_name]["parametri"][param_key][main_phone_number] = XML_sim_1
 
    let sim_length = $('input[name="n_sim"]').val()
    for (let index = 2; index <= sim_length; index++) {
        let sim_code = 'sim_' + index
        let phone_number = $(`input[name="${sim_code}"]`).val()
 
        let new_method_name = sim_code + "_" + sso_method_name
        profileObj["sso"][method_name]["parametri"][param_key][phone_number] = xmlHead + xmlMethods[new_method_name]["actualXML"]
    }
 
    return profileObj
}
 
/**
 * costruisco e mostro l' array (formato PHP) in pagina
 */
function showResult() {
    let profileObj = {
        "name": $('input[name="profile_user_name"]').val() ?? "inserire un nome utente",
        "sso": {
            "getWebcustomerInformation":
                {
                    "parametri": {
                        "t":
                            {
                                "415F2B31F1C15FA45C9A6E1CBEB0ADF3": xmlMethods.sso_getWebcustomerInformation.actualXML
                            }
                    }
                }
            ,
            "getMSISDNDetails":
                {
                    "parametri": {
                        "t":
                            {
                                "415F2B31F1C15FA45C9A6E1CBEB0ADF3": xmlMethods.sso_getMSISDNDetails.actualXML
                            }
                    }
                }
            ,
            "getMSISDNList":
                {
                    "parametri": {
                        "t":
                            {
                                "415F2B31F1C15FA45C9A6E1CBEB0ADF3": xmlMethods.sso_getMSISDNList.actualXML
                            }
                    }
                }
            ,
            "getSelectedMSISDNDetails":
                {
                    "parametri": {
                        "t":
                            {
                                "415F2B31F1C15FA45C9A6E1CBEB0ADF3": '<?xml version="1.0" encoding="iso-8859-1"?><getMDISDNDetails><CardType>Ric</CardType><SimSeniorityDate>15/02/2020</SimSeniorityDate><VodafoneOne>false</VodafoneOne><TopClub>false</TopClub><IdPiano>2491</IdPiano><SeniorityCluster></SeniorityCluster></getMDISDNDetails>'
                            },
                        "ms":
                            {
                                '3464232371': '',//deve essere gestito con un foreach
                                '3464232372': ''//deve essere gestito con un foreach
                            }
                    }
                }
            ,
            "getInfoActivationWSC":
                {
                    "parametri": {
                        "t":
                            {
                                "415F2B31F1C15FA45C9A6E1CBEB0ADF3": '<?xml version="1.0" encoding="iso-8859-1"?><getInfoActivationWSC><catalog><channel>SSO</channel><providerID></providerID><appidID></appidID><selectedBoId>3464232371</selectedBoId><selectedBoType>SIM_MOBILE</selectedBoType><username>FAKE_SSO_1</username><readOnlyCondition></readOnlyCondition><showcase><showcaseId>27</showcaseId><showcaseDescription>Vetrina Elite</showcaseDescription><tabs><tabPosition>1</tabPosition><tabDescription>new Corporate Infoattivazione Showcase</tabDescription><tabId>17</tabId><sections><collapsed>N</collapsed><sectionPosition>20</sectionPosition><sectionDescription>Tutti gli altri servizi</sectionDescription><sectionId>112</sectionId><products><productId>2583</productId><activationDate><time>1702249200000</time></activationDate><changeStateDate><time>1702249200000</time></changeStateDate><inheritanceRule></inheritanceRule><buyCost>0.0</buyCost><frequency></frequency><infoRecurringFees>N</infoRecurringFees><invertStatus>N</invertStatus><maxNumOfTry>0</maxNumOfTry><monopoliFlag>N</monopoliFlag><longDescription>Abilita la SIM alla distinzione del traffico personale da quello aziendale</longDescription><longName>Autorizzazione Dual</longName><productPosition>1</productPosition><numberOfUsedTry>0</numberOfUsedTry><numberOfTryAvailable>0</numberOfTryAvailable><OMProductId>2156</OMProductId><OMSource>CCBS</OMSource><productType>Service</productType><shortDescription>Abilita la SIM alla distinzione del traffico personale da quello aziendale</shortDescription><shortName>Autorizzazione Dual</shortName><productStateOnSim>ACTIVE</productStateOnSim><spyderId></spyderId><flagCommitment></flagCommitment><mm4MPromoId></mm4MPromoId><idJoin></idJoin><lastPaidFlag></lastPaidFlag><offerType></offerType><lastChargeZeroReason></lastChargeZeroReason></products><products><productId>3823</productId><activationDate><time>1702854000000</time></activationDate><changeStateDate><time>1702854000000</time></changeStateDate><inheritanceRule></inheritanceRule><buyCost>0.0</buyCost><frequency></frequency><infoRecurringFees>N</infoRecurringFees><invertStatus>N</invertStatus><maxNumOfTry>0</maxNumOfTry><monopoliFlag>N</monopoliFlag><longDescription></longDescription><longName>TM9 Smart Passport Extra Europa 1 Rinnovo Ricaricabile</longName><productPosition>1</productPosition><numberOfUsedTry>0</numberOfUsedTry><numberOfTryAvailable>0</numberOfTryAvailable><OMProductId>14644</OMProductId><OMSource>CCBS</OMSource><productType>Service</productType><shortDescription></shortDescription><shortName>TM9 Smart Passport Extra Europa 1 Rinnovo Ricaricabile</shortName><productStateOnSim>ACTIVE</productStateOnSim><spyderId></spyderId><flagCommitment></flagCommitment><mm4MPromoId></mm4MPromoId><idJoin></idJoin><lastPaidFlag></lastPaidFlag><offerType></offerType><lastChargeZeroReason></lastChargeZeroReason></products><____hashCodeCalc>false</____hashCodeCalc></sections><____hashCodeCalc>false</____hashCodeCalc></tabs><____hashCodeCalc>false</____hashCodeCalc></showcase><tmProduct><tmCode>2491</tmCode><description>TM9 Ricaricabile P30</description><activationDate><time>1696244062000</time></activationDate><____hashCodeCalc>false</____hashCodeCalc></tmProduct><convergentOffer><rewardID></rewardID><groupTypeID></groupTypeID><hungReasonID></hungReasonID><cli></cli><status></status></convergentOffer></catalog><operationStatus><status>OK</status><errCode>0</errCode><diagnostic>SUCCESS</diagnostic><____hashCodeCalc>false</____hashCodeCalc></operationStatus></getInfoActivationWSC>'
                            },
                        "boID":
                            {
                                '3464232371': '',//deve essere gestito con un foreach
                                '3464232372': ''//deve essere gestito con un foreach
                            }
                    }
                }
        },
        "picasso": {
            "getWebcustomerInformation": {
                "parametri": {
                    "t": {
                        "415F2B31F1C15FA45C9A6E1CBEB0ADF3": xmlMethods.picasso_getWebcustomerInformation.actualXML
                    }
                }
            }
        }
    }
 
 
    profileObj = set_dynamic_keys_for_profile_method(profileObj, "getSelectedMSISDNDetails", "ms")
    profileObj = set_dynamic_keys_for_profile_method(profileObj, "getInfoActivationWSC", "boID")
    const arrayPHP = buildArrayPHP(profileObj);
 
    $('#final_result  pre').text(arrayPHP);
    $("html, body").animate({scrollTop: $(document).height()}, "slow");
    $('#final_result').show();
}
 
function copyToClipboard() {
    let textToCopy = $("#final_result_text").text();
    let tempInput = $("<textarea>");
    $("body").append(tempInput);
    tempInput.val(textToCopy).select();
    document.execCommand("copy");
    tempInput.remove();
}