/application/controllers/member.php
PHP | 1233 lines | 991 code | 189 blank | 53 comment | 113 complexity | 019249e67ade793e790fefb8e9d3adbb MD5 | raw file
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- class Member extends MY_Controller
- {
- private $profile = null;
- public function __construct()
- {
- parent::__construct();
- // Make sure the user is logged in on this page
- // - if not set a session message and redirect to the homepage
- if (!$this->ion_auth->logged_in())
- {
- $this->session->set_flashdata('error', 'You must be logged in to view that page. Click <a class="login_link containerLink" data-target="loginFrm" title="Login" href="#">here</a> to login');
- redirect(site_url(), 'refresh');
- }
- $this->profile = $this->ion_auth->user()->row();
- $this->setLayout('layout/member');
- $this->layoutData['member_page'] = 'CHANGE ME [' . $this->router->method . ']';
- //Loading The Cashier Model
- $this->load->model('payment_method_model', 'PaymentMethod');
- $this->load->model('transaction_model', 'Transaction');
- $this->load->model('earning_transfer_model', 'Transfer');
- $this->load->model('email_queue_model', 'EmailQueue');
- $this->load->model('history_model', 'History');
- $this->load->model('investment_model', 'Investment');
- $this->load->driver('cache', array('adapter' => 'file'));
- $this->load->library('table');
- $this->load->library('AccountObject');
- //$this->output->enable_profiler(true);
- }
- public function add_funds()
- {
- if ($this->input->is_ajax_request())
- {
- $balances = $this->PaymentMethod->getBalancesList($this->profile->id);
- $totalBalance = $this->profile->balance;
- echo $this->loadPartialView("member/add_funds", compact('totalBalance', 'balances'));
- }
- else show_404();
- }
- public function index()
- {
- $this->lang->load('live_news');
- //script for tabs main_content
- $this->addJavascript(asset('scripts/tabs.js'));
- $forum_post = $this->forum_latest_post();
- $live_new_feed = $this->live_news_feed();
- $this->layoutData['member_page'] = 'Main Page';
- $this->loadView('member/index', 'My Traffic Value - Your Home',compact('forum_post', 'live_new_feed') );
- }
- // Forum post to show
- public function forum_latest_post()
- {
- $limit = 5;
- $this->load->model('forum_model','Forum');
- return $this->Forum->getLatestMessages($limit);
- }
- // Live News to show on the page
- public function live_news_feed()
- {
- $filter = 2047;
- $page = 1;
- $perpage = 9;
- $this->load->model('live_news_model', 'LiveNews');
- return $this->LiveNews->getSubset($filter, $page, $perpage, false);
- }
- /**
- * Shows Referrals View in User > Earn Money > Referrals
- *
- * @param string $sorting 'username', 'ptv', 'referrals', 'commission'
- * @param int $level It can be level '1' or '2'
- * @param int $page
- * @param int $perpage
- *
- * @author Alex
- * @author Fede update
- */
- public function referrals($level = false, $sorting = 'username', $order = 'asc', $page = 1, $perpage = 15)
- {
- $this->load->model('referral_model', 'Referral');
- $userId = $this->profile->id;
- if ( in_array($sorting, array ('username', 'referrals', 'ptv', 'ref_by', 'commission') ) === FALSE)
- $sorting = 'username';
- if ( in_array($order, array ('asc', 'desc') ) === FALSE)
- $order = 'asc';
- if ($this->input->is_ajax_request())
- {
- $levelData = $this->Referral->getCount($userId, $level);
- if ($levelData)
- {
- $count = $levelData->count;
- $data = $this->Referral->getSubset($userId, $level, $sorting, $order, $page, $perpage);
- $paging = generatePagination(site_url('member/referrals/' . $level . '/' . $sorting . '/' . $order), $count, $page, $perpage, true);
- $hasPages = $count > $perpage;
- echo $this->load->view('member/referral/partial/referrals_level' . $level, compact ('data', 'paging', 'hasPages', 'sorting', 'order'), true);
- }
- }
- else
- {
- $username = $this->profile->username;
- $commissions = $this->Referral->getCommissionTable();
- // Init the variables
- $L2 = $referralsL1 = $referralsL2 = null;
- $L1 = $this->Referral->getCount($userId, 1);
- if ($L1)
- {
- $count = $L1->count;
- $data = $this->Referral->getSubset($userId, 1, $sorting, $order);
- $paging = generatePagination(site_url('member/referrals/1/' . $sorting. '/' . $order), $count, $page, $perpage, true);
- $hasPages = $count > $perpage;
- $referralsL1 = $this->load->view('member/referral/partial/referrals_level1', compact ('data', 'paging', 'hasPages', 'sorting', 'order'), true);
- $L2 = $this->Referral->getCount($userId, 2);
- if ($L2)
- {
- $count = $L2->count;
- $data = $this->Referral->getSubset($userId, 2, $sorting, $order);
- $paging = generatePagination(site_url('member/referrals/2/' . $sorting. '/' . $order), $count, $page, $perpage, true);
- $hasPages = $count > $perpage;
- $referralsL2 = $this->load->view('member/referral/partial/referrals_level2', compact ('data', 'paging', 'hasPages','sorting', 'order'), true);
- }
- }
- $this->addJavascript(asset('scripts/paging.js'));
- $this->addJavascript(asset('scripts/sortable.js'));
- $this->layoutData['member_page'] = anchor ('member/earn_money.html', 'Earn Money') . ' - Referrals';
- $this->loadView('member/referrals', 'My Traffic Value - Your Home', compact('username', 'commissions', 'L1', 'L2', 'referralsL1', 'referralsL2'));
- }
- }
- public function support($code = null)
- {
- $this->load->model('support_ticket_model', 'Ticket');
- if ($code)
- {
- $ticketData = $this->Ticket->get($code, $this->profile->id);
- if (!$ticketData)
- {
- $this->session->set_flashdata('error', 'There is no support ticket with that code');
- redirect(site_url('member/support.html'), 'refresh');
- }
- $ticket = $ticketData['ticket'];
- $messages = $ticketData['messages'];
- }
- if (!$this->input->is_ajax_request())
- {
- if ($code)
- {
- $this->addJavascript(asset('scripts/forms.js'));
- $this->layoutData['member_page'] = anchor('member/support.html', 'Support') . ' - Ticket #' . $ticket->id;
- $this->loadView('support/member/view', 'My Traffic Value: Support for Member', compact('ticket', 'messages'));
- }
- else
- {
- $openTickets = $this->Ticket->getSummary($this->profile->id, false, 'open');
- $closedTickets = $this->Ticket->getSummary($this->profile->id, false, 'closed');
- $profile = $this->profile;
- $this->layoutData['member_page'] = 'Support';
- $this->loadView('support/member/index', 'My Traffic Value: Support for Member', compact('openTickets', 'closedTickets', 'profile'));
- }
- }
- else
- {
- if ($this->form_validation->run('support_reply')) // Defined in form_validation
- {
- $post = $this->input->post();
- $ticketData = null;
- if (isset ($post['status']))
- {
- $ticketData = array(
- 'status' => $post['status']
- );
- }
- $messageData = array(
- 'ticket_id' => $ticket->id,
- 'user_id' => $this->profile->id,
- 'message' => $post['message']
- );
- if ($this->Ticket->store($messageData, $ticketData) === TRUE)
- {
- $data = array(
- 'success' => 'success',
- 'html' => '<strong>Thank you for your message!</strong>',
- 'redirect' => array(
- 'url' => site_url('member/support/' . $code . '.html'),
- 'timeout' => 1000
- )
- );
- }
- else
- {
- $data = array(
- 'error' => 'Your message was not sent'
- );
- }
- }
- else
- {
- $data = array(
- 'errorElements' => array(
- 'message' => form_error('message')
- )
- );
- }
- echo json_encode($data);
- }
- }
- public function support_add()
- {
- if (!$this->input->is_ajax_request())
- {
- $this->addJavascript(asset('scripts/forms.js'));
- $this->layoutData['member_page'] = anchor ('member/support.html', 'Support') . ' - New Ticket';
- $this->loadView('support/member/new', 'My Traffic Value: Support for Member');
- }
- else
- {
- if ($this->form_validation->run('member_support')) // Defined in form_validation
- {
- $this->load->model('support_ticket_model', 'Ticket');
- $code = uniqid();
- $post = $this->input->post();
- $ticketData = array(
- 'code' => $code,
- 'user_id' => $this->profile->id,
- 'subject' => $post['subject']
- );
- $messageData = array(
- 'user_id' => $this->profile->id,
- 'message' => $post['message']
- );
- if ($this->Ticket->store($messageData, $ticketData) === TRUE)
- {
- // Send the email to the guest so he/she can refer back to it
- $ticketUrl = site_url('member/support/' . $code . '.html');
- $this->EmailQueue->store($this->profile->email, 'Support Ticket #' . $ticketData['id'], 'emails/support/ticket_created', compact('ticketUrl'));
- $data = array(
- 'success' => 'success',
- 'html' => '<strong>Thank you for your message!</strong>',
- 'redirect' => array(
- 'url' => site_url('member/support/' . $code . '.html'),
- 'timeout' => 1000
- )
- );
- }
- else
- {
- $data = array(
- 'error' => 'Your message was not sent'
- );
- }
- }
- else
- {
- $data = array(
- 'errorElements' => array(
- 'subject' => form_error('subject'),
- 'message' => form_error('message'),
- )
- );
- }
- echo json_encode($data);
- }
- }
- public function live_news($filter = 2047, $page = 1, $perpage = 30)
- {
- $this->load->model('live_news_model', 'LiveNews');
- $post = $this->input->post();
- if ($post)
- $filter = isset($post['check']) ? intval($post['check']) : $filter;
- $count = $this->LiveNews->getCount($filter);
- // We only want 10 pages of data to start with so restrict it here
- // --8<--
- $count = min(10 * $perpage, $count);
- $page = min(10, $page);
- // -->8--
- if ($count)
- {
- $this->lang->load('live_news');
- $data = $this->LiveNews->getSubset($filter, $page, $perpage);
- $paging = generatePagination(site_url('/member/live_news/' . $filter), $count, $page, $perpage, true);
- $hasPages = $count > $perpage;
- $feed = $this->load->view('partial/live_news', compact ('data', 'paging', 'hasPages'), true);
- }
- else $feed = 'Nothing for the selected filters';
- if ($this->input->is_ajax_request())
- {
- echo $feed;
- }
- else
- {
- $this->load->model('user_model', 'User');
- $totalUsers = $this->User->getActiveUsersCount();
- //TODO: Alex change this please
- $today_reg_users = $this->LiveNews->getRegisteredTodayCount();
- $online_users = $this->LiveNews->getUsersOnlineCount();
- $online_guests = $this->LiveNews->getGuestsOnlineCount();
- $this->addJavascript(asset('scripts/paging.js'));
- $this->addJavascript(asset('scripts/live_news.js'));
- $this->layoutData['member_page'] = 'Live News';
- $this->loadView('member/live_news', 'My Traffic Value: Live News', compact('today_reg_users', 'online_users', 'online_guests', 'totalUsers', 'feed'));
- }
- }
- public function users_online($page = 1, $perpage = 10)
- {
- $this->load->model('live_news_model', 'LiveNews');
- $this->load->model('referral_model');
- $count = $this->LiveNews->getUsersOnlineCount();
- if ($count)
- {
- $data = $this->LiveNews->getUsersOnlineSubset($page, $perpage);
- $paging = generatePagination('/member/users_online', $count, $page, $perpage, true);
- $hasPages = $count > $perpage;
- $online = $this->load->view('partial/users_online', compact ('data', 'paging', 'hasPages'), true);
- }
- else $online = '';
- if ($this->input->is_ajax_request())
- {
- echo $online;
- }
- else
- {
- $this->addJavascript(asset('scripts/paging.js'));
- $this->layoutData['member_page'] = anchor('member/live_news.html', 'Live News') . ' - Who is Online';
- $this->loadView('member/users_online', 'My Traffic Value: Online Users', compact ('online'));
- }
- }
- public function my_account()
- {
- $this->load->model('my_account_model', 'Account');
- $this->load->model('referral_model', 'Referral');
- $this->load->model('shares_model', 'Shares');
- $userId = $this->profile->id;
- //Summary Data:
- //TODO Investment
- //TODO Shares
- $summary = $this->Account->summary($userId);
- //Profile Data:
- $profile = $this->Account->profile($userId);
- $history = $this->history('all', 1, 30, true);
- $this->addJavascript(asset('scripts/account_history.js'));
- $this->addJavascript(asset('scripts/paging.js'));
- $this->addJavascript(asset('scripts/tabs.js'));
- $this->addJavascript(asset('scripts/forms.js'));
- $this->addJavascript(asset('scripts/my_account.js'));
- $this->addStyleSheet(asset('styles/my_account.css'));
- $this->addStyleSheet(asset('styles/cupertino/jquery.ui.all.css'));
- $this->addStyleSheet(asset('styles/cupertino/jquery.ui.theme.css'));
- $this->addStyleSheet(asset('styles/cupertino/jquery.ui.datepicker.css'));
- $this->layoutData['member_page'] = 'My Account';
- $this->loadView('member/my_account', 'My Traffic Value - Your Account', compact('summary', 'profile', 'email_not', 'history'));
- }
- public function history($method = 'all', $page = 1, $perpage = 30, $return = false)
- {
- $userId = $this->profile->id;
- $count = $this->History->getCount($userId, $method, null);
- if ($count)
- {
- $data = $this->History->getSubset($userId, $method, null, $page, $perpage);
- $paging = generatePagination(site_url('member/history/' . $method), $count, $page, $perpage, true);
- $hasPages = $count > $perpage;
- $history = $this->load->view('partial/account_history', compact ('data', 'method', 'paging', 'hasPages'), true);
- }
- else
- $history = 'Nothing for the selected filters';
- if ($return)
- return $history;
- echo $history;
- }
- //Get Info to Popup about history cashier selected
- public function info_history($histId=NULL)
- {
- if ($this->input->is_ajax_request())
- {
- /*
- $result = $this->Transaction->getById($histId);
- $user = $this->PaymentMethod->getAccountForUser($this->profile->id, $result->method);
- $mtv = $this->PaymentMethod->getAccountDetails($result->method);
- echo $this->loadPartialView('partial/history', compact('result','user', 'mtv'));
- */
- // Maybe functions above should be reviewed, if they are in other parts or not
- $transaction = $this->Transaction->getDetails($histId, $this->profile->id);
- if (!$transaction)
- show_404();
- echo $this->loadPartialView('cashier/partial/transaction', compact('transaction'));
- }
- else
- {
- show_404();
- }
- }
- public function blackhole()
- {
- $this->layoutData['member_page'] = 'Page Under Construction';
- $this->loadView('blank', 'My Traffic Value - BLANK');
- }
- public function investments()
- {
- $this->layoutData['member_page'] = 'Investments';
- $this->loadView('member/investments', 'My Traffic Value - Investment');
- }
- public function earn_money()
- {
- $this->layoutData['member_page'] = 'Earn Money';
- $this->loadView('member/earn_money', 'My Traffic Value - Earn Money');
- }
- public function ref_more_info()
- {
- $username = $this->profile->username;
- $this->layoutData['member_page'] = anchor ('member/earn_money.html', 'Earn Money') . ' - ' . anchor('member/referrals.html', 'Referrals') . ' - Information';
- $this->loadView('member/referral/more_info', 'My Traffic Value - Referrals - More Info', compact('username'));
- }
- public function ref_top_referrer($sorting = 'count_l1', $page = 1, $perpage = 20)
- {
- $this->load->model('user_model', 'User');
- $this->load->model('referral_model', 'Referral');
- $count = $this->User->getActiveUsersCount();
- // Do some checking on the data to be sure
- if (in_array ($sorting, array ('count_l1', 'count_l2', 'earnings')) === FALSE)
- $sorting = 'count_l1';
- $data = $this->Referral->getTopReferrersSubset($sorting, $page, $perpage);
- $paging = generatePagination('/member/ref_top_referrer/' . $sorting, $count, $page, $perpage, true);
- $hasPages = $count > $perpage;
- $referrers = $this->load->view('partial/top_referrers', compact ('data', 'paging', 'sorting', 'hasPages'), true);
- if ($this->input->is_ajax_request())
- {
- echo $referrers;
- }
- else
- {
- $this->addJavascript(asset('scripts/paging.js'));
- $this->addJavascript(asset('scripts/sortable.js'));
- $this->layoutData['member_page'] = anchor ('member/earn_money.html', 'Earn Money') . ' - ' . anchor('member/referrals.html', 'Referrals') . ' - Top Referrers';
- $this->loadView('member/referral/top_referrers', 'My Traffic Value - Referrals - Top Referrers', compact('referrers'));
- }
- }
- public function ref_banners()
- {
- $refUrl = site_url('ref/' . $this->profile->username);
- $this->layoutData['member_page'] = anchor ('member/earn_money.html', 'Earn Money') . ' - ' . anchor('member/referrals.html', 'Referrals') . ' - Banners';
- $this->loadView('member/referral/banners', 'My Traffic Value - Referrals - Banners', compact('refUrl'));
- }
- public function ads()
- {
- $this->addStyleSheet(asset('styles/ads.css'));
- $guest = false;
- $this->layoutData['member_page'] = 'Advertise';
- $this->loadView('common/ads', 'My Traffic Value - Advertise', compact('guest'));
- }
- //Show The Cashier
- public function cashier()
- {
- $userId = $this->profile->id;
- $balances = $this->PaymentMethod->getBalancesList($userId);
- $total = 0;
- foreach ($balances as $balance)
- $total += $balance->balance;
- $accounts = dropdown ($this->PaymentMethod->getList(), 'code');
- $pendingTransactions = $this->Transaction->getSubsetByUserId($userId, 'pending');
- $completedTransactions = $this->Transaction->getSubsetByUserId($userId, 'ok');
- $earnings = $this->PaymentMethod->getBalance($userId, 'eb');
- $this->addJavascript(asset('scripts/tabs.js'));
- $this->addJavascript(asset('scripts/forms.js'));
- $this->layoutData['member_page'] = 'Cashier';
- $this->loadView('cashier/index', 'My Traffic Value - Cashier', compact('balances', 'total', 'accounts', 'pendingTransactions', 'completedTransactions', 'earnings'));
- }
- public function transaction($id)
- {
- if (!$this->input->is_ajax_request())
- show_404();
- $transaction = $this->Transaction->getDetails($id, $this->profile->id);
- if (!$transaction)
- show_404();
- $accountDetails = null;
- $mtvAccountDetails = null;
- $transactionDetails = null;
- switch ($transaction->method)
- {
- case 'wu':
- $transactionDetails = new WesternUnionDetails($transaction->details);
- $userAccount = new WesternUnion($transaction->user);
- $systemAccount = new WesternUnion($transaction->system);
- break;
- case 'bw':
- $transactionDetails = new BankWireDetails($transaction->details);
- $userAccount = new BankWire($transaction->user);
- $systemAccount = new BankWire($transaction->system);
- break;
- default:
- $userAccount = $transaction->user;
- $systemAccount = $transaction->system;
- }
- echo $this->loadPartialView('cashier/partial/transaction', compact('transaction', 'transactionDetails', 'userAccount', 'systemAccount'));
- }
- // This function allows people to cancel theuir pending transaction
- public function cancel_transaction($id)
- {
- $transaction = $this->Transaction->getDetails($id, $this->profile->id);
- if ($transaction)
- {
- $this->Transaction->update($id, 'cancel');
- $this->session->set_flashdata('success', 'Transaction successfully cancelled');
- redirect('member/cashier.html');
- }
- else show_error('Forbidden', 403);
- }
- public function cashier_account($code)
- {
- if ($code == 'eb')
- show_error('Forbidden', 403); // failsafe
- $this->load->model('user_model', 'User');
- $listCountries = $this->User->getCountries();
- $userId = $this->profile->id;
- $account = $this->PaymentMethod->getAccountForUser($userId, $code);
- if (!$account->enabled)
- {
- $this->session->set_flashdata('error', 'Sorry but <strong>' . $account->name . '</strong> interaction has not been enabled');
- redirect('member/cashier.html');
- }
- if ($account->account == null || $account->locked == 0) // Add or edit
- {
- if ($this->input->is_ajax_request())
- {
- if ($this->form_validation->run($code . '_account') === true)
- {
- $post = $this->input->post();
- switch ($code)
- {
- case 'wu':
- $accountData = new WesternUnion($post);
- $accountData = $accountData->__toString();
- break;
- case 'bw':
- $accountData = new BankWire($post);
- $accountData = $accountData->__toString();
- break;
- default:
- $accountData = $code == 'lr' ? strtoupper($post['account']) : strtolower($post['account']);
- }
- if ($this->PaymentMethod->set($userId, $code, $accountData))
- {
- $this->session->set_flashdata('success', 'Successfully updated your <strong>' . $account->name . '</strong> account');
- $data = array(
- 'success' => 'success',
- 'redirect' => array(
- 'url' => site_url('member/deposit/'.$code.'.html')
- )
- );
- }
- else
- {
- $data = array(
- 'error' => 'An unknown error has occurred'
- );
- }
- }
- else
- {
- $data = array(
- 'errorElements' => $this->form_validation->error_array()
- );
- }
- echo json_encode($data);
- return;
- }
- else
- {
- $this->layoutData['member_page'] = anchor ('member/cashier.html', 'Cashier') . ' - Add/Edit account';
- $countries = dropdown($listCountries, 'name');
- $country = $this->profile->country;
- $this->addJavascript(asset('scripts/forms.js'));
- $this->loadView('cashier/account', 'My Traffic Value - Cashier', compact('code', 'account', 'countries', 'country'));
- }
- }
- else // All set and locked so go away
- {
- $this->session->set_flashdata('info', 'Your <strong>' . $account->name . '</strong> account is locked and cannot be changed');
- redirect('member/cashier.html');
- }
- }
- public function cashier_deposit($code)
- {
- if ($code == 'eb')
- show_error('Forbidden', 403); // failsafe
- $this->load->model('user_model', 'User');
- $listCountries = $this->User->getCountries();
- $userId = $this->profile->id;
- $account = $this->PaymentMethod->getAccountForUser($userId, $code);
- if (!$account->enabled)
- {
- $this->session->set_flashdata('error', 'Sorry but <strong>' . $account->name . '</strong> interaction has not been enabled');
- redirect('member/cashier.html');
- }
- if ($account->account)
- {
- $accounts = $this->PaymentMethod->getAccountDetails($code,'in');
- $depositAccount = $accounts[0];
- if ($this->input->is_ajax_request())
- {
- $post = $this->input->post();
- $data = null;
- if (count ($accounts) > 1)
- {
- $accountId = isset($post['account_id']) ? intval($post['account_id']) : null;
- if ($accountId)
- {
- // We already have all the accounts at hand so no need to fetch it again
- foreach ($accounts as $acct)
- {
- if ($acct->id == $accountId)
- {
- $depositAccount = $acct;
- break;
- }
- }
- }
- }
- // We have to set this rule on the fly for the limits
- $this->form_validation->set_rules('amount', 'Amount', 'trim|required|greater_than[' . ($depositAccount->minimum - 0.01) . ']|xss_clean');
- if ($code == 'bw')
- {
- $this->form_validation->set_rules('memo', 'Memo Line', 'trim|required|xss_clean');
- }
- else if ($code == 'wu')
- {
- $this->form_validation->set_rules('city', 'City', 'trim|required|xss_clean');
- $this->form_validation->set_rules('country', 'Country', 'trim|required|xss_clean');
- $this->form_validation->set_rules('mtcn', 'MTCN No.', 'trim|required|xss_clean|numeric|min_length[6]|max_length[14]');
- }
- if ($this->form_validation->run() === true)
- {
- $amount = $post['amount'];
- if (!isset ($post['currency']))
- $post['currency'] = 'USD'; // Set the currency to USD by default
- $depositData = array(
- 'user_id' => $userId,
- 'method' => $code,
- 'account_id' => $depositAccount->id,
- 'gross_amount' => $amount,
- 'identifier' => $this->Transaction->identifier()
- );
- switch ($code)
- {
- case 'bw':
- $depositDetails = new BankWireDetails($post);
- $depositData['details'] = $depositDetails->__toString();
- break;
- case 'wu':
- $depositDetails = new WesternUnionDetails($post);
- $depositData['details'] = $depositDetails->__toString();
- break;
- default:
- $depositDetails = null;
- }
- if ($transactionId = $this->Transaction->addDeposit($depositData))
- {
- $data = array(
- 'success' => 'success',
- 'html' => $this->loadPartialView('cashier/deposit_finish', compact('code', 'account', 'depositDetails', 'depositData', 'depositAccount', 'transactionId'))
- );
- }
- else
- {
- $data = array(
- 'error' => 'An unknown error has occurred'
- );
- }
- }
- else
- {
- $data = array(
- 'errorElements' => $this->form_validation->error_array()
- );
- }
- echo json_encode($data);
- return;
- }
- else
- {
- $this->layoutData['member_page'] = anchor ('member/cashier.html', 'Cashier') . ' - Deposit';
- $fees = $this->PaymentMethod->getLatestBillDetails($code);
- $countries = dropdown($listCountries, 'name');
- $this->addJavascript(asset('scripts/forms.js'));
- $this->addJavascript(asset('scripts/cashier.js'));
- $this->addStyleSheet(asset('styles/depositmethods.css'));
- $depositMethodInfo = $this->loadPartialView('cashier/partial/deposit_method_info', compact('code', 'depositAccount', 'fees'));
- $this->loadView('cashier/deposit', 'My Traffic Value - Cashier', compact('code', 'account', 'accounts', 'depositAccount', 'fees', 'countries', 'depositMethodInfo'));
- }
- }
- else // huho
- {
- $this->session->set_flashdata('error', 'Your <strong>' . $account->name . '</strong> account has not been set up');
- redirect('member/account/' . $code . '.html');
- }
- }
- public function cashier_email_instructions($code, $accountId = 0)
- {
- if ($this->input->is_ajax_request())
- {
- if ($accountId > 0)
- $depositAccount = $this->PaymentMethod->getAccountDetailsById($accountId);
- else
- {
- $accounts = $this->PaymentMethod->getAccountDetails($code);
- $depositAccount = $accounts[0];
- }
- $fees = $this->PaymentMethod->getFeeData($code, 'deposit');
- switch ($code)
- {
- case 'bw':
- $emailSubject = 'Bank Wire Deposit Instructions';
- $depositDetails = new BankWire($depositAccount->details);
- break;
- case 'wu':
- $emailSubject = 'Western Union Deposit Instructions';
- $depositDetails = new WesternUnion($depositAccount->details);
- break;
- default:
- return; // Don't want to be here if not BW or WU
- }
- $this->EmailQueue->store($this->profile->email, $emailSubject, 'emails/cashier/deposit_instructions_' . $code, compact('depositAccount', 'depositDetails', 'fees'));
- }
- }
- public function cashier_cashout($code)
- {
- if ($code == 'eb')
- show_error('Forbidden', 403); // failsafe
- $userId = $this->profile->id;
- $account = $this->PaymentMethod->getAccountForUser($userId, $code);
- $balance = $this->PaymentMethod->getBalance($userId, $code);
- if (!$account->enabled)
- {
- $this->session->set_flashdata('error', 'Sorry but <strong>' . $account->name . '</strong> interaction has not been enabled');
- redirect('member/cashier.html');
- }
- if ($balance <= 0)
- {
- $this->session->set_flashdata('error', 'Sorry but you do not have funds in your <strong>' . $account->name . '</strong> account');
- redirect('member/cashier.html');
- }
- if ($account->account)
- {
- if ($this->input->is_ajax_request())
- {
- $post = $this->input->post();
- $data = null;
- // We have to set this rule on the fly for the limits
- $this->form_validation->set_rules('amount', 'Amount', 'trim|required|xss_clean');
- $this->form_validation->set_rules('day', 'Date of Birth', 'trim|required|callback_valid_dob');
- $this->form_validation->set_rules('month', 'Date of Birth', 'trim|required|callback_valid_dob');
- $this->form_validation->set_rules('year', 'Date of Birth', 'trim|required|callback_valid_dob');
- // If requesting WU we need to ask for City and Country (!!)
- if ($code == 'wu')
- {
- $this->form_validation->set_rules('city', 'City', 'trim|required|xss_clean');
- $this->form_validation->set_rules('country', 'Country', 'trim|required|xss_clean');
- }
- if ($this->form_validation->run() === true)
- {
- // Amount validation requires more options:
- $amount = roundDown($post['amount'], 2);
- $mtvAccounts = $this->PaymentMethod->getAccountDetails($code,'out');
- $mtvAccount = $mtvAccounts[0];
- $min = $mtvAccount->minimum;
- $max = ($balance > $mtvAccount->maximum) ? $mtvAccount->maximum : $balance;
- if($amount >= $min AND $amount <= $max)
- {
- $cashoutData = array(
- 'user_id' => $userId,
- 'gross_amount' => $amount,
- 'method' => $code,
- 'identifier' => $this->Transaction->identifier()
- );
- if ($code == 'wu')
- {
- $cashoutDetails = new WesternUnionDetails($post);
- $cashoutData['details'] = $cashoutDetails->__toString();
- }
- if ($transactionId = $this->Transaction->addCashout($cashoutData))
- {
- $data = array(
- 'success' => 'success',
- 'balance' => money($this->ion_auth->select('balance')->user()->row()->balance), // For updating Balance shown to user
- 'html' => $this->loadPartialView('cashier/cashout_finish', compact('code', 'account', 'cashoutDetails', 'cashoutData', 'transactionId'))
- );
- }
- else
- {
- $data = array(
- 'error' => 'An unknown error has occurred'
- );
- }
- }
- else
- {
- $data = array(
- 'errorElements' => array('amount' => 'Out of limits Amount')
- );
- }
- }
- else
- {
- $data = array(
- 'errorElements' => $this->form_validation->error_array()
- );
- }
- echo json_encode($data);
- }
- else
- {
- $this->layoutData['member_page'] = anchor ('member/cashier.html', 'Cashier') . ' - Cashout';
- // We have to fix a bit this, mtvAccount and depositAccount are the same in different parts...
- $mtvAccounts = $this->PaymentMethod->getAccountDetails($code, 'out');
- $mtvAccount = $mtvAccounts[0]; //Needed to indicate maximum and minimum
- $depositAccount = $mtvAccount;
- $countries = null;
- if ($code == 'wu')
- {
- $this->load->model('user_model', 'User');
- $listCountries = $this->User->getCountries();
- $countries = dropdown($listCountries, 'name');
- }
- $this->addJavascript(asset('scripts/forms.js'));
- $this->addJavascript(asset('scripts/cashier.js'));
- $this->addStyleSheet(asset('styles/depositmethods.css'));
- $fees = $this->PaymentMethod->getLatestBillDetails($code);
- $depositMethodInfo = $this->loadPartialView('cashier/partial/deposit_method_info', compact('code', 'depositAccount', 'fees'));
- $this->loadView('cashier/cashout', 'My Traffic Value - Cashier', compact('code', 'account', 'fees', 'countries', 'cashoutMethodInfo', 'balance', 'mtvAccount','depositMethodInfo'));
- }
- }
- else // huho
- {
- $this->session->set_flashdata('error', 'Your <strong>' . $account->name . '</strong> account has not been set up');
- redirect('member/account/' . $code . '.html');
- }
- }
- public function cashier_account_details($id)
- {
- if ($this->input->is_ajax_request())
- {
- $account = $this->PaymentMethod->getAccountDetailsById($id);
- echo $this->loadPartialView('cashier/details', compact('account'));
- }
- else
- {
- show_404();
- }
- }
- public function transfer_earnings()
- {
- if ($this->input->is_ajax_request())
- {
- if ($this->form_validation->run())
- {
- $post = $this->input->post();
- $data = array(
- 'user_id' => $this->profile->id,
- 'amount' => $post['amount'],
- 'method' => $post['account']
- );
- if ($this->Transfer->add($data))
- {
- $this->session->set_flashdata('success', 'Your transfer has been recorded');
- $data = array(
- 'success' => 'Saved',
- 'redirect' => array(
- 'url' => site_url('member/cashier.html')
- )
- );
- }
- else
- {
- $data = array(
- 'error' => 'Errrr, not worked'
- );
- }
- }
- else
- {
- $data = array(
- 'errorElements' => $this->form_validation->error_array()
- );
- }
- echo json_encode($data);
- }
- }
- /**
- * Used to return a valid date of birth from Database. It needs to construct the
- * rule for year, month and day
- *
- * @return boolean
- */
- function valid_dob()
- {
- $dob = $this->input->post('year') . '-' . $this->input->post('month') . '-' . $this->input->post('day');
- if (strtotime($dob) != strtotime($this->profile->date_of_birth))
- {
- $this->form_validation->set_message('valid_dob', '* invalid');
- return FALSE;
- }
- return true;
- }
- public function lr_account_check($param)
- {
- if (!preg_match('/^[u|x]\d{2,8}$/i', $param))
- {
- $this->form_validation->set_message('lr_account_check', '* incorrect - use Uxxxxxxxx');
- return false;
- }
- if ($this->PaymentMethod->checkAccountExists('lr', $this->profile->id, $param))
- {
- $this->form_validation->set_message('lr_account_check', '* incorrect - already in use');
- return false;
- }
- return true;
- }
- public function ap_account_check($param)
- {
- if ($this->PaymentMethod->checkAccountExists('ap', $this->profile->id, $param))
- {
- $this->form_validation->set_message('ap_account_check', '* incorrect - already in use');
- return false;
- }
- return true;
- }
- function valid_earnings($param)
- {
- $userId = $this->profile->id;
- $earnings = $this->PaymentMethod->getBalance($userId, 'eb');
- if ((float)$param < 0.00001 || (float)$param > (float)$earnings)
- {
- $this->form_validation->set_message('valid_earnings', '* incorrect');
- return FALSE;
- }
- return true;
- }
- //FAQ
- public function faq()
- {
- $this->addJavascript(asset('scripts/faq.js'));
- $this->addJavascript(asset('scripts/forum/forum.js'));
- $this->load->library('text_format');
- $this->load->model('faq_model','Faq');
- $isAdmin = $this->ion_auth->is_admin();
- if ($isAdmin)
- $this->addJavascript(asset('scripts/forms.js'));
- $faqs = $this->Faq->getFaqs();
- $guest = false;
- $this->layoutData['member_page'] = 'FAQ';
- $this->loadView('common/faq', 'My Traffic Value: FAQ', compact('guest','faqs','isAdmin'));
- }
- public function add_edit_faq($faqId = NULL)
- {
- if (!$this->ion_auth->is_admin())
- show_error("Forbidden", 403);
- if (!$this->input->is_ajax_request())
- {
- show_404();
- }
- else
- {
- $this->load->model('faq_model','Faq');
- if ($post = $this->input->post())
- {
- if ($this->form_validation->run('member/add_edit_faq') === TRUE)
- {
- $faqData = array(
- 'title' => strip_tags($post['title']),
- 'text' => strip_tags($post['text']),
- 'date' => now()
- );
- if($faqId == NULL) //Added new FAQ
- {
- if ($this->Faq->storeFaq($faqData))
- {
- $this->session->set_flashdata('success', 'FAQ successfully added');
- $data = array(
- 'success' => 'Saved',
- 'redirect' => array(
- 'url' => site_url('member/faq.html')
- )
- );
- }
- else
- {
- $data = array(
- 'error' => 'Error storing FAQ'
- );
- }
- }
- else //Updated FAQ
- {
- if ($this->Faq->updateFaq($faqId, $faqData))
- {
- $this->session->set_flashdata('success', 'FAQ successfully updated');
- $data = array(
- 'success' => 'Saved',
- 'redirect' => array(
- 'url' => site_url('member/faq.html')
- )
- );
- }
- else
- {
- $data = array(
- 'error' => 'Error updating FAQ'
- );
- }
- }
- }
- else
- {
- $data = array(
- 'errorElements' => $this->form_validation->error_array()
- );
- }
- echo json_encode($data);
- }
- else
- {
- $this->load->library('text_format');
- $smiley_table = $this->text_format->add_smileys(asset('images/smileys'), 'text', 8);
- $faq = ($faqId) ? $this->Faq->getFaq($faqId) : NULL;
- echo $this->loadPartialView('partial/add_edit_faq', compact('smiley_table','faq'));
- }
- }
- }
- public function delete_faq($faqId)
- {
- if (!$this->ion_auth->is_admin())
- show_error("Forbidden", 403);
- $this->load->model('faq_model','Faq');
- $faq = $this->Faq->getFaq($faqId);
- if (!$faq)
- show_404();
- if ($this->Faq->deleteFaq($faqId))
- {
- $this->session->set_flashdata('success', 'FAQ deleted');
- }
- else
- {
- $this->session->set_flashdata('error', 'FAQ not deleted');
- }
- $faqUrl = site_url('member/faq.html');
- redirect($faqUrl);
- }
- }