Хранилища Subversion ant

Редакция

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

Редакция Автор № строки Строка
304 alex-w 1
<?php
2
 
3
/**
4
 *  
5
 *  Codename: ant-ng - generator of sources.list for Debian and
6
 *  distributives, based on Debian
7
 *  http://alex-w.org.ru/p/antng/
8
 *
9
 *  Copyright (c) 2009 Alexander Wolf
10
 *  Dual licensed under the MIT and GNU LGPL licenses.
11
 *  http://alex-w.org.ru/p/antng/license
12
 *
13
 */
14
 
15
class Core {
308 alex-w 16
    protected $db       = NULL;
17
    protected $prefix   = NULL;
313 alex-w 18
    protected $secure   = NULL;    
304 alex-w 19
 
309 alex-w 20
 
314 alex-w 21
    function __construct($database, $prefix, $secure) {
308 alex-w 22
        $this->db       = $database;
23
        $this->prefix   = $prefix;
312 alex-w 24
        $this->secure   = $secure;        
307 alex-w 25
    }
26
 
315 alex-w 27
    // Получение данных о настройке
314 alex-w 28
    function getOption($attr) {
308 alex-w 29
        $result = array();
315 alex-w 30
        $query = "SELECT optvalue FROM ".$this->prefix."settings WHERE opt='".$this->secure->checkStr($attr)."'";
314 alex-w 31
        $rq =& $this->db->query($query);
308 alex-w 32
        if ($rq->numRows()!=0) {
33
            $rq->fetchInto($element);
34
            $result["ERR"] = 0;
35
            $result["OptValue"] = $element["optvalue"];
36
        } else {
37
            $result["ERR"] = 1;
38
            $result["ERRINFO"] = "Empty result";
39
        }
40
        return $result;
41
    }
42
 
315 alex-w 43
    // Получение и отображение списка дистрибутивов
44
    function showDistributionList($name, $info = "", $format = 'html') {
45
        $query = "SELECT * FROM ".$this->prefix."distribution ORDER BY dist_id ASC";
317 alex-w 46
        $rq =& $this->db->query($query);
315 alex-w 47
        switch ($format) {
48
            case 'html':
317 alex-w 49
                $show = "<fieldset><legend>".$info."</legend>\n<select id='".$name."' name='".$name."'>\n";                
315 alex-w 50
                while ($rq->fetchInto($element)) {
51
                    $show .= "<option value='".$this->secure->checkInt($element["dist_id"])."'>".$this->secure->checkStr($element["distname"],1)."</option>\n";
52
                }
317 alex-w 53
                $show .= "</select></fieldset>";
315 alex-w 54
                break;
55
            case 'json':
317 alex-w 56
                $show = '[{value:"",text:"'.$info.'"}';                
315 alex-w 57
                while ($rq->fetchInto($element)) {
58
                    $show .= ',{value:"'.$this->secure->checkInt($element["dist_id"]).'",text:"'.$this->secure->checkStr($element["distname"],1).'"}';
59
                }
60
                $show .= ']';
61
                break;
62
        }
63
        return $show;
64
    }
65
 
66
    // Получение названия дистрибутива
67
    function getDistName($distID) {
68
        $result = array();
69
        $query = "SELECT distname FROM ".$this->prefix."distribution WHERE dist_id='".$this->secure->checkInt($distID)."'";
70
        $rq =& $this->db->query($query);
71
        if (PEAR::isError($this->db)) {
72
            $result["ERR"] = 1;
73
            $result["ERRINFO"] = $this->db->getMessage();
74
        } else {
75
            $rq->fetchInto($element);
76
            $result["ERR"] = 0;
77
            $result["DistName"] = $this->secure->checkStr($element["distname"],1);
78
        }
79
 
80
        return $result;
81
    }
82
 
83
    // Получение и отображение списка версий дистрибутива
84
    function showDistVersionsList($name, $distID, $format = 'html') {
316 alex-w 85
        $distname = $this->getDistName($distID);
315 alex-w 86
        $query = "SELECT * FROM ".$this->prefix."version WHERE dist_id='".$this->secure->checkInt($distID)."' ORDER BY version ASC";
317 alex-w 87
        $rq =& $this->db->query($query);
315 alex-w 88
        switch ($format) {
89
            case 'html':
317 alex-w 90
                $show = "<fieldset><legend>Версии ".$distname["DistName"]."</legend>\n<select id='".$name."' name='".$name."'>\n";                
315 alex-w 91
                while ($rq->fetchInto($element)) {
316 alex-w 92
                    $show .= "<option value='".$this->secure->checkInt($element["version_id"])."'>".$this->secure->checkStr($element["version"],1)." ".$this->secure->checkStr($element["vname"],1)."</option>\n";
315 alex-w 93
                }
317 alex-w 94
                $show .= "</select></fieldset>";
315 alex-w 95
                break;
96
            case 'json':
317 alex-w 97
                $show = '[{value:"",text:"Выбери версию '.$distname["DistName"].'"}';                
315 alex-w 98
                while ($rq->fetchInto($element)) {
316 alex-w 99
                    $show .= ',{value:"'.$this->secure->checkInt($element["version_id"]).'",text:"'.$this->secure->checkStr($element["version"],1).' '.$this->secure->checkStr($element["vname"],1).'"}';
315 alex-w 100
                }
101
                $show .= ']';
102
                break;
103
        }
104
        return $show;
105
    }
106
 
317 alex-w 107
    // Получение и отображение списка секций основного (официального) репозитория
108
    function showBranchesList($version, $format = 'html') {
109
        $query  = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='1'";
110
        $rq =& $this->db->query($query);
111
        $rq->fetchInto($types);
112
        $query  = "SELECT s.*,t.rtype FROM ".$this->prefix."section s ";
113
        $query .= "JOIN ".$this->prefix."sect2rep l ON s.sect_id=l.sect_id ";
114
        $query .= "JOIN ".$this->prefix."repository r ON r.rep_id=l.rep_id ";
115
        $query .= "JOIN ".$this->prefix."rtype t ON r.rtype_id=t.rtype_id ";
116
        $query .= "WHERE t.rtype_id='1' AND r.version='".$this->secure->checkInt($version)."'";
117
        $rq =& $this->db->query($query);
118
        switch ($format) {
119
            case 'html':
120
                $show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n";
121
                while ($rq->fetchInto($element)) {
122
                    $show .= "<div class='sections'><input type='checkbox' name='section[]' value='".$element["sect_id"]."'> ".$this->secure->checkStr($element["sectname"])." &mdash; ".$this->secure->checkStr($element["sectinfo"])."</div>\n";
123
                }
124
                $show .= "</fieldset>\n";
125
                break;
126
            case 'json':
127
                //TODO Доделать JSON-вывод списка секций основного репозитория
128
                break;
129
        }
130
    }
131
 
132
    // Получение и отображение списка репозиториев 
133
    function showRepList($version, $reptype, $format = 'html') {
134
        $query  = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='1'";
135
        $rq =& $this->db->query($query);
136
        $rq->fetchInto($types);
137
        $query = "SELECT * FROM ".$this->prefix."repository WHERE version='".$this->secure->checkInt($version)."' AND rtype_id='".$this->secure->checkInt($reptype)."'";
138
        $rq =& $this->db->query($query);
139
        switch ($format) {
140
            case 'html':
141
                $show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n";
142
                while ($rq->fetchInto($types)) {
143
                    $show .= "<div class='repository'><input type='checkbox' name='repository[]' value='".$element["rep_id"]."'> ".$this->secure->checkStr($element["repname"])." &mdash; ".$this->secure->checkStr($element["repinfo"])."</div>\n";
144
                }
145
                $show .= "</fieldset>\n";
146
                break;
147
            case 'json':
148
                //TODO Доделать JSON-вывод списка репозиториев
149
                break;
150
        }
151
    }
152
 
304 alex-w 153
}
154
 
155
?>