function common_network($conf, $item, $vocables)
{
    $final_results = array();
    $item_checked = $item;
    $pdo = connexionbdd($conf);
    //second we take fails checker ip
    $fails = array();
    $sql = "SELECT DISTINCT checker_id, checker_ip FROM results WHERE result!=0 AND item=:item";
    $statement = $pdo->prepare($sql);
    $statement->bindValue(':item', $item);
    if (!$statement->execute()) {
        throw new PDOException();
    }
    $result = $statement->fetchAll(PDO::FETCH_ASSOC);
    foreach ($result as $checker) {
        $fails[] = $checker;
    }
    $statement->closeCursor();
    if (!!$fails) {
        //var_dump($fails);
        //third we take no fails checker ip
        $no_fails = array();
        $sql = "SELECT DISTINCT checker_id, checker_ip FROM results WHERE result=0 AND item=:item";
        $statement = $pdo->prepare($sql);
        $statement->bindValue(':item', $item);
        if (!$statement->execute()) {
            throw new PDOException();
        }
        $result = $statement->fetchAll(PDO::FETCH_ASSOC);
        foreach ($result as $checker) {
            $no_fails[] = $checker;
        }
        $statement->closeCursor();
        //fourth we take lost checker ip
        $lost = array();
        $sql = "SELECT distinct checker_id, checker_ip\n\t\tFROM results \n\t\tWHERE item = :item\n\t\t\t\tand check_timestamp < :dateMinus3000 \n\t\t\t\tand check_timestamp > :dateMinus6000\n\t\t\t\tand checker_ip NOT IN ( select checker_ip from results where item = :item\n\t\t\t\t\t\t\t\t\t\t\tand check_timestamp < :date \n\t\t\t\t\t\t\t\t\t\t\tand  check_timestamp > :dateMinus3000 )";
        $statement = $pdo->prepare($sql);
        $statement->bindValue(':item', $item);
        $statement->bindValue(':dateMinus3000', date('Y-m-d H:i:s', time() - 3000));
        $statement->bindValue(':dateMinus6000', date('Y-m-d H:i:s', time() - 6000));
        $statement->bindValue(':date', date('Y-m-d H:i:s', time()));
        if (!$statement->execute()) {
            throw new PDOException();
        }
        $result = $statement->fetchAll(PDO::FETCH_ASSOC);
        foreach ($result as $checker) {
            $lost[] = $checker;
        }
        $statement->closeCursor();
        //var_dump($lost);
        //calculate common network for checker failed
        $netmask_find = 0;
        $netmask_incr = $conf['maximum_netmask_for_groups'];
        $networks = array();
        //first we search all shortest common network for all ip checker
        //we loop all ip checker who failed
        for ($i = 0; $i < count($fails); $i++) {
            $checker = $fails[$i];
            //we loop again ip checker who failed to compare networks
            for ($j = $i; $j < count($fails); $j++) {
                $checker_to_compare = $fails[$j];
                //if the two ip checker are different
                if ($checker['checker_id'] != $checker_to_compare['checker_id']) {
                    //echo "<p>".netmask($checker['checker_ip'],$netmask_incr)."</p>";
                    //we look for the shortest common network between the two ips
                    while ($netmask_find == 0 and $netmask_incr >= $conf['minimum_netmask_for_groups']) {
                        if (netmask($checker['checker_ip'], $netmask_incr) == netmask($checker_to_compare['checker_ip'], $netmask_incr)) {
                            $netmask_find = $netmask_incr;
                        }
                        $netmask_incr--;
                    }
                    //if the networks exists in the array, we only add the ip checker to compare to the network key
                    if (array_key_exists(netmask($checker['checker_ip'], $netmask_find) . "/" . $netmask_find, $networks)) {
                        $networks[netmask($checker['checker_ip'], $netmask_find) . "/" . $netmask_find][] = $checker_to_compare['checker_ip'];
                    } else {
                        // else we add a new key entry ( network ) in the array adding the two ips to compare
                        $networks[netmask($checker['checker_ip'], $netmask_find) . "/" . $netmask_find] = array($checker['checker_ip'], $checker_to_compare['checker_ip']);
                    }
                }
            }
        }
        //then we look for ip checker who doesn't failed to throw networks away if only one hasn't failed
        $networks_exclusiv = $networks;
        foreach ($networks as $network => $ip_checkers) {
            $network_has_non_fails = false;
            $i = 0;
            while ($i < count($no_fails) and !$network_has_non_fails) {
                $netmask = split("/", $network);
                if ($netmask[0] == netmask($no_fails[$i], $netmask[1])) {
                    $network_has_non_fails = true;
                }
                $i++;
            }
            if ($network_has_non_fails) {
                array_splice($networks_exclusiv, $network, 1);
            }
        }
        $networks_for_display = array();
        foreach ($networks_exclusiv as $network => $ips) {
            echo $network;
            $networks_for_display[] = array('nb_f_network' => count($ips), 'network' => fromIpnetToNetwork($network));
        }
        $nb_all = count($fails) + count($no_fails);
        if (count($networks_for_display) > 0 && $conf['active_logstalgia'] == 1) {
            $final_results[] = array('factors' => $networks_for_display, 'type_of_checker' => 'failed');
            foreach ($networks_for_display as $network) {
                $item_log_explode = explode(":", $item_checked);
                $size = $network['nb_f_network'] * 100 / $nb_all * $conf['size_super_ball'];
                $item_log = time() . "|" . $network['network'] . "|" . $item_log_explode[0] . "|" . "Fail" . "|" . $size . "|" . "0" . "|" . "FF0000" . "\n";
                file_put_contents($conf['directory_tmp'] . "logstalgia.txt", $item_log, FILE_APPEND);
            }
        }
        $result_final = array('networks' => $networks_for_display, 'nb_all' => $nb_all);
        //calculate common network for checker lost
        $netmask_find = 0;
        $netmask_incr = $conf['maximum_netmask_for_groups'];
        $networks = array();
        //first we search all shortest common network for all ip checker
        for ($i = 0; $i < count($fails); $i++) {
            $checker = $fails[$i];
            //we loop again ip checker who failed to compare networks
            for ($j = $i; $j < count($fails); $j++) {
                $checker_to_compare = $fails[$j];
                //if the two ip checker are different
                if ($checker['checker_ip'] != $checker_to_compare['checker_ip']) {
                    //we look for the shortest common network between the two ips
                    while ($netmask_find == 0 and $netmask_incr >= $conf['minimum_netmask_for_groups']) {
                        if (netmask($checker['checker_ip'], $netmask_incr) == netmask($checker_to_compare['checker_ip'], $netmask_incr)) {
                            $netmask_find = $netmask_incr;
                        }
                        $netmask_incr--;
                    }
                    //if the networks exists in the array, we only add the ip checker to compare to the network key
                    if (array_key_exists(netmask($checker['checker_ip'], $netmask_find) . "/" . $netmask_find, $networks)) {
                        $networks[netmask($checker['checker_ip'], $netmask_find) . "/" . $netmask_find][] = $checker_to_compare['checker_ip'];
                    } else {
                        // else we add a new key entry ( network ) in the array adding the two ips to compare
                        $networks[netmask($checker['checker_ip'], $netmask_find) . "/" . $netmask_find] = array($checker['checker_ip'], $checker_to_compare['checker_ip']);
                    }
                }
            }
        }
        //then we look for ip checker who doesn't failed to throw networks away if only one hasn't failed
        $networks_exclusiv_lost = $networks;
        foreach ($networks as $network => $ip_checkers) {
            $network_has_non_fails = false;
            $i = 0;
            while ($i < count($no_fails) and !$network_has_non_fails) {
                $netmask = split("/", $network);
                if ($netmask[0] == netmask($no_fails[$i], $netmask[1])) {
                    $network_has_non_fails = true;
                }
                $i++;
            }
            if ($network_has_non_fails) {
                array_splice($networks_exclusiv_lost, array_search($network, $networks_exclusiv_lost), 1);
            }
            $network_has_fails = false;
            $i = 0;
            while ($i < count($fails) and !$network_has_fails) {
                $netmask = split("/", $network);
                if ($netmask[0] == netmask($fails[$i]["checker_ip"], $netmask[1])) {
                    $network_has_fails = true;
                }
                $i++;
            }
            if ($network_has_fails) {
                array_splice($networks_exclusiv_lost, array_search($network, $networks_exclusiv_lost), 1);
            }
        }
        $networks_for_display_lost = array();
        foreach ($networks_exclusiv_lost as $network => $ips) {
            $networks_for_display_lost[] = array('nb_f_network' => count($ips), 'network' => fromIpnetToNetwork($network));
        }
        if (count($networks_for_display_lost) > 0 && $conf['active_logstalgia'] == 1) {
            $final_results[] = array('factors' => $networks_for_display_lost, 'type_of_checker' => 'lost');
            foreach ($networks_for_display_lost as $network) {
                $item_log_explode = explode(":", $item_checked);
                $size = $network['nb_f_network'] * 100 / $nb_all * $conf['size_super_ball'];
                $item_log = time() . "|" . $network['network'] . "|" . $item_log_explode[0] . "|" . "Fail" . "|" . $size . "|" . "0" . "|" . "FF0000" . "\n";
                file_put_contents($conf['directory_tmp'] . "logstalgia.txt", $item_log, FILE_APPEND);
            }
        }
    }
    return $final_results;
}
function common_network($conf, $item_md5)
{
    //it first connects to the database
    $pdo = connexionbdd($conf);
    //it retrieves the edge of the item of information
    $sql = "SELECT item from global_result WHERE md5='" . $item_md5 . "'";
    $statement = $pdo->prepare($sql);
    $statement->bindValue(':md5', $item_md5);
    if (!$statement->execute()) {
        throw new PDOException();
    }
    $result = $statement->fetch(PDO::FETCH_ASSOC);
    $item = $result['item'];
    $statement->closeCursor();
    //second we take fails checker ip
    $fails = array();
    $sql = "SELECT DISTINCT checker_id, checker_ip FROM results WHERE result!=0 AND item=:item";
    $statement = $pdo->prepare($sql);
    $statement->bindValue(':item', $item);
    if (!$statement->execute()) {
        throw new PDOException();
    }
    $result = $statement->fetchAll(PDO::FETCH_ASSOC);
    foreach ($result as $checker) {
        $fails[] = $checker;
    }
    $statement->closeCursor();
    //var_dump($fails);
    //third we take no fails checker ip
    $no_fails = array();
    $sql = "SELECT DISTINCT checker_id, checker_ip FROM results WHERE result=0 AND item='" . $item . "'";
    $statement = $pdo->prepare($sql);
    $statement->bindValue(':item', $item);
    if (!$statement->execute()) {
        throw new PDOException();
    }
    $result = $statement->fetchAll(PDO::FETCH_ASSOC);
    foreach ($result as $checker) {
        $no_fails[] = $checker;
    }
    $statement->closeCursor();
    //calculate common network for checker failed
    $netmask_find = 0;
    $netmask_incr = $conf['maximum_netmask_for_groups'];
    $networks = array();
    //first we search all shortest common network for all ip checker
    //we loop all ip checker who failed
    for ($i = 0; $i < count($fails); $i++) {
        $checker = $fails[$i];
        //we loop again ip checker who failed to compare networks
        for ($j = $i; $j < count($fails); $j++) {
            $checker_to_compare = $fails[$j];
            //if the two ip checker are different
            if ($checker['checker_id'] != $checker_to_compare['checker_id']) {
                //we look for the shortest common network between the two ips
                while ($netmask_find == 0 and $netmask_incr >= $conf['minimum_netmask_for_groups']) {
                    if (netmask($checker['checker_ip'], $netmask_incr) == netmask($checker_to_compare['checker_ip'], $netmask_incr)) {
                        $netmask_find = $netmask_incr;
                    }
                    $netmask_incr--;
                }
                //if the networks exists in the array, we only add the ip checker to compare to the network key
                if (array_key_exists(netmask($checker['checker_ip'], $netmask_find) . "/" . $netmask_find, $networks)) {
                    $networks[netmask($checker['checker_ip'], $netmask_find) . "/" . $netmask_find][] = $checker_to_compare['checker_ip'];
                } else {
                    // else we add a new key entry ( network ) in the array adding the two ips to compare
                    $networks[netmask($checker['checker_ip'], $netmask_find) . "/" . $netmask_find] = array($checker['checker_ip'], $checker_to_compare['checker_ip']);
                }
            }
        }
    }
    //then we look for ip checker who doesn't failed to throw networks away if only one hasn't failed
    $networks_exclusiv = $networks;
    foreach ($networks as $network => $ip_checkers) {
        $network_has_non_fails = false;
        $i = 0;
        while ($i < count($no_fails) and !$network_has_non_fails) {
            $netmask = split("/", $network);
            if ($netmask[0] == netmask($no_fails[$i], $netmask[1])) {
                $network_has_non_fails = true;
            }
            $i++;
        }
        if ($network_has_non_fails) {
            array_splice($networks_exclusiv, $network, 1);
        }
    }
    $networks_for_display = array();
    foreach ($networks_exclusiv as $network => $ips) {
        $networks_for_display[] = array('nb_f_network' => count($ips), 'network' => fromIpnetToNetwork($network));
    }
    $nb_target = array();
    $nb_rest = array();
    if (count($fails) < count($no_fails)) {
        $nb_target = array_values($fails);
        $nb_rest = array_values($no_fails);
    } else {
        $nb_target = array_values($no_fails);
        $nb_rest = array_values($fails);
    }
    foreach ($nb_rest as $checker) {
        $i = 0;
        while ($i < count($nb_target) && $checker['checker_id'] !== $nb_target[$i]['checker_id']) {
            $i++;
        }
        if ($i < count($nb_rest)) {
            $nb_target[] = $checker;
        }
    }
    $nb_all = count($nb_target);
    $result_final = $networks_for_display;
    return $result_final;
}