Просмотр файла mch-lib/sys/php_code/admin.php

Размер файла: 69.64Kb
<?php
##########################################
##UTF-8,lang-ru,"Monospace"(regular)[10]##
##########################################

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

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

##Создадим объект Smarty (шаблонизатор)
$smarty = new Smarty;



##Меню администрантора
$smarty->display($theme.'/admin/adm_menu.tpl');

##Получим текущего действия
@$Act = $_GET["do"];
  if($Act) {
    if(!is_numeric($Act)) { //Она должна быть числом
	  exit(NOT_NUMBER);
	}
  }
#####Прокручиваем действия на выбор текущего
  switch($Act) {
  	##Первое действие - создание категорий текстов
    case 1: {
    	if(@!$_GET["ok"]) {
			  $sql_out = "SELECT * FROM mlb_cat ORDER BY cat_hid, cat_pid ASC";
			  $out_query = mysql_query($sql_out) or die(mysql_error());
			  $select = '';
		      		while($array_query = mysql_fetch_array($out_query)) {
		      				if($array_query["cat_pid"] == 0) {
		      						$select_val[] = '';
		      						$select_names[] = LINE;
							}
							if($array_query["cat_status"] == 1) {
									$hid = HIDDEN;
							} else $hid = '';
			    			$select_val[] = $array_query["cat_id"];
			    			$select_names[] = $hid.htmlspecialchars(stripslashes($array_query["cat_name"]))
			    							  .' (id='.$array_query["cat_id"].'/pid='.$array_query["cat_pid"].')';
                 			$hid = '';
			    			if($array_query["cat_pid"] == 0) {
			    					$select_val[] = '';
		      						$select_names[] = '   ';
							}
			  		}
			  $smarty->assign("id",$select_val);
			  $smarty->assign("names",$select_names);
		      $smarty->assign("DATE_N",date("d.m.y/H:i"));
    	      $smarty->display($theme.'/admin/adm_create_cat.tpl');
	    } else {
	    	$name = trim($_POST["cat_name"]);
	    		if(empty($name)) {
	    				$smarty->assign("INFORMATION",NAME_CAT_NOT.mysql_error());
	    	    		$smarty->assign("LINK","?do=1");
	    	    		$smarty->assign("LINKT","Назад");
    	        		$smarty->display($theme.'/info.tpl');
    	        		exit();
				}
	    			$about = trim($_POST["about"]);
	    			$date = trim(time());
	    		if(trim($_POST["n_cat"])) {
	    				$cat_pid = intval($_POST["n_cat"]);
	    				$sel_hid = mysql_fetch_array(mysql_query("SELECT cat_hid FROM mlb_cat WHERE cat_id='$cat_pid'"));
	    				$cat_hid = $sel_hid[0];
				} else {
					$cat_pid = 0;
					$cat_hid = 0;
			  	}
	    	  			$name = mysql_real_escape_string($name);
	    	 			$about = mysql_real_escape_string($about);
	    	    		$sql_create_cat = "INSERT INTO mlb_cat VALUES ('', '$name', '$about', '$date', '$cat_pid', '$cat_hid', 0)";
	    	    	if(mysql_query($sql_create_cat)) {
	    	    			if($cat_pid == 0) {
	    	    	  				$id = mysql_insert_id();
	    	    	  				mysql_query("UPDATE mlb_cat SET cat_hid='$id' WHERE cat_id='$id'");
	    	    			}
	    	    				$smarty->assign("INFORMATION",CAT_SUCSSESS_CREATE);
	    	    				$smarty->assign("LINK","?main");
	    	    				$smarty->assign("LINKT","Назад");
    	            			$smarty->display($theme.'/info.tpl');
	    	    	} else {
	    	    		$smarty->assign("INFORMATION",CAT_NOT_SUCSSESS_CREATE.mysql_error());
	    	    		$smarty->assign("LINK","?do=1");
	    	    		$smarty->assign("LINKT","Назад");
    	            	$smarty->display($theme.'/info.tpl');
				  	}
		}
	} break;
	##Второе действие - редактирование категорий
	case 2: {
		##Выбор категорий и текстов "списком" (визуальной навигацией)
		if(@$_GET["fie"]) {
				if(@!$_GET["id"]) {
						$id = 0;
				} else {
						$id = intval($_GET["id"]);
			    		$id = mysql_real_escape_string($id);
				}
			  		$sqlb = "SELECT * FROM mlb_cat WHERE cat_id=$id";
			 	 	$qb = mysql_query($sqlb);
			  			$resb = mysql_fetch_array($qb);
			    		$smarty->assign("back",$resb["cat_pid"]);
					if($start == 0) {
			  				$sql = "SELECT * FROM mlb_cat WHERE cat_pid=$id ORDER BY cat_date DESC";
			  				$query = mysql_query($sql);
			  			while($res = mysql_fetch_array($query)) {
				  				$name[] = stripslashes(htmlspecialchars($res["cat_name"]));
				  				$ids[] = $res["cat_id"];
			  	  				$is_cat[] = 1;
			  			}
		    		}
						$sql_t = "SELECT text_name, text_id, text_cid, text_pid FROM mlb_texts
						WHERE text_cid={$resb["cat_id"]} and text_pid=0 ORDER BY text_name DESC LIMIT $start, $topage";
						$q_t = mysql_query($sql_t);
					while(@$res_t = mysql_fetch_array($q_t)) {
							$namet[] = stripslashes(htmlspecialchars($res_t["text_name"]));
				    		$idst[] = $res_t["text_id"];
				    		$is_cat[] = 0;
					}
						if($start == 0) {
								@$smarty->assign("name",$name);
								@$smarty->assign("ids",$ids);
						}
							@$smarty->assign("namet",$namet);
							@$smarty->assign("idst",$idst);
							$smarty->display($theme.'/admin/adm_edit_cat_select.tpl');
#############
#############
#############
			@$count = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM mlb_texts
					 WHERE text_cid={$resb["cat_id"]} and text_pid=0"));
			$all = $count[0];
					ob_start();
					echo (round($start/$topage,0)+1).'/'
					.((round($all/$topage,0)>10) ? (round($all/$topage,0)) : (round($all/$topage,0)+1)).'<br />';
						if($start>0) {
			  					echo '<a href="?do=2&fie=1&id='.$id.'&p='.($start-$topage).'">'.PREV.'</a>|';
						}
						if(round($all/$topage,0) > 10) {
								if(round($start/$topage,0) < 4) {
				  						for($i=0;$i<=4;$i++) {
				  								if((round($start/$topage,0)+1) == ($i+1)) echo '[';
				  									echo '<a href="?do=2&fie=1&id='.$id.'&p='.($i*$topage).'">'.($i+1).'</a>';
				  								if((round($start/$topage,0)+1) == ($i+1)) echo ']';
				  								if($i!=4) echo ',';
				  						}
				  								echo ' ... ';
				  						for($i=round($all/$topage,0)-3;$i<=round($all/$topage,0)-1;$i++) {
				  								echo '<a href="?do=2&fie=1&id='.$id.'&p='.($i*$topage).'">'.($i+1).'</a>';
				  								if($i!=round($all/$topage,0)-1) echo ',';
				  						}
			    				}
			    				if(round($start/$topage,0) >= 4) {
				  						for($i=0;$i<=2;$i++) {
				  								echo '<a href="?do=2&fie=1&id='.$id.'&p='.($i*$topage).'">'.($i+1).'</a>';
				  								if($i!=2) echo ',';
				  						}
				  								echo ' ... ';
				  						if($all > $start+$topage*4) {
				    							echo '<a href="?do=2&fie=1&id='.$id.'&p='.($start-$topage).'">'
				    							.(round($start/$topage,0)).'</a>,';
				    							echo '[<a href="?do=2&fie=1&id='.$id.'&p='.($start).'">'
				    							.(round($start/$topage,0)+1).'</a>],';
				    							echo '<a href="?do=2&fie=1&id='.$id.'&p='.($start+$topage).'">'
				    							.(round($start/$topage,0)+1+1).'</a>';
				  										echo ' ... ';
			      						} else {
			      	  							echo '<a href="?do=2&fie=1&id='.$id.'&p='.($all+1-$topage * 6).'">'
			      	  							.(round(($all-$topage * 5)/$topage,0)).'</a>,';
			      	  							echo '<a href="?do=2&fie=1&id='.$id.'&p='.($all+1-$topage * 5).'">'
			      	  							.(round(($all-$topage * 4)/$topage,0)).'</a>,';
			      	  									if($start == $all+1-$topage * 4) echo '[';
			      	  											echo '<a href="?do=2&fie=1&id='.$id.'&p='.($all+1-$topage * 4).'">'
			      	  											.(round(($all-$topage * 3)/$topage,0)).'</a>';
			      	  									if($start == $all+1-$topage * 4) echo ']';
			      	  											echo ',';
				    					}
				  								for($i=round($all/$topage,0)-3;$i<=round($all/$topage,0)-1;$i++) {
				  										if((round($start/$topage,0)+1) == ($i+1)) echo '[';
				  												echo '<a href="?do=2&fie=1&id='.$id.'&p='.($i*$topage).'">'
				  												.($i+1).'</a>';
				  												if((round($start/$topage,0)+1) == ($i+1)) echo ']';
				  	if($i!=round($all/$topage,0)-1) echo ',';
				  }
			    }
			} else {
				for($i=0;$i<=round($all/$topage,0);$i++) {
					if((round($start/$topage,0)+1) == ($i+1)) echo '[';
				  	echo '<a href="?do=2&fie=1&id='.$id.'&p='.($i*$topage).'">'.($i+1).'</a>';
				  	if((round($start/$topage,0)+1) == ($i+1)) echo ']';
				  	if($i!=round($all/$topage,0)) echo ',';
				  }
			  }
			  if($start+$topage<$all) {
			    echo '|<a href="?do=2&fie=1&id='.$id.'&p='.($start+$topage).'">'.NEXT.'</a>';
			  }
$nav = ob_get_contents();
ob_clean();
			  $smarty->assign("nav_here",$nav);
			  $smarty->display($theme.'/admin/adm_nav.tpl');
#############
#############
#############
		break;
		}
		##Показать все нижеподчиненные категории
		if(@$_GET["vpc"]) {
			$id = intval($_GET["vpc"]);
			$id = mysql_real_escape_string($id);
			$sql_exte = "SELECT * FROM mlb_cat WHERE cat_id=$id";
			$witch = mysql_fetch_array(mysql_query($sql_exte));
			$tr = 1;
			$c = $witch["cat_id"];
			        function scan($c,$smarty) {
			        		$query = mysql_query("SELECT * FROM mlb_cat WHERE cat_pid=$c");
			        		if(@!$co) {
			        	  			$co = 0;
			        	  			GLOBAL $co;
					    	}
			        		GLOBAL $co;
			        		while($result_rec = mysql_fetch_array($query)) {
			        				$smarty->assign("struct",$result_rec["cat_name"]);
			                		@$smarty->display($theme.'/admin/adm_struct.tpl');
			                		scan($result_rec["cat_id"], $smarty);
			                		$co++;
							}
				    }

					scan($c,$smarty);
					if(!$co) {
							$smarty->assign("INFORMATION",CAT_NOT_EXISTS);
							$smarty->display($theme.'/info.tpl');
					}
		}
		##Показать все нижеподчиненные тексты
		if(@$_GET["vpt"]) {
			$id = intval($_GET["vpt"]);
			$id = mysql_real_escape_string($id);
			$sql_t = "SELECT text_name FROM mlb_texts WHERE text_cid=$id and text_pid=0 ORDER BY text_name ASC";
			$query_t = mysql_query($sql_t);
				while($res_t = mysql_fetch_array($query_t)) {
						$smarty->assign("struct",$res_t["text_name"]);
						$smarty->display($theme.'/admin/adm_struct.tpl');
				}
		}
		##Переместить категорию
		if(@$_GET["move"]) {
			$id = intval($_GET["move"]);
			$id = mysql_real_escape_string($id);
			$idn = intval($_POST["n_cat"]);
			$idn = mysql_real_escape_string($idn);
			$sql_exte = "SELECT * FROM mlb_cat WHERE cat_id=$idn";
			$witch = mysql_fetch_array(mysql_query($sql_exte));
			$c = $witch["cat_id"];
			$c2 = $witch["cat_hid"];
			mysql_query("UPDATE mlb_cat SET cat_pid=$idn WHERE cat_id=$id");
			mysql_query("UPDATE mlb_cat SET cat_hid=$c2 WHERE cat_id=$id");

			        function scan_to_move($c,$smarty,$c2) {
							$query = mysql_query("SELECT * FROM mlb_cat WHERE cat_pid=$c");
							while(@$result_rec = mysql_fetch_array($query)) {
									$c = $result_rec["cat_id"];
									mysql_query("UPDATE mlb_cat SET cat_hid=$c2 WHERE cat_id=$c");
									scan_to_move($result_rec["cat_id"], $smarty,$c2);
							}
							return 1;
				    }

			if(scan_to_move($c,$smarty,$c2)) {
					$smarty->assign("INFORMATION",CAT_IS_MOVE);
					$smarty->assign("LINK","?do=2");
					$smarty->assign("LINKT","Назад");
					$smarty->display($theme.'/info.tpl');
			}
		}
		##Удалить только текущую категорию
		if(@$_GET["del_cur"]) {
			$id = intval($_GET["del_cur"]);
			$id = mysql_real_escape_string($id);
			$sql_del = "DELETE FROM mlb_cat WHERE cat_id=$id";
			if(mysql_query($sql_del)) {
					$smarty->assign("INFORMATION",CAT_IS_REMOVE);
					$smarty->assign("LINK","?do=2");
					$smarty->assign("LINKT","Назад");
					$smarty->display($theme.'/info.tpl');
			}
		}
		##Удалить текущую категорию и все вложенные в нее категории
		if(@$_GET["del_full"]) {
			$id = intval($_GET["del_full"]);
			$id = mysql_real_escape_string($id);
			$sql_exte = "SELECT * FROM mlb_cat WHERE cat_id=$id";
			$witch = mysql_fetch_array(mysql_query($sql_exte));
			$sql_del = "DELETE FROM mlb_cat WHERE cat_id=$id";
			mysql_query($sql_del);
			$c = $witch["cat_id"];

			        function scan_to_del($c,$smarty,$c2) {
							$query = mysql_query("SELECT * FROM mlb_cat WHERE cat_pid=$c");
							while($result_rec = mysql_fetch_array($query)) {
									$c = $result_rec["cat_id"];
									mysql_query("DELETE FROM mlb_cat WHERE cat_id=$c");
									scan_to_del($result_rec["cat_id"], $smarty,$c2);
							}
							return 1;
				    }

			if(scan_to_del($c,$smarty,'')) {
					$smarty->assign("INFORMATION",CAT_TREE_IS_REMOVE);
					$smarty->assign("LINK","?do=2");
					$smarty->assign("LINKT","Назад");
					$smarty->display($theme.'/info.tpl');
			}
		}
		##Обработка подтверждения изменения категории (изменение категории - действия)
		if(@$_GET["editdo"]) {
			$id = intval($_GET["editdo"]);
			$id = mysql_real_escape_string($id);
			$name = trim($_POST["cat_name"]);
	    	if(empty($name)) {
					$smarty->assign("INFORMATION",NAME_CAT_NOT);
					$smarty->assign("LINK","?do=2");
					$smarty->assign("LINKT","Назад");
					$smarty->display($theme.'/info.tpl');
					exit();
			}
	    	$about = trim($_POST["about"]);
	    	$name = mysql_real_escape_string($name);
	    	$about = mysql_real_escape_string($about);
	    	$_POST["hid"] ? ($hid = intval($_POST["hid"])) : ($hid = FALSE);
	    	  if(mysql_query("UPDATE mlb_cat SET cat_name='$name',cat_about='$about', cat_status='$hid' WHERE cat_id=$id")) {
					$smarty->assign("INFORMATION",CAT_IS_CHANGE);
					$smarty->assign("LINK","?do=2");
					$smarty->assign("LINKT","Назад");
					$smarty->display($theme.'/info.tpl');
			  }
		}
		##Редактировать категорию Вывод параметров для редактирования, заполнение данных, формы
		if(@$_GET["edit"]) {
			$id = trim($_POST["n_cat"]);
			if(empty($id)) {
					$id = trim($_GET["edit"]);
			}
			$id = intval($id);
			$id = mysql_real_escape_string($id);
			$sql_edit = "SELECT * FROM mlb_cat WHERE cat_id=$id";
			$query_edit = mysql_query($sql_edit);
			$result_edit = mysql_fetch_array($query_edit);
			if(empty($result_edit["cat_name"])) {
					$smarty->assign("INFORMATION",CAT_ONE_NOT_EXISTS);
					$smarty->assign("LINK","?do=2");
					$smarty->assign("LINKT","Назад");
					$smarty->display($theme.'/info.tpl');
					exit();
			}
				$smarty->assign("date",date("d.m.y/H:i",$result_edit["cat_date"]));
				$smarty->assign("id",$result_edit["cat_id"]);
				$smarty->assign("name",htmlspecialchars(stripslashes($result_edit["cat_name"])));
				$smarty->assign("about",htmlspecialchars(stripslashes($result_edit["cat_about"])));
				$smarty->assign("go",$result_edit["cat_pid"]);
				$smarty->assign("chec",$result_edit["cat_status"]);

			  $sql_out = "SELECT * FROM mlb_cat ORDER BY cat_hid, cat_pid ASC";
			  $out_query = mysql_query($sql_out) or die(mysql_error());
			  $select = '';
		      while($array_query = mysql_fetch_array($out_query)) {
					if($array_query["cat_pid"] == 0) {
							$select_val1[] = '';
							$select_names1[] = LINE;
					}
					if($array_query["cat_id"] == $id) {
							$thisis = IN_THIS;
					} else $thisis = '';
					if($array_query["cat_status"] == 1) {
							$hid = HIDDEN;
					} else $hid = '';
						$select_val1[] = $array_query["cat_id"];
						$select_names1[] = $hid.$thisis.htmlspecialchars(stripslashes($array_query["cat_name"])).' (id='.$array_query["cat_id"].'/pid='.$array_query["cat_pid"].')';
						$hid = '';
					if($array_query["cat_pid"] == 0) {
							$select_val1[] = '';
							$select_names1[] = '   ';
					}
			  }
			  $smarty->assign("ids",$select_val1);
			  $smarty->assign("namess",$select_names1);

    	    		$smarty->display($theme.'/admin/adm_edit_cat_edit.tpl');
		}
		##Показ "селектора" категорий
			  $sql_out = "SELECT * FROM mlb_cat ORDER BY cat_hid, cat_pid ASC";
			  $out_query = mysql_query($sql_out) or die(mysql_error());
			  $select = '';
		      while($array_query = mysql_fetch_array($out_query)) {
					if($array_query["cat_pid"] == 0) {
							$select_val[] = '';
							$select_names[] = LINE;
					}
					if($array_query["cat_status"] == 1) {
							$hid = HIDDEN;
					} else $hid = '';
						$select_val[] = $array_query["cat_id"];
						$select_names[] = $hid.htmlspecialchars(stripslashes($array_query["cat_name"])).' (id='.$array_query["cat_id"].'/pid='.$array_query["cat_pid"].')';
						$hid = '';
					if($array_query["cat_pid"] == 0) {
							$select_val[] = '';
							$select_names[] = '   ';
					}
			  }
				  $smarty->assign("id2",$select_val);
				  $smarty->assign("names2",$select_names);
				  $smarty->display($theme.'/admin/adm_edit_cat.tpl');

	} break;
	##Действие третье, "Создать запись" Создание текстов
	case 3: {
		##Вывод формы и параметров для создание записи (Заполнение)
		if(@!$_GET["ok"]) {
			  $sql_out = "SELECT * FROM mlb_cat ORDER BY cat_hid, cat_pid ASC";
			  $out_query = mysql_query($sql_out) or die(mysql_error());
			  $select = '';
		      while($array_query = mysql_fetch_array($out_query)) {
					if($array_query["cat_pid"] == 0) {
							$select_val[] = '';
							$select_names[] = LINE;
					}
					if($array_query["cat_status"] == 1) {
							$hid = HIDDEN;
					} else $hid = '';
						$select_val[] = $array_query["cat_id"];
						$select_names[] = $hid.htmlspecialchars(stripslashes($array_query["cat_name"])).' (id='.$array_query["cat_id"].'/pid='.$array_query["cat_pid"].')';
						 $hid = '';
					if($array_query["cat_pid"] == 0) {
							$select_val[] = '';
							$select_names[] = '   ';
					}
			  }
			  for($i=1;$i<=$cfd;$i++) {
		        		@$dl .= '<br /> <input type="file" name="file'.$i.'" class="q">'."\n";
			  }

			  $smarty->assign("dl",$dl);
			  $smarty->assign("fext",$fext);
			  $smarty->assign("mbf",$mfb);
			  $smarty->assign("id",$select_val);
			  $smarty->assign("names",$select_names);
		      $smarty->assign("DATE_N",date("d.m.y/H:i"));
    	      $smarty->display($theme.'/admin/adm_create_text.tpl');
		} else {
			##Проверка введенных данных и действия по созданию записи
			if(@!$_POST["n_cat"]) {
					$smarty->assign("INFORMATION",CAT_ONE_NOT_EXISTS);
					$smarty->assign("LINK","?do=3");
					$smarty->assign("LINKT","Назад");
					$smarty->display($theme.'/info.tpl');
					exit();
			}
			$text_cid = intval($_POST["n_cat"]);
			$name = trim($_POST["text_name"]);
			##Проверка, если был загружен текст не из формы набора, а из файла
			##Тогда будем брать текст из загруженного файла, а после прочтения файл удалим
			##Иначе будем брать текст, напечатанный в форме
			if(@$_FILES["file_text"]["size"]) {
              	$ext = strrchr($_FILES["file_text"]["name"], '.');
              	if(!stristr('.txt', $ext)) {
						$smarty->assign("INFORMATION",EXT_FILE_NOT);
						$smarty->assign("LINK","?do=3");
						$smarty->assign("LINKT","Назад");
						$smarty->display($theme.'/info.tpl');
						exit();
		        }
		        if(is_file($dir_f.$_FILES["file_text"]["name"])) {
						$smarty->assign("INFORMATION",FILE_NOT_LOADED);
						$smarty->assign("LINK","?do=3");
						$smarty->assign("LINKT","Назад");
						$smarty->display($theme.'/info.tpl');
						break;
		        }
		        @chmod($dir_f, 0777);
		        if(move_uploaded_file($_FILES["file_text"]["tmp_name"], $dir_f.$_FILES["file_text"]["name"].'.tmp')) {
						  @chmod($dir_f.$_FILES["file_text"]["name"].'.tmp', 0777);
						  $text = file_get_contents($dir_f.$_FILES["file_text"]["name"].'.tmp');
						  unlink($dir_f.$_FILES["file_text"]["name"].'.tmp');
                } else {
						$smarty->assign("INFORMATION",FILE_NOT_LOADED);
						$smarty->assign("LINK","");
						$smarty->assign("LINKT","");
						$smarty->display($theme.'/info.tpl');
				  }
			} else {
					$text = trim($_POST["text"]);
			}
			$about = trim($_POST["about"]);
			$author = trim($_POST["text_author"]);
			$original = trim($_POST["text_original"]);
			$date = time();
			$tc = trim($_POST["tc"]);
			  if(empty($name)) {
					$smarty->assign("INFORMATION",NAME_NOT_EXISTS);
					$smarty->assign("LINK","?do=3");
					$smarty->assign("LINKT","Назад");
					$smarty->display($theme.'/info.tpl');
					exit();
			  }
			  if(empty($text)) {
					$smarty->assign("INFORMATION",TEXT_NOT_EXISTS);
					$smarty->assign("LINK","?do=3");
					$smarty->assign("LINKT","Назад");
					$smarty->display($theme.'/info.tpl');
					exit();
			  }
			      $name = mysql_real_escape_string($name);
			      $text = mysql_real_escape_string($text);
			      $about = mysql_real_escape_string($about);
			      $author =mysql_real_escape_string($author);
			      $original = mysql_real_escape_string($original);
			      $text_pid = 0;
			      $text_hid = 0;
			      $text_cid = mysql_real_escape_string($text_cid);

		  ##Посмотрим, были ли загруженны дополнительные файлы,
		  ## которые следует сопоставлять с данной записью
		  for($i=1;$i<=$cfd;$i++) {
            if($_FILES["file$i"]["size"]) {
			  if($_FILES["file$i"]["size"] > 1024*$mfb*1024) {
					$smarty->assign("INFORMATION",MAX_FILE_1.$mfb.MAX_FILE_2);
					$smarty->assign("LINK","?do=3");
					$smarty->assign("LINKT","Назад");
					$smarty->display($theme.'/info.tpl');
					$ftg = FALSE;
              } else {
              	  	$ftg == TRUE;
			    }
              if($ftg !== FALSE) {
              	$ext = strrchr($_FILES["file$i"]["name"], '.');
              	if(!stristr($fext, $ext)) {
						$smarty->assign("INFORMATION",EXT_FILE_NOT);
						$smarty->assign("LINK","?do=3");
						$smarty->assign("LINKT","Назад");
						$smarty->display($theme.'/info.tpl');
						exit();
		        }
		        $endp = $end.$ext;
		        if(is_file($dir_f.$_FILES["file$i"]["name"].$endp)) {
		          		$endth = $end.(str_replace(' ', '', microtime())*10000000000000).'_'.$ext;
		        } else {
		        		$endth = $end.$ext;
				  }
		        @chmod($dir_f, 0777);
		        if(move_uploaded_file($_FILES["file$i"]["tmp_name"], $dir_f.$_FILES["file$i"]["name"].$endth)) {
					  @chmod($dir_f.$_FILES["file$i"]["name"].$endth, 0777);
					  $files[] = mysql_real_escape_string($_FILES["file$i"]["name"].$endth);
                } else {
						$smarty->assign("INFORMATION",FILE_NOT_LOADED);
						$smarty->assign("LINK","");
						$smarty->assign("LINKT","");
						$smarty->display($theme.'/info.tpl');
				  }
			  }
            }
          }

			        $sql_create_text = "INSERT INTO mlb_texts VALUES (
			          '', '$name', '$text', '$about', '$author', '$original', '$date', $text_cid, $text_pid, $text_hid
			        )";
			        if(mysql_query($sql_create_text)) {
							$id = mysql_insert_id();
							$sqlup = "UPDATE mlb_texts SET text_hid=$id WHERE text_id=$id";
							mysql_query($sqlup) or die(mysql_error());
							for($i=0;$i<=@sizeof($files)-1;$i++) {
									mysql_query("INSERT INTO mlb_files VALUES('', '{$files[$i]}', $date, $id)");
							}
							  if($tc == 1) {
									$smarty->assign('INFORMATION',TEXT_IS_OK_1.$name.TEXT_IS_OK_1.$id);
									$smarty->assign("LINK","?do=4&pod=$id");
									$smarty->assign("LINKT",GO_TO_DO_LAPS);
									$smarty->display($theme.'/info.tpl');
							  } else {
										  $smarty->assign('INFORMATION',TEXT_ONE_IS_OK);
										  $smarty->assign("LINK","?do=3");
										  $smarty->assign("LINKT","Назад");
										  $smarty->display($theme.'/info.tpl');
								}
					} else {
						      $smarty->assign('INFORMATION',TEXT_ONE_IS_NOT.mysql_error());
			        	  	  $smarty->assign("LINK","?do=3");
	    	    			  $smarty->assign("LINKT","Назад");
			        	  	  $smarty->display($theme.'/info.tpl');
					  }
		}
	} break;
	##Действие четвертое, редактирование записей
	case 4: {


		##Редактирование подтекстов (глав в тематике контекста)
		##Главы - дочерние записи для записи родителя
		if(@$_GET["pod"]) {
			if(@$_GET["poedit"]) {
				@$id = intval($_POST["n_text"]);
				$id = mysql_real_escape_string($id);
				$sql = "SELECT * FROM mlb_texts WHERE text_id=$id and text_pid!=0";
				$query = mysql_query($sql);
				$result_array = mysql_fetch_array($query);

				if(empty($result_array["text_name"])) {
						  $smarty->assign('INFORMATION',TEXT_ID_NOT_EXIST_1.$id.TEXT_ID_NOT_EXIST_2);
						  $smarty->assign("LINK","?do=4");
						  $smarty->assign("LINKT","Назад");
						  $smarty->display($theme.'/info.tpl');
						  exit();
				}

					$smarty->assign("name", stripslashes(htmlspecialchars($result_array["text_name"])));
					$smarty->assign("text", stripslashes(htmlspecialchars($result_array["text_text"])));
					$smarty->assign("about", stripslashes(htmlspecialchars($result_array["text_about"])));
					$smarty->assign("original", stripslashes(htmlspecialchars($result_array["text_original"])));
					$smarty->assign("author", stripslashes(htmlspecialchars($result_array["text_author"])));
					$smarty->assign("id",$id);
					$smarty->assign("date",date("d.m.y/H:i",$result_array["text_date"]));
					$smarty->display($theme.'/admin/adm_edit_ptext_edit.tpl');
			    break;
			}
			if(@$_GET["pdel"]) {
				$id = intval($_GET["pdel"]);
				$id = mysql_real_escape_string($id);
				$sql_del = "DELETE FROM mlb_texts WHERE text_id=$id and text_pid!=0";
				if(mysql_query($sql_del)) {
						$smarty->assign('INFORMATION',LAP_IS_REMOVED);
						$smarty->assign("LINK","?do=4");
						$smarty->assign("LINKT","Назад");
						$smarty->display($theme.'/info.tpl');
				} else {
						$smarty->assign('INFORMATION',LAP_IS_NOT_REMOVED.mysql_error());
						$smarty->assign("LINK","?do=4");
						$smarty->assign("LINKT","Назад");
						$smarty->display($theme.'/info.tpl');
				  }
				  break;
			}
			if(@$_GET["ok"]) {
					$id = intval($_GET["pod"]);
					$id = mysql_real_escape_string($id);
					$sql = "SELECT text_name, text_date, text_hid, text_pid, text_cid, text_id FROM mlb_texts WHERE text_id=$id";
					$query_my = mysql_query($sql);
					$result_w = mysql_fetch_array($query_my);
					if($result_w["text_pid"] != 0) {
							  $smarty->assign('INFORMATION',THIS_TEXT_IS_LAP);
							  $smarty->assign("LINK","?do=4");
							  $smarty->assign("LINKT","Назад");
							  $smarty->display($theme.'/info.tpl');
							  exit();
				   }
					 $pname = trim($_POST["pname"]);
					 $ptext = trim($_POST["ptext"]);
					 $pname =mysql_real_escape_string($pname);
					 $ptext = mysql_real_escape_string($ptext);
					 $pdate = $result_w["text_date"];
					 $ptext_pid = $result_w["text_id"];
					 $ptext_cid = $result_w["text_cid"];
					 $ptext_hid = $result_w["text_hid"];
					 $sql_create_ptext = "INSERT INTO mlb_texts VALUES (
						  '', '$pname', '$ptext', '', '', '', '$pdate', '$ptext_cid', '$ptext_pid', '$ptext_hid'
						)";
						if(mysql_query($sql_create_ptext)) {
								$smarty->assign('INFORMATION',LAP_IS_CREATED);
								$smarty->assign("LINK","");
								$smarty->assign("LINKT","");
								$smarty->display($theme.'/info.tpl');
						} else {
									  $smarty->assign('INFORMATION',LAP_IS_NOT_CREATED.mysql_error());
									  $smarty->assign("LINK","?do=4");
									  $smarty->assign("LINKT","Назад");
									  $smarty->display($theme.'/info.tpl');
						  }
			}
			$id = intval($_GET["pod"]);
			$id = mysql_real_escape_string($id);
			  $sql = "SELECT text_name, text_date, text_hid, text_pid FROM mlb_texts WHERE text_id=$id";
			  $query_my = mysql_query($sql);
			  $result_w = mysql_fetch_array($query_my);
			  if($result_w["text_pid"] != 0) {
						$smarty->assign('INFORMATION',THIS_TEXT_IS_LAP);
						$smarty->assign("LINK","?do=4");
						$smarty->assign("LINKT","Назад");
						$smarty->display($theme.'/info.tpl');
						exit();
			  }
			  $sql_pod = "SELECT text_name, text_id FROM mlb_texts WHERE text_pid=$id ORDER BY text_name";
			  $query_pod = mysql_query($sql_pod);
			  $co = 0;
				  while($result_p = mysql_fetch_array($query_pod)) {
						$ids[] = $result_p["text_id"];
						$pcts[] = stripslashes(htmlspecialchars($result_p["text_name"]));
						$co++;
				  }

			    @$smarty->assign("names", $pcts);
			    @$smarty->assign("ids", $ids);
			    if($co == 0) {
			  	  		$smarty->assign("names","Не содержит");
			    }
					$smarty->assign("id",$id);
					$smarty->assign("name",stripslashes(htmlspecialchars($result_w["text_name"])));
					$smarty->assign("date",date("d.m.y/H:i",$result_w["text_date"]));
					$smarty->display($theme.'/admin/adm_inc_text.tpl');
		}
		##Редактирование записи, вывод и заполнение формы, ввод параметров
		if(@$_GET["edit"]) {
			@$id = trim($_POST["n_text"]);
			if(empty($id)) {
					$id = trim($_GET["edit"]);
			}
			$id = intval($id);
			$id = mysql_real_escape_string($id);
			  $sql_get = "SELECT * FROM mlb_texts WHERE text_id=$id and text_pid=0";
			  $query_this = mysql_query($sql_get);
			  $result_array = @mysql_fetch_array($query_this);
			    if(empty($result_array["text_name"])) {
						  $smarty->assign('INFORMATION',TEXT_ID_NOT_EXIST_1.$id.TEXT_ID_NOT_EXIST_2);
						  $smarty->assign("LINK","?do=4");
						  $smarty->assign("LINKT","Назад");
						  $smarty->display($theme.'/info.tpl');
						  exit();
				}

				$sql_out = "SELECT * FROM mlb_cat ORDER BY cat_hid, cat_pid ASC";
			    $out_query = mysql_query($sql_out) or die(mysql_error());
			    $select = '';

		        while($array_query = mysql_fetch_array($out_query)) {
					  if($array_query["cat_pid"] == 0) {
							  $select_val1[] = '';
							  $select_names1[] = '-------';
					  }
					  if($array_query["cat_id"] == $result_array["text_cid"]) {
							  $thisis = '=>';
					  } else $thisis = '';
					  if($array_query["cat_status"] == 1) {
						 	 $hid = '(Скр.) ';
					  } else $hid = '';
						  $select_val1[] = $array_query["cat_id"];
						  $select_names1[] = $hid.$thisis.htmlspecialchars(stripslashes($array_query["cat_name"])).' (id='.$array_query["cat_id"].'/pid='.$array_query["cat_pid"].')';
						  $hid = '';
					  if($array_query["cat_pid"] == 0) {
							  $select_val1[] = '';
							  $select_names1[] = '   ';
					  }
			    }
					$smarty->assign("idss",$select_val1);
					$smarty->assign("namess",$select_names1);

					$smarty->assign("name", stripslashes(htmlspecialchars($result_array["text_name"])));
					$smarty->assign("text", stripslashes(htmlspecialchars($result_array["text_text"])));
					$smarty->assign("about", stripslashes(htmlspecialchars($result_array["text_about"])));
					$smarty->assign("original", stripslashes(htmlspecialchars($result_array["text_original"])));
					$smarty->assign("author", stripslashes(htmlspecialchars($result_array["text_author"])));
					$smarty->assign("id",$id);
					$smarty->assign("date",date("d.m.y/H:i",$result_array["text_date"]));
					$smarty->display($theme.'/admin/adm_edit_text_edit.tpl');
		}
		##Редактирование записи.
		##Проверка введенных данных, обновление записи в базе данных
		if(@$_GET["edok"]) {
				$id = trim($_GET["edok"]);
				$id = intval($id);
				$id = mysql_real_escape_string($id);
				  $text_name = trim($_POST["text_name"]);
				  $text_text = trim($_POST["text_text"]);
				  $_POST["text_about"] ? ($text_about = trim($_POST["text_about"])) : ($text_about = '');
				  $_POST["text_author"] ? ($text_author = trim($_POST["text_author"])) : ($text_author = '');
				  $_POST["text_original"] ? ($text_original = trim($_POST["text_original"])) : ($text_original = '');
				  $text_name = mysql_real_escape_string($text_name);
				  $text_text = mysql_real_escape_string($text_text);
				  $text_about = mysql_real_escape_string($text_about);
				  $text_author = mysql_real_escape_string($text_author);
				  $text_original = mysql_real_escape_string($text_original);
					$sql = "UPDATE mlb_texts SET text_name='$text_name', text_text='$text_text', text_about='$text_about', text_author='$text_author', text_original='$text_original' WHERE text_id=$id";
					if(mysql_query($sql)) {
						  $smarty->assign('INFORMATION',TEXT_IS_RELOADED);
						  $smarty->assign("LINK","?do=4");
						  $smarty->assign("LINKT","Назад");
						  $smarty->display($theme.'/info.tpl');
					} else {
							$smarty->assign('INFORMATION',TEXT_IS_NOT_RELOADED.mysql_error());
							$smarty->assign("LINK","?do=4");
							$smarty->assign("LINKT","Назад");
							$smarty->display($theme.'/info.tpl');
					  }
		}
		##Удаление записи
		if(@$_GET["del"]) {
			$id = trim($_GET["del"]);
			$id = intval($id);
			$id = mysql_real_escape_string($id);
			  $sql_del = "DELETE FROM mlb_texts WHERE text_id=$id or text_pid=$id";
			  $qd = mysql_query("SELECT file_address FROM mlb_files WHERE file_tid=$id");
			  while($res_s = mysql_fetch_array($qd)) {
			  		unlink($dir_f.$res_s["file_address"]);
			  }
				  $sql_del2 = "DELETE FROM mlb_files WHERE file_tid=$id";
				  $sql_del3 = "DELETE FROM mlb_comments WHERE comm_tid=$id";
				  if(mysql_query($sql_del)) {
						  mysql_query($sql_del2);
						  mysql_query($sql_del3);
						  $smarty->assign('INFORMATION',TEXT_IS_REMOVED);
						  $smarty->assign("LINK","?do=4");
						  $smarty->assign("LINKT","Назад");
						  $smarty->display($theme.'/info.tpl');
				  } else {
							$smarty->assign('INFORMATION',TEXT_IS_NOT_REMOVED.mysql_error());
							$smarty->assign("LINK","?do=4&edit=".$id);
							$smarty->assign("LINKT","Назад");
							$smarty->display($theme.'/info.tpl');
					}
		}
		##Перемещение записи
		if(@$_GET["move"]) {
			$id = trim($_GET["move"]);
			$id = intval($id);
			$id = mysql_real_escape_string($id);
			$cid =trim($_POST["n_cat"]);
			$cid = intval($cid);
			  $sql_move = "UPDATE mlb_texts SET text_cid=$cid WHERE text_id=$id or text_pid=$id";
			  if(mysql_query($sql_move)) {
					  $smarty->assign('INFORMATION',TEXT_IS_MOVED);
					  $smarty->assign("LINK","?do=4");
					  $smarty->assign("LINKT","Назад");
					  $smarty->display($theme.'/info.tpl');
			  } else {
						$smarty->assign('INFORMATION',TEXT_IS_NOT_MOVED.mysql_error());
						$smarty->assign("LINK","?do=4&edit=".$id);
						$smarty->assign("LINKT","Назад");
						$smarty->display($theme.'/info.tpl');
			    }
		}
		##Просмотр и управление файлами, приаттаченными к данной записи
		##Дочерние файлы для данной записи
		if(@$_GET["fed"]) {
			$id = trim($_GET["fed"]);
			$id = intval($id);
			$id = mysql_real_escape_string($id);
			  $sql_f = "SELECT * FROM mlb_files WHERE file_tid=$id";
			  $query = mysql_query($sql_f);
			  $c=0;
			  while($res_f = mysql_fetch_array($query)) {
					$file[] = $res_f["file_address"];
					$dates[] = date("d.m.y/H:i",$res_f["file_date"]);
					$sz[] = round(filesize($dir_f.$res_f["file_address"])/1024, 2);
					$ids[] = $res_f["file_id"];
					$c++;
			  }
			  @$smarty->assign('id',$ids);
			  $smarty->assign('dir_f',$dir_f);
			  @$smarty->assign('file',$file);
			  @$smarty->assign('dates',$dates);
			  @$smarty->assign('sz',$sz);
			  $smarty->display($theme.'/admin/adm_edit_files.tpl');
			   if($c<1) {
						$smarty->assign('INFORMATION',FILES_NOT_FOUND);
						$smarty->assign("LINK","?do=4&edit=".$id);
						$smarty->assign("LINKT","Назад");
						$smarty->display($theme.'/info.tpl');
				}
		}
		##Загрузить еще файлы к данной записи
		if(@$_GET["fedadd"]) {
			$id = trim($_GET["fedadd"]);
			$id = intval($id);
			$id = mysql_real_escape_string($id);
			if(@$_GET["ok"]) {
				  for($i=1;$i<=$cfd;$i++) {
						if($_FILES["file$i"]["size"]) {
							  if($_FILES["file$i"]["size"] > 1024*$mfb*1024) {
									$smarty->assign("INFORMATION",MAX_FILE_1.$mfb.MAX_FILE_2);
									$smarty->assign("LINK","?do=3");
									$smarty->assign("LINKT","Назад");
									$smarty->display($theme.'/info.tpl');
									$ftg = FALSE;
							  } else {
									@$ftg == TRUE;
								}
							  if(@$ftg !== FALSE) {
									$ext = strrchr($_FILES["file$i"]["name"], '.');
									if(!stristr($fext, $ext)) {
											$smarty->assign("INFORMATION",EXT_FILE_NOT);
											$smarty->assign("LINK","?do=3");
											$smarty->assign("LINKT","Назад");
											$smarty->display($theme.'/info.tpl');
											exit();
									}
									$endp = $end.$ext;
									if(is_file($dir_f.$_FILES["file$i"]["name"].$endp)) {
											$endth = $end.(str_replace(' ', '', microtime())*10000000000000).'_'.$ext;
									} else {
											$endth = $end.$ext;
									  }
									@chmod($dir_f, 0777);
									if(move_uploaded_file($_FILES["file$i"]["tmp_name"], $dir_f.$_FILES["file$i"]["name"].$endth)) {
										  @chmod($dir_f.$_FILES["file$i"]["name"].$endth, 0777);
										  $files[] = mysql_real_escape_string($_FILES["file$i"]["name"].$endth);
									} else {
											$smarty->assign("INFORMATION",FILE_NOT_LOADED);
											$smarty->assign("LINK","");
											$smarty->assign("LINKT","");
											$smarty->display($theme.'/info.tpl');
									  }
							  }
						}
				  }
          				for($i=0;$i<=sizeof($files)-1;$i++) {
			        			mysql_query("INSERT INTO mlb_files VALUES('', '{$files[$i]}', ".time().", $id)");
						}
						$smarty->assign("INFORMATION",DO_IT);
	    	        	$smarty->assign("LINK","");
	    	        	$smarty->assign("LINKT","");
    	            	$smarty->display($theme.'/info.tpl');
			}

			for($i=1;$i<=$cfd;$i++) {
		        	@$dl .= '<br /> <input type="file" name="file'.$i.'" class="q">'."\n";
			}

			  $smarty->assign("dl",$dl);
			  $smarty->assign("fext",$fext);
			  $smarty->assign("mbf",$mfb);
			  $smarty->assign("id",$id);
    	      $smarty->display($theme.'/admin/adm_file_text.tpl');
		}
		##Удаление определенного файла из базы и физического каталога
		if(@$_GET["del_file"]) {
			$id = trim($_GET["del_file"]);
			$id = intval($id);
			$id = mysql_real_escape_string($id);
			  $res_s = mysql_fetch_array(mysql_query("SELECT file_address FROM mlb_files WHERE file_id=$id"));
			  $sql_del = "DELETE FROM mlb_files WHERE file_id=$id";
			  if(mysql_query($sql_del)) {
					unlink($dir_f.$res_s["file_address"]);
						  $smarty->assign('INFORMATION',FILE_IS_REMOVED);
						  $smarty->assign("LINK","?do=4");
						  $smarty->assign("LINKT","Назад");
						  $smarty->display($theme.'/info.tpl');
			  } else {
						$smarty->assign('INFORMATION',FILE_IS_NOT_REMOVED.mysql_error());
						$smarty->assign("LINK","?do=4");
						$smarty->assign("LINKT","Назад");
						$smarty->display($theme.'/info.tpl');
			    }
		}
		##Редактирование записей, для которых не существует родительской категории
		if(@$_GET["tnc"]) {
			##Удаление записей, выбранных чекбоксами
			if(@$_GET["sdel"]) {
				$i = 0;
				while($_POST["del"][$i]) {
						$id = intval($_POST["del"][$i]);
						$id = mysql_real_escape_string($id);
							mysql_query("DELETE FROM mlb_texts WHERE text_id='$id' or text_pid=$id");
							mysql_query("DELETE FROM mlb_comments WHERE comm_tid='$id'");
							mysql_query("DELETE FROM mlb_files WHERE file_tid='$id'");
						$i++;
				}
					$smarty->assign('INFORMATION',$i.' - '.DO_IT);
			        $smarty->assign("LINK","?do=4");
	    	        $smarty->assign("LINKT","Назад");
			        $smarty->display($theme.'/info.tpl');
				break;
			}
			$and = '';
			$sql_out = "SELECT cat_id FROM mlb_cat";
			    $out_query = mysql_query($sql_out) or die(mysql_error());
		        while($array_query = mysql_fetch_array($out_query)) {
		      	   		$and .= ' and text_cid!='.$array_query["cat_id"];
			    }
				$sql = "SELECT text_name, text_id, text_cid FROM mlb_texts WHERE text_pid=0$and ORDER BY text_name ASC";
				$query = mysql_query($sql);
				$c = 0;
				  while($res_texts = mysql_fetch_array($query)) {
						$texts[] = $res_texts["text_name"];
						$ids[] = $res_texts["text_id"];
						$i[] = $c;
						$c++;
				  }
				  $smarty->assign("texts",$texts);
				  $smarty->assign("ids",$ids);
				  $smarty->assign("i",$i);
				  $smarty->display($theme.'/admin/adm_texts_non.tpl');
		}


		##"Селектор" записей с поблочной разбивкой
		$sql_out = "SELECT * FROM mlb_cat ORDER BY cat_hid, cat_pid ASC";
			  $out_query = mysql_query($sql_out) or die(mysql_error());
			  $select = '';
		      while($array_query = mysql_fetch_array($out_query)) {
					if($array_query["cat_pid"] == 0) {
							$select_val[] = '';
							$select_names[] = LINE;
					}
					if($array_query["cat_status"] == 1) {
							$hid = HIDDEN;
					} else $hid = '';

						$select_val[] = '';
						$select_names[] = $hid.htmlspecialchars(stripslashes($array_query["cat_name"])).' (id='.$array_query["cat_id"].'/pid='.$array_query["cat_pid"].')';
						 $hid = '';

					if($array_query["cat_pid"] == 0) {
							$select_val[] = '';
							$select_names[] = '   ';
					}
					$sql_t = "SELECT text_name, text_id, text_cid, text_pid FROM mlb_texts WHERE text_cid=".$array_query["cat_id"]." and text_pid=0 ORDER BY text_name ASC";
					$query_t = mysql_query($sql_t);
					  while($res_t = mysql_fetch_array($query_t)) {
							$select_val[] = $res_t["text_id"];
							$select_names[] = ' - '.$res_t["text_name"];
					  }
			  }
			  	if($select_val > $psa) {
			  		$poc = $start.'-'.($start+$psa);
			  		if($start>0) {
			  				$pre = '<a href="?do=4&p='.($start-$psa).'"><<Предыдушие</a>';
					}
					if($start < sizeof($select_val)-$psa) {
			  				$next = '<a href="?do=4&p='.($start+$psa).'">Следующие>></a>';
					}
							$select_val = array_splice($select_val, $start, $psa);
							$select_names = array_splice($select_names, $start, $psa);
							$select_val = array_values($select_val);
							$select_names = array_values($select_names);
				}
				  $smarty->assign("poc",$poc);
				  $smarty->assign("pre",$pre);
				  $smarty->assign("next",$next);
				  $smarty->assign("id2",$select_val);
				  $smarty->assign("names2",$select_names);
				  $smarty->display($theme.'/admin/adm_edit_text.tpl');
	} break;
	##Управление конфигурацией прогрммы
	case 5: {
			    if(@!$_GET["ok"]) {
						$smarty->assign("topage",$topage);
						$smarty->assign("topageu",$topageu);
						$smarty->assign("cfd",$cfd);
						$smarty->assign("fext",$fext);
						$smarty->assign("dir_f",$dir_f);
						$smarty->assign("end",$end);
						$smarty->assign("mfb",$mfb);
						$smarty->assign("is_new",$is_new);
						$smarty->assign("comp",$comp);
						$smarty->assign("textn",$textn);
						$smarty->assign("psa",$psa);
						$stol = array(0=>'Да',1=>'Нет');
						$bool = array(0=>1,1=>0);
						if($is_stol == 1) {
							$sels = array(0=>'selected',1=>'');
						} else {
							$sels = array(0=>'',1=>'selected');
						  }
						$smarty->assign("stol",$stol);
						$smarty->assign("bool",$bool);
						$smarty->assign("sels",$sels);
						$tema = array(0=>'Да',1=>'Нет');
						$boolt = array(0=>1,1=>0);
						if($is_tema == 1) {
							$selst = array(0=>'selected',1=>'');
						} else {
							$selst = array(0=>'',1=>'selected');
						  }
						  //echo $tema.'>'.$selst.'>'.$boolt;
						$smarty->assign("tema",$tema);
						$smarty->assign("boolt",$boolt);
						$smarty->assign("selst",$selst);
						$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.'/admin/adm_edit_conf.tpl');
			    } else {
			    	$topage2 = intval($_POST["topage"]);
			    	$topageu2 = intval($_POST["topageu"]);
			    	$cfd2 = intval($_POST["cfd"]);
			    	$comp2 = intval($_POST["comp"]);
			    	$textn2 = intval($_POST["textn"]);
			    	$mfb2 = intval($_POST["mfb"]);
			    	$is_new2 = intval($_POST["is_new"]);
			    	$psa2 = intval($_POST["psa"]);
			    	$is_tema2 = intval($_POST["is_tema"]);
			    	$fext2 = trim($_POST["fext"]);
			    	$dir_f2 = trim($_POST["dir_f"]);
			    	$end2 = trim($_POST["end"]);
			    	$themes2 = trim($_POST["theme"]);
			    	$is_stol2 = trim($_POST["is_stol"]);
			    		$topage2 = mysql_real_escape_string($topage2);
			    		$topageu2 = mysql_real_escape_string($topageu2);
			    		$cfd2 = mysql_real_escape_string($cfd2);
			    		$comp2 = mysql_real_escape_string($comp2);
			    		$textn2 = mysql_real_escape_string($textn2);
			    		$mfb2 = mysql_real_escape_string($mfb2);
			    		$is_new2 = mysql_real_escape_string($is_new2);
			    		$psa2 = mysql_real_escape_string($psa2);
			    		$is_tema2 = mysql_real_escape_string($is_tema2);
			    		$fext2 = mysql_real_escape_string($fext2);
			    		$dir_f2 = mysql_real_escape_string($dir_f2);
			    		$end2 = mysql_real_escape_string($end2);
			    		$themes2 = mysql_real_escape_string($themes2);
			    		$is_stol2 = mysql_real_escape_string($is_stol2);
			    			$sql = "SELECT * FROM mlb_config ORDER BY conf_id ASC";
			    			$query = mysql_query($sql);
			    			while($res = mysql_fetch_array($query)) {
			    				if($res["conf_ident"] == "topage") {
			    					mysql_query("UPDATE mlb_config SET conf_value_int=$topage2 WHERE conf_ident='{$res["conf_ident"]}'");
			    					$ok_topage = 1;
								}
			    				if($res["conf_ident"] == "topageu") {
			    					mysql_query("UPDATE mlb_config SET conf_value_int=$topageu2 WHERE conf_ident='{$res["conf_ident"]}'");
			    					$ok_topageu = 1;
								}
			    				if($res["conf_ident"] == "cfd") {
			    					mysql_query("UPDATE mlb_config SET conf_value_int=$cfd2 WHERE conf_ident='{$res["conf_ident"]}'");
			    					$ok_cfd = 1;
								}
			    				if($res["conf_ident"] == "comp") {
			    					mysql_query("UPDATE mlb_config SET conf_value_int=$comp2 WHERE conf_ident='{$res["conf_ident"]}'");
			    					$ok_comp = 1;
								}
			    				if($res["conf_ident"] == "textn") {
			    					mysql_query("UPDATE mlb_config SET conf_value_int=$textn2 WHERE conf_ident='{$res["conf_ident"]}'");
			    					$ok_textn = 1;
								}
			    				if($res["conf_ident"] == "psa") {
			    					mysql_query("UPDATE mlb_config SET conf_value_int=$psa2 WHERE conf_ident='{$res["conf_ident"]}'");
			    					$ok_psa = 1;
								}
			    				if($res["conf_ident"] == "is_tema") {
			    					mysql_query("UPDATE mlb_config SET conf_value_int=$is_tema2 WHERE conf_ident='{$res["conf_ident"]}'");
			    					$ok_is_tema = 1;
								}
			    				if($res["conf_ident"] == "mfb") {
			    					mysql_query("UPDATE mlb_config SET conf_value_int=$mfb2 WHERE conf_ident='{$res["conf_ident"]}'");
			    					$ok_mfb = 1;
								}
			    				if($res["conf_ident"] == "is_new") {
			    					mysql_query("UPDATE mlb_config SET conf_value_int=$is_new2 WHERE conf_ident='{$res["conf_ident"]}'");
			    					$ok_is_new = 1;
								}
			    				if($res["conf_ident"] == "is_stol") {
			    					mysql_query("UPDATE mlb_config SET conf_value_int=$is_stol2 WHERE conf_ident='{$res["conf_ident"]}'");
			    					$ok_is_stol = 1;
								}
			    				if($res["conf_ident"] == "fext") {
			    					mysql_query("UPDATE mlb_config SET conf_value_text='$fext2' WHERE conf_ident='{$res["conf_ident"]}'");
			    					$ok_fext = 1;
								}
			    				if($res["conf_ident"] == "dir_f") {
			    					mysql_query("UPDATE mlb_config SET conf_value_text='$dir_f2' WHERE conf_ident='{$res["conf_ident"]}'");
			    					$ok_dir_f = 1;
								}
			    				if($res["conf_ident"] == "end") {
			    					mysql_query("UPDATE mlb_config SET conf_value_text='$end2' WHERE conf_ident='{$res["conf_ident"]}'");
			    					$ok_end = 1;
								}
			    				if($res["conf_ident"] == "theme") {
			    					mysql_query("UPDATE mlb_config SET conf_value_text='$themes2' WHERE conf_ident='{$res["conf_ident"]}'");
			    					$ok_theme = 1;
								}
							}
							if($ok_topage !== 1) {
								mysql_query("INSERT INTO mlb_config VALUES ('', 'topage', '', '$topage2', '')");
							}
							if($ok_topageu !== 1) {
								mysql_query("INSERT INTO mlb_config VALUES ('', 'topageu', '', '$topageu2', '')");
							}
							if($ok_cfd !== 1) {
								mysql_query("INSERT INTO mlb_config VALUES ('', 'cfd', '', '$cfd2', '')");
							}
							if($ok_comp !== 1) {
								mysql_query("INSERT INTO mlb_config VALUES ('', 'comp', '', '$comp2', '')");
							}
							if($ok_textn !== 1) {
								mysql_query("INSERT INTO mlb_config VALUES ('', 'textn', '', '$textn2', '')");
							}
							if($ok_psa !== 1) {
								mysql_query("INSERT INTO mlb_config VALUES ('', 'psa', '', '$psa2', '')");
							}
							if($ok_mfb !== 1) {
								mysql_query("INSERT INTO mlb_config VALUES ('', 'mfb', '', '$mfb2', '')");
							}
							if($ok_is_new !== 1) {
								mysql_query("INSERT INTO mlb_config VALUES ('', 'is_new', '', '$is_new2', '')");
							}
							if($ok_is_stol !== 1) {
								mysql_query("INSERT INTO mlb_config VALUES ('', 'is_stol', '', '$is_stol2', '')");
							}
							if($ok_is_tema !== 1) {
								mysql_query("INSERT INTO mlb_config VALUES ('', 'is_tema', '', '$is_tema2', '')");
							}
							if($ok_fext !== 1) {
								mysql_query("INSERT INTO mlb_config VALUES ('', 'fext', '', '', '$fext2')");
							}
							if($ok_dir_f !== 1) {
								mysql_query("INSERT INTO mlb_config VALUES ('', 'dir_f', '', '', '$dir_f2')");
							}
							if($ok_end !== 1) {
								mysql_query("INSERT INTO mlb_config VALUES ('', 'end', '', '', '$end2')");
							}
							if($ok_theme !== 1) {
								mysql_query("INSERT INTO mlb_config VALUES ('', 'theme', '', '', '$themes2')");
							}

								$smarty->assign('INFORMATION',DO_IT);
			      				$smarty->assign("LINK","?do=");
	    	      				$smarty->assign("LINKT","Назад");
			      				$smarty->display($theme.'/info.tpl');

				  }
	} break;
	##Управление комментариями к выбранной записи
	##Выбор записи, родительской для комментов, осуществляется по id
	case 6: {

		##Удаление комментариями
		if(@$_GET["del"]) {
			$id = intval($_GET["del"]);
			$id = mysql_real_escape_string($id);
			if(mysql_query("DELETE FROM mlb_comments WHERE comm_id=$id")) {
					$smarty->assign('INFORMATION',DO_IT);
					$smarty->assign("LINK","?do=6&id=".intval($_GET["idb"]));
					$smarty->assign("LINKT","Назад");
					$smarty->display($theme.'/info.tpl');
			}
			break;
		}

		$id = intval($_GET["id"]);
		$id = mysql_real_escape_string($id);
			    if(@$_GET["ok"]) {
						$name = trim($_POST["namec"]);
						if(empty($name)) {
								$smarty->assign("INFORMATION",NAME_COMM_NOT_EXISTS);
								$smarty->assign("LINK","?do=6&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=6&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)) {
								$smarty->assign("INFORMATION",COMMENT_IS_ADD);
								$smarty->assign("LINK","?do=6&id=".$id);
								$smarty->assign("LINKT","Назад");
								$smarty->display($theme.'/info.tpl');
								exit();
						  }
				  }
				  	$sql = "SELECT * FROM mlb_comments WHERE comm_tid=$id ORDER BY comm_date DESC LIMIT $start, $comp";
					$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;
							$comms_id[] = stripslashes(htmlspecialchars($res_comm["comm_id"]));
					}
					@$smarty->assign("comms_n",$comms_n);
					@$smarty->assign("comms_d",$comms_d);
					@$smarty->assign("comms_t",$comms_t);
					@$smarty->assign("comms_id",$comms_id);
					@$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=6&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=6&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=6&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=6&id='.$id.'&p='.($i*$comp).'">'.($i+1).'</a>';
				  	if($i!=2) echo ',';
				  }
				  echo ' ... ';
				  if($all > $start+$comp*4) {
				    echo '<a href="?do=6&id='.$id.'&p='.($start-$comp).'">'.(round($start/$comp,0)).'</a>,';
				    echo '[<a href="?do=6&id='.$id.'&p='.($start).'">'.(round($start/$comp,0)+1).'</a>],';
				    echo '<a href="?do=6&id='.$id.'&p='.($start+$comp).'">'.(round($start/$comp,0)+1+1).'</a>';
				  echo ' ... ';
			      } else {
			      	  echo '<a href="?do=6&id='.$id.'&p='.($all+1-$comp * 6).'">'.(round(($all-$comp * 5)/$comp,0)).'</a>,';
			      	  echo '<a href="?do=6&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=6&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=6&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=6&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=6&id='.$id.'&p='.($start+$comp).'">'.NEXT.'</a>';
			  }
$nav = ob_get_contents();
ob_clean();
			  	$smarty->assign("nav_here",$nav);
#############
#############
#############
				$smarty->display($theme.'/admin/adm_comments.tpl');

		} break;
		##Пункт "Разное", сдесь находятся различные опции программы,
		## которые не входят под определения полного раздела
		case 7: {
			if(@$_GET["stat"]) {
					$res1 = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM mlb_cat"));
					$res2 = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM mlb_texts WHERE text_pid=0"));
					$res3 = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM mlb_files"));
					$res4 = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM mlb_comments"));
					$res5 = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM mlb_table"));
					$res6 = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM mlb_pages"));
							$smarty->assign("cat",$res1[0]);
							$smarty->assign("text",$res2[0]);
							$smarty->assign("file",$res3[0]);
							$smarty->assign("comm",$res4[0]);
							$smarty->assign("stab",$res5[0]);
							$smarty->assign("page",$res6[0]);
							$smarty->display($theme.'/admin/adm_stat.tpl');
			}
			if(@$_GET["opt"]) {
					$sql = "OPTIMIZE TABLE mlb_cat, mlb_comments, mlb_config, mlb_files, mlb_texts, mlb_table, mlb_pages";
					if(mysql_query($sql)) {
							$smarty->assign("INFORMATION",OPT_DO_IT);
							$smarty->assign("LINK","");
							$smarty->assign("LINKT","");
							$smarty->display($theme.'/info.tpl');
					}
			}
			if(@$_GET["mail"]) {
				if(!@$_GET["ok"]) {
    	        		$smarty->display($theme.'/admin/adm_mail.tpl');
				} else {
						$to = trim($_POST["to"]);
						$from = trim($_POST["from"]);
						$themem= trim($_POST["themem"]);
						$message= trim($_POST["message"]);
							  $headers  = "From: ".$from."\r\n";
                              $headers .= "MIME-Version: 1.0\r\n";
                              $headers .= "Content-Transfer-Encoding: 8bit\r\n";
                              $headers .= "Content-Type: text/plain; charset=\"utf-8\"\r\n";
                              $headers .= "X-Mailer: PHP v.".phpversion();
									@mail($to, $themem, $message, $headers);
											$smarty->assign("INFORMATION",MAIL_DO_IT);
											$smarty->assign("LINK","");
											$smarty->assign("LINKT","");
											$smarty->display($theme.'/info.tpl');
				  }
			}
			if(@$_GET["exit"]) {
					unset($_SESSION["ok"]);
						$_SESSION["ok"] = FALSE;
					unset($_SESSION["p"]);
						$_SESSION["p"] = FALSE;
					unset($_SESSION["p"]);
						session_destroy();
			}
			if(@$_GET["stol"]) {
				$sql = "SELECT * FROM mlb_table ORDER BY table_date DESC LIMIT $start, 15";
				$query = mysql_query($sql);
				$cz = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM mlb_table"));
				if($cz[0] == 0) {
						$smarty->assign("INFORMATION",CON_NOT_FOUND);
						$smarty->assign("LINK","");
						$smarty->assign("LINKT","");
						$smarty->display($theme.'/info.tpl');
				}
				while($res = mysql_fetch_array($query)) {
						$namezak[] = stripslashes(htmlspecialchars($res["table_name"]));
						$zak[] = stripslashes(htmlspecialchars($res["table_text"]));
						$idz[] = $res["table_id"];
						$date[] = date("d.m.y/H:i", $res["table_date"]);
				}
				@$smarty->assign("namezak",$namezak);
				@$smarty->assign("zak",$zak);
				@$smarty->assign("idz",$idz);
				@$smarty->assign("date",$date);
				$smarty->display($theme.'/admin/adm_stol.tpl');
				$all = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM mlb_table"));
    							ob_start();
    								echo '<small>Страниц: '.(round($all[0]/15,0)).', тек.: '.(round($start/15,0)+1).'</small> <br />';
    								for($i=0;$i<=$all[0]/15;$i++) {
    										echo '<a href="?do=7&stol=1&p='.($i*15).'">'.($i+1).'</a> ';
									}
								$nav = ob_get_contents();
								ob_clean();
								$smarty->assign("nav_here",$nav);
    	        				$smarty->display($theme.'/admin/adm_nav.tpl');
			}
			if(@$_GET["delzak"]) {
					$id = intval($_GET["delzak"]);
					$id = mysql_real_escape_string($id);
					if(mysql_query("DELETE FROM mlb_table WHERE table_id=$id")) {
							$smarty->assign("INFORMATION",REMOVE);
							$smarty->assign("LINK","");
							$smarty->assign("LINKT","");
							$smarty->display($theme.'/info.tpl');
					}
			}
			$smarty->display($theme.'/admin/adm_misc.tpl');
		} break;
		##Добавление записей путем сканирования каталога texts
		case 8: {


				function trans($text,$t=0)  {
 						if($t == 1) {
     							return $text;
    					} else {
  								$mass_en=array(
										"SCH", "Sch", "YO", "Yo", "ZH", "Zh",
										"CH", "Ch", "SH", "Sh", "YE", "Ye",
										"YU", "Yu", "YA", "Ya", "sch", "yo",
										"zh", "ch", "sh", "yz", "yu", "ya",
										"A", "B", "V", "G", "D", "E",
										"Z", "I", "J", "K","L", "M",
										"N", "O", "P", "R", "S", "T",
										"U", "F", "H", "C", "Y", "a",
										"b", "v", "g", "d", "e", "z",
										"i", "j", "k", "l", "m", "n",
										"o", "p", "r", "s", "t", "u",
										"f", "h", "c", '"', "y", "=", "_"
    							);
  								$mass_ru=array(
										"Щ", "Щ", "Ё", "Ё", "Ж", "Ж",
										"Ч", "Ч", "Ш", "Ш", "Э", "Э",
										"Ю", "Ю", "Я", "Я", "щ", "ё",
										"ж", "ч", "ш", "э", "ю", "я",
										"А", "Б", "В", "Г", "Д", "Е",
										"З", "И", "Й", "К", "Л", "М",
										"Н", "О", "П", "Р", "С", "Т",
										"У", "Ф", "Х", "Ц", "Ы", "а",
										"б", "в", "г", "д", "е", "з",
										"и", "й", "к", "л", "м", "н",
										"о", "п", "р", "с", "т", "у",
										"ф", "х", "ц", "ъ", "ы", "ь", " "
    							);
								$source_len=strlen($text);
								while(strlen($text)!=0)  {
  										$position_1=strpos($text, "<");
										  if(empty($position_1))  {
													$new_string.=str_replace($mass_en, $mass_ru, $text);
													$text=substr_replace($text, "", 0, strlen($text));
													break;
										  } else  {
													$sub_string=substr($text, 0, $position_1+1);
													$new_string.=str_replace($mass_en, $mass_ru, $sub_string);
													$text=substr_replace($text, "", 0, $position_1+1);
													$position_2=strpos($text, ">");
													$sub_string=substr($text, 0, $position_2+1);
													$new_string.=$sub_string;
													$text=substr_replace($text, "", 0, $position_2+1);
										  }
 								}
							  $text=$new_string;
							  return $text;
  						}
 				}
 				if(@$_GET["trans"]) {
 					$mass_en=array(
										"SCH", "Sch", "YO", "Yo", "ZH", "Zh",
										"CH", "Ch", "SH", "Sh", "YE", "Ye",
										"YU", "Yu", "YA", "Ya", "sch", "yo",
										"zh", "ch", "sh", "yz", "yu", "ya",
										"A", "B", "V", "G", "D", "E",
										"Z", "I", "J", "K","L", "M",
										"N", "O", "P", "R", "S", "T",
										"U", "F", "H", "C", "Y", "a",
										"b", "v", "g", "d", "e", "z",
										"i", "j", "k", "l", "m", "n",
										"o", "p", "r", "s", "t", "u",
										"f", "h", "c", '"', "y", "=", "_"
    							);
  								$mass_ru=array(
										"Щ", "Щ", "Ё", "Ё", "Ж", "Ж",
										"Ч", "Ч", "Ш", "Ш", "Э", "Э",
										"Ю", "Ю", "Я", "Я", "щ", "ё",
										"ж", "ч", "ш", "э", "ю", "я",
										"А", "Б", "В", "Г", "Д", "Е",
										"З", "И", "Й", "К", "Л", "М",
										"Н", "О", "П", "Р", "С", "Т",
										"У", "Ф", "Х", "Ц", "Ы", "а",
										"б", "в", "г", "д", "е", "з",
										"и", "й", "к", "л", "м", "н",
										"о", "п", "р", "с", "т", "у",
										"ф", "х", "ц", "ъ", "ы", "ь", " "
    							);
    							$c=0;
    							foreach($mass_ru as $cr) {
    									echo $cr.'->'.$mass_en[$c].'<br />';
    									$c++;
								}
								break;
				}


			if(@!$_GET["ok"]) {

				$sql_out = "SELECT * FROM mlb_cat ORDER BY cat_hid, cat_pid ASC";
			  $out_query = mysql_query($sql_out) or die(mysql_error());
			  $select = '';
				  while($array_query = mysql_fetch_array($out_query)) {
					if($array_query["cat_pid"] == 0) {
							$select_val[] = '';
							$select_names[] = LINE;
					}
					if($array_query["cat_status"] == 1) {
							$hid = HIDDEN;
					} else $hid = '';
						$select_val[] = $array_query["cat_id"];
						$select_names[] = $hid.htmlspecialchars(stripslashes($array_query["cat_name"])).' (id='.$array_query["cat_id"].'/pid='.$array_query["cat_pid"].')';
						 $hid = '';
					if($array_query["cat_pid"] == 0) {
							$select_val[] = '';
							$select_names[] = '   ';
					}
			  }
			  	$smarty->assign("idss",$select_val);
			  	$smarty->assign("namess",$select_names);
				$smarty->display($theme.'/admin/adm_steck.tpl');
			} else {
				$open = opendir('./import/');
				$c = 0;
				$cid = intval($_POST["n_cat"]);
				$cid = mysql_real_escape_string($cid);
				while($r = readdir($open)) {
					if(is_file('./import/'.$r)) {
						if($r != '.htaccess') {
								$extf = strrchr($r, '.');
								$rn = str_replace($extf, '', $r);
								if(mysql_query("INSERT INTO mlb_texts VALUES('', '".mysql_real_escape_string(trans($rn))."', '".mysql_real_escape_string(file_get_contents('./import/'.$r))."', '', '', '', '".time()."', '$cid', '0', '0')")) {
									mysql_query("UPDATE mlb_texts SET text_hid='".mysql_insert_id()."' WHERE text_id='".mysql_insert_id()."'");
									unlink('./import/'.$r);
									$c++;
								}
						}
					}
				}
				echo $c.' - '.DO_IT;
			}
		} break;
		##Создание "псевдо-страниц"
		case 9: {
			if(@$_GET["about"]) {
					$smarty->display($theme.'/admin/adm_help_pages.tpl');
				break;
			}
			if(@!$_GET["ok"]) {
					$smarty->assign("date",date("d.m.y/H:i"));
					$smarty->display($theme.'/admin/adm_create_page.tpl');
			} else {
				$name = trim($_POST["title"]);
				$name = mysql_real_escape_string($name);
				$text = trim($_POST["text"]);
				$text = mysql_real_escape_string($text);
					if(empty($name) || empty($text)) {
							$smarty->assign("INFORMATION",TEXT_NOT_EXISTS);
							$smarty->assign("LINK","");
							$smarty->assign("LINKT","");
							$smarty->display($theme.'/info.tpl');
						break;
					}
					if(mysql_query("INSERT INTO mlb_pages VALUES('', '$name', '$text', '".time()."')")) {
							$smarty->assign("INFORMATION",DO_IT."<br />Ссылка на страницу: <a href=\"./index.php?do=6&go=".mysql_insert_id()."\">$name</a> <br /> <input type=\"text\" value=\"http://".$_SERVER["HTTP_HOST"].''.str_replace('admin.php', '', $_SERVER["PHP_SELF"])."index.php?do=6&go=".mysql_insert_id()."\" class=\"q\">");
							$smarty->assign("LINK","");
							$smarty->assign("LINKT","");
							$smarty->display($theme.'/info.tpl');
    	        		break;
					}
			}
		} break;
		##Управление "псевдо-страницами"
		case 10: {
			if(@$_GET["del"]) {
				$id = intval($_GET["del"]);
				$id = mysql_real_escape_string($id);
					if(mysql_query("DELETE FROM mlb_pages WHERE page_id=$id")) {
							$smarty->assign("INFORMATION",REMOVE);
							$smarty->assign("LINK","");
							$smarty->assign("LINKT","");
							$smarty->display($theme.'/info.tpl');
						break;
					}
			}
			if(@$_GET["edit"]) {
				$id = intval($_GET["edit"]);
				$id = mysql_real_escape_string($id);
				if(@!$_GET["ok"]) {
						$sql = mysql_query("SELECT * FROM mlb_pages WHERE page_id=$id");
						$res = mysql_fetch_array($sql);
								$smarty->assign("edit", 1);
								$smarty->assign("id", $id);
								$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.'/admin/adm_create_page.tpl');
				} else {
					$name = trim($_POST["title"]);
					$name = mysql_real_escape_string($name);
					$text = trim($_POST["text"]);
					$text = mysql_real_escape_string($text);
						if(empty($name) || empty($text)) {
								$smarty->assign("INFORMATION",TEXT_NOT_EXISTS);
								$smarty->assign("LINK","");
								$smarty->assign("LINKT","");
								$smarty->display($theme.'/info.tpl');
							break;
						}
						if(mysql_query("UPDATE mlb_pages SET page_name='$name', page_text='$text' WHERE page_id='$id'")) {
									$smarty->assign("INFORMATION",DO_IT);
									$smarty->assign("LINK","");
									$smarty->assign("LINKT","");
									$smarty->display($theme.'/info.tpl');
								break;
						}
				}
			break;
			}
			$sql = "SELECT page_name, page_id FROM mlb_pages ORDER BY page_name ASC LIMIT $start, 25";
			$query = mysql_query($sql);
			$arr2out = array();
			while($res = mysql_fetch_array($query)) {
					$arr2out[] = $res["page_name"];
					$id2out[] = $res["page_id"];
			}
						$smarty->assign("list",$arr2out);
						$smarty->assign("id",$id2out);
    					$smarty->display($theme.'/admin/adm_pages.tpl');
    							$all = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM mlb_pages"));
    							ob_start();
    								echo '<small>Страниц: '.(round($all[0]/25,0)).', тек.: '.(round($start/25,0)+1).'</small> <br />';
    								for($i=0;$i<=$all[0]/25;$i++) {
    									echo '<a href="?do=10&p='.($i*25).'">'.($i+1).'</a> ';
									}
								$nav = ob_get_contents();
								ob_clean();
								$smarty->assign("nav_here",$nav);
    	        				$smarty->display($theme.'/admin/adm_nav.tpl');

		} break;
		##Управление всеми файлами
		case 11: {
			$sql = "SELECT file_address, file_id, file_date FROM mlb_files ORDER BY file_date DESC LIMIT $start, 25";
			$query = mysql_query($sql);
			$arr2out = array();
			while($res = mysql_fetch_array($query)) {
					$arr2out[] = $res["file_address"];
					$id2out[] = $res["file_id"];
					$d2out[] = date("d.m.y/H:i", $res["file_date"]);
			}
						$smarty->assign("list",$arr2out);
						$smarty->assign("id",$id2out);
						$smarty->assign("date", $d2out);
						$smarty->assign("dir", $dir_f);
    					$smarty->display($theme.'/admin/adm_files.tpl');
    							$all = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM mlb_files"));
    							ob_start();
    								echo '<small>Страниц: '.(round($all[0]/25,0)).', тек.: '.(round($start/25,0)+1).'</small> <br />';
    								for($i=0;$i<=$all[0]/25;$i++) {
    										echo '<a href="?do=11&p='.($i*25).'">'.($i+1).'</a> ';
									}
								$nav = ob_get_contents();
								ob_clean();
								$smarty->assign("nav_here",$nav);
    	        				$smarty->display($theme.'/admin/adm_nav.tpl');
		} break;
  }
?>