Хранилища Subversion ant

Редакция

Редакция 314 | Редакция 316 | К новейшей редакции | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | 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";
46
        switch ($format) {
47
            case 'html':
48
                $show = "<label for='".$name."'>".$info."</label> <select id='".$name."' name='".$name."'>\n";
49
                $rq =& $this->db->query($query);
50
                while ($rq->fetchInto($element)) {
51
                    $show .= "<option value='".$this->secure->checkInt($element["dist_id"])."'>".$this->secure->checkStr($element["distname"],1)."</option>\n";
52
                }
53
                $show .= "</select>";
54
                break;
55
            case 'json':
56
                $show = '[{value:"",text:"'.$info.'"}';
57
                $rq =& $this->db->query($query);
58
                while ($rq->fetchInto($element)) {
59
                    $show .= ',{value:"'.$this->secure->checkInt($element["dist_id"]).'",text:"'.$this->secure->checkStr($element["distname"],1).'"}';
60
                }
61
                $show .= ']';
62
                break;
63
        }
64
        return $show;
65
    }
66
 
67
    // Получение названия дистрибутива
68
    function getDistName($distID) {
69
        $result = array();
70
        $query = "SELECT distname FROM ".$this->prefix."distribution WHERE dist_id='".$this->secure->checkInt($distID)."'";
71
        $rq =& $this->db->query($query);
72
        if (PEAR::isError($this->db)) {
73
            $result["ERR"] = 1;
74
            $result["ERRINFO"] = $this->db->getMessage();
75
        } else {
76
            $rq->fetchInto($element);
77
            $result["ERR"] = 0;
78
            $result["DistName"] = $this->secure->checkStr($element["distname"],1);
79
        }
80
 
81
        return $result;
82
    }
83
 
84
    // Получение и отображение списка версий дистрибутива
85
    function showDistVersionsList($name, $distID, $format = 'html') {
86
        $query = "SELECT * FROM ".$this->prefix."version WHERE dist_id='".$this->secure->checkInt($distID)."' ORDER BY version ASC";
87
        switch ($format) {
88
            case 'html':
89
                $show = "<label for='".$name."'>".$info."</label> <select id='".$name."' name='".$name."'>\n";
90
                $rq =& $this->db->query($query);
91
                while ($rq->fetchInto($element)) {
92
                    $show .= "<option value='".$this->secure->checkInt($element["dist_id"])."'>".$this->secure->checkStr($element["distname"],1)."</option>\n";
93
                }
94
                $show .= "</select>";
95
                break;
96
            case 'json':
97
                $show = '[{value:"",text:"'.$info.'"}';
98
                $rq =& $this->db->query($query);
99
                while ($rq->fetchInto($element)) {
100
                    $show .= ',{value:"'.$this->secure->checkInt($element["dist_id"]).'",text:"'.$this->secure->checkStr($element["distname"],1).'"}';
101
                }
102
                $show .= ']';
103
                break;
104
        }
105
        return $show;
106
    }
107
 
304 alex-w 108
}
109
 
110
?>