$months = str_replace('buy', '', $purchase); if ($months > 12 || $months < 0) { $months = 1; } $balance = User::getBalance($userID); $amount = $adFreeMonthCost * $months; $bonus = floor($months / 6); $months += $bonus; if ($balance >= $amount) { $dttm = UserConfig::get('adFreeUntil', null); $now = $dttm == null ? ' now() ' : "'{$dttm}'"; $newDTTM = Db::queryField("select date_add({$now}, interval {$months} month) as dttm", 'dttm', array(), 0); Db::execute('update zz_account_balance set balance = balance - :amount where userID = :userID', array(':userID' => $userID, ':amount' => $amount)); Db::execute('insert into zz_account_history (userID, purchase, amount) values (:userID, :purchase, :amount)', array(':userID' => $userID, ':purchase' => $purchase, ':amount' => $amount)); UserConfig::set('adFreeUntil', $newDTTM); $twig->addGlobal('accountBalance', User::getBalance($userID)); $error = "Funds have been applied for {$months} month" . ($months == 1 ? '' : 's') . ", you are now ad free until {$newDTTM}"; Log::log("Ad free time purchased by user {$userID} for {$months} months with " . number_format($amount) . ' ISK'); } else { $error = 'Insufficient Funds... Nice try though....'; } } } $keyid = Util::getPost('keyid'); $vcode = Util::getPost('vcode'); $label = Util::getPost('label'); // Apikey stuff if (isset($keyid) || isset($vcode)) { $error = Api::addKey($keyid, $vcode, $label); } $deletesessionid = Util::getPost('deletesessionid');
} $user_id = $addresses[$detail['address']]['site_user']; $request_id = !empty($requests[$transaction['txid']]) ? $requests[$transaction['txid']] : false; // check for hot wallet recharge if ($addresses[$detail['address']]['hot_wallet'] == 'Y') { if ($transaction['confirmations'] > 0) { $hot_wallet_in = $detail['amount']; } continue; } elseif ($addresses[$detail['address']]['system_address'] == 'Y') { unlink($transactions_dir . $t_id); break; } // get user balance... no need to lock if (empty($user_balances[$user_id])) { $bal_info = User::getBalance($user_id, $CFG->btc_currency_id); $user_balances[$user_id] = $bal_info['balance']; } // if not confirmed enough if ($addresses[$detail['address']]['trusted'] == 'Y' && $transaction['confirmations'] < 1 || $addresses[$detail['address']]['trusted'] != 'Y' && $transaction['confirmations'] < 3) { if (!($request_id > 0)) { $rid = db_insert('requests', array('date' => date('Y-m-d H:i:s'), 'site_user' => $user_id, 'currency' => $CFG->btc_currency_id, 'amount' => $detail['amount'], 'description' => $CFG->deposit_bitcoin_desc, 'request_status' => $CFG->request_pending_id, 'request_type' => $CFG->request_deposit_id, 'transaction_id' => $transaction['txid'], 'send_address' => $detail['address'])); db_insert('history', array('date' => date('Y-m-d H:i:s'), 'history_action' => $CFG->history_deposit_id, 'site_user' => $user_id, 'request_id' => $rid, 'balance_before' => $user_balances[$user_id], 'balance_after' => $user_balances[$user_id] + $detail['amount'], 'bitcoin_address' => $detail['address'])); } echo 'Transaction pending.' . PHP_EOL; $pending = true; } else { // if confirmation sufficient if (!($request_id > 0)) { $updated = db_insert('requests', array('date' => date('Y-m-d H:i:s'), 'site_user' => $user_id, 'currency' => $CFG->btc_currency_id, 'amount' => $detail['amount'], 'description' => $CFG->deposit_bitcoin_desc, 'request_status' => $CFG->request_completed_id, 'request_type' => $CFG->request_deposit_id, 'transaction_id' => $transaction['txid'], 'send_address' => $detail['address'])); db_insert('history', array('date' => date('Y-m-d H:i:s'), 'history_action' => $CFG->history_deposit_id, 'site_user' => $user_id, 'request_id' => $updated, 'balance_before' => $user_balances[$user_id], 'balance_after' => $user_balances[$user_id] + $detail['amount'], 'bitcoin_address' => $detail['address']));
<?php // Load Twig globals $app->view(new \Slim\Views\Twig()); // Theme $viewtheme = null; $accountBalance = 0; $userShowAds = true; if (User::isLoggedIn()) { $accountBalance = User::getBalance(User::getUserID()); $adFreeUntil = UserConfig::get('adFreeUntil', null); $userShowAds = $adFreeUntil == null ? true : $adFreeUntil <= date('Y-m-d H:i'); } // Setup Twig $cachepath = 'cache/templates/'; $view = $app->view(); $view->parserOptions = array('debug' => $debug ? true : false, 'cache' => $cachepath); $twig = $app->view()->getEnvironment(); $uri = $_SERVER['REQUEST_URI']; $explode = explode('/', $uri); $expager = explode('/', $uri); foreach ($expager as $key => $ex) { if (in_array($ex, array('page'))) { unset($expager[$key]); unset($expager[$key + 1]); } } foreach ($explode as $key => $ex) { if (in_array($ex, array('year', 'month', 'page'))) { // find the key for the page array unset($explode[$key]);
function beforeFilter() { $this->Auth->loginRedirect = '/'; // for the authorizations $this->Auth->authorize = 'actions'; $this->Auth->actionPath = 'controllers/'; // if the user is not logged and it requests the root '/' url // redirects to '/login' if (!$this->Session->read('Auth.User.id')) { if ($this->params['url']['url'] == '/') { $this->redirect('/login'); } } App::import('Model', 'User'); if ($this->Session->read('Auth.User.id')) { if ($this->params['url']['url'] == '/') { $user = new User(); $user = $user->read(null, $this->Session->read('Auth.User.id')); $this->redirect($user['UserGroup']['home_url']); } } if ($this->layout == 'default' && $this->Session->read('Auth.User.id')) { // creating an array with all the permissions for this user // and in the view we check if it has permissions to show the link // getting all the acos with permissions App::import('Model', 'Aco'); App::import('Model', 'Aro'); App::import('Model', 'ArosAco'); $aco = new Aco(); $aro = new Aro(); $aros_aco = new ArosAco(); $acos = $aco->find('threaded', array('recursive' => 0)); // consulta el id del aro $aro_row = $aro->find('first', array('conditions' => array('model' => 'UserGroup', 'foreign_key' => $this->Session->read('Auth.User.user_group_id')))); // consulta la relacion de aros_acos $aros_acos = $aros_aco->find('all', array('conditions' => array('aro_id' => $aro_row['Aro']['id']))); $this->set('acl_lists', $this->AclGetList->get($this->Session->read('Auth.User.user_group_id'), $acos, $aros_acos)); } // rendering the menu for "default" layout // checking if there is a logged user if ($this->layout == 'default' && $this->Session->read('Auth.User.id')) { // renders the menu according the user group App::import('Model', 'Menu'); $menu = new Menu(); $this->set('layout_menus', $menu->find_for_show($this->Session->read('Auth.User.user_group_id'))); // selecting the current menu $this->set('layout_current', $this->params['url']['url']); //$route = Router::parse('/'.$this->params['url']['url']); //$aco_alias = 'controllers/'.$route['controller'].'/'.$route['action']; //$this->set('layout_acos', $this->Acl->Aco->node('controllers/'.$route['controller'].'/'.$route['action'])); // asks the controller for selecting the correct link in the menu $cont = split('_', $this->params['controller']); $newcont = ''; foreach ($cont as $c) { $newcont .= ucfirst($c); } $current_aco = $this->Acl->Aco->node('controllers/' . $newcont . '/' . $this->params['action']); $this->set('layout_aco_id', $current_aco[0]['Aco']['id']); //$route = Router::parse('/profile'); //$this->set('menu_url', '/'.$this->params['controller'].'/'.$this->params['action']); if ($this->Session->read('Auth.User.type') == 'web') { $user = new User(); $user->id = $this->Session->read('Auth.User.id'); $user->updatecredit_expiration(); $this->set('user_balance', $user->getBalance()); $this->set('user_expirationdate', $user->getExpirationDate()); } } }
/** * ajax method to get the balance of the user */ function getbalance($id = null) { $this->layout = "ajax"; // ajax method if ($this->Session->read('Auth.User.type') == 'web') { $id = $this->Session->read('Auth.User.id'); } if (!$id) { $this->redirect('/'); } $user = new User(); $user->read(null, $id); $this->set('balance', $user->getBalance()); }
$transactions = array(); $user_balances = array(); $addresses = array(); if ($result) { $pending = 0; foreach ($result as $row) { // check if user sending to himself $addr_info = BitcoinAddresses::getAddress($row['send_address']); if (!empty($addr_info['site_user']) && $addr_info['site_user'] == $row['site_user']) { db_update('requests', $row['id'], array('request_status' => $CFG->request_completed_id)); continue; } // check if sending to another wlox user if (!empty($addr_info['site_user'])) { if (empty($user_balances[$addr_info['site_user']])) { $bal_info = User::getBalance($addr_info['site_user'], $CFG->btc_currency_id, true); $user_balances[$addr_info['site_user']] = $bal_info['balance']; } User::updateBalances($row['site_user'], array('btc' => -1 * $row['amount']), true); User::updateBalances($addr_info['site_user'], array('btc' => $row['amount']), true); db_update('requests', $row['id'], array('request_status' => $CFG->request_completed_id)); $rid = db_insert('requests', array('date' => date('Y-m-d H:i:s'), 'site_user' => $addr_info['site_user'], 'currency' => $CFG->btc_currency_id, 'amount' => $row['amount'], 'description' => $CFG->deposit_bitcoin_desc, 'request_status' => $CFG->request_completed_id, 'request_type' => $CFG->request_deposit_id)); if ($rid) { db_insert('history', array('date' => date('Y-m-d H:i:s'), 'history_action' => $CFG->history_deposit_id, 'site_user' => $addr_info['site_user'], 'request_id' => $rid, 'balance_before' => $user_balances[$addr_info['site_user']], 'balance_after' => $user_balances[$addr_info['site_user']] + $row['amount'], 'bitcoin_address' => $row['send_address'])); } $user_balances[$addr_info['site_user']] = $user_balances[$addr_info['site_user']] + $row['amount']; continue; } // check if hot wallet has enough to send $pending += $row['amount']; if ($row['amount'] > $available) {
/** * makes a new reservation (admin/sales user) */ function addforuser($room_id, $schedule_id, $date) { $room = $this->Reservation->Room->read(null, $room_id); if (!empty($this->data)) { // checks if the user has enough credit to reserve the room $this->data['Reservation']['amount'] = $room['Room']['cost']; if ($this->Session->read('Auth.User.type') != 'web') { $operation['Operation']['user_id'] = $this->data['Reservation']['user_id']; } else { $operation['Operation']['user_id'] = $this->Session->read('Auth.User.id'); } $user = new User(); $userdata = $user->read(null, $operation['Operation']['user_id']); if ($room['Room']['cost'] > $user->getBalance(null, null, false, true)) { $this->Session->setFlash(__('Not enough credit to make the reservation.', true)); $this->set('userdata', $userdata); } else { // registers a new operation of debit type $new_operation = new Operation(); $new_operation->create(); $operation['Operation']['date'] = date('Y-m-d H:i:s'); // date of the operation $operation['Operation']['type'] = 'C'; $operation['Operation']['amount'] = $this->data['Reservation']['amount']; $operation['Operation']['description'] = 'Room Reservation'; // registers the new reservation $reservation['Reservation']['schedule_id'] = $schedule_id; $reservation['Reservation']['room_id'] = $room_id; $reservation['Reservation']['date'] = $date; $reservation['Reservation']['notes'] = $this->data['Reservation']['description']; // NOTE the date of the reservation may be different of the date of the operation //$operation['Operation']['Reservation'][0] = $reservation['Reservation']; if ($new_operation->save($operation)) { $this->Reservation->create(); $reservation['Reservation']['operation_id'] = $new_operation->id; $this->Reservation->save($reservation); $this->Session->setFlash(__('The Reservation has been saved', true)); $this->redirect('/'); } else { //$this->Session->setFlash(__('The Reservation could not be saved. Please try again.', true)); $this->Session->setFlash(__('Please input a description.', true)); } } } $this->set('room', $room); $this->set('schedule', $this->Reservation->Schedule->read(null, $schedule_id)); $this->set('date', $date); $this->set('users', $this->Reservation->Operation->User->find('all', array('conditions' => array('type' => 'web')))); }