paperweb/web/query.inc.php

52 lines
1.7 KiB
PHP

<section id="result">
<?php
if (array_key_exists('doQuery', $_REQUEST)) {
$pattern='/(?<=")(?:[^"]|\\\\")*[^" ](?:[^"]|\\\\")*(?=")|[^ "]+/';
preg_match_all($pattern, $_REQUEST['D'], $matches);
$dates = escapeshellarg(implode('|', $matches[0]));
preg_match_all($pattern, $_REQUEST['L'], $matches);
$labels = escapeshellarg(implode('|', $matches[0]));
preg_match_all($pattern, $_REQUEST['K'], $matches);
$words = escapeshellarg(implode('|', $matches[0]));
$json = exec("sudo -u {$CONF['USER']} {$CONF['PATH']} -Q -d {$dates} -l {$labels} -k {$words} -i");
unset($_REQUEST['doThumbnails']);
unset($_REQUEST['thumbnailsDone']);
unset($_REQUEST['currentDoc']);
} else {
$json = @$_REQUEST['queryDone'];
}
if ($json) {
if ($json == '[]') {
?>
<p>No result.</p>
<?php
} else {
$current = (array_key_exists('doThumbnails', $_REQUEST) ? $_REQUEST['doThumbnails'] : @$_REQUEST['currentDoc']);
?>
<h2>Documents found</h2>
<input type="hidden" name="queryDone" value="<?php echo htmlentities($json, ENT_COMPAT|ENT_XML1); ?>"/>
<?php
foreach (json_decode($json, true) as $doc) {
?>
<button type="submit" name="doThumbnails" value="<?php echo htmlentities($doc['folder'], ENT_COMPAT|ENT_XML1); ?>"<?php
if ($doc['folder'] == $current) {
echo ' disabled="disabled"';
}
?>>
<h3><?php echo preg_replace('/^(....)(..)(..).*$/', '$1-$2-$3', $doc['folder']); ?></h3>
<p><?php echo $doc['count']; ?> pages (<?php echo ($doc['type']=='pdf'?'PDF':'images'); ?>)</p>
<?php if (count($doc['labels'])) { ?>
<ul>
<?php foreach ($doc['labels'] as $lab) { ?>
<li><?php echo htmlentities($lab, ENT_COMPAT|ENT_XML1); ?></li>
<?php } ?>
</ul>
<?php } ?>
</button>
<?php
}
}
}
?>
</section>