PageRenderTime 51ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/my.invitations.php

https://bitbucket.org/DESURE/dcms
PHP | 144 lines | 121 code | 21 blank | 2 comment | 21 complexity | c0325c1fd7ccd8cc52dd934acd917878 MD5 | raw file
  1. <?php
  2. include_once 'sys/inc/start.php';
  3. $doc = new document(1);
  4. $doc->title = __('???????????????');
  5. if (isset($_GET['id'])) {
  6. $id_inv = (int) $_GET['id'];
  7. $q = mysql_query("SELECT * FROM `invations` WHERE `id` = '$id_inv' AND `id_user` = '$user->id' AND `id_invite` IS NULL LIMIT 1");
  8. if (!mysql_num_rows($q)) {
  9. header('Refresh: 1; url=?');
  10. $design->err(__('??????????????? ?? ??????'));
  11. $design->ret(__('? ???????????????'), '?');
  12. $design->head($title); // ????? ????????
  13. $design->title($title); // ????????? ????????
  14. $design->foot(); // ????
  15. exit;
  16. }
  17. $inv = mysql_fetch_assoc($q);
  18. if (isset($_POST['delete']) && $inv['time_reg'] < TIME - 86400) {
  19. mysql_query("DELETE FROM `invations` WHERE `id` = '$inv[id]' LIMIT 1");
  20. header('Refresh: 1; url=?');
  21. $doc->msg(__('??????????????? ??????? ??????'));
  22. $doc->ret(__('? ???????????????'), '?');
  23. exit;
  24. }
  25. if (isset($_POST['email']) && !$inv['email']) {
  26. if (!is_valid::mail($_POST['email']))
  27. $doc->err(__('?????? ?? ?????????? E-mail'));
  28. else {
  29. $email = $_POST['email'];
  30. $inv['code'] = passgen();
  31. $t = new design();
  32. $t->assign('title', __('???????????????'));
  33. $t->assign('login', $user->login);
  34. $t->assign('site', $dcms->sitename);
  35. $t->assign('url', 'http://' . $_SERVER['HTTP_HOST'] . '/reg.php?invite=' . $inv['code']);
  36. if (mail::send($email, __('???????????'), $t->fetch('file:' . H . '/sys/templates/mail.invite.tpl'))) {
  37. mysql_query("UPDATE `invations` SET `email` = '" . my_esc($email) . "', `time_reg` = '" . TIME . "', `code` = '$inv[code]' WHERE `id` = '$inv[id]' LIMIT 1");
  38. header('Refresh: 1; url=?');
  39. $doc->msg(__('??????????????? ??????? ?????????'));
  40. $doc->ret(__('? ???????????????'), '?');
  41. exit;
  42. } else
  43. $doc->err(__('?????? ??? ???????? email, ?????????? ?????'));
  44. }
  45. }
  46. $doc->title = __("??????????????? #%s", $inv['id']);
  47. $doc->ret(__('? ???????????????'), '?');
  48. if ($inv['email']) {
  49. echo __('??????????????? ????????? ?? email: %s', $inv['email']) . "<br />";
  50. echo __("?????????: %s", vremja($inv['time_reg'])) . "<br />";
  51. if ($inv['time_reg'] < TIME - 86400) {
  52. if (isset($_GET['delete'])) {
  53. $smarty = new design();
  54. $smarty->assign('method', 'post');
  55. $smarty->assign('action', "?id=$inv[id]");
  56. $elements = array();
  57. $elements[] = array('type' => 'text', 'br' => 1, 'value' => __('??????????? ???????? ????????????????'));
  58. $elements[] = array('type' => 'text', 'br' => 1, 'value' => __('??? ????? ?????? ????? ???????????????'));
  59. $elements[] = array('type' => 'submit', 'br' => 0, 'info' => array('name' => 'delete', 'value' => __('???????'))); // ??????
  60. $smarty->assign('el', $elements);
  61. $smarty->display('input.form.tpl');
  62. }
  63. $doc->act(__('??????? ???????????'), "?id=$inv[id]&amp;delete");
  64. } else {
  65. echo __("? ?????? ?????? ??? ?????? ?? ???????????????? ??? ????? ????? ??????? ?? ????????? ????? ? ??????? ????????");
  66. }
  67. } else {
  68. $smarty = new design();
  69. $smarty->assign('method', 'post');
  70. $smarty->assign('action', "?id=$inv[id]");
  71. $elements = array();
  72. $elements[] = array('type' => 'input_text', 'br' => 1, 'title' => __('Email'), 'info' => array('name' => 'email', 'value' => ''));
  73. $elements[] = array('type' => 'submit', 'br' => 0, 'info' => array('value' => __('?????????'))); // ??????
  74. $smarty->assign('el', $elements);
  75. $smarty->display('input.form.tpl');
  76. }
  77. exit;
  78. }
  79. $k_inv = (int) ($user->balls / $dcms->balls_for_invite); // ?????????? ???????????????
  80. $doc->msg(__("? ??? %s ??????????????" . misc::number($k_inv, '?', 'x', '?'), $k_inv), 'invations');
  81. $k = mysql_result(mysql_query("SELECT COUNT(*) FROM `invations` WHERE `id_user` = '$user->id'"), 0);
  82. if ($k_inv > $k) {
  83. // ????????? ?????? ??????????????
  84. $k_add = $k_inv - $k;
  85. $arr_ins = array();
  86. for ($i = 0; $i < $k_add; $i++)
  87. $arr_ins[] = "('$user->id')";
  88. mysql_query("INSERT INTO `invations` (`id_user`) VALUES " . implode(',', $arr_ins));
  89. }
  90. $pages = new pages;
  91. $pages->posts = mysql_result(mysql_query("SELECT COUNT(*) FROM `invations` WHERE `id_user` = '$user->id'"), 0); // ?????????? ???????????????
  92. $pages->this_page(); // ???????? ??????? ????????
  93. $q = mysql_query("SELECT * FROM `invations` WHERE `id_user` = '$user->id' ORDER BY (`id_invite` IS NULL) DESC, (`email` IS NULL) ASC, `id` ASC LIMIT $pages->limit");
  94. $listing = new listing();
  95. while ($inv = mysql_fetch_assoc($q)) {
  96. $post = $listing->post();
  97. $post->icon('invite');
  98. if ($inv['id_invite']) {
  99. $ank = new user($inv['id_invite']);
  100. $post->time = vremja($inv['time_reg']);
  101. $post->content = __('???????????');
  102. $post->title = $ank->nick();
  103. $post->url = '/profile.view.php?id=' . $ank->id;
  104. } elseif ($inv['email']) {
  105. $post->url = '?id=' . $inv['id'];
  106. $post->title = __('??????????????? #%s', $inv['id']);
  107. $post->content = __('????????? ?? email: %s', $inv['email']) . '<br />';
  108. if (!$inv['code']) {
  109. $post->content .= __('???????????');
  110. }
  111. if ($inv['time_reg'] < TIME - 86400) {
  112. // 86400 ?????? = 1 ????? - ?????, ????? ??????? ????? ?????????????? ???????????????? ???????????????
  113. $post->action('delete', "?id={$inv['id']}&amp;delete");
  114. }
  115. } else {
  116. $post->title = "<a href='?id=$inv[id]'>" . __('??????????????? #%s', $inv['id']) . "</a>";
  117. $post->content = __('?? ???????????');
  118. }
  119. }
  120. $listing->display(__('?????? ??????????????? ????'));
  121. $pages->display('?'); // ????? ???????
  122. $doc->ret(__('?????? ????'), '/menu.user.php');
  123. ?>