View file apanel/pages/city.php

File size: 12.08Kb
<?php
/**********************************************/
/* Автор скрипта: Александр Есин              */
/* E-Mail: [email protected] ([email protected]) */
/* ICQ: 6464729                               */
/* Site: http://ticlove.ru                    */
/**********************************************/
?>
<?php if (!defined('SECURED')) die("SORRY! Unknown Error!"); ?>
<h3>Добавление/Удаление стран-регионов-городов</h3>
<?php $mode = isset($_GET['mode']) ? $_GET['mode'] : NULL; ?>
<?php
switch($mode) {
case 'region':
?>
<?php
$id_country = intval($_GET['id_country']);
$sql = mysql_query("SELECT * FROM `q_country` WHERE `id_country` = '".$id_country."' LIMIT 1;");
if (mysql_num_rows($sql) == 0) {
echo '<script type="text/javascript">location="apanel.php";</script>';
}
$array_country = mysql_fetch_array($sql);
?>
<div style="padding-top: 10px;">Страна: <strong><?php echo htmlspecialchars($array_country['name_country'], ENT_QUOTES); ?></strong></div>
<div style="padding-top: 10px;">
<h4>Регионы</h4>
<?php
$col = 50;
if (isset($_GET['start'])) $start = abs(intval($_GET['start']));
else $start = 0;
$count_p = mysql_result(mysql_query("SELECT COUNT(*) FROM `q_region` WHERE `id_country` = '".$id_country."';"), 0);
if ($count_p > 0) {
if ($start >= $count_p) $start = 0;
$q = mysql_query("SELECT * FROM `q_region` WHERE `id_country` = '".$id_country."' ORDER BY `name_region` ASC LIMIT ".$start.", ".$col);
$i = 1;
?>
<?php while ($array = mysql_fetch_array($q)) { ?>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?page=city&amp;mode=city&amp;id_country=<?php echo $id_country; ?>&amp;id_region=<?php echo $array['id_region']; ?>"><?php echo htmlspecialchars($array['name_region'], ENT_QUOTES); ?></a> [<a class="red" href="javascript:void(0)" onclick="javascript:edit_region('<?php echo $array['id_region']; ?>')">ред.</a>]<br/>
<?php } ?>
<?php function_page($_SERVER['PHP_SELF'].'?page=city&amp;mode=region&amp;id_country='.$id_country.'&amp;', $col, $start, $count_p); ?>
<?php } else { ?>
<div style="text-align: center;">Регионов нет</div>
<?php } ?>
<div style="padding-top: 10px;">
<a id="menu_add" href="javascript:void(0)" onclick="javascript:menu_add_region()">[добавить новые регионы]</a>
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#menu_add_region").hide();
});
function menu_add_region() {
   $("#menu_add_region").show();
   $("#menu_add").hide();
}

function edit_region(rid) {
     $.arcticmodal({
     type: 'ajax',
     url: 'moduls/edit_region.php',
     ajax: {
          type: 'POST',
          data: { auth_admin: <?php echo $_SESSION['auth_admin']; ?>, rid: rid },
          dataType: 'html',
          success: function(data, el, responce) {
               var h = $(responce);
               $('B', h).html(responce.title);
               $('P:last', h).html(responce.text);
               data.body.html(h);
          }
     }
});
}
</script>
<div id="menu_add_region" style="padding-top: 20px;">
<div id="status_add_region" style="padding: 5px 0; text-align: center;"></div>
Добавить новые регионы (новый регион - с новой строки):<br/>
<textarea class="textarea" id="name_region" style="width: 200px; max-width: 400px; min-width: 400px; height: 200px; padding: 10px;"></textarea>
<div style="padding-top: 8px;">
<input type="submit" class="submit" id="add_region" value="Отправить" />
</div>
<script type="text/javascript">
	      $(document).ready(function() {
	           $('#add_region').click(function() {
		        var name_region = $('#name_region').val();
			if (name_region != '') {
			$.ajax({
			type: "POST",
			url: "moduls/add_region.php",
			data: { auth_admin: <?php echo $_SESSION['auth_admin']; ?>, id_country: <?php echo $id_country; ?>, name_region: name_region },
			beforeSend: function() {
			     $("#status_add_region").html('<img src="../images/ajax.gif" alt="" />');
			},
			success: function(data) {
			     $("#status_add_region").html(data);
			     document.getElementById('name_region').value = '';
			},
			error: function() {
			     $("#status_add_region").html('<span class="red">Произошла неизвестная ошибка.' + '<br/>' + 'Возможно, проблемы с подключением к интернету.</span>');
			}
			});
			}
		   });
	      });
</script>
</div>
</div>
<?php
break;

case 'city':
?>
<?php
$id_country = intval($_GET['id_country']);
$sql = mysql_query("SELECT * FROM `q_country` WHERE `id_country` = '".$id_country."' LIMIT 1;");
if (mysql_num_rows($sql) == 0) {
echo '<script type="text/javascript">location="apanel.php";</script>';
}

$id_region = intval($_GET['id_region']);
$q = mysql_query("SELECT * FROM `q_region` WHERE `id_region` = '".$id_region."' AND `id_country` = '".$id_country."' LIMIT 1;");
if (mysql_num_rows($q) == 0) {
echo '<script type="text/javascript">location="apanel.php";</script>';
}

$array_country = mysql_fetch_array($sql);
$array_region = mysql_fetch_array($q);
?>
<div style="padding-top: 10px;">Страна: <strong><?php echo htmlspecialchars($array_country['name_country'], ENT_QUOTES); ?></strong></div>
<div style="padding-top: 2px;">Регион: <strong><?php echo htmlspecialchars($array_region['name_region'], ENT_QUOTES); ?></strong></div>
<div style="padding-top: 10px;">
<h4>Города</h4>
<?php
$col = 50;
if (isset($_GET['start'])) $start = abs(intval($_GET['start']));
else $start = 0;
$count_p = mysql_result(mysql_query("SELECT COUNT(*) FROM `q_city` WHERE `id_country` = '".$id_country."' AND `id_region` = '".$id_region."';"), 0);
if ($count_p > 0) {
if ($start >= $count_p) $start = 0;
$q = mysql_query("SELECT * FROM `q_city` WHERE `id_country` = '".$id_country."' AND `id_region` = '".$id_region."' ORDER BY `name_city` ASC LIMIT ".$start.", ".$col);
$i = 1;
?>
<?php while ($array = mysql_fetch_array($q)) { ?>
<?php echo htmlspecialchars($array['name_city'], ENT_QUOTES); ?> [<a class="red" href="javascript:void(0)" onclick="javascript:edit_city('<?php echo $array['id_city']; ?>')">ред.</a>]<br/>
<?php } ?>
<?php function_page($_SERVER['PHP_SELF'].'?page=city&amp;mode=city&amp;id_country='.$id_country.'&amp;id_region='.$id_region.'&amp;', $col, $start, $count_p); ?>
<?php } else { ?>
<div style="text-align: center;">Городов нет</div>
<?php } ?>
<div style="padding-top: 10px;">
<a id="menu_add" href="javascript:void(0)" onclick="javascript:menu_add_city()">[добавить новые города]</a>
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#menu_add_city").hide();
});
function menu_add_city() {
   $("#menu_add_city").show();
   $("#menu_add").hide();
}

function edit_city(gid) {
     $.arcticmodal({
     type: 'ajax',
     url: 'moduls/edit_city.php',
     ajax: {
          type: 'POST',
          data: { auth_admin: <?php echo $_SESSION['auth_admin']; ?>, gid: gid },
          dataType: 'html',
          success: function(data, el, responce) {
               var h = $(responce);
               $('B', h).html(responce.title);
               $('P:last', h).html(responce.text);
               data.body.html(h);
          }
     }
});
}
</script>
<div id="menu_add_city" style="padding-top: 20px;">
<div id="status_add_city" style="padding: 5px 0; text-align: center;"></div>
Добавить новые города (новый город - с новой строки):<br/>
<textarea class="textarea" id="name_city" style="width: 200px; max-width: 400px; min-width: 400px; height: 200px; padding: 10px;"></textarea>
<div style="padding-top: 8px;">
<input type="submit" class="submit" id="add_city" value="Отправить" />
</div>
<script type="text/javascript">
	      $(document).ready(function() {
	           $('#add_city').click(function() {
		        var name_city = $('#name_city').val();
			if (name_city != '') {
			$.ajax({
			type: "POST",
			url: "moduls/add_city.php",
			data: { auth_admin: <?php echo $_SESSION['auth_admin']; ?>, id_country: <?php echo $id_country; ?>, id_region: <?php echo $id_region; ?>, name_city: name_city },
			beforeSend: function() {
			     $("#status_add_city").html('<img src="../images/ajax.gif" alt="" />');
			},
			success: function(data) {
			     $("#status_add_city").html(data);
			     document.getElementById('name_city').value = '';
			},
			error: function() {
			     $("#status_add_city").html('<span class="red">Произошла неизвестная ошибка.' + '<br/>' + 'Возможно, проблемы с подключением к интернету.</span>');
			}
			});
			}
		   });
	      });
</script>
</div>
</div>
<?php
break;

default:
?>
<div style="padding-top: 10px;">
<h4>Страны</h4>
<?php
$col = 50;
if (isset($_GET['start'])) $start = abs(intval($_GET['start']));
else $start = 0;
$count_p = mysql_result(mysql_query("SELECT COUNT(*) FROM `q_country`;"), 0);
if ($count_p > 0) {
if ($start >= $count_p) $start = 0;
$q = mysql_query("SELECT * FROM `q_country` ORDER BY `name_country` ASC LIMIT ".$start.", ".$col);
$i = 1;
?>
<?php while ($array = mysql_fetch_array($q)) { ?>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?page=city&amp;mode=region&amp;id_country=<?php echo $array['id_country']; ?>"><?php echo htmlspecialchars($array['name_country'], ENT_QUOTES); ?></a> [<a class="red" href="javascript:void(0)" onclick="javascript:edit_country('<?php echo $array['id_country']; ?>')">ред.</a>]<br/>
<?php } ?>
<?php function_page($_SERVER['PHP_SELF'].'?page=city&amp;mode=country&amp;', $col, $start, $count_p); ?>
<?php } else { ?>
<div style="text-align: center;">Стран нет</div>
<?php } ?>
<div style="padding-top: 10px;">
<a id="menu_add" href="javascript:void(0)" onclick="javascript:menu_add_country()">[добавить новые страны]</a>
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#menu_add_country").hide();
});

function menu_add_country() {
   $("#menu_add_country").show();
   $("#menu_add").hide();
}

function edit_country(cid) {
     $.arcticmodal({
     type: 'ajax',
     url: 'moduls/edit_country.php',
     ajax: {
          type: 'POST',
          data: { auth_admin: <?php echo $_SESSION['auth_admin']; ?>, cid: cid },
          dataType: 'html',
          success: function(data, el, responce) {
               var h = $(responce);
               $('B', h).html(responce.title);
               $('P:last', h).html(responce.text);
               data.body.html(h);
          }
     }
});
}
</script>
<div id="menu_add_country" style="padding-top: 20px;">
<div id="status_add_country" style="padding: 5px 0; text-align: center;"></div>
Добавить новые страны (новая страна - с новой строки):<br/>
<textarea class="textarea" id="name_country" style="width: 200px; max-width: 400px; min-width: 400px; height: 200px; padding: 10px;"></textarea>
<div style="padding-top: 8px;">
<input type="submit" class="submit" id="add_country" value="Отправить" />
</div>
<script type="text/javascript">
	      $(document).ready(function() {
	           $('#add_country').click(function() {
		        var name_country = $('#name_country').val();
		        if (name_country != '') {
			$.ajax({
			type: "POST",
			url: "moduls/add_country.php",
			data: { auth_admin: <?php echo $_SESSION['auth_admin']; ?>, name_country: name_country },
			beforeSend: function() {
			     $("#status_add_country").html('<img src="../images/ajax.gif" alt="" />');
			},
			success: function(data) {
			     $("#status_add_country").html(data);
			     document.getElementById('name_country').value = '';
			},
			error: function() {
			     $("#status_add_country").html('<span class="red">Произошла неизвестная ошибка.' + '<br/>' + 'Возможно, проблемы с подключением к интернету.</span>');
			}
			});
			}
		   });
	      });
</script>
</div>
</div>
<?php
break;
}
?>