Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var iarray = new Object();
  2. iarray.register_process = 0;
  3. iarray.login_process = 0;
  4. iarray.url_hash_loaded = 0;
  5. iarray.url_hash_last = false;
  6. iarray.order_node = false;
  7. iarray.order_game = false;
  8. iarray.services_avail = false;
  9. iarray.service_active = false;
  10. iarray.services = false;
  11. iarray.support_messages_t = false;
  12. iarray.current_page = 'main';
  13. iarray.support_active = false;
  14. iarray.support_reply = false;
  15.  
  16. $(document).ready(function() {
  17.     render_news();
  18.     account();
  19. });
  20.  
  21. function dateformat(date) {
  22.     var d = new Date(date);
  23.     return ('0' + d.getDate()).slice(-2) + "." + ('0' + (d.getMonth() + 1)).slice(-2) + "." + d.getFullYear();
  24. }
  25.  
  26. function post_auth_events() {}
  27.  
  28. function post_account_events() {
  29.     if (iarray.games && iarray.nodes) {
  30.         render_services();
  31.     } else {
  32.         render_tech();
  33.     }
  34.     render_support();
  35.     setInterval('render_support_q()', 5000);
  36. }
  37.  
  38. function post_tech_events() {
  39.     render_services();
  40. }
  41.  
  42. function post_services_events() {
  43.     render_preorders();
  44.     setInterval('render_service()', 5000);
  45.     if (iarray.user.ulevel == 2) {
  46.         $('.free').hide();
  47.         $('.services .title').html('Список серверов: <label class="link_s" onclick="$(\'.free\').show()">показать все</label>');
  48.     }
  49. }
  50.  
  51. $(window).on('hashchange', function() {
  52.     if (window.location.hash) {
  53.         var page = window.location.hash.replace('#', '');
  54.         if (page != '') {
  55.             switch (page) {
  56.                 case 'logout':
  57.                     logout();
  58.                     break;
  59.                 default:
  60.                     switch_panel(page);
  61.             }
  62.         }
  63.     }
  64. });
  65.  
  66. function switch_panel(page) {
  67.     if (page != '') {
  68.         iarray.current_page = page;
  69.  
  70.         $("#pages").children().hide();
  71.         if ($("." + page).length) {
  72.             document.title = $("." + page).find(".title").text() + " - SAMP-Host.Ru";
  73.             $("." + page).stop(true, true).fadeIn(300);
  74.         } else {
  75.             document.title = "Страница не найдена - SAMP-Host.Ru";
  76.             $(".404").stop(true, true).fadeIn(300);
  77.         }
  78.         $("#main_page").hide();
  79.         $(".advants").hide();
  80.         $("#about").hide();
  81.         $("#dynamic").show();
  82.  
  83.         switch (page) {
  84.             case 'main':
  85.                 $("#main_page").fadeIn(300);
  86.                 $(".advants").fadeIn(300);
  87.                 $("#about").fadeIn(300);
  88.                 $("#dynamic").hide();
  89.                 document.title = "Главная страница - SAMP-Host.Ru";
  90.                 break;
  91.             case 'order':
  92.                 if (iarray.user.auth) {
  93.                     iarray.service_active = false;
  94.                 } else {
  95.                     switch_panel('login');
  96.                     iarray.url_hash_last = page;
  97.                 }
  98.                 break;
  99.             case 'services':
  100.                 if (iarray.user.auth) {
  101.                     iarray.service_active = false;
  102.                 } else {
  103.                     switch_panel('login');
  104.                     iarray.url_hash_last = page;
  105.                 }
  106.                 break;
  107.             case 'support':
  108.                 if (iarray.user.auth) {
  109.                     iarray.service_active = false;
  110.                 } else {
  111.                     switch_panel('login');
  112.                     iarray.url_hash_last = page;
  113.                 }
  114.                 break;
  115.             case 'login':
  116.                 if (iarray.user.auth) {
  117.                     switch_panel('main');
  118.                     iarray.service_active = false;
  119.                 } else {
  120.  
  121.                 }
  122.                 break;
  123.             case 'register':
  124.                 if (iarray.user.auth) {
  125.                     iarray.service_active = false;
  126.                     switch_panel('main');
  127.                 } else {
  128.  
  129.                 }
  130.                 break;
  131.             case 'recovery':
  132.                 if (iarray.user.auth) {
  133.                     iarray.service_active = false;
  134.                     switch_panel('main');
  135.                 } else {
  136.  
  137.                 }
  138.                 break;
  139.         }
  140.     }
  141. }
  142.  
  143. function render_balance(balance) {
  144.     if (iarray.user) {
  145.         if (balance) {
  146.             iarray.user.balance = parseInt(iarray.user.balance) + parseInt(balance);
  147.         }
  148.         $("#profile_balance").text(iarray.user.balance + " руб.");
  149.         $(".timer").html(iarray.user.balance + " руб. - <a href='#pay'>Пополнить</a>");
  150.     }
  151. }
  152.  
  153. function pay() {
  154.     $.post(
  155.         "/includes/back.php?func=pay", {
  156.             sum: $("#pay_sum").val()
  157.         },
  158.         function(info) {
  159.             if (info.success == 1) {
  160.                 var payment = new UnitPay();
  161.                 payment.createWidget({
  162.                     publicKey: "101721-b881b",
  163.                     sum: info.payment.sum,
  164.                     account: info.payment.id,
  165.                     desc: "Оплата платежа #" + info.payment.id,
  166.                     locale: "ru",
  167.                 });
  168.  
  169.                 payment.success(function(params) {
  170.                     render_balance(info.payment.sum);
  171.                 });
  172.  
  173.             } else {
  174.                 if (info.auth == false) {
  175.                     account('login');
  176.                 } else {
  177.                     alert(info.error);
  178.                 }
  179.             }
  180.             $("#dialog").dialog('close');
  181.         });
  182. }
  183.  
  184. function render_services() {
  185.     if (iarray.games && iarray.nodes) {
  186.         $.getJSON("/includes/back.php?func=services", function(services) {
  187.             $("#preorders_list").html('');
  188.             $("#services_list").html('');
  189.             iarray.services = {};
  190.             if (services) {
  191.                 $.each(services, function(key, value) {
  192.                     if ($(".service-" + value['id']).length) {
  193.                         $(".service-" + value['id']).remove();
  194.                     }
  195.                     iarray.services[value['id']] = {};
  196.                     iarray.services[value['id']]['id'] = value['id'];
  197.                     iarray.services[value['id']]['node_id'] = value['node_id'];
  198.                     iarray.services[value['id']]['user_id'] = value['user_id'];
  199.                     iarray.services[value['id']]['ip'] = value['ip'];
  200.                     iarray.services[value['id']]['port'] = value['port'];
  201.                     iarray.services[value['id']]['user'] = value['user'];
  202.                     iarray.services[value['id']]['password'] = value['password'];
  203.                     iarray.services[value['id']]['game_id'] = value['game_id'];
  204.                     iarray.services[value['id']]['hostname'] = value['hostname'];
  205.                     iarray.services[value['id']]['slots'] = value['slots'];
  206.                     iarray.services[value['id']]['slots_cur'] = value['slots_cur'];
  207.                     iarray.services[value['id']]['online'] = value['online'];
  208.                     iarray.services[value['id']]['order_date'] = value['order_date'];
  209.                     iarray.services[value['id']]['expires_date'] = value['expires_date'];
  210.                     iarray.services[value['id']]['load'] = value['load'];
  211.                     iarray.services[value['id']]['free'] = value['free'];
  212.                     iarray.services[value['id']]['status'] = value['status'];
  213.                     iarray.services[value['id']]['mysql_name'] = value['mysql_name'];
  214.                     iarray.services[value['id']]['mysql_user'] = value['mysql_user'];
  215.                     iarray.services[value['id']]['mysql_password'] = value['mysql_password'];
  216.                     iarray.services[value['id']]['mysql_host'] = value['mysql_host'];
  217.  
  218.                     if (value['hostname'].length > 33) {
  219.                         hostname = value['hostname'].substr(0, 30) + "...";
  220.                     } else {
  221.                         hostname = value['hostname'];
  222.                     }
  223.                     if (value['free'] == 1) {
  224.                         var free = ' free';
  225.                     } else {
  226.                         var free = '';
  227.                     }
  228.                     if (value['status'] == 1) {
  229.                         $("#pages").append("<div class='service-" + value['id'] + "' id='service-page'><p class='title'>Управление сервером</p><div><table class='service_table'><tr><td><img src='" + iarray.games[value['game_id']].icon + "' class='icon-24-s'> <b class='service_hostname' id='service_hostname-" + value['id'] + "'>" + hostname + "</b> <b id='service_status-" + value['id'] + "'>" + status + "</b><br><b class='service_ip'>IP: " + value['ip'] + ":" + value['port'] + "</b><img src='" + iarray.nodes[value['node_id']].icon + "' class='icon-16-f'> " + iarray.nodes[value['node_id']].location + "</td><td class='service_controlls'><img src='/imgs/icons/start.png' onclick='service_action(" + value['id'] + ", \"cmd_start\")' title='Запуск/Перезагрузка сервера'> <img src='/imgs/icons/stop.png' onclick='service_action(" + value['id'] + ", \"cmd_stop\")' title='Отключение сервера'> <img src='/imgs/icons/reinstall.png' onclick='service_action(" + value['id'] + ", \"cmd_install\", 1)' title='Переустановка сервера'></td></tr><tr><td colspan='2'><hr class='service_hr'></td></tr><tr><td><div class='service_console' id='console-" + value['id'] + "'>Загрузка...</div></td><td class='service_info_d'><div class='expires_info'>Сервер активен до:<br><label id='service_expires_d-" + value['id'] + "'>" + dateformat(value['expires_date']) + "</label><br><br><label class='service_menu_label' onclick='show_extend(" + value['id'] + ")'>Продлить</label><br><hr class='service_hr'><label id='service_slots_d-" + value['id'] + "'>" + value['slots'] + "</label> слотов<br><br><label class='service_menu_label' onclick='show_edit(" + value['id'] + ")'>Изменить</label><hr class='service_hr'>FTP информация<br><br><label class='service_menu_label' onclick='show_ftp(" + value['id'] + ")'>Показать</label><hr class='service_hr'>MySQL база данных<br><br><label class='service_menu_label' onclick='show_mysql(" + value['id'] + ")'>Показать</label></div></td></tr></table></div></div>");
  230.                         $("#services_list").append("<table class='service_item" + free + "'><tr><td class='l_service_ip'><img src='" + iarray.games[value['game_id']].icon + "' class='icon-16-g'> " + value['ip'] + ":" + value['port'] + "</td><td class='l_preorder_slots'>" + value['slots'] + " слотов</td><td class='l_preorder_node'><img src='" + iarray.nodes[value['node_id']].icon + "' class='icon-16-f'> " + iarray.nodes[value['node_id']].name + "</td><td class='l_service_period'>До: " + dateformat(value['expires_date']) + "</td><td class='l_pay'><a class='l_edit_label' title='Панель управления' href='#service-" + value['id'] + "' onclick='iarray.service_active = " + value['id'] + "'>Управление</a></td><td></td></tr></table>");
  231.                         if (value['online'] == 1) {
  232.                             $("#service_status-" + value['id']).text('online');
  233.                             $("#service_status-" + value['id']).css('color', '#4ead6d');
  234.                         } else {
  235.                             $("#service_status-" + value['id']).text('offline');
  236.                             $("#service_status-" + value['id']).css('color', '#c93434');
  237.                         }
  238.                     } else {
  239.                         $("#services_list").append("<table class='service_item'><tr><td class='l_service_ip'><img src='" + iarray.games[value['game_id']].icon + "' class='icon-16-g'> " + value['ip'] + ":" + value['port'] + "</td><td class='l_preorder_slots'>" + value['slots'] + " слотов</td><td class='l_preorder_node'><img src='" + iarray.nodes[value['node_id']].icon + "' class='icon-16-f'> " + iarray.nodes[value['node_id']].name + "</td><td class='l_service_period'>До: " + dateformat(value['expires_date']) + "</td><td class='l_pay'><label class='l_edit_label' title='Продлить' onclick='show_extend(" + value['id'] + ")'>Продлить</label></td><td></td></tr></table>");
  240.                     }
  241.  
  242.                     $("#services_list").fadeIn(300);
  243.                 });
  244.                 iarray.services_avail = 1;
  245.             }
  246.             post_services_events();
  247.         });
  248.     }
  249. }
  250.  
  251. function show_ftp(gid) {
  252.     $("#dialog").html("<form action='http://files.samp-host.ru/index.php' method='post' id='filemanager' target='_blank'><table><tr><td>Хост:</td><td><input type='text' value='" + iarray.nodes[iarray.services[gid].node_id].ip + "' class='ftp_input' name='ftpserver' readonly></td></tr><tr><td>Логин:</td><td><input type='text' value='" + iarray.services[gid].user + "' class='ftp_input' name='username' readonly></td></tr><tr><td>Пароль:</td><td><input type='text' value='" + iarray.services[gid].password + "' class='ftp_input' name='password' readonly><input type='hidden' name='ftpserverport' value='21'></td></tr><tr><td colspan='2' style='text-align:center'><label onclick='$(\"#filemanager\").submit()' class='l_edit_label'>Войти в менеджер файлов</label></td><tr></table><input type='hidden' name='protocol' value='FTP'><input type='hidden' name='language' value='ru'><input type='hidden' name='skin' value='shinra'><input type='hidden' name='ftpmode' value='binary'><input type='hidden' name='state' value='browse'><input type='hidden' name='state2' value='main'><input type='hidden' name='Login' value='Вход'></form>");
  253.     $("#dialog").dialog({
  254.         title: 'FTP информация',
  255.         autoOpen: true,
  256.         width: 'auto',
  257.         height: 'auto',
  258.         resizable: false,
  259.         modal: true,
  260.         draggable: false
  261.     });
  262. }
  263.  
  264. function show_mysql(gid) {
  265.     $("#dialog").html("<form action='http://" + iarray.services[gid].mysql_host + "/phpmyadmin' id='phpmyadmin' target='_blank'><table><tr><td>Хост:</td><td><input type='text' value='" + iarray.services[gid].mysql_host + "' class='ftp_input' readonly></td></tr><tr><td>Имя базы данных:</td><td><input type='text' value='" + iarray.services[gid].mysql_name + "' class='ftp_input' readonly></td></tr><tr><td>Пользователь:</td><td><input type='text' value='" + iarray.services[gid].mysql_user + "' name='pma_username' class='ftp_input' readonly></td></tr><tr><td>Пароль:</td><td><input type='text' value='" + iarray.services[gid].mysql_password + "' name='pma_password' class='ftp_input' readonly></td></tr><tr><td colspan='2' style='text-align:center'><label onclick='$(\"#phpmyadmin\").submit()' class='l_edit_label'>Войти в phpMyAdmin</label></td><tr></table></form>");
  266.     $("#dialog").dialog({
  267.         title: 'MySQL база данных',
  268.         autoOpen: true,
  269.         width: 'auto',
  270.         height: 'auto',
  271.         resizable: false,
  272.         modal: true,
  273.         draggable: false
  274.     });
  275. }
  276.  
  277. function show_extend(gid) {
  278.     $("#dialog").html("<div><table class='order_confirm_t'><tr><td>" + iarray.services[gid].slots + " слотов</td><td align='right' width='300px'>Период продления: <select class='extend_period_select'><option value='1'>1 месяц</option><option value='3'>3 месяца (5% скидка)</option><option value='6'>6 месяцев (15% скидка)</option></select></td></tr><tr><td colspan='2' with='100%'>Итоговая сумма: <b id='extend_total_sum'></b> руб.</td></tr></table><span class='l_edit_label' onclick='service_extend(" + gid + ")'>Продлить</span></div>");
  279.     extend_calculate(gid);
  280.     $(".extend_period_select").change(function() {
  281.         extend_calculate(gid);
  282.     });
  283.     $("#dialog").dialog({
  284.         title: 'Продление сервера',
  285.         autoOpen: true,
  286.         width: 'auto',
  287.         height: 'auto',
  288.         resizable: false,
  289.         modal: true,
  290.         draggable: false
  291.     });
  292. }
  293.  
  294. function extend_calculate(gid) {
  295.     var total = 0;
  296.     var slots = iarray.services[gid].slots;
  297.     var cost = iarray.games[iarray.services[gid].game_id].cost;
  298.     var period = parseInt($(".extend_period_select").val());
  299.     switch (period) {
  300.         case 1:
  301.             total = parseInt(slots * cost);
  302.             break;
  303.         case 3:
  304.             total = (slots * cost) * period;
  305.             total = parseInt(total - ((total / 100) * 5));
  306.             break;
  307.         case 6:
  308.             total = (slots * cost) * period;
  309.             total = parseInt(total - ((total / 100) * 15));
  310.             break;
  311.     }
  312.     $("#extend_total_sum").text(total);
  313. }
  314.  
  315. function service_extend(gid) {
  316.     $.post(
  317.         "/includes/back.php?func=service_extend", {
  318.             id: gid,
  319.             period: $(".extend_period_select").val()
  320.         },
  321.         function(info) {
  322.             if (info.success == 1) {
  323.                 switch (info.type) {
  324.                     case 1:
  325.                         render_service();
  326.                         if (iarray.current_page == 'services') {
  327.                             render_services();
  328.                         }
  329.                         break;
  330.                     case 2:
  331.                         var payment = new UnitPay();
  332.                         payment.createWidget({
  333.                             publicKey: "101721-b881b",
  334.                             sum: info.payment.sum,
  335.                             account: info.payment.id,
  336.                             desc: "Оплата платежа #" + info.payment.id,
  337.                             locale: "ru",
  338.                         });
  339.  
  340.                         payment.success(function(params) {
  341.                             render_service();
  342.                             if (iarray.current_page == 'services') {
  343.                                 render_services();
  344.                             }
  345.                         });
  346.  
  347.                         payment.error(function(message, params) {
  348.  
  349.                         });
  350.                         break;
  351.                 }
  352.             } else {
  353.                 if (info.auth == false) {
  354.                     account('login');
  355.                 } else {
  356.                     alert(info.error);
  357.                 }
  358.             }
  359.             $("#dialog").dialog('close');
  360.         });
  361. }
  362.  
  363. function show_edit(gid) {
  364.     $("#dialog").html("<table class='order_confirm_t'><tr><td colspan='2'><div id='edit_slots_slider'></div></td></tr><tr><td><input type='number' id='edit_slots_input' value='" + iarray.services[gid].slots + "'> шт.</td><td align='right'>Итоговая сумма: <b id='edit_total_sum'>0</b> руб.</td></tr></table><span class='l_edit_label' onclick='service_edit(" + gid + ")'>Изменить</span>");
  365.     $("#edit_slots_slider").slider({
  366.         range: "min",
  367.         value: iarray.services[gid].slots,
  368.         min: parseInt(iarray.games[iarray.services[gid].game_id].minslots),
  369.         max: parseInt(iarray.games[iarray.services[gid].game_id].maxslots),
  370.         slide: function(event, ui) {
  371.             $("#edit_slots_input").val(ui.value);
  372.             edit_calculate(gid);
  373.         }
  374.     });
  375.     $("#edit_slots_input").change(function() {
  376.         $("#edit_slots_slider").slider('value', $("#edit_slots_input").val());
  377.         edit_calculate(gid);
  378.     });
  379.     $("#dialog").dialog({
  380.         title: 'Изменение слотов',
  381.         autoOpen: true,
  382.         width: 'auto',
  383.         height: 'auto',
  384.         resizable: false,
  385.         modal: true,
  386.         draggable: false
  387.     });
  388. }
  389.  
  390. function edit_calculate(gid) {
  391.     var slots = parseInt(iarray.services[gid].slots);
  392.     var new_slots = parseInt($("#edit_slots_input").val());
  393.     var cost = iarray.games[iarray.services[gid].game_id].cost / 30;
  394.     var days_left = parseInt(((new Date(iarray.services[gid].expires_date) / 1000) - (Date.now() / 1000)) / 86400);
  395.     var total = 0;
  396.  
  397.     if (new_slots >= slots) {
  398.         total = parseInt((days_left * cost) * (new_slots - slots));
  399.     } else {
  400.         total = 0;
  401.     }
  402.     $("#edit_total_sum").text(total);
  403. }
  404.  
  405. function service_edit(gid) {
  406.     if (confirm('Вы уверены что хотите изменить количество слотов?')) {
  407.         $.post(
  408.             "/includes/back.php?func=service_edit", {
  409.                 id: gid,
  410.                 new_slots: $("#edit_slots_input").val()
  411.             },
  412.             function(info) {
  413.                 if (info.success == 1) {
  414.                     switch (info.type) {
  415.                         case 1:
  416.                             render_service();
  417.                             service_action(gid, "cmd_start");
  418.                             break;
  419.                         case 2:
  420.                             var payment = new UnitPay();
  421.                             payment.createWidget({
  422.                                 publicKey: "101721-b881b",
  423.                                 sum: info.payment.sum,
  424.                                 account: info.payment.id,
  425.                                 desc: "Оплата платежа #" + info.payment.id,
  426.                                 locale: "ru",
  427.                             });
  428.  
  429.                             payment.success(function(params) {
  430.                                 render_service();
  431.                                 service_action(gid, "cmd_start");
  432.                             });
  433.  
  434.                             payment.error(function(message, params) {});
  435.                             break;
  436.                     }
  437.                 } else {
  438.                     if (info.auth == false) {
  439.                         account('login');
  440.                     } else {
  441.                         alert(info.error);
  442.                     }
  443.                 }
  444.                 $("#dialog").dialog('close');
  445.             });
  446.     }
  447. }
  448.  
  449. function render_service() {
  450.     if (iarray.service_active) {
  451.         $.getJSON("/includes/back.php?func=service&id=" + iarray.service_active, function(service) {
  452.             if (service.id == iarray.service_active) {
  453.                 $("#console-" + iarray.service_active).html(service.console);
  454.  
  455.                 if (service.hostname.length > 33) {
  456.                     hostname = service.hostname.substr(0, 30) + "...";
  457.                 } else {
  458.                     hostname = service.hostname;
  459.                 }
  460.                 $("#service_hostname-" + iarray.service_active).text(hostname);
  461.  
  462.                 var d = $("#console-" + iarray.service_active);
  463.                 d.scrollTop(d.prop('scrollHeight'));
  464.                 if (service.game_status == 1) {
  465.                     $("#service_status-" + iarray.service_active).text('online');
  466.                     $("#service_status-" + iarray.service_active).css('color', '#4ead6d');
  467.                 } else {
  468.                     $("#service_status-" + iarray.service_active).text('offline');
  469.                     $("#service_status-" + iarray.service_active).css('color', '#c93434');
  470.                 }
  471.                 $("#service_expires_d-" + iarray.service_active).text(dateformat(service.expires_date));
  472.                 $("#service_slots_d-" + iarray.service_active).text(service.slots_max);
  473.             }
  474.  
  475.             iarray.services[service.id]['slots'] = service.slots_max;
  476.             iarray.services[service.id]['expires_date'] = service.expires_date;
  477.         });
  478.     }
  479. }
  480.  
  481. function service_action(gid, action, reinstall = 0) {
  482.     if ((reinstall == 1 && confirm('Вы уверены что хотите переустановить сервер?')) || reinstall == 0) {
  483.         $(".service_controlls img").fadeOut(200);
  484.         $.post(
  485.             "/includes/back.php?func=service_action", {
  486.                 id: gid,
  487.                 action: action
  488.             },
  489.             function(info) {
  490.                 if (info.success == 1) {
  491.                     $(".service_controlls img").fadeIn(200);
  492.                 } else {
  493.                     $(".service_controlls img").fadeIn(200);
  494.                     alert(info.error);
  495.                 }
  496.             });
  497.     }
  498. }
  499.  
  500. function render_news() {
  501.     $.getJSON("/includes/back.php?func=news", function(data) {
  502.         if (data) {
  503.             $.each(data, function(key, value) {
  504.                 $(".news_box").append("<table class='news_item'><tr><td class='news_time'>" + value['date'] + "</td></tr><tr><td>" + value['text'] + "</td></tr></table>");
  505.             });
  506.         }
  507.     });
  508. }
  509.  
  510. function order(p_iteam, game, node, slots, period) {
  511.     $("#" + p_iteam + " .l_pay_label").hide();
  512.     $("#" + p_iteam + " .icon-24-d").hide();
  513.     $("#" + p_iteam + " .l_load").show();
  514.     $.post(
  515.         "/includes/back.php?func=order", {
  516.             game: game,
  517.             node: node,
  518.             slots: slots,
  519.             period: period
  520.         },
  521.         function(info) {
  522.             if (info.success == 1) {
  523.                 switch (info.type) {
  524.                     case 1:
  525.                         remove_preorder(p_iteam);
  526.                         account();
  527.                         break;
  528.                     case 2:
  529.                         var payment = new UnitPay();
  530.                         payment.createWidget({
  531.                             publicKey: "101721-b881b",
  532.                             sum: info.payment.sum,
  533.                             account: info.payment.id,
  534.                             desc: "Оплата платежа #" + info.payment.id,
  535.                             locale: "ru",
  536.                         });
  537.  
  538.                         payment.success(function(params) {
  539.                             remove_preorder(p_iteam);
  540.                             render_services();
  541.                         });
  542.  
  543.                         payment.error(function(message, params) {
  544.                             $("#" + p_iteam + " .l_pay_label").show();
  545.                             $("#" + p_iteam + " .icon-24-d").show();
  546.                             $("#" + p_iteam + " .l_load").hide();
  547.                         });
  548.                         setTimeout("$('#" + p_iteam + " .l_pay_label').show();$('#" + p_iteam + " .icon-24-d').show();$('#" + p_iteam + " .l_load').hide();", 15000)
  549.                         break;
  550.                 }
  551.             } else {
  552.                 if (info.auth == false) {
  553.                     account('login');
  554.                 } else {
  555.                     alert(info.error);
  556.                 }
  557.             }
  558.         }
  559.     );
  560. }
  561.  
  562. function account(next_page = false, force = false) {
  563.     $.getJSON("/includes/back.php?func=account", function(account) {
  564.         iarray.user = account;
  565.         if (account.auth == true) {
  566.             $(".header_py_list").html("<li class='py_link'><a href='#services'>Список серверов</a></li><li class='reg_link'><a href='#profile'>Профиль</a></li><li class='lk_link'><a href='#logout'>Выход</a></li>");
  567.             $(".timer_title").text("Баланс:");
  568.             $(".timer").html(account.balance + " руб. - <a href='#pay'>Пополнить</a>");
  569.  
  570.             $(".profile .title").text("Профиль: " + account.login);
  571.             $(".reg_link a").text(account.login);
  572.             $("#profile_email").text(account.email);
  573.             $("#profile_balance").text(account.balance + " руб.");
  574.             post_account_events();
  575.         } else {
  576.             $(".timer_title").text("Нам уже:");
  577.             $(".header_py_list").html("<li class='py_link'><a href='#services'>Панель управления</a></li><li class='lk_link'><a href='#' onclick='login_open_box()'>Личный кабинет</a></li><li class='reg_link'><a href='#register'>Регистрация</a></li>");
  578.             $(".timer").text(account.times);
  579.         }
  580.     }).complete(function() {
  581.         if (next_page) {
  582.             if (force) {
  583.                 window.location = "#" + next_page;
  584.                 switch_panel(next_page, true);
  585.             } else {
  586.                 window.location = "#" + next_page;
  587.             }
  588.         }
  589.         if (iarray.url_hash_loaded == 0) {
  590.             if (window.location.hash) {
  591.                 var page = window.location.hash.replace('#', '');
  592.                 switch (page) {
  593.                     case 'logout':
  594.                         window.location = "#main";
  595.                         break;
  596.                     default:
  597.                         switch_panel(page);
  598.                 }
  599.             }
  600.             iarray.url_hash_loaded = 1;
  601.         }
  602.     });
  603. }
  604.  
  605. function render_tech() {
  606.     $.getJSON("/includes/back.php?func=games", function(games) {
  607.         iarray.games = games;
  608.         $(".order_games").html('');
  609.         $.each(games, function(key, value) {
  610.             if (value['status'] == 1) {
  611.                 $(".order_games").append("<div id='game-" + value['id'] + "' class='order_game_item' style='background-image: url(" + value['image'] + ")' onclick='select_game(" + value['id'] + ")'><label class='order_label'>" + value['name'] + "</label></div>");
  612.             }
  613.         });
  614.     }).complete(function() {
  615.         $.getJSON("/includes/back.php?func=nodes", function(nodes) {
  616.             iarray.nodes = nodes;
  617.             $(".order_nodes").html('');
  618.             $.each(nodes, function(key, value) {
  619.                 if (value['discount'] != "0") {
  620.                     $(".order_nodes").append("<div id='node-" + value['id'] + "' class='order_node_item' style='background-image: url(" + value['image'] + ")' onclick='select_node(" + value['id'] + ")' title='Скидка " + value['discount'] + "%!'><label class='order_label'>" + value['name'] + "</label><img src='/imgs/icons/sale.png' class='sale_i'><img src='" + value['icon'] + "' class='image_i'></div>");
  621.                 } else {
  622.                     $(".order_nodes").append("<div id='node-" + value['id'] + "' class='order_node_item' style='background-image: url(" + value['image'] + ")' onclick='select_node(" + value['id'] + ")'><label class='order_label'>" + value['name'] + "</label><img src='" + value['icon'] + "' class='image_i'></div>");
  623.                 }
  624.             });
  625.         }).complete(function() {
  626.             post_tech_events();
  627.         });
  628.     });
  629. }
  630.  
  631. function select_game(id) {
  632.     $(".order_games").find(".order_game_item").css('border', '3px solid rgb(231, 179, 0)');
  633.     $(".order_games #game-" + id).css('border', '3px solid rgb(36, 153, 0)');
  634.     iarray.order_game = id;
  635.     render_order_info();
  636. }
  637.  
  638. function select_node(id) {
  639.     $(".order_nodes").find(".order_node_item").css('border', '3px solid rgb(231, 179, 0)');
  640.     $(".order_nodes #node-" + id).css('border', '3px solid rgb(36, 153, 0)')
  641.     iarray.order_node = id;
  642.     render_order_info();
  643. }
  644.  
  645. function render_order_info() {
  646.     if (iarray.order_node && iarray.order_game) {
  647.         var node = iarray.nodes[iarray.order_node];
  648.         var game = iarray.games[iarray.order_game];
  649.         var current_slots = parseInt((game.maxslots / 100) * 25);
  650.         eval('var location = ' + node.google_location + ';');
  651.         var map = new google.maps.Map(document.getElementById('google_map'), {
  652.             zoom: 6,
  653.             center: location
  654.         });
  655.         var marker = new google.maps.Marker({
  656.             position: location,
  657.             map: map
  658.         });
  659.  
  660.         $("#order_details").html("<table><tr><td>" + game.name + "</td></tr><tr><td>" + node.location + "</td></tr><tr><td>" + node.protection + "</td></tr><tr><td><a href='" + game.protocol + "://" + node.testip + ":" + game.testport + "'>" + node.testip + ":" + game.testport + "</a></td></tr><tr><td>" + game.cost + " руб./слот</td></tr></table>");
  661.         $(".order_info").fadeIn(300);
  662.         $("#order_slots_input").val(current_slots);
  663.         $("#order_slots_slider").slider({
  664.             range: "min",
  665.             value: current_slots,
  666.             min: parseInt(game.minslots),
  667.             max: parseInt(game.maxslots),
  668.             slide: function(event, ui) {
  669.                 $("#order_slots_input").val(ui.value);
  670.                 order_calculate();
  671.             }
  672.         });
  673.         $("#order_slots_input").change(function() {
  674.             $("#order_slots_slider").slider('value', $("#order_slots_input").val());
  675.             order_calculate();
  676.         });
  677.         $("#order_slots_input").attr('min', game.minslots);
  678.         $("#order_slots_input").attr('max', game.maxslots);
  679.         $(".order_confirm").fadeIn(300);
  680.         $(".order_period_select").change(function() {
  681.             order_calculate();
  682.         });
  683.         order_calculate();
  684.     } else {
  685.         $(".order_info").fadeOut(300);
  686.     }
  687. }
  688.  
  689. function order_calculate() {
  690.     if (iarray.order_node && iarray.order_game) {
  691.         var game = iarray.games[iarray.order_game];
  692.         var node = iarray.nodes[iarray.order_node];
  693.         var period = parseInt($(".order_period_select").val());
  694.         var slots = $("#order_slots_input").val();
  695.         var total = 0;
  696.         var discount_p = 0;
  697.         var discount = parseInt(node.discount);
  698.         switch (period) {
  699.             case 1:
  700.                 total = parseInt(slots * game.cost);
  701.                 break;
  702.             case 3:
  703.                 total = (slots * game.cost) * period;
  704.                 total = parseInt(total - ((total / 100) * 5));
  705.                 discount_p = 5;
  706.                 break;
  707.             case 6:
  708.                 total = (slots * game.cost) * period;
  709.                 total = parseInt(total - ((total / 100) * 15));
  710.                 discount_p = 15;
  711.                 break;
  712.         }
  713.         if (discount != 0) {
  714.             total = parseInt(total - ((total / 100) * discount));
  715.             if (discount_p != 0) {
  716.                 $("#discount_label").text("Экономия " + (discount + discount_p) + "%!");
  717.             } else {
  718.                 $("#discount_label").text("Экономия " + discount + "%!");
  719.             }
  720.         } else {
  721.             if (discount_p != 0) {
  722.                 $("#discount_label").text("Экономия " + discount_p + "%!");
  723.             } else {
  724.                 $("#discount_label").text("");
  725.             }
  726.         }
  727.         $("#total_sum").text(total);
  728.     }
  729. }
  730.  
  731. function preorder() {
  732.     if (iarray.order_node && iarray.order_game) {
  733.         var user = iarray.user;
  734.         var game = iarray.games[iarray.order_game];
  735.         var node = iarray.nodes[iarray.order_node];
  736.         var period = parseInt($(".order_period_select").val());
  737.         var slots = parseInt($("#order_slots_input").val());
  738.         if (slots >= parseInt(game['minslots']) && slots <= parseInt(game['maxslots'])) {
  739.             var preorders = {};
  740.  
  741.             if (Cookies.get('preorders-' + user.id)) {
  742.                 preorders = JSON.parse(Cookies.get('preorders-' + user.id));
  743.                 var k = Object.keys(preorders).length + 1;
  744.                 preorders[k] = {};
  745.                 preorders[k]['i'] = k;
  746.                 preorders[k]['g'] = iarray.order_game;
  747.                 preorders[k]['s'] = slots;
  748.                 preorders[k]['n'] = iarray.order_node;
  749.                 preorders[k]['p'] = period;
  750.                 Cookies.set('preorders-' + user.id, JSON.stringify(preorders), {
  751.                     expires: 365
  752.                 });
  753.             } else {
  754.                 preorders[1] = {};
  755.                 preorders[1]['i'] = 1;
  756.                 preorders[1]['g'] = iarray.order_game;
  757.                 preorders[1]['s'] = slots;
  758.                 preorders[1]['n'] = iarray.order_node;
  759.                 preorders[1]['p'] = period;
  760.                 Cookies.set('preorders-' + user.id, JSON.stringify(preorders), {
  761.                     expires: 365
  762.                 });
  763.             }
  764.             render_preorders();
  765.             window.location = "#services";
  766.             order_reset_form();
  767.         } else {
  768.             $("#order_slots_input").val(game['minslots']);
  769.             $("#order_slots_slider").slider('value', $("#order_slots_input").val());
  770.             order_calculate();
  771.         }
  772.     }
  773. }
  774.  
  775. function order_reset_form() {
  776.     $(".order_nodes").find(".order_node_item").css('border', '3px solid rgb(231, 179, 0)');
  777.     $(".order_games").find(".order_game_item").css('border', '3px solid rgb(231, 179, 0)');
  778.     $(".order_info").hide();
  779.     $(".order_confirm").hide();
  780.     iarray.order_node = false;
  781.     iarray.order_game = false;
  782. }
  783.  
  784. function render_preorders() {
  785.     var user = iarray.user;
  786.     if (Cookies.get('preorders-' + user.id)) {
  787.         var preorders = JSON.parse(Cookies.get('preorders-' + user.id));
  788.         preorders = Object.keys(preorders).map(function(key) {
  789.             return preorders[key];
  790.         });
  791.         preorders = preorders.reverse();
  792.         if (preorders != '') {
  793.             $("#preorders_list").html('');
  794.             $.each(preorders, function(key, value) {
  795.                 var period = value['p'];
  796.                 var slots = value['s'];
  797.                 var game = iarray.games[value['g']];
  798.                 var node = iarray.nodes[value['n']];
  799.                 var total = 0;
  800.                 switch (period) {
  801.                     case 1:
  802.                         total = parseInt(slots * game.cost);
  803.                         var month = 'месяц';
  804.                         break;
  805.                     case 3:
  806.                         total = (slots * game.cost) * period;
  807.                         total = parseInt(total - ((total / 100) * 5));
  808.                         var month = 'месяца';
  809.                         break;
  810.                     case 6:
  811.                         total = (slots * game.cost) * period;
  812.                         total = parseInt(total - ((total / 100) * 15));
  813.                         var month = 'месяцев';
  814.                         break;
  815.                 }
  816.                 if (node.discount != "0") {
  817.                     total = parseInt(total - ((total / 100) * node.discount));
  818.                 }
  819.                 $("#preorders_list").append("<table class='preorder_item' id='" + value['i'] + "'><tr><td class='l_preorder_name'><img src='" + iarray.games[value['g']].icon + "' class='icon-16-g'> " + iarray.games[value['g']].name + " сервер</td><td class='l_preorder_slots'>" + slots + " слотов</td><td class='l_preorder_node'><img src='" + iarray.nodes[value['n']].icon + "' class='icon-16-f'> " + iarray.nodes[value['n']].name + "</td><td class='l_preorder_period'>" + period + " " + month + " - " + total + " руб.</td><td class='l_pay'><label class='l_pay_label' title='Оплатить заказ' onclick='order(" + value['i'] + ", " + value['g'] + ", " + value['n'] + ", " + value['s'] + ", " + period + ")'>Оплатить</label></td><td class='l_load'><img src='/imgs/icons/load.gif'></td><td><img src='/imgs/icons/del.png' onclick='remove_preorder(" + value['i'] + ")' class='icon-24-d' title='Удалить'></td></tr></table>");
  820.             });
  821.         } else {
  822.             if (iarray.services_avail == false) {
  823.                 $("#preorders_list").html('<div>У вас пока нет серверов, <a href="#order">закажите</a> прямо сейчас!</div>');
  824.             }
  825.         }
  826.     } else {
  827.         if (iarray.services_avail == false) {
  828.             $("#preorders_list").html('<div>У вас пока нет серверов, <a href="#order">закажите</a> прямо сейчас!</div>');
  829.         }
  830.     }
  831.     $('#preorders_list').fadeIn(300);
  832. }
  833.  
  834. function remove_preorder(id) {
  835.     var user = iarray.user;
  836.     if (Cookies.get('preorders-' + user.id)) {
  837.         var preorders = JSON.parse(Cookies.get('preorders-' + user.id));
  838.         delete preorders[id];
  839.  
  840.         var i = 1;
  841.         preorders_n = {};
  842.         $.each(preorders, function(key, value) {
  843.             preorders_n[i] = {};
  844.             preorders_n[i]['i'] = i;
  845.             preorders_n[i]['g'] = value['g'];
  846.             preorders_n[i]['s'] = value['s'];
  847.             preorders_n[i]['n'] = value['n'];
  848.             preorders_n[i]['p'] = value['p'];
  849.             i++;
  850.         });
  851.  
  852.         Cookies.set('preorders-' + user.id, JSON.stringify(preorders_n), {
  853.             expires: 365
  854.         });
  855.         $("#preorders_list #" + id).fadeOut(300, function() {
  856.             $("#preorders_list #" + id).remove();
  857.             render_preorders();
  858.         });
  859.     }
  860. }
  861.  
  862. function register() {
  863.     if (iarray.register_process == 0) {
  864.         iarray.register_process = 1;
  865.         if ($("#register_login").val() && $("#register_password").val() && $("#register_password_1").val() && $("#register_email").val()) {
  866.             if ($("#register_password").val() == $("#register_password_1").val()) {
  867.                 $.post(
  868.                     "/includes/back.php?func=register", {
  869.                         login: $("#register_login").val(),
  870.                         password: $("#register_password").val(),
  871.                         email: $("#register_email").val()
  872.                     },
  873.                     function(info) {
  874.                         if (info.success == 1) {
  875.                             if (iarray.url_hash_last) {
  876.                                 account(iarray.url_hash_last, true);
  877.                             } else {
  878.                                 account('services');
  879.                             }
  880.                         } else {
  881.                             if (info.error) {
  882.                                 d_error(info.error, 'register');
  883.                                 iarray.register_process = 0;
  884.                             }
  885.                         }
  886.                         $(document).find('input:password').val('');
  887.                     }
  888.                 );
  889.             } else {
  890.                 d_error('Пароли не совпадают!', 'register');
  891.                 iarray.register_process = 0;
  892.             }
  893.         } else {
  894.             d_error('Заполните все поля!', 'register');
  895.             iarray.register_process = 0;
  896.         }
  897.     }
  898. }
  899.  
  900. function login(ext = false) {
  901.     if (iarray.user.auth == false) {
  902.         if (iarray.login_process == 0) {
  903.             if (ext) {
  904.                 var login = $("." + ext).find("#login").val();
  905.                 var password = $("." + ext).find("#password").val();
  906.             } else {
  907.                 var login = $("#login").val();
  908.                 var password = $("#password").val();
  909.             }
  910.             if (login != '' && password != '') {
  911.                 iarray.login_process = 1;
  912.                 $.post(
  913.                     "/includes/back.php?func=login", {
  914.                         login: login,
  915.                         password: password
  916.                     },
  917.                     function(info) {
  918.                         if (info.success == 1) {
  919.                             iarray.login_process = 0;
  920.                             if (iarray.url_hash_last) {
  921.                                 account(iarray.url_hash_last, true);
  922.                             } else {
  923.                                 account('services');
  924.                             }
  925.                             $("#ajax").fadeOut(500);
  926.                             post_auth_events();
  927.                         } else {
  928.                             if (info.error) {
  929.                                 d_error(info.error, 'login');
  930.                                 iarray.login_process = 0;
  931.                             }
  932.                         }
  933.                         $(document).find('input:password').val('');
  934.                     }
  935.                 );
  936.             } else {
  937.                 d_error('Заполните все поля!', 'login');
  938.             }
  939.         }
  940.     }
  941. }
  942.  
  943. function logout() {
  944.     if (iarray.user.auth == true) {
  945.         $.getJSON("/includes/back.php?func=logout", function(data) {
  946.             if (data.success == 1) {
  947.                 iarray.services_avail = false;
  948.                 iarray.url_hash_last = false;
  949.                 iarray.service_active = false;
  950.                 window.location = "#main";
  951.                 account();
  952.             } else {
  953.                 alert(data.error);
  954.             }
  955.         });
  956.     }
  957. }
  958.  
  959. function d_error(text, page = false) {
  960.     if (page) {
  961.         if ($("." + page).find("#error").length) {
  962.             $("." + page).find("#error").text(text);
  963.             $("." + page).find("#error").finish().stop(true, true).show('pulsate', 500).delay(5000).fadeOut(500);
  964.         } else {
  965.             alert(text);
  966.         }
  967.     } else {
  968.         if ($("#error").length) {
  969.             $("#error").text(text);
  970.             $("#error").finish().stop(true, true).show('pulsate', 500).delay(5000).fadeOut(500);
  971.         } else {
  972.             alert(text);
  973.         }
  974.     }
  975. }
  976.  
  977. function render_support_q() {
  978.     if (iarray.current_page == 'support') {
  979.         render_support();
  980.     }
  981. }
  982.  
  983. function render_support() {
  984.     if (iarray.user.auth == true) {
  985.         var user = iarray.user;
  986.         $.getJSON("/includes/back.php?func=support&list", function(data) {
  987.             if (data) {
  988.                 $("#support_messages").text("");
  989.                 iarray.support_messages_t = true;
  990.                 iarray.support_reply = false;
  991.                 $("#support_close_button").show();
  992.                 if (user.ulevel == 1) {
  993.                     $.each(data, function(key, value) {
  994.                         $("#support_messages").append("<table class='support_item'><tr><td class='support_avatar_item'><img src='/imgs/support-lvl-" + value['ulevel'] + ".png'></td><td class='support_message_item'>" + value['message'] + "</td></tr><tr><td colspan='2' class='support_date_item'>" + dateformat(value['date']) + "</td></tr></table>");
  995.                     });
  996.                     show_support_area();
  997.                 }
  998.  
  999.                 if (user.ulevel == 2) {
  1000.                     $.each(data, function(key, value) {
  1001.                         $(".support-" + value['user_id']).remove();
  1002.                         $("#support_messages").append("<a href='/#support-" + value['user_id'] + "' onclick='iarray.support_active = " + value['user_id'] + ";show_support_area(" + value['user_id'] + ")' id='support_link-" + value['user_id'] + "'><table class='support_item'><tr><td class='support_avatar_item'><img src='/imgs/support-lvl-" + value['ulevel'] + ".png'></td><td class='support_message_item'>" + value['title'] + "</td></tr><tr><td colspan='2' class='support_date_item'>" + dateformat(value['date']) + "</td></tr></table></a>");
  1003.                         $("#pages").append("<div class='support-" + value['user_id'] + "' id='support-page'><p class='title'>Просмотр запроса: <label onclick='render_user_services(" + value['user_id'] + ")' class='link_s'>Сервера</label></p><div id='support_messages'></div></div>");
  1004.                         $(".support-" + value['user_id'] + " .support_item").remove();
  1005.                         if (value['messages'][Object.keys(value['messages']).length]['ulevel'] == 2) {
  1006.                             $("#support_link-" + value['user_id']).css('opacity', 0.5);
  1007.                         }
  1008.                         $.each(value['messages'], function(k, v) {
  1009.                             $(".support-" + value['user_id'] + " #support_messages").append("<table class='support_item'><tr><td class='support_avatar_item'><img src='/imgs/support-lvl-" + v['ulevel'] + ".png'></td><td class='support_message_item'>" + v['message'] + "</td></tr><tr><td colspan='2' class='support_date_item'>" + dateformat(v['date']) + "</td></tr></table>");
  1010.                         });
  1011.                         $(".support-" + value['user_id']).append("<div id='support_area'><textarea id='support_message-" + value['user_id'] + "' class='support_message' placeholder='Сообщение до 2048 символов'></textarea><br><label id='support_reply_b' class='l_support_label' onclick='support_reply(" + value['user_id'] + ")'>Отправить</label> <img src='/imgs/icons/del.png' onclick='support_close(" + value['user_id'] + ")' class='icon-24-d-s' title='Закрыть' id='support_close_button'> <label id='error'></label></div>");
  1012.                     });
  1013.                     $("#support_controlls").hide();
  1014.                 }
  1015.  
  1016.             } else {
  1017.                 iarray.support_messages_t = false;
  1018.                 if (iarray.support_reply == false) {
  1019.                     $("#support_area").hide();
  1020.                     $("#support_close_button").hide();
  1021.                     $("#support_messages").text("У вас нет активных запросов в техническую поддержку.");
  1022.                     $("#support_controlls").html("<label class='l_support_label' onclick='show_support_area();iarray.support_reply = true;'>Задать вопрос</label>");
  1023.                     $("#support_controlls").fadeIn(300);
  1024.                 }
  1025.                 if (user.ulevel == 2) {
  1026.                     $("#support_controlls").hide();
  1027.                 }
  1028.             }
  1029.         });
  1030.     }
  1031. }
  1032.  
  1033. function render_user_services(user_id) {
  1034.     $(".user_services").remove();
  1035.     $("#pages").append("<div class='user_services'><p class='title'>Сервера клиента #" + user_id + "</p><div id='services_list'></div></div>");
  1036.     $.each(iarray.services, function(key, value) {
  1037.         if (value['user_id'] == user_id) {
  1038.             $(".user_services #services_list").append("<table class='service_item'><tr><td class='l_service_ip'><img src='" + iarray.games[value['game_id']].icon + "' class='icon-16-g'> " + value['ip'] + ":" + value['port'] + "</td><td class='l_preorder_slots'>" + value['slots'] + " слотов</td><td class='l_preorder_node'><img src='" + iarray.nodes[value['node_id']].icon + "' class='icon-16-f'> " + iarray.nodes[value['node_id']].name + "</td><td class='l_service_period'>До: " + dateformat(value['expires_date']) + "</td><td class='l_pay'><a class='l_edit_label' title='Панель управления' href='#service-" + value['id'] + "' onclick='iarray.service_active = " + value['id'] + "'>Управление</a></td><td></td></tr></table>");
  1039.         }
  1040.         window.location = '#user_services';
  1041.         $(".user_services #services_list").fadeIn(200);
  1042.     });
  1043. }
  1044.  
  1045. function show_support_area(page = false) {
  1046.     if (page) {
  1047.         $(".support-" + page + " #support_area").fadeIn(300);
  1048.     } else {
  1049.         $("#support_controlls").hide();
  1050.         $("#support_area").fadeIn(300);
  1051.         if (iarray.support_messages_t) {
  1052.  
  1053.         } else {
  1054.             $("#support_messages").text("");
  1055.             $("#support_close_button").hide();
  1056.         }
  1057.     }
  1058. }
  1059.  
  1060. function support_reply(page = false) {
  1061.     if (page) {
  1062.         if ($("#support_message-" + page).val().length >= 6 && $("#support_message-" + page).val().length <= 2048) {
  1063.             $.post(
  1064.                 "/includes/back.php?func=support&reply", {
  1065.                     message: $("#support_message-" + page).val(),
  1066.                     user_id: page
  1067.                 },
  1068.                 function(info) {
  1069.                     if (info.success == 1) {
  1070.                         $(".support-" + page + " #support_messages").append("<table class='support_item'><tr><td class='support_avatar_item'><img src='/imgs/support-lvl-" + iarray.user.ulevel + ".png'></td><td class='support_message_item'>" + $("#support_message-" + page).val() + "</td></tr><tr><td colspan='2' class='support_date_item'>" + dateformat(new Date()) + "</td></tr></table>");
  1071.                         $("#support_message-" + page).val('');
  1072.                         $(".support-" + page + " #support_close_button").fadeIn(300);
  1073.                         $("#support_link-" + page).css('opacity', 0.5);
  1074.                         window.location = '#support';
  1075.                     } else {
  1076.                         d_error(info.error, 'support-' + page);
  1077.                     }
  1078.                 }
  1079.             );
  1080.         } else {
  1081.             d_error('Сообщение должно содержать от 6 до 2048 символов!', 'support-' + page);
  1082.         }
  1083.     } else {
  1084.         if ($("#support_message").val().length >= 6 && $("#support_message").val().length <= 2048) {
  1085.             $.post(
  1086.                 "/includes/back.php?func=support&reply", {
  1087.                     message: $("#support_message").val()
  1088.                 },
  1089.                 function(info) {
  1090.                     if (info.success == 1) {
  1091.                         $("#support_messages").append("<table class='support_item'><tr><td class='support_avatar_item'><img src='/imgs/support-lvl-" + iarray.user.ulevel + ".png'></td><td class='support_message_item'>" + $("#support_message").val() + "</td></tr><tr><td colspan='2' class='support_date_item'>" + dateformat(new Date()) + "</td></tr></table>");
  1092.                         $("#support_message").val('');
  1093.                         $("#support_close_button").fadeIn(300);
  1094.                         iarray.support_messages_t = true;
  1095.                         iarray.support_reply = false;
  1096.                     } else {
  1097.                         d_error(info.error, 'support');
  1098.                     }
  1099.                 }
  1100.             );
  1101.         } else {
  1102.             d_error('Сообщение должно содержать от 6 до 2048 символов!', 'support');
  1103.         }
  1104.     }
  1105. }
  1106.  
  1107. function support_close(page = false) {
  1108.     if (iarray.user.auth == true) {
  1109.         if (page) {
  1110.             if (confirm('Вы уверены что хотите закрыть запрос?')) {
  1111.                 $.getJSON("/includes/back.php?func=support&close&user_id=" + page, function(data) {
  1112.                     if (data.success == 1) {
  1113.                         $(".support-" + page).remove();
  1114.                         window.location = '#support';
  1115.                         $("#support_link-" + page).fadeOut();
  1116.                     } else {
  1117.                         alert(data.error);
  1118.                     }
  1119.                 });
  1120.             }
  1121.         } else {
  1122.             if (confirm('Вы уверены что хотите закрыть запрос?')) {
  1123.                 $("#support_messages").html("");
  1124.                 $.getJSON("/includes/back.php?func=support&close", function(data) {
  1125.                     if (data.success == 1) {
  1126.                         iarray.support_messages_t = false;
  1127.                         iarray.support_reply = false;
  1128.                         $("#support_area").hide();
  1129.                         $("#support_close_button").hide();
  1130.                         $("#support_messages").text("У вас нет активных запросов в техническую поддержку.");
  1131.                         $("#support_controlls").html("<label class='l_support_label' onclick='show_support_area()'>Задать вопрос</label>");
  1132.                         $("#support_controlls").fadeIn(300);
  1133.                     } else {
  1134.                         alert(data.error);
  1135.                     }
  1136.                 });
  1137.             }
  1138.         }
  1139.     }
  1140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement