Редакция 315 | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | 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') { |
||
316 | alex-w | 86 | $distname = $this->getDistName($distID); |
315 | alex-w | 87 | $query = "SELECT * FROM ".$this->prefix."version WHERE dist_id='".$this->secure->checkInt($distID)."' ORDER BY version ASC"; |
88 | switch ($format) { |
||
89 | case 'html': |
||
316 | alex-w | 90 | $show = "<label for='".$name."'>Версии ".$distname["DistName"]."</label> <select id='".$name."' name='".$name."'>\n"; |
315 | alex-w | 91 | $rq =& $this->db->query($query); |
92 | while ($rq->fetchInto($element)) { |
||
316 | alex-w | 93 | $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 | 94 | } |
95 | $show .= "</select>"; |
||
96 | break; |
||
97 | case 'json': |
||
316 | alex-w | 98 | $show = '[{value:"",text:"Выбери версию '.$distname["DistName"].'"}'; |
315 | alex-w | 99 | $rq =& $this->db->query($query); |
100 | while ($rq->fetchInto($element)) { |
||
316 | alex-w | 101 | $show .= ',{value:"'.$this->secure->checkInt($element["version_id"]).'",text:"'.$this->secure->checkStr($element["version"],1).' '.$this->secure->checkStr($element["vname"],1).'"}'; |
315 | alex-w | 102 | } |
103 | $show .= ']'; |
||
104 | break; |
||
105 | } |
||
106 | return $show; |
||
107 | } |
||
108 | |||
304 | alex-w | 109 | } |
110 | |||
111 | ?> |