Просмотр файла pages/anketa.php

Размер файла: 6.83Kb
  1. <?php
  2. include '../engine/includes/start.php';
  3. if (!$user_id)
  4. Core::stop();
  5.  
  6. $set['title'] = 'Изменение данных';
  7.  
  8. include H.'engine/includes/head.php';
  9.  
  10. if (isset($_POST['edit']))
  11. {
  12. if (!empty($_FILES['avatar']['tmp_name']))
  13. {
  14. Core::get('class_upload');
  15. $handle = new upload($_FILES['avatar']);
  16. if ($handle->uploaded)
  17. {
  18. $handle->file_new_name_body = $user_id;
  19. $handle->allowed = array('image/jpeg', 'image/gif', 'image/png');
  20. $handle->file_overwrite = true;
  21. $handle->image_resize = true;
  22. $handle->image_x = 100;
  23. $handle->image_ratio_y = true;
  24. $handle->image_convert = 'jpg';
  25. $handle->process(H . 'style/users/avatar/');
  26. if ($handle->processed) {
  27. echo '<div class="msg">Аватар добавлен</div>';
  28. }
  29. else
  30. echo '<div class="err">Проблема с загрузкой: ' . $handle->error . '</div>';
  31. }
  32. }
  33.  
  34. # Имя
  35. if ($user['ank_name'] != $_POST['name'])
  36. {
  37. if (preg_match('#^([A-zА-я \-]*)$#ui', $_POST['name']))
  38. {
  39. $name = my_esc($_POST['name'], 'true');
  40. $sql->query("UPDATE `user` SET `ank_name` = '$name' WHERE `id` = '$user_id'");
  41. }
  42. else
  43. Core::msg_show('Не верный формат имени');
  44. }
  45.  
  46. # Пол
  47. if ($user['pol'] != $_POST['sex'])
  48. {
  49. $sex = intval($_POST['sex']);
  50. $sql->query("UPDATE `user` SET `pol` = '$sex' WHERE `id` = '$user_id'");
  51. }
  52.  
  53. # Город
  54. if ($user['ank_city'] != $_POST['city'])
  55. {
  56. if (preg_match('#^([A-zА-я \-]*)$#ui', $_POST['city']))
  57. {
  58. $city = my_esc($_POST['city'], 'true');
  59. $sql->query("UPDATE `user` SET `ank_city` = '$city' WHERE `id` = '$user_id'");
  60. }
  61. else
  62. Core::msg_show('Не верный формат города');
  63. }
  64.  
  65. # Дата рождения
  66. if ($user['ank_d_r'] != $_POST['day'] || $user['ank_m_r'] != $_POST['month'] || $user['ank_g_r'] != $_POST['year'])
  67. {
  68. if (is_numeric($_POST['day']) && is_numeric($_POST['month']) && is_numeric($_POST['year']) && $_POST['day'] <= 31 && $_POST['month'] <= 12 && $_POST['year'] <= 2013)
  69. {
  70. $day = intval($_POST['day']);
  71. $month = intval($_POST['month']);
  72. $year = intval($_POST['year']);
  73. $sql->query("UPDATE `user` SET `ank_d_r` = '$day', `ank_m_r` = '$month', `ank_g_r` = '$year' WHERE `id` = '$user_id'");
  74. }
  75. else
  76. Core::msg_show('Не правильно введена дата рождения');
  77. }
  78.  
  79. # Icq
  80. if ($user['ank_icq'] != $_POST['icq'])
  81. {
  82. if (is_numeric($_POST['icq']))
  83. {
  84. $icq = intval($_POST['icq']);
  85. $sql->query("UPDATE `user` SET `ank_icq` = '$icq' WHERE `id` = '$user_id'");
  86. }
  87. else
  88. Core::msg_show('Не верный формат icq');
  89. }
  90.  
  91. # E-mail
  92. if ($user['ank_mail'] != $_POST['email'])
  93. {
  94. if (preg_match('#^[A-z0-9-\._]+@[A-z0-9]{2,}\.[A-z]{2,4}$#ui',$_POST['email']))
  95. {
  96. $user['ank_mail'] = my_esc($_POST['email']);
  97. if ($sql->query("select count(*) from `user` where `ank_mail` = '".$user['ank_mail']."' and `id` <> ".$user_id)->result())
  98. Core::msg_show('Данный e-mail занят');
  99. else
  100. $sql->query("UPDATE `user` SET `ank_mail` = '".$user['ank_mail']."' WHERE `id` = ".$user_id);
  101. }
  102. else
  103. Core::msg_show('Не верный формат E-mail');
  104. }
  105.  
  106. # Номер телефона
  107. if ($user['ank_n_tel'] != $_POST['num_phone'])
  108. {
  109. if (is_numeric($_POST['num_phone']) && strlen($_POST['num_phone']) >= 5 && strlen($_POST['num_phone']) <= 11)
  110. {
  111. $user['num_phone'] = intval($_POST['num_phone']);
  112.  
  113. if ($sql->query("select count(*) from `user` where `ank_n_tel` = '".$user['num_phone']."' and `id` <> ".$user_id)->result())
  114. Core::msg_show('Данный номер телефона занят');
  115. else
  116. $sql->query("UPDATE `user` SET `ank_n_tel` = '".$user['num_phone']."' WHERE `id` = ".$user_id);
  117. }
  118. else
  119. Core::msg_show('Не верный формат номера телефона');
  120. }
  121.  
  122. # О себе
  123. if ($user['ank_o_sebe'] != $_POST['about'])
  124. {
  125. $user['about'] = my_esc($_POST['about'], true);
  126. $sql->query("UPDATE `user` SET `ank_o_sebe` = '".$user['about']."' WHERE `id` = ".$user_id);
  127. }
  128. $user = Core::get_user($user_id, true);
  129. if (file_exists(tmpDir . 'user[id='.$user_id.'].swc'))
  130. unlink(tmpDir . 'user[id='.$user_id.'].swc');
  131. //Core::get('cache.class');
  132. //Cache::multi_delete('user[id='.$user_id);
  133.  
  134. Core::msg_show('Данные успешно изменены<br /><div class="menu"><a href="anketa.php">Редактировать еще</a><br /><a href="user.php?id='.$user_id.'">Посмотреть анкету</a></div>','msg');
  135. include H.'engine/includes/foot.php';
  136. }
  137.  
  138.  
  139. ?>
  140. <form method="POST" enctype="multipart/form-data">
  141. Аватар:<br />
  142. <?=Core::user_avatar()?><br />
  143. <input type="file" name="avatar"/><br />
  144.  
  145. Имя:<br />
  146. <input type="text" name="name" value="<?=$user['ank_name']?>" /><br />
  147. Пол:<br />
  148. <select name="sex">
  149. <option value="1">Мужской</option>
  150. <option value="0" <?=$user['pol'] == 0 ? 'selected="selected"': ''?>>Женский</option>
  151. </select><br />
  152. Город:<br />
  153. <input type="text" name="city" value="<?=$user['ank_city']?>" /><br />
  154. Дата рождения <small>(день/месяц/год)</small>:<br />
  155. <input type="text" name="day" size="1" value="<?=$user['ank_d_r']?>" />&nbsp;.&nbsp;<input type="text" name="month" size="1" value="<?=$user['ank_m_r']?>" />&nbsp;.&nbsp;<input type="text" name="year" size="1" value="<?=$user['ank_g_r']?>" /><br />
  156. Icq:<br />
  157. <input type="text" name="icq" value="<?=$user['ank_icq']?>" /><br />
  158. E-mail:<br />
  159. <input type="text" name="email" value="<?=$user['ank_mail']?>" /><br />
  160. Номер телефона:<br />
  161. <input type="text" name="num_phone" value="<?=$user['ank_n_tel']?>" /><br />
  162. О себе:<br />
  163. <textarea name="about"><?=$user['ank_o_sebe']?></textarea><br />
  164. <input type="submit" name="edit" value="Изменить" />
  165. </form>
  166. <a href="user.php"><div class="link">Анкета</div></a>
  167. <a href="menu.php"><div class="link">Кабинет</div></a>
  168. <a href="/"><div class="link">Главная</div></a>
  169. <?
  170. include H.'engine/includes/foot.php';