<commit_before><?php
include("res/bibliodb.php");
if(isset($_POST['user'])&&isset($_POST['password'])){
    $database = new PDO('sqlite:bibliodb.sqlite');
    $database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $qry='SELECT * FROM Utenti WHERE Utente = :u';
    $stmt = $database->prepare($qry);
    $stmt->bindParam(':u',$_POST["user"]);
    $stmt->execute();
    $utenti=$stmt->fetchAll(PDO::FETCH_ASSOC);
    if(count($utenti)==1){
        if($utenti[0]["Master"]=="1"){
            if(password_verify($_POST["password"],$utenti[0]["Password"])){
				$qry='INSERT INTO Sessioni VALUES (:token, :ip, :scadenza, :utente)';
                $token=strval(uniqid("sess"));
                $scadenza=date("Y-m-d H:i:s",time()+860);
                $ip=$_SERVER['REMOTE_ADDR'];
				$stmt = $database->prepare($qry);
                $stmt->bindParam(':token',$token);
                $stmt->bindParam(':ip',$ip);
                $stmt->bindParam(':scadenza',$scadenza);
                $stmt->bindParam(':utente',$_POST["user"]);
				$stmt->execute();
                setcookie("token",$token, time()+860);
                header("Location: mgr.php");
            }
            else{
                header("Location: index.php?error=Password+errata");
            }
        }
        else{
            header("Location: index.php?error=Utente+non+autorizzato&mode=login");
        }
    }
    else{
        header("Location: index.php?error=Utente+inesistente&mode=login");
    }
    die();
}
$loggedIn=false;
if(isset($_COOKIE['token'])){
    $database = new PDO('sqlite:bibliodb.sqlite');
    $database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $qry='SELECT * FROM Sessioni WHERE Token = :tk';
    $stmt = $database->prepare($qry);
    $stmt->bindParam(':tk',$_COOKIE['token']);
    $stmt->execute();
    $sess=$stmt->fetchAll(PDO::FETCH_ASSOC)[0];
    if(date_timestamp_get(date_create_from_format("Y-m-d H:i:s",$sess["Scadenza"]))>time()){
        $qry='SELECT * FROM Utenti WHERE Utente = :u';
        $stmt = $database->prepare($qry);
        $stmt->bindParam(':u',$sess["Utente"]);
        $stmt->execute();
        $role=$stmt->fetchAll(PDO::FETCH_ASSOC)[0]["Master"];
        if($role=="1"){
            if($_SERVER['REMOTE_ADDR']==$sess["IP"]){
                $loggedIn=true;
                //Prolungare la durata della sessione
            }
            else{
                header("Location: index.php?error=Login+fallito&mode=login");
            }
        }
        else{
            header("Location: index.php?error=Non+autorizzato&mode=login");
        }
    }
    else{
        header("Location: index.php?error=Sessione+scaduta&mode=login");
    }
}
else{
    header("Location: index.php#login");
    die();
}
?>
<html>
    <head>
    <meta charset="utf-8">
    <title>
        BiblioDB Manager
    </title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <!-- For non-Retina (@1× display) iPhone, iPod Touch, and Android 2.1+ devices: -->
    <link rel="apple-touch-icon" href="apple-touch-icon.png"><!-- 57×57px -->
    <!-- For the iPad mini and the first- and second-generation iPad (@1× display) on iOS = 6: -->
    <link rel="apple-touch-icon" sizes="72x72" href="apple-touch-icon-72x72.png">
    <!-- For the iPad mini and the first- and second-generation iPad (@1× display) on iOS = 7: -->
    <link rel="apple-touch-icon" sizes="76x76" href="apple-touch-icon-76x76.png">
    <!-- For iPhone with @2× display running iOS = 6: -->
    <link rel="apple-touch-icon" sizes="114x114" href="apple-touch-icon-114x114.png">
    <!-- For iPhone with @2× display running iOS = 7: -->
    <link rel="apple-touch-icon" sizes="120x120" href="apple-touch-icon-120x120.png">
    <!-- For iPad with @2× display running iOS = 6: -->
    <link rel="apple-touch-icon" sizes="144x144" href="apple-touch-icon-144x144.png">
    <!-- For iPad with @2× display running iOS = 7: -->
    <link rel="apple-touch-icon" sizes="152x152" href="apple-touch-icon-152x152.png">
    <!-- For iPhone 6 Plus with @3× display: -->
    <link rel="apple-touch-icon" sizes="180x180" href="apple-touch-icon-180x180.png">
    <link rel="icon" href="favicon.ico">
    <link rel="stylesheet" href="css/jquery.mobile-1.4.5.min.css" />
    <script src="js/jquery-1.11.1.min.js"></script>
    <script type="text/javascript">
     $(document).bind("mobileinit", function () {
         $.mobile.ajaxEnabled = false;
     });
    </script>
    <script src="js/jquery.mobile-1.4.5.min.js"></script>
    <script src="js/sha512.js"></script>
    <script src="js/bibliodb.js"></script>
    <style type="text/css">
    td{
        max-width: 33%;
    }
    img{
        max-height: 10em;
        /*max-width: 33%*/
        min-width: 2em;
     }
     .nascosto{
         display:none;
     }
    </style>
    </head>
    <body>
    <div data-role="page" data-control-title="Home" id="page1"><?php if($loggedIn){ echo'
        <div data-role="panel" id="panel1" data-position="left" data-display="reveal"
        data-theme="a">
        <ul data-role="listview" data-divider-theme="h" data-inset="false">
            <li data-role="list-divider" role="heading">
                BiblioDB Manager
            </li>
                <!--li data-theme="a">
                    <a href="javascript:void(0);" data-transition="slide">
                        Aggiungi titolo
                    </a>
                </li>
                <li data-theme="a">
                    <a href="javascript:void(0);" data-transition="slide">
                        Presta titolo
                    </a>
                </li>
                <li data-theme="a">
                    <a href="javascript:void(0);" data-transition="slide">
                        Aggiungi Utente
                    </a>
                </li-->
                <li data-theme="a">
                    <a href="?mode=scatola" data-transition="slide">
                        Sposta posizione
                    </a>
                </li>
                <li data-theme="a">
                    <a href="?mode=modifica" data-transition="slide">
                        Modifica voce
                    </a>
                </li>
                <li data-theme="a">
                    <a href="?mode=lbif" data-transition="slide">
                        Importazione file LBIF
                    </a>
                </li>
                <li data-theme="a">
                    <a href="?mode=deduplbif" data-transition="slide">
                        Rimozione duplicati
                    </a>
                </li>
                <li data-theme="a">
                    <a href="logout.php" data-transition="slide">
                        Esci
                    </a>
                </li>
            </ul>
        </div>';}?>
        <div data-theme="a" data-role="header" data-position="fixed"><?php if($loggedIn){ echo'
            <div id="menubutton">
                <a data-controltype="panelbutton" data-role="button" href="#panel1" data-icon="bars" data-iconpos="left" class="ui-btn-left">
                    Menù
                </a>
            </div>';}?>
        <h3>
            BiblioDB Manager
        </h3>
        </div>
        <div data-role="content">
        <?php
        $database = new PDO('sqlite:bibliodb.sqlite');
        if(isset($_POST['mode'])&&$_POST['mode']=='edit'){<commit_msg>Aggiunta funzionalità di rimozione duplicati<commit_after><?php
include("res/bibliodb.php");
if(isset($_POST['user'])&&isset($_POST['password'])){
    $database = new PDO('sqlite:bibliodb.sqlite');
    $database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $qry='SELECT * FROM Utenti WHERE Utente = :u';
    $stmt = $database->prepare($qry);
    $stmt->bindParam(':u',$_POST["user"]);
    $stmt->execute();
    $utenti=$stmt->fetchAll(PDO::FETCH_ASSOC);
    if(count($utenti)==1){
        if($utenti[0]["Master"]=="1"){
            if(password_verify($_POST["password"],$utenti[0]["Password"])){
				$qry='INSERT INTO Sessioni VALUES (:token, :ip, :scadenza, :utente)';
                $token=strval(uniqid("sess"));
                $scadenza=date("Y-m-d H:i:s",time()+860);
                $ip=$_SERVER['REMOTE_ADDR'];
				$stmt = $database->prepare($qry);
                $stmt->bindParam(':token',$token);
                $stmt->bindParam(':ip',$ip);
                $stmt->bindParam(':scadenza',$scadenza);
                $stmt->bindParam(':utente',$_POST["user"]);
				$stmt->execute();
                setcookie("token",$token, time()+860);
                header("Location: mgr.php");
            }
            else{
                header("Location: index.php?error=Password+errata");
            }
        }
        else{
            header("Location: index.php?error=Utente+non+autorizzato&mode=login");
        }
    }
    else{
        header("Location: index.php?error=Utente+inesistente&mode=login");
    }
    die();
}
$loggedIn=false;
if(isset($_COOKIE['token'])){
    $database = new PDO('sqlite:bibliodb.sqlite');
    $database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $qry='SELECT * FROM Sessioni WHERE Token = :tk';
    $stmt = $database->prepare($qry);
    $stmt->bindParam(':tk',$_COOKIE['token']);
    $stmt->execute();
    $sess=$stmt->fetchAll(PDO::FETCH_ASSOC)[0];
    if(date_timestamp_get(date_create_from_format("Y-m-d H:i:s",$sess["Scadenza"]))>time()){
        $qry='SELECT * FROM Utenti WHERE Utente = :u';
        $stmt = $database->prepare($qry);
        $stmt->bindParam(':u',$sess["Utente"]);
        $stmt->execute();
        $role=$stmt->fetchAll(PDO::FETCH_ASSOC)[0]["Master"];
        if($role=="1"){
            if($_SERVER['REMOTE_ADDR']==$sess["IP"]){
                $loggedIn=true;
                //Prolungare la durata della sessione
            }
            else{
                header("Location: index.php?error=Login+fallito&mode=login");
            }
        }
        else{
            header("Location: index.php?error=Non+autorizzato&mode=login");
        }
    }
    else{
        header("Location: index.php?error=Sessione+scaduta&mode=login");
    }
}
else{
    header("Location: index.php#login");
    die();
}
?>
<html>
    <head>
    <meta charset="utf-8">
    <title>
        BiblioDB Manager
    </title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <!-- For non-Retina (@1× display) iPhone, iPod Touch, and Android 2.1+ devices: -->
    <link rel="apple-touch-icon" href="apple-touch-icon.png"><!-- 57×57px -->
    <!-- For the iPad mini and the first- and second-generation iPad (@1× display) on iOS = 6: -->
    <link rel="apple-touch-icon" sizes="72x72" href="apple-touch-icon-72x72.png">
    <!-- For the iPad mini and the first- and second-generation iPad (@1× display) on iOS = 7: -->
    <link rel="apple-touch-icon" sizes="76x76" href="apple-touch-icon-76x76.png">
    <!-- For iPhone with @2× display running iOS = 6: -->
    <link rel="apple-touch-icon" sizes="114x114" href="apple-touch-icon-114x114.png">
    <!-- For iPhone with @2× display running iOS = 7: -->
    <link rel="apple-touch-icon" sizes="120x120" href="apple-touch-icon-120x120.png">
    <!-- For iPad with @2× display running iOS = 6: -->
    <link rel="apple-touch-icon" sizes="144x144" href="apple-touch-icon-144x144.png">
    <!-- For iPad with @2× display running iOS = 7: -->
    <link rel="apple-touch-icon" sizes="152x152" href="apple-touch-icon-152x152.png">
    <!-- For iPhone 6 Plus with @3× display: -->
    <link rel="apple-touch-icon" sizes="180x180" href="apple-touch-icon-180x180.png">
    <link rel="icon" href="favicon.ico">
    <link rel="stylesheet" href="css/jquery.mobile-1.4.5.min.css" />
    <script src="js/jquery-1.11.1.min.js"></script>
    <script type="text/javascript">
     $(document).bind("mobileinit", function () {
         $.mobile.ajaxEnabled = false;
     });
    </script>
    <script src="js/jquery.mobile-1.4.5.min.js"></script>
    <script src="js/sha512.js"></script>
    <script src="js/bibliodb.js"></script>
    <style type="text/css">
    td{
        max-width: 33%;
    }
    img{
        max-height: 10em;
        /*max-width: 33%*/
        min-width: 2em;
     }
     .nascosto{
         display:none;
     }
    </style>
    </head>
    <body>
    <div data-role="page" data-control-title="Home" id="page1"><?php if($loggedIn){ echo'
        <div data-role="panel" id="panel1" data-position="left" data-display="reveal"
        data-theme="a">
        <ul data-role="listview" data-divider-theme="h" data-inset="false">
            <li data-role="list-divider" role="heading">
                BiblioDB Manager
            </li>
                <!--li data-theme="a">
                    <a href="javascript:void(0);" data-transition="slide">
                        Aggiungi titolo
                    </a>
                </li>
                <li data-theme="a">
                    <a href="javascript:void(0);" data-transition="slide">
                        Presta titolo
                    </a>
                </li>
                <li data-theme="a">
                    <a href="javascript:void(0);" data-transition="slide">
                        Aggiungi Utente
                    </a>
                </li-->
                <li data-theme="a">
                    <a href="?mode=scatola" data-transition="slide">
                        Sposta posizione
                    </a>
                </li>
                <li data-theme="a">
                    <a href="?mode=modifica" data-transition="slide">
                        Modifica voce
                    </a>
                </li>
                <li data-theme="a">
                    <a href="?mode=lbif" data-transition="slide">
                        Importazione file LBIF
                    </a>
                </li>
                <li data-theme="a">
                    <a href="?mode=dedup" data-transition="slide">
                        Rimozione duplicati
                    </a>
                </li>
                <li data-theme="a">
                    <a href="logout.php" data-transition="slide">
                        Esci
                    </a>
                </li>
            </ul>
        </div>';}?>
        <div data-theme="a" data-role="header" data-position="fixed"><?php if($loggedIn){ echo'
            <div id="menubutton">
                <a data-controltype="panelbutton" data-role="button" href="#panel1" data-icon="bars" data-iconpos="left" class="ui-btn-left">
                    Menù
                </a>
            </div>';}?>
        <h3>
            BiblioDB Manager
        </h3>
        </div>
        <div data-role="content">
        <?php
        $database = new PDO('sqlite:bibliodb.sqlite');
        if(isset($_POST['mode'])&&$_POST['mode']=='edit'){
{'fraction_non_alphanumeric': 0.18271833124298634, 'fraction_numerical': 0.018483068189319427, 'mean_word_length': 2.0065489184361978, 'pattern_counts': {'":': 0, '<': 189, '<?xml version=': 0, '>': 229, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '427517', 'n_tokens_mistral': 5084, 'n_tokens_neox': 4770, 'n_words': 805}