View file apanel/moduls/edit_city.php

File size: 5.31Kb
<?php
/**********************************************/
/* Автор скрипта: Александр Есин              */
/* E-Mail: [email protected] ([email protected]) */
/* ICQ: 6464729                               */
/* Site: http://ticlove.ru                    */
/**********************************************/
?>
<?php define ('SECURED', true); ?>
<?php require (dirname(__FILE__).'/../../_inc/sql.php'); ?>
<?php require (dirname(__FILE__).'/../../_inc/config.php'); ?>
<?php require (dirname(__FILE__).'/../../_inc/function.php'); ?>
<?php
	 if (!empty($_SESSION['auth_admin']) && (intval($_POST['auth_admin']) == $_SESSION['auth_admin']))
	 {
	      $gid = intval($_POST['gid']);
	      $sql = mysql_query("SELECT * FROM `q_city` WHERE `id_city` = '".$gid."' LIMIT 1;");
	      $array_city = mysql_fetch_array($sql);
	      
	      $page = isset($_GET['page']) ? $_GET['page'] : NULL;
	      switch($page)
	      {
	      case 'update':
	      $name_new_city = trim($_POST['name_new_city']);
	      if (empty($name_new_city))
	      {
	           echo '<span class="red">Введите название города</span>';
	      }
	      else
	      {
	      if (mysql_num_rows(mysql_query("SELECT * FROM `q_city` WHERE `id_city` <> '".$gid."' AND `name_city` = '".function_sql($name_new_city)."' LIMIT 1")) > 0)
	      {
	           echo '<span class="red">Такой город уже есть в БД</span>';
	      }
	      else
	      {
	           $name_new_city = iconv('utf-8', 'windows-1251', $name_new_city);
		   $name_new_city = ucfirst(strtolower($name_new_city));
		   $name_new_city = iconv('windows-1251', 'utf-8', $name_new_city);
		   
		   mysql_query("UPDATE `q_city` SET `name_city` = '".function_sql($name_new_city)."' WHERE `id_city` = '".$gid."';");
	           echo '<span class="green">Сохранено!</span>';
	      }
	      }
	      break;
	      
	      case 'delete':
	      mysql_query("DELETE FROM `q_city` WHERE `id_city` = '".$gid."';");
	      echo '<span class="green">Город удален</span>';
	      break;
	      
	      default:
	      ?>
	      <div class="box_bg" style="width: 370px;">
	      <div class="box_title">
	      <div class="left" style="padding-top: 2px; padding-left: 10px;">Редактирование города</div><div class="box_close right b-modal_close arcticmodal-close"></div>
	      </div>
	      <div class="clear"></div>
	      <div class="box_conetnt">
	      <div style="padding: 10px;">
	      <div id="status_edit_city" style="margin-bottom: 10px; font-size: 12px; text-align: center;"></div>
	      <div id="inp_city">
	      <div class="left" style="padding-top: 2px;">Название:</div>
	      <div class="left" style="padding-left: 10px;"><input class="input" type="text" id="name_edit_city" name="name_edit_city" maxlength="" value="<?php echo htmlspecialchars($array_city['name_city'], ENT_QUOTES); ?>" /> <a class="red" href="javascript:void(0)" id="delete_city">[удалить]</a></div>
	      <div class="clear"></div>
	      </div>
	      <script type="text/javascript">
	      $(document).ready(function() {
	           $("#menu_delete_city").hide();
		   
		   $('#name_edit_city').change(function() {
		      $.ajax({
			type: "POST",
			url: "moduls/edit_city.php?page=update",
			data: { auth_admin: <?php echo $_SESSION['auth_admin']; ?>, gid: <?php echo $gid; ?>, name_new_city: $('#name_edit_city').val() },
			success: function(data) {
			     $("#status_edit_city").fadeIn(700);
			     $("#status_edit_city").html(data);
			     $("#status_edit_city").fadeOut(700);
			}
			});
		   });
		   
		   
		   $('#delete_city').click(function() {
		      $("#inp_city").hide();
		      $("#menu_delete_city").show();
		   });
		   
		   
		   $('#delete_city_update').click(function() {
		      $.ajax({
			type: "POST",
			url: "moduls/edit_city.php?page=delete",
			data: { auth_admin: <?php echo $_SESSION['auth_admin']; ?>, gid: <?php echo $gid; ?> },
			beforeSend: function() {
			     $("#status_edit_city").html('<img src="../images/ajax.gif" alt="" />');
			},
			success: function(data) {
			     $("#status_edit_city").html(data);
			     setTimeout(function() {
			          $.arcticmodal('close')
			     }, 1000);
			},
			error: function() {
			     $("#status_edit_city").html('<span class="red">Произошла неизвестная ошибка.' + '<br/>' + 'Возможно, проблемы с подключением к интернету.</span>');
			}
			});
		   });
	      });
	      </script>
	      <div id="menu_delete_city" style="padding-top: 5px; text-align: center;">
	      Вы действительно хотите удалить город "<strong><?php echo htmlspecialchars($array_city['name_city'], ENT_QUOTES); ?></strong>"?<br/>
	      <a class="red" href="javascript:void(0)" id="delete_city_update">[удалить]</a> или <a class="b-modal_close arcticmodal-close" href="javascript:void(0)" id="delete_city_update">[отмена]</a>
	      </div>
	      </div>
	      </div>
	      <div class="box_footer">
	      <div class="right"><button class="submit_red b-modal_close arcticmodal-close">Отмена</button></div>
	      </div>
	      <div class="clear"></div>
	      </div>
	      <?php
	      break;
	      }
	 }
?>