<div id="paper-list" class="box box-full"><h2>Paper List</h2><?php 
$paper = json_decode(file_exists("config/paper.json") ? file_get_contents("config/paper.json") : '{}');
$del = Get_Values('delete');
$add = Get_Values('add');
$N_width = Get_Values('width');
$N_height = Get_Values('height');
if ($N_height == null && $N_width == null) {
    $N_width = Get_Values('Mwidth');
    $N_height = Get_Values('Mheight');
    $metric = true;
} else {
    $metric = false;
}
if ($del != null) {
    if (isset($paper->{$del})) {
        unset($paper->{$del});
    }
}
if ($add != null && $N_width != null && $N_height != null) {
    if (!isset($paper->{$add}) && is_numeric($N_width) && is_numeric($N_height)) {
        if ($N_width <= 0 || $N_height <= 0) {
            $message = true;
        } else {
            if ($metric) {
                $N_width = $N_width / 25.4;
                $N_height = $N_height / 25.4;
            }
            if ($N_width > $N_height) {
                $tmp = $N_height;
                $N_height = $N_width;
                $N_width = $tmp;
         if (is_null($t)) {
             $t = Get_Values('y') * 31557600 + Get_Values('d') * 86400 + Get_Values('h') * 3600 + Get_Values('m') * 60 + Get_Values('s');
         } else {
             $t = $time - $t;
         }
         $human = ageSeconds2Human($t);
         $time = $time - $t;
         Print_Message('Notice', 'Only displaying files ' . ($filter === 2 ? 'newer' : 'older') . " than {$human}<br/>" . "Here is a fixed <a href=\"index.php?page={$PAGE}&amp;filter={$filter}&amp;t={$time}\">link</a> you can save.", 'center');
     } else {
         $T2 = Get_Values('T2');
         if (is_null($T2)) {
             $t2 = Get_Values('t2');
             $t1 = Get_Values('t1');
         } else {
             $t2 = $time - $T2;
             $t1 = $time - Get_Values('T1');
         }
         $time = array($time - $t1, $time - $t2);
         Print_Message('Notice', 'Only displaying files newer than ' . ageSeconds2Human($t2) . '<br/>and older than ' . ageSeconds2Human($t1) . '<br/>' . 'Here is a fixed <a href="index.php?page=Scans&amp;filter=3&amp;T2=' . $time[1] . '&amp;T1=' . $time[0] . '">link</a> you can save.', 'center');
     }
 }
 for ($i = 0, $max = count($FILES); $i < $max; $i++) {
     $FILE = $FILES[$i];
     if (isset($time)) {
         if ($filter === 2) {
             if (filemtime("scans/thumb/{$FILE}") < $time) {
                 continue;
             }
         } else {
             if ($filter === 1) {
                 if (filemtime("scans/thumb/{$FILE}") > $time) {
 if (!is_null($CANNERS[$SCANNER]->{"UUID"})) {
     // Bug #13
     $DEVICE2 = uuid2bus($CANNERS[$SCANNER]);
     $CANNERS[$SCANNER]->{"DEVICE"} = $DEVICE2;
     $DEVICE = shell($DEVICE2);
 }
 $cmd = "scanimage -d {$DEVICE} {$OURCE}-l {$X} -t {$Y} -x {$SIZE_X} -y {$SIZE_Y} {$DUPLEX}--resolution {$QUALITY} --mode " . shell($MODE) . " {$LAMP}--format={$RAW}";
 if ($SOURCE == 'ADF' || $SOURCE == 'Automatic Document Feeder') {
     # Multi-page scan
     exe("cd {$CANDIR};{$cmd} --batch", true);
 } else {
     # Single page scan
     exe("{$cmd} > " . shell("{$CANDIR}/scan_file{$SCANNER}.{$RAW}"), false);
 }
 if (file_exists("{$CANDIR}/scan_file{$SCANNER}.{$RAW}")) {
     if (Get_Values('size') == 'full' && filesize("{$CANDIR}/scan_file{$SCANNER}.{$RAW}") == 0) {
         exe("echo 'Scan Failed...'", true);
         exe("echo 'Maybe this scanner does not report it size correctly, maybe the default scan size will work it may or may not be a full scan.'", true);
         exe("echo 'If it is not a full scan you are welcome to manually edit your {$here}/config/scanners.json file with the correct size.'", true);
         @unlink("{$CANDIR}/scan_file{$SCANNER}.{$RAW}");
         exe("echo 'Attempting to scan without forcing full scan'", true);
         exe("scanimage -d {$DEVICE} --resolution {$QUALITY} --mode " . shell($MODE) . " {$LAMP}--format={$RAW} > " . shell("{$CANDIR}/scan_file{$SCANNER}.{$RAW}"), false);
     }
 }
 if (count($CANNERS) > 1 && isset($DEVICE2)) {
     $CANNERS = json_decode(file_get_contents("config/scanners.json"));
     $CANNERS[$SCANNER]->{"DEVICE"} = $DEVICE2;
     // See bug 13
 }
 $CANNERS[$SCANNER]->{"INUSE"} = 0;
 SaveFile("config/scanners.json", json_encode($CANNERS));