<?php
define('_IN_JOHNCMS', 1);
$headmod = 'lib';
$textl = 'Установка';
require_once ("../incfiles/core.php");
require_once ("./inc/conf.php");
require_once ("../incfiles/head.php");
set_time_limit(0);
switch($act)
{
default:
echo '<p>Вы запускаете конвнртет, из стандартной библиотеки в Gnom_Lib_For_JohnCMS</p>';
echo '<p><strong>Внимание при конвертировании будет удалена таблица `library` и создана заново с статьями из таблицы `lib`</strong></p>';
echo '<a href="CONVERTER.php?act=go">Начать</a><br/>';
break;
case "go":
mysql_query("DROP TABLE `library`");
mysql_query("TRUNCATE TABLE `lib_kom`");
mysql_query("create table `library` select `id`,`refid` from `lib` where `type` != 'komm' ");
mysql_query("ALTER TABLE `library` ADD PRIMARY KEY ( `id` )");
mysql_query("ALTER TABLE `library` CHANGE `refid` `fid` INT NOT NULL ");
mysql_query("ALTER TABLE `library` CHANGE `id` `id` INT NOT NULL AUTO_INCREMENT ");
mysql_query("ALTER TABLE `library` ADD `path` TEXT NOT NULL ,
ADD `file` TEXT NOT NULL ,
ADD `type` TINYTEXT NOT NULL ,
ADD `type2` TINYTEXT NOT NULL ,
ADD `name` TEXT NOT NULL ,
ADD `opis` TEXT NOT NULL ,
ADD `text` LONGTEXT NOT NULL ,
ADD `ip` VARCHAR( 25 ) NOT NULL ,
ADD `soft` TEXT NOT NULL ,
ADD `time` INT NOT NULL ,
ADD `count` INT NOT NULL ,
ADD `id_avtor` INT NOT NULL ,
ADD `rating` TEXT NOT NULL ,
ADD `moder` TINYINT NOT NULL ;");
$sql = mysql_query("select * from `lib`");
while($mas = mysql_fetch_array($sql))
{
if($mas['refid'] == "0" && $mas['type'] == 'cat')
{
mysql_query("update `library` set `path` = '/".trans2($mas['text'])."', `name`='".$mas['text']."', `type` = 'dir', `type2` = 'NO', `ip` = '".$ipp."', `soft` = '".$agn."', `time` = '".$mas['time']."' where `id` = '".$mas['id']."'");
}elseif($mas['refid'] !== "0" && $mas['type'] == 'cat')
{
$ar = mysql_fetch_array(mysql_query("select `path` from `library` where `id` = '".$mas['refid']."'"));
mysql_query("update `library` set `path` = '".$ar['path'].'/'.trans2($mas['text'])."', `name`='".$mas['text']."', `type` = 'dir', `type2` = '".($mas['soft'] == "1" ? "YES" : "NO")."', `ip` = '".$ipp."', `soft` = '".$agn."', `time` = '".$mas['time']."' where `id` = '".$mas['id']."'");
}
if($mas['type'] == 'bk')
{
$file = trans2($mas['name']).'.txt';
$name_stat = $mas['name'];
$opis_stat = $mas['announce'];
$text = $mas['text'];
$ar = mysql_fetch_array(mysql_query("select `path` from `library` where `id` = '".$mas['refid']."'"));
$arrr = mysql_fetch_array(mysql_query("select `id` from `users` where `name` = '".$mas['avtor']."'"));
mysql_query("update `library` set
`file` = '".$file."',
`path` = '".$ar['path']."',
`type` = 'file',
`name` = '".$name_stat."',
`opis` = '".$opis_stat."',
`text` = '".$text."',
`ip` = '".long2ip($mas['ip'])."',
`soft` = '".$mas['soft']."',
`time` = '".$mas['time']."',
`count` = '".$mas['count']."',
`id_avtor` = '".$arrr['id']."',
`rating` = '0',
`moder` = '".$mas['moder']."' where `id` = '".$mas['id']."'");
}
if($mas['type'] == 'komm')
{
$arrr = mysql_fetch_array(mysql_query("select `id` from `users` where `name` = '".$mas['avtor']."'"));
mysql_query("insert into `lib_kom` set
`id` = '',
`fid` = '".$mas['refid']."',
`user` = '".$arrr['id']."',
`text` = '".$mas['text']."',
`ip` = '".long2ip($mas['ip'])."',
`soft` = '".$mas['soft']."',
`time` = '".$mas['time']."';");
}
}
echo 'Все успешно!!!<br/><a href="index.php?">В библиотеку</a><hr/>';
break;
}
require_once ("../incfiles/end.php");
?>