Файл: adminka/shop.php
Строк: 353
<?php
session_start();
define('IN_SCRIPT', true);
include "../includes/ini.php";
include "header.php";
include "../smiles/smiles.php";
#=====================================================================#
function BBcode($txt)
{
//$txt=preg_replace_callback('{(?:(w+://)|www.|wap.)[w-]+(.[w-]+)*(?: : d+)?[^<>"'()[]s]*(?:(?<! [[:punct:]])|(?<= [-/&+*;]))}xis', "hrefCallback", $txt);
$txt=preg_replace('#[big](.*?)[/big]#si','<big>1</big>',$txt);
$txt=preg_replace('#[b](.*?)[/b]#si','<b>1</b>',$txt);
$txt=preg_replace('#[i](.*?)[/i]#si','<i>1</i>',$txt);
$txt=preg_replace('#[u](.*?)[/u]#si','<u>1</u>',$txt);
$txt=preg_replace('#[small](.*?)[/small]#si','<small>1</small>',$txt);
$txt=preg_replace('#[c](.*?)[/c]#si','<b>Цитата:</b> 1<br/>',$txt);
$txt=preg_replace("/[color=([0-9a-f]{6})](.*?)[/color]/i","<font color="#$1">$2</font>",$txt);
$txt=eregi_replace("(.*)\[url\](.*)\[/url\](.*)","\1<a href=http://\2>\2</a>\3",$txt);
$txt=eregi_replace("(.*)\[url=(.*)\](.*)\[/url\]","\1<a href="\2">\3</a>",$txt);
return $txt;
}
function hrefCallback($p)
{
$href = !empty($p[1]) ? $p[0] : 'http://' . $p[0];
return '<a href="' . $href . '">' . $p[0] . '</a>';
}
function roundTo($number)
{
return floor(($number + 10 / 10) / 10) * 10;
}
function pagenav($base_url, $start, $max_value, $num_per_page)
{
$pgcont = 4;
$pgcont = (int)($pgcont - ($pgcont % 2)) / 2;
if ($start >= $max_value)
$start = max(0, (int)$max_value - (((int)$max_value % (int)$num_per_page) == 0 ? $num_per_page : ((int)$max_value % (int)$num_per_page)));
else
$start = max(0, (int)$start - ((int)$start % (int)$num_per_page));
$base_link = '<a class="navpg" href="' . strtr($base_url, array('%' => '%%')) . 'start=%d' . '">%s</a> ';
$pageindex = $start == 0 ? '' : sprintf($base_link, $start - $num_per_page, '<<');
if ($start > $num_per_page * $pgcont)
$pageindex .= sprintf($base_link, 0, '1');
if ($start > $num_per_page * ($pgcont + 1))
$pageindex .= '<span style="font-weight: bold;"> ... </span>';
for ($nCont = $pgcont; $nCont >= 1; $nCont--)
if ($start >= $num_per_page * $nCont)
{
$tmpStart = $start - $num_per_page * $nCont;
$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
}
$pageindex .= '[<b>' . ($start / $num_per_page + 1) . '</b>] ';
$tmpMaxPages = (int)(($max_value - 1) / $num_per_page) * $num_per_page;
for ($nCont = 1; $nCont <= $pgcont; $nCont++)
if ($start + $num_per_page * $nCont <= $tmpMaxPages)
{
$tmpStart = $start + $num_per_page * $nCont;
$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
}
if ($start + $num_per_page * ($pgcont + 1) < $tmpMaxPages)
$pageindex .= '<span style="font-weight: bold;"> ... </span>';
if ($start + $num_per_page * $pgcont < $tmpMaxPages)
$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
if ($start + $num_per_page < $max_value)
{
$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
$pageindex .= sprintf($base_link, $display_page, '>>');
}
return $pageindex;
}
function check($per)
{
$value1=array("&","$","'",""","<",">","`","~");
$value2=array("","","","","","","","");
$per=str_replace($value1,$value2,$per);
$per=htmlspecialchars($per);
$per = str_replace("'", "'", $per);
$per = str_replace('\', "\", $per);
$per = str_replace("|", "I", $per);
$per = str_replace("||", "I", $per);
$per = str_replace("/\$/", "$", $per);
$per = mysql_real_escape_string($per);
return $per;
}
#=====================================================================================#Global var
$id = isset($_REQUEST['id']) ? abs(intval($_REQUEST['id'])) : 0;
$start = isset($_GET['start']) ? abs(intval($_GET['start'])) : 0;
$kmess=10;
$realtime=time();
#======================================================================================#
///////////////////
if (isset($_SESSION['auth'])){
$login = $_SESSION['login'];
$login = htmlspecialchars(trim($login));
$login = mysql_real_escape_string($login);
$count = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE login='$login'"));
if($count['tyuioteteeitruytripoetiweero']==1){
If (!isset($_GET['do']) || !ereg("^[a-z0-9_-]{1,15}$",$_GET['do'])) $do=false; else $do=$_GET['do'];
switch ($do) {
///////////////////////////////////Модуль онлайн магазина/////////////////////////////////
case "produkt":
if (empty($_SESSION['sort_users'])) $_SESSION['sort_users'] = 0;
if (isset($_GET['sort']))
{
$_SESSION['sort_users'] = (int)$_GET['sort'];
if ($_SESSION['sort_users'] < 0 or $_SESSION['sort_users'] > 2) $_SESSION['sort_users'] = 0;
}
switch($_SESSION['sort_users'])
{
case 0:
default:
$q = "WHERE `status`='0'";
$t = 'Новые|<a href="shop.php?do=produkt&sort=1">Активные</a>|<a href="shop.php?do=produkt&sort=2">В Блоке</a>';
break;
case 1:
$q = "WHERE `status`='1'";
$t = 'Активные|<a href="shop.php?do=produkt&sort=0">Новые</a>|<a href="shop.php?do=produkt&sort=2">В Блоке</a>';
break;
case 2:
$q = "WHERE `status`='2'";
$t = 'В Блоке|<a href="shop.php?do=produkt&sort=1">Активные</a>|<a href="shop.php?do=produkt&sort=0">Новые</a>';
break;
}
echo '<div class="title_page">'.$t.'</div>';
$c = mysql_result(mysql_query("SELECT COUNT(*) FROM `shop` ".$q.";"), 0);
if ($c > 0)
{
$qwq = mysql_query("SELECT * FROM `shop` ".$q." ORDER BY `ts`");
$ss = mysql_fetch_array($qwq);
$page = intval(@$_GET['page']);
$start = intval(@$_GET['start']);
$onpage = 5;
$all = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM `shop` ".$q." ORDER BY `ts`"));
$all = $all[0];
$pages = ceil($all/$onpage);
if(!$pages) $pages = 1;
if($page>$pages or $page<=0) $page=1;
if($start>$all or $start<=0) $start = 0;
if($page) $start = ($page - 1) * $onpage; else $start = 0;
$sql = mysql_query("SELECT * FROM `shop` ".$q." ORDER BY `ts` ASC LIMIT ".$start.", ".$onpage);
while ($rows = mysql_fetch_array($sql))
{
if($rows['vid']==1){
$stoim=$rows['stoim']-($rows['stoim']*0.05);
$stoim = explode(".", $stoim);
}
else
{
$stoim=$rows['stoim']-($rows['stoim']*0.03);
$stoim = explode(".", $stoim);
}
if($rows['status']==0){
$status='<b style="color:#CC9933">на проверке</b>';
}
if($rows['status']==1){
$status='<b style="color:#009900">активный</b>';
}
if($rows['status']==2){
$status='<b style="color:#FF0000">заблокирован</b>';
}
if($rows['icq_status']==1){
$icq_status='<b>vis</b>';
}
if($rows['icq_status']==2){
$icq_status='<b>inv</b>';
}
if($rows['icq_status']==3){
$icq_status='<b>clean</b>';
}
$kols = mysql_num_rows(mysql_query("SELECT * FROM `shoppokypki` WHERE `ids`='".$rows['id']."'"));
$msg=$rows['opis'];
$msg=BBcode($msg);
echo '<div class="box_2"><span style="color:#000099">Название:</span><br/>
<b>'.htmlspecialchars(trim($rows['nazva'])).'</b> '.$icq_status.'<br/>
<span style="color:#000099">Описание:</span><br/>
<b>'.$msg.'</b><br/>';
if($rows['fail']==1){
echo '<span style="color:#000099">Товар:</span>
<a href="../'.htmlspecialchars(trim($rows['parol'])).'"><b>СКАЧАТЬ</b></a><br/>';
}
if($rows['fail']==2){
echo '<span style="color:#000099">Товар:</span><br/>
<input type="text" name="name" value="'.htmlspecialchars(trim($rows['parol'])).'"/><br/>';
}
if($rows['fail']==3){
echo '<span style="color:#000099">Товар:</span><br/>
<input type="text" name="name" value="'.htmlspecialchars(trim($rows['parol'])).'"/><br/>';
}
$ur = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '".$rows['user_id']."';"));
echo '<span style="color:#000099">Статус:</span> '.$status.'<br/>
<span style="color:#000099">Цена:</span> <b>'.$stoim[0].' </b>руб.<br/>
<span style="color:#000099">Продает:</span> <b><a href="../mail.php?do=leave&log='.$ur['login'].'">'.$ur['login'].'</a></b><br/>
<span style="color:#000099">Продаж:</span>
<b>'.$kols.'</b></div>';
echo '<div class="box_1"></b><a href="shop.php?do=produkt_ok&id='.intval($rows['id']).'"><b>Акт</b></a> | </b><a href="shop.php?do=produkt_ban&id='.intval($rows['id']).'"><b>Бан</b></a> | </b><a href="shop.php?do=produkt_del&id='.intval($rows['id']).'"><b>Дел</b></a> ';
echo '</div>';
}
if($all > 5){
echo '<div class="box_1">Страницы: ';
$asd = $page - 2;
$asd2 = $page + 3; if ($pages>1){
if($asd<$all && $asd>0 && $page>3 ) echo ' <a href="shop.php?do=produkt&page=1">1</a> ... ';
for($i=$asd; $i<$asd2;$i++)
{
if($i<$all && $i>0)
{
if ($i > $pages ) break;
if ($page==$i) echo '<span><b>'.$i.'</b></span> ';
else echo '<a href="shop.php?do=produkt&page='.$i.'">'.$i.'</a> ';
}
}
if ($i <= $pages)
{
if($asd2<$all) echo ' ... <a href="shop.php?do=produkt&page='.$pages.'">'.$pages.'</a>';
}
}
echo '</div>';
}
} else echo '<div class="box_1">Нет выбранных товаров!</div>';
echo '<div class="title_page"><a href="index.php?do=index">Админка</a>/<a href="shop.php">Магазин</a></div>';
break;
case "produkt_ok":
echo '<div class="title_page">Товары</div>';
$id=$_GET['id'];
$c = mysql_result(mysql_query("SELECT COUNT(*) FROM `shop` where `id`='".$id."';"), 0);
if ($c > 0)
{
$result=@mysql_query("UPDATE `shop` SET `status`='1' WHERE `id`='".$id."'");
echo '<div class="box_1">Товар активирован!</div>';
} else echo '<div class="box_1">Нет выбранных товаров!</div>';
echo '<div class="title_page"><a href="index.php?do=index">Админка</a>/<a href="shop.php">Магазин</a></div>';
break;
case "produkt_ban":
echo '<div class="title_page">Товары</div>';
$id=$_GET['id'];
$c = mysql_result(mysql_query("SELECT COUNT(*) FROM `shop` where `id`='".$id."';"), 0);
if ($c > 0)
{
$result=@mysql_query("UPDATE `shop` SET `status`='2' WHERE `id`='".$id."'");
echo '<div class="box_1">Товар заблокирован!</div>';
} else echo '<div class="box_1">Нет выбранных товаров!</div>';
echo '<div class="title_page"><a href="index.php?do=index">Админка</a>/<a href="shop.php">Магазин</a></div>';
break;
case "produkt_del":
print '<div class="title_page">Товары</div>';
$id=$_GET['id'];
$c = mysql_result(mysql_query("SELECT COUNT(*) FROM `shop` where `id`='".$id."';"), 0);
if ($c > 0)
{
$rows = mysql_fetch_array(mysql_query("SELECT * FROM shop WHERE `id`='".$id."'"));
if ($rows['fail']==1) {
unlink ("".$rows['parol']."");
}
mysql_query("DELETE FROM `shop` WHERE `id`='".$rows['id']."'");
echo '<div class="box_1">Товар успешно удален.</div>';
} else echo '<div class="box_1">Нет выбранных товаров!</div>';
echo '<div class="title_page"><a href="index.php?do=index">Админка</a>/<a href="shop.php">Магазин</a></div>';
break;
case "kat_add":
echo '<div class="title_page">Катигория</div>';
if($_POST['ok'])
{
if (empty($_POST['nazva'])) $error ='Не заполнено поле <b>Название</b>!<br/>';
else
if(!preg_match(('#^([А-яA-z0-9 -.,"№;:@|ё<>()/?!]*)$#ui'), $_POST['nazva']) or (strlen($_POST['nazva']) < 2 or strlen($_POST['nazva']) > 1000000000)) $error ='Длина Сообщение от 2 до 1000000000 букв русского алфавита!<br/>';
if (!$count['tyuioteteeitruytripoetiweero']==1) $error ='Ошибка! Вы не администратор!<br/>';
if(!empty($error))
{
echo '<div class="output_err">';
echo $error;
echo '</div>';
echo '<div class="box_1">
<form action="shop.php?do=kat_add" method="post">
Название:<br/>
<textarea name="nazva" type="text" cols="13" rows="3"/>'.$_POST['nazva'].'</textarea><br/>
Товар:<br/>
<select name="fail">
<option value="1">Файл</option>
<option value="2">ICQ</option>
<option value="3">Текст</option>
</select><br/>
Номер:<br/>
<input name="cod" type="text" maxlength="4" size="6" value="'.$_POST['cod'].'"/><br/>
<input type="hidden" name="ok" value="true"/>
<input value="Добавить" class="button" type="submit"/></form></div>
';
}
else
{
$ts=time();
mysql_query("INSERT INTO `shopkategor` (`nazva`,`ids`,`idss`,`num`,`fail`) VALUE ('".$_POST['nazva']."','0','0','".$_POST['cod']."','".$_POST['fail']."');");
echo '<div class="box_1">Катигория добавлена!</div>';
}
}
else
{
echo '<div class="box_1">
<form action="shop.php?do=kat_add" method="post">
Название:<br/>
<textarea name="nazva" type="text" cols="13" rows="3"/></textarea><br/>
Товар:<br/>
<select name="fail">
<option value="1">Файл</option>
<option value="2">ICQ</option>
<option value="3">Текст</option>
</select><br/>
Номер:<br/>
<input name="cod" type="text" maxlength="4" size="6"/><br/>
<input type="hidden" name="ok" value="true"/>
<input value="Добавить" class="button" type="submit"/></form></div>
';
}
echo '<div class="title_page"><a href="index.php?do=index">Админка</a>/<a href="shop.php">Магазин</a></div>';
break;
case "kat_edit":
echo '<div class="title_page">Катигория</div>';
if($_GET['id']){
$id=$_GET['id'];
}
if($_POST['id']){
$id=$_POST['id'];
}
$kat=mysql_query("select * from `shopkategor` where `id`='".$id."';");
$nkat=mysql_num_rows($kat);
if($nkat > 0){
$okat = mysql_fetch_array($kat);
if($_POST['ok'])
{
if (empty($_POST['nazva'])) $error ='Не заполнено поле <b>Название</b>!<br/>';
else
if(!preg_match(('#^([А-яA-z0-9 -.,"№;:@|ё<>()/?!]*)$#ui'), $_POST['nazva']) or (strlen($_POST['nazva']) < 2 or strlen($_POST['nazva']) > 1000000000)) $error ='Длина Сообщение от 2 до 1000000000 букв русского алфавита!<br/>';
if (!$count['tyuioteteeitruytripoetiweero']==1) $error ='Ошибка! Вы не администратор!<br/>';
if(!empty($error))
{
echo '<div class="output_err">';
echo $error;
echo '</div>';
echo '<div class="box_1">
<form action="shop.php?do=kat_edit" method="post">
Название:<br/>
<textarea name="nazva" type="text" cols="13" rows="3"/>'.$_POST['nazva'].'</textarea><br/>
Номер:<br/>
<input name="cod" type="text" maxlength="4" size="6" value="'.$_POST['cod'].'"/><br/>
<input type="hidden" name="id" value="'.$id.'"/>
<input type="hidden" name="ok" value="true"/>
<input value="Изменить" type="submit"/></form></div>
';
}
else
{
$result=@mysql_query("UPDATE `shopkategor` SET `nazva`='".$_POST['nazva']."',`num`='".$_POST['cod']."' WHERE `id`='".$id."'");
echo '<div class="box_1">Катигория изменена!</div>';
}
}
else
{
echo '<div class="box_1">
<form action="shop.php?do=kat_edit" method="post">
Название:<br/>
<textarea name="nazva" type="text" cols="13" rows="3"/>'.$okat['nazva'].'</textarea><br/>
Номер:<br/>
<input name="cod" type="text" maxlength="4" size="6" value="'.$okat['num'].'"/><br/>
<input type="hidden" name="id" value="'.$id.'"/>
<input type="hidden" name="ok" value="true"/>
<input value="Изменить" type="submit"/></form></div>
';
}
}else{
echo '<div class="box_1">Ошибка! Катигория не найдена!</div>';
}
echo '<div class="title_page"><a href="index.php?do=index">Админка</a>/<a href="shop.php">Магазин</a></div>';
break;
case "sub_add":
echo '<div class="title_page">Катигория</div>';
if($_POST['ok'])
{
if (empty($_POST['nazva'])) $error ='Не заполнено поле <b>Название</b>!<br/>';
else
if(!preg_match(('#^([А-яA-z0-9 -.,"№;:@|ё<>()/?!]*)$#ui'), $_POST['nazva']) or (strlen($_POST['nazva']) < 2 or strlen($_POST['nazva']) > 1000000000)) $error ='Длина Сообщение от 2 до 1000000000 букв русского алфавита!<br/>';
if(!empty($error))
{
echo '<div class="output_err">';
echo $error;
echo '</div>';
echo '<div class="box_1">
<form action="shop.php?do=sub_add" method="post">
<select name="ids">';
$res = @mysql_query("SELECT * FROM `shopkategor` WHERE `ids`='0' and `idss`='0'");
while($row = @mysql_fetch_array($res)) {
echo '<option value="'.$row['id'].'" '.($_POST['ids']==$row['id']?" selected='selected'":null).'>'.$row['nazva'].'</option>';
}
echo '</select><br/>
Название:<br/>
<textarea name="nazva" type="text" cols="13" rows="3"/>'.$_POST['nazva'].'</textarea><br/>
Номер:<br/>
<input name="cod" type="text" maxlength="4" size="6" value="'.$_POST['cod'].'"/><br/>
<input type="hidden" name="ok" value="true"/>
<input value="Добавить" class="button" type="submit"/></form></div>
';
}
else
{
$ts=time();
mysql_query("INSERT INTO `shopkategor` (`nazva`,`ids`,`idss`,`num`) VALUE ('".$_POST['nazva']."','".$_POST['ids']."','0','".$_POST['cod']."');");
echo '<div class="box_1">Катигория добавлена!</div>';
}
}
else
{
echo '<div class="box_1">
<form action="shop.php?do=sub_add" method="post">
<select name="ids">';
$res = @mysql_query("SELECT * FROM `shopkategor` WHERE `ids`='0' and `idss`='0'");
while($row = @mysql_fetch_array($res)) {
echo '<option value="'.$row['id'].'">'.$row['nazva'].'</option>';
}
echo '</select><br/>
Название:<br/>
<textarea name="nazva" type="text" cols="13" rows="3"/></textarea><br/>
Номер:<br/>
<input name="cod" type="text" maxlength="4" size="6"/><br/>
<input type="hidden" name="ok" value="true"/>
<input value="Добавить" type="submit"/></form></div>
';
}
echo '<div class="title_page"><a href="index.php?do=index">Админка</a>/<a href="shop.php">Магазин</a></div>';
break;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
case 'index':
default:
echo '<div class="title_page">Магазин</div>';
$new = mysql_result(mysql_query("SELECT COUNT(*) FROM `shop` WHERE `status`='0'"), 0);
$aktiv = mysql_result(mysql_query("SELECT COUNT(*) FROM `shop` WHERE `status`='1'"), 0);
$ban = mysql_result(mysql_query("SELECT COUNT(*) FROM `shop` WHERE `status`='2' "), 0);
echo '<div class="box_2"><b class="b">»</b> <a href="shop.php?do=produkt&sort=0">На проверке Товары</a> ['.$new.']</div>';
echo '<div class="box_1"><b class="b">»</b> <a href="shop.php?do=produkt&sort=1">Активные Товары</a> ['.$aktiv.']</div>';
echo '<div class="box_2"><b class="b">»</b> <a href="shop.php?do=produkt&sort=2">Заблокироаные Товары</a> ['.$ban.']</div>';
echo '<div class="box_1"><b class="b">»</b> <a href="shop.php?do=kat_add">Новая Катeгория</a></div>';
echo '<div class="box_2"><b class="b">»</b> <a href="shop.php?do=sub_add">Суб Катигория</a></div>';
echo '<div class="title_page"><a href="index.php?do=index">Админка</a></div>';
break;
}
}else{
header("Location: ../index.php");
echo '<div id="link" style="display: none;">
<meta http-equiv="refresh" content="0;url=../index.php"></div>';
}
}else{
header("Location: ../index.php");
echo '<div id="link" style="display: none;">
<meta http-equiv="refresh" content="0;url=../index.php"></div>';
}
include "footer.php";
mysql_close();
?>