View file moduls/edit_city.php

File size: 5.76Kb
<?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_id']) && (intval($_POST['user_id']) == $_SESSION['auth_id']))
	 {
	      $page = isset($_GET['page']) ? $_GET['page'] : NULL;
	      switch($page)
	      {
	      case 'update':
	      $country_id = intval($_POST['country']);
	      $region_id = intval($_POST['region']);
	      $city_id = intval($_POST['city']);
	      
	      $country_sql = mysql_query("SELECT * FROM `q_country` WHERE `id_country` = '".$country_id."' LIMIT 1");
	      $region_sql = mysql_query("SELECT * FROM `q_region` WHERE `id_region` = '".$region_id."' LIMIT 1");
	      $city_sql = mysql_query("SELECT * FROM `q_city` WHERE `id_city` = '".$city_id."' LIMIT 1");
	      
	      if (mysql_num_rows($country_sql) == 0) echo '<span class="red">Вы не выбрали страну в которой проживаете</span>';
	      else if (mysql_num_rows($region_sql) == 0) echo '<span class="red">Вы не выбрали регион в котором проживаете</span>';
	      else if (mysql_num_rows($city_sql) == 0) echo '<span class="red">Вы не выбрали город в котором проживаете</span>';
	      else
	      {
	           $country_array = mysql_fetch_array($country_sql);
		   $region_array = mysql_fetch_array($region_sql);
		   $city_array = mysql_fetch_array($city_sql);
	           
	           if (mysql_query("UPDATE `q_users` SET `country` = '".function_sql($country_array['name_country'])."', `region` = '".function_sql($region_array['name_region'])."', `city` = '".function_sql($city_array['name_city'])."' WHERE `id_user` = '".$_SESSION['auth_id']."';")) echo '<span class="green">Данные успешно сохранены!</span>';
	           echo '<script language="JavaScript" type="text/javascript">
		   <!--
		   location="/profile.php"
		   //-->
		   </script>';
	      }
	      break;
	      
	      default:
	      ?>
	      <div class="box_bg" style="width: 380px;">
	      <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_city" style="padding-bottom: 10px; text-align: center"></div>
	      <div style="margin-bottom: 5px;">
	      <div class="left" style="width: 80px;">Страна:</div>
	      <div class="left">
	      <select class="select" style="width:200px;" id="sel_country" onchange="javascript:select_region()">
	      <option value="">-- Выберите страну --</option>
	      <?php $res = mysql_query("SELECT * FROM `q_country` ORDER BY `name_country` ASC;"); ?>
	      <?php while ($row = mysql_fetch_assoc($res)) { ?>
	      <option value="<?php echo $row['id_country']; ?>"><?php echo htmlspecialchars($row['name_country'], ENT_QUOTES); ?></option>
	      <?php } ?>
	      </select>
	      </div>
	      <div class="clear"></div>
	      </div>
	      <div style="margin-bottom: 5px;">
	      <div class="left" style="width: 80px;">Регион:</div>
	      <div class="left">
	      <div id="select_region">
	      <select class="select" style="width:200px;" id="sel_region" disabled="disabled">
	      <option value="">-- Выберите регион --</option>
	      </select>
	      </div>
	      </div>
	      <div class="clear"></div>
	      </div>
	      <div style="margin-bottom: 5px;">
	      <div class="left" style="width: 80px;">Город:</div>
	      <div class="left">
	      <div id="select_city">
	      <select class="select" style="width:200px;" id="sel_city" disabled="disabled">
	      <option value="">-- Выберите город --</option>
	      </select>
	      </div>
	      </div>
	      <div class="clear"></div>
	      </div>
	      <div style="text-align: center; padding-top: 5px;">
	      <input type="submit" class="submit" id="update_city" value="Сохранить" />
	      </div>
	      <script type="text/javascript">
	      $(document).ready(function() {
	           $('#update_city').click(function() {
		        $.ajax({
			type: "POST",
			url: "http://<?php echo $_SERVER['HTTP_HOST']; ?>/moduls/edit_city.php?page=update",
			data: { user_id: <?php echo $_SESSION['auth_id']; ?>, country: $('#sel_country').val(), region: $('#sel_region').val(), city: $('#sel_city').val() },
			beforeSend: function() {
			     $("#status_city").html('<img src="http://<?php echo $_SERVER['HTTP_HOST']; ?>/images/ajax.gif" alt="" />');
			},
			success: function(data) {
			     $("#status_city").html(data);
			},
			error: function() {
			     $("#status_city").html('<span class="red">Произошла неизвестная ошибка.' + '<br/>' + 'Возможно, проблемы с подключением к интернету.</span>');
			}
			});
		   });
	      });
	      </script>
	      </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;
	      }
	 }
?>