/my.invitations.php
PHP | 144 lines | 121 code | 21 blank | 2 comment | 21 complexity | c0325c1fd7ccd8cc52dd934acd917878 MD5 | raw file
- <?php
- include_once 'sys/inc/start.php';
- $doc = new document(1);
- $doc->title = __('???????????????');
- if (isset($_GET['id'])) {
- $id_inv = (int) $_GET['id'];
- $q = mysql_query("SELECT * FROM `invations` WHERE `id` = '$id_inv' AND `id_user` = '$user->id' AND `id_invite` IS NULL LIMIT 1");
- if (!mysql_num_rows($q)) {
- header('Refresh: 1; url=?');
- $design->err(__('??????????????? ?? ??????'));
- $design->ret(__('? ???????????????'), '?');
- $design->head($title); // ????? ????????
- $design->title($title); // ????????? ????????
- $design->foot(); // ????
- exit;
- }
- $inv = mysql_fetch_assoc($q);
- if (isset($_POST['delete']) && $inv['time_reg'] < TIME - 86400) {
- mysql_query("DELETE FROM `invations` WHERE `id` = '$inv[id]' LIMIT 1");
- header('Refresh: 1; url=?');
- $doc->msg(__('??????????????? ??????? ??????'));
- $doc->ret(__('? ???????????????'), '?');
- exit;
- }
- if (isset($_POST['email']) && !$inv['email']) {
- if (!is_valid::mail($_POST['email']))
- $doc->err(__('?????? ?? ?????????? E-mail'));
- else {
- $email = $_POST['email'];
- $inv['code'] = passgen();
- $t = new design();
- $t->assign('title', __('???????????????'));
- $t->assign('login', $user->login);
- $t->assign('site', $dcms->sitename);
- $t->assign('url', 'http://' . $_SERVER['HTTP_HOST'] . '/reg.php?invite=' . $inv['code']);
- if (mail::send($email, __('???????????'), $t->fetch('file:' . H . '/sys/templates/mail.invite.tpl'))) {
- mysql_query("UPDATE `invations` SET `email` = '" . my_esc($email) . "', `time_reg` = '" . TIME . "', `code` = '$inv[code]' WHERE `id` = '$inv[id]' LIMIT 1");
- header('Refresh: 1; url=?');
- $doc->msg(__('??????????????? ??????? ?????????'));
- $doc->ret(__('? ???????????????'), '?');
- exit;
- } else
- $doc->err(__('?????? ??? ???????? email, ?????????? ?????'));
- }
- }
- $doc->title = __("??????????????? #%s", $inv['id']);
- $doc->ret(__('? ???????????????'), '?');
- if ($inv['email']) {
- echo __('??????????????? ????????? ?? email: %s', $inv['email']) . "<br />";
- echo __("?????????: %s", vremja($inv['time_reg'])) . "<br />";
- if ($inv['time_reg'] < TIME - 86400) {
- if (isset($_GET['delete'])) {
- $smarty = new design();
- $smarty->assign('method', 'post');
- $smarty->assign('action', "?id=$inv[id]");
- $elements = array();
- $elements[] = array('type' => 'text', 'br' => 1, 'value' => __('??????????? ???????? ????????????????'));
- $elements[] = array('type' => 'text', 'br' => 1, 'value' => __('??? ????? ?????? ????? ???????????????'));
- $elements[] = array('type' => 'submit', 'br' => 0, 'info' => array('name' => 'delete', 'value' => __('???????'))); // ??????
- $smarty->assign('el', $elements);
- $smarty->display('input.form.tpl');
- }
- $doc->act(__('??????? ???????????'), "?id=$inv[id]&delete");
- } else {
- echo __("? ?????? ?????? ??? ?????? ?? ???????????????? ??? ????? ????? ??????? ?? ????????? ????? ? ??????? ????????");
- }
- } else {
- $smarty = new design();
- $smarty->assign('method', 'post');
- $smarty->assign('action', "?id=$inv[id]");
- $elements = array();
- $elements[] = array('type' => 'input_text', 'br' => 1, 'title' => __('Email'), 'info' => array('name' => 'email', 'value' => ''));
- $elements[] = array('type' => 'submit', 'br' => 0, 'info' => array('value' => __('?????????'))); // ??????
- $smarty->assign('el', $elements);
- $smarty->display('input.form.tpl');
- }
- exit;
- }
- $k_inv = (int) ($user->balls / $dcms->balls_for_invite); // ?????????? ???????????????
- $doc->msg(__("? ??? %s ??????????????" . misc::number($k_inv, '?', 'x', '?'), $k_inv), 'invations');
- $k = mysql_result(mysql_query("SELECT COUNT(*) FROM `invations` WHERE `id_user` = '$user->id'"), 0);
- if ($k_inv > $k) {
- // ????????? ?????? ??????????????
- $k_add = $k_inv - $k;
- $arr_ins = array();
- for ($i = 0; $i < $k_add; $i++)
- $arr_ins[] = "('$user->id')";
- mysql_query("INSERT INTO `invations` (`id_user`) VALUES " . implode(',', $arr_ins));
- }
- $pages = new pages;
- $pages->posts = mysql_result(mysql_query("SELECT COUNT(*) FROM `invations` WHERE `id_user` = '$user->id'"), 0); // ?????????? ???????????????
- $pages->this_page(); // ???????? ??????? ????????
- $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");
- $listing = new listing();
- while ($inv = mysql_fetch_assoc($q)) {
- $post = $listing->post();
- $post->icon('invite');
- if ($inv['id_invite']) {
- $ank = new user($inv['id_invite']);
- $post->time = vremja($inv['time_reg']);
- $post->content = __('???????????');
- $post->title = $ank->nick();
- $post->url = '/profile.view.php?id=' . $ank->id;
- } elseif ($inv['email']) {
- $post->url = '?id=' . $inv['id'];
- $post->title = __('??????????????? #%s', $inv['id']);
- $post->content = __('????????? ?? email: %s', $inv['email']) . '<br />';
- if (!$inv['code']) {
- $post->content .= __('???????????');
- }
- if ($inv['time_reg'] < TIME - 86400) {
- // 86400 ?????? = 1 ????? - ?????, ????? ??????? ????? ?????????????? ???????????????? ???????????????
- $post->action('delete', "?id={$inv['id']}&delete");
- }
- } else {
- $post->title = "<a href='?id=$inv[id]'>" . __('??????????????? #%s', $inv['id']) . "</a>";
- $post->content = __('?? ???????????');
- }
- }
- $listing->display(__('?????? ??????????????? ????'));
- $pages->display('?'); // ????? ???????
- $doc->ret(__('?????? ????'), '/menu.user.php');
- ?>