Skip to content

Commit

Permalink
Some changes again
Browse files Browse the repository at this point in the history
New items and ajax save data in PHPConfig.
Added Angular JS.
  • Loading branch information
myaaghubi committed Sep 12, 2019
1 parent e15604a commit 1faae83
Show file tree
Hide file tree
Showing 7 changed files with 575 additions and 140 deletions.
3 changes: 2 additions & 1 deletion xamppboard/include/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function getUserConfigParameters() {

function saveUserConfig($path, $specificKeysTemp) {
if (!file_exists($path)) {
return false;
return "error";
}

// var_dump($specificKeysTemp);
Expand Down Expand Up @@ -66,5 +66,6 @@ function saveUserConfig($path, $specificKeysTemp) {
// var_dump($specificKeysTemp);

file_put_contents($path, $fileFinal);
return "done";
// var_dump($fileFinal);
}
2 changes: 1 addition & 1 deletion xamppboard/include/init.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

$sys_vesrion = "0.3.1";
$sys_vesrion = "0.3.3";


?>
176 changes: 100 additions & 76 deletions xamppboard/phpconfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@

require "include/init.php";
require "include/functions.php";

getHeader("PHPConfig", "switch");
// exit;

$phpIniPath = php_ini_loaded_file(); // path of php.ini
$isPhpIniWirtable = is_writable($phpIniPath);

if (isset($_POST['name']) and $_POST['name'] == "config") { // detect is user saving?
saveUserConfig($phpIniPath, getUserConfigParameters());
print saveUserConfig($phpIniPath, getUserConfigParameters());
exit;
}

getHeader("PHPConfig", "switch");

$phpIniFullConfig = parse_ini_file($phpIniPath, false, INI_SCANNER_TYPED);

$specificKeys = array(
"max_execution_time", "max_input_time", "memory_limit", "upload_max_filesize", "post_max_size", "date.timezone", "asp_tags", "file_uploads",
"magic_quotes_gpc", "register_globals", "zlib.output_compression", "display_errors", "allow_url_fopen", "allow_url_include"
"max_execution_time", "max_input_time", "memory_limit", "post_max_size", "session.gc_maxlifetime", "upload_max_filesize", "max_file_uploads",
"date.timezone", "mysqli.default_port", "default_charset", "safe_mode", "asp_tags", "file_uploads", "magic_quotes_gpc", "register_globals",
"zlib.output_compression", "display_errors", "allow_url_fopen", "allow_url_include"
);

$specificKeys_ = array();
Expand All @@ -29,113 +32,134 @@
?>

<!-- Page Content -->
<div class="container">
<div class="container" ng-app="configApp" ng-controller="configCtrl">
<h1 class="page-header" style="position: relative;">PHPConfig <br><span class="details">
<?php
print $phpIniPath . ' ';
if (is_writable($phpIniPath)) {
showLabel("Writable", "success");
} else {
showLabel("Not-Writable", "danger");
}
?>

<button type="button" id="save-btn" style="float: right" ng-click="save()" class="btn btn-<?php print($isPhpIniWirtable ? 'primary' : 'default'); ?>" <?php print($isPhpIniWirtable ? '' : 'disabled'); ?>>
<span id="msg-block-spinner" class="spinner-grow spinner-grow-sm spinner-hidden" style="margin:0 5px 0 -2px;" role="status" aria-hidden="true"></span>Save
</button>
</span>
</h1>
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">PHPConfig <br><span class="details">
<?php
print $phpIniPath . ' ';
if (is_writable($phpIniPath)) {
showLabel("Writable", "success");
} else {
showLabel("Not-Writable", "danger");
}
?>
<button value="Save" style="float: right" onclick="$('#form-config').submit()" class="btn btn-default" <?php print(is_writable($phpIniPath) ? '' : 'disabled'); ?>>Save</button>
</span>
</h1>
</div>

<div class="col-lg-12">
<form class="form-horizontal" method="post" id="form-config">
<div class="form-group row">
<input type="hidden" name="name" value="config">
<input type="hidden" name="name" ng-model="data.name" value="config">
<?php
$isTypeChanged = false;
$index = 0;
$prefixHtml = '<div class="col-md-6">';
$suffixHtml = '</div>';
foreach ($specificKeys_ as $key => $value) {
if ($value === null) {
continue;
$isTypeChanged = false;
$index = 0;
$prefixHtml = '<div class="col-md-6">';
$suffixHtml = '</div>';
foreach ($specificKeys_ as $key => $value) {
if ($value === null) {
continue;
}
if ($index > 1 and $index % 2 == 0) {
print '</div> <div class="form-group row">';
}
if (gettype($value) == "boolean") {
if (!$isTypeChanged) {
print '</div><br> <div class="form-group row">';

$isTypeChanged = true;
$index = 0;
}
if ($index > 1 and $index % 2 == 0) {
print '</div> <div class="form-group row">';
if ($value == 1) {
$value = "checked";
} else {
$value = "";
}
if (gettype($value) == "boolean") {
if (!$isTypeChanged) {
print '</div><br> <div class="form-group row">';

$isTypeChanged = true;
$index = 0;
}
if ($value == 1) {
$value = "checked";
} else {
$value = "";
}
print $prefixHtml . '
print $prefixHtml . '
<label class="col-md-7 col-xs-8 col-form-label">' . $key . '</label>
<div class="col-md-5 col-xs-4">
<label class="switch">
<input type="checkbox" name="config[' . $key . ']" ' . $value . '>
<input type="hidden" name="config[' . $key . ']" value="Off">
<input type="checkbox" name="config[' . $key . ']" value="On" ' . $value . '>
<span class="slider round"></span>
</label>
</div>
' . $suffixHtml;
} else if ($key == 'date.timezone') {
$tzlist = DateTimeZone::listIdentifiers(DateTimeZone::ALL);
$options = '';
foreach ($tzlist as $item) {
$selection = '';
if ($value == $item) {
$selection = 'selected';
}
$options .= '<option value="' . $item . '" ' . $selection . '>' . $item . '</option>';
} else if ($key == 'date.timezone') {
$tzlist = DateTimeZone::listIdentifiers(DateTimeZone::ALL);
$options = '';
foreach ($tzlist as $item) {
$selection = '';
if ($value == $item) {
$selection = 'selected';
}
print $prefixHtml . '
$options .= '<option value="' . $item . '" ' . $selection . '>' . $item . '</option>';
}
print $prefixHtml . '
<label class="col-md-7 col-form-label">' . $key . '</label>
<div class="col-md-5">
' . '<select class="form-control form-control-plaintext" name="config[' . $key . ']">'
. $options .
'<select>
. $options .
'<select>
</div>
' . $suffixHtml;
} else {
print $prefixHtml . '
} else {
print $prefixHtml . '
<label class="col-md-7 col-form-label">' . $key . '</label>
<div class="col-md-5">
<input type="text" class="form-control form-control-plaintext" name="config[' . $key . ']" value="' . $value . '">
</div>
' . $suffixHtml;
}
$index += 1;
}
$index += 1;
}

?>
?>
</div>
</div>
</form>
</div>
</div>
</div>
<!-- /.container -->
<script type="text/javascript">
jQuery(document).ready(function($) {
$("#form-config").submit(function() {
var form = $(this);
form.find('input[type="checkbox"]').each(function() {
var checkbox = $(this);
if (checkbox.is(":checked") == true) {
checkbox.attr('value', 'On');
} else {
checkbox.prop('checked', true);
checkbox.attr('value', 'Off');
}
})
});
<script>
var form = angular.element('#form-config');
var saveBtn = angular.element('#save-btn');
var msgBlockSpinner = angular.element('#msg-block-spinner');
var msgBlockMsg = angular.element('#msg-block-msg');
angular.module('configApp', []).controller('configCtrl', function($scope, $http, $timeout) {
saveBtn.removeClass().addClass('btn btn-primary');
$scope.save = function(angular) {
saveBtn.attr('disabled', true);
msgBlockSpinner.removeClass('spinner-hidden');
saveBtn.removeClass().addClass('btn btn-warning');

$http({
method: 'POST',
url: "phpconfig.php",
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: form.serialize()
}).then(function successCallback(response) {
$timeout(function() {
saveBtn.attr('disabled', false);
saveBtn.removeClass().addClass('btn btn-primary');
msgBlockSpinner.addClass('spinner-hidden');
}, 500);
}, function errorCallback(response) {
$timeout(function() {
saveBtn.attr('disabled', false);
saveBtn.removeClass().addClass('btn btn-danger');
msgBlockSpinner.addClass('spinner-hidden');
}, 500);
});
};
});
</script>
<!-- /.container -->
<?php
getFooter();
?>
Loading

0 comments on commit 1faae83

Please sign in to comment.