View file mch-lib/sys/php_code/index.php

File size: 30.47Kb
<?php
##########################################
##UTF-8,lang-ru,"Monospace"(regular)[10]##
##########################################

######                                ######
##Администраторский раздел - основной код.##
######                                ######

######################
##Проверить крнстанту для проверки, запущен ли файл так, как предусмотрено:
  if(!defined("IN_USE")) {
  	exit('CLOSE');
  }
######################



$smarty = new Smarty;
//$smarty->display($theme.'/user/index.tpl');


@$Act = $_GET["do"];
  if($Act) {
    if(!is_numeric($Act)) {
	  exit(NOT_NUMBER);
	}
  }

  switch($Act) {
    case 1: {
    	$id = intval($_GET["id"]);
		$id = mysql_real_escape_string($id);
		$sql_sel = "SELECT * FROM mlb_texts WHERE text_id=$id and text_pid=0";
		$query = mysql_query($sql_sel);
		@$res_read = mysql_fetch_array($query);
		if(empty($res_read["text_id"])) {
					$smarty->assign('INFORMATION',TEXT_NOT_EXISTS_ELSE);
			        $smarty->assign("LINK","?do=");
	    	        $smarty->assign("LINKT","Назад");
			        $smarty->display($theme.'/info.tpl');
			        break;
		}
		@$tpuser = intval($_GET["tpuser"]);
		//@$tex = intval($_GET["tpuser"]);
			if(@$tpuser) {
				switch ($tpuser) {
					case $textn: $_SESSION["ctpr"] = $textn; break;
					case $textn*2: $_SESSION["ctpr"] = $textn*2; break;
					case $textn*3: $_SESSION["ctpr"] = $textn*3; break;
					case $textn*4: $_SESSION["ctpr"] = $textn*4; break;
					default : $_SESSION["ctpr"] = $textn; break;
				}
			}
			@$_SESSION["ctpr"] ? $tpuser = $_SESSION["ctpr"] : $tpuser = $textn;
			$textp = $tpuser;
			@$font = intval($_GET["font"]);
		//@$tex = intval($_GET["tpuser"]);
		if($font) $_SESSION["fontn"] = $font;
		if(@$_SESSION["fontn"] || @!$_SESSION["font"]) {
				switch ($_SESSION["fontn"]) {
					case 1: $_SESSION["font"] = "<small>#</small>"; $_SESSION["fontn"]=1; break;
					case 2: $_SESSION["font"] = " # ";$_SESSION["fontn"]=2; break;
					case 3: $_SESSION["font"] = "<big>#</big>";$_SESSION["fontn"]=3; break;
					default : $_SESSION["font"] = "<small>#</small>";$_SESSION["fontn"]=1; break;
				}
		}
				$font = $_SESSION["font"];
		$r_b = mysql_fetch_array(mysql_query("SELECT cat_name, cat_id FROM mlb_cat WHERE cat_id={$res_read["text_cid"]}"));
		  $sql_g = mysql_query("SELECT text_id, text_pid, text_name, text_about FROM mlb_texts WHERE text_pid=$id ORDER BY text_name ASC");
		  while($glav = mysql_fetch_array($sql_g)) {
					$names_g[] = stripslashes(htmlspecialchars($glav["text_name"]));
					$ids_g[] = $glav["text_id"];
					if($glav["text_id"] == $_GET["pg"]) {
				  			$nl_g[] = $glav["text_id"];
					} else $nl_g[] = FALSE;
		  }
				@$smarty->assign("names_g",$names_g);
				@$smarty->assign("ids_g",$ids_g);
				@$smarty->assign("nl_g",$nl_g);

				$smarty->assign("r_bi",$r_b["cat_id"]);
				$smarty->assign("name",stripslashes(htmlspecialchars($res_read["text_name"])));
				$smarty->assign("id",$res_read["text_id"]);
				$smarty->assign("date",date("d.m.y/H:i", $res_read["text_date"]));
				$smarty->assign("author",stripslashes(htmlspecialchars($res_read["text_author"])));
				$smarty->assign("original",stripslashes(htmlspecialchars($res_read["text_original"])));

		    $fcount = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM mlb_files WHERE file_tid=$id"));
		    if($fcount[0]>0) {
					  $smarty->assign("vfiles",1);
					  $smarty->assign("fc",$fcount[0]);
			}

		if(@$_GET["pg"]) {
				$idg = intval($_GET["pg"]);
				$idg = mysql_real_escape_string($idg);
			 		$thg = mysql_fetch_array(mysql_query("SELECT text_name, text_id, text_text FROM mlb_texts WHERE text_id=$idg"));
			 		$texte1 = wordwrap(stripslashes(trim($thg["text_text"])), 224);
		} else {
		     	$texte1 = wordwrap(stripslashes(trim($res_read["text_text"])), 224);
		  }

		  $text = explode("\n", $texte1);

		  	if(@$_POST["do_my_page"]) {
					@$start = (intval($_POST["do_my_page"])-1)*$textp;
			}
			@$start = abs($start);
		    if(sizeof($text)-1 <= $textp) {
					$texte = new bbcode($texte1);
					$texte -> mnemonics = $smiles;
					$texte = $texte -> get_html();
				  $smarty->assign("text",$texte);
		    } else {
		    	$cur_text = '';
		    	if($start != 0) $start = $start + 1;
		    	for($i=$start;$i<=$start+$textp;$i++) {
		    			@$cur_text .= $text[$i].' ';
				}
					$textec = new bbcode($cur_text);
					$textec -> mnemonics = $smiles;
					$textec = $textec -> get_html();
					$smarty->assign("text",$textec);
			  }

					  $sq_comm = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM mlb_comments WHERE comm_tid=$id"));
					  $smarty->assign("comm",$sq_comm[0]);



#############
#############
#############
			$all = sizeof($text)-1;
			if($start > $all) exit();
if(@$_GET["pg"])  {
	 $in = '&pg='.$idg;
} else {
	 $in = '';
  }
ob_start();
			echo (round($start/$textp,0)+1).'/'.(($all/$textp>round($all/$textp,0)) ? (round($all/$textp,0)+1) : (round($all/$textp,0))).'<br />';
			if($start>0) {
			  echo '<a href="?do=1'.$in.'&id='.$id.'&p='.($start-$textp).'">'.PREV.'</a>|';
			}
			if(round($all/$textp,0) > 10) {
				if(round($start/$textp,0) < 4) {
				  for($i=0;$i<=4;$i++) {
				  	if((round($start/$textp,0)+1) == ($i+1)) echo '[';
				  	echo '<a href="?do=1'.$in.'&id='.$id.'&p='.($i*$textp).'">'.($i+1).'</a>';
				  	if((round($start/$textp,0)+1) == ($i+1)) echo ']';
				  	if($i!=4) echo ',';
				  }
				  echo ' ... ';
				  for($i=round($all/$textp,0)-3;$i<=round($all/$textp,0)-1;$i++) {
				  	echo '<a href="?do=1'.$in.'&id='.$id.'&p='.($i*$textp).'">'.($i+1).'</a>';
				  	if($i!=round($all/$textp,0)-1) echo ',';
				  }
			    }
			    if(round($start/$textp,0) >= 4) {
				  for($i=0;$i<=2;$i++) {
				  	echo '<a href="?do=1'.$in.'&id='.$id.'&p='.($i*$textp).'">'.($i+1).'</a>';
				  	if($i!=2) echo ',';
				  }
				  echo ' ... ';
				  if($all > $start+$textp*4) {
				    echo '<a href="?do=1'.$in.'&id='.$id.'&p='.($start-$textp).'">'.(round($start/$textp,0)).'</a>,';
				    echo '[<a href="?do=1'.$in.'&id='.$id.'&p='.($start).'">'.(round($start/$textp,0)+1).'</a>],';
				    echo '<a href="?do=1'.$in.'&id='.$id.'&p='.($start+$textp).'">'.(round($start/$textp,0)+1+1).'</a>';
				  echo ' ... ';
			      } else {
			      	  echo '<a href="?do=1'.$in.'&id='.$id.'&p='.($all+1-$textp * 6).'">'.(round(($all-$textp * 5)/$textp,0)).'</a>,';
			      	  echo '<a href="?do=1'.$in.'&id='.$id.'&p='.($all+1-$textp * 5).'">'.(round(($all-$textp * 4)/$textp,0)).'</a>,';
			      	  if($start == $all+1-$textp * 4) echo '[';
			      	  echo '<a href="?do=1'.$in.'&id='.$id.'&p='.($all+1-$textp * 4).'">'.(round(($all-$textp * 3)/$textp,0)).'</a>';
			      	  if($start == $all+1-$textp * 4) echo ']';
			      	  echo ',';
				    }
				  for($i=round($all/$textp,0)-3;$i<=round($all/$textp,0)-1;$i++) {
				  	if((round($start/$textp,0)+1) == ($i+1)) echo '[';
				  	echo '<a href="?do=1'.$in.'&id='.$id.'&p='.($i*$textp).'">'.($i+1).'</a>';
				  	if((round($start/$textp,0)+1) == ($i+1)) echo ']';
				  	if($i!=round($all/$textp,0)-1) echo ',';
				  }
			    }
			} else {
				for($i=0;$i<=round($all/$textp,0);$i++) {
					if((round($start/$textp,0)+1) == ($i+1)) echo '[';
				  	echo '<a href="?do=1'.$in.'&id='.$id.'&p='.($i*$textp).'">'.($i+1).'</a>';
				  	if((round($start/$textp,0)+1) == ($i+1)) echo ']';
				  	if($i!=round($all/$textp,0)) echo ',';
					if(($i/10*$topage+1)>=$all/$textp) break;
				  }
			  }
			  if($start+$textp<$all) {
			    echo '|<a href="?do=1'.$in.'&id='.$id.'&p='.($start+$textp).'">'.NEXT.'</a>';
			  }
$nav = ob_get_contents();
ob_clean();
			  $smarty->assign("nav_here",$nav);
#############
#############
#############
		$mfont = explode("#", $font);
		$mfont1 = $mfont[0];
		$mfont2 = $mfont[1];
		$smarty->assign('mfont1', $mfont1);
		$smarty->assign('mfont2', $mfont2);
		$smarty->display($theme.'/user/read.tpl');
		$smarty->display($theme.'/user/nav.tpl');
		$smarty->assign('textn', $textn);
		$smarty->assign('ctpr', $textp);
		$smarty->assign('font', $font);
		$smarty->assign('all', $all);
		$smarty->assign('id', $id);
		$smarty->display($theme.'/user/block_select_read.tpl');


	} break;
	case 2: {
		$id = intval($_GET["tid"]);
		$id = mysql_real_escape_string($id);
		    	$fsql = mysql_query("SELECT * FROM mlb_files WHERE file_tid=$id");
		    	while(@$resf = mysql_fetch_array($fsql)) {
		    		$files[] = $resf["file_address"];
		    		$fsize[] = round(filesize($dir_f.$resf["file_address"])/1024,2);
				}
				$smarty->assign("fsize",$fsize);
				$smarty->assign("files",$files);
				$smarty->assign("dir",$dir_f);
				$smarty->assign("id",$id);
				$smarty->display($theme.'/user/files.tpl');
	} break;
	case 3: {
		if(@!$_GET["text"]) {
		  $smarty->display($theme.'/user/search.tpl');
	  	} else {
	  		$text = trim($_GET["text"]);
	  		@$wh = intval($_GET["wh"]);
	  		$text = mysql_real_escape_string($text);
	  		if(@!$_GET["wh"]) {
	  				$smarty->assign('INFORMATION',SEARCH_MODE_NOT);
			        $smarty->assign("LINK","?do=4");
	    	        $smarty->assign("LINKT","Назад");
			        $smarty->display($theme.'/info.tpl');
			}
	  		  if($wh == 1) {
	  		  	$co = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM mlb_texts WHERE text_name LIKE '%$text%' and text_pid=0"));
	  		  	if($co[0] == 0) {
	  		  			$smarty->assign("INFORMATION",SEARCH_NOT_VALID);
	    	    		$smarty->assign("LINK","?do=3");
	    	    		$smarty->assign("LINKT","Назад");
    	        		$smarty->display($theme.'/info.tpl');
    	        		break;
				}
	  		  	$sql = "SELECT * FROM mlb_texts WHERE text_name LIKE '%$text%' and text_pid=0 LIMIT $start, 20";
	  		  	$query = mysql_query($sql);
	  		  	while($res = mysql_fetch_array($query)) {
	  		  		$sq_ca = mysql_fetch_array(mysql_query("SELECT cat_name FROM mlb_cat WHERE cat_id={$res["text_cid"]}"));
	  		  		empty($sq_ca["cat_name"]) ? $is_cont = 1 : $cats[] = $sq_ca["cat_name"];
	  		  		if(@$is_cont) {
	  		  			$is_cont = 0;
	  		  			continue;
					}
	  		  		$ser[] = str_replace($text, '<font color="#555500">'.$text.'</font>', stripslashes(htmlspecialchars($res["text_name"])));
	  		  		$ids[] = $res["text_id"];
				}
				ob_start();
				@$start = abs($start);
				if($start+20 > $co[0]) $dmes = $co[0]; else $dmes = $start+20;
				if($start > $co[0]) exit(SEARCH_NOT_VALID);
				echo 'Результатов поиска: '.$start.'-'.$dmes.' из '.$co[0].'<br />';
				if($start>0) {
		    		echo '<small> <a href="?do=3&text='.$text.'&p='.($start-20).'&wh='.$wh.'">Пред.</a></small>';
          		}
          		if($start + 20 < $co[0]) {
		    	  echo '<small> <a href="?do=3&text='.$text.'&p='.($start+20).'&wh='.$wh.'">След.</a> </small>';
				}
				$nav = ob_get_contents();
				ob_clean();
				$smarty->assign("nav",$nav);
				$smarty->assign("cats",$cats);
				$smarty->assign("ser",$ser);
				$smarty->assign("ids",$ids);
				$smarty->display($theme.'/user/search_act.tpl');
				break;
			  }
			  if($wh == 2) {
			  	$co = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM mlb_texts WHERE text_text LIKE '%$text%' and text_pid=0"));
			  	if($co[0] == 0) {
	  		  			$smarty->assign("INFORMATION",SEARCH_NOT_VALID);
	    	    		$smarty->assign("LINK","?do=3");
	    	    		$smarty->assign("LINKT","Назад");
    	        		$smarty->display($theme.'/info.tpl');
    	        		break;
				}
	  		  	$sql = "SELECT * FROM mlb_texts WHERE text_text LIKE '%$text%' and text_pid=0 LIMIT $start, 20";
	  		  	$query = mysql_query($sql);
	  		  	while($res = mysql_fetch_array($query)) {
	  		  		$sq_ca = mysql_fetch_array(mysql_query("SELECT cat_name FROM mlb_cat WHERE cat_id={$res["text_cid"]}"));
	  		  		empty($sq_ca["cat_name"]) ? $is_cont = 1 : $cats[] = $sq_ca["cat_name"];
	  		  		if(@$is_cont) {
	  		  			$is_cont = 0;
	  		  			continue;
					}
	  		  		$ser[] = str_replace($text, '<font color="#555500">'.$text.'</font>', stripslashes(htmlspecialchars($res["text_name"])));
	  		  		$ids[] = $res["text_id"];
				}
				ob_start();
				@$start = abs($start);
				if($start+20 > $co[0]) $dmes = $co[0]; else $dmes = $start+20;
				if($start > $co[0]) exit(SEARCH_NOT_VALID);
				echo 'Результатов поиска: '.$start.'-'.$dmes.' из '.$co[0].'<br />';
				if($start>0) {
		    		echo '<small> <a href="?do=3&text='.$text.'&p='.($start-20).'&wh='.$wh.'">Пред.</a></small>';
          		}
          		if($start + 20 < $co[0]) {
		    	  echo '<small> <a href="?do=3&text='.$text.'&p='.($start+20).'&wh='.$wh.'">След.</a> </small>';
				}
				$nav = ob_get_contents();
				ob_clean();
				$smarty->assign("nav",$nav);
				$smarty->assign("cats",$cats);
				$smarty->assign("ser",$ser);
				$smarty->assign("ids",$ids);
				$smarty->display($theme.'/user/search_act.tpl');
				break;
			  }
			  if($wh == 3) {
			  	$co = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM mlb_cat WHERE cat_name LIKE '%$text%' and cat_status=0"));
			  	if($co[0] == 0) {
	  		  			$smarty->assign("INFORMATION",SEARCH_NOT_VALID);
	    	    		$smarty->assign("LINK","?do=3");
	    	    		$smarty->assign("LINKT","Назад");
    	        		$smarty->display($theme.'/info.tpl');
    	        		break;
				}
	  		  	$sql = "SELECT * FROM mlb_cat WHERE cat_name LIKE '%$text%' and cat_status=0 LIMIT $start, 20";
	  		  	$query = mysql_query($sql);
	  		  	while($res = mysql_fetch_array($query)) {
	  		  		$ser[] = str_replace($text, '<font color="#555500">'.$text.'</font>', stripslashes(htmlspecialchars($res["cat_name"])));
	  		  		$ids[] = $res["cat_id"];
				}
				ob_start();
				@$start = abs($start);
				if($start+20 > $co[0]) $dmes = $co[0]; else $dmes = $start+20;
				if($start > $co[0]) exit(SEARCH_NOT_VALID);
				echo 'Результатов поиска: '.$start.'-'.$dmes.' из '.$co[0].'<br />';
				if($start>0) {
		    		echo '<small> <a href="?do=3&text='.$text.'&p='.($start-20).'&wh='.$wh.'">Пред.</a></small>';
          		}
          		if($start + 20 < $co[0]) {
		    	  echo '<small> <a href="?do=3&text='.$text.'&p='.($start+20).'&wh='.$wh.'">След.</a> </small>';
				}
				$nav = ob_get_contents();
				ob_clean();
				$smarty->assign("nav",$nav);
				$smarty->assign("ser",$ser);
				$smarty->assign("ids",$ids);
				$smarty->display($theme.'/user/search_act_cat.tpl');
				break;
			  }
		  }
	} break;
	case 4: {
		$id = intval($_GET["id"]);
		$id = mysql_real_escape_string($id);
			    if(@$_GET["ok"]) {
			    	if($_SESSION["comment"]) {
			    			if((time() - $_SESSION["comment"]) < 5) {
			    				$smarty->assign("INFORMATION", COMM_TIME);
	    	    				$smarty->assign("LINK","?do=4&id=".$id);
	    	    				$smarty->assign("LINKT","Назад");
    	        				$smarty->display($theme.'/info.tpl');
    	        				break;
							}
					}
			    	$name = trim($_POST["namec"]);
			    	if(empty($name)) {
			    		$smarty->assign("INFORMATION",NAME_COMM_NOT_EXISTS);
	    	    		$smarty->assign("LINK","?do=4&id=".$id);
	    	    		$smarty->assign("LINKT","Назад");
    	        		$smarty->display($theme.'/info.tpl');
    	        		exit();
					}
					$name = substr($name, 0, 64);
					$text = trim($_POST["comm"]);
					if(empty($text)) {
			    		$smarty->assign("INFORMATION",TEXT_COMM_NOT_EXISTS);
	    	    		$smarty->assign("LINK","?do=4&id=".$id);
	    	    		$smarty->assign("LINKT","Назад");
    	        		$smarty->display($theme.'/info.tpl');
    	        		exit();
					}
					$text = substr($text, 0, 8412);
					$date = time();
					$name = mysql_real_escape_string($name);
					$text = mysql_real_escape_string($text);
					  $sql = "INSERT INTO mlb_comments VALUES ('', '$name', '$text', $date, $id)";
					  if(mysql_query($sql)) {
					  	$_SESSION["comment"] = time();
					  	$smarty->assign("INFORMATION",COMMENT_IS_ADD);
	    	    		$smarty->assign("LINK","?do=4&id=".$id);
	    	    		$smarty->assign("LINKT","Назад");
    	        		$smarty->display($theme.'/info.tpl');
    	        		break;
					  }
				  }
				  $sql = "SELECT * FROM mlb_comments WHERE comm_tid=$id ORDER BY comm_date DESC LIMIT $start, $comp";
				  $sql_sel = "SELECT * FROM mlb_texts WHERE text_id=$id and text_pid=0";
					$query = mysql_query($sql_sel);
					@$res_read = mysql_fetch_array($query);
					if(empty($res_read["text_id"])) {
						$smarty->assign('INFORMATION',TEXT_NOT_EXISTS_ELSE);
			        	$smarty->assign("LINK","?do=");
	    	        	$smarty->assign("LINKT","Назад");
			        	$smarty->display($theme.'/info.tpl');
			        	break;
					}
					$query = mysql_query($sql);
					while($res_comm = mysql_fetch_array($query)) {
						$texte = new bbcode(stripslashes(htmlspecialchars($res_comm["comm_text"])));
	            		$texte -> mnemonics = $smiles;
	            		$texte = $texte -> get_html();
						$comms_n[] = stripslashes(htmlspecialchars($res_comm["comm_name"]));
						$comms_d[] = date("d.m.y/H:i", $res_comm["comm_date"]);
						$comms_t[] = $texte;
					}
					@$smarty->assign("comms_n",$comms_n);
					@$smarty->assign("comms_d",$comms_d);
					@$smarty->assign("comms_t",$comms_t);
					$smarty->assign("id",$id);
					$smarty->assign("nav",$theme.'/user/nav.tpl');


#############
#############
#############
$count = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM mlb_comments WHERE comm_tid=$id"));
			$all = $count[0];
			if($start > $all) exit();
ob_start();
			echo (round($start/$comp,0)+1).'/'.(($all/$comp>round($all/$comp,0)) ? (round($all/$comp,0)+1) : (round($all/$comp,0))).'<br />';
			if($start>0) {
			  echo '<a href="?do=4&id='.$id.'&p='.($start-$comp).'">'.PREV.'</a>|';
			}
			if(round($all/$comp,0) > 10) {
				if(round($start/$comp,0) < 4) {
				  for($i=0;$i<=4;$i++) {
				  	if((round($start/$comp,0)+1) == ($i+1)) echo '[';
				  	echo '<a href="?do=4&id='.$id.'&p='.($i*$comp).'">'.($i+1).'</a>';
				  	if((round($start/$comp,0)+1) == ($i+1)) echo ']';
				  	if($i!=4) echo ',';
				  }
				  echo ' ... ';
				  for($i=round($all/$comp,0)-3;$i<=round($all/$comp,0)-1;$i++) {
				  	echo '<a href="?do=4&id='.$id.'&p='.($i*$comp).'">'.($i+1).'</a>';
				  	if($i!=round($all/$comp,0)-1) echo ',';
				  }
			    }
			    if(round($start/$comp,0) >= 4) {
				  for($i=0;$i<=2;$i++) {
				  	echo '<a href="?do=4&id='.$id.'&p='.($i*$comp).'">'.($i+1).'</a>';
				  	if($i!=2) echo ',';
				  }
				  echo ' ... ';
				  if($all > $start+$comp*4) {
				    echo '<a href="?do=4&id='.$id.'&p='.($start-$comp).'">'.(round($start/$comp,0)).'</a>,';
				    echo '[<a href="?do=4&id='.$id.'&p='.($start).'">'.(round($start/$comp,0)+1).'</a>],';
				    echo '<a href="?do=4&id='.$id.'&p='.($start+$comp).'">'.(round($start/$comp,0)+1+1).'</a>';
				  echo ' ... ';
			      } else {
			      	  echo '<a href="?do=4&id='.$id.'&p='.($all+1-$comp * 6).'">'.(round(($all-$comp * 5)/$comp,0)).'</a>,';
			      	  echo '<a href="?do=4&id='.$id.'&p='.($all+1-$comp * 5).'">'.(round(($all-$comp * 4)/$comp,0)).'</a>,';
			      	  if($start == $all+1-$comp * 4) echo '[';
			      	  echo '<a href="?do=4&id='.$id.'&p='.($all+1-$comp * 4).'">'.(round(($all-$comp * 3)/$comp,0)).'</a>';
			      	  if($start == $all+1-$comp * 4) echo ']';
			      	  echo ',';
				    }
				  for($i=round($all/$comp,0)-3;$i<=round($all/$comp,0)-1;$i++) {
				  	if((round($start/$comp,0)+1) == ($i+1)) echo '[';
				  	echo '<a href="?do=4&id='.$id.'&p='.($i*$comp).'">'.($i+1).'</a>';
				  	if((round($start/$comp,0)+1) == ($i+1)) echo ']';
				  	if($i!=round($all/$comp,0)-1) echo ',';
				  }
			    }
			} else {
				for($i=0;$i<=round($all/$comp,0);$i++) {
					if($i*$comp>$all) break;
					if((round($start/$comp,0)+1) == ($i+1)) echo '[';
				  	echo '<a href="?do=4&id='.$id.'&p='.($i*$comp).'">'.($i+1).'</a>';
				  	if((round($start/$comp,0)+1) == ($i+1)) echo ']';
				  	if($i!=round($all/$comp,0)) echo ',';
				  }
			  }
			  if($start+$comp<$all) {
			    echo '|<a href="?do=4&id='.$id.'&p='.($start+$comp).'">'.NEXT.'</a>';
			  }
$nav = ob_get_contents();
ob_clean();
			if($all >= $comp) {
					$smarty->assign("nav_here",$nav);
		  	}
#############
#############
#############
				$smarty->display($theme.'/user/comments.tpl');

	} break;
	case 5: {
		if($is_stol) {
			if(@!$_GET["ok"]) {
				$smarty->display($theme.'/user/stol.tpl');
			} else {
				$namestol = trim($_POST["namestol"]);
				$zakaz = trim($_POST["zakaz"]);
				if(!$namestol) {
					$smarty->assign('INFORMATION',CON_NAME_NOT_EXISTS);
			        $smarty->assign("LINK","?do=5");
	    	      	$smarty->assign("LINKT","Назад");
			      	$smarty->display($theme.'/info.tpl');
			      	break;
				}
				if(!$zakaz) {
					$smarty->assign('INFORMATION',CON_NOT_EXISTS);
			        $smarty->assign("LINK","?do=5");
	    	      	$smarty->assign("LINKT","Назад");
			      	$smarty->display($theme.'/info.tpl');
			      	break;
				}
				$namestol= mysql_real_escape_string($namestol);
				$zakaz = mysql_real_escape_string($zakaz);
				$date = time();
				  $sql = "INSERT INTO mlb_table VALUES ('', '$namestol', '$zakaz', '$date')";
				    if(mysql_query($sql)) {
				  		$smarty->assign('INFORMATION',CON_OK);
			        	$smarty->assign("LINK","?do=");
	    	      		$smarty->assign("LINKT","Назад");
			      		$smarty->display($theme.'/info.tpl');
					}
			  }
		}
	} break;
	case 6: {
		$id = intval($_GET["go"]);
		$id = mysql_real_escape_string($id);
			$sql = mysql_query("SELECT * FROM mlb_pages WHERE page_id=$id");
			$res = mysql_fetch_array($sql);
			if(empty($res["page_id"])) {
				exit();
			}
				$smarty->assign("name", stripslashes($res["page_name"]));
				$smarty->assign("date", date("d.m.y", $res["page_date"]));
				$smarty->assign("content", stripslashes($res["page_text"]));
				$smarty->display($theme.'/user/my_pages.tpl');
	} break;
	default : {

			if(@!$_GET["id"]) {
				$id = 0;
			} else {
				$id = intval($_GET["id"]);
			    $id = mysql_real_escape_string($id);
			}
			@$tpuser = intval($_GET["tpuser"]);
			if(@$tpuser) {
				switch ($tpuser) {
					case 10: $_SESSION["ctp"] = 10; break;
					case 20: $_SESSION["ctp"] = 20; break;
					case 30: $_SESSION["ctp"] = 30; break;
					case 40: $_SESSION["ctp"] = 40; break;
					case 50: $_SESSION["ctp"] = 50; break;
					default : $_SESSION["ctp"] = $topageu; break;
				}
			}
			@$_SESSION["ctp"] ? $tpuser = $_SESSION["ctp"] : $tpuser = $topageu;
			$topageu = $tpuser;
			if(@$_POST["do_my_page"]) {
					@$start = (intval($_POST["do_my_page"])-1)*$topageu;
			}
			@$start = abs($start);
			@$tsort = intval($_GET["tsort"]);
			if(@$tsort) {
				switch ($tsort) {
					case 1: $_SESSION["csort"] = "date DESC"; break;
					case 2: $_SESSION["csort"] = "name ASC"; break;
					default : $_SESSION["csort"] = "name ASC"; break;
				}
			}
			@$_SESSION["csort"] ? $tsort = $_SESSION["csort"] : $tsort =  "name ASC";
			$tsort = mysql_real_escape_string($tsort);
			  $sqlb = "SELECT * FROM mlb_cat WHERE cat_id=$id and cat_status=0";
			  $qb = mysql_query($sqlb);
			  $resb = mysql_fetch_array($qb);
			  if($id !== 0) {
			  	if(empty($resb["cat_id"])) {
			  		break;
			  	}
		  	  }
		  	  @$count = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM mlb_texts WHERE text_cid={$resb["cat_id"]} and text_pid=0"));
		  	  if($start > $count[0]+1) {
		  	  		$smarty->assign('INFORMATION',CAT_NOT_EXISTS);
					$smarty->assign("LINK","?id=".$id);
					$smarty->assign("LINKT","Назад");
					$smarty->display($theme.'/info.tpl');
					break;
			  }
			  $sqlb2 = "SELECT cat_name FROM mlb_cat WHERE cat_id={$resb["cat_pid"]} and cat_status=0";
			  $qb2 = mysql_query($sqlb2);
			  @$resb2 = mysql_fetch_array($qb2);
			  if(@$_GET["id"] > 0) {
			    $smarty->assign("back", $resb["cat_pid"]);
			    $smarty->assign("backk", "Назад");
			    $smarty->assign("backkk", "-");
			    $smarty->assign("backkkk", "<br />");
			    $smarty->assign("bac", ', '.(empty($resb2["cat_name"])?TO_MAIN_MLB:$resb2["cat_name"]));
			  }
			  $smarty->assign("is_stol", $is_stol);
			if($start == 0) {
			  $sql = "SELECT * FROM mlb_cat WHERE cat_pid=$id and cat_status!=1 ORDER BY cat_$tsort";
			  $query = mysql_query($sql);
			  function scan($c,$smarty,$ch) {
			        	$query = mysql_query("SELECT * FROM mlb_cat WHERE cat_pid=$c and cat_hid=$ch and cat_status=0");
			        	if(@!$co) {
			        	  $co = 0;
					    }
			        	GLOBAL $co;
			        	while($result_rec = mysql_fetch_array($query)) {
			        		$rt = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM mlb_texts WHERE text_cid={$result_rec["cat_id"]} and text_pid=0"));
			                scan($result_rec["cat_id"], $smarty, $ch);
			                $co = $co+$rt[0];
						}
						return $co;
			  }
			  while($res = mysql_fetch_array($query)) {
			  	if($c == 1) $c = $c+1; else $c = $c - 1;
				  $name[] = stripslashes(htmlspecialchars($res["cat_name"]));
				  $about[] = stripslashes(htmlspecialchars($res["cat_about"]));
				  $ids[] = $res["cat_id"];
			  	  $is_cat[] = 1;
			  	  $cc[] = $b[$c];
			  	  $new1 = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM mlb_texts WHERE ".time()."-text_date<$is_new and text_pid=0 and text_cid={$res["cat_id"]}"));
			  	    $new[] = $new1[0];
				    $r1 = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM mlb_cat WHERE cat_pid={$res["cat_id"]} and cat_status=0"));
				    $ccat[] = $r1[0];
				    $co=0;
				    $ctext = scan($res["cat_id"],$smarty, $res["cat_hid"]);
				    if($ctext == 0) {
				    	$r2 = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM mlb_texts WHERE text_cid={$res["cat_id"]} and text_pid=0"));
				      $cs[] = $ctext+$r2[0];
			    	} else {
			    		$cs[] = $ctext;
					  }

			  }
		    }
			$sql_t = "SELECT text_name, text_id, text_cid, text_pid, text_date, text_about FROM mlb_texts WHERE text_cid={$resb["cat_id"]} and text_pid=0 ORDER BY text_$tsort LIMIT $start, $topageu";
				$q_t = mysql_query($sql_t);
				while(@$res_t = mysql_fetch_array($q_t)) {
					if($c == 1) $c = $c+1; else $c = $c - 1;
					$cct[] = $b[$c];
					$namet[] = stripslashes(htmlspecialchars($res_t["text_name"]));
					$aboutt[] = stripslashes(htmlspecialchars($res_t["text_about"]));
				    $idst[] = $res_t["text_id"];
				    if(time() - $res_t["text_date"] < $is_new) {
				    	$newt[] = 1;
					}
					$dates[] = date("d.m.y", $res_t["text_date"]);
				    $is_cat[] = 0;
				}
			if($start == 0) {
				@$smarty->assign("col",sizeof($name));
				@$smarty->assign("name",$name);
				@$smarty->assign("cc",$cc);
				@$smarty->assign("cs",$cs);
				@$smarty->assign("new",$new);
				@$smarty->assign("date",$dates);
				@$smarty->assign("ccat",$ccat);
				@$smarty->assign("about",$about);
				@$smarty->assign("ids",$ids);
			}
			if(@sizeof($namet) > 0) {
				$smarty->assign("col",500);
			  }


			  @$count2 = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM mlb_cat WHERE cat_pid={$resb["cat_id"]} and cat_status=0"));

			if($start>$count[0]+$topage) {
				break;
			}


			@$smarty->assign("namet",$namet);
			@$smarty->assign("idst",$idst);
			@$smarty->assign("newt",$newt);
			@$smarty->assign("date",$dates);
			@$smarty->assign("cct",$cct);
			@$smarty->assign("aboutt",$aboutt);
			$smarty->assign("spl",$resb["cat_name"]);
			if(@$_GET["id"] > 0) {
				$smarty->assign("cats",$count2[0]);
				$smarty->assign("texts",$count[0]);
			}
			$smarty->display($theme.'/user/select.tpl');
#############
#############
#############
			$all = $count[0];

ob_start();
			echo (round($start/$topageu,0)+1).'/'.(($all/$topageu>round($all/$topageu,0)) ? (round($all/$topageu,0)+1) : (round($all/$topageu,0))).'<br />';
			if($start>0) {
			  echo '<a href="?id='.$id.'&p='.($start-$topageu).'">'.PREV.'</a>|';
			}
			if(round($all/$topageu,0) > 10) {
				if(round($start/$topageu,0) < 4) {
				  for($i=0;$i<=4;$i++) {
				  	if((round($start/$topageu,0)+1) == ($i+1)) echo '[';
				  	echo '<a href="?id='.$id.'&p='.($i*$topageu).'">'.($i+1).'</a>';
				  	if((round($start/$topageu,0)+1) == ($i+1)) echo ']';
				  	if($i!=4) echo ',';
				  }
				  echo ' ... ';
				  for($i=round($all/$topageu,0)-3;$i<=round($all/$topageu,0)-1;$i++) {
				  	echo '<a href="?id='.$id.'&p='.($i*$topageu).'">'.($i+1).'</a>';
				  	if($i!=round($all/$topageu,0)-1) echo ',';
				  }
			    }
			    if(round($start/$topageu,0) >= 4) {
				  for($i=0;$i<=2;$i++) {
				  	echo '<a href="?id='.$id.'&p='.($i*$topageu).'">'.($i+1).'</a>';
				  	if($i!=2) echo ',';
				  }
				  echo ' ... ';
				  if($all > $start+$topageu*4) {
				    echo '<a href="?id='.$id.'&p='.($start-$topageu).'">'.(round($start/$topageu,0)).'</a>,';
				    echo '[<a href="?id='.$id.'&p='.($start).'">'.(round($start/$topageu,0)+1).'</a>],';
				    echo '<a href="?id='.$id.'&p='.($start+$topageu).'">'.(round($start/$topageu,0)+1+1).'</a>';
				  echo ' ... ';
			      } else {
			      	  echo '<a href="?id='.$id.'&p='.($all+1-$topageu * 6).'">'.(round(($all-$topageu * 5)/$topageu,0)).'</a>,';
			      	  echo '<a href="?id='.$id.'&p='.($all+1-$topageu * 5).'">'.(round(($all-$topageu * 4)/$topageu,0)).'</a>,';
			      	  if($start == $all+1-$topageu * 4) echo '[';
			      	  echo '<a href="?id='.$id.'&p='.($all+1-$topageu * 4).'">'.(round(($all-$topageu * 3)/$topageu,0)).'</a>';
			      	  if($start == $all+1-$topageu * 4) echo ']';
			      	  echo ',';
				    }
				  for($i=round($all/$topageu,0)-3;$i<=round($all/$topageu,0)-1;$i++) {
				  	if((round($start/$topageu,0)+1) == ($i+1)) echo '[';
				  	echo '<a href="?id='.$id.'&p='.($i*$topageu).'">'.($i+1).'</a>';
				  	if((round($start/$topageu,0)+1) == ($i+1)) echo ']';
				  	if($i!=round($all/$topageu,0)-1) echo ',';
				  }
			    }
			} else {
				for($i=0;$i<=round($all/$topageu,0);$i++) {
					if(($all/$topageu<$i)) break;
					if((round($start/$topageu,0)+1) == ($i+1)) echo '[';
				  	echo '<a href="?id='.$id.'&p='.($i*$topageu).'">'.($i+1).'</a>';
				  	if((round($start/$topageu,0)+1) == ($i+1)) echo ']';
				  	if($i!=round($all/$topageu,0)) echo ',';
				  }
			  }
			  if($start+$topageu<$all) {
			    echo '|<a href="?id='.$id.'&p='.($start+$topageu).'">'.NEXT.'</a>';
			  }
$nav = ob_get_contents();
ob_clean();
			if($all >= $topageu) {
			  		$smarty->assign("nav_here",$nav);
			  		$smarty->display($theme.'/user/nav.tpl');
			}
#############
#############
#############
			$smarty->assign("id",$id);
			$smarty->assign("ctp",$tpuser);
			$smarty->assign("csort",$tsort);
			if($all >= $topageu) {
					$smarty->assign("all",$all);
			}
			$smarty->assign("is_tema", $is_tema);
			if($is_tema) {
					$open = opendir('./templates/');
						while($r = readdir($open)) {
							if(is_dir('./templates/'.$r)) {
								if($r != '.' && $r != '..') {
									$themes[] = $r;
									$names[] = $r;
									if($r == $theme) {
										$sel[] = 'selected';
									} else {
										$sel[] = '';
									  }
								}
							}
						} closedir($open);
						$smarty->assign("themes",$themes);
						$smarty->assign("names",$names);
						$smarty->assign("sel",$sel);
			}
			$smarty->display($theme.'/user/block_select.tpl');
	} break;
    }


?>