<?
include_once("req.php");

#array_walk($_REQUEST,"format_string");   
#array_walk($_POST,"format_string");   
#array_walk($_GET,"format_string");   

include_once("config.php");
include_once("session_class.php");
include_once("persinfo_class.php");
error_reporting(E_ALL ^ E_NOTICE);
session_start();
$session = new Sessions;

if(in_array(userip(),array('63.91.58.124','8.72.95.166'))) {
 $enter=1; $id=12;$session->id_person=$id;
}
if ($session->is_session(session_id())){
	$id=$session->id_person;$enter=1; 
} 
if ($enter) {

$myinfo =new Persinfo($id);
$myinfo->get_chat_params();
#if ($myinfo->id_person==279 && $myinfo->id_clan==24) {$myinfo->align=1.5;}
if ($myinfo->id_person==58 or $myinfo->id_person==12) {$myinfo->align=1.999;$mynazv='Ангел';}else{
if ((int)$myinfo->align==3) {$mynazv='Тарман';}
elseif ((int)$myinfo->align==1) {$mynazv='Паладин';}
else {$mynazv='Персонаж';}
}

$res=db_use('array',"select pal_access from align where align='".$myinfo->align."'");
$pal_abil=$res['pal_access'];
for ($i=0;$i<strlen($pal_abil);$i++) if ($pal_abil[$i]) $pal=1; 

if ($myinfo->id_person==12) {$vip=1;}

if (!$vip){ header("Location: main.php"); die;}


echo"
<HTML><HEAD>
<link rel=stylesheet type=\"text/css\" href=\"../i/main.css\">
<meta content=\"text/html; charset=windows-1251\" http-equiv=Content-type>
<META Http-Equiv=Cache-Control Content=no-cache>
<meta http-equiv=PRAGMA content=NO-CACHE>
<META Http-Equiv=Expires Content=0>
<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"../i/sl2.24.js\"></SCRIPT>
</HEAD>
<body leftmargin=5 topmargin=5 marginwidth=5 marginheight=5 bgcolor=#e2e0e0>
<SCRIPT src='../i/commoninf.js'></SCRIPT>
<p align=right><INPUT TYPE=button value=\"Вернуться\" onclick=\"top.returned()\"></p>
<div id=hint4 class=ahint></div>
<h3>
Доброе утро, товарищ <SCRIPT>drwfl(\"".$myinfo->name."\",".$myinfo->id_person.",\"".$myinfo->level."\",'".$myinfo->align."',\"".$myinfo->clanname."\")</SCRIPT></h3>
";
echo '<FONT style="FONT-SIZE: 10pt; COLOR: red"><B><div id="rezultat"></div></B></FONT>';

function text1($t1) {
switch ($t1) {
case 0:$t="- нет -";break;
case 1:$t="обмундирование";break;
case 2:$t="заклятия";break;
case 3:$t="Эликсиры";break;
case 4:$t="прочее";break;
}
return $t;
}
function text2($t2) {
switch ($t2) {
case 0:$t="- нет -";break;
case 1:$t="шлем";break;
case 2:$t="оружие";break;
case 3:$t="броня";break;
case 4:$t="пояс";break;
case 5:$t="серьги";break;
case 6:$t="кулон";break;
case 7:$t="наручи";break;
case 8:$t="перчатки";break;
case 9:$t="кольца";break;
case 10:$t="щит";break;
case 11:$t="сапоги";break;
case 12:$t="карманная вещь";break;
case 13:$t="свиток";break;
case 14:$t="зелье";break;
case 15:$t="амуниция";break;
case 16:$t="подарки";break;
}
return $t;
}
function text3($t3,$t2) {
switch ($t3) {
case 0:$t="- нет -";break;
case 1:$t=($t2==2?"оружие":'').($t2==3?"обычная":'').($t2==13?"нейтральные":'').($t2==16?"недобрые":'').($t2==14?"статовый элик":'');break;
case 2:$t=($t2==2?"двуручное":'').($t2==3?"легкая":'').($t2==13?"боевые и защитные":'').($t2==16?"открытки":'').($t2==14?"??":'');break;
case 3:$t=($t2==2?"костыли":'').($t2==3?"майка":'').($t2==13?"??":'').($t2=16?"упаковка":'').($t2==14?"??":'');break;
case 4:case 3:$t=($t2==2?"для двух слотов":'').($t2==3?"плащ":'').($t2==13?"??":'').($t2==16?"фейерверки":'').($t2==14?"??":'');break;
}
return $t;
}
function text4($t4) {
switch ($t4) {
case 0:$t="- нет -";break;
case 1:$t="кастеты/ножи";break;
case 2:$t="топоры";break;
case 3:$t="дубины/булавы";break;
case 4:$t="мечи";break;
case 5:$t="посохи";break;
case 6:$t="луки и арбалеты";break;
case 7:$t="цветы";break;
}
return $t;
}
if ($myinfo->id_person==12) {



if ($_REQUEST['rmask']) {
	$res=db_use('query',"select * from align where align>=1.1 and align<100");
	unset($i);while ($i<mysql_num_rows($res)) { 
		$i++;$s=mysql_fetch_array($res);
		$rm=str_repeat('0',37);
		for ($j=0;$j<37;$j++) {
			if ($_REQUEST['right'.str_replace('.','_',$s['align']).'-'.$j]=='on') {
				$rm[$j]=1;
			}
		}
		db_use('query',"update align set name='".mysql_escape_string($_REQUEST['name'.str_replace('.','_',$s['align'])])."',fullname='".mysql_escape_string($_REQUEST['fullname'.str_replace('.','_',$s['align'])])."',pal_access='".$rm."' where align='".$s['align']."'");
	}
	echo "Сохранено<br />";
	$_REQUEST['showrmask']=1;
}
if ($_REQUEST['showrmask']){
	echo "<form method=post action=vip.php?rmask=1>";
	echo "<h4>Права палов</h4><table>";
	$zag="<tr>
	<td>Склонность</td>
	<td id=0>+th
	<td id=1>delth
	<td id=2>+mf
	<td id=3>viewth
	<td id=4><img src=/img/palbutt/sleep_002.gif>+прайс палов
	<td id=5>delo
	<td id=6>palstatus
	<td id=7><img src=../i/items/pal_button3.gif>
	<td id=8><img src=../i/items/pal_button4.gif>
	<td id=9><img src=../i/items/pal_button5.gif>
	<td id=10><img src=../i/items/pal_button6.gif>
	<td id=11><img src=../i/items/pal_button7.gif>
	<td id=12><img src=../i/items/pal_button8.gif>
	<td id=13><img src=../i/items/pal_button9.gif>
	<td id=14><img src=../i/items/palbuttonzu3.gif>
	<td id=15>IP
	<td id=16>гос
	<td id=17>гос++
	<td id=18>palsite
	<td id=19><img src=../i/items/pal_buttons.gif>
	<td id=20><img src=../i/items/cui.gif>
	<td id=21><img src=../i/items/uncui.gif>
	<td id=22>Свадьба
	<td id=23>дата
	<td id=24>емейл
	<td id=25>склонности
	<td id=26>модерация форума
	<td id=27>разводы
	<td id=28><IMG SRC=../i/items/pal_button[password].gif WIDTH=40 HEIGHT=25>
	<td id=29><IMG SRC=../i/items/pal_button[nick].gif WIDTH=40 HEIGHT=25>
	<td id=30><IMG SRC=../i/items/pal_button[gender].gif WIDTH=40 HEIGHT=25>
	<td id=31>файлы прайсов
	<td id=32><IMG SRC=../i/items/pal_button[delete2].gif WIDTH=40 HEIGHT=25>
	<td id=33><IMG SRC=../i/items/pal_button[battle_delete].gif WIDTH=40 HEIGHT=25>
	<td id=34>беспл смена ника
	<td id=35>ORGTeam chat
	</tr>";
	echo $zag;
	$res=db_use('query',"select * from align where align>=1 and align<400");
	unset($i);while ($i<mysql_num_rows($res)) { 
		$i++;$s=mysql_fetch_array($res);
		echo $zag;
		echo "<tr><td><img src=../i/align".$s['align'].".gif>".$s['align']."</td>";
		echo "<tr><td><input type=text name=\"name".str_replace('.','_',$s['align'])."\" maxlength=20 value=\"".htmlspecialchars($s[name])."\"><br /><input type=text name=\"fullname".str_replace('.','_',$s['align'])."\" maxlength=35 value=\"".htmlspecialchars($s[fullname])."\">
</td>";
		for ($j=0;$j<37;$j++) {
			echo"<td><input type=checkbox 
			name=\"right".str_replace('.','_',$s['align']).'-'.$j."\" ".($s['pal_access'][$j]?'checked':'').">";
		}
		echo"</tr>";
	}
	echo "</table><input type=submit></form>";
}else{
echo "<a href=vip.php?showrmask=1>Права палов</a> ";
}
if ($myinfo->id_person==12 or $myinfo->id_person==58) { # Добавить шмот в магаз
	if ($_REQUEST['addth']) {
		$res=db_use('array',"select * from thing_har where id_thing2='".mysql_escape_string($_REQUEST['addth'])."'");
		$price=($res['ekr']?($res['ekr']>$res['god_price']?$res['ekr']:$res['gos_price']):$res['gos_price']);
		if ($price>$_REQUEST['price']) {$mess='Цена ниже номинала';}else{
		
		$res=db_use('array',"select * from shop where id_thing2='".mysql_escape_string($_REQUEST['addth'])."' and id_room=17");
		if ($res['id_thing2']) {
			db_use('query',"update shop set scount='".(0+mysql_escape_string($_REQUEST['scount']))."',price='".(0+mysql_escape_string($_REQUEST['price']))."' where id_thing2='".mysql_escape_string($_REQUEST['addth'])."' and id_room=17");
		}elseif ($myinfo->id_person==12){
			db_use('query',"insert into shop (id_thing2,scount,price,id_room) values ('".mysql_escape_string($_REQUEST['addth'])."','".(0+mysql_escape_string($_REQUEST['scount']))."','".(0+mysql_escape_string($_REQUEST['price']))."',17)");
		}else{
			$mess='Access Denied';}
			$_REQUEST['addth']='';
		}
		}#/nominal
}
#if ($pal_abil[16]) {
if ($myinfo->id_person==12 or $myinfo->id_person==58 ) { # Добавить шмот в магаз
echo "<a href=vip.php?shop=1&desc=desc>Гос Магазин</a> ";
	if($_REQUEST['shop']) {
		if ($_REQUEST['savething']) {
			$res=db_use('array',"select * from thing_har where id_thing2='".mysql_escape_string($_REQUEST['editth'])."'");
			if ($_REQUEST['price']<($res['gos_price']>$res['ekr']?$res['gos_price']:$res['ekr'])) { $mess='Нельзя выставить меньше номинала'; }else{
				db_use('query',"update shop set scount='".(0+mysql_escape_string($_REQUEST['scount']))."',price='".(0+mysql_escape_string($_REQUEST['price']))."' where id_thing2='".mysql_escape_string($_REQUEST['editth'])."' and id_room=17");
				$_REQUEST['editth']='';
			}
		}elseif($_REQUEST['delth']) {
			db_use('query',"delete from shop where id_thing2='".mysql_escape_string($_REQUEST['delth'])."' and id_room=17");
		}
		
		/*$res=db_use('query',"select sh.*,th.name,th.gos_price,th.ekr,th.artefact FROM shop sh left join thing_har th on th.id_thing2=sh.id_thing2 order by th.name");
		echo "<table cellspacing=0 cellpadding=0><tr><td><small>idt2</small></td><td><small>Название</small></td><td><small>Количество</small></td><td><small>Цена</small></td><td><small>Гос</small></td><td><small>Управл</small></td></tr>";
		unset($i);while ($i<mysql_num_rows($res)) { 
			$i++;$s=mysql_fetch_array($res);
			if ($_REQUEST['editth']==$s['id_thing2']) {
				echo "<form method=post action=vip.php?shop=1&editth=".$s['id_thing2']."><tr><td><small>".$s['id_thing2'].'</small></td><td><small>'.($s['artefact']?'<img src=../i/artefact.gif>':'').$s['name'].'</small></td><td><input type=text value="'.$s['scount'].'" name=scount></td><td><input type=text value="'.$s['price'].'" name=price></td><td><small>'.$s['gos_price'].($s['ekr']?'('.$s['ekr'].' екр)':'').'</small></td><td><input type=submit name=savething value="Сохранить"></td></tr></form>';
			}else{
				echo "<tr><td><small>".$s['id_thing2'].'</small>&nbsp;</td><td><small>'.($s['artefact']?'<img src=../i/artefact.gif>':'').$s['name'].'</small></td><td><small>'.$s['scount'].'</small></td><td><small>'.$s['price'].'</small></td><td><small>'.$s['gos_price'].($s['ekr']?'('.$s['ekr'].' екр)':'').'</small></td><td><small><a href=vip.php?shop=1&editth='.$s['id_thing2'].'>Изменить</a> <a href=vip.php?shop=1&delth='.$s['id_thing2'].'>Удалить</a><a href=vip.php?viewshm='.$s['id_thing2'].' target=_blank>Просмотр</a></small></td></tr>';
			}
		}
		echo "</table><hr>";
		*/ 
		if ($myinfo->id_person==12 or $myinfo->id_person==58) {
			$skip=(($_REQUEST['skip']+0)>0?($_REQUEST['skip']+0):0);
			$max=(($_REQUEST['max']+0)>0?($_REQUEST['max']+0):30);
			if ($_REQUEST['desc']=='desc') {$desc='desc';$antidesc='asc';} else {$desc='asc';$antidesc='desc';}
			echo "<form method=post action=vip.php?shop=1&desc=$desc&order=".$_REQUEST['order'].">Вывести: <input type=text name=max value=\"".$max."\"> шт начиная с <input type=text name=skip value=\"".$skip."\"><input type=submit value=\"Показать\"></form><br />";
			echo ($skip?"<a href=vip.php?shop=1&skip=".($skip-$max)."&desc=$desc&order=".$_REQUEST['order']."&max=$max><<назад</a>":'')."<a href=vip.php?shop=1&skip=".($skip+$max)."&desc=$desc&order=".$_REQUEST['order']."&max=$max>вперед>></a><br />";
			echo "<table cellspacing=0 cellpadding=0><tr><td><a href=vip.php?shop=1&skip=$skip&max=$max&order=0&desc=".($_REQUEST['order']?$desc:$antidesc).">idt2</a></td><td><a href=vip.php?shop=1&skip=$skip&max=$max&order=1&desc=".($_REQUEST['order']==1?$antidesc:$desc).">Название</a></td><td><a href=vip.php?shop=1&skip=$skip&max=$max&order=2&desc=".($_REQUEST['order']==2?$antidesc:$desc).">Количество</a></td><td><a href=vip.php?shop=1&skip=$skip&max=$max&order=3&desc=".($_REQUEST['order']==3?$antidesc:$desc).">Цена</a></td><td><a href=vip.php?shop=1&skip=$skip&max=$max&order=4&desc=".($_REQUEST['order']==4?$antidesc:$desc).">Гос</a> <a href=vip.php?shop=1&skip=$skip&max=$max&order=5&desc=".($_REQUEST['order']==5?$antidesc:$desc).">Екр</a></td><td><a href=vip.php?shop=1&skip=$skip&max=$max&order=6&desc=".($_REQUEST['order']==6?$antidesc:$desc).">тип1</a></td><td><a href=vip.php?shop=1&skip=$skip&max=$max&order=7&desc=".($_REQUEST['order']==7?$antidesc:$desc).">тип2</a></td><td><a href=vip.php?shop=1&skip=$skip&max=$max&order=8&desc=".($_REQUEST['order']==8?$antidesc:$desc).">тип3</a></td><td><a href=vip.php?shop=1&skip=$skip&max=$max&order=9&desc=".($_REQUEST['order']==9?$antidesc:$desc).">тип4</a></td><td>Всего</td><td>Инв</td><td>Надето</td><td>Комок</td><td>Управл</td></tr>";
			switch ($_REQUEST['order']) {
			case 1: $order='th.name'; break;
			case 2: $order='sh.scount'; break;
			case 3: $order='sh.price'; break;
			case 4: $order='th.gos_price'; break;
			case 5: $order='th.ekr'; break;
			case 6: $order='th.type1'; break;
			case 7: $order='th.type2'; break;
			case 8: $order='th.type3'; break;
			case 9: $order='th.type4'; break;
			default: $order='id_thing2';break;
			}
			$res=db_use('query',"select th.*,sh.scount,sh.price , (select count(*) from thing where id_thing2=th.id_thing2) as coun_all
			 , (select count(id_thing) from thing where id_thing2=th.id_thing2 and id_thing in (select id_thing from inv)) as coun_inv
			 , (select count(id_thing) from thing where id_thing2=th.id_thing2 and id_thing in (select id_thing from puton)) as coun_puton
			 , (select count(id_thing) from thing where id_thing2=th.id_thing2 and id_thing in (select id_thing from komok)) as coun_komok
			from thing_har th 
			left join shop sh on sh.id_thing2=th.id_thing2 and sh.id_room=17 
			order by ".$order." ".$desc." limit ".$skip.",".$max."");
		unset($i);while ($i<mysql_num_rows($res)) { 
			$i++;$s=mysql_fetch_array($res);
			echo "<form method=post action=vip.php?shop=1&addth=".$s['id_thing2']."&desc=$desc&order=".$_REQUEST['order']."&max=$max&skip=$skip#".$s['id_thing2']."><tr><td><small>".$s['id_thing2'].'</small></td><td><nobr><small>'.($s['artefact']?'<img src=../i/artefact.gif>':'').($s['scount']<1?'<font color=red>':'').$s['name'].($s['align']?'<img src=../i/align'.$s['align'].'.gif>':'').($s['scount']<1?'</font>':'').'</small></nobr></td><td><input type=text value="'.$s['scount'].'" name=scount width=\"100 px\"></td><td><input type=text value="'.($s['price']?$s['price']:($s['gos_price']>$s['ekr']?$s['gos_price']:$s['ekr'])).'" name=price></td><td>'.$s['gos_price'].($s['ekr']?' ('.$s['ekr'].' екр)':'').'</td><td>'.text1($s['type1']).'</td><td>'.text2($s['type2']).'</td><td>'.text3($s['type3'],$s['type2']).'</td><td>'.text4($s['type4']).'</td><td>'.$s[coun_all].'</td><td>'.$s[coun_inv].'</td><td>'.$s[coun_puton].'</td><td>'.$s[coun_komok].'</td><td><nobr><input type=submit name=addthing value="Выставить">';
			
	if ($_GET['shm']==$s['id_thing2']) {echo "</nobr>";
		$s2=db_use('array',"select th.maxsrok_default,th.weight,th.type1 from thing_har th 
			where th.id_thing2='".$s['id_thing2']."';");
			$value=new thinginfo($s['id_thing2']);
			$value->maxsrok=$s2['maxsrok_default'];
		$harnames=getharnames();$cityname=getcitiesnames();
	echo "<!--Рюкзак--><TABLE WIDTH=100% CELLSPACING=1 CELLPADDING=2 BGCOLOR=A5A5A5>
<TR id=".$s['id_thing2']." bgcolor=#".($i<0?"C7C7C7":"D5D5D5").">";
		printinfo($value,$myinfo,1,"","<A target=_blank HREF=\"shop.php?set=".$value->id_thing2."&id=1&".($ott=='present'?'present':$ott)."&sid=".$_REQUEST['sid']."&sd4=1152918974&".rand(0,1111111)."\">купить</A>&nbsp;<IMG SRC=\"../i/up.gif\" WIDTH=11 HEIGHT=11 BORDER=0 ALT=\"Купить несколько штук\" style=\"cursor:hand\" onclick=\"AddCount('".$value->id_thing2."', '".mysql_escape_string($value->name)."')\">",($myinfo->money<$value->gos_price?"<FONT COLOR=RED>":"").$value->gos_price.($myinfo->money<$value->gos_price?"</FONT>":"")." кр.</b> <small>(количество: ".$value->scount.")</small>");
	echo"</TR></table>";
	echo "<nobr>";
	}
	echo"<small><a href=vip.php?viewshm=".$s['id_thing2']." target=_shmotview>VIEW</a><a href=vip.php?shop=1&shm=".$s['id_thing2']."&desc=$desc&order=".$_REQUEST['order']."&max=$max&skip=$skip#".$s['id_thing2'].">просм</a></small> <a href=http://img.combats.ru/i/items/".$s['pic'].".gif target=_blank>Картинка БК</a></nobr>";
			
			echo'</td></tr></form>';
		}
		echo "</table><hr>";
			die;
		}
	}
}



}#/12


}else {
$session->destroy_session(session_id() );
session_destroy();
header("Location: totop.htm"); die;
}
?>
</FORM>
</BODY>
</HTML>