Редакция 598 |
К новейшей редакции |
Авторство |
Сравнить с предыдущей |
Последнее изменение |
Открыть журнал
| Скачать
| RSS
<?php
/**
*
* Codename: ant-ng - generator of sources.list for apt-distributives
* 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;
protected $cookie = NULL;
/**
* Конструктор класса Core - ядро генератора
*
* @author Alexander Wolf
* @category Core
*
* @param string $database
* @param string $prefix
* @param object $secure
* @param string $cookie
*/
public function __construct
($database, $prefix, $secure, $cookie) {
$this->db = $database;
$this->prefix = $prefix;
$this->secure = $secure;
$this->cookie = $cookie;
}
/**
* Получение данных о настройке
*
* @author Alexander Wolf
* @category Core
*
* @param string $attr
* @return array
*/
public 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;
}
/**
* Установка данных о настройке
*
* @author Alexander Wolf
* @category Core
*
* @param string $attr
* @param string $value
* @return array
*/
public function setOption
($attr, $value) {
$result = array();
if ($attr != "passwd") {
$sValue = $this->secure->checkStr($value);
} else {
$sValue = $value;
}
$query = "UPDATE ".$this->prefix."settings SET optvalue='".$sValue."' WHERE opt='".$attr."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Создание настройки
*
* @author Alexander Wolf
* @category Core
*
* @param string $attr
* @param string $value
* @return array
*/
public function addOption
($attr, $value) {
$result = array();
$sValue = $this->secure->checkStr($value);
$query = "INSERT INTO ".$this->prefix."settings SET opt='".$attr."', optvalue='".$sValue."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Получение и отображение списка дистрибутвов
*
* @author Alexander Wolf
* @category Core
* @deprecated may be deprecated XXX
*
* @param string $name
* @param string $heads
* @param string $info
* @param string $format
* @return string
*/
public function showDistributionList
($name, $heads = "", $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>".$heads."</legend>\n<select id='".$name."' name='".$name."'>\n";
$show .= "<option value=''>".$info."</option>\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;
case 'innerhtml':
$show = "<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>";
break;
case 'list':
$show = "<ul>";
while ($rq->fetchInto($element)) {
$show .= "<li>[<a href='".$heads."?mode=".$name."&action=edit&uuid=".$this->secure->checkInt($element["dist_id"])."' class='edit'>править</a>][<a href='".$heads."?mode=".$name."&action=delete&uuid=".$this->secure->checkInt($element["dist_id"])."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["distname"],1)."</li>\n";
}
$show .= "</ul>";
break;
}
return $show;
}
/**
* Получение названия дистрибутива
*
* @author Alexander Wolf
* @category Core
*
* @param integer $distID
* @return array
*/
public 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;
}
/**
* Получение названия программы, ее версии и описания
*
* @author Alexander Wolf
* @category Core
*
* @param string $attr
* @return string
*/
public function getEngineAttr
($attr = 'codename') {
$cname = $this->getOption($attr);
return $this->secure->checkStr($cname["OptValue"],1);
}
/**
* Получение и отображение списка версий дистрибутива
*
* @author Alexander Wolf
* @category Core
*
* @param string $name
* @param integer $distID
* @param string $format
* @return string
*/
public function showDistVersionsList
($name, $distID, $format = 'html', $actor = '') {
$distname = $this->getDistName($distID);
if ($distID == 0) {
$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";
} else {
$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";
$show .= "<option value=''>Выбери версию ".$distname["DistName"]."</option>\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;
case 'list':
$show = "<ul>\n";
while ($rq->fetchInto($element)) {
$show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$this->secure->checkInt($element["version_id"])."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$this->secure->checkInt($element["version_id"])."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["distname"],1)." ".$this->secure->checkStr($element["version"],1)." “<em>".$this->secure->checkStr($element["vname"],1)."</em>”</li>\n";
}
$show .= "</ul>";
break;
}
return $show;
}
/**
* Получение и отображение списка секций основного (официального) репозитория
*
* @author Alexander Wolf
* @category Core
*
* @param integer $version
* @param string $format
* @return string
*/
public 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["sectinfo"],1)."</div>\n";
}
$show .= "</fieldset>\n";
break;
case 'json':
//TODO Доделать JSON-вывод списка секций основного репозитория
break;
}
return $show;
}
/**
* Получение и отображение списка репозиториев
*
* @author Alexander Wolf
* @category Core
*
* @param integer $version
* @param integer $reptype
* @param string $format
* @return string
*/
public function showRepList
($version, $reptype, $format = 'html') {
$query = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='".$this->secure->checkInt($reptype)."'";
$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-дистрибутива
*
* @author Alexander Wolf
* @category Core
*
* @param string $distname
* @param integer $disttype
* @param string $distua
* @param byte $distlogo
* @return array
*/
public function addDistribution
($distname, $disttype, $distua = '', $distlogo = 0) {
$result = array();
$sDName = $this->secure->checkStr($distname);
$sDType = $this->secure->checkInt($disttype);
$sDUAgt = $this->secure->checkStr($distua);
$sDLogo = $this->secure->checkInt($distlogo);
$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 {
$result["ERR"] = 0;
}
return $result;
}
/**
* Обновление информации о дистрибутиве
*
* @author Alexander Wolf
* @category Core
*
* @param integer $distID
* @param string $distname
* @param integer $disttype
* @param string $distua
* @param integer $distlogo
* @return array
*/
public function updateDistribution
($distID, $distname, $disttype, $distua, $distlogo = 0) {
$result = array();
$sDID = $this->secure->checkInt($distID);
$sDName = $this->secure->checkStr($distname);
$sDType = $this->secure->checkInt($disttype);
$sDUAgt = $this->secure->checkStr($distua);
$sDLogo = $this->secure->checkInt($distlogo);
if ($sDLogo!=0) {
$query = "UPDATE ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."', distlogo='".$sDLogo."' WHERE dist_id='".$sDID."'";
} else {
$query = "UPDATE ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."' WHERE dist_id='".$sDID."'";
}
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Удаление информации о дистрибутиве
*
* @author Alexander Wolf
* @category Core
*
* @param integer $distID
* @return array
*/
public function dropDistribution
($distID) {
$result = array();
$sDID = $this->secure->checkInt($distID);
// Удаление дистрибутива
$query = "DELETE FROM ".$this->prefix."distribution WHERE dist_id='".$sDID."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
// Удаление версий дистрибутива
$query = "DELETE FROM ".$this->prefix."version WHERE dist_id='".$sDID."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Добавление поддержки новой версии apt-дистрибутива
*
* @author Alexander Wolf
* @category Core
*
* @param integer $distID
* @param integer $version
* @param string $vname
* @param integer $vcodename
* @return array
*/
public function addDistVersion
($distID, $version, $vname = "", $vcodename = "") {
$result = array();
$sDistID = $this->secure->checkInt($distID);
$sDVersion = $this->secure->checkStr($version);
$sDVName = $this->secure->checkStr($vname);
$sDVCName = $this->secure->checkStr($vcodename);
$query = "INSERT INTO ".$this->prefix."version SET dist_id='".$sDistID."', vname='".$sDVName."', version='".$sDVersion."', vcodename='".$sDVCName."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Редактирование информации о версии дистрибутива
*
* @author Alexander Wolf
* @category Core
*
* @param integer $versionID
* @param string $version
* @param string $vname
* @param string $vcodename
* @return array
*/
public function updateDistVersion
($versionID, $version, $vname = "", $vcodename = "") {
$result = array();
$sVersID = $this->secure->checkInt($versionID);
$sDVersion = $this->secure->checkStr($version,1);
$sDVName = $this->secure->checkStr($vname,1);
$sDVCName = $this->secure->checkStr($vcodename,1);
$query = "UPDATE ".$this->prefix."version SET vname='".$sDVName."', version='".$sDVersion."', vcodename='".$sDVCName."' WHERE version_id='".$sVersID."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Удаление информации о версии дистрибутива
*
* @author Alexander Wolf
* @category Core
*
* @param integer $versionID
* @return array
*/
public function dropDistVersion
($versionID) {
$result = array();
$sVersID = $this->secure->checkInt($versionID);
// Удаление версии дистрибутива
$query = "DELETE FROM ".$this->prefix."version WHERE version_id='".$sVersID."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
// Удаление репозиториев этой версии дистрибутива
$query = "DELETE FROM ".$this->prefix."repository WHERE version='".$sVersID."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Отображение типа дистрибутива
*
* @author Alexander Wolf
* @category Core
*
* @param string $name
* @param byte $type
* @return string
*/
public 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["type_id"] == $type) {
$show .= "<option value='".$element["type_id"]."' selected>".$this->secure->checkStr($element["type"],1)."</option>\n";
} else {
$show .= "<option value='".$element["type_id"]."'>".$this->secure->checkStr($element["type"],1)."</option>\n";
}
}
$show .= "</select>";
return $show;
}
/**
* Отображение формы создания и редактирования apt-дистрибутива
*
* @author Alexander Wolf
* @category Core
*
* @param integer $distID
* @return string
*/
public function showDistributionForm
($distID = 0, $info = '') {
$sDistID = $this->secure->checkInt($distID);
$sInfo = $this->secure->checkStr($info, 1);
if ($sInfo == "") {
$sInfo = "Дистрибутив";
}
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/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)."'>";
} else {
$image = "<img src='./img/d/empty-logo.png' width='32' height='32' id='adm-dist-logo' alt='Логотип дистрибутива' title='Логотип дистрибутива не загружен'>";
}
$show = "<fieldset><legend>".$sInfo."</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["disttype"])."</div>\n";
$show .= "<div class='inputbox'><table><tr><td class='td-name'>Логотип дистрибутива:</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;
}
// sourses.list
public function showSourcesList
($distID,$versID,$sectIDs,$repIDs) {
//TODO Написать генератор sources.list
}
/**
* Показывает список секций
*
* @author Alexander Wolf
* @category Core
*
* @param string $name
* @param string $actor
* @param string $format
* @return string
*/
public function showSectionsList
($name, $actor, $format = 'html') {
switch($format) {
case 'html':
$query = "SELECT * FROM ".$this->prefix."section";
$rq =& $this->db->query($query);
$show = "<ul>\n";
while ($rq->fetchInto($element)) {
$show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$element["sect_id"]."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$element["sect_id"]."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["secname"],1)."</li>\n";
}
$show .= "</ul>";
break;
case 'innerhtml':
$show = "";
$repID = $this->secure->checkInt($actor);
if ($repID==0) {
$query = "SELECT * FROM ".$this->prefix."section";
$rq =& $this->db->query($query);
while ($rq->fetchInto($element)) {
$show .= "<input type='checkbox' name='".$name."[]' value='".$element["sect_id"]."'> ".$this->secure->checkStr($element["secname"],1)." ";
}
} else {
$query = "SELECT * FROM ".$this->prefix."section s JOIN ".$this->prefix."sect2rep r ON s.sect_id=r.sect_id WHERE r.rep_id='$repID'";
$rq =& $this->db->query($query);
while ($rq->fetchInto($element)) {
$show .= "<input type='checkbox' name='".$name."[]' value='".$element["sect_id"]."' checked> ".$this->secure->checkStr($element["secname"],1)." ";
}
$query = "SELECT s.* FROM ".$this->prefix."section s WHERE s.sect_id NOT IN (SELECT sect_id FROM ".$this->prefix."sect2rep WHERE rep_id='$repID')";
$rq =& $this->db->query($query);
while ($rq->fetchInto($element)) {
$show .= "<input type='checkbox' name='".$name."[]' value='".$element["sect_id"]."'> ".$this->secure->checkStr($element["secname"],1)." ";
}
}
break;
}
return $show;
}
/**
* Вывод формы редактирования/добавления секций
*
* @author Alexander Wolf
* @category Core
*
* @param integer $sectionID
* @param string $info
* @return string
*/
public function showSectionsForm
($sectionID = 0, $info = "") {
$sSectID = $this->secure->checkInt($sectionID);
$sInfo = $this->secure->checkStr($info, 1);
if ($sInfo == "") {
$sInfo = "Секция";
}
if ($sSectID != 0) {
// Режим редактирования
$query = "SELECT * FROM ".$this->prefix."section WHERE sect_id='".$sSectID."'";
$rq =& $this->db->query($query);
$rq->fetchInto($element);
}
$show = "<fieldset><legend>".$sInfo."</legend>\n";
$show .= "<div class='inputbox'><label for='sname'>Название секции:</label> <input type='text' name='sname' id='sname' value='".$this->secure->checkStr($element["secname"],1)."'></div>\n";
$show .= "<div class='inputbox'><label for='sinfo'>Описание секции:</label> <input type='text' name='sinfo' id='sinfo' value='".$this->secure->checkStr($element["sectinfo"],1)."'></div>\n";
$show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
return $show;
}
/**
* Обновление информации о секции
*
* @author Alexander Wolf
* @category Core
*
* @param integer $sectionID
* @param string $sname
* @param string $sinfo
* @return array
*/
public function updateSection
($sectionID, $sname, $sinfo = "") {
$result = array();
$sSectID = $this->secure->checkInt($sectionID);
$sSName = $this->secure->checkStr($sname);
$sSInfo = $this->secure->checkStr($sinfo);
$query = "UPDATE ".$this->prefix."section SET secname='".$sSName."', sectinfo='".$sSInfo."' WHERE sect_id='".$sSectID."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Удаление информации о секции
*
* @author Alexander Wolf
* @category Core
*
* @param integer $sectionID
* @return array
*/
public function dropSection
($sectionID) {
$result = array();
$sSectID = $this->secure->checkInt($sectionID);
// Удаление секции
$query = "DELETE FROM ".$this->prefix."section WHERE sect_id='".$sSectID."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Добавление новой секции
*
* @author Alexander Wolf
* @category Core
*
* @param string $sname
* @param string $sinfo
* @return array
*/
public function addSection
($sname, $sinfo = "") {
$result = array();
$sSName = $this->secure->checkStr($sname);
$sSInfo = $this->secure->checkStr($sinfo);
$query = "INSERT INTO ".$this->prefix."section SET secname='".$sSName."', sectinfo='".$sSInfo."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Вывод списка поддерживаемых архитектур
*
* @author Alexander Wolf
* @category Core
*
* @param string $name
* @param string $actor
* @param string $format
* @return string
*/
public function showArchList
($name, $actor, $format = 'list') {
switch($format) {
case 'list':
$query = "SELECT * FROM ".$this->prefix."arch";
$rq =& $this->db->query($query);
$show = "<ul>\n";
while ($rq->fetchInto($element)) {
$show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$element["arch_id"]."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$element["arch_id"]."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["arch"],1)."</li>\n";
}
$show .= "</ul>";
break;
case 'innerhtml':
$show = "";
$repID = $this->secure->checkInt($actor);
if ($archID==0) {
$query = "SELECT * FROM ".$this->prefix."arch";
$rq =& $this->db->query($query);
while ($rq->fetchInto($element)) {
$show .= "<input type='checkbox' name='".$name."[]' value='".$element["arch_id"]."'> ".$this->secure->checkStr($element["arch"],1)." ";
}
} else {
$query = "SELECT * FROM ".$this->prefix."arch a JOIN ".$this->prefix."arch2rep r ON a.arch_id=r.arch_id WHERE r.rep_id='$repID'";
$rq =& $this->db->query($query);
while ($rq->fetchInto($element)) {
$show .= "<input type='checkbox' name='".$name."[]' value='".$element["arch_id"]."' checked> ".$this->secure->checkStr($element["arch"],1)." ";
}
$query = "SELECT a.* FROM ".$this->prefix."arch a WHERE a.arch_id NOT IN (SELECT arch_id FROM ".$this->prefix."arch2rep WHERE rep_id='$repID')";
$rq =& $this->db->query($query);
while ($rq->fetchInto($element)) {
$show .= "<input type='checkbox' name='".$name."[]' value='".$element["arch_id"]."'> ".$this->secure->checkStr($element["arch"],1)." ";
}
}
break;
}
return $show;
}
/**
* Добавление новой архитектуры
*
* @author Alexander Wolf
* @category Core
*
* @param string $arch
* @return array
*/
public function addArch
($arch) {
$result = array();
$sArch = $this->secure->checkStr($arch);
$query = "INSERT INTO ".$this->prefix."arch SET arch='".$sArch."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Удаление информации об архитектуре
*
* @author Alexander Wolf
* @category Core
*
* @param integer $archID
* @return array
*/
public function dropArch
($archID) {
$result = array();
$sArchID = $this->secure->checkInt($archID);
// Удаление архитектуры
$query = "DELETE FROM ".$this->prefix."arch WHERE arch_id='".$sArchID."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
// Удаление архитектуры из списка репозиториев
$query = "DELETE FROM ".$this->prefix."arch2rep WHERE arch_id='".$sArchID."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Обновление информации об архитектуре
*
* @author Alexander Wolf
* @category Core
*
* @param integer $archID
* @param string $arch
* @return array
*/
public function updateArch
($archID, $arch) {
$result = array();
$sArchID = $this->secure->checkInt($archID);
$sArch = $this->secure->checkStr($arch);
$query = "UPDATE ".$this->prefix."arch SET arch='".$sArch."' WHERE arch_id='".$sArchID."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Вывод формы редактирования/добавления архитектур
*
* @author Alexander Wolf
* @category Core
*
* @param integer $archID
* @param string $info
* @return string
*/
public function showArchForm
($archID = 0, $info = "") {
$sArchID = $this->secure->checkInt($archID);
$sInfo = $this->secure->checkStr($info, 1);
if ($sInfo == "") {
$sInfo = "Архитектура";
}
if ($sArchID != 0) {
// Режим редактирования
$query = "SELECT * FROM ".$this->prefix."arch WHERE arch_id='".$sArchID."'";
$rq =& $this->db->query($query);
$rq->fetchInto($element);
}
$show = "<fieldset><legend>".$sInfo."</legend>\n";
$show .= "<div class='inputbox'><label for='arch'>Архитектура:</label> <input type='text' name='arch' id='arch' value='".$this->secure->checkStr($element["arch"],1)."'></div>\n";
$show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
return $show;
}
/**
* Вывод списка схем репозиториев
*
* @author Alexander Wolf
* @category Core
*
* @param string $name
* @param string $actor
* @param string $format
* @return string
*/
public function showSchemeList
($name, $actor, $format = 'list') {
switch($format) {
case 'list':
$query = "SELECT * FROM ".$this->prefix."repscheme";
$rq =& $this->db->query($query);
$show = "<ul>\n";
while ($rq->fetchInto($element)) {
$show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$element["scheme_id"]."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$element["scheme_id"]."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["scheme"],1)."</li>\n";
}
$show .= "</ul>";
break;
case 'innerhtml':
$repID = $this->secure->checkInt($actor);
$query = "SELECT * FROM ".$this->prefix."repscheme";
$rq =& $this->db->query($query);
$show = "<select name='".$name."' id='".$name."'>\n";
while ($rq->fetchInto($element)) {
if ($element["scheme_id"]==$repID) {
$show .= "<option value='".$this->secure->checkInt($element["scheme_id"])."' selected>".$this->secure->checkStr($element["scheme"],1)."</option>\n";
} else {
$show .= "<option value='".$this->secure->checkInt($element["scheme_id"])."'>".$this->secure->checkStr($element["scheme"],1)."</option>\n";
}
}
$show .= "</select>";
break;
}
return $show;
}
/**
* Добавление новой схемы репозитория
*
* @author Alexander Wolf
* @category Core
*
* @param string $scheme
* @return array
*/
public function addScheme
($scheme) {
$result = array();
$sScheme = $this->secure->checkStr($scheme);
$query = "INSERT INTO ".$this->prefix."repscheme SET scheme='".$sScheme."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Удаление информации о схеме репозитория
*
* @author Alexander Wolf
* @category Core
*
* @param integer $schemeID
* @return array
*/
public function dropScheme
($schemeID) {
$result = array();
$sSchemeID = $this->secure->checkInt($schemeID);
// Удаление схемы
$query = "DELETE FROM ".$this->prefix."repscheme WHERE scheme_id='".$sSchemeID."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Обновление информации о схеме репозитория
*
* @author Alexander Wolf
* @category Core
*
* @param integer $schemeID
* @param string $info
* @return array
*/
public function updateScheme
($schemeID, $info) {
$result = array();
$sSchemeID = $this->secure->checkInt($schemeID);
$sScheme = $this->secure->checkStr($info);
$query = "UPDATE ".$this->prefix."repscheme SET scheme='".$sScheme."' WHERE scheme_id='".$sSchemeID."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Вывод формы редактирования/добавления схем репозиториев
*
* @author Alexander Wolf
* @category Core
*
* @param integer $schemeID
* @param string $info
* @return string
*/
public function showSchemeForm
($schemeID = 0, $info = "") {
$sSchemeID = $this->secure->checkInt($schemeID);
$sInfo = $this->secure->checkStr($info, 1);
if ($sInfo == "") {
$sInfo = "Схема репозитория";
}
$show = "<fieldset><legend>".$sInfo."</legend>\n";
if ($sSchemeID != 0) {
// Режим редактирования
$query = "SELECT * FROM ".$this->prefix."repscheme WHERE scheme_id='".$sSchemeID."'";
$rq =& $this->db->query($query);
$rq->fetchInto($element);
}
$show .= "<div class='inputbox'><label for='scheme'>Схема репозитория:</label> <input type='text' name='scheme' id='scheme' value='".$this->secure->checkStr($element["scheme"],1)."'></div>\n";
$show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
return $show;
}
/**
* Вывод списка протоколов
*
* @author Alexander Wolf
* @category Core
*
* @param string $name
* @param string $actor
* @param string $format
* @return string
*/
public function showProtoList
($name, $actor, $format = 'list') {
switch($format) {
case 'list':
$query = "SELECT * FROM ".$this->prefix."protos";
$rq =& $this->db->query($query);
$show = "<ul>\n";
while ($rq->fetchInto($element)) {
$show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$element["proto_id"]."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$element["proto_id"]."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["proto"],1)."</li>\n";
}
$show .= "</ul>";
break;
case 'innerhtml':
$protoID = $this->secure->checkInt($actor);
$query = "SELECT * FROM ".$this->prefix."protos";
$rq =& $this->db->query($query);
$show = "<select name='".$name."' id='".$name."'>\n";
while ($rq->fetchInto($element)) {
if ($element["proto_id"]==$protoID) {
$show .= "<option value='".$this->secure->checkInt($element["proto_id"])."' selected>".$this->secure->checkStr($element["proto"],1)."</option>\n";
} else {
$show .= "<option value='".$this->secure->checkInt($element["proto_id"])."'>".$this->secure->checkStr($element["proto"],1)."</option>\n";
}
}
$show .= "</select>";
break;
}
return $show;
}
/**
* Добавление нового протокола
*
* @author Alexander Wolf
* @category Core
*
* @param string $proto
* @return array
*/
public function addProto
($proto) {
$result = array();
$sProto = $this->secure->checkStr($proto);
$query = "INSERT INTO ".$this->prefix."protos SET proto='".$sProto."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Удаление информации о протоколе
*
* @author Alexander Wolf
* @category Core
*
* @param integer $protoID
* @return array
*/
public function dropProto
($protoID) {
$result = array();
$sProtoID = $this->secure->checkInt($protoID);
// Удаление протокола
$query = "DELETE FROM ".$this->prefix."protos WHERE proto_id='".$sProtoID."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Обновление информации о протоколе
*
* @author Alexander Wolf
* @category Core
*
* @param integer $protoID
* @param string $info
* @return array
*/
public function updateProto
($protoID, $info) {
$result = array();
$sProtoID = $this->secure->checkInt($protoID);
$sProto = $this->secure->checkStr($info);
$query = "UPDATE ".$this->prefix."protos SET proto='".$sProto."' WHERE proto_id='".$sProtoID."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Вывод формы редактирования/добавления протоколов
*
* @author Alexander Wolf
* @category Core
*
* @param integer $protoID
* @param string $info
* @return string
*/
public function showProtoForm
($protoID = 0, $info = "") {
$sProtoID = $this->secure->checkInt($protoID);
$sInfo = $this->secure->checkStr($info, 1);
if ($sInfo == "") {
$sInfo = "Протокол доступа";
}
$show = "<fieldset><legend>".$sInfo."</legend>\n";
if ($sProtoID != 0) {
// Режим редактирования
$query = "SELECT * FROM ".$this->prefix."protos WHERE proto_id='".$sProtoID."'";
$rq =& $this->db->query($query);
$rq->fetchInto($element);
}
$show .= "<div class='inputbox'><label for='proto'>Протокол доступа:</label> <input type='text' name='proto' id='proto' value='".$this->secure->checkStr($element["proto"],1)."'></div>\n";
$show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
return $show;
}
/**
* Вывод списка хостов
*
* @author Alexander Wolf
* @category Core
*
* @param string $name
* @param string $actor
* @param string $format
* @return string
*/
public function showHostsList
($name, $actor, $format = 'list') {
switch($format) {
case 'list':
$query = "SELECT * FROM ".$this->prefix."rephost";
$rq =& $this->db->query($query);
$show = "<ul>\n";
while ($rq->fetchInto($element)) {
$show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$element["rhost_id"]."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$element["rhost_id"]."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["rhost"],1)."</li>\n";
}
$show .= "</ul>";
break;
case 'innerhtml':
$hostID = $this->secure->checkInt($actor);
$query = "SELECT * FROM ".$this->prefix."rephost";
$rq =& $this->db->query($query);
$show = "<select name='".$name."' id='".$name."'>\n";
while ($rq->fetchInto($element)) {
if ($element["rhost_id"]==$hostID) {
$show .= "<option value='".$this->secure->checkInt($element["rhost_id"])."' selected>".$this->secure->checkStr($element["rhost"],1)."</option>\n";
} else {
$show .= "<option value='".$this->secure->checkInt($element["rhost_id"])."'>".$this->secure->checkStr($element["rhost"],1)."</option>\n";
}
}
$show .= "</select>";
break;
}
return $show;
}
/**
* Добавление нового хоста
*
* @author Alexander Wolf
* @category Core
*
* @param string $host
* @return array
*/
public function addHost
($host) {
$result = array();
$sHost = $this->secure->checkStr($host);
$query = "INSERT INTO ".$this->prefix."rephost SET rhost='".$sHost."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Удаление информации о хосте
*
* @author Alexander Wolf
* @category Core
*
* @param integer $hostID
* @return array
*/
public function dropHost
($hostID) {
$result = array();
$sHostID = $this->secure->checkInt($hostID);
// Удаление хоста
$query = "DELETE FROM ".$this->prefix."rephost WHERE rhost_id='".$sHostID."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Обновление информации о хосте
*
* @author Alexander Wolf
* @category Core
*
* @param integer $hostID
* @param string $info
* @return array
*/
public function updateHost
($hostID, $info) {
$result = array();
$sHostID = $this->secure->checkInt($hostID);
$sHost = $this->secure->checkStr($info);
$query = "UPDATE ".$this->prefix."rephost SET rhost='".$sHost."' WHERE rhost_id='".$sHostID."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Вывод формы редактирования/добавления хостов
*
* @author Alexander Wolf
* @category Core
*
* @param integer $hostID
* @param string $info
* @return string
*/
public function showHostForm
($hostID = 0, $info = "") {
$sHostID = $this->secure->checkInt($hostID);
$sInfo = $this->secure->checkStr($info, 1);
if ($sInfo == "") {
$sInfo = "Хост репозитория";
}
$show = "<fieldset><legend>".$sInfo."</legend>\n";
if ($sHostID != 0) {
// Режим редактирования
$query = "SELECT * FROM ".$this->prefix."rephost WHERE rhost_id='".$sHostID."'";
$rq =& $this->db->query($query);
$rq->fetchInto($element);
}
$show .= "<div class='inputbox'><label for='rhost'>Хост репозитория:</label> <input type='text' name='rhost' id='rhost' value='".$this->secure->checkStr($element["rhost"],1)."'></div>\n";
$show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
return $show;
}
/**
* Вывод списка корневых папок
*
* @author Alexander Wolf
* @category Core
*
* @param string $name
* @param string $actor
* @param string $format
* @return string
*/
public function showFoldersList
($name, $actor, $format = 'list') {
switch($format) {
case 'list':
$query = "SELECT * FROM ".$this->prefix."repfolder";
$rq =& $this->db->query($query);
$show = "<ul>\n";
while ($rq->fetchInto($element)) {
$show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$element["rfolder_id"]."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$element["rfolder_id"]."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["rfolder"],1)."</li>\n";
}
$show .= "</ul>";
break;
case 'innerhtml':
$folderID = $this->secure->checkInt($actor);
$query = "SELECT * FROM ".$this->prefix."repfolder";
$rq =& $this->db->query($query);
$show = "<select name='".$name."' id='".$name."'>\n";
while ($rq->fetchInto($element)) {
if ($element["rfolder_id"]==$folderID) {
$show .= "<option value='".$this->secure->checkInt($element["rfolder_id"])."' selected>".$this->secure->checkStr($element["rfolder"],1)."</option>\n";
} else {
$show .= "<option value='".$this->secure->checkInt($element["rfolder_id"])."'>".$this->secure->checkStr($element["rfolder"],1)."</option>\n";
}
}
$show .= "</select>";
break;
}
return $show;
}
/**
* Добавление нового корневого каталога
*
* @author Alexander Wolf
* @category Core
*
* @param string $flder
* @return array
*/
public function addFolder
($folder) {
$result = array();
$sFolder = $this->secure->checkStr($folder);
$query = "INSERT INTO ".$this->prefix."repfolder SET rfolder='".$sFolder."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Удаление информации о корневой папке
*
* @author Alexander Wolf
* @category Core
*
* @param integer $folderID
* @return array
*/
public function dropFolder
($folderID) {
$result = array();
$sFolderID = $this->secure->checkInt($folderID);
// Удаление корневой папки
$query = "DELETE FROM ".$this->prefix."repfolder WHERE rfolder_id='".$sFolderID."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Обновление информации о корневой папки
*
* @author Alexander Wolf
* @category Core
*
* @param integer $folderID
* @param string $info
* @return array
*/
public function updateFolder
($folderID, $info) {
$result = array();
$sFolderID = $this->secure->checkInt($folderID);
$sFolder = $this->secure->checkStr($info);
$query = "UPDATE ".$this->prefix."repfolder SET rfolder='".$sFolder."' WHERE rfolder_id='".$sFolderID."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Вывод формы редактирования/добавления корневых папок
*
* @author Alexander Wolf
* @category Core
*
* @param integer $folderID
* @param string $info
* @return string
*/
public function showFolderForm
($folderID = 0, $info = "") {
$sFolderID = $this->secure->checkInt($folderID);
$sInfo = $this->secure->checkStr($info, 1);
if ($sInfo == "") {
$sInfo = "Корневая папка";
}
if ($sFolderID != 0) {
// Режим редактирования
$query = "SELECT * FROM ".$this->prefix."repfolder WHERE rfolder_id='".$sFolderID."'";
$rq =& $this->db->query($query);
$rq->fetchInto($element);
}
$show = "<fieldset><legend>".$sInfo."</legend>\n";
$show .= "<div class='inputbox'><label for='rfolder'>Корневая папка:</label> <input type='text' name='rfolder' id='rfolder' value='".$this->secure->checkStr($element["rfolder"],1)."'></div>\n";
$show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
return $show;
}
/**
* Показывает список подписей
*
* @author Alexander Wolf
* @category Core
*
* @param string $name
* @param string $actor
* @param string $format
* @return string
*/
public function showSignsList
($name, $actor, $format = 'list') {
$query = "SELECT * FROM ".$this->prefix."signs";
$rq =& $this->db->query($query);
switch ($format) {
case 'list':
$show = "<ul>\n";
while ($rq->fetchInto($element)) {
$show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$element["sign_id"]."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$element["sign_id"]."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["sname"],1)."</li>\n";
}
$show .= "</ul>";
break;
case 'innerhtml':
$signID = $this->secure->checkInt($actor);
$show = "<select name='".$name."' id='".$name."'>\n";
$show .= "<option value='0'>Подписи нет</option>\n";
while ($rq->fetchInto($element)) {
if ($element["sign_id"]==$signID) {
$show .= "<option value='".$this->secure->checkInt($element["sign_id"])."' selected>".$this->secure->checkStr($element["sname"],1)."</option>\n";
} else {
$show .= "<option value='".$this->secure->checkInt($element["sign_id"])."'>".$this->secure->checkStr($element["sname"],1)."</option>\n";
}
}
$show .= "</select>\n";
break;
}
return $show;
}
/**
* Вывод формы редактирования/добавления подписей
*
* @author Alexander Wolf
* @category Core
*
* @param integer $sectionID
* @param string $info
* @return string
*/
public function showSignsForm
($signID = 0, $info = "") {
$sSignID = $this->secure->checkInt($signID);
$sInfo = $this->secure->checkStr($info, 1);
if ($sInfo == "") {
$sInfo = "Подписи";
}
if ($sSignID != 0) {
// Режим редактирования
$query = "SELECT * FROM ".$this->prefix."signs WHERE sign_id='".$sSignID."'";
$rq =& $this->db->query($query);
$rq->fetchInto($element);
}
$show = "<fieldset><legend>".$sInfo."</legend>\n";
$show .= "<div class='inputbox'><label for='sname'>Название подписи:</label> <input type='text' name='sname' id='sname' value='".$this->secure->checkStr($element["sname"],1)."'></div>\n";
$show .= "<div class='inputbox'><label for='sinfo'>Описание подписи:</label> <input type='text' name='sinfo' id='sinfo' value='".$this->secure->checkStr($element["sinfo"],1)."'></div>\n";
$show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
return $show;
}
/**
* Обновление информации о секции
*
* @author Alexander Wolf
* @category Core
*
* @param integer $sectionID
* @param string $sname
* @param string $sinfo
* @return array
*/
public function updateSign
($signID, $sname, $sinfo = "") {
$result = array();
$sSignID = $this->secure->checkInt($signID);
$sSName = $this->secure->checkStr($sname);
$sSInfo = $this->secure->checkStr($sinfo);
$query = "UPDATE ".$this->prefix."signs SET sname='".$sSName."', sinfo='".$sSInfo."' WHERE sign_id='".$sSignID."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Удаление информации о подписи
*
* @author Alexander Wolf
* @category Core
*
* @param integer $sectionID
* @return array
*/
public function dropSign
($signID) {
$result = array();
$sSignID = $this->secure->checkInt($signID);
// Удаление подписи
$query = "DELETE FROM ".$this->prefix."signs WHERE sign_id='".$sSignID."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Добавление новой подписи
*
* @author Alexander Wolf
* @category Core
*
* @param string $sname
* @param string $sinfo
* @return array
*/
public function addSign
($sname, $sinfo = "") {
$result = array();
$sSName = $this->secure->checkStr($sname);
$sSInfo = $this->secure->checkStr($sinfo);
$query = "INSERT INTO ".$this->prefix."signs SET sname='".$sSName."', sinfo='".$sSInfo."'";
$rq =& $this->db->query($query);
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
/**
* Проверка пароля (из формы авторизации)
*
* @author Alexander Wolf
* @category Core
*
* @param string $word
* @return array
*/
public function checkSign
($word) {
$result = array();
$sHash = $this->secure->encryptStr($word);
$pwd = $this->getOption("passwd");
if ($sHash == $pwd["OptValue"]) {
$result["ERR"] = 0;
$result["Location"] = "manager.php";
setcookie($this->cookie, $sHash);
} else {
$result["ERR"] = 1;
$result["ERRINFO"] = "Password not valid";
$result["Location"] = "manager.php?error=1";
}
return $result;
}
/**
* Проверка пароля (из cookies)
*
* @author Alexander Wolf
* @category Core
*
* @param string $hash
* @return array
*/
public function checkCookieSign
($hash) {
$result = array();
$pwd = $this->getOption("passwd");
if ($hash == $pwd["OptValue"]) {
$result["ERR"] = 0;
} else {
$result["ERR"] = 1;
$result["ERRINFO"] = "Hash not valid";
$result["Location"] = "manager.php";
}
return $result;
}
/**
* Форма ввода пароля
*
* @author Alexander Wolf
* @category Core
*
* @return string
*/
public function showSigninForm
() {
$show = "<div id='regform'>";
$show .= "<form action='process.php' method='post'>\n";
$show .= "<fieldset><legend>Пароль</legend>\n";
$show .= "<input type='hidden' name='mode' value='authorize'>\n";
$show .= "<input type='password' name='word' value=''>\n";
$show .= "<input type='submit' value=' Войти '>\n";
$show .= "</fieldset>\n</form></div>\n";
return $show;
}
/**
* Обновление пароля
*
* @author Alexander Wolf
* @category Core
*
* @param string $word1
* @param string $word2
* @return array
*/
public function updatePassword
($word1, $word2) {
$result = array();
if ($word1 == $word2) {
$sWord = $this->secure->encryptStr($word1);
$r = $this->setOption("passwd", $sWord);
$result = $r;
} else {
$result["ERR"] = 1;
$result["ERRINFO"] = "Passwords is mismatch";
}
return $result;
}
/**
* Отображение формы создания и редактирования версии apt-дистрибутива
*
* @author Alexander Wolf
* @category Core
*
* @param string $name
* @param string $actor
* @param integer $versionID
* @return string
*/
public function showDistVersionsForm
($versionID = 0, $info = '') {
$sVersionID = $this->secure->checkInt($versionID);
$sInfo = $this->secure->checkStr($info, 1);
if ($sInfo == "") {
$sInfo = "Версия дистрибутива";
}
if ($sVersionID != 0) {
// Режим редактирования
$query = "SELECT * FROM ".$this->prefix."version v JOIN ".$this->prefix."distribution d ON v.dist_id=d.dist_id WHERE v.version_id='".$sVersionID."'";
$rq =& $this->db->query($query);
$rq->fetchInto($element);
}
$show = "<fieldset><legend>".$sInfo."</legend>\n";
if ($sVersionID != 0) {
$show .= "<div class='inputbox'><label for='distname'>Дистрибутив:</label> <input type='text' name='distname' value='".$this->secure->checkStr($element["distname"],1)."' readonly='readonly'></div>\n";
} else {
$show .= "<div class='inputbox'><label for='distname'>Дистрибутив:</label> ".$this->showDistributionList("distname", "", "", "innerhtml")."</div>\n";
}
$show .= "<div class='inputbox'><label for='vname'>Название версии:</label> <input type='text' name='vname' value='".$this->secure->checkStr($element["vname"],1)."'></div>\n";
$show .= "<div class='inputbox'><label for='version'>Номер версии:</label> <input type='text' name='version' value='".$this->secure->checkStr($element["version"],1)."'></div>\n";
$show .= "<div class='inputbox'><label for='vcodename'>Кодовое имя версии:</label> <input type='text' name='vcodename' value='".$this->secure->checkStr($element["vcodename"],1)."'></div>\n";
$show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div></fieldset>\n";
return $show;
}
/**
* Парсер схемы адреса репозитория
* FIXME Возможно не потребуется
*
* @author Alexander Wolf
* @category Core
*
* @param string $repstring
* @return integer
*/
public function repositoryParser
($repstring) {
$tokens = array();
$sections = array();
$tokens = split(" ",$repstring);
if ($tokens[0] == "deb") {
// debian/ubuntu репозиторий "type proto://host/folder distr sections"
$url = parse_url($tokens[1]);
$distr = $tokens[2];
for($i=3;$i<count($tokens);$i++) {
$sections[] = $tokens[$i];
}
} else {
// altlinux репозиторий "type [sign] proto://host/folder base repname"
if (stripos($tokens[1],"]")!=0) {
$sign = $tokens[1];
$url = parse_url($tokens[2]);
$base = $tokens[3];
$repname = $tokens[4];
} else {
$url = parse_url($tokens[1]);
$base = $tokens[2];
$repname = $tokens[3];
}
}
$proto = $url["scheme"]."://";
$addr = $url["host"];
if ($url["port"]!="") {
$addr .= ":".$url["port"];
}
$path = $url["path"];
return 0;
}
/**
* Выгрузка картинок логотипов дистрибутивов
*
* @author Alexander Wolf
* @category Core
*
* @param string $path
* @param string $dist
* @param array $datafile
* @return integer
*/
public function uploadPicture
($path, $dist, $datafile) {
$folder = $path.$dist."-orig.png";
$folderN = $path.$dist.".png";
$folderEM = $path.$dist."-em.png";
$distlogo = 0;
if (move_uploaded_file($datafile["distlogo"]["tmp_name"],$folder)) {
chmod($folder, 0644);
list($width, $height) = GetImageSize($folder);
$percent = 32/$height;
$newwidth = $width * $percent;
$newheight = $height * $percent;
$output = ImageCreateTrueColor($newwidth, $newheight);
$source = ImageCreateFromPNG($folder);
ImageCopyResampled($output, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
ImagePNG($output, $folderEM);
$percent = 15/$height;
$newwidth = $width * $percent;
$newheight = $height * $percent;
$output = ImageCreateTrueColor($newwidth, $newheight);
ImageCopyResized($output, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
ImagePNG($output, $folderN);
unlink($folder);
$distlogo = 1;
}
return $distlogo;
}
/**
* Показ списка репозиториев
*
* @author Alexander Wolf
* @category Core
*
* @param string $name
* @param string $actor
* @param string $format
* @return string
*/
public function showRepositoriesList
($name, $actor, $format = 'list') {
$query = "SELECT * FROM ".$this->prefix."repository r ";
$query .= "JOIN ".$this->prefix."rtype rt ON rt.rtype_id=r.rtype_id ";
$rq =& $this->db->query($query);
$show = "<ul>";
while ($rq->fetchInto($element)) {
$show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$this->secure->checkInt($element["rep_id"])."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$this->secure->checkInt($element["rep_id"])."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["repname"],1)." (".$this->secure->checkStr($element["rtype"],1).")</li>\n";
}
$show .= "</ul>";
return $show;
}
/**
* Вывод списка типов репозиториев
*
* @author Alexander Wolf
* @category Core
*
* @param integer $reptype
* @param string $name
* @return string
*/
public function showRepType
($reptype = 0, $name = "") {
$sRT = $this->secure->checkInt($reptype);
$sNM = $this->secure->checkStr($name,1);
$query = "SELECT * FROM ".$this->prefix."rtype";
$rq =& $this->db->query($query);
$show = "<select name='".$sNM."' id='".$sNM."'>\n";
while ($rq->fetchInto($element)) {
if ($element["rtype_id"]==$sRT) {
$show .= "<option value='".$this->secure->checkInt($element["rtype_id"])."' selected>".$this->secure->checkStr($element["rtype"],1)."</option>\n";
} else {
$show .= "<option value='".$this->secure->checkInt($element["rtype_id"])."'>".$this->secure->checkStr($element["rtype"],1)."</option>\n";
}
}
$show .= "</select>";
return $show;
}
public function showVDList
($name, $versionID = 0) {
$query = "SELECT v.version_id, CONCAT(d.distname, ' ', v.version, ' ', v.vname) AS fullname FROM ".$this->prefix."version v ";
$query .= "JOIN ".$this->prefix."distribution d ON v.dist_id=d.dist_id";
$rq =& $this->db->query($query);
$show = "<select name='".$name."' id='".$name."'>\n";
while ($rq->fetchInto($element)) {
if ($element["version_id"]==$versionID) {
$show .= "<option value='".$this->secure->checkInt($element["version_id"])."' selected>".$this->secure->checkStr($element["fullname"],1)."</option>\n";
} else {
$show .= "<option value='".$this->secure->checkInt($element["version_id"])."'>".$this->secure->checkStr($element["fullname"],1)."</option>\n";
}
}
$show .= "</select>";
return $show;
}
/**
* Форма создания/редактирвоания репозиториев
*
* @author Alexander Wolf
* @category Core
*
* @param integer $repID
* @param string $info
* @param string $reptype
* @return string
*/
public function showRepositoriesForm
($repID = 0, $info = "") {
$sRepID = $this->secure->checkInt($repID);
$sInfo = $this->secure->checkStr($info, 1);
if ($sInfo == "") {
$sInfo = "Репозиторий";
}
if ($sRepID != 0) {
// Режим редактирования
$query = "SELECT r.*,v.*,d.dist_id,dt.type FROM ".$this->prefix."repository r ";
$query .= "JOIN ".$this->prefix."version v ON r.version=v.version_id ";
$query .= "JOIN ".$this->prefix."distribution d ON v.dist_id=d.dist_id ";
$query .= "JOIN ".$this->prefix."dtype dt ON d.disttype=dt.type_id ";
$query .= "WHERE r.rep_id='".$sRepID."'";
$rq =& $this->db->query($query);
$rq->fetchInto($element);
}
$show = "<fieldset><legend>".$sInfo."</legend>\n";
$show .= "<div class='inputbox'><label for='rdist'>Дистрибутив:</label> ".$this->showVDList("rdist",$this->secure->checkInt($element["dist_id"]),"innerhtml")."</div>\n";
$show .= "<div class='inputbox'><label for='rname'>Название репозитория:</label> <input type='text' name='rname' value='".$this->secure->checkStr($element["repname"],1)."'></div>\n";
$show .= "<div class='inputbox'><label for='rinfo'>Описание репозитория:</label> <input type='text' name='rinfo' value='".$this->secure->checkStr($element["repinfo"],1)."'></div>\n";
$show .= "<div class='inputbox'><label for='rkey'>Ключ подписи репозитория:</label> <input type='text' name='rkey' value='".$this->secure->checkStr($element["repkey"],1)."'></div>\n";
$show .= "<div class='inputbox'><label for='rproto'>Протокол доступа:</label> ".$this->showProtoList("rproto",$this->secure->checkInt($element["proto_id"]),"innerhtml")."</div>\n";
$show .= "<div class='inputbox'><label for='rhost'>Хост репозитория:</label> ".$this->showHostsList("rhost",$this->secure->checkInt($element["rhost_id"]),"innerhtml")."</div>\n";
$show .= "<div class='inputbox'><label for='rfolder'>Корневая папка:</label> ".$this->showFoldersList("rhost",$this->secure->checkInt($element["rfolder_id"]),"innerhtml")."</div>\n";
$show .= "<div class='inputbox'><label for='rtype'>Тип репозитория:</label> ".$this->showRepType($this->secure->checkInt($element["rtype_id"]), "rtype")."</div>\n";
$show .= "<div class='inputbox'><label for='rsects'>Секции репозитория:</label> <div class='formwrapper'>".$this->showSectionsList("rsects",$sRepID,"innerhtml")."</div></div>\n";
$show .= "<div class='inputbox'><label for='rarchs'>Архитектуры:</label> <div class='formwrapper'>".$this->showArchList("rarchs",$sRepID,"innerhtml")."</div></div>\n";
$show .= "<div class='inputbox'><label for='rscheme'>Схема репозитория:</label> ".$this->showSchemeList("rscheme",$sRepID,"innerhtml")."</div>\n";
$show .= "<div class='inputbox'><label for='rsign'>Подпись репозитория:</label> ".$this->showSignsList("rsign",$this->secure->checkInt($element["sign_id"]),"innerhtml")."</div>\n";
$show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div></fieldset>\n";
return $show;
}
/**
* Добавление нового репозитория
*
* @author Alexander Wolf
* @category Core
*
* @param integer $verionID
* @param string $rname
* @param string $rinfo
* @param string $rkey
* @param integer $proto
* @param integer $rhost
* @param integer $rfolder
* @param integer $rtype
* @param array $sections
* @param array $arch
* @param integer $scheme
* @param integer $sign
* @return array
*/
public function addRepository
($verionID, $rname, $rinfo, $rkey, $proto, $rhost, $rfolder, $rtype, $sections, $arch, $scheme, $sign) {
$result = array();
$sVersionID = $this->secure->checkInt($verionID);
$sRName = $this->secure->checkStr($rname);
$sRInfo = $this->secure->checkStr($rinfo);
$sRKey = $this->secure->checkStr($rkey);
$sProto = $this->secure->checkInt($proto);
$sRHost = $this->secure->checkInt($rhost);
$sRFolder = $this->secure->checkInt($rfolder);
$sRType = $this->secure->checkInt($rtype);
$sRScheme = $this->secure->checkInt($scheme);
$sRSign = $this->secure->checkInt($sign);
phpinfo();
$query = "INSERT INTO ".$this->prefix."repository SET proto_id='".$sProto."', rhost_id='".$sRHost."', rfolder_id='".$sRFolder."', version='".$sVersionID.", rtype_id='".$sRType."', scheme_id='".$sRScheme."', sign_id='".$sRSign."', repname='".$sRName."', repinfo='".$sRInfo."', repkey='".$sRKey."'";
$rq =& $this->db->query($query);
$query = "SELECT rep_id FROM ".$this->prefix."repository ORDER BY rep_id DESC LIMIT 0, 1";
$rq =& $this->db->query($query);
$rq->fetchInto($repository);
for($i=0;$i<count($sections);$i++) {
$query = "INSERT INTO ".$this->prefix."sect2rep SET rep_id='".$repository["rep_id"]."', sect_id='".$sections[$i]."'";
$rq =& $this->db->query($query);
}
for($i=0;$i<count($arch);$i++) {
$query = "INSERT INTO ".$this->prefix."arch2rep SET rep_id='".$repository["rep_id"]."', arch_id='".$arch[$i]."'";
$rq =& $this->db->query($query);
}
if (PEAR
::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$result["ERR"] = 0;
}
return $result;
}
}
?>