Пример #1
0
function SearchComputers()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $sock = new sockets();
    $EnableIntelCeleron = intval($sock->GET_INFO("EnableIntelCeleron"));
    $q = new mysql();
    $sock = new sockets();
    $fontsize = "14px";
    $cs = 0;
    $page = 1;
    if (!$q->DATABASE_EXISTS("ocsweb")) {
        $sock->getFrameWork("services.php?mysql-ocs=yes");
    }
    if (!$q->TABLE_EXISTS("hardware", "ocsweb")) {
        $sock->getFrameWork("services.php?mysql-ocs=yes");
    }
    if (!$q->TABLE_EXISTS("networks", "ocsweb", true)) {
        $sock->getFrameWork("services.php?mysql-ocs=yes");
    }
    if (!$q->FIELD_EXISTS("networks", "isActive", "ocsweb")) {
        $q->QUERY_SQL("ALTER TABLE `networks` ADD `isActive` SMALLINT( 1 ) NOT NULL DEFAULT '0',ADD INDEX ( `isActive` ) ", "ocsweb");
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $table = "(SELECT networks.HARDWARE_ID,networks.MACADDR,networks.STATUS,networks.IPADDRESS,networks.isActive,\n\t\t\thardware.* FROM networks,hardware WHERE networks.HARDWARE_ID=hardware.ID) as t";
    $searchstring = string_to_flexquery();
    if ($searchstring != null) {
        $sql = "SELECT COUNT(*) as TCOUNT FROM {$table} WHERE 1 {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "ocsweb"));
        if (!$q->ok) {
            json_error_show($q->mysql_error . "<br>{$sql}");
        }
        $total = $ligne["TCOUNT"];
    } else {
        $sql = "SELECT COUNT(*) as TCOUNT FROM {$table} WHERE 1";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "ocsweb"));
        if (!$q->ok) {
            json_error_show($q->mysql_error . "<br>{$sql}");
        }
        $total = $ligne["TCOUNT"];
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    $sql = "SELECT *  FROM {$table} WHERE 1 {$searchstring} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql, "ocsweb");
    if (!$q->ok) {
        json_error_show($q->mysql_error . "<hr>{$sql}");
    }
    if (mysql_num_rows($results) == 0) {
        json_error_show("no data");
    }
    $users = new usersMenus();
    $DHC_MAIN = false;
    if ($users->dhcp_installed) {
        $EnableDHCPServer = intval($sock->GET_INFO('EnableDHCPServer'));
        if ($EnableDHCPServer == 1) {
            $DHC_MAIN = true;
        }
    }
    $SQUID_MAIN = false;
    if ($users->SQUID_INSTALLED) {
        $SQUID_MAIN = true;
    }
    $fontsize = "22px";
    $computer = new computers();
    $q2 = new mysql_squid_builder();
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        if ($ligne["MACADDR"] == "unknown") {
            continue;
        }
        $ligne["MACADDR"] = strtolower($ligne["MACADDR"]);
        $HARDWARE_ID = $ligne["HARDWARE_ID"];
        $uid = null;
        $OSNAME = null;
        if ($ligne["OSNAME"] == "Unknown") {
            $ligne["OSNAME"] = null;
        }
        $color = "#7D7D7D";
        $md = md5($ligne["MACADDR"]);
        $uri = strtolower($ligne["NAME"]);
        if ($EnableIntelCeleron == 0) {
            $uid = $computer->ComputerIDFromMAC($ligne["MACADDR"]);
        }
        $view = "&nbsp;";
        $jslink = null;
        $jsfiche = null;
        $ISDB = "ok32-grey.png";
        $DHCP = "ok32-none.png";
        $SQUID = "ok32-none.png";
        if ($DHC_MAIN) {
            $DHCP = "ok32-grey.png";
            if ($computer->dhcpfixedFromMac($ligne["MACADDR"])) {
                $DHCP = "ok32.png";
            }
        }
        if ($SQUID_MAIN) {
            $ligne2 = mysql_fetch_array($q2->QUERY_SQL("SELECT enabled FROM computers_time WHERE `MAC`='{$ligne["MACADDR"]}'", "artica_backup"));
            if (intval($ligne2["enabled"]) != 0) {
                $SQUID = "warning24.png";
            }
        }
        if ($uid != null) {
            $ISDB = "ok32.png";
            $jsfiche = MEMBER_JS($uid, 1, 1);
            $view = "<a href=\"javascript:blur();\" \n\t\t\tOnClick=\"javascript:{$jsfiche}\" \n\t\t\tstyle='font-size:{$fontsize};text-decoration:underline'>" . str_replace("\$", "", strtolower($uid)) . "</a>";
            $jslink = "<a href=\"javascript:blur();\" \n\t\t\tOnClick=\"javascript:{$jsfiche}\" \n\t\t\tstyle='font-size:{$fontsize};text-decoration:underline'>";
        } else {
            $uid = $ligne["NAME"];
            if (preg_match("#^[0-9]+\\.[0-9]+\\.[0-9]+#", $uid)) {
                $q = new mysql_squid_builder();
                $NAME2 = $q->UID_FROM_MAC($ligne["MACADDR"]);
                if ($NAME2 != null) {
                    $uid = $NAME2;
                }
            }
            if ($uid == null) {
                $uid = "Unknown";
            }
            $jsfiche = "Loadjs('domains.computer.autoadd.php?mac=" . urlencode($ligne["MACADDR"]) . "&ipaddr=" . urlencode($ligne["IPADDRESS"]) . "&computername=" . urlencode($uid) . "&t={$_GET["t"]}')";
            if ($EnableIntelCeleron == 1) {
                $jsfiche = "Loadjs('domains.computer.mysql.php?HARDWARE_ID={$HARDWARE_ID}&t={$_GET["t"]}')";
            }
            $jslink = "<a href=\"javascript:blur();\"\n\t\t\tOnClick=\"javascript:{$jsfiche}\"\n\t\t\tstyle='font-size:{$fontsize};text-decoration:underline'>";
            $view = "<a href=\"javascript:blur();\"\n\t\t\tOnClick=\"javascript:{$jsfiche}\"\n\t\t\tstyle='font-size:{$fontsize};text-decoration:underline'>{$uid}</a>";
        }
        $js[] = "LoadAjaxTiny('cmp-{$md}','{$page}?compt-status={$ligne["IPADDRESS"]}');";
        $icon = "<img src='img/{$ISDB}'>";
        if ($ligne["OSNAME"] != null) {
            $OSNAME = "<div style='font-size:9px'><i>{$ligne["OSNAME"]}</i></div>";
        }
        if ($_GET["callback"] != null) {
            $color = "black";
            if ($_GET["fullvalues"] == 1) {
                $viewjs = "{$_GET["callback"]}('{$uid}','{$ligne["IPADDRESS"]}','{$ligne["MACADDR"]}')";
            } else {
                $viewjs = "{$_GET["callback"]}('{$uid}')";
            }
            $view = "<a href=\"javascript:blur();\" \n\t\t\t\t\t\tOnClick=\"javascript:{$viewjs}\" \n\t\t\t\t\t\tstyle='font-size:{$fontsize};text-decoration:underline'>" . str_replace("\$", "", strtolower($uid)) . "</a>";
            $icon = imgtootltip("arrow-blue-left-32.png", null, $viewjs);
        }
        if (!IsPhysicalAddress($ligne["MACADDR"])) {
            if ($_GET["CorrectMac"] == 1) {
                continue;
            }
        }
        $AlreadyMAC[$ligne["MACADDR"]] = true;
        $zdate = null;
        if (isset($ligne["zDate"])) {
            $zdate = "<div style='font-size:11px;color:#7D7D7D'>{$ligne["zDate"]}</div>";
        }
        $macenc = urlencode($ligne["MACADDR"]);
        $ipenc = urlencode($ligne["IPADDRESS"]);
        $jsDelete = "Loadjs('{$MyPage}?delete-computer-js=yes&MAC={$macenc}&t={$_GET["t"]}');";
        $alias = $q2->UID_FROM_MAC($ligne["MACADDR"]);
        if ($alias != null) {
            $alias_uri = "Loadjs('squid.nodes.php?node-infos-js=yes&MAC={$macenc}');";
        }
        if ($alias == null) {
            $alias = $q2->UID_FROM_IP($ligne["IPADDRESS"]);
            if ($alias != null) {
                $alias_uri = "Loadjs('squid.nodes.php?node-infos-js=yes&ipaddr={$ipenc}');";
            }
        }
        if ($alias == null) {
            $alias = "<center><img src='img/32-plus.png'></center>";
            $alias_uri = "Loadjs('squid.nodes.php?link-user-js=yes&MAC={$macenc}&ipaddr={$ipenc}',true)";
        }
        if ($EnableIntelCeleron == 1) {
            $jsfiche = "Loadjs('domains.computer.mysql.php?HARDWARE_ID={$HARDWARE_ID}&t={$_GET["t"]}')";
        }
        $cs++;
        $data['rows'][] = array('id' => md5(serialize($ligne)), 'cell' => array($view . $zdate, "<span style='font-size:{$fontsize}'>{$jslink}{$ligne["IPADDRESS"]}</a></span>", "<span style='font-size:{$fontsize}'>{$jslink}{$ligne["MACADDR"]}</a></span>", "<span style='font-size:{$fontsize}'><a href=\"javascript:blur();\" \n\t\t\tOnClick=\"javascript:{$alias_uri}\" style='text-decoration:underline'>{$alias}</a></span>", "<center><a href=\"javascript:blur();\" OnClick=\"javascript:{$jsfiche}\">{$icon}</a></center>", "<center><a href=\"javascript:blur();\" OnClick=\"javascript:{$jsfiche}\"><img src='img/{$DHCP}'></center></a>", "<center><a href=\"javascript:blur();\" OnClick=\"javascript:{$jsfiche}\"><img src='img/{$SQUID}'></center></a>", "<center><a href=\"javascript:blur();\" OnClick=\"javascript:{$jsDelete}\"><img src='img/delete-32.png'></center></a>"));
    }
    if ($cs > $_POST["rp"]) {
        $data['total'] = $cs;
        echo json_encode($data);
        return;
    }
    if ($cs == 0) {
        json_error_show("no item");
    }
    $data['total'] = $cs;
    echo json_encode($data);
}