You've already forked OpenShorte.old
Added new lines at the end of files, added edit functionality
This commit is contained in:
33
lib/php/management/edit.php
Normal file
33
lib/php/management/edit.php
Normal 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;
|
Reference in New Issue
Block a user