Редакция 321 | Редакция 345 | К новейшей редакции | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 321 | Редакция 329 | ||
---|---|---|---|
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 | $rq =& $this->db->query($query); |
46 | $rq =& $this->db->query($query); |
47 | switch ($format) { |
47 | switch ($format) { |
48 | case 'html': |
48 | case 'html': |
49 | $show = "<fieldset><legend>".$info."</legend>\n<select id='".$name."' name='".$name."'>\n"; |
49 | $show = "<fieldset><legend>".$info."</legend>\n<select id='".$name."' name='".$name."'>\n"; |
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></fieldset>"; |
53 | $show .= "</select></fieldset>"; |
54 | break; |
54 | break; |
55 | case 'json': |
55 | case 'json': |
56 | $show = '[{value:"",text:"'.$info.'"}'; |
56 | $show = '[{value:"",text:"'.$info.'"}'; |
57 | while ($rq->fetchInto($element)) { |
57 | while ($rq->fetchInto($element)) { |
58 | $show .= ',{value:"'.$this->secure->checkInt($element["dist_id"]).'",text:"'.$this->secure->checkStr($element["distname"],1).'"}'; |
58 | $show .= ',{value:"'.$this->secure->checkInt($element["dist_id"]).'",text:"'.$this->secure->checkStr($element["distname"],1).'"}'; |
59 | }
|
59 | }
|
60 | $show .= ']'; |
60 | $show .= ']'; |
61 | break; |
61 | break; |
62 | }
|
62 | }
|
63 | return $show; |
63 | return $show; |
64 | }
|
64 | }
|
65 | 65 | ||
66 | // Получение названия дистрибутива
|
66 | // Получение названия дистрибутива
|
67 | function getDistName($distID) { |
67 | function getDistName($distID) { |
68 | $result = array(); |
68 | $result = array(); |
69 | $query = "SELECT distname FROM ".$this->prefix."distribution WHERE dist_id='".$this->secure->checkInt($distID)."'"; |
69 | $query = "SELECT distname FROM ".$this->prefix."distribution WHERE dist_id='".$this->secure->checkInt($distID)."'"; |
70 | $rq =& $this->db->query($query); |
70 | $rq =& $this->db->query($query); |
71 | if (PEAR::isError($this->db)) { |
71 | if (PEAR::isError($this->db)) { |
72 | $result["ERR"] = 1; |
72 | $result["ERR"] = 1; |
73 | $result["ERRINFO"] = $this->db->getMessage(); |
73 | $result["ERRINFO"] = $this->db->getMessage(); |
74 | } else { |
74 | } else { |
75 | $rq->fetchInto($element); |
75 | $rq->fetchInto($element); |
76 | $result["ERR"] = 0; |
76 | $result["ERR"] = 0; |
77 | $result["DistName"] = $this->secure->checkStr($element["distname"],1); |
77 | $result["DistName"] = $this->secure->checkStr($element["distname"],1); |
78 | }
|
78 | }
|
79 | 79 | ||
80 | return $result; |
80 | return $result; |
81 | }
|
81 | }
|
82 | 82 | ||
83 | // Получение и отображение списка версий дистрибутива
|
83 | // Получение и отображение списка версий дистрибутива
|
84 | function showDistVersionsList($name, $distID, $format = 'html') { |
84 | function showDistVersionsList($name, $distID, $format = 'html') { |
85 | $distname = $this->getDistName($distID); |
85 | $distname = $this->getDistName($distID); |
86 | $query = "SELECT * FROM ".$this->prefix."version WHERE dist_id='".$this->secure->checkInt($distID)."' ORDER BY version ASC"; |
86 | $query = "SELECT * FROM ".$this->prefix."version WHERE dist_id='".$this->secure->checkInt($distID)."' ORDER BY version ASC"; |
87 | $rq =& $this->db->query($query); |
87 | $rq =& $this->db->query($query); |
88 | switch ($format) { |
88 | switch ($format) { |
89 | case 'html': |
89 | case 'html': |
90 | $show = "<fieldset><legend>Версии ".$distname["DistName"]."</legend>\n<select id='".$name."' name='".$name."'>\n"; |
90 | $show = "<fieldset><legend>Версии ".$distname["DistName"]."</legend>\n<select id='".$name."' name='".$name."'>\n"; |
91 | while ($rq->fetchInto($element)) { |
91 | while ($rq->fetchInto($element)) { |
92 | $show .= "<option value='".$this->secure->checkInt($element["version_id"])."'>".$this->secure->checkStr($element["version"],1)." ".$this->secure->checkStr($element["vname"],1)."</option>\n"; |
92 | $show .= "<option value='".$this->secure->checkInt($element["version_id"])."'>".$this->secure->checkStr($element["version"],1)." ".$this->secure->checkStr($element["vname"],1)."</option>\n"; |
93 | }
|
93 | }
|
94 | $show .= "</select></fieldset>"; |
94 | $show .= "</select></fieldset>"; |
95 | break; |
95 | break; |
96 | case 'json': |
96 | case 'json': |
97 | $show = '[{value:"",text:"Выбери версию '.$distname["DistName"].'"}'; |
97 | $show = '[{value:"",text:"Выбери версию '.$distname["DistName"].'"}'; |
98 | while ($rq->fetchInto($element)) { |
98 | while ($rq->fetchInto($element)) { |
99 | $show .= ',{value:"'.$this->secure->checkInt($element["version_id"]).'",text:"'.$this->secure->checkStr($element["version"],1).' '.$this->secure->checkStr($element["vname"],1).'"}'; |
99 | $show .= ',{value:"'.$this->secure->checkInt($element["version_id"]).'",text:"'.$this->secure->checkStr($element["version"],1).' '.$this->secure->checkStr($element["vname"],1).'"}'; |
100 | }
|
100 | }
|
101 | $show .= ']'; |
101 | $show .= ']'; |
102 | break; |
102 | break; |
103 | }
|
103 | }
|
104 | return $show; |
104 | return $show; |
105 | }
|
105 | }
|
106 | 106 | ||
107 | // Получение и отображение списка секций основного (официального) репозитория
|
107 | // Получение и отображение списка секций основного (официального) репозитория
|
108 | function showBranchesList($version, $format = 'html') { |
108 | function showBranchesList($version, $format = 'html') { |
109 | $query = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='1'"; |
109 | $query = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='1'"; |
110 | $rq =& $this->db->query($query); |
110 | $rq =& $this->db->query($query); |
111 | $rq->fetchInto($types); |
111 | $rq->fetchInto($types); |
112 | $query = "SELECT s.*,t.rtype FROM ".$this->prefix."section s "; |
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 "; |
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 "; |
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 "; |
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)."'"; |
116 | $query .= "WHERE t.rtype_id='1' AND r.version='".$this->secure->checkInt($version)."'"; |
117 | $rq =& $this->db->query($query); |
117 | $rq =& $this->db->query($query); |
118 | switch ($format) { |
118 | switch ($format) { |
119 | case 'html': |
119 | case 'html': |
120 | $show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n"; |
120 | $show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n"; |
121 | while ($rq->fetchInto($element)) { |
121 | while ($rq->fetchInto($element)) { |
122 | $show .= "<div class='sections'><input type='checkbox' name='section[]' value='".$element["sect_id"]."'> ".$this->secure->checkStr($element["secname"],1)." — ".$this->secure->checkStr($element["secinfo"],1)."</div>\n"; |
122 | $show .= "<div class='sections'><input type='checkbox' name='section[]' value='".$element["sect_id"]."'> ".$this->secure->checkStr($element["secname"],1)." — ".$this->secure->checkStr($element["secinfo"],1)."</div>\n"; |
123 | }
|
123 | }
|
124 | $show .= "</fieldset>\n"; |
124 | $show .= "</fieldset>\n"; |
125 | break; |
125 | break; |
126 | case 'json': |
126 | case 'json': |
127 | //TODO Доделать JSON-вывод списка секций основного репозитория
|
127 | //TODO Доделать JSON-вывод списка секций основного репозитория
|
128 | break; |
128 | break; |
129 | }
|
129 | }
|
130 | 130 | ||
131 | return $show; |
131 | return $show; |
132 | }
|
132 | }
|
133 | 133 | ||
134 | // Получение и отображение списка репозиториев
|
134 | // Получение и отображение списка репозиториев
|
135 | function showRepList($version, $reptype, $format = 'html') { |
135 | function showRepList($version, $reptype, $format = 'html') { |
136 | $query = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='1'"; |
136 | $query = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='1'"; |
137 | $rq =& $this->db->query($query); |
137 | $rq =& $this->db->query($query); |
138 | $rq->fetchInto($types); |
138 | $rq->fetchInto($types); |
139 | $query = "SELECT * FROM ".$this->prefix."repository WHERE version='".$this->secure->checkInt($version)."' AND rtype_id='".$this->secure->checkInt($reptype)."'"; |
139 | $query = "SELECT * FROM ".$this->prefix."repository WHERE version='".$this->secure->checkInt($version)."' AND rtype_id='".$this->secure->checkInt($reptype)."'"; |
140 | $rq =& $this->db->query($query); |
140 | $rq =& $this->db->query($query); |
141 | switch ($format) { |
141 | switch ($format) { |
142 | case 'html': |
142 | case 'html': |
143 | $show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n"; |
143 | $show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n"; |
144 | while ($rq->fetchInto($types)) { |
144 | while ($rq->fetchInto($types)) { |
145 | $show .= "<div class='repository'><input type='checkbox' name='repository[]' value='".$element["rep_id"]."'> ".$this->secure->checkStr($element["repname"],1)." — ".$this->secure->checkStr($element["repinfo"],1)."</div>\n"; |
145 | $show .= "<div class='repository'><input type='checkbox' name='repository[]' value='".$element["rep_id"]."'> ".$this->secure->checkStr($element["repname"],1)." — ".$this->secure->checkStr($element["repinfo"],1)."</div>\n"; |
146 | }
|
146 | }
|
147 | $show .= "</fieldset>\n"; |
147 | $show .= "</fieldset>\n"; |
148 | break; |
148 | break; |
149 | case 'json': |
149 | case 'json': |
150 | //TODO Доделать JSON-вывод списка репозиториев
|
150 | //TODO Доделать JSON-вывод списка репозиториев
|
151 | break; |
151 | break; |
152 | }
|
152 | }
|
153 | 153 | ||
154 | return $show; |
154 | return $show; |
155 | }
|
155 | }
|
156 | 156 | ||
157 | // Добавление поддержки нового apt-дистрибутива
|
157 | // Добавление поддержки нового apt-дистрибутива
|
158 | function addDistribution($distname, $disttype, $distua = 1, $distlogo = 0) { |
158 | function addDistribution($distname, $disttype, $distua = 1, $distlogo = 0) { |
159 | $result = array(); |
159 | $result = array(); |
160 | $sDName = $this->secure->checkStr($distname); |
160 | $sDName = $this->secure->checkStr($distname); |
161 | $sDType = $this->secure->checkInt($disttype); |
161 | $sDType = $this->secure->checkInt($disttype); |
162 | $sDUAgt = $this->secure->checkStr($distua); |
162 | $sDUAgt = $this->secure->checkStr($distua); |
163 | $sDLogo = $this->secure->checkInt($distname); |
163 | $sDLogo = $this->secure->checkInt($distname); |
164 | 164 | ||
165 | $query = "INSERT INTO ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."', distlogo='".$sDLogo."'"; |
165 | $query = "INSERT INTO ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."', distlogo='".$sDLogo."'"; |
166 | $rq =& $this->db->query($query); |
166 | $rq =& $this->db->query($query); |
167 | if (PEAR::isError($this->db)) { |
167 | if (PEAR::isError($this->db)) { |
168 | $result["ERR"] = 1; |
168 | $result["ERR"] = 1; |
169 | $result["ERRINFO"] = $this->db->getMessage(); |
169 | $result["ERRINFO"] = $this->db->getMessage(); |
170 | } else { |
170 | } else { |
171 | $rq->fetchInto($element); |
171 | $rq->fetchInto($element); |
172 | $result["ERR"] = 0; |
172 | $result["ERR"] = 0; |
173 | }
|
173 | }
|
174 | 174 | ||
175 | return $result; |
175 | return $result; |
176 | }
|
176 | }
|
177 | 177 | ||
- | 178 | // Отображение типа дистрибутива
|
|
- | 179 | function showDistTypeForm($name = "dtype",$type = 0) { |
|
- | 180 | $query = "SELECT * FROM ".$this->prefix."dtype"; |
|
- | 181 | $rq =& $this->db->query($query); |
|
- | 182 | $show = "<select name='".$name."' id='".$name."'>\n"; |
|
- | 183 | while ($rq->fetchInto($element)) { |
|
- | 184 | if ($element["dtype_id"] == $type) { |
|
- | 185 | $show .= "<option value='".$element["dtype_id"]."' selected>".$this->secure->checkStr($element["dtype"])."</option>\n"; |
|
- | 186 | } else { |
|
- | 187 | $show .= "<option value='".$element["dtype_id"]."'>".$this->secure->checkStr($element["dtype"])."</option>\n"; |
|
- | 188 | }
|
|
- | 189 | }
|
|
- | 190 | $show .= "</select>"; |
|
- | 191 | ||
- | 192 | return $show; |
|
- | 193 | }
|
|
- | 194 | ||
- | 195 | // Отображение формы создания и редактирования apt-дистрибутива
|
|
- | 196 | function showDistributionForm($distID = 0) { |
|
- | 197 | $sDistID = $this->secure->checkInt($distID); |
|
- | 198 | if ($sDistID != 0) { |
|
- | 199 | // Режим редактирования
|
|
- | 200 | $query = "SELECT * FROM ".$this->prefix."distribution WHERE dist_id='".$sDistID."'"; |
|
- | 201 | $rq =& $this->db->query($query); |
|
- | 202 | $rq->fetchInto($element); |
|
- | 203 | }
|
|
- | 204 | ||
- | 205 | if ($element["distlogo"] == 1) { |
|
- | 206 | $image = "<img src='./img/".$this->secure->checkStr($element["distua"],1).".png' width='32' height='32' id='adm-dist-logo'>"; |
|
- | 207 | } else { |
|
- | 208 | $image = "<img src='./img/empty-logo.png' width='32' height='32' id='adm-dist-logo'>"; |
|
- | 209 | }
|
|
- | 210 | ||
- | 211 | $show = "<fieldset><legend>Дистрибутив</legend>\n"; |
|
- | 212 | $show .= "<div class='inputbox'><label for='dname'>Название дистрибутива</label> <input type='text' name='dname' id='dname' value='".$this->secure->checkStr($element["distname"],1)."'></div>\n"; |
|
- | 213 | $show .= "<div class='inputbox'><label for='dua'>UA дистрибутива</label> <input type='text' name='dua' id='dua' value='".$this->secure->checkStr($element["distua"],1)."'></div>\n"; |
|
- | 214 | $show .= "<div class='inputbox'><label for='dtype'>Тип дистрибутива</label> ".$this->showDistTypeForm("dtype",$element["dtype_id"])."</div>\n"; |
|
- | 215 | $show = "<div class='inputbox'><table><tr><td>Логотип дистрибутива:</td>\n"; |
|
- | 216 | $show .= "<td>".$image."</td>\n<td><input type='file' name='distlogo'></td>\n</tr></table>\n</div>\n"; |
|
- | 217 | $show .= "<div class='inputbox'><input type='submit' value='Отправить дынные'></div>\n</fieldset>\n"; |
|
- | 218 | ||
- | 219 | return $show; |
|
- | 220 | }
|
|
- | 221 | ||
178 | }
|
222 | }
|
179 | 223 | ||
180 | ?>
|
224 | ?>
|
181 | 225 |