Редакция 516 | Редакция 518 | К новейшей редакции | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | 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; |
359 | alex-w | 19 | protected $cookie = NULL; |
304 | alex-w | 20 | |
463 | alex-w | 21 | /** |
22 | * Конструктор класса Core - ядро генератора |
||
23 | * |
||
24 | * @author Alexander Wolf |
||
25 | * @category Core |
||
26 | * |
||
27 | * @param string $database |
||
28 | * @param string $prefix |
||
29 | * @param object $secure |
||
30 | * @param string $cookie |
||
31 | */ |
||
368 | alex-w | 32 | public function __construct($database, $prefix, $secure, $cookie) { |
308 | alex-w | 33 | $this->db = $database; |
34 | $this->prefix = $prefix; |
||
359 | alex-w | 35 | $this->secure = $secure; |
36 | $this->cookie = $cookie; |
||
307 | alex-w | 37 | } |
38 | |||
463 | alex-w | 39 | /** |
40 | * Получение данных о настройке |
||
41 | * |
||
42 | * @author Alexander Wolf |
||
43 | * @category Core |
||
44 | * |
||
45 | * @param string $attr |
||
46 | * @return array |
||
47 | */ |
||
368 | alex-w | 48 | public function getOption($attr) { |
308 | alex-w | 49 | $result = array(); |
315 | alex-w | 50 | $query = "SELECT optvalue FROM ".$this->prefix."settings WHERE opt='".$this->secure->checkStr($attr)."'"; |
314 | alex-w | 51 | $rq =& $this->db->query($query); |
308 | alex-w | 52 | if ($rq->numRows()!=0) { |
53 | $rq->fetchInto($element); |
||
54 | $result["ERR"] = 0; |
||
55 | $result["OptValue"] = $element["optvalue"]; |
||
56 | } else { |
||
57 | $result["ERR"] = 1; |
||
58 | $result["ERRINFO"] = "Empty result"; |
||
59 | } |
||
60 | return $result; |
||
61 | } |
||
62 | |||
463 | alex-w | 63 | /** |
64 | * Установка данных о настройке |
||
65 | * |
||
66 | * @author Alexander Wolf |
||
67 | * @category Core |
||
68 | * |
||
69 | * @param string $attr |
||
70 | * @param string $value |
||
71 | * @return array |
||
72 | */ |
||
368 | alex-w | 73 | public function setOption($attr, $value) { |
359 | alex-w | 74 | $result = array(); |
75 | |||
76 | if ($attr != "passwd") { |
||
77 | $sValue = $this->secure->checkStr($value); |
||
78 | } else { |
||
79 | $sValue = $value; |
||
80 | } |
||
81 | |||
82 | $query = "UPDATE ".$this->prefix."settings SET optvalue='".$sValue."' WHERE opt='".$attr."'"; |
||
83 | $rq =& $this->db->query($query); |
||
84 | if (PEAR::isError($this->db)) { |
||
85 | $result["ERR"] = 1; |
||
86 | $result["ERRINFO"] = $this->db->getMessage(); |
||
87 | } else { |
||
88 | $result["ERR"] = 0; |
||
89 | } |
||
90 | |||
91 | return $result; |
||
92 | } |
||
93 | |||
463 | alex-w | 94 | /** |
95 | * Создание настройки |
||
96 | * |
||
97 | * @author Alexander Wolf |
||
98 | * @category Core |
||
99 | * |
||
100 | * @param string $attr |
||
101 | * @param string $value |
||
102 | * @return array |
||
103 | */ |
||
368 | alex-w | 104 | public function addOption($attr, $value) { |
359 | alex-w | 105 | $result = array(); |
106 | $sValue = $this->secure->checkStr($value); |
||
107 | |||
108 | $query = "INSERT INTO ".$this->prefix."settings SET opt='".$attr."', optvalue='".$sValue."'"; |
||
109 | $rq =& $this->db->query($query); |
||
110 | if (PEAR::isError($this->db)) { |
||
111 | $result["ERR"] = 1; |
||
112 | $result["ERRINFO"] = $this->db->getMessage(); |
||
113 | } else { |
||
114 | $result["ERR"] = 0; |
||
115 | } |
||
116 | |||
117 | return $result; |
||
118 | } |
||
463 | alex-w | 119 | |
120 | /** |
||
467 | alex-w | 121 | * Получение и отображение списка дистрибутвов |
463 | alex-w | 122 | * |
123 | * @author Alexander Wolf |
||
124 | * @category Core |
||
125 | * @deprecated may be deprecated XXX |
||
126 | * |
||
127 | * @param string $name |
||
128 | * @param string $heads |
||
129 | * @param string $info |
||
130 | * @param string $format |
||
131 | * @return string |
||
132 | */ |
||
393 | alex-w | 133 | public function showDistributionList($name, $heads = "", $info = "", $format = 'html') { |
315 | alex-w | 134 | $query = "SELECT * FROM ".$this->prefix."distribution ORDER BY dist_id ASC"; |
317 | alex-w | 135 | $rq =& $this->db->query($query); |
315 | alex-w | 136 | switch ($format) { |
137 | case 'html': |
||
394 | alex-w | 138 | $show = "<fieldset><legend>".$heads."</legend>\n<select id='".$name."' name='".$name."'>\n"; |
390 | alex-w | 139 | $show .= "<option value=''>".$info."</option>\n"; |
315 | alex-w | 140 | while ($rq->fetchInto($element)) { |
141 | $show .= "<option value='".$this->secure->checkInt($element["dist_id"])."'>".$this->secure->checkStr($element["distname"],1)."</option>\n"; |
||
142 | } |
||
317 | alex-w | 143 | $show .= "</select></fieldset>"; |
315 | alex-w | 144 | break; |
145 | case 'json': |
||
317 | alex-w | 146 | $show = '[{value:"",text:"'.$info.'"}'; |
315 | alex-w | 147 | while ($rq->fetchInto($element)) { |
148 | $show .= ',{value:"'.$this->secure->checkInt($element["dist_id"]).'",text:"'.$this->secure->checkStr($element["distname"],1).'"}'; |
||
149 | } |
||
150 | $show .= ']'; |
||
151 | break; |
||
504 | alex-w | 152 | case 'innerhtml': |
153 | $show = "<select id='".$name."' name='".$name."'>\n"; |
||
154 | while ($rq->fetchInto($element)) { |
||
155 | $show .= "<option value='".$this->secure->checkInt($element["dist_id"])."'>".$this->secure->checkStr($element["distname"],1)."</option>\n"; |
||
156 | } |
||
157 | $show .= "</select>"; |
||
158 | break; |
||
506 | alex-w | 159 | case 'list': |
160 | $show = "<ul>"; |
||
161 | while ($rq->fetchInto($element)) { |
||
509 | alex-w | 162 | $show .= "<li>[<a href='".$heads."?mode=".$name."&action=edit&uuid=".$this->secure->checkInt($element["dist_id"])."'>править</a>][<a href='".$heads."?mode=".$name."&action=delete&uuid=".$this->secure->checkInt($element["dist_id"])."'>удалить</a>] ".$this->secure->checkStr($element["distname"],1)."</li>\n"; |
506 | alex-w | 163 | } |
164 | $show .= "</ul>"; |
||
165 | break; |
||
315 | alex-w | 166 | } |
167 | return $show; |
||
168 | } |
||
169 | |||
463 | alex-w | 170 | /** |
171 | * Получение названия дистрибутива |
||
172 | * |
||
173 | * @author Alexander Wolf |
||
174 | * @category Core |
||
175 | * |
||
176 | * @param integer $distID |
||
177 | * @return array |
||
178 | */ |
||
368 | alex-w | 179 | public function getDistName($distID) { |
315 | alex-w | 180 | $result = array(); |
181 | $query = "SELECT distname FROM ".$this->prefix."distribution WHERE dist_id='".$this->secure->checkInt($distID)."'"; |
||
182 | $rq =& $this->db->query($query); |
||
183 | if (PEAR::isError($this->db)) { |
||
184 | $result["ERR"] = 1; |
||
185 | $result["ERRINFO"] = $this->db->getMessage(); |
||
186 | } else { |
||
187 | $rq->fetchInto($element); |
||
188 | $result["ERR"] = 0; |
||
189 | $result["DistName"] = $this->secure->checkStr($element["distname"],1); |
||
190 | } |
||
191 | |||
192 | return $result; |
||
193 | } |
||
194 | |||
463 | alex-w | 195 | /** |
196 | * Получение названия программы, ее версии и описания |
||
197 | * |
||
198 | * @author Alexander Wolf |
||
199 | * @category Core |
||
200 | * |
||
201 | * @param string $attr |
||
202 | * @return string |
||
203 | */ |
||
383 | alex-w | 204 | public function getEngineAttr($attr = 'codename') { |
205 | $cname = $this->getOption($attr); |
||
382 | alex-w | 206 | return $this->secure->checkStr($cname["OptValue"],1); |
381 | alex-w | 207 | } |
208 | |||
463 | alex-w | 209 | /** |
210 | * Получение и отображение списка версий дистрибутива |
||
211 | * |
||
212 | * @author Alexander Wolf |
||
213 | * @category Core |
||
214 | * |
||
215 | * @param string $name |
||
216 | * @param integer $distID |
||
217 | * @param string $format |
||
218 | * @return string |
||
219 | */ |
||
509 | alex-w | 220 | public function showDistVersionsList($name, $distID, $format = 'html', $actor = '') { |
316 | alex-w | 221 | $distname = $this->getDistName($distID); |
509 | alex-w | 222 | if ($distID == 0) { |
223 | $query = "SELECT * FROM ".$this->prefix."version v JOIN ".$this->prefix."distribution d ON v.dist_id=d.dist_id ORDER BY d.dist_id,v.version ASC"; |
||
224 | } else { |
||
225 | $query = "SELECT * FROM ".$this->prefix."version WHERE dist_id='".$this->secure->checkInt($distID)."' ORDER BY version ASC"; |
||
226 | } |
||
317 | alex-w | 227 | $rq =& $this->db->query($query); |
315 | alex-w | 228 | switch ($format) { |
229 | case 'html': |
||
394 | alex-w | 230 | $show = "<fieldset><legend>Версии ".$distname["DistName"]."</legend>\n<select id='".$name."' name='".$name."'>\n"; |
231 | $show .= "<option value=''>Выбери версию ".$distname["DistName"]."</option>\n"; |
||
315 | alex-w | 232 | while ($rq->fetchInto($element)) { |
316 | alex-w | 233 | $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 | 234 | } |
317 | alex-w | 235 | $show .= "</select></fieldset>"; |
315 | alex-w | 236 | break; |
237 | case 'json': |
||
317 | alex-w | 238 | $show = '[{value:"",text:"Выбери версию '.$distname["DistName"].'"}'; |
315 | alex-w | 239 | while ($rq->fetchInto($element)) { |
316 | alex-w | 240 | $show .= ',{value:"'.$this->secure->checkInt($element["version_id"]).'",text:"'.$this->secure->checkStr($element["version"],1).' '.$this->secure->checkStr($element["vname"],1).'"}'; |
315 | alex-w | 241 | } |
242 | $show .= ']'; |
||
243 | break; |
||
509 | alex-w | 244 | case 'list': |
245 | $show = "<ul>\n"; |
||
246 | while ($rq->fetchInto($element)) { |
||
247 | $show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$this->secure->checkInt($element["version_id"])."'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$this->secure->checkInt($element["version_id"])."'>удалить</a>] ".$this->secure->checkStr($element["distname"],1)." ".$this->secure->checkStr($element["version"],1)." “<em>".$this->secure->checkStr($element["vname"],1)."</em>”</li>\n"; |
||
248 | } |
||
249 | $show .= "</ul>"; |
||
250 | break; |
||
315 | alex-w | 251 | } |
252 | return $show; |
||
253 | } |
||
254 | |||
463 | alex-w | 255 | /** |
256 | * Получение и отображение списка секций основного (официального) репозитория |
||
257 | * |
||
258 | * @author Alexander Wolf |
||
259 | * @category Core |
||
260 | * |
||
261 | * @param integer $version |
||
262 | * @param string $format |
||
263 | * @return string |
||
264 | */ |
||
368 | alex-w | 265 | public function showBranchesList($version, $format = 'html') { |
317 | alex-w | 266 | $query = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='1'"; |
267 | $rq =& $this->db->query($query); |
||
268 | $rq->fetchInto($types); |
||
269 | $query = "SELECT s.*,t.rtype FROM ".$this->prefix."section s "; |
||
270 | $query .= "JOIN ".$this->prefix."sect2rep l ON s.sect_id=l.sect_id "; |
||
271 | $query .= "JOIN ".$this->prefix."repository r ON r.rep_id=l.rep_id "; |
||
272 | $query .= "JOIN ".$this->prefix."rtype t ON r.rtype_id=t.rtype_id "; |
||
273 | $query .= "WHERE t.rtype_id='1' AND r.version='".$this->secure->checkInt($version)."'"; |
||
274 | $rq =& $this->db->query($query); |
||
275 | switch ($format) { |
||
276 | case 'html': |
||
277 | $show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n"; |
||
278 | while ($rq->fetchInto($element)) { |
||
493 | alex-w | 279 | $show .= "<div class='sections'><input type='checkbox' name='section[]' value='".$element["sect_id"]."'> ".$this->secure->checkStr($element["secname"],1)." — ".$this->secure->checkStr($element["sectinfo"],1)."</div>\n"; |
317 | alex-w | 280 | } |
281 | $show .= "</fieldset>\n"; |
||
282 | break; |
||
283 | case 'json': |
||
284 | //TODO Доделать JSON-вывод списка секций основного репозитория |
||
285 | break; |
||
286 | } |
||
318 | alex-w | 287 | |
288 | return $show; |
||
317 | alex-w | 289 | } |
290 | |||
463 | alex-w | 291 | /** |
292 | * Получение и отображение списка репозиториев |
||
293 | * |
||
294 | * @author Alexander Wolf |
||
295 | * @category Core |
||
296 | * |
||
297 | * @param integer $version |
||
298 | * @param integer $reptype |
||
299 | * @param string $format |
||
300 | * @return string |
||
301 | */ |
||
368 | alex-w | 302 | public function showRepList($version, $reptype, $format = 'html') { |
406 | alex-w | 303 | $query = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='".$this->secure->checkInt($reptype)."'"; |
317 | alex-w | 304 | $rq =& $this->db->query($query); |
305 | $rq->fetchInto($types); |
||
306 | $query = "SELECT * FROM ".$this->prefix."repository WHERE version='".$this->secure->checkInt($version)."' AND rtype_id='".$this->secure->checkInt($reptype)."'"; |
||
307 | $rq =& $this->db->query($query); |
||
308 | switch ($format) { |
||
309 | case 'html': |
||
310 | $show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n"; |
||
311 | while ($rq->fetchInto($types)) { |
||
320 | alex-w | 312 | $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"; |
317 | alex-w | 313 | } |
314 | $show .= "</fieldset>\n"; |
||
315 | break; |
||
316 | case 'json': |
||
317 | //TODO Доделать JSON-вывод списка репозиториев |
||
318 | break; |
||
319 | } |
||
318 | alex-w | 320 | |
321 | return $show; |
||
317 | alex-w | 322 | } |
323 | |||
463 | alex-w | 324 | /** |
325 | * Добавление поддержки нового apt-дистрибутива |
||
326 | * |
||
327 | * @author Alexander Wolf |
||
328 | * @category Core |
||
329 | * |
||
330 | * @param string $distname |
||
331 | * @param integer $disttype |
||
332 | * @param string $distua |
||
333 | * @param byte $distlogo |
||
334 | * @return array |
||
335 | */ |
||
514 | alex-w | 336 | public function addDistribution($distname, $disttype, $distua = '', $distlogo = 0) { |
321 | alex-w | 337 | $result = array(); |
516 | alex-w | 338 | $sDName = $this->secure->checkStr($distname,1); |
321 | alex-w | 339 | $sDType = $this->secure->checkInt($disttype); |
516 | alex-w | 340 | $sDUAgt = $this->secure->checkStr($distua,1); |
514 | alex-w | 341 | $sDLogo = $this->secure->checkInt($distlogo); |
321 | alex-w | 342 | |
343 | $query = "INSERT INTO ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."', distlogo='".$sDLogo."'"; |
||
344 | $rq =& $this->db->query($query); |
||
345 | if (PEAR::isError($this->db)) { |
||
346 | $result["ERR"] = 1; |
||
347 | $result["ERRINFO"] = $this->db->getMessage(); |
||
515 | alex-w | 348 | } else { |
321 | alex-w | 349 | $result["ERR"] = 0; |
350 | } |
||
351 | |||
352 | return $result; |
||
353 | } |
||
354 | |||
463 | alex-w | 355 | /** |
514 | alex-w | 356 | * Обновление информации о дистрибутиве |
357 | * |
||
358 | * @author Alexander Wolf |
||
359 | * @category Core |
||
360 | * |
||
361 | * @param integer $distID |
||
362 | * @param string $distname |
||
363 | * @param integer $disttype |
||
364 | * @param string $distua |
||
365 | * @param integer $distlogo |
||
366 | * @return array |
||
367 | */ |
||
368 | public function updateDistribution($distID, $distname, $disttype, $distua, $distlogo) { |
||
369 | $result = array(); |
||
370 | $sDID = $this->secure->checkInt($distID); |
||
516 | alex-w | 371 | $sDName = $this->secure->checkStr($distname,1); |
514 | alex-w | 372 | $sDType = $this->secure->checkInt($disttype); |
516 | alex-w | 373 | $sDUAgt = $this->secure->checkStr($distua,1); |
514 | alex-w | 374 | $sDLogo = $this->secure->checkInt($distlogo); |
375 | |||
376 | $query = "UPDATE ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."', distlogo='".$sDLogo."' WHERE dist_id='".$sDID."'"; |
||
377 | $rq =& $this->db->query($query); |
||
378 | if (PEAR::isError($this->db)) { |
||
379 | $result["ERR"] = 1; |
||
380 | $result["ERRINFO"] = $this->db->getMessage(); |
||
515 | alex-w | 381 | } else { |
514 | alex-w | 382 | $result["ERR"] = 0; |
383 | } |
||
384 | |||
385 | return $result; |
||
386 | } |
||
387 | |||
388 | /** |
||
389 | * Удаление информации о дистрибутиве |
||
390 | * |
||
391 | * @author Alexander Wolf |
||
392 | * @category Core |
||
393 | * |
||
394 | * @param integer $distID |
||
395 | * @return array |
||
396 | */ |
||
397 | public function dropDistribution($distID) { |
||
398 | $result = array(); |
||
399 | $sDID = $this->secure->checkInt($distID); |
||
400 | |||
401 | // Удаление дистрибутива |
||
402 | $query = "DELETE FROM ".$this->prefix."distribution WHERE dist_id='".$sDID."'"; |
||
403 | $rq =& $this->db->query($query); |
||
404 | if (PEAR::isError($this->db)) { |
||
405 | $result["ERR"] = 1; |
||
406 | $result["ERRINFO"] = $this->db->getMessage(); |
||
407 | } else { |
||
408 | $rq->fetchInto($element); |
||
409 | $result["ERR"] = 0; |
||
410 | } |
||
411 | |||
412 | // Удаление версий дистрибутива |
||
413 | $query = "DELETE FROM ".$this->prefix."version WHERE dist_id='".$sDID."'"; |
||
414 | $rq =& $this->db->query($query); |
||
415 | if (PEAR::isError($this->db)) { |
||
416 | $result["ERR"] = 1; |
||
417 | $result["ERRINFO"] = $this->db->getMessage(); |
||
418 | } else { |
||
419 | $rq->fetchInto($element); |
||
420 | $result["ERR"] = 0; |
||
421 | } |
||
422 | |||
423 | return $result; |
||
424 | } |
||
425 | |||
426 | /** |
||
463 | alex-w | 427 | * Добавление поддержки новой версии apt-дистрибутива |
428 | * |
||
429 | * @author Alexander Wolf |
||
430 | * @category Core |
||
431 | * |
||
432 | * @param integer $distID |
||
433 | * @param integer $version |
||
434 | * @param string $vname |
||
435 | * @param integer $vcodename |
||
436 | * @return array |
||
437 | */ |
||
368 | alex-w | 438 | public function addDistVersion($distID, $version, $vname = "", $vcodename = "") { |
356 | alex-w | 439 | $result = array(); |
463 | alex-w | 440 | $sDistID = $this->secure->checkInt($distID); |
516 | alex-w | 441 | $sDVersion = $this->secure->checkStr($version,1); |
442 | $sDVName = $this->secure->checkStr($vname,1); |
||
443 | $sDVCName = $this->secure->checkStr($vcodename,1); |
||
356 | alex-w | 444 | |
445 | $query = "INSERT INTO ".$this->prefix."version SET dist_id='".$sDistID."', vname='".$sDVName."', version='".$sDVersion."', vcodename='".$sDVCName."'"; |
||
446 | $rq =& $this->db->query($query); |
||
447 | if (PEAR::isError($this->db)) { |
||
448 | $result["ERR"] = 1; |
||
449 | $result["ERRINFO"] = $this->db->getMessage(); |
||
515 | alex-w | 450 | } else { |
356 | alex-w | 451 | $result["ERR"] = 0; |
452 | } |
||
453 | |||
454 | return $result; |
||
455 | } |
||
358 | alex-w | 456 | |
463 | alex-w | 457 | /** |
514 | alex-w | 458 | * Редактирование информации о версии дистрибутива |
459 | * |
||
460 | * @author Alexander Wolf |
||
461 | * @category Core |
||
462 | * |
||
463 | * @param integer $versionID |
||
464 | * @param string $version |
||
465 | * @param string $vname |
||
466 | * @param string $vcodename |
||
467 | * @return array |
||
468 | */ |
||
469 | public function updateDistVersion($versionID, $version, $vname = "", $vcodename = "") { |
||
470 | $result = array(); |
||
471 | $sVersID = $this->secure->checkInt($versionID); |
||
516 | alex-w | 472 | $sDVersion = $this->secure->checkStr($version,1); |
473 | $sDVName = $this->secure->checkStr($vname,1); |
||
474 | $sDVCName = $this->secure->checkStr($vcodename,1); |
||
514 | alex-w | 475 | |
476 | $query = "UPDATE ".$this->prefix."version SET vname='".$sDVName."', version='".$sDVersion."', vcodename='".$sDVCName."' WHERE version_id='".$sVersID."'"; |
||
477 | $rq =& $this->db->query($query); |
||
478 | if (PEAR::isError($this->db)) { |
||
479 | $result["ERR"] = 1; |
||
480 | $result["ERRINFO"] = $this->db->getMessage(); |
||
515 | alex-w | 481 | } else { |
514 | alex-w | 482 | $result["ERR"] = 0; |
483 | } |
||
484 | |||
485 | return $result; |
||
486 | } |
||
487 | |||
488 | /** |
||
489 | * Удаление информации о версии дистрибутива |
||
490 | * |
||
491 | * @author Alexander Wolf |
||
492 | * @category Core |
||
493 | * |
||
494 | * @param integer $versionID |
||
495 | * @return array |
||
496 | */ |
||
497 | public function dropDistVersion($versionID) { |
||
498 | $result = array(); |
||
499 | $sVersID = $this->secure->checkInt($versionID); |
||
500 | |||
501 | // Удаление версии дистрибутива |
||
502 | $query = "DELETE FROM ".$this->prefix."version WHERE version_id='".$sVersID."'"; |
||
503 | $rq =& $this->db->query($query); |
||
504 | if (PEAR::isError($this->db)) { |
||
505 | $result["ERR"] = 1; |
||
506 | $result["ERRINFO"] = $this->db->getMessage(); |
||
515 | alex-w | 507 | } else { |
514 | alex-w | 508 | $result["ERR"] = 0; |
509 | } |
||
510 | |||
511 | // Удаление репозиториев этой версии дистрибутива |
||
512 | $query = "DELETE FROM ".$this->prefix."repository WHERE version='".$sVersID."'"; |
||
513 | $rq =& $this->db->query($query); |
||
514 | if (PEAR::isError($this->db)) { |
||
515 | $result["ERR"] = 1; |
||
516 | $result["ERRINFO"] = $this->db->getMessage(); |
||
517 | alex-w | 517 | } else { |
514 | alex-w | 518 | $result["ERR"] = 0; |
519 | } |
||
520 | |||
521 | return $result; |
||
522 | } |
||
523 | |||
524 | /** |
||
463 | alex-w | 525 | * Отображение типа дистрибутива |
526 | * |
||
527 | * @author Alexander Wolf |
||
528 | * @category Core |
||
529 | * |
||
530 | * @param string $name |
||
531 | * @param byte $type |
||
532 | * @return string |
||
533 | */ |
||
368 | alex-w | 534 | public function showDistTypeForm($name = "dtype",$type = 0) { |
329 | alex-w | 535 | $query = "SELECT * FROM ".$this->prefix."dtype"; |
536 | $rq =& $this->db->query($query); |
||
537 | $show = "<select name='".$name."' id='".$name."'>\n"; |
||
538 | while ($rq->fetchInto($element)) { |
||
347 | alex-w | 539 | if ($element["type_id"] == $type) { |
540 | $show .= "<option value='".$element["type_id"]."' selected>".$this->secure->checkStr($element["type"],1)."</option>\n"; |
||
329 | alex-w | 541 | } else { |
347 | alex-w | 542 | $show .= "<option value='".$element["type_id"]."'>".$this->secure->checkStr($element["type"],1)."</option>\n"; |
329 | alex-w | 543 | } |
544 | } |
||
545 | $show .= "</select>"; |
||
546 | |||
547 | return $show; |
||
548 | } |
||
549 | |||
463 | alex-w | 550 | /** |
551 | * Отображение формы создания и редактирования apt-дистрибутива |
||
552 | * |
||
553 | * @author Alexander Wolf |
||
554 | * @category Core |
||
555 | * |
||
556 | * @param integer $distID |
||
557 | * @return string |
||
558 | */ |
||
511 | alex-w | 559 | public function showDistributionForm($distID = 0, $info = '') { |
329 | alex-w | 560 | $sDistID = $this->secure->checkInt($distID); |
511 | alex-w | 561 | $sInfo = $this->secure->checkStr($info, 1); |
562 | if ($sInfo == "") { |
||
563 | $sInfo = "Дистрибутив"; |
||
564 | } |
||
329 | alex-w | 565 | if ($sDistID != 0) { |
566 | // Режим редактирования |
||
567 | $query = "SELECT * FROM ".$this->prefix."distribution WHERE dist_id='".$sDistID."'"; |
||
568 | $rq =& $this->db->query($query); |
||
569 | $rq->fetchInto($element); |
||
570 | } |
||
571 | |||
572 | if ($element["distlogo"] == 1) { |
||
380 | alex-w | 573 | $image = "<img src='./img/d/".$this->secure->checkStr($element["distua"],1).".png' width='32' height='32' id='adm-dist-logo' alt='Логотип дистрибутива ".$this->secure->checkStr($element["distname"],1)."' title='Логотип дистрибутива ".$this->secure->checkStr($element["distname"],1)."'>"; |
329 | alex-w | 574 | } else { |
380 | alex-w | 575 | $image = "<img src='./img/d/empty-logo.png' width='32' height='32' id='adm-dist-logo' alt='Логотип дистрибутива' title='Логотип дистрибутива не загружен'>"; |
329 | alex-w | 576 | } |
577 | |||
511 | alex-w | 578 | $show = "<fieldset><legend>".$sInfo."</legend>\n"; |
350 | alex-w | 579 | $show .= "<div class='inputbox'><label for='dname'>Название дистрибутива:</label> <input type='text' name='dname' id='dname' value='".$this->secure->checkStr($element["distname"],1)."'></div>\n"; |
580 | $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"; |
||
581 | $show .= "<div class='inputbox'><label for='dtype'>Тип дистрибутива:</label> ".$this->showDistTypeForm("dtype",$element["dtype_id"])."</div>\n"; |
||
348 | alex-w | 582 | $show .= "<div class='inputbox'><table><tr><td class='td-name'>Логотип дистрибутива:</td>\n"; |
329 | alex-w | 583 | $show .= "<td>".$image."</td>\n<td><input type='file' name='distlogo'></td>\n</tr></table>\n</div>\n"; |
350 | alex-w | 584 | $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n"; |
329 | alex-w | 585 | |
586 | return $show; |
||
587 | } |
||
588 | |||
358 | alex-w | 589 | // sourses.list |
423 | alex-w | 590 | public function showSourcesList($distID,$versID,$sectIDs,$repIDs) { |
591 | //TODO Написать генератор sources.list |
||
358 | alex-w | 592 | } |
593 | |||
463 | alex-w | 594 | /** |
595 | * Проверка пароля (из формы авторизации) |
||
596 | * |
||
597 | * @author Alexander Wolf |
||
598 | * @category Core |
||
599 | * |
||
600 | * @param string $word |
||
601 | * @return array |
||
602 | */ |
||
368 | alex-w | 603 | public function checkSign($word) { |
359 | alex-w | 604 | $result = array(); |
605 | |||
606 | $sHash = $this->secure->encryptStr($word); |
||
607 | $pwd = $this->getOption("passwd"); |
||
608 | if ($sHash == $pwd["OptValue"]) { |
||
609 | $result["ERR"] = 0; |
||
610 | $result["Location"] = "manager.php"; |
||
611 | setcookie($this->cookie, $sHash); |
||
612 | } else { |
||
613 | $result["ERR"] = 1; |
||
614 | $result["ERRINFO"] = "Password not valid"; |
||
368 | alex-w | 615 | $result["Location"] = "manager.php?error=1"; |
359 | alex-w | 616 | } |
617 | |||
618 | return $result; |
||
358 | alex-w | 619 | } |
357 | alex-w | 620 | |
463 | alex-w | 621 | /** |
622 | * Проверка пароля (из cookies) |
||
623 | * |
||
624 | * @author Alexander Wolf |
||
625 | * @category Core |
||
626 | * |
||
627 | * @param string $hash |
||
628 | * @return array |
||
629 | */ |
||
368 | alex-w | 630 | public function checkCookieSign($hash) { |
359 | alex-w | 631 | $result = array(); |
632 | |||
633 | $pwd = $this->getOption("passwd"); |
||
634 | if ($hash == $pwd["OptValue"]) { |
||
635 | $result["ERR"] = 0; |
||
636 | } else { |
||
637 | $result["ERR"] = 1; |
||
638 | $result["ERRINFO"] = "Hash not valid"; |
||
368 | alex-w | 639 | $result["Location"] = "manager.php"; |
359 | alex-w | 640 | } |
641 | |||
642 | return $result; |
||
643 | } |
||
644 | |||
463 | alex-w | 645 | /** |
646 | * Форма ввода пароля |
||
647 | * |
||
648 | * @author Alexander Wolf |
||
649 | * @category Core |
||
650 | * |
||
651 | * @return string |
||
652 | */ |
||
368 | alex-w | 653 | public function showSigninForm() { |
425 | alex-w | 654 | $show = "<div id='regform'>"; |
655 | $show .= "<form action='process.php' method='post'>\n"; |
||
368 | alex-w | 656 | $show .= "<fieldset><legend>Пароль</legend>\n"; |
657 | $show .= "<input type='hidden' name='mode' value='authorize'>\n"; |
||
427 | alex-w | 658 | $show .= "<input type='password' name='word' value=''>\n"; |
368 | alex-w | 659 | $show .= "<input type='submit' value=' Войти '>\n"; |
425 | alex-w | 660 | $show .= "</fieldset>\n</form></div>\n"; |
368 | alex-w | 661 | |
662 | return $show; |
||
663 | } |
||
664 | |||
463 | alex-w | 665 | /** |
666 | * Обновление пароля |
||
667 | * |
||
668 | * @author Alexander Wolf |
||
669 | * @category Core |
||
670 | * |
||
671 | * @param string $word1 |
||
672 | * @param string $word2 |
||
673 | * @return array |
||
674 | */ |
||
368 | alex-w | 675 | public function updatePassword($word1, $word2) { |
359 | alex-w | 676 | $result = array(); |
677 | |||
678 | if ($word1 == $word2) { |
||
679 | $sWord = $this->secure->encryptStr($word1); |
||
680 | $r = $this->setOption("passwd", $sWord); |
||
681 | $result = $r; |
||
682 | } else { |
||
683 | $result["ERR"] = 1; |
||
684 | $result["ERRINFO"] = "Passwords is mismatch"; |
||
685 | } |
||
686 | |||
687 | return $result; |
||
688 | } |
||
689 | |||
504 | alex-w | 690 | /** |
509 | alex-w | 691 | * Отображение формы создания и редактирования версии apt-дистрибутива |
504 | alex-w | 692 | * |
693 | * @author Alexander Wolf |
||
694 | * @category Core |
||
695 | * |
||
696 | * @param string $name |
||
697 | * @param string $actor |
||
698 | * @param integer $versionID |
||
699 | * @return string |
||
700 | */ |
||
511 | alex-w | 701 | public function showDistVersionsForm($versionID = 0, $info = '') { |
509 | alex-w | 702 | $sVersionID = $this->secure->checkInt($versionID); |
511 | alex-w | 703 | $sInfo = $this->secure->checkStr($info, 1); |
704 | if ($sInfo == "") { |
||
705 | $sInfo = "Версия дистрибутива"; |
||
706 | } |
||
509 | alex-w | 707 | if ($sVersionID != 0) { |
708 | // Режим редактирования |
||
497 | alex-w | 709 | $query = "SELECT * FROM ".$this->prefix."version v JOIN ".$this->prefix."distribution d ON v.dist_id=d.dist_id WHERE v.version_id='".$versionID."'"; |
710 | $rq =& $this->db->query($query); |
||
711 | $rq->fetchInto($element); |
||
509 | alex-w | 712 | } |
713 | |||
511 | alex-w | 714 | $show = "<fieldset><legend>".$sInfo."</legend>\n"; |
510 | alex-w | 715 | if ($sVersionID != 0) { |
716 | $show .= "<div class='inputbox'><label for='distname'>Дистрибутив:</label> <input type='text' name='distname' value='".$this->secure->checkStr($element["distname"],1)."' readonly='readonly'></div>\n"; |
||
717 | } else { |
||
718 | $show .= "<div class='inputbox'><label for='distname'>Дистрибутив:</label> ".$this->showDistributionList("distname", "", "", "innerhtml")."</div>\n"; |
||
719 | } |
||
509 | alex-w | 720 | $show .= "<div class='inputbox'><label for='vname'>Название версии:</label> <input type='text' name='vname' value='".$this->secure->checkStr($element["vname"],1)."'></div>\n"; |
721 | $show .= "<div class='inputbox'><label for='version'>Номер версии:</label> <input type='text' name='version' value='".$this->secure->checkStr($element["version"],1)."'></div>\n"; |
||
722 | $show .= "<div class='inputbox'><label for='vcodename'>Кодовое имя версии:</label> <input type='text' name='vcodename' value='".$this->secure->checkStr($element["vcodename"],1)."'></div>\n"; |
||
723 | $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div></fieldset>\n"; |
||
495 | alex-w | 724 | |
504 | alex-w | 725 | return $show; |
509 | alex-w | 726 | } |
504 | alex-w | 727 | |
304 | alex-w | 728 | } |
729 | |||
356 | alex-w | 730 | ?> |