links::editLinkByName PHP Method

editLinkByName() public method

public editLinkByName ( $originalName, $name, $address )
    function editLinkByName($originalName, $name, $address)
    {
        require_once $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "classes" . DIRECTORY_SEPARATOR . "settings.class.php";
        $settings = new settings();
        if ($settings::db_driver == "xml") {
            // XML
            $links = simplexml_load_file($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR . "links.xml");
            foreach ($links->xpath("link[name='" . $originalName . "']") as $link) {
                $link->name = $name;
                $link->address = $address;
            }
            file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR . "links.xml", $links->asXML());
        } else {
            // PDO
            require_once $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "classes" . DIRECTORY_SEPARATOR . "common.class.php";
            $common = new common();
            $dbh = $common->pdoOpen();
            $sql = "UPDATE " . $settings::db_prefix . "links SET name = :name, address = :address WHERE name = :originalName";
            $sth = $dbh->prepare($sql);
            $sth->bindParam(':originalName', $originalName, PDO::PARAM_STR, 100);
            $sth->bindParam(':name', $name, PDO::PARAM_STR, 100);
            $sth->bindParam(':address', $address, PDO::PARAM_STR, 250);
            $sth->execute();
            $sth = NULL;
            $dbh = NULL;
        }
    }

Usage Example

コード例 #1
0
ファイル: edit.php プロジェクト: jprochazka/adsb-receiver
session_start();
// Load the require PHP classes.
require_once $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "classes" . DIRECTORY_SEPARATOR . "common.class.php";
require_once $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "classes" . DIRECTORY_SEPARATOR . "account.class.php";
require_once $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "classes" . DIRECTORY_SEPARATOR . "links.class.php";
$common = new common();
$account = new account();
$links = new links();
// Check if the user is logged in.
if (!$account->isAuthenticated()) {
    // The user is not logged in so forward them to the login page.
    header("Location: login.php");
}
if ($common->postBack()) {
    // Update the contents of the blog post.
    $links->editLinkByName(urldecode($_POST['originalName']), $_POST['name'], $_POST['address']);
    // Forward the user to the link management index page.
    header("Location: /admin/links/");
}
// Get the link data.
$link = $links->getLinkByName(urldecode($_GET['name']));
////////////////
// BEGIN HTML
require_once $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "admin" . DIRECTORY_SEPARATOR . "includes" . DIRECTORY_SEPARATOR . "header.inc.php";
?>
            <h1>Links Management</h1>
            <hr />
            <h2>Edit Link</h2>
            <h3><?php 
echo $link['name'];
?>