Хранилища Subversion ant

Редакция

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

<?php

class Core {

        function getRepList($distro,$version,$dblink) {
                $query =& $dblink->query("SELECT * FROM settings");
                $settings = array();
                while ($query->fetchInto($setting, DB_FETCHMODE_ASSOC)) {
                        $settings[stripslashes($setting["opt"])] = stripslashes($setting["optvalue"]);
                };
                if ($_GET['mainreps']!='no'){
        $query =& $dblink->query("SELECT * FROM version v JOIN distribution d ON d.dist_id=v.dist_id JOIN dtype p ON d.disttype=p.type_id WHERE v.dist_id='$distro' AND v.version_id='$version'");
                $query->fetchInto($infodist, DB_FETCHMODE_ASSOC);
                $query =& $dblink->query("SELECT * FROM repository r JOIN ver2rep v ON r.rep_id=v.rep_id JOIN origin o ON o.orig_id=r.orig_id JOIN version v2 ON v.ver_id=v2.version_id JOIN scheme s ON s.scheme_id=r.scheme_id JOIN root r2 ON r2.root_id=r.root_id WHERE v.ver_id='$version' AND r.rtype_id!=3 ORDER BY r.rtype_id, r.scheme_id ASC");
                $pre=-1;
                while ($query->fetchInto($resinfo, DB_FETCHMODE_ASSOC)) {
                        $repscheme = stripslashes($resinfo["scheme"]);

                        $querysect =& $dblink->query("SELECT * FROM section s JOIN sect2rep r ON s.sect_id=r.sect_id WHERE
r.rep_id='$resinfo[rep_id]'"
);
                        $sections = "";
                        while ($querysect->fetchInto($section,DB_FETCHMODE_ASSOC)) {
                                $sections .= stripslashes($section["sectname"])." ";
                        }

                        $repscheme = str_replace("{TYPE}",stripslashes($infodist["type"]),$repscheme);
                        $repscheme = str_replace("{PROTO}",$settings["proto"],$repscheme);
                        $repscheme = str_replace("{URL}",$settings["url"],$repscheme);
                        $repscheme = str_replace("{REP}",stripslashes($resinfo["repname"]),$repscheme);
                        $repscheme = str_replace("{DIST}",stripslashes($infodist["vcodename"]),$repscheme);
                        $repscheme = str_replace("{SECT}",$sections,$repscheme);
                        $repscheme = str_replace("{ROOT}",stripslashes($resinfo["root_folder"]),$repscheme);
                       
                        if($pre != $resinfo["orig_id"]) {
                            $result .= "### ".$resinfo["origin"]."( ".$resinfo["desk"]." ) - ".$resinfo["homeurl"]." ###\n";
                        }
                        $pre = $resinfo["orig_id"];
                       
                        $result .= "# ".stripslashes($resinfo["repdescribe"])."\n".$repscheme."\n\n";
                }
        }
            if (count($_GET)>3){
                $addsreps=array_values($_GET);
                if ($_GET['mainreps']=='no'){$offs=1;}else{$offs=0;} //пока такой костыль
                for ($i=3;$i<count($addsreps)-$offs;$i++){
$pre=-1;
                   $id=(int)$addsreps[$i];
                    $sql =& $dblink->query('SELECT * FROM repository r JOIN ver2rep v ON r.rep_id=v.rep_id JOIN origin o ON o.orig_id=r.orig_id JOIN version v2 ON v.ver_id=v2.version_id JOIN scheme s ON s.scheme_id=r.scheme_id JOIN root r2 ON r2.root_id=r.root_id WHERE r.rep_id='.$id);
                    $sql->fetchInto($resinfo, DB_FETCHMODE_ASSOC);
           
                    $repscheme = stripslashes($resinfo["scheme"]);
                    $querysect =& $dblink->query("SELECT * FROM section s JOIN sect2rep r ON s.sect_id=r.sect_id WHERE
r.rep_id='$resinfo[rep_id]'"
);
                    $sections = "";
                        while ($querysect->fetchInto($section,DB_FETCHMODE_ASSOC)) {
                                $sections .= stripslashes($section["sectname"])." ";
                        }
                    $repscheme = str_replace("{TYPE}",stripslashes($infodist["type"]),$repscheme);
                    $repscheme = str_replace("{PROTO}",$settings["proto"],$repscheme);
                    $repscheme = str_replace("{URL}",$settings["url"],$repscheme);
                    $repscheme = str_replace("{REP}",stripslashes($resinfo["repname"]),$repscheme);
                    $repscheme = str_replace("{DIST}",stripslashes($infodist["vcodename"]),$repscheme);
                    $repscheme = str_replace("{SECT}",$sections,$repscheme);
                    $repscheme = str_replace("{ROOT}",stripslashes($resinfo["root_folder"]),$repscheme);
                    if($pre != $resinfo["orig_id"]) {
                        $result .= "### ".$resinfo["origin"]."( ".$resinfo["desk"]." ) - ".$resinfo["homeurl"]." ###\n";
                    }
                    $pre = $resinfo["orig_id"];
                    $result .= "# ".stripslashes($resinfo["repdescribe"])."\n".$repscheme."\n\n";                    
                }
            }

                return $result;
        }
       
        function getInfo($message,$dblink){
                $answer = array();

                if (preg_match("/linux/i",$message)) {
                        $dist_id = 0;
                        $dist_info = "";
                        $vers_id = 0;
                        $vers_info = "";
                        $qd =& $dblink->query("SELECT * FROM distribution");
                        while ($qd->fetchInto($res, DB_FETCHMODE_ASSOC)) {
                                if (preg_match("/".stripslashes($res["distua"])."/i",$message)) {
                                        $dist_id = $res["dist_id"];
                                        $dist_info = stripslashes($res["distname"]);
                                        $qv =& $dblink->query("SELECT * FROM version WHERE dist_id='$dist_id'");
                                        while($qv->fetchInto($rev, DB_FETCHMODE_ASSOC)) {
                                                if (preg_match("/".stripslashes($rev["vcodename"])."/i",$message)) {
                                                        $vers_id = $rev["version_id"];
                                                        $vers_info = stripslashes($rev["version"])." &#8220;".stripslashes($rev["vname"])."&#8221;";
                                                }
                                        }
                                }
                        }
                        $answer[] = "Linux";
                        $answer[] = "Судя по всему у Вас операционная система ";
                        if ($dist_id!=0) {
                                $answer[] = $dist_id;
                                $answer[] = $dist_info;
                        }
                        if ($vers_id!=0) {
                                $answer[] = $vers_id;
                                $answer[] = $vers_info;
                        }

                } else {
                        $answer[] = "unknown";
                        $answer[] = "Ресурс рассчитан явно не на Вашу операционную систему!";
                }

                return $answer;
        }

        function getInterfacesList($current,$dblink) {
                $url  = parse_url($current);
                $path = array();
                $path = split("/",$url["path"]);
                $currentIF = str_replace(".php","",$path[count($path)-1]);
                $req =& $dblink->query("SELECT * FROM interfaces WHERE interface NOT LIKE '$currentIF'");
                $iflist = "<a href='./'>Интерфейсы</a>: ";
                while ($req->fetchInto($if, DB_FETCHMODE_ASSOC)) {
                        $iflist .= "<a href='./".stripslashes($if["interface"]).".php'>".strtolower(stripslashes($if["interfaceinfo"]))."</a>, ";
                }
                $iflist = substr($iflist, 0, strlen($iflist)-2);
                return $iflist;
        }

        function getCSSList($dblink) {
                $req =& $dblink->query("SELECT * FROM distribution");
                if ($req->numRows()>0) {
                        $css = "<style type=\"text/css\">\n";
                        while ($req->fetchInto($dist, DB_FETCHMODE_ASSOC)) {
                                if ($dist["distlogo"]) {
                                        $css .= ".".stripslashes($dist["distua"])." { display: inline; padding-left: 15px; background: transparent url(./img/logo/".stripslashes($dist["distua"]).".png) top left no-repeat; }\n";
                                        $css .= ".".stripslashes($dist["distua"])."-em { display: inline; padding-left: 30px; background: transparent url(./img/logo/".stripslashes($dist["distua"])."-em.png) top left no-repeat; }\n";
                                } else {
                                        $css .= "";
                                }
                        }
                        $css .= "</style>";
                } else {
                        $css = "";
                }
                return $css;
        }

        function getSetting($setting, $dblink) {
                $query =& $dblink->query("SELECT * FROM settings WHERE opt LIKE '".$setting."'");
                $query->fetchInto($sett, DB_FETCHMODE_ASSOC);
                return stripslashes($sett["optvalue"]);
        }

        function getUUID($param) {
                $param_s = md5($param);
                $time_low = bin2hex(substr($param_s,0, 4));
                $time_mid = bin2hex(substr($param_s,4, 2));
                $time_hi_and_version = bin2hex(substr($param_s,6, 2));
                $clock_seq_hi_and_reserved = bin2hex(substr($param_s,8, 2));
                $node = bin2hex(substr($param_s,10, 6));

                $time_hi_and_version = hexdec($time_hi_and_version);
                $time_hi_and_version = $time_hi_and_version >> 4;
                $time_hi_and_version = $time_hi_and_version | 0x4000;
       
                $clock_seq_hi_and_reserved = hexdec($clock_seq_hi_and_reserved);
                $clock_seq_hi_and_reserved = $clock_seq_hi_and_reserved >> 2;
                $clock_seq_hi_and_reserved = $clock_seq_hi_and_reserved | 0x8000;
       
                return sprintf('%08s-%04s-%04x-%04x-%012s',$time_low, $time_mid, $time_hi_and_version, $clock_seq_hi_and_reserved, $node);
        }


    function getAddsRepList($distro,$version,$dblink) {
        $query =& $dblink->query("SELECT * FROM settings");
        $settings = array();
        while ($query->fetchInto($setting, DB_FETCHMODE_ASSOC)) {
            $settings[stripslashes($setting["opt"])] = stripslashes($setting["optvalue"]);
        };
        $query =& $dblink->query("SELECT * FROM version v JOIN distribution d ON d.dist_id=v.dist_id JOIN dtype p ON d.disttype=p.type_id WHERE v.dist_id='$distro' AND v.version_id='$version'");
        $query->fetchInto($infodist, DB_FETCHMODE_ASSOC);
        $query =& $dblink->query("SELECT * FROM repository r JOIN ver2rep v ON r.rep_id=v.rep_id JOIN origin o ON o.orig_id=r.orig_id JOIN version v2 ON v.ver_id=v2.version_id JOIN scheme s ON s.scheme_id=r.scheme_id JOIN root r2 ON r2.root_id=r.root_id WHERE v.ver_id='$version' AND r.rtype_id=3 ORDER BY r.rtype_id, r.scheme_id ASC");
        $result.='<input type="hidden" name="d" value="'.$_GET['d'].'">
                  <input type="hidden" name="v" value="'
.$_GET['v'].'">';
        $tmp=0;
        while ($query->fetchInto($resinfo, DB_FETCHMODE_ASSOC)) {
             $tmp++;
             $result.='<input type="checkbox" name="'.$tmp.'"  value="'.$resinfo['rep_id'].'">'.$resinfo['repname'].' <em>('.$resinfo['repdescribe'].')</em><br>';
        }
        return $result;
    }
}    
?>