Хранилища Subversion www_nix-files

Редакция

Редакция 177 | Авторство | Сравнить с предыдущей | Последнее изменение | Открыть журнал | RSS

<?php
        require_once dirname(__FILE__)."/lib/init.php";
        include "./inc/header.htm";
       
        // detect network
        $addr=$_SERVER['REMOTE_ADDR'];
        $snets =& $db->query("SELECT * FROM subnets");
        $is_addr_found = false;
        while ($snets->fetchInto($info_snets, DB_FETCHMODE_ASSOC)&&!$is_addr_found) {
            list($ip,$mask) = explode('/',$info_snets['subnet']);
            if (ip2long($addr) >> (32 - $mask) == ip2long($ip) >> (32 - $mask)) {
                $is_addr_found = true;
                $curnet = $info_snets['network_id'];
            }
        }
       
        // table header
        echo "<table>";
       
        $netlist = array();
        $netcount = 0;
       
        $theader1 = "<tr>\n<th rowspan='2'>&nbsp;</th><th rowspan='2'>&nbsp;</th><th rowspan='2'>Ресурс</th>\n"; // category header
        $theader2 = "<tr>\n"; // networks header
       
        $ncats =& $db->query("SELECT * FROM netcats");
        while ($ncats->fetchInto($info_ncats, DB_FETCHMODE_ASSOC)) {
            $ccnc = 0; // Count networks of current category
            $nets =& $db->query("SELECT * FROM networks WHERE netcat_id=".$info_ncats['id']);
            while ($nets->fetchInto($info_nets, DB_FETCHMODE_ASSOC)) {
                // network name & link
                if ($info_nets['link']=="") { $theader2 .= " <th>".$info_nets['network']."</th>\n"; }
                else { $theader2 .= " <th><a href='./networks.php?net=".$info_nets['id']."'>".$info_nets['network']."</a></th>\n"; }
                // netlist
                $netlist[$netcount] = $info_nets['id'];
                $netcount++;
                $ccnc++;
            }
            $theader1 .= "<th colspan='".$ccnc."'>".$info_ncats['netcat']."</th>";
        }
        echo $theader1."\n</tr>\n";
        echo $theader2."\n</tr>\n";
       
        // table body
        $cats =& $db->query("SELECT * FROM categories");
        while ($cats->fetchInto($info_cats, DB_FETCHMODE_ASSOC)) {
            $res =& $db->query("SELECT * FROM resources WHERE category_id=".$info_cats['id']);
            $first = true;
            while ($res->fetchInto($info_res, DB_FETCHMODE_ASSOC)) {
                echo "<tr>\n";
               
                // add rowspan on first resource on category
                if ($first) {
                    echo " <td rowspan='".$res->numRows()."'>".$info_cats['category']."</td>\n";
                    $first = false;
                }
               
                // resource picture
                echo " <td><img src='".$info_res['picture']."' alt='".$info_res['resource']."'></td>\n";
               
                // resource name & link
                echo " <td><a href='./details.php?res=".$info_res['id']."'>".$info_res['resource']."</a></td>\n";
               
                // resource state by network
                for ($i=0;$i<$netcount;$i++) {
                    $curstate =& $db->getOne("SELECT state_id FROM res_net_stat WHERE resource_id=".$info_res['id']." AND network_id=".$netlist[$i]);
                    if($netlist[$i]==$curnet) { echo " <td bgcolor='#CFE79F'>"; }
                    else { echo " <td>"; };
                   
                    $curimg = "./img/state/unknown.png";
                    if ($curstate == null) {
                        echo "&mdash;";
                    }
                    else {
                        // !replace in future!
                        switch ($curstate) {
                            case '1':
                                $curimg = "./img/state/tick_gold.png";
                                $curalt = "Основной ресурс";
                            break;
                            case '2':
                                $curimg = "./img/state/tick_blue.png";
                                $curalt = "Зеркало";
                            break;
                            case '3':
                                $curimg = "./img/state/tick_green.png";
                                $curalt = "Скоростной доступ";
                            break;
                            case '4':
                                $curimg = "./img/state/tick_gray.png";
                                $curalt = "Доступен";
                            break;
                            case '5':
                                $curimg = "./img/state/snowflake.png";
                                $curalt = "Заморожен";
                            break;
                        }
                        echo "<a href='".$info_res['link_res']."'><img src='".$curimg."' alt='".$curalt."'></a>";
                    }
                    echo "</td>\n";
                }
                echo "</tr>\n";
            }
        }
        // table footer
        echo "</table>";
        include "./inc/legend.php";

        include "./inc/footer.htm";
?>