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

Размер файла: 8.07Kb
  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. $sql->query('UPDATE `user` SET `gravatar` = "no" WHERE `id` = '.$user_id);
  29. }
  30. else
  31. echo '<div class="err">Проблема с загрузкой: ' . $handle->error . '</div>';
  32. }
  33. }
  34.  
  35. # Имя
  36. if ($user['ank_name'] != $_POST['name'])
  37. {
  38. if (preg_match('#^([A-zА-я \-]*)$#ui', $_POST['name']))
  39. {
  40. $name = my_esc($_POST['name'], 'true');
  41. $sql->query("UPDATE `user` SET `ank_name` = '$name' WHERE `id` = '$user_id'");
  42. }
  43. else
  44. Core::msg_show('Не верный формат имени');
  45. }
  46.  
  47. # Пол
  48. if ($user['pol'] != $_POST['sex'])
  49. {
  50. $sex = intval($_POST['sex']);
  51. $sql->query("UPDATE `user` SET `pol` = '$sex' WHERE `id` = '$user_id'");
  52. }
  53.  
  54. # Город
  55. if ($user['ank_city'] != $_POST['city'])
  56. {
  57. if (preg_match('#^([A-zА-я \-]*)$#ui', $_POST['city']))
  58. {
  59. $city = my_esc($_POST['city'], 'true');
  60. $sql->query("UPDATE `user` SET `ank_city` = '$city' WHERE `id` = '$user_id'");
  61. }
  62. else
  63. Core::msg_show('Не верный формат города');
  64. }
  65.  
  66. # Дата рождения
  67. if ($user['ank_d_r'] != $_POST['day'] || $user['ank_m_r'] != $_POST['month'] || $user['ank_g_r'] != $_POST['year'])
  68. {
  69. if (is_numeric($_POST['day']) && is_numeric($_POST['month']) && is_numeric($_POST['year']) && $_POST['day'] <= 31 && $_POST['month'] <= 12 && $_POST['year'] <= 2013)
  70. {
  71. $day = intval($_POST['day']);
  72. $month = intval($_POST['month']);
  73. $year = intval($_POST['year']);
  74. $sql->query("UPDATE `user` SET `ank_d_r` = '$day', `ank_m_r` = '$month', `ank_g_r` = '$year' WHERE `id` = '$user_id'");
  75. }
  76. else
  77. Core::msg_show('Не правильно введена дата рождения');
  78. }
  79.  
  80. # Icq
  81. if ($user['ank_icq'] != $_POST['icq'])
  82. {
  83. if (is_numeric($_POST['icq']))
  84. {
  85. $icq = intval($_POST['icq']);
  86. $sql->query("UPDATE `user` SET `ank_icq` = '$icq' WHERE `id` = '$user_id'");
  87. }
  88. else
  89. Core::msg_show('Не верный формат icq');
  90. }
  91.  
  92. # E-mail
  93. if ($user['ank_mail'] != $_POST['email'])
  94. {
  95. if (preg_match('#^[A-z0-9-\._]+@[A-z0-9]{2,}\.[A-z]{2,4}$#ui',$_POST['email']))
  96. {
  97. $user['ank_mail'] = my_esc($_POST['email']);
  98. if ($sql->query("select count(*) from `user` where `ank_mail` = '".$user['ank_mail']."' and `id` <> ".$user_id)->result())
  99. Core::msg_show('Данный e-mail занят');
  100. else
  101. $sql->query("UPDATE `user` SET `ank_mail` = '".$user['ank_mail']."' WHERE `id` = ".$user_id);
  102. }
  103. else
  104. Core::msg_show('Не верный формат E-mail');
  105. }
  106.  
  107. # Номер телефона
  108. if ($user['ank_n_tel'] != $_POST['num_phone'])
  109. {
  110. if (is_numeric($_POST['num_phone']) && strlen($_POST['num_phone']) >= 5 && strlen($_POST['num_phone']) <= 11)
  111. {
  112. $user['num_phone'] = intval($_POST['num_phone']);
  113.  
  114. if ($sql->query("select count(*) from `user` where `ank_n_tel` = '".$user['num_phone']."' and `id` <> ".$user_id)->result())
  115. Core::msg_show('Данный номер телефона занят');
  116. else
  117. $sql->query("UPDATE `user` SET `ank_n_tel` = '".$user['num_phone']."' WHERE `id` = ".$user_id);
  118. }
  119. else
  120. Core::msg_show('Не верный формат номера телефона');
  121. }
  122.  
  123. # О себе
  124. if ($user['ank_o_sebe'] != $_POST['about'])
  125. {
  126. $user['about'] = my_esc($_POST['about'], true);
  127. $sql->query("UPDATE `user` SET `ank_o_sebe` = '".$user['about']."' WHERE `id` = ".$user_id);
  128. }
  129. $user = Core::get_user($user_id, true);
  130. if (file_exists(tmpDir . 'user[id='.$user_id.'].swc'))
  131. unlink(tmpDir . 'user[id='.$user_id.'].swc');
  132. //Core::get('cache.class');
  133. //Cache::multi_delete('user[id='.$user_id);
  134.  
  135. Core::msg_show('Данные успешно изменены<br /><div class="menu"><a href="anketa.php">Редактировать еще</a><br /><a href="user.php?id='.$user_id.'">Посмотреть анкету</a></div>','msg');
  136. include H.'engine/includes/foot.php';
  137. }
  138.  
  139. if ($user['gravatar'] == 'no' && !empty($user['ank_mail']))
  140. {
  141. $gravatar_url = 'http://www.gravatar.com/avatar/' . md5(strtolower($user['ank_mail'])) . '?d=404';
  142. $headers = get_headers($gravatar_url);
  143. if ($headers[0] != 'HTTP/1.0 404 Not Found')
  144. {
  145. if ($act == 'use_gravatar')
  146. {
  147. $sql->query('UPDATE `user` SET `gravatar` = "yes" WHERE `id` = '.$user_id);
  148. $user = Core::get_user($user_id, true);
  149. Core::msg_show('Новая аватарка применена, обновите кеш', 'msg');
  150. file_put_contents(H. 'style/users/avatar/'.$user_id.'.jpg', file_get_contents('http://www.gravatar.com/avatar/' . md5(strtolower($user['ank_mail'])).'?s=100&amp;d=identicon'));
  151. }
  152. else
  153. {
  154. echo 'У Вас есть изображение на Gravatar, <a href="?act=use_gravatar">использовать его как аватар</a>?<br /> <img src="http://www.gravatar.com/avatar/' . md5(strtolower($user['ank_mail'])).'?s=100&amp;d=identicon" alt="" />';
  155. }
  156. }
  157. }
  158. ?>
  159. <form method="POST" enctype="multipart/form-data">
  160. Аватар:<br />
  161. <?=Core::user_avatar()?><br />
  162. <input type="file" name="avatar"/><br />
  163.  
  164. Имя:<br />
  165. <input type="text" name="name" value="<?=$user['ank_name']?>" /><br />
  166. Пол:<br />
  167. <select name="sex">
  168. <option value="1">Мужской</option>
  169. <option value="0" <?=$user['pol'] == 0 ? 'selected="selected"': ''?>>Женский</option>
  170. </select><br />
  171. Город:<br />
  172. <input type="text" name="city" value="<?=$user['ank_city']?>" /><br />
  173. Дата рождения <small>(день/месяц/год)</small>:<br />
  174. <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 />
  175. Icq:<br />
  176. <input type="text" name="icq" value="<?=$user['ank_icq']?>" /><br />
  177. E-mail:<br />
  178. <input type="text" name="email" value="<?=$user['ank_mail']?>" /><br />
  179. Номер телефона:<br />
  180. <input type="text" name="num_phone" value="<?=$user['ank_n_tel']?>" /><br />
  181. О себе:<br />
  182. <textarea name="about"><?=$user['ank_o_sebe']?></textarea><br />
  183. <input type="submit" name="edit" value="Изменить" />
  184. </form>
  185. <a href="user.php"><div class="link">Анкета</div></a>
  186. <a href="menu.php"><div class="link">Кабинет</div></a>
  187. <a href="/"><div class="link">Главная</div></a>
  188. <?
  189. include H.'engine/includes/foot.php';