You've already forked OpenShorte.old
							
							Website refactored
Prepared the website structure for the new layout
This commit is contained in:
		@@ -1,63 +1,43 @@
 | 
			
		||||
<?php
 | 
			
		||||
    if ( ! isset ( $_SESSION [ 'user_id' ] ) ) {
 | 
			
		||||
        header ( "Location: " . substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ) . "/login" );
 | 
			
		||||
    }
 | 
			
		||||
    $database = new Database ( $GLOBALS [ 'config' ] [ 'db' ] );
 | 
			
		||||
    $database->connect ( );
 | 
			
		||||
    if ( isset ( $_POST [ 'url' ] ) ) {
 | 
			
		||||
        $url = $_POST [ 'url' ];
 | 
			
		||||
        $database->prepare ( "INSERT INTO `links` ( `ID`, `URL`, `created_by` ) VALUES ( NULL, ?, " . $_SESSION [ 'user_id' ] . " );" );
 | 
			
		||||
        $parameters = [
 | 
			
		||||
            [ "s" ],
 | 
			
		||||
            [ &$url ],
 | 
			
		||||
        ];
 | 
			
		||||
        $database->bind ( $parameters );
 | 
			
		||||
        $database->execute ( );
 | 
			
		||||
        $database->prepare ( "SELECT MAX( links.ID ) as `last` FROM links;");
 | 
			
		||||
        $database->execute ( );
 | 
			
		||||
        $result = $database->get_result ( );
 | 
			
		||||
        $row = $result->fetch_assoc ( );
 | 
			
		||||
        header ( 'Content-Type: application/json' );
 | 
			
		||||
        http_response_code ( 401 );
 | 
			
		||||
        $response = [
 | 
			
		||||
            'status' => 200,
 | 
			
		||||
            'message' => 'URL inserted correctly.',
 | 
			
		||||
            'last_insert' => $row [ 'last' ],
 | 
			
		||||
            'status' => 401,
 | 
			
		||||
            'error_message' => 'You either are not logged in or you do not have permissions to insert new URLs.'
 | 
			
		||||
        ];
 | 
			
		||||
        echo ( json_encode ( $response ) );
 | 
			
		||||
        exit;
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
        $database->prepare ( "SELECT links.ID, links.URL FROM links WHERE links.created_by = " . $_SESSION [ 'user_id' ] );
 | 
			
		||||
        $database->execute ( );
 | 
			
		||||
        $result = $database->get_result ( );
 | 
			
		||||
        $row = $result->fetch_assoc ( );
 | 
			
		||||
?>
 | 
			
		||||
<!DOCTYPE html>
 | 
			
		||||
<html>
 | 
			
		||||
    <head>
 | 
			
		||||
        <title>BJPHoster URL Shortener | Control Panel</title>
 | 
			
		||||
        <link href="<?=substr($_SERVER['SCRIPT_NAME'],0,-10)?>/favicon.ico" rel="icon" type="image/x-icon">
 | 
			
		||||
    </head>
 | 
			
		||||
    <body>
 | 
			
		||||
        <button onclick="logout()">Logout</button>
 | 
			
		||||
        <div id="urllist">
 | 
			
		||||
<?php
 | 
			
		||||
                if ( ! $row ) {
 | 
			
		||||
                    echo ( "You have not created any URL yet.<br>" );
 | 
			
		||||
                }
 | 
			
		||||
                else {
 | 
			
		||||
                    do {
 | 
			
		||||
                        echo ( "\t\t\t" . '<div>' . $row [ 'ID' ] . " | " . $row [ 'URL' ] . "</div>\n" );
 | 
			
		||||
                    } while ( $row = $result->fetch_assoc ( ) );
 | 
			
		||||
                }
 | 
			
		||||
?>
 | 
			
		||||
        </div>
 | 
			
		||||
        <input type="text" id="form-url" placeholder="URL:">
 | 
			
		||||
        <button onclick="urlinsert()">Insert new URL</button><br>
 | 
			
		||||
        <div id="responsetext"></div>
 | 
			
		||||
        <script src="<?=substr($_SERVER['SCRIPT_NAME'],0,-10)?>/lib/js/insertnew.js"></script>
 | 
			
		||||
        <script>var script_name = "<?=substr($_SERVER['SCRIPT_NAME'],0,-10)?>";</script>
 | 
			
		||||
    </body>
 | 
			
		||||
</html>
 | 
			
		||||
<?php
 | 
			
		||||
    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 ( );
 | 
			
		||||
    $url = $_POST [ 'url' ];
 | 
			
		||||
    $database->prepare ( "INSERT INTO `links` ( `URL`, `created_by` ) VALUES ( ?, " . $_SESSION [ 'user_id' ] . " );" );
 | 
			
		||||
    $parameters = [
 | 
			
		||||
        [ "s" ],
 | 
			
		||||
        [ &$url ],
 | 
			
		||||
    ];
 | 
			
		||||
    $database->bind ( $parameters );
 | 
			
		||||
    $database->execute ( );
 | 
			
		||||
    $database->prepare ( "SELECT MAX( links.ID ) as `last` FROM links;");
 | 
			
		||||
    $database->execute ( );
 | 
			
		||||
    $result = $database->get_result ( );
 | 
			
		||||
    $row = $result->fetch_assoc ( );
 | 
			
		||||
    header ( 'Content-Type: application/json' );
 | 
			
		||||
    $response = [
 | 
			
		||||
        'status' => 200,
 | 
			
		||||
        'message' => 'URL inserted correctly.',
 | 
			
		||||
        'last_insert' => $row [ 'last' ],
 | 
			
		||||
    ];
 | 
			
		||||
    echo ( json_encode ( $response ) );
 | 
			
		||||
    exit;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user