0
0

Added new lines at the end of files, added edit functionality

This commit is contained in:
Bryan 2019-06-02 14:46:51 +02:00
parent ed20989e14
commit 312d03599f
No known key found for this signature in database
GPG Key ID: 6CB4C49B61AD50EF
13 changed files with 137 additions and 11 deletions

View File

@ -1,3 +1,3 @@
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?URI=$1 [L,QSA]
RewriteRule ^(.*)$ index.php?URI=$1 [L,QSA]

View File

@ -29,4 +29,4 @@ create one? Use it to do whatever you want, it may break
the website or it may not, it's up to you and the fact that
it is provided empty.
Only a suggestion: if you don't populate the config file,
what part of the website you think that will work properly?
what part of the website you think that will work properly?

View File

@ -49,4 +49,4 @@ body {
min-width: 100%;
margin-top: 5px;
}
}
}

28
lib/css/manage.css Normal file
View File

@ -0,0 +1,28 @@
.urlContainer {
width:100%;
margin:0 auto;
display:inline-block;
}
.urlContainer .urlId, .urlContainer .urlLink, .urlContainer .urlControl {
display: inline;
}
.urlContainer .urlLink {
border: none;
background-color: transparent;
padding: 10px;
font-family: "Consolas", "Lucida Console", "monospace";
width: 50ch;
}
.urlContainer .urlLink:hover {
border: 2px;
border-radius: 10px;
border-color: aqua;
background-color: lightgrey;
}
.urlContainer .urlLink:focus {
border: none;
border-radius: 10px;
background-color: transparent;
outline: none;
box-shadow: 0px 0px 3px blue;
}

View File

@ -8,4 +8,4 @@
<h1>404: Page not found!</h1>
</center>
</body>
</html>
</html>

View File

@ -39,3 +39,56 @@ function insertNewURL() {
data.append('url', url);
xhr.send( data );
}
function editURL(node) {
var url = node.childNodes[3].value;
var url_id = node.childNodes[1].innerHTML
var xhr = new XMLHttpRequest ( );
xhr.open ( "POST", 'edit', true );
xhr.onreadystatechange = function ( ) {
if ( xhr.status == 200 ) {
if ( xhr.readyState == XMLHttpRequest.DONE ) {
var response = xhr.responseText;
response = JSON.parse ( response );
if ( response [ 'status' ] == 200 ) {
document.getElementById ( "responsetext" ).innerHTML = response [ 'message' ];
setTimeout( function( ) {
document.getElementById ( 'responsetext' ).innerHTML = ""
}, 1500 );
}
else {
document.getElementById ( "responsetext" ).innerHTML = response [ 'error_message' ];
setTimeout( function( ) {
document.getElementById ( 'responsetext' ).innerHTML = ""
}, 1500 );
}
}
}
else {
document.getElementById ( "responsetext" ).innerHTML = response [ 'error_message' ];
setTimeout( function( ) {
document.getElementById ( 'responsetext' ).innerHTML = ""
}, 1500 );
}
}
data = new FormData ( );
data.append('url', url);
data.append('url_id', url_id);
xhr.send( data );
}
(function(){
var URLs = document.getElementsByClassName("urlLink");
for(i=0;i<URLs.length;i++) {
URLs[i].onclick = function() {
var oldText = this.value;
this.parentNode.childNodes[5].style.display = "";
this.parentNode.childNodes[5].childNodes[1].onclick = function() {
editURL(this.parentNode.parentNode);
this.parentNode.style.display = "none";
}
this.parentNode.childNodes[5].childNodes[3].onclick = function() {
this.parentNode.parentNode.childNodes[3].value = oldText;
this.parentNode.style.display = "none";
};
}
}
})();

View File

@ -246,4 +246,4 @@ function SHA512 ( str )
binarray.push ( H [ i ].lowOrder );
}
return binb2hex ( binarray );
}
}

View File

@ -13,4 +13,4 @@ use the code as is, without explicit permission to do so.
Such permissions can be requested at copyright@bryanpedini.it
No permissions to do anything against this license is given
without an explicit and valid motivation to do so, so please
don't email me asking any permission without providing a valid reason.
don't email me asking any permission without providing a valid reason.

View File

@ -10,6 +10,9 @@
case "insert":
include ( 'lib/php/management/insert.php' );
break;
case "edit":
include ( 'lib/php/management/edit.php' );
break;
default:
http_response_code ( 404 );
include ( 'errors/404.html' );

View File

@ -20,4 +20,4 @@
<p>Reset your password here - Placeholder</p>
</center>
</body>
</html>
</html>

View File

@ -71,7 +71,7 @@
</div>
</div>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="<?=$GLOBALS['config']['installation_path']?>/lib/js/sha512.min.js"></script>
<script src="<?=$GLOBALS['config']['installation_path']?>/lib/js/login.js"></script>
<script>var script_name = "<?=$GLOBALS['config']['installation_path']?>";</script>

View File

@ -13,10 +13,12 @@
<head>
<title>Management Panel | <?=$GLOBALS['config']['website_name']?></title>
<link href="<?=$GLOBALS['config']['installation_path']?>/favicon.ico" rel="icon" type="image/x-icon">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.2/css/all.css" integrity="sha256-39jKbsb/ty7s7+4WzbtELS4vq9udJ+MDjGTD5mtxHZ0=" crossorigin="anonymous" />
<link href="<?=$GLOBALS['config']['installation_path']?>/lib/css/manage.css" rel="stylesheet">
</head>
<body>
<button onclick="logout()">Logout</button>
<div id="urllist">
<div class="urlList">
<?php
if ( $result->rowCount ( ) == 0 ) {
echo ( "You have not created any URL yet.<br>" );
@ -24,7 +26,14 @@
else {
$rows = $result->fetchAll ( PDO::FETCH_ASSOC );
foreach ( $rows as $row ) {
echo ( "\t\t\t" . '<div>' . $row [ 'ID' ] . " | " . $row [ 'URL' ] . "</div>\n" );
echo ( "\t\t\t<div class=\"urlContainer\">" );
echo ( "\t\t\t\t<div class=\"urlId\">" . $row [ 'ID' ] . "</div>" );
echo ( "\t\t\t\t<input type=\"text\" class=\"urlLink\" value=\"" . $row [ 'URL' ] . "\">" );
echo ( "\t\t\t\t<div class=\"urlControl\" style=\"display: none;\">" );
echo ( "\t\t\t\t\t<button><i class=\"fas fa-check\"></i></button>" );
echo ( "\t\t\t\t\t<button><i class=\"fas fa-times\"></i></button>" );
echo ( "\t\t\t\t</div>" );
echo ( "\t\t\t</div>" );
}
}
?>
@ -32,8 +41,8 @@
<input type="text" id="form-url" placeholder="URL:">
<button onclick="insertNewURL()">Insert new URL</button><br>
<div id="responsetext"></div>
<script>var script_name = "<?=$GLOBALS['config']['installation_path']?>";</script>
<script src="<?=$GLOBALS['config']['installation_path']?>/lib/js/manage.js"></script>
<script src="<?=$GLOBALS['config']['installation_path']?>/lib/js/logout.js"></script>
<script>var script_name = "<?=$GLOBALS['config']['installation_path']?>";</script>
</body>
</html>

View File

@ -0,0 +1,33 @@
<?php
if ( ! isset ( $_SESSION [ 'user_id' ] ) ) {
header ( 'Content-Type: application/json' );
http_response_code ( 401 );
$response = [
'status' => 401,
'error_message' => 'You either are not logged in or you do not have permissions to edit URLs.'
];
echo ( json_encode ( $response ) );
exit;
}
if ( ! isset ( $_POST [ 'url' ] ) ) {
header ( 'Content-Type: application/json' );
http_response_code ( 400 );
$response = [
'status' => 400,
'error_message' => 'You either did not provide a URL or you provided an invalid one.'
];
echo ( json_encode ( $response ) );
exit;
}
$database = new Database ( $GLOBALS [ 'config' ] [ 'db' ] );
$database->connect ( );
$database->prepare ( "UPDATE `links` SET `URL`=:url WHERE `ID`=:url_id;" );
$database->bind ( [ ':url' => $_POST [ 'url' ], 'url_id' => $_POST [ 'url_id' ] ] );
$database->execute ( );
header ( 'Content-Type: application/json' );
$response = [
'status' => 200,
'message' => 'URL edited correctly.'
];
echo ( json_encode ( $response ) );
exit;