Location: PHPKode > projects > mediaIndex > includes/editFile.php
<?php
if (isset($_POST['submit']) && $_POST['submit']=="Save") {
    $GLOBALS['file']->title = $_POST['title'];
    $GLOBALS['file']->desc = $_POST['desc'];
    $GLOBALS['file']->saveMetadata();
}
elseif (isset($_POST['submit']) && $_POST['submit']=="Delete") {
    // remove checked comments
    if (isset($_POST['delcomment'])) {
        $sql = "DELETE FROM comments WHERE id < 0 ";
        foreach ($_POST['delcomment'] as $id) {
            $sql .= "OR id = {$id} ";
            _addMessage("Deleted comment {$id}.");
        }
        sqlite_query($GLOBALS['gDb'],$sql);
    }
}
elseif (isset($_POST['submit']) && $_POST['submit']=="Add Mirror") {
    // insert mirror
    $sql = "INSERT INTO mirrors (hash,url) ";
    $sql .= "VALUES ('{$GLOBALS['file']->hash}',";
    $sql .= "'"._escape($_POST['url'])."')";
    sqlite_query($GLOBALS['gDb'],$sql);
    _addMessage("Mirror added.");
}
elseif (isset($_POST['submit']) && $_POST['submit']=="Delete Mirrors") {
    // remove checked mirrors
    if (isset($_POST['delmirror'])) {
        $sql = "DELETE FROM mirrors WHERE id < 0 ";
        foreach ($_POST['delmirror'] as $id) {
            $sql .= "OR id = {$id} ";
            _addMessage("Deleted mirror {$id}.");
        }
        sqlite_query($GLOBALS['gDb'],$sql);
    }
}

echo "<div class=\"edit\" style=\"display:none;\" id=\"editForm\">\n";
_printSubtitle("Editing file ".basename($GLOBALS['file']->path));
echo "<form method=\"POST\">\n";
echo "<table>\n";
echo "<tr><td width=\"20%\">Title: </td><td><input type=\"text\" name=\"title\" size=\"40\" maxlength=\"255\" value=\"".stripslashes($GLOBALS['file']->title)."\" /></td></tr>\n";
echo "<tr><td width=\"20%\">Description: </td><td><textarea name=\"desc\" rows=\"5\" cols=\"50\">".stripslashes($GLOBALS['file']->desc)."</textarea></td></tr>\n";
echo "<tr><td colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"Save\" /></td></tr>\n";
echo "</table><br />\n";

_printSubtitle("File Mirrors");
// remove mirrors
$sql = "SELECT * FROM mirrors WHERE hash = '{$GLOBALS['file']->hash}'";
$result = sqlite_array_query($GLOBALS['gDb'],$sql,SQLITE_ASSOC);
if (count($result)>0) {
    foreach ($result as $A) {
        echo "<input type=\"checkbox\" name=\"delmirror[]\" value=\"{$A['id']}\" /> \n";
        echo $A['url'] . "<br />";
    }
    echo "<input type=\"submit\" name=\"submit\" value=\"Delete Mirrors\" />\n";
    echo "<br /><br />\n";
}
// add new mirror
echo "<table>\n";
echo "<tr><td width=\"20%\">URL: </td><td><input type=\"text\" name=\"url\" size=\"60\" maxlength=\"255\" /></td></tr>\n";
echo "<tr><td colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"Add Mirror\" /></td></tr>\n";
echo "</table>\n";

// print form for removing comments
$sql = "SELECT * FROM comments WHERE hash = '{$GLOBALS['file']->hash}'";
$result = sqlite_array_query($GLOBALS['gDb'],$sql,SQLITE_ASSOC);
if (count($result)>0) {
    _printSubtitle("Remove Comments");
    foreach ($result as $A) {
        echo "<input type=\"checkbox\" name=\"delcomment[]\" value=\"{$A['id']}\" />\n";
        echo "<span class=\"comment\">Posted by <b>".htmlspecialchars(stripslashes($A['name']))."</b> on ".date(_DATEFORMAT,$A['time'])."<br />\n";
        echo "<blockquote>"._parseText($A['body'])."</blockquote></span>\n";
    }
    echo "<input type=\"submit\" name=\"submit\" value=\"Delete\" />\n";
}
echo "</form>\n";
echo "</div>\n";
?>
Return current item: mediaIndex