initial commit
This commit is contained in:
		
							
								
								
									
										10
									
								
								web/errors.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								web/errors.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,10 @@
 | 
			
		||||
<?php
 | 
			
		||||
    include ('template.inc');
 | 
			
		||||
    ob_start();
 | 
			
		||||
    $l = file_get_contents("../data/isbn-error.txt");
 | 
			
		||||
    print "<pre>";
 | 
			
		||||
        print_r($l);
 | 
			
		||||
    print "</pre>";
 | 
			
		||||
    $output = ob_get_clean();
 | 
			
		||||
    Template::render( $output);
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										46
									
								
								web/index.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								web/index.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
			
		||||
<?php
 | 
			
		||||
    include ('template.inc');
 | 
			
		||||
    $rets = ['OK'=>'OK', 'ERROR'=>'ERROR'];
 | 
			
		||||
 | 
			
		||||
    ob_start();
 | 
			
		||||
    print "<h2>Book ID input</h2>";
 | 
			
		||||
    print "<div class='isbn-input'>";
 | 
			
		||||
    print '<form action="/scan.php" method="POST">';
 | 
			
		||||
    print '<dl>';
 | 
			
		||||
        print '<h3>ID type</h3>';
 | 
			
		||||
        print '<input type="radio" id="isbn" name="idtype" value="isbn" checked="checked">';
 | 
			
		||||
        print '<label for="isbn">ISBN</label><br>';
 | 
			
		||||
        print '<input type="radio" id="moly" name="idtype" value="moly">';
 | 
			
		||||
        print '<label for="moly">Moly.hu</label><br>';
 | 
			
		||||
    print '</dl>';
 | 
			
		||||
    print '<label for="content">ID:</label>';
 | 
			
		||||
    print '<input type="text" id="isbn-content" name="content" inputmode="tel" autofocus>';
 | 
			
		||||
    print '<input type="hidden" id="manual" name="manual" value="1">';
 | 
			
		||||
    print '<input class="hidden" type="submit" value="Submit">';
 | 
			
		||||
    print '</form>';
 | 
			
		||||
    if (isset ($_GET['ret'])){
 | 
			
		||||
        if (array_key_exists($_GET['ret'],$rets)){
 | 
			
		||||
            $r = $rets[$_GET['ret']];
 | 
			
		||||
            print "<p class='retek $r'>$r</p>";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    print "</div>";
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    print "<h2>Errors</h2>";
 | 
			
		||||
    print "<div class='errors'>".errors()."</div>";
 | 
			
		||||
 | 
			
		||||
    $output = ob_get_clean();
 | 
			
		||||
    Template::render($output);
 | 
			
		||||
 | 
			
		||||
    function errors(){
 | 
			
		||||
        ob_start();
 | 
			
		||||
        $a = file("../data/isbn-error.txt");
 | 
			
		||||
        $r = array_reverse($a);
 | 
			
		||||
        print "<pre>";
 | 
			
		||||
        foreach ($r as $l){
 | 
			
		||||
            print($l);
 | 
			
		||||
        }
 | 
			
		||||
        print "</pre>";
 | 
			
		||||
        return ob_get_clean();
 | 
			
		||||
    }
 | 
			
		||||
							
								
								
									
										17
									
								
								web/scan.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								web/scan.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
<?php
 | 
			
		||||
    include_once('template.inc');
 | 
			
		||||
    include_once ('store.inc');
 | 
			
		||||
 | 
			
		||||
    if (isset($_POST['content'])){
 | 
			
		||||
        $m = isset($_POST['manual']);
 | 
			
		||||
        if (isset($_POST['idtype']) && $_POST['idtype'] === 'moly'){
 | 
			
		||||
            StoreMoly::save($_POST['content'],$m);
 | 
			
		||||
        } else{
 | 
			
		||||
        Store::save($_POST['content'],$m);
 | 
			
		||||
        }
 | 
			
		||||
    }else {
 | 
			
		||||
        header("Location: /index.php");
 | 
			
		||||
        exit();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										51
									
								
								web/store.inc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								web/store.inc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,51 @@
 | 
			
		||||
<?php
 | 
			
		||||
include ('../vendor/autoload.php');
 | 
			
		||||
 | 
			
		||||
use Biblys\Isbn\Isbn;
 | 
			
		||||
 | 
			
		||||
class Store{
 | 
			
		||||
    const DATAFILE = '/opt/konyvleltar/data/isbn.txt';
 | 
			
		||||
    const ERRORFILE = '/opt/konyvleltar/data/isbn-error.txt';
 | 
			
		||||
 | 
			
		||||
    public static function save($v,$manual=false){
 | 
			
		||||
        if (Isbn::isParsable($v)){
 | 
			
		||||
            $outputfile = self::DATAFILE;
 | 
			
		||||
            $ret = 'OK';
 | 
			
		||||
        }else{
 | 
			
		||||
            $outputfile = self::ERRORFILE;
 | 
			
		||||
            $ret = 'ERROR';
 | 
			
		||||
        }
 | 
			
		||||
        $o = self::sanitize($v);
 | 
			
		||||
        file_put_contents($outputfile,$o."\n",FILE_APPEND); 
 | 
			
		||||
 | 
			
		||||
        if ($manual) { header("Location: /index.php?ret=$ret");}
 | 
			
		||||
        else { print $ret;}
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static function sanitize($string){
 | 
			
		||||
        $sx = preg_replace("/\.$/", "X", $string);
 | 
			
		||||
        return preg_replace("/[^a-zA-Z0-9-]/", "", $sx);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class StoreMoly extends Store{
 | 
			
		||||
    const DATAFILE = '/opt/konyvleltar/data/moly.txt';
 | 
			
		||||
    const ERRORFILE = '/opt/konyvleltar/data/moly-error.txt';
 | 
			
		||||
 | 
			
		||||
    public static function save($v,$manual=false){
 | 
			
		||||
        $outputfile = self::DATAFILE;
 | 
			
		||||
        $ret = 'OK';
 | 
			
		||||
        $o = self::sanitize($v);
 | 
			
		||||
 | 
			
		||||
        file_put_contents($outputfile,$o."\n",FILE_APPEND); 
 | 
			
		||||
 | 
			
		||||
        if ($manual) { header("Location: /index.php?ret=$ret");}
 | 
			
		||||
        else { print $ret;}
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static function sanitize($string){
 | 
			
		||||
        $sx = preg_replace("/\.$/", "X", $string);
 | 
			
		||||
        return preg_replace("/[^a-zA-Z0-9-]/", "", $sx);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										28
									
								
								web/template.inc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								web/template.inc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
class Template{
 | 
			
		||||
    public static function render($content){
 | 
			
		||||
        print "<!DOCTYPE html>";
 | 
			
		||||
        print "<html>";
 | 
			
		||||
        print " <head>";
 | 
			
		||||
        print '  <meta name="viewport" content="width=device-width, initial-scale=1.0">';
 | 
			
		||||
        print '  <style>
 | 
			
		||||
            .errors{
 | 
			
		||||
                width: 100%;
 | 
			
		||||
            }
 | 
			
		||||
            .ERROR{
 | 
			
		||||
                background-color: #FAA;
 | 
			
		||||
            }
 | 
			
		||||
            .OK{
 | 
			
		||||
                background-color: #AFA;
 | 
			
		||||
            }
 | 
			
		||||
        </style';
 | 
			
		||||
        print " </head>";
 | 
			
		||||
        print " <body>";
 | 
			
		||||
        print $content;
 | 
			
		||||
        print " </body>";
 | 
			
		||||
        print "</html>";
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
		Reference in New Issue
	
	Block a user