dat/bulk.php - index




















































































<?php 

/* AUX/BULK.PHP - perform text query bulk operations on the posts */

$url "?arg=$arg&amp;op=bulkdelete";

$query = <<<HTML
<form name="done" method="post" action="$url">
<div style="float:left;margin-right:10px;"><input type="text" name="deletewhere" size="32" value="title: ">
<input type="submit" name="button" value="go">
<input type="submit" name="button" value="done"></div>
<div style="width:90%;">Enter header and value to bulk delete posts by. 'title: Title' will delete all with title of 'Title'. (Not very useful until we add wildcard support.)</div><input type="checkbox" name="verbose" checked> Verbose
<input type="checkbox" name="test" checked> Test Only<br><br>
</form>

HTML;

if (
$deletewhere) {

    
$arg getvar('arg');
    
$test $_POST['test'];
    
$verbose $_POST['verbose'];

    
$recs dblistrecords();

    
$c count($recs); $n 0;        // count, number deleted

    // example: "title: Title" will delete all posts with title of Title

    
if (!preg_match("/(.+):\s*(.+)/",$deletewhere,$res))

        echo 
"failed to discern string: '$deletewhere'";

    else {
        
$index $res[1];
        
$string $res[2];
        
$index strtolower($index);

        if (
$verbose)
        echo 
"searching '$index' for '$string'";

        foreach (
$recs as $id) {
            
$record dbreadrecord($id);

            if (!isset(
$record[$index])) {
                echo 
"<br>record $id: '$index' missing";
                continue;
            }

            if (
$verbose)
            echo 
"<br>checking record $id '{$record[$index]}'";

            
// ??? wildcards? substring? case?
            
if ($record[$index] == $string) {

                if (
$verbose)
                echo 
" matched";

                
$n++;
                if (
$test) echo " (would delete: $id)"; else
                
dbdelrecord($id);
                if (
$verbose)
                echo 
" deleted";

            }
            else
                if (
$verbose)
                echo 
" skipped";
        }
    }

    echo 
"<br><b>$n deleted</b> of $c records<br>";
    echo 
"<form name='done' method='post' action='$url'>";
    echo 
"<input type='submit' name='button' value='done'>";
    echo 
"</form>";
}
else {
    echo 
$query;
    echo 
'<div id="posts">';
    
_entries(0);
    echo 
'</div>';
}