api_key = $api_key; $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $this->curl = $curl; } function fetch_config($license){ $ch = $this->curl; curl_setopt($ch, CURLOPT_URL, self::API_URL . "?api_key={$this->api_key}&type=fetch_config&license=$license"); if(!($resp = curl_exec($ch))){ die(curl_error($ch)); } return json_decode($resp); } function update_config_tab($license, $tab, $data){ $ch = $this->curl; curl_setopt($ch, CURLOPT_URL, self::API_URL . "?api_key={$this->api_key}&type=update_config_tab&license=$license&tab=$tab"); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(['data' => $data])); if(!($resp = curl_exec($ch))){ die(curl_error($ch)); } curl_setopt($ch, CURLOPT_POST, false); return json_decode($resp); } function __destruct(){ curl_close($this->curl); } } $api_key = ''; $license = ''; $mn = new menu($api_key); $response = $mn->fetch_config($license); if(!$response->success){ die($response->reason); } $current_config = $response->config; $tab = $_GET['tab'] ?? null; $is_valid_tab = ($tab && isset($current_config->$tab)); if($is_valid_tab && isset($_POST['c'])){ $mn->update_config_tab($license, $tab, $_POST); header('Refresh:0'); exit; } ?>
$tab; foreach($tab as $name => $option){//parse the types and display a label and input for each of them $extra = ''; $value = $option->value; echo ""; switch($option->type){ //handle types case 'number': $addition = "type='number'"; case 'boolean': $extra = ""; //use a trick to pass 0 or 1 if it's checked or not $addition = "type='checkbox'"; if($value){ $addition .= 'checked'; //handles the looks of the checkbox } $value = '1'; break; case 'string': $addition = "type='string'"; break; case 'color': $addition = "type='color'"; break; default: die('found an unsupported type'); } echo $extra; echo "
"; } ?>
$options) { echo "Modify $name
"; //display tabs } } ?>