Show sourcecode

The following files exists in this folder. Click to view.

test/incl/blokket/

add-article.php
aside.php
blokket-default.php
data/
initiate.php
remove-article.php
show-all-articles.php
show-article.php
update-article.php

add-article.php

1 lines ASCII Unix (LF)
1
<?php
$path = "incl/blokket/data";
$result = null;
$listitems = null;
$added = null;
$message = null;
if(isset($_POST['doAdd']))
{
    if(isset($_POST['article-name']))
    {
        $nameAlreadyExists = false;
        $filenames = readDirectory($path);
        foreach($filenames as $filename)
        {
            if($_POST['article-name'] == $filename)
            {
                $nameAlreadyExists = true;
                $message = "There's already an article with that name.";
            }
        }

        if($nameAlreadyExists == false)
        {
            $articlename = $_POST['article-name'];
            $newfile = fopen("$path/$articlename", "w");
            chmod("$path/$articlename", 0666);
            fclose($newfile);
            $added = true;
        }
        else
            $added = false;
    }
}
?>

<h1>Add article</h1>
<fieldset>
    <p>Add a new article with a unique name.</p>
    <form method="post">
        <p><label for="article-list">Available articles:</label><br>
        <select id="article-list" size=4 name="article-list">
            <?php
            $filenames = readDirectory($path);
            foreach ($filenames as $filename)
                    $listitems .= "<option value='" . $filename . "'>" . $filename . "</option>";
            echo $listitems;
            ?>
        </select></p>

        <p><label for="article-name">New article:</label><br>
        <input id="article-name" type="text" name="article-name" value=""></p>

        <p><input type="submit" name="doAdd" value="Add article">
    </form>

    <?php
    if(isset($added))
    {
        if ($added == true)
            echo "<p class='success'>The article was added.</p>";
    }
    ?>
</fieldset>