Хранилища Subversion ant

Редакция

Редакция 315 | Редакция 317 | К новейшей редакции | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS

Редакция 315 Редакция 316
1
<?php
1
<?php
2
2
3
/**
3
/**
4
 *  
4
 *  
5
 *  Codename: ant-ng - generator of sources.list for Debian and
5
 *  Codename: ant-ng - generator of sources.list for Debian and
6
 *  distributives, based on Debian
6
 *  distributives, based on Debian
7
 *  http://alex-w.org.ru/p/antng/
7
 *  http://alex-w.org.ru/p/antng/
8
 *
8
 *
9
 *  Copyright (c) 2009 Alexander Wolf
9
 *  Copyright (c) 2009 Alexander Wolf
10
 *  Dual licensed under the MIT and GNU LGPL licenses.
10
 *  Dual licensed under the MIT and GNU LGPL licenses.
11
 *  http://alex-w.org.ru/p/antng/license
11
 *  http://alex-w.org.ru/p/antng/license
12
 *
12
 *
13
 */
13
 */
14
14
15
class Core {
15
class Core {
16
    protected $db       = NULL;
16
    protected $db       = NULL;
17
    protected $prefix   = NULL;
17
    protected $prefix   = NULL;
18
    protected $secure   = NULL;    
18
    protected $secure   = NULL;    
19
19
20
20
21
    function __construct($database, $prefix, $secure) {
21
    function __construct($database, $prefix, $secure) {
22
        $this->db       = $database;
22
        $this->db       = $database;
23
        $this->prefix   = $prefix;
23
        $this->prefix   = $prefix;
24
        $this->secure   = $secure;        
24
        $this->secure   = $secure;        
25
    }
25
    }
26
26
27
    // Получение данных о настройке
27
    // Получение данных о настройке
28
    function getOption($attr) {
28
    function getOption($attr) {
29
        $result = array();
29
        $result = array();
30
        $query = "SELECT optvalue FROM ".$this->prefix."settings WHERE opt='".$this->secure->checkStr($attr)."'";
30
        $query = "SELECT optvalue FROM ".$this->prefix."settings WHERE opt='".$this->secure->checkStr($attr)."'";
31
        $rq =& $this->db->query($query);
31
        $rq =& $this->db->query($query);
32
        if ($rq->numRows()!=0) {
32
        if ($rq->numRows()!=0) {
33
            $rq->fetchInto($element);
33
            $rq->fetchInto($element);
34
            $result["ERR"] = 0;
34
            $result["ERR"] = 0;
35
            $result["OptValue"] = $element["optvalue"];
35
            $result["OptValue"] = $element["optvalue"];
36
        } else {
36
        } else {
37
            $result["ERR"] = 1;
37
            $result["ERR"] = 1;
38
            $result["ERRINFO"] = "Empty result";
38
            $result["ERRINFO"] = "Empty result";
39
        }
39
        }
40
        return $result;
40
        return $result;
41
    }
41
    }
42
42
43
    // Получение и отображение списка дистрибутивов
43
    // Получение и отображение списка дистрибутивов
44
    function showDistributionList($name, $info = "", $format = 'html') {
44
    function showDistributionList($name, $info = "", $format = 'html') {
45
        $query = "SELECT * FROM ".$this->prefix."distribution ORDER BY dist_id ASC";
45
        $query = "SELECT * FROM ".$this->prefix."distribution ORDER BY dist_id ASC";
46
        switch ($format) {
46
        switch ($format) {
47
            case 'html':
47
            case 'html':
48
                $show = "<label for='".$name."'>".$info."</label> <select id='".$name."' name='".$name."'>\n";
48
                $show = "<label for='".$name."'>".$info."</label> <select id='".$name."' name='".$name."'>\n";
49
                $rq =& $this->db->query($query);
49
                $rq =& $this->db->query($query);
50
                while ($rq->fetchInto($element)) {
50
                while ($rq->fetchInto($element)) {
51
                    $show .= "<option value='".$this->secure->checkInt($element["dist_id"])."'>".$this->secure->checkStr($element["distname"],1)."</option>\n";
51
                    $show .= "<option value='".$this->secure->checkInt($element["dist_id"])."'>".$this->secure->checkStr($element["distname"],1)."</option>\n";
52
                }
52
                }
53
                $show .= "</select>";
53
                $show .= "</select>";
54
                break;
54
                break;
55
            case 'json':
55
            case 'json':
56
                $show = '[{value:"",text:"'.$info.'"}';
56
                $show = '[{value:"",text:"'.$info.'"}';
57
                $rq =& $this->db->query($query);
57
                $rq =& $this->db->query($query);
58
                while ($rq->fetchInto($element)) {
58
                while ($rq->fetchInto($element)) {
59
                    $show .= ',{value:"'.$this->secure->checkInt($element["dist_id"]).'",text:"'.$this->secure->checkStr($element["distname"],1).'"}';
59
                    $show .= ',{value:"'.$this->secure->checkInt($element["dist_id"]).'",text:"'.$this->secure->checkStr($element["distname"],1).'"}';
60
                }
60
                }
61
                $show .= ']';
61
                $show .= ']';
62
                break;
62
                break;
63
        }
63
        }
64
        return $show;
64
        return $show;
65
    }
65
    }
66
66
67
    // Получение названия дистрибутива
67
    // Получение названия дистрибутива
68
    function getDistName($distID) {
68
    function getDistName($distID) {
69
        $result = array();
69
        $result = array();
70
        $query = "SELECT distname FROM ".$this->prefix."distribution WHERE dist_id='".$this->secure->checkInt($distID)."'";
70
        $query = "SELECT distname FROM ".$this->prefix."distribution WHERE dist_id='".$this->secure->checkInt($distID)."'";
71
        $rq =& $this->db->query($query);
71
        $rq =& $this->db->query($query);
72
        if (PEAR::isError($this->db)) {
72
        if (PEAR::isError($this->db)) {
73
            $result["ERR"] = 1;
73
            $result["ERR"] = 1;
74
            $result["ERRINFO"] = $this->db->getMessage();
74
            $result["ERRINFO"] = $this->db->getMessage();
75
        } else {
75
        } else {
76
            $rq->fetchInto($element);
76
            $rq->fetchInto($element);
77
            $result["ERR"] = 0;
77
            $result["ERR"] = 0;
78
            $result["DistName"] = $this->secure->checkStr($element["distname"],1);
78
            $result["DistName"] = $this->secure->checkStr($element["distname"],1);
79
        }
79
        }
80
80
81
        return $result;
81
        return $result;
82
    }
82
    }
83
83
84
    // Получение и отображение списка версий дистрибутива
84
    // Получение и отображение списка версий дистрибутива
85
    function showDistVersionsList($name, $distID, $format = 'html') {
85
    function showDistVersionsList($name, $distID, $format = 'html') {
-
 
86
        $distname = $this->getDistName($distID);
86
        $query = "SELECT * FROM ".$this->prefix."version WHERE dist_id='".$this->secure->checkInt($distID)."' ORDER BY version ASC";
87
        $query = "SELECT * FROM ".$this->prefix."version WHERE dist_id='".$this->secure->checkInt($distID)."' ORDER BY version ASC";
87
        switch ($format) {
88
        switch ($format) {
88
            case 'html':
89
            case 'html':
89
                $show = "<label for='".$name."'>".$info."</label> <select id='".$name."' name='".$name."'>\n";
90
                $show = "<label for='".$name."'>Версии ".$distname["DistName"]."</label> <select id='".$name."' name='".$name."'>\n";
90
                $rq =& $this->db->query($query);
91
                $rq =& $this->db->query($query);
91
                while ($rq->fetchInto($element)) {
92
                while ($rq->fetchInto($element)) {
92
                    $show .= "<option value='".$this->secure->checkInt($element["dist_id"])."'>".$this->secure->checkStr($element["distname"],1)."</option>\n";
93
                    $show .= "<option value='".$this->secure->checkInt($element["version_id"])."'>".$this->secure->checkStr($element["version"],1)." ".$this->secure->checkStr($element["vname"],1)."</option>\n";
93
                }
94
                }
94
                $show .= "</select>";
95
                $show .= "</select>";
95
                break;
96
                break;
96
            case 'json':
97
            case 'json':
97
                $show = '[{value:"",text:"'.$info.'"}';
98
                $show = '[{value:"",text:"Выбери версию '.$distname["DistName"].'"}';
98
                $rq =& $this->db->query($query);
99
                $rq =& $this->db->query($query);
99
                while ($rq->fetchInto($element)) {
100
                while ($rq->fetchInto($element)) {
100
                    $show .= ',{value:"'.$this->secure->checkInt($element["dist_id"]).'",text:"'.$this->secure->checkStr($element["distname"],1).'"}';
101
                    $show .= ',{value:"'.$this->secure->checkInt($element["version_id"]).'",text:"'.$this->secure->checkStr($element["version"],1).' '.$this->secure->checkStr($element["vname"],1).'"}';
101
                }
102
                }
102
                $show .= ']';
103
                $show .= ']';
103
                break;
104
                break;
104
        }
105
        }
105
        return $show;
106
        return $show;
106
    }
107
    }
107
108
108
}
109
}
109
110
110
?>
111
?>
111
 
112