Редакция 345 | Редакция 347 | К новейшей редакции | Авторство | Сравнить с предыдущей | Последнее изменение | Открыть журнал | Скачать | RSS
<?php
/**
*
* Codename: ant-ng - generator of sources.list for Debian and
* distributives, based on Debian
* http://alex-w.org.ru/p/antng/
*
* Copyright (c) 2009 Alexander Wolf
* Dual licensed under the MIT and GNU LGPL licenses.
* http://alex-w.org.ru/p/antng/license
*
*/
class Core {
protected $db = NULL;
protected $prefix = NULL;
protected $secure = NULL;
function __construct($database, $prefix, $secure) {
$this->db = $database;
$this->prefix = $prefix;
$this->secure = $secure;
}
// Получение данных о настройке
function getOption($attr) {
$result = array();
$query = "SELECT optvalue FROM ".$this->prefix."settings WHERE opt='".$this->secure->checkStr($attr)."'";
$rq =& $this->db->query($query);
if ($rq->numRows()!=0) {
$rq->fetchInto($element);
$result["ERR"] = 0;
$result["OptValue"] = $element["optvalue"];
} else {
$result["ERR"] = 1;
$result["ERRINFO"] = "Empty result";
}
return $result;
}
// Получение и отображение списка дистрибутивов
function showDistributionList($name, $info = "", $format = 'html') {
$query = "SELECT * FROM ".$this->prefix."distribution ORDER BY dist_id ASC";
$rq =& $this->db->query($query);
switch ($format) {
case 'html':
$show = "<fieldset><legend>".$info."</legend>\n<select id='".$name."' name='".$name."'>\n";
while ($rq->fetchInto($element)) {
$show .= "<option value='".$this->secure->checkInt($element["dist_id"])."'>".$this->secure->checkStr($element["distname"],1)."</option>\n";
}
$show .= "</select></fieldset>";
break;
case 'json':
$show = '[{value:"",text:"'.$info.'"}';
while ($rq->fetchInto($element)) {
$show .= ',{value:"'.$this->secure->checkInt($element["dist_id"]).'",text:"'.$this->secure->checkStr($element["distname"],1).'"}';
}
$show .= ']';
break;
}
return $show;
}
// Получение названия дистрибутива
function getDistName($distID) {
$result = array();
$query = "SELECT distname FROM ".$this->prefix."distribution WHERE dist_id='".$this->secure->checkInt($distID)."'";
$rq =& $this->db->query($query);
if (PEAR::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$rq->fetchInto($element);
$result["ERR"] = 0;
$result["DistName"] = $this->secure->checkStr($element["distname"],1);
}
return $result;
}
// Получение и отображение списка версий дистрибутива
function showDistVersionsList($name, $distID, $format = 'html') {
$distname = $this->getDistName($distID);
$query = "SELECT * FROM ".$this->prefix."version WHERE dist_id='".$this->secure->checkInt($distID)."' ORDER BY version ASC";
$rq =& $this->db->query($query);
switch ($format) {
case 'html':
$show = "<fieldset><legend>Версии ".$distname["DistName"]."</legend>\n<select id='".$name."' name='".$name."'>\n";
while ($rq->fetchInto($element)) {
$show .= "<option value='".$this->secure->checkInt($element["version_id"])."'>".$this->secure->checkStr($element["version"],1)." ".$this->secure->checkStr($element["vname"],1)."</option>\n";
}
$show .= "</select></fieldset>";
break;
case 'json':
$show = '[{value:"",text:"Выбери версию '.$distname["DistName"].'"}';
while ($rq->fetchInto($element)) {
$show .= ',{value:"'.$this->secure->checkInt($element["version_id"]).'",text:"'.$this->secure->checkStr($element["version"],1).' '.$this->secure->checkStr($element["vname"],1).'"}';
}
$show .= ']';
break;
}
return $show;
}
// Получение и отображение списка секций основного (официального) репозитория
function showBranchesList($version, $format = 'html') {
$query = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='1'";
$rq =& $this->db->query($query);
$rq->fetchInto($types);
$query = "SELECT s.*,t.rtype FROM ".$this->prefix."section s ";
$query .= "JOIN ".$this->prefix."sect2rep l ON s.sect_id=l.sect_id ";
$query .= "JOIN ".$this->prefix."repository r ON r.rep_id=l.rep_id ";
$query .= "JOIN ".$this->prefix."rtype t ON r.rtype_id=t.rtype_id ";
$query .= "WHERE t.rtype_id='1' AND r.version='".$this->secure->checkInt($version)."'";
$rq =& $this->db->query($query);
switch ($format) {
case 'html':
$show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n";
while ($rq->fetchInto($element)) {
$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";
}
$show .= "</fieldset>\n";
break;
case 'json':
//TODO Доделать JSON-вывод списка секций основного репозитория
break;
}
return $show;
}
// Получение и отображение списка репозиториев
function showRepList($version, $reptype, $format = 'html') {
$query = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='1'";
$rq =& $this->db->query($query);
$rq->fetchInto($types);
$query = "SELECT * FROM ".$this->prefix."repository WHERE version='".$this->secure->checkInt($version)."' AND rtype_id='".$this->secure->checkInt($reptype)."'";
$rq =& $this->db->query($query);
switch ($format) {
case 'html':
$show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n";
while ($rq->fetchInto($types)) {
$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";
}
$show .= "</fieldset>\n";
break;
case 'json':
//TODO Доделать JSON-вывод списка репозиториев
break;
}
return $show;
}
// Добавление поддержки нового apt-дистрибутива
function addDistribution($distname, $disttype, $distua = 1, $distlogo = 0) {
$result = array();
$sDName = $this->secure->checkStr($distname);
$sDType = $this->secure->checkInt($disttype);
$sDUAgt = $this->secure->checkStr($distua);
$sDLogo = $this->secure->checkInt($distname);
$query = "INSERT INTO ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."', distlogo='".$sDLogo."'";
$rq =& $this->db->query($query);
if (PEAR::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$rq->fetchInto($element);
$result["ERR"] = 0;
}
return $result;
}
// Отображение типа дистрибутива
function showDistTypeForm($name = "dtype",$type = 0) {
$query = "SELECT * FROM ".$this->prefix."dtype";
$rq =& $this->db->query($query);
$show = "<select name='".$name."' id='".$name."'>\n";
while ($rq->fetchInto($element)) {
if ($element["dtype_id"] == $type) {
$show .= "<option value='".$element["dtype_id"]."' selected>".$this->secure->checkStr($element["dtype"],1)."</option>\n";
} else {
$show .= "<option value='".$element["dtype_id"]."'>".$this->secure->checkStr($element["dtype"],1)."</option>\n";
}
}
$show .= "</select>";
return $show;
}
// Отображение формы создания и редактирования apt-дистрибутива
function showDistributionForm($distID = 0) {
$sDistID = $this->secure->checkInt($distID);
if ($sDistID != 0) {
// Режим редактирования
$query = "SELECT * FROM ".$this->prefix."distribution WHERE dist_id='".$sDistID."'";
$rq =& $this->db->query($query);
$rq->fetchInto($element);
}
if ($element["distlogo"] == 1) {
$image = "<img src='./img/".$this->secure->checkStr($element["distua"],1).".png' width='32' height='32' id='adm-dist-logo'>";
} else {
$image = "<img src='./img/empty-logo.png' width='32' height='32' id='adm-dist-logo'>";
}
$show = "<fieldset><legend>Дистрибутив</legend>\n";
$show .= "<div class='inputbox'><label for='dname'>Название дистрибутива</label> <input type='text' name='dname' id='dname' value='".$this->secure->checkStr($element["distname"],1)."'></div>\n";
$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";
$show .= "<div class='inputbox'><label for='dtype'>Тип дистрибутива</label> ".$this->showDistTypeForm("dtype",$element["dtype_id"])."</div>\n";
$show .= "<div class='inputbox'><table><tr><td>Логотип дистрибутива:</td>\n";
$show .= "<td>".$image."</td>\n<td><input type='file' name='distlogo'></td>\n</tr></table>\n</div>\n";
$show .= "<div class='inputbox'><input type='submit' value='Отправить дынные'></div>\n</fieldset>\n";
return $show;
}
}
?>