@@ -562,7 +562,7 @@ public function switchAction($action, $httpVars, $fileVars)
562
562
}
563
563
if (isSet ($ httpVars ["format " ]) && $ httpVars ["format " ] == "json " ) {
564
564
HTMLWriter::charsetHeader ("application/json " );
565
- $ roleData = $ role ->getDataArray ();
565
+ $ roleData = $ role ->getDataArray (true );
566
566
$ allReps = ConfService::getRepositoriesList ("all " , false );
567
567
$ repos = array ();
568
568
if (!empty ($ userObject )){
@@ -673,11 +673,14 @@ public function switchAction($action, $httpVars, $fileVars)
673
673
$ parsed ,
674
674
($ userObject !=null ?$ usrId :null ),
675
675
"ROLE_PARAM_ " ,
676
- $ binariesContext
676
+ $ binariesContext ,
677
+ AJXP_Role::$ cypheredPassPrefix
677
678
);
678
679
$ roleData ["PARAMETERS " ][$ repoScope ][$ plugId ] = $ parsed ;
679
680
}
680
681
}
682
+ $ existingParameters = $ originalRole ->listParameters (true );
683
+ $ this ->mergeExistingParameters ($ roleData ["PARAMETERS " ], $ existingParameters );
681
684
if (isSet ($ userObject ) && isSet ($ data ["USER " ]) && isSet ($ data ["USER " ]["PROFILE " ])) {
682
685
$ userObject ->setAdmin (($ data ["USER " ]["PROFILE " ] == "admin " ));
683
686
$ userObject ->setProfile ($ data ["USER " ]["PROFILE " ]);
@@ -718,7 +721,7 @@ public function switchAction($action, $httpVars, $fileVars)
718
721
} else {
719
722
AuthService::updateRole ($ originalRole );
720
723
}
721
- $ output = array ("ROLE " => $ originalRole ->getDataArray (), "SUCCESS " => true );
724
+ $ output = array ("ROLE " => $ originalRole ->getDataArray (true ), "SUCCESS " => true );
722
725
} catch (Exception $ e ) {
723
726
$ output = array ("ERROR " => $ e ->getMessage ());
724
727
}
@@ -1004,7 +1007,7 @@ public function switchAction($action, $httpVars, $fileVars)
1004
1007
if (!is_array ($ custom )) $ custom = array ();
1005
1008
1006
1009
$ options = $ custom ;
1007
- $ this ->parseParameters ($ httpVars , $ options , $ userId );
1010
+ $ this ->parseParameters ($ httpVars , $ options , $ userId, false , $ custom );
1008
1011
$ custom = $ options ;
1009
1012
$ user ->setPref ("CUSTOM_PARAMS " , $ custom );
1010
1013
$ user ->save ();
@@ -1037,7 +1040,8 @@ public function switchAction($action, $httpVars, $fileVars)
1037
1040
$ wallet [$ repoID ] = array ();
1038
1041
}
1039
1042
$ options = $ wallet [$ repoID ];
1040
- $ this ->parseParameters ($ httpVars , $ options , $ userId );
1043
+ $ existing = $ options ;
1044
+ $ this ->parseParameters ($ httpVars , $ options , $ userId , false , $ existing );
1041
1045
$ wallet [$ repoID ] = $ options ;
1042
1046
$ user ->setPref ("AJXP_WALLET " , $ wallet );
1043
1047
$ user ->save ();
@@ -1277,6 +1281,7 @@ public function switchAction($action, $httpVars, $fileVars)
1277
1281
}
1278
1282
}
1279
1283
$ nested = array ();
1284
+ $ definitions = $ plug ->getConfigsDefinitions ();
1280
1285
print ("<repository index= \"$ repId \"" );
1281
1286
foreach ($ repository as $ name => $ option ) {
1282
1287
if (strstr ($ name , " " )>-1 ) continue ;
@@ -1300,7 +1305,10 @@ public function switchAction($action, $httpVars, $fileVars)
1300
1305
} else {
1301
1306
if (is_bool ($ optValue )) {
1302
1307
$ optValue = ($ optValue ?"true " :"false " );
1308
+ } else if (isSet ($ definitions [$ key ]) && $ definitions [$ key ]["type " ] == "password " && !empty ($ optValue )){
1309
+ $ optValue = "__AJXP_VALUE_SET__ " ;
1303
1310
}
1311
+
1304
1312
$ optValue = AJXP_Utils::xmlEntities ($ optValue , true );
1305
1313
print ("<param name= \"$ key \" value= \"$ optValue \"/> " );
1306
1314
}
@@ -1373,7 +1381,10 @@ public function switchAction($action, $httpVars, $fileVars)
1373
1381
$ res = ConfService::replaceRepository ($ repId , $ repo );
1374
1382
} else {
1375
1383
$ options = array ();
1376
- $ this ->parseParameters ($ httpVars , $ options , null , true );
1384
+ $ existing = $ repo ->getOptionsDefined ();
1385
+ $ existingValues = array ();
1386
+ foreach ($ existing as $ exK ) $ existingValues [$ exK ] = $ repo ->getOption ($ exK , true );
1387
+ $ this ->parseParameters ($ httpVars , $ options , null , true , $ existingValues );
1377
1388
if (count ($ options )) {
1378
1389
foreach ($ options as $ key =>$ value ) {
1379
1390
if ($ key == "AJXP_SLUG " ) {
@@ -1502,6 +1513,9 @@ public function switchAction($action, $httpVars, $fileVars)
1502
1513
$ options = array ();
1503
1514
$ this ->parseParameters ($ httpVars , $ options , null , true );
1504
1515
}
1516
+ if (isset ($ repoOptions [$ metaSourceId ])){
1517
+ $ this ->mergeExistingParameters ($ options , $ repoOptions [$ metaSourceId ]);
1518
+ }
1505
1519
$ repoOptions [$ metaSourceId ] = $ options ;
1506
1520
uksort ($ repoOptions , array ($ this ,"metaSourceOrderingFunction " ));
1507
1521
$ repo ->addOption ("META_SOURCES " , $ repoOptions );
@@ -1597,6 +1611,7 @@ public function switchAction($action, $httpVars, $fileVars)
1597
1611
$ fullManifest = $ ajxpPlugin ->getManifestRawContent ("" , "xml " );
1598
1612
$ xPath = new DOMXPath ($ fullManifest ->ownerDocument );
1599
1613
$ addParams = "" ;
1614
+ $ instancesDefinitions = array ();
1600
1615
$ pInstNodes = $ xPath ->query ("server_settings/global_param[contains(@type, 'plugin_instance:')] " );
1601
1616
foreach ($ pInstNodes as $ pInstNode ) {
1602
1617
$ type = $ pInstNode ->getAttribute ("type " );
@@ -1617,33 +1632,48 @@ public function switchAction($action, $httpVars, $fileVars)
1617
1632
$ addParams .= str_replace ("<param " , "<global_param group_switch_name= \"$ {fieldName}\" group_switch_label= \"" .$ typePlug ->getManifestLabel ().$ checkErrorMessage ."\" group_switch_value= \"" .$ typePlug ->getId ()."\" " , $ tParams );
1618
1633
$ addParams .= str_replace ("<param " , "<global_param " , AJXP_XMLWriter::replaceAjxpXmlKeywords ($ typePlug ->getManifestRawContent ("server_settings/param[@group_switch_name] " )));
1619
1634
$ addParams .= AJXP_XMLWriter::replaceAjxpXmlKeywords ($ typePlug ->getManifestRawContent ("server_settings/global_param " ));
1635
+ $ instancesDefs = $ typePlug ->getConfigsDefinitions ();
1636
+ if (!empty ($ instancesDefs ) && is_array ($ instancesDefs )) {
1637
+ foreach ($ instancesDefs as $ defKey => $ defData ){
1638
+ $ instancesDefinitions [$ fieldName ."/ " .$ defKey ] = $ defData ;
1639
+ }
1640
+ }
1620
1641
}
1621
1642
}
1622
1643
$ allParams = AJXP_XMLWriter::replaceAjxpXmlKeywords ($ fullManifest ->ownerDocument ->saveXML ($ fullManifest ));
1623
1644
$ allParams = str_replace ('type="plugin_instance: ' , 'type="group_switch: ' , $ allParams );
1624
1645
$ allParams = str_replace ("</server_settings> " , $ addParams ."</server_settings> " , $ allParams );
1625
1646
1626
1647
echo ($ allParams );
1627
- $ definitions = $ ajxpPlugin ->getConfigsDefinitions ();
1648
+ $ definitions = $ ajxpPlugin ->getConfigsDefinitions () + $ instancesDefinitions ;
1628
1649
$ values = $ ajxpPlugin ->getConfigs ();
1629
1650
if (!is_array ($ values )) $ values = array ();
1630
1651
echo ("<plugin_settings_values> " );
1652
+ // First flatten keys
1653
+ $ flattenedKeys = array ();
1654
+ foreach ($ values as $ key => $ value ){
1655
+ $ type = $ definitions [$ key ]["type " ];
1656
+ if ((strpos ($ type , "group_switch: " ) === 0 || strpos ($ type , "plugin_instance: " ) === 0 ) && is_array ($ value )) {
1657
+ $ res = array ();
1658
+ $ this ->flattenKeyValues ($ res , $ definitions , $ value , $ key );
1659
+ $ flattenedKeys += $ res ;
1660
+ // Replace parent key by new flat value
1661
+ $ values [$ key ] = $ flattenedKeys [$ key ];
1662
+ }
1663
+ }
1664
+ $ values += $ flattenedKeys ;
1665
+
1631
1666
foreach ($ values as $ key => $ value ) {
1632
1667
$ attribute = true ;
1633
1668
$ type = $ definitions [$ key ]["type " ];
1634
1669
if ($ type == "array " && is_array ($ value )) {
1635
1670
$ value = implode (", " , $ value );
1636
- } else if ((strpos ($ type , "group_switch: " ) === 0 || strpos ($ type , "plugin_instance: " ) === 0 ) && is_array ($ value )) {
1637
- $ res = array ();
1638
- $ this ->flattenKeyValues ($ res , $ value , $ key );
1639
- foreach ($ res as $ newKey => $ newVal ) {
1640
- echo ("<param name= \"$ newKey \" value= \"" .AJXP_Utils::xmlEntities ($ newVal )."\"/> " );
1641
- }
1642
- continue ;
1643
1671
} else if ($ type == "boolean " ) {
1644
1672
$ value = ($ value === true || $ value === "true " || $ value == 1 ?"true " :"false " );
1645
1673
} else if ($ type == "textarea " ) {
1646
1674
$ attribute = false ;
1675
+ } else if ($ type == "password " && !empty ($ value )){
1676
+ $ value = "__AJXP_VALUE_SET__ " ;
1647
1677
}
1648
1678
if ($ attribute ) {
1649
1679
echo ("<param name= \"$ key \" value= \"" .AJXP_Utils::xmlEntities ($ value )."\"/> " );
@@ -1692,6 +1722,9 @@ public function switchAction($action, $httpVars, $fileVars)
1692
1722
$ options = array ();
1693
1723
$ this ->parseParameters ($ httpVars , $ options , null , true );
1694
1724
$ confStorage = ConfService::getConfStorageImpl ();
1725
+ list ($ pType , $ pName ) = explode (". " , $ httpVars ["plugin_id " ]);
1726
+ $ existing = $ confStorage ->loadPluginConfig ($ pType , $ pName );
1727
+ $ this ->mergeExistingParameters ($ options , $ existing );
1695
1728
$ confStorage ->savePluginConfig ($ httpVars ["plugin_id " ], $ options );
1696
1729
AJXP_PluginsService::clearPluginsCache ();
1697
1730
AJXP_XMLWriter::header ();
@@ -2404,22 +2437,40 @@ public function updateUserRole($userId, $roleId, $addOrRemove, $updateSubUsers =
2404
2437
}
2405
2438
2406
2439
2407
- public function parseParameters (&$ repDef , &$ options , $ userId = null , $ globalBinaries = false )
2440
+ protected function parseParameters (&$ repDef , &$ options , $ userId = null , $ globalBinaries = false , $ existingValues = array () )
2408
2441
{
2409
2442
AJXP_Utils::parseStandardFormParameters ($ repDef , $ options , $ userId , "DRIVER_OPTION_ " , ($ globalBinaries ?array ():null ));
2443
+ if (!count ($ existingValues )){
2444
+ return ;
2445
+ }
2446
+ $ this ->mergeExistingParameters ($ options , $ existingValues );
2447
+ }
2410
2448
2449
+ protected function mergeExistingParameters (&$ parsed , $ existing ){
2450
+ foreach ($ parsed as $ k => &$ v ){
2451
+ if ($ v === "__AJXP_VALUE_SET__ " && isSet ($ existing [$ k ])){
2452
+ $ parsed [$ k ] = $ existing [$ k ];
2453
+ }else if (is_array ($ v ) && is_array ($ existing [$ k ])){
2454
+ $ this ->mergeExistingParameters ($ v , $ existing [$ k ]);
2455
+ }
2456
+ }
2411
2457
}
2412
2458
2413
- public function flattenKeyValues (&$ result , $ values , $ parent = "" )
2459
+ public function flattenKeyValues (&$ result , & $ definitions , $ values , $ parent = "" )
2414
2460
{
2415
2461
foreach ($ values as $ key => $ value ) {
2416
2462
if (is_array ($ value )) {
2417
- $ this ->flattenKeyValues ($ result , $ value , $ parent ."/ " .$ key );
2463
+ $ this ->flattenKeyValues ($ result , $ definitions , $ value , $ parent ."/ " .$ key );
2418
2464
} else {
2419
2465
if ($ key == "group_switch_value " || $ key == "instance_name " ) {
2420
2466
$ result [$ parent ] = $ value ;
2421
2467
} else {
2422
2468
$ result [$ parent .'/ ' .$ key ] = $ value ;
2469
+ if (isSet ($ definitions [$ key ])){
2470
+ $ definitions [$ parent .'/ ' .$ key ] = $ definitions [$ key ];
2471
+ }else if (isSet ($ definitions [dirname ($ parent )."/ " .$ key ])){
2472
+ $ definitions [$ parent .'/ ' .$ key ] = $ definitions [dirname ($ parent )."/ " .$ key ];
2473
+ }
2423
2474
}
2424
2475
}
2425
2476
}
0 commit comments