PageRenderTime 55ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/application/controllers/member.php

https://bitbucket.org/justin_anastos/coin_flip_game
PHP | 1233 lines | 991 code | 189 blank | 53 comment | 113 complexity | 019249e67ade793e790fefb8e9d3adbb MD5 | raw file
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. class Member extends MY_Controller
  3. {
  4. private $profile = null;
  5. public function __construct()
  6. {
  7. parent::__construct();
  8. // Make sure the user is logged in on this page
  9. // - if not set a session message and redirect to the homepage
  10. if (!$this->ion_auth->logged_in())
  11. {
  12. $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');
  13. redirect(site_url(), 'refresh');
  14. }
  15. $this->profile = $this->ion_auth->user()->row();
  16. $this->setLayout('layout/member');
  17. $this->layoutData['member_page'] = 'CHANGE ME [' . $this->router->method . ']';
  18. //Loading The Cashier Model
  19. $this->load->model('payment_method_model', 'PaymentMethod');
  20. $this->load->model('transaction_model', 'Transaction');
  21. $this->load->model('earning_transfer_model', 'Transfer');
  22. $this->load->model('email_queue_model', 'EmailQueue');
  23. $this->load->model('history_model', 'History');
  24. $this->load->model('investment_model', 'Investment');
  25. $this->load->driver('cache', array('adapter' => 'file'));
  26. $this->load->library('table');
  27. $this->load->library('AccountObject');
  28. //$this->output->enable_profiler(true);
  29. }
  30. public function add_funds()
  31. {
  32. if ($this->input->is_ajax_request())
  33. {
  34. $balances = $this->PaymentMethod->getBalancesList($this->profile->id);
  35. $totalBalance = $this->profile->balance;
  36. echo $this->loadPartialView("member/add_funds", compact('totalBalance', 'balances'));
  37. }
  38. else show_404();
  39. }
  40. public function index()
  41. {
  42. $this->lang->load('live_news');
  43. //script for tabs main_content
  44. $this->addJavascript(asset('scripts/tabs.js'));
  45. $forum_post = $this->forum_latest_post();
  46. $live_new_feed = $this->live_news_feed();
  47. $this->layoutData['member_page'] = 'Main Page';
  48. $this->loadView('member/index', 'My Traffic Value - Your Home',compact('forum_post', 'live_new_feed') );
  49. }
  50. // Forum post to show
  51. public function forum_latest_post()
  52. {
  53. $limit = 5;
  54. $this->load->model('forum_model','Forum');
  55. return $this->Forum->getLatestMessages($limit);
  56. }
  57. // Live News to show on the page
  58. public function live_news_feed()
  59. {
  60. $filter = 2047;
  61. $page = 1;
  62. $perpage = 9;
  63. $this->load->model('live_news_model', 'LiveNews');
  64. return $this->LiveNews->getSubset($filter, $page, $perpage, false);
  65. }
  66. /**
  67. * Shows Referrals View in User > Earn Money > Referrals
  68. *
  69. * @param string $sorting 'username', 'ptv', 'referrals', 'commission'
  70. * @param int $level It can be level '1' or '2'
  71. * @param int $page
  72. * @param int $perpage
  73. *
  74. * @author Alex
  75. * @author Fede update
  76. */
  77. public function referrals($level = false, $sorting = 'username', $order = 'asc', $page = 1, $perpage = 15)
  78. {
  79. $this->load->model('referral_model', 'Referral');
  80. $userId = $this->profile->id;
  81. if ( in_array($sorting, array ('username', 'referrals', 'ptv', 'ref_by', 'commission') ) === FALSE)
  82. $sorting = 'username';
  83. if ( in_array($order, array ('asc', 'desc') ) === FALSE)
  84. $order = 'asc';
  85. if ($this->input->is_ajax_request())
  86. {
  87. $levelData = $this->Referral->getCount($userId, $level);
  88. if ($levelData)
  89. {
  90. $count = $levelData->count;
  91. $data = $this->Referral->getSubset($userId, $level, $sorting, $order, $page, $perpage);
  92. $paging = generatePagination(site_url('member/referrals/' . $level . '/' . $sorting . '/' . $order), $count, $page, $perpage, true);
  93. $hasPages = $count > $perpage;
  94. echo $this->load->view('member/referral/partial/referrals_level' . $level, compact ('data', 'paging', 'hasPages', 'sorting', 'order'), true);
  95. }
  96. }
  97. else
  98. {
  99. $username = $this->profile->username;
  100. $commissions = $this->Referral->getCommissionTable();
  101. // Init the variables
  102. $L2 = $referralsL1 = $referralsL2 = null;
  103. $L1 = $this->Referral->getCount($userId, 1);
  104. if ($L1)
  105. {
  106. $count = $L1->count;
  107. $data = $this->Referral->getSubset($userId, 1, $sorting, $order);
  108. $paging = generatePagination(site_url('member/referrals/1/' . $sorting. '/' . $order), $count, $page, $perpage, true);
  109. $hasPages = $count > $perpage;
  110. $referralsL1 = $this->load->view('member/referral/partial/referrals_level1', compact ('data', 'paging', 'hasPages', 'sorting', 'order'), true);
  111. $L2 = $this->Referral->getCount($userId, 2);
  112. if ($L2)
  113. {
  114. $count = $L2->count;
  115. $data = $this->Referral->getSubset($userId, 2, $sorting, $order);
  116. $paging = generatePagination(site_url('member/referrals/2/' . $sorting. '/' . $order), $count, $page, $perpage, true);
  117. $hasPages = $count > $perpage;
  118. $referralsL2 = $this->load->view('member/referral/partial/referrals_level2', compact ('data', 'paging', 'hasPages','sorting', 'order'), true);
  119. }
  120. }
  121. $this->addJavascript(asset('scripts/paging.js'));
  122. $this->addJavascript(asset('scripts/sortable.js'));
  123. $this->layoutData['member_page'] = anchor ('member/earn_money.html', 'Earn Money') . ' - Referrals';
  124. $this->loadView('member/referrals', 'My Traffic Value - Your Home', compact('username', 'commissions', 'L1', 'L2', 'referralsL1', 'referralsL2'));
  125. }
  126. }
  127. public function support($code = null)
  128. {
  129. $this->load->model('support_ticket_model', 'Ticket');
  130. if ($code)
  131. {
  132. $ticketData = $this->Ticket->get($code, $this->profile->id);
  133. if (!$ticketData)
  134. {
  135. $this->session->set_flashdata('error', 'There is no support ticket with that code');
  136. redirect(site_url('member/support.html'), 'refresh');
  137. }
  138. $ticket = $ticketData['ticket'];
  139. $messages = $ticketData['messages'];
  140. }
  141. if (!$this->input->is_ajax_request())
  142. {
  143. if ($code)
  144. {
  145. $this->addJavascript(asset('scripts/forms.js'));
  146. $this->layoutData['member_page'] = anchor('member/support.html', 'Support') . ' - Ticket #' . $ticket->id;
  147. $this->loadView('support/member/view', 'My Traffic Value: Support for Member', compact('ticket', 'messages'));
  148. }
  149. else
  150. {
  151. $openTickets = $this->Ticket->getSummary($this->profile->id, false, 'open');
  152. $closedTickets = $this->Ticket->getSummary($this->profile->id, false, 'closed');
  153. $profile = $this->profile;
  154. $this->layoutData['member_page'] = 'Support';
  155. $this->loadView('support/member/index', 'My Traffic Value: Support for Member', compact('openTickets', 'closedTickets', 'profile'));
  156. }
  157. }
  158. else
  159. {
  160. if ($this->form_validation->run('support_reply')) // Defined in form_validation
  161. {
  162. $post = $this->input->post();
  163. $ticketData = null;
  164. if (isset ($post['status']))
  165. {
  166. $ticketData = array(
  167. 'status' => $post['status']
  168. );
  169. }
  170. $messageData = array(
  171. 'ticket_id' => $ticket->id,
  172. 'user_id' => $this->profile->id,
  173. 'message' => $post['message']
  174. );
  175. if ($this->Ticket->store($messageData, $ticketData) === TRUE)
  176. {
  177. $data = array(
  178. 'success' => 'success',
  179. 'html' => '<strong>Thank you for your message!</strong>',
  180. 'redirect' => array(
  181. 'url' => site_url('member/support/' . $code . '.html'),
  182. 'timeout' => 1000
  183. )
  184. );
  185. }
  186. else
  187. {
  188. $data = array(
  189. 'error' => 'Your message was not sent'
  190. );
  191. }
  192. }
  193. else
  194. {
  195. $data = array(
  196. 'errorElements' => array(
  197. 'message' => form_error('message')
  198. )
  199. );
  200. }
  201. echo json_encode($data);
  202. }
  203. }
  204. public function support_add()
  205. {
  206. if (!$this->input->is_ajax_request())
  207. {
  208. $this->addJavascript(asset('scripts/forms.js'));
  209. $this->layoutData['member_page'] = anchor ('member/support.html', 'Support') . ' - New Ticket';
  210. $this->loadView('support/member/new', 'My Traffic Value: Support for Member');
  211. }
  212. else
  213. {
  214. if ($this->form_validation->run('member_support')) // Defined in form_validation
  215. {
  216. $this->load->model('support_ticket_model', 'Ticket');
  217. $code = uniqid();
  218. $post = $this->input->post();
  219. $ticketData = array(
  220. 'code' => $code,
  221. 'user_id' => $this->profile->id,
  222. 'subject' => $post['subject']
  223. );
  224. $messageData = array(
  225. 'user_id' => $this->profile->id,
  226. 'message' => $post['message']
  227. );
  228. if ($this->Ticket->store($messageData, $ticketData) === TRUE)
  229. {
  230. // Send the email to the guest so he/she can refer back to it
  231. $ticketUrl = site_url('member/support/' . $code . '.html');
  232. $this->EmailQueue->store($this->profile->email, 'Support Ticket #' . $ticketData['id'], 'emails/support/ticket_created', compact('ticketUrl'));
  233. $data = array(
  234. 'success' => 'success',
  235. 'html' => '<strong>Thank you for your message!</strong>',
  236. 'redirect' => array(
  237. 'url' => site_url('member/support/' . $code . '.html'),
  238. 'timeout' => 1000
  239. )
  240. );
  241. }
  242. else
  243. {
  244. $data = array(
  245. 'error' => 'Your message was not sent'
  246. );
  247. }
  248. }
  249. else
  250. {
  251. $data = array(
  252. 'errorElements' => array(
  253. 'subject' => form_error('subject'),
  254. 'message' => form_error('message'),
  255. )
  256. );
  257. }
  258. echo json_encode($data);
  259. }
  260. }
  261. public function live_news($filter = 2047, $page = 1, $perpage = 30)
  262. {
  263. $this->load->model('live_news_model', 'LiveNews');
  264. $post = $this->input->post();
  265. if ($post)
  266. $filter = isset($post['check']) ? intval($post['check']) : $filter;
  267. $count = $this->LiveNews->getCount($filter);
  268. // We only want 10 pages of data to start with so restrict it here
  269. // --8<--
  270. $count = min(10 * $perpage, $count);
  271. $page = min(10, $page);
  272. // -->8--
  273. if ($count)
  274. {
  275. $this->lang->load('live_news');
  276. $data = $this->LiveNews->getSubset($filter, $page, $perpage);
  277. $paging = generatePagination(site_url('/member/live_news/' . $filter), $count, $page, $perpage, true);
  278. $hasPages = $count > $perpage;
  279. $feed = $this->load->view('partial/live_news', compact ('data', 'paging', 'hasPages'), true);
  280. }
  281. else $feed = 'Nothing for the selected filters';
  282. if ($this->input->is_ajax_request())
  283. {
  284. echo $feed;
  285. }
  286. else
  287. {
  288. $this->load->model('user_model', 'User');
  289. $totalUsers = $this->User->getActiveUsersCount();
  290. //TODO: Alex change this please
  291. $today_reg_users = $this->LiveNews->getRegisteredTodayCount();
  292. $online_users = $this->LiveNews->getUsersOnlineCount();
  293. $online_guests = $this->LiveNews->getGuestsOnlineCount();
  294. $this->addJavascript(asset('scripts/paging.js'));
  295. $this->addJavascript(asset('scripts/live_news.js'));
  296. $this->layoutData['member_page'] = 'Live News';
  297. $this->loadView('member/live_news', 'My Traffic Value: Live News', compact('today_reg_users', 'online_users', 'online_guests', 'totalUsers', 'feed'));
  298. }
  299. }
  300. public function users_online($page = 1, $perpage = 10)
  301. {
  302. $this->load->model('live_news_model', 'LiveNews');
  303. $this->load->model('referral_model');
  304. $count = $this->LiveNews->getUsersOnlineCount();
  305. if ($count)
  306. {
  307. $data = $this->LiveNews->getUsersOnlineSubset($page, $perpage);
  308. $paging = generatePagination('/member/users_online', $count, $page, $perpage, true);
  309. $hasPages = $count > $perpage;
  310. $online = $this->load->view('partial/users_online', compact ('data', 'paging', 'hasPages'), true);
  311. }
  312. else $online = '';
  313. if ($this->input->is_ajax_request())
  314. {
  315. echo $online;
  316. }
  317. else
  318. {
  319. $this->addJavascript(asset('scripts/paging.js'));
  320. $this->layoutData['member_page'] = anchor('member/live_news.html', 'Live News') . ' - Who is Online';
  321. $this->loadView('member/users_online', 'My Traffic Value: Online Users', compact ('online'));
  322. }
  323. }
  324. public function my_account()
  325. {
  326. $this->load->model('my_account_model', 'Account');
  327. $this->load->model('referral_model', 'Referral');
  328. $this->load->model('shares_model', 'Shares');
  329. $userId = $this->profile->id;
  330. //Summary Data:
  331. //TODO Investment
  332. //TODO Shares
  333. $summary = $this->Account->summary($userId);
  334. //Profile Data:
  335. $profile = $this->Account->profile($userId);
  336. $history = $this->history('all', 1, 30, true);
  337. $this->addJavascript(asset('scripts/account_history.js'));
  338. $this->addJavascript(asset('scripts/paging.js'));
  339. $this->addJavascript(asset('scripts/tabs.js'));
  340. $this->addJavascript(asset('scripts/forms.js'));
  341. $this->addJavascript(asset('scripts/my_account.js'));
  342. $this->addStyleSheet(asset('styles/my_account.css'));
  343. $this->addStyleSheet(asset('styles/cupertino/jquery.ui.all.css'));
  344. $this->addStyleSheet(asset('styles/cupertino/jquery.ui.theme.css'));
  345. $this->addStyleSheet(asset('styles/cupertino/jquery.ui.datepicker.css'));
  346. $this->layoutData['member_page'] = 'My Account';
  347. $this->loadView('member/my_account', 'My Traffic Value - Your Account', compact('summary', 'profile', 'email_not', 'history'));
  348. }
  349. public function history($method = 'all', $page = 1, $perpage = 30, $return = false)
  350. {
  351. $userId = $this->profile->id;
  352. $count = $this->History->getCount($userId, $method, null);
  353. if ($count)
  354. {
  355. $data = $this->History->getSubset($userId, $method, null, $page, $perpage);
  356. $paging = generatePagination(site_url('member/history/' . $method), $count, $page, $perpage, true);
  357. $hasPages = $count > $perpage;
  358. $history = $this->load->view('partial/account_history', compact ('data', 'method', 'paging', 'hasPages'), true);
  359. }
  360. else
  361. $history = 'Nothing for the selected filters';
  362. if ($return)
  363. return $history;
  364. echo $history;
  365. }
  366. //Get Info to Popup about history cashier selected
  367. public function info_history($histId=NULL)
  368. {
  369. if ($this->input->is_ajax_request())
  370. {
  371. /*
  372. $result = $this->Transaction->getById($histId);
  373. $user = $this->PaymentMethod->getAccountForUser($this->profile->id, $result->method);
  374. $mtv = $this->PaymentMethod->getAccountDetails($result->method);
  375. echo $this->loadPartialView('partial/history', compact('result','user', 'mtv'));
  376. */
  377. // Maybe functions above should be reviewed, if they are in other parts or not
  378. $transaction = $this->Transaction->getDetails($histId, $this->profile->id);
  379. if (!$transaction)
  380. show_404();
  381. echo $this->loadPartialView('cashier/partial/transaction', compact('transaction'));
  382. }
  383. else
  384. {
  385. show_404();
  386. }
  387. }
  388. public function blackhole()
  389. {
  390. $this->layoutData['member_page'] = 'Page Under Construction';
  391. $this->loadView('blank', 'My Traffic Value - BLANK');
  392. }
  393. public function investments()
  394. {
  395. $this->layoutData['member_page'] = 'Investments';
  396. $this->loadView('member/investments', 'My Traffic Value - Investment');
  397. }
  398. public function earn_money()
  399. {
  400. $this->layoutData['member_page'] = 'Earn Money';
  401. $this->loadView('member/earn_money', 'My Traffic Value - Earn Money');
  402. }
  403. public function ref_more_info()
  404. {
  405. $username = $this->profile->username;
  406. $this->layoutData['member_page'] = anchor ('member/earn_money.html', 'Earn Money') . ' - ' . anchor('member/referrals.html', 'Referrals') . ' - Information';
  407. $this->loadView('member/referral/more_info', 'My Traffic Value - Referrals - More Info', compact('username'));
  408. }
  409. public function ref_top_referrer($sorting = 'count_l1', $page = 1, $perpage = 20)
  410. {
  411. $this->load->model('user_model', 'User');
  412. $this->load->model('referral_model', 'Referral');
  413. $count = $this->User->getActiveUsersCount();
  414. // Do some checking on the data to be sure
  415. if (in_array ($sorting, array ('count_l1', 'count_l2', 'earnings')) === FALSE)
  416. $sorting = 'count_l1';
  417. $data = $this->Referral->getTopReferrersSubset($sorting, $page, $perpage);
  418. $paging = generatePagination('/member/ref_top_referrer/' . $sorting, $count, $page, $perpage, true);
  419. $hasPages = $count > $perpage;
  420. $referrers = $this->load->view('partial/top_referrers', compact ('data', 'paging', 'sorting', 'hasPages'), true);
  421. if ($this->input->is_ajax_request())
  422. {
  423. echo $referrers;
  424. }
  425. else
  426. {
  427. $this->addJavascript(asset('scripts/paging.js'));
  428. $this->addJavascript(asset('scripts/sortable.js'));
  429. $this->layoutData['member_page'] = anchor ('member/earn_money.html', 'Earn Money') . ' - ' . anchor('member/referrals.html', 'Referrals') . ' - Top Referrers';
  430. $this->loadView('member/referral/top_referrers', 'My Traffic Value - Referrals - Top Referrers', compact('referrers'));
  431. }
  432. }
  433. public function ref_banners()
  434. {
  435. $refUrl = site_url('ref/' . $this->profile->username);
  436. $this->layoutData['member_page'] = anchor ('member/earn_money.html', 'Earn Money') . ' - ' . anchor('member/referrals.html', 'Referrals') . ' - Banners';
  437. $this->loadView('member/referral/banners', 'My Traffic Value - Referrals - Banners', compact('refUrl'));
  438. }
  439. public function ads()
  440. {
  441. $this->addStyleSheet(asset('styles/ads.css'));
  442. $guest = false;
  443. $this->layoutData['member_page'] = 'Advertise';
  444. $this->loadView('common/ads', 'My Traffic Value - Advertise', compact('guest'));
  445. }
  446. //Show The Cashier
  447. public function cashier()
  448. {
  449. $userId = $this->profile->id;
  450. $balances = $this->PaymentMethod->getBalancesList($userId);
  451. $total = 0;
  452. foreach ($balances as $balance)
  453. $total += $balance->balance;
  454. $accounts = dropdown ($this->PaymentMethod->getList(), 'code');
  455. $pendingTransactions = $this->Transaction->getSubsetByUserId($userId, 'pending');
  456. $completedTransactions = $this->Transaction->getSubsetByUserId($userId, 'ok');
  457. $earnings = $this->PaymentMethod->getBalance($userId, 'eb');
  458. $this->addJavascript(asset('scripts/tabs.js'));
  459. $this->addJavascript(asset('scripts/forms.js'));
  460. $this->layoutData['member_page'] = 'Cashier';
  461. $this->loadView('cashier/index', 'My Traffic Value - Cashier', compact('balances', 'total', 'accounts', 'pendingTransactions', 'completedTransactions', 'earnings'));
  462. }
  463. public function transaction($id)
  464. {
  465. if (!$this->input->is_ajax_request())
  466. show_404();
  467. $transaction = $this->Transaction->getDetails($id, $this->profile->id);
  468. if (!$transaction)
  469. show_404();
  470. $accountDetails = null;
  471. $mtvAccountDetails = null;
  472. $transactionDetails = null;
  473. switch ($transaction->method)
  474. {
  475. case 'wu':
  476. $transactionDetails = new WesternUnionDetails($transaction->details);
  477. $userAccount = new WesternUnion($transaction->user);
  478. $systemAccount = new WesternUnion($transaction->system);
  479. break;
  480. case 'bw':
  481. $transactionDetails = new BankWireDetails($transaction->details);
  482. $userAccount = new BankWire($transaction->user);
  483. $systemAccount = new BankWire($transaction->system);
  484. break;
  485. default:
  486. $userAccount = $transaction->user;
  487. $systemAccount = $transaction->system;
  488. }
  489. echo $this->loadPartialView('cashier/partial/transaction', compact('transaction', 'transactionDetails', 'userAccount', 'systemAccount'));
  490. }
  491. // This function allows people to cancel theuir pending transaction
  492. public function cancel_transaction($id)
  493. {
  494. $transaction = $this->Transaction->getDetails($id, $this->profile->id);
  495. if ($transaction)
  496. {
  497. $this->Transaction->update($id, 'cancel');
  498. $this->session->set_flashdata('success', 'Transaction successfully cancelled');
  499. redirect('member/cashier.html');
  500. }
  501. else show_error('Forbidden', 403);
  502. }
  503. public function cashier_account($code)
  504. {
  505. if ($code == 'eb')
  506. show_error('Forbidden', 403); // failsafe
  507. $this->load->model('user_model', 'User');
  508. $listCountries = $this->User->getCountries();
  509. $userId = $this->profile->id;
  510. $account = $this->PaymentMethod->getAccountForUser($userId, $code);
  511. if (!$account->enabled)
  512. {
  513. $this->session->set_flashdata('error', 'Sorry but <strong>' . $account->name . '</strong> interaction has not been enabled');
  514. redirect('member/cashier.html');
  515. }
  516. if ($account->account == null || $account->locked == 0) // Add or edit
  517. {
  518. if ($this->input->is_ajax_request())
  519. {
  520. if ($this->form_validation->run($code . '_account') === true)
  521. {
  522. $post = $this->input->post();
  523. switch ($code)
  524. {
  525. case 'wu':
  526. $accountData = new WesternUnion($post);
  527. $accountData = $accountData->__toString();
  528. break;
  529. case 'bw':
  530. $accountData = new BankWire($post);
  531. $accountData = $accountData->__toString();
  532. break;
  533. default:
  534. $accountData = $code == 'lr' ? strtoupper($post['account']) : strtolower($post['account']);
  535. }
  536. if ($this->PaymentMethod->set($userId, $code, $accountData))
  537. {
  538. $this->session->set_flashdata('success', 'Successfully updated your <strong>' . $account->name . '</strong> account');
  539. $data = array(
  540. 'success' => 'success',
  541. 'redirect' => array(
  542. 'url' => site_url('member/deposit/'.$code.'.html')
  543. )
  544. );
  545. }
  546. else
  547. {
  548. $data = array(
  549. 'error' => 'An unknown error has occurred'
  550. );
  551. }
  552. }
  553. else
  554. {
  555. $data = array(
  556. 'errorElements' => $this->form_validation->error_array()
  557. );
  558. }
  559. echo json_encode($data);
  560. return;
  561. }
  562. else
  563. {
  564. $this->layoutData['member_page'] = anchor ('member/cashier.html', 'Cashier') . ' - Add/Edit account';
  565. $countries = dropdown($listCountries, 'name');
  566. $country = $this->profile->country;
  567. $this->addJavascript(asset('scripts/forms.js'));
  568. $this->loadView('cashier/account', 'My Traffic Value - Cashier', compact('code', 'account', 'countries', 'country'));
  569. }
  570. }
  571. else // All set and locked so go away
  572. {
  573. $this->session->set_flashdata('info', 'Your <strong>' . $account->name . '</strong> account is locked and cannot be changed');
  574. redirect('member/cashier.html');
  575. }
  576. }
  577. public function cashier_deposit($code)
  578. {
  579. if ($code == 'eb')
  580. show_error('Forbidden', 403); // failsafe
  581. $this->load->model('user_model', 'User');
  582. $listCountries = $this->User->getCountries();
  583. $userId = $this->profile->id;
  584. $account = $this->PaymentMethod->getAccountForUser($userId, $code);
  585. if (!$account->enabled)
  586. {
  587. $this->session->set_flashdata('error', 'Sorry but <strong>' . $account->name . '</strong> interaction has not been enabled');
  588. redirect('member/cashier.html');
  589. }
  590. if ($account->account)
  591. {
  592. $accounts = $this->PaymentMethod->getAccountDetails($code,'in');
  593. $depositAccount = $accounts[0];
  594. if ($this->input->is_ajax_request())
  595. {
  596. $post = $this->input->post();
  597. $data = null;
  598. if (count ($accounts) > 1)
  599. {
  600. $accountId = isset($post['account_id']) ? intval($post['account_id']) : null;
  601. if ($accountId)
  602. {
  603. // We already have all the accounts at hand so no need to fetch it again
  604. foreach ($accounts as $acct)
  605. {
  606. if ($acct->id == $accountId)
  607. {
  608. $depositAccount = $acct;
  609. break;
  610. }
  611. }
  612. }
  613. }
  614. // We have to set this rule on the fly for the limits
  615. $this->form_validation->set_rules('amount', 'Amount', 'trim|required|greater_than[' . ($depositAccount->minimum - 0.01) . ']|xss_clean');
  616. if ($code == 'bw')
  617. {
  618. $this->form_validation->set_rules('memo', 'Memo Line', 'trim|required|xss_clean');
  619. }
  620. else if ($code == 'wu')
  621. {
  622. $this->form_validation->set_rules('city', 'City', 'trim|required|xss_clean');
  623. $this->form_validation->set_rules('country', 'Country', 'trim|required|xss_clean');
  624. $this->form_validation->set_rules('mtcn', 'MTCN No.', 'trim|required|xss_clean|numeric|min_length[6]|max_length[14]');
  625. }
  626. if ($this->form_validation->run() === true)
  627. {
  628. $amount = $post['amount'];
  629. if (!isset ($post['currency']))
  630. $post['currency'] = 'USD'; // Set the currency to USD by default
  631. $depositData = array(
  632. 'user_id' => $userId,
  633. 'method' => $code,
  634. 'account_id' => $depositAccount->id,
  635. 'gross_amount' => $amount,
  636. 'identifier' => $this->Transaction->identifier()
  637. );
  638. switch ($code)
  639. {
  640. case 'bw':
  641. $depositDetails = new BankWireDetails($post);
  642. $depositData['details'] = $depositDetails->__toString();
  643. break;
  644. case 'wu':
  645. $depositDetails = new WesternUnionDetails($post);
  646. $depositData['details'] = $depositDetails->__toString();
  647. break;
  648. default:
  649. $depositDetails = null;
  650. }
  651. if ($transactionId = $this->Transaction->addDeposit($depositData))
  652. {
  653. $data = array(
  654. 'success' => 'success',
  655. 'html' => $this->loadPartialView('cashier/deposit_finish', compact('code', 'account', 'depositDetails', 'depositData', 'depositAccount', 'transactionId'))
  656. );
  657. }
  658. else
  659. {
  660. $data = array(
  661. 'error' => 'An unknown error has occurred'
  662. );
  663. }
  664. }
  665. else
  666. {
  667. $data = array(
  668. 'errorElements' => $this->form_validation->error_array()
  669. );
  670. }
  671. echo json_encode($data);
  672. return;
  673. }
  674. else
  675. {
  676. $this->layoutData['member_page'] = anchor ('member/cashier.html', 'Cashier') . ' - Deposit';
  677. $fees = $this->PaymentMethod->getLatestBillDetails($code);
  678. $countries = dropdown($listCountries, 'name');
  679. $this->addJavascript(asset('scripts/forms.js'));
  680. $this->addJavascript(asset('scripts/cashier.js'));
  681. $this->addStyleSheet(asset('styles/depositmethods.css'));
  682. $depositMethodInfo = $this->loadPartialView('cashier/partial/deposit_method_info', compact('code', 'depositAccount', 'fees'));
  683. $this->loadView('cashier/deposit', 'My Traffic Value - Cashier', compact('code', 'account', 'accounts', 'depositAccount', 'fees', 'countries', 'depositMethodInfo'));
  684. }
  685. }
  686. else // huho
  687. {
  688. $this->session->set_flashdata('error', 'Your <strong>' . $account->name . '</strong> account has not been set up');
  689. redirect('member/account/' . $code . '.html');
  690. }
  691. }
  692. public function cashier_email_instructions($code, $accountId = 0)
  693. {
  694. if ($this->input->is_ajax_request())
  695. {
  696. if ($accountId > 0)
  697. $depositAccount = $this->PaymentMethod->getAccountDetailsById($accountId);
  698. else
  699. {
  700. $accounts = $this->PaymentMethod->getAccountDetails($code);
  701. $depositAccount = $accounts[0];
  702. }
  703. $fees = $this->PaymentMethod->getFeeData($code, 'deposit');
  704. switch ($code)
  705. {
  706. case 'bw':
  707. $emailSubject = 'Bank Wire Deposit Instructions';
  708. $depositDetails = new BankWire($depositAccount->details);
  709. break;
  710. case 'wu':
  711. $emailSubject = 'Western Union Deposit Instructions';
  712. $depositDetails = new WesternUnion($depositAccount->details);
  713. break;
  714. default:
  715. return; // Don't want to be here if not BW or WU
  716. }
  717. $this->EmailQueue->store($this->profile->email, $emailSubject, 'emails/cashier/deposit_instructions_' . $code, compact('depositAccount', 'depositDetails', 'fees'));
  718. }
  719. }
  720. public function cashier_cashout($code)
  721. {
  722. if ($code == 'eb')
  723. show_error('Forbidden', 403); // failsafe
  724. $userId = $this->profile->id;
  725. $account = $this->PaymentMethod->getAccountForUser($userId, $code);
  726. $balance = $this->PaymentMethod->getBalance($userId, $code);
  727. if (!$account->enabled)
  728. {
  729. $this->session->set_flashdata('error', 'Sorry but <strong>' . $account->name . '</strong> interaction has not been enabled');
  730. redirect('member/cashier.html');
  731. }
  732. if ($balance <= 0)
  733. {
  734. $this->session->set_flashdata('error', 'Sorry but you do not have funds in your <strong>' . $account->name . '</strong> account');
  735. redirect('member/cashier.html');
  736. }
  737. if ($account->account)
  738. {
  739. if ($this->input->is_ajax_request())
  740. {
  741. $post = $this->input->post();
  742. $data = null;
  743. // We have to set this rule on the fly for the limits
  744. $this->form_validation->set_rules('amount', 'Amount', 'trim|required|xss_clean');
  745. $this->form_validation->set_rules('day', 'Date of Birth', 'trim|required|callback_valid_dob');
  746. $this->form_validation->set_rules('month', 'Date of Birth', 'trim|required|callback_valid_dob');
  747. $this->form_validation->set_rules('year', 'Date of Birth', 'trim|required|callback_valid_dob');
  748. // If requesting WU we need to ask for City and Country (!!)
  749. if ($code == 'wu')
  750. {
  751. $this->form_validation->set_rules('city', 'City', 'trim|required|xss_clean');
  752. $this->form_validation->set_rules('country', 'Country', 'trim|required|xss_clean');
  753. }
  754. if ($this->form_validation->run() === true)
  755. {
  756. // Amount validation requires more options:
  757. $amount = roundDown($post['amount'], 2);
  758. $mtvAccounts = $this->PaymentMethod->getAccountDetails($code,'out');
  759. $mtvAccount = $mtvAccounts[0];
  760. $min = $mtvAccount->minimum;
  761. $max = ($balance > $mtvAccount->maximum) ? $mtvAccount->maximum : $balance;
  762. if($amount >= $min AND $amount <= $max)
  763. {
  764. $cashoutData = array(
  765. 'user_id' => $userId,
  766. 'gross_amount' => $amount,
  767. 'method' => $code,
  768. 'identifier' => $this->Transaction->identifier()
  769. );
  770. if ($code == 'wu')
  771. {
  772. $cashoutDetails = new WesternUnionDetails($post);
  773. $cashoutData['details'] = $cashoutDetails->__toString();
  774. }
  775. if ($transactionId = $this->Transaction->addCashout($cashoutData))
  776. {
  777. $data = array(
  778. 'success' => 'success',
  779. 'balance' => money($this->ion_auth->select('balance')->user()->row()->balance), // For updating Balance shown to user
  780. 'html' => $this->loadPartialView('cashier/cashout_finish', compact('code', 'account', 'cashoutDetails', 'cashoutData', 'transactionId'))
  781. );
  782. }
  783. else
  784. {
  785. $data = array(
  786. 'error' => 'An unknown error has occurred'
  787. );
  788. }
  789. }
  790. else
  791. {
  792. $data = array(
  793. 'errorElements' => array('amount' => 'Out of limits Amount')
  794. );
  795. }
  796. }
  797. else
  798. {
  799. $data = array(
  800. 'errorElements' => $this->form_validation->error_array()
  801. );
  802. }
  803. echo json_encode($data);
  804. }
  805. else
  806. {
  807. $this->layoutData['member_page'] = anchor ('member/cashier.html', 'Cashier') . ' - Cashout';
  808. // We have to fix a bit this, mtvAccount and depositAccount are the same in different parts...
  809. $mtvAccounts = $this->PaymentMethod->getAccountDetails($code, 'out');
  810. $mtvAccount = $mtvAccounts[0]; //Needed to indicate maximum and minimum
  811. $depositAccount = $mtvAccount;
  812. $countries = null;
  813. if ($code == 'wu')
  814. {
  815. $this->load->model('user_model', 'User');
  816. $listCountries = $this->User->getCountries();
  817. $countries = dropdown($listCountries, 'name');
  818. }
  819. $this->addJavascript(asset('scripts/forms.js'));
  820. $this->addJavascript(asset('scripts/cashier.js'));
  821. $this->addStyleSheet(asset('styles/depositmethods.css'));
  822. $fees = $this->PaymentMethod->getLatestBillDetails($code);
  823. $depositMethodInfo = $this->loadPartialView('cashier/partial/deposit_method_info', compact('code', 'depositAccount', 'fees'));
  824. $this->loadView('cashier/cashout', 'My Traffic Value - Cashier', compact('code', 'account', 'fees', 'countries', 'cashoutMethodInfo', 'balance', 'mtvAccount','depositMethodInfo'));
  825. }
  826. }
  827. else // huho
  828. {
  829. $this->session->set_flashdata('error', 'Your <strong>' . $account->name . '</strong> account has not been set up');
  830. redirect('member/account/' . $code . '.html');
  831. }
  832. }
  833. public function cashier_account_details($id)
  834. {
  835. if ($this->input->is_ajax_request())
  836. {
  837. $account = $this->PaymentMethod->getAccountDetailsById($id);
  838. echo $this->loadPartialView('cashier/details', compact('account'));
  839. }
  840. else
  841. {
  842. show_404();
  843. }
  844. }
  845. public function transfer_earnings()
  846. {
  847. if ($this->input->is_ajax_request())
  848. {
  849. if ($this->form_validation->run())
  850. {
  851. $post = $this->input->post();
  852. $data = array(
  853. 'user_id' => $this->profile->id,
  854. 'amount' => $post['amount'],
  855. 'method' => $post['account']
  856. );
  857. if ($this->Transfer->add($data))
  858. {
  859. $this->session->set_flashdata('success', 'Your transfer has been recorded');
  860. $data = array(
  861. 'success' => 'Saved',
  862. 'redirect' => array(
  863. 'url' => site_url('member/cashier.html')
  864. )
  865. );
  866. }
  867. else
  868. {
  869. $data = array(
  870. 'error' => 'Errrr, not worked'
  871. );
  872. }
  873. }
  874. else
  875. {
  876. $data = array(
  877. 'errorElements' => $this->form_validation->error_array()
  878. );
  879. }
  880. echo json_encode($data);
  881. }
  882. }
  883. /**
  884. * Used to return a valid date of birth from Database. It needs to construct the
  885. * rule for year, month and day
  886. *
  887. * @return boolean
  888. */
  889. function valid_dob()
  890. {
  891. $dob = $this->input->post('year') . '-' . $this->input->post('month') . '-' . $this->input->post('day');
  892. if (strtotime($dob) != strtotime($this->profile->date_of_birth))
  893. {
  894. $this->form_validation->set_message('valid_dob', '* invalid');
  895. return FALSE;
  896. }
  897. return true;
  898. }
  899. public function lr_account_check($param)
  900. {
  901. if (!preg_match('/^[u|x]\d{2,8}$/i', $param))
  902. {
  903. $this->form_validation->set_message('lr_account_check', '* incorrect - use Uxxxxxxxx');
  904. return false;
  905. }
  906. if ($this->PaymentMethod->checkAccountExists('lr', $this->profile->id, $param))
  907. {
  908. $this->form_validation->set_message('lr_account_check', '* incorrect - already in use');
  909. return false;
  910. }
  911. return true;
  912. }
  913. public function ap_account_check($param)
  914. {
  915. if ($this->PaymentMethod->checkAccountExists('ap', $this->profile->id, $param))
  916. {
  917. $this->form_validation->set_message('ap_account_check', '* incorrect - already in use');
  918. return false;
  919. }
  920. return true;
  921. }
  922. function valid_earnings($param)
  923. {
  924. $userId = $this->profile->id;
  925. $earnings = $this->PaymentMethod->getBalance($userId, 'eb');
  926. if ((float)$param < 0.00001 || (float)$param > (float)$earnings)
  927. {
  928. $this->form_validation->set_message('valid_earnings', '* incorrect');
  929. return FALSE;
  930. }
  931. return true;
  932. }
  933. //FAQ
  934. public function faq()
  935. {
  936. $this->addJavascript(asset('scripts/faq.js'));
  937. $this->addJavascript(asset('scripts/forum/forum.js'));
  938. $this->load->library('text_format');
  939. $this->load->model('faq_model','Faq');
  940. $isAdmin = $this->ion_auth->is_admin();
  941. if ($isAdmin)
  942. $this->addJavascript(asset('scripts/forms.js'));
  943. $faqs = $this->Faq->getFaqs();
  944. $guest = false;
  945. $this->layoutData['member_page'] = 'FAQ';
  946. $this->loadView('common/faq', 'My Traffic Value: FAQ', compact('guest','faqs','isAdmin'));
  947. }
  948. public function add_edit_faq($faqId = NULL)
  949. {
  950. if (!$this->ion_auth->is_admin())
  951. show_error("Forbidden", 403);
  952. if (!$this->input->is_ajax_request())
  953. {
  954. show_404();
  955. }
  956. else
  957. {
  958. $this->load->model('faq_model','Faq');
  959. if ($post = $this->input->post())
  960. {
  961. if ($this->form_validation->run('member/add_edit_faq') === TRUE)
  962. {
  963. $faqData = array(
  964. 'title' => strip_tags($post['title']),
  965. 'text' => strip_tags($post['text']),
  966. 'date' => now()
  967. );
  968. if($faqId == NULL) //Added new FAQ
  969. {
  970. if ($this->Faq->storeFaq($faqData))
  971. {
  972. $this->session->set_flashdata('success', 'FAQ successfully added');
  973. $data = array(
  974. 'success' => 'Saved',
  975. 'redirect' => array(
  976. 'url' => site_url('member/faq.html')
  977. )
  978. );
  979. }
  980. else
  981. {
  982. $data = array(
  983. 'error' => 'Error storing FAQ'
  984. );
  985. }
  986. }
  987. else //Updated FAQ
  988. {
  989. if ($this->Faq->updateFaq($faqId, $faqData))
  990. {
  991. $this->session->set_flashdata('success', 'FAQ successfully updated');
  992. $data = array(
  993. 'success' => 'Saved',
  994. 'redirect' => array(
  995. 'url' => site_url('member/faq.html')
  996. )
  997. );
  998. }
  999. else
  1000. {
  1001. $data = array(
  1002. 'error' => 'Error updating FAQ'
  1003. );
  1004. }
  1005. }
  1006. }
  1007. else
  1008. {
  1009. $data = array(
  1010. 'errorElements' => $this->form_validation->error_array()
  1011. );
  1012. }
  1013. echo json_encode($data);
  1014. }
  1015. else
  1016. {
  1017. $this->load->library('text_format');
  1018. $smiley_table = $this->text_format->add_smileys(asset('images/smileys'), 'text', 8);
  1019. $faq = ($faqId) ? $this->Faq->getFaq($faqId) : NULL;
  1020. echo $this->loadPartialView('partial/add_edit_faq', compact('smiley_table','faq'));
  1021. }
  1022. }
  1023. }
  1024. public function delete_faq($faqId)
  1025. {
  1026. if (!$this->ion_auth->is_admin())
  1027. show_error("Forbidden", 403);
  1028. $this->load->model('faq_model','Faq');
  1029. $faq = $this->Faq->getFaq($faqId);
  1030. if (!$faq)
  1031. show_404();
  1032. if ($this->Faq->deleteFaq($faqId))
  1033. {
  1034. $this->session->set_flashdata('success', 'FAQ deleted');
  1035. }
  1036. else
  1037. {
  1038. $this->session->set_flashdata('error', 'FAQ not deleted');
  1039. }
  1040. $faqUrl = site_url('member/faq.html');
  1041. redirect($faqUrl);
  1042. }
  1043. }