2nd update
This commit is contained in:
78
admin/countries.php
Normal file
78
admin/countries.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
defined('admin') or exit;
|
||||
//------------------------------------------
|
||||
// GET COUNTRIES FROM API
|
||||
//------------------------------------------
|
||||
//CALL TO API FOR COUNTRIES
|
||||
$api_url = '/v2/taxes/';
|
||||
$countries = ioAPIv2($api_url,'',$clientsecret);
|
||||
//Decode Payload
|
||||
if (!empty($countries)){$countries = json_decode($countries,true);}else{$countries = null;}
|
||||
|
||||
var_dump($countries);
|
||||
//CountryID mapping
|
||||
$countryMap = array_column($countries, 'country', 'id');
|
||||
|
||||
//------------------------------------------
|
||||
// UPDATE COUNTRIES FROM SETTINGS FILE
|
||||
//------------------------------------------
|
||||
if (isset($_POST['updateCountries'])){
|
||||
//INITIAL VARIABLE
|
||||
$new_countries_in_scope;
|
||||
|
||||
foreach($_POST['country_select'] as $value){
|
||||
$new_countries_in_scope[$value] = $countryMap[$value];
|
||||
}
|
||||
|
||||
$filePath = '../custom/settings/settings.php';
|
||||
$fileContent = file_get_contents($filePath);
|
||||
|
||||
// Convert the new array to a string representation
|
||||
$newArrayString = var_export($new_countries_in_scope, true);
|
||||
|
||||
// Pattern to find the existing array assignment
|
||||
$pattern = '/\$countries_in_scope\s*=\s*array\s*\(.*?\)\s*;|\$countries_in_scope\s*=\s*\[.*?\]\s*;/s';
|
||||
|
||||
// Replace the old array with the new one
|
||||
$replacement = '$countries_in_scope = ' . $newArrayString . ';';
|
||||
$newContent = preg_replace($pattern, $replacement, $fileContent);
|
||||
|
||||
// Write the updated content back to the file
|
||||
file_put_contents($filePath, $newContent);
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
// GET COUNTRIES FROM SETTINGS FILE
|
||||
//------------------------------------------
|
||||
include '../custom/settings/settings.php';
|
||||
|
||||
template_admin_header('Countries', 'countries');
|
||||
|
||||
$view .='
|
||||
<form action="" method="post">
|
||||
<div class="content-title responsive-flex-wrap responsive-pad-bot-3">
|
||||
<h2 class="responsive-width-100">Countries in scope</h2>
|
||||
</div>';
|
||||
|
||||
$view .= '<div class="tabs">
|
||||
<a href="#" class="active">'.($general_actions ?? 'Actions' ).'</a>
|
||||
</div>
|
||||
';
|
||||
|
||||
$view .= '<div class="content-block tab-content active">
|
||||
<div class="form responsive-width-100">
|
||||
<label for="">Countries in scope</label>';
|
||||
foreach($countries as $country){
|
||||
$view .= '<div><input type="checkbox" id="'.$country['id'] .'" name="country_select[]" value="'.$country['id'].'" '.(isset($countries_in_scope[$country['id']])? " checked" : "").'> '.(${$country['country']} ?? $country['country']).'</div>';
|
||||
}
|
||||
$view .='
|
||||
<input type="submit" name="updateCountries" style="width: 15%;" value="Update Countries" class="btn">
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
$view .= '</form>';
|
||||
|
||||
//Output
|
||||
echo $view;
|
||||
|
||||
template_admin_footer();
|
||||
Reference in New Issue
Block a user