<?php include_once '../include/ucp.php'; if (isset($_GET['ok'])) { header("Location: http://google.com.ua/"); $req = $db->query("SELECT * FROM `" . DB_TABLE_PREFIX . "user` WHERE iplist LIKE '%\"" . $_SERVER['REMOTE_ADDR'] . "\"%'")->fetchAll(); $row = $req ? $req[0] : null; if ($row) { controllerRouterQueue($row['router'], 'clearnotification', $row['id']); } sleep(1); } $tpl = array("user" => $user); $fenom->display($theme->getTemplateLocation('header.tpl'), $headerData); $fenom->display($theme->getTemplateLocation('nocosts-notification.tpl'), $tpl); $fenom->display($theme->getTemplateLocation('footer.tpl'));
function payment($mode, $id = false) { global $db; global $mysqlTimeDateFormat; /* $mode 0 payment: new cash value will be written, 'upd' action on routers 1 shownotification: new cash value will not be writtent, 'shownotify' on routers 2 clearnotifications: 'clearnotify' on all routers */ if ($mode !== 2) { if ($res = $db->query("SELECT id, price FROM " . DB_TABLE_PREFIX . "tariff")->fetchAll()) { $price = array(); foreach ($res as $row) { $price[$row['id']] = $row['price']; } } $typeOfCalculation = configgetvalue('system', 'cash', NULL, 'typeOfCalculation'); $creditMonths = configgetvalue('system', 'cash', NULL, 'creditMonths'); $routerAction = $mode ? "shownotification" : "update"; $usersTable = new table('user'); $usersRes = $usersTable->load($id ? "WHERE id={$id}" : ""); foreach ($usersRes as $row) { if (!isset($price[$row['tariff']])) { continue; } $tariffId = $row['tariff']; $userId = $row['id']; // Calculate amounts $cash = money($row['cash']); $sum = -getCashToPay($userId, $row, $price[$tariffId]); $fullMonthSum = -getCashToPay($userId, $row, $price[$tariffId], true); $newCash = $cash + $sum; $minimumCash = $fullMonthSum * intval($creditMonths); $currentOrder = getCurrentTariff($userId); if ($mode == 0) { if ($row['disabled'] == '0' && (!$currentOrder || $currentOrder['temp'] == 1) && ($newCash >= $minimumCash || $row['credit'] == '1')) { //Add info to payments table $orderTable = new table('order'); $moneyFlowTable = new table('moneyflow'); $currentDate = new DateTime('midnight'); $startDate = new DateTime('first day of this month midnight'); $endDate = new DateTime('first day of next month midnight'); $endDate->modify("-1 sec"); $withdrawalDay = configgetvalue('system', 'cash', NULL, 'withdrawalDay'); $withdrawalDay -= 1; if ($withdrawalDay) { $startDate->modify("+{$withdrawalDay} day"); $endDate->modify("+{$withdrawalDay} day"); } if ($currentDate < $startDate) { $startDate->modify("-1 month"); $endDate->modify("-1 month"); } if ($currentOrder) { $orderTable->edit(array('id' => $currentOrder['id'], 'canceled' => 1, 'enddate' => $currentDate->format($mysqlTimeDateFormat))); } $orderId = $orderTable->add(array('user' => $userId, 'detailsname' => 'tariff', 'detailsid' => $tariffId, 'startdate' => $currentDate->format($mysqlTimeDateFormat), 'enddate' => $endDate->format($mysqlTimeDateFormat))); $moneyFlowTable->add(array('user' => $userId, 'detailsname' => 'order', 'detailsid' => $orderId, 'sum' => money($sum))); } else { controllerRouterQueue($row['router'], "update", $row['id']); } } else { if ($mode == 1) { if ($row['disabled'] == '0' && ($newCash < $minimumCash && $row['credit'] == '0')) { controllerRouterQueue($row['router'], "shownotification", $row['id']); } } } } } else { $routerTable = new table('router'); $routerRes = $routerTable->load($id ? "WHERE id={$id}" : ""); foreach ($routerRes as $row) { controllerRouterQueue($row['id'], 'clearnotification', $id); } } }
$request .= "(`recipient`=" . $user->getId() . " AND `recipient_is_admin`=0)) "; if (isset($_GET['id'])) { $request .= "AND `id`=" . intval($_GET['id']); } $request = "UPDATE " . DB_TABLE_PREFIX . "`message` SET `is_new`=0, `readdate`='" . date($mysqlTimeDateFormat) . "' " . $request; $db->query($request); // Check for another unread messages $request = "WHERE `recipient`=" . $user->getId() . " AND `recipient_is_admin`=0 AND `is_new`=1"; $newMessages = $messageTable->load($request); if (count($newMessages)) { $nextMessage = $newMessages[0]; redirect('message.php?action=show&id=' . $nextMessage['id']); } else { $usersTable = new table('user'); $row = $usersTable->loadById($user->getId()); controllerRouterQueue($row['router'], "hidemessage", $user->getId()); redirect('message.php?action=finish'); } break; case 'send': if (isset($_POST['text']) && $_POST['text']) { $messageText = htmlspecialchars($_POST['text']); $messageTable->add(array("text" => $messageText, "sender" => $user->getId(), "sender_is_admin" => 0, "recipient" => 0, "is_new" => 1, "recipient_is_admin" => 1, "date" => date($mysqlTimeDateFormat))); } redirect('message.php?action=messagehasbeensent'); break; case 'messagehasbeensent': $fenom->display($theme->getTemplateLocation('header.tpl'), $headerData); $fenom->display($theme->getTemplateLocation('messagehasbeensent.tpl')); $fenom->display($theme->getTemplateLocation('footer.tpl')); break;