Esempio n. 1
0
 public function pay($code, $userId)
 {
     if (preg_match("/^\\d{" . $this->codeLength . "}\$/", $code)) {
         $cardmatch = $this->table->load("WHERE activated=0 AND code='{$code}'");
         if (count($cardmatch) == 1) {
             $card = $cardmatch[0];
             $this->table->edit(array('id' => $card['id'], 'activated' => 1, 'activationdate' => date("Y-m-d H:i:s"), 'user' => $userId));
             $moneyflowTable = new table('moneyflow');
             $paySum = floatval($card['value']);
             $moneyflowTable->add(array("detailsname" => "scratchcard", "detailsid" => $card['id'], "user" => $userId, "sum" => $paySum));
             return $paySum;
         } else {
             l('payment', 'badscratchcard', NULL, $userId, NULL, array());
             return false;
         }
     }
 }
Esempio n. 2
0
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);
        }
    }
}
Esempio n. 3
0
         $id = $table->edit($data);
         break;
     case 'dbremove':
         $id = $table->delete($data);
         break;
 }
 if ($target == 'user' && ($action == 'dbedit' || $action == 'dbadd') && isset($_POST['cash']) && checkPermission($sessionId, array('table', $target, 'edit', 'cash'))) {
     if ($action === 'dbedit') {
         $user = $table->loadById($id);
         $sum = money($_POST['cash']) - money($user['cash']);
     } else {
         $sum = money($_POST['cash']);
     }
     if ($sum) {
         $moneyflowTable = new table('moneyflow');
         $moneyflowTable->add(array("user" => $id, "sum" => $sum, "detailsname" => "adminpay", "detailsid" => $sessionId));
     }
     payment(0, $id);
 }
 if ($id) {
     if (strpos($id, ',') === false) {
         $table->load4AJAX(" WHERE id={$id}");
     } else {
         $table->load4AJAX(" WHERE id in ({$id})");
     }
 }
 $res = $db->query("SELECT COUNT(*) FROM `" . DB_TABLE_PREFIX . $target . "`");
 $row = $res->fetch();
 $response->length = intval($row['COUNT(*)']);
 foreach ($response->header as $key => $value) {
     if ($value[1] === 'timestamp') {
Esempio n. 4
0
     $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;
 case 'finish':
     $fenom->display($theme->getTemplateLocation('header.tpl'), $headerData);
     $fenom->display($theme->getTemplateLocation('messagehasbeenhidden.tpl'));
     $fenom->display($theme->getTemplateLocation('footer.tpl'));
     break;
 default:
     redirect('message.php?action=list');