PageRenderTime 43ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/application/controllers/main.php

https://bitbucket.org/justin_anastos/coin_flip_game
PHP | 515 lines | 403 code | 90 blank | 22 comment | 40 complexity | 67d823e7a7ebe6ae7b5fab6df20c0a02 MD5 | raw file
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. class Main extends MY_Controller
  3. {
  4. public function __construct()
  5. {
  6. parent::__construct();
  7. $referrerId = get_cookie('ref');
  8. $referrerData = $referrerId ? $this->ion_auth->user($referrerId)->row() : null;
  9. $this->layoutData['registerForm'] = $this->loadPartialView('partial/register', compact('referrerData'));
  10. $this->layoutData['loginForm'] = $this->loadPartialView('partial/login');
  11. $this->layoutData['forgotForm'] = $this->loadPartialView('partial/forgot');
  12. $this->layoutData['activationForm'] = $this->loadPartialView('partial/activation');
  13. $this->load->driver('cache', array('adapter' => 'file'));
  14. $this->load->model('investment_model', 'Investment');
  15. $this->load->model('result_model', 'Result');
  16. //$this->output->enable_profiler(true);
  17. }
  18. public function index()
  19. {
  20. if ($this->ion_auth->logged_in())
  21. redirect(site_url('member.html'), 'refresh');
  22. $this->load->model('user_model', 'User');
  23. $usersCount = $this->User->getActiveUsersCount();
  24. $trafficValue = $this->User->getProvenTrafficValue();
  25. $this->loadView('start', 'My Traffic Value', compact('usersCount', 'trafficValue'));
  26. }
  27. public function referral($username)
  28. {
  29. // Set referrer cookie here and redirect to the index page
  30. // only if not already set
  31. if (!get_cookie('ref'))
  32. {
  33. $refData = $this->ion_auth->where('username', $username)->limit(1, 0)->users()->row();
  34. if ($refData)
  35. {
  36. $cookie = array(
  37. 'name' => 'ref',
  38. 'value' => $refData->id,
  39. 'expire' => '86500'
  40. );
  41. $this->input->set_cookie($cookie);
  42. }
  43. }
  44. redirect ('/', 'refresh');
  45. }
  46. public function languages()
  47. {
  48. if (!$this->input->is_ajax_request())
  49. {
  50. show_404(); // prevents direct access to this function - Request has to be AJAX
  51. }
  52. $this->setLayout(null);
  53. echo $this->loadPartialView('languages');
  54. }
  55. public function contact()
  56. {
  57. if (!$this->input->is_ajax_request())
  58. {
  59. $this->loadView('contact', 'My Traffic Value: Contact Form');
  60. }
  61. else
  62. {
  63. $data = null;
  64. if ($this->form_validation->run('contact')) //Defined in form_validation
  65. {
  66. $this->load->model('contact_model', 'Contact');
  67. $post = $this->input->post();
  68. $contactData = array(
  69. 'email' => $post['email'],
  70. 'name' => $post['name'],
  71. 'subject' => $post['subject'],
  72. 'message' => $post['message']
  73. );
  74. if ($this->Contact->store($contactData)===TRUE)
  75. {
  76. $data = array(
  77. 'success' => 'success',
  78. 'html' => '<strong>Thank you for your message!</strong>'
  79. );
  80. }
  81. else
  82. {
  83. $data = array(
  84. 'error' => 'Your message was not sent'
  85. );
  86. }
  87. }
  88. else
  89. {
  90. $data = array(
  91. 'errorElements' => array(
  92. 'name' => form_error('name'), //It must take all errors separately
  93. 'email' => form_error('email'),
  94. 'subject' => form_error('subject'),
  95. 'message' => form_error('message')
  96. )
  97. );
  98. }
  99. echo json_encode($data);
  100. }
  101. }
  102. public function support($code = null)
  103. {
  104. if ($this->ion_auth->logged_in())
  105. {
  106. // Force logged in users to use the proper support features
  107. redirect(site_url('member/support.html'), 'refresh');
  108. }
  109. if ($code)
  110. {
  111. $this->load->model('support_ticket_model', 'Ticket');
  112. $ticketData = $this->Ticket->get($code);
  113. if (!$ticketData)
  114. {
  115. $this->session->set_flashdata('error', 'There is no support ticket with that code');
  116. redirect(site_url('support.html'), 'refresh');
  117. }
  118. $ticket = $ticketData['ticket'];
  119. $messages = $ticketData['messages'];
  120. }
  121. if (!$this->input->is_ajax_request())
  122. {
  123. if ($code)
  124. $this->loadView('support/guest/view', 'My Traffic Value: Support for Guest', compact('ticket', 'messages'));
  125. else $this->loadView('support/guest/index', 'My Traffic Value: Support for Guest');
  126. }
  127. else
  128. {
  129. $data = null;
  130. if ($code)
  131. {
  132. if ($this->form_validation->run('support_reply')) // Defined in form_validation
  133. {
  134. $post = $this->input->post();
  135. $ticketData = null;
  136. if (isset ($post['status']))
  137. {
  138. $ticketData = array(
  139. 'status' => $post['status']
  140. );
  141. }
  142. $messageData = array(
  143. 'ticket_id' => $ticket->id,
  144. 'message' => $post['message']
  145. );
  146. if ($this->Ticket->store($messageData, $ticketData) === TRUE)
  147. {
  148. $data = array(
  149. 'success' => 'success',
  150. 'html' => '<strong>Thank you for your message!</strong>',
  151. 'redirect' => array(
  152. 'url' => site_url('support/' . $code . '.html'),
  153. 'timeout' => 1000
  154. )
  155. );
  156. }
  157. else
  158. {
  159. $data = array(
  160. 'error' => 'Your message was not sent'
  161. );
  162. }
  163. }
  164. else
  165. {
  166. $data = array(
  167. 'errorElements' => array(
  168. 'message' => form_error('message')
  169. )
  170. );
  171. }
  172. }
  173. else
  174. {
  175. if ($this->form_validation->run('support')) // Defined in form_validation
  176. {
  177. $this->load->model('support_ticket_model', 'Ticket');
  178. $code = uniqid();
  179. $post = $this->input->post();
  180. $ticketData = array(
  181. 'code' => $code,
  182. 'email' => $post['email'],
  183. 'subject' => $post['subject']
  184. );
  185. $messageData = array(
  186. 'message' => $post['message']
  187. );
  188. if ($this->Ticket->store($messageData, $ticketData) === TRUE)
  189. {
  190. $this->load->model('email_model', 'EmailQueue');
  191. // Send the email to the guest so he/she can refer back to it
  192. $ticketUrl = site_url('support/' . $code . '.html');
  193. $this->EmailQueue->store($post['email'], 'Support Ticket #' . $ticketData['id'], 'emails/support/ticket_created.php' , compact('ticketUrl'));
  194. $data = array(
  195. 'success' => 'success',
  196. 'html' => $this->loadPartialView('support/guest/created', compact('code'))
  197. );
  198. }
  199. else
  200. {
  201. $data = array(
  202. 'error' => 'Your message was not sent'
  203. );
  204. }
  205. }
  206. else
  207. {
  208. $data = array(
  209. 'errorElements' => array(
  210. 'email' => form_error('email'),
  211. 'subject' => form_error('subject'),
  212. 'message' => form_error('message')
  213. )
  214. );
  215. }
  216. }
  217. echo json_encode($data);
  218. }
  219. }
  220. public function blackhole()
  221. {
  222. $this->session->set_flashdata('info', 'Page is not yet available');
  223. redirect('/');
  224. }
  225. //About us
  226. public function aboutus()
  227. {
  228. $guest = !$this->ion_auth->logged_in();
  229. if (!$guest)
  230. $this->__memberPageSetup('About Us');
  231. $this->loadView('common/aboutus', 'My Traffic Value: About Us', compact('guest'));
  232. }
  233. //Advertise
  234. public function ads()
  235. {
  236. $this->addStyleSheet(asset('styles/ads.css'));
  237. $guest = !$this->ion_auth->logged_in();
  238. if (!$guest)
  239. $this->__memberPageSetup('Adversising');
  240. $this->loadView('common/ads', 'My Traffic Value: Advertising', compact('guest'));
  241. }
  242. //Terms and conditions
  243. public function terms()
  244. {
  245. // If there is a logged in user then we need to load a different template
  246. // which comes with different data to be displayed
  247. $guest = !$this->ion_auth->logged_in();
  248. if (!$guest)
  249. $this->__memberPageSetup('Terms and Conditions');
  250. $this->loadView('common/terms', 'My Traffic Value: Terms and Conditions', compact('guest'));
  251. }
  252. //Deposit Methods
  253. public function depositmethods()
  254. {
  255. $this->addStyleSheet(asset('styles/depositmethods.css'));
  256. $guest = !$this->ion_auth->logged_in();
  257. if (!$guest)
  258. $this->__memberPageSetup('Deposit Methods');
  259. $this->load->model('payment_method_model', 'PaymentMethod');
  260. $accounts = array();
  261. $accountList = $this->PaymentMethod->getList();
  262. foreach ($accountList as $account)
  263. $accounts[$account->code] = $this->PaymentMethod->getLatestBillDetails($account->code);
  264. $this->loadView('common/depositmethods', 'My Traffic Value: Deposit Methods', compact('guest', 'accounts'));
  265. }
  266. //Results
  267. public function results()
  268. {
  269. $this->addStyleSheet(asset('styles/results.css'));
  270. $this->addJavascript(asset('scripts/paging.js'));
  271. $guest = !$this->ion_auth->logged_in();
  272. if (!$guest)
  273. $this->__memberPageSetup('Results');
  274. $results = $this->result_page(1, 5, true);
  275. $this->loadView('results/index', 'My Traffic Value: Results', compact('guest', 'results'));
  276. }
  277. public function result_page($page = 1, $perPage = 5, $return = false)
  278. {
  279. $count = $this->Result->getResultCount();
  280. $data = $this->Result->getResultSubset($page);
  281. $paging = generatePagination(site_url('main/result_page'), $count, $page, 5, true);
  282. $hasPages = $count > 5;
  283. $results = $this->load->view('results/partial/results', compact ('data', 'method', 'paging', 'hasPages'), true);
  284. if ($return)
  285. return $results;
  286. echo $results;
  287. }
  288. public function result_details($date)
  289. {
  290. $data = $this->Result->card_data($date, true);
  291. if (!$data)
  292. {
  293. $this->session->set_flashdata('error', 'No result for that date');
  294. redirect('results.html');
  295. }
  296. $this->addStyleSheet(asset('styles/results.css'));
  297. $this->addJavascript(asset('scripts/paging.js'));
  298. $guest = !$this->ion_auth->logged_in();
  299. if (!$guest)
  300. $this->__memberPageSetup(anchor('results.html', 'Results') . ' - ' . date("l jS, F Y", $data->date));
  301. $this->loadView('results/details', 'My Traffic Value: Results - ' . date("d/m/Y", $data->date), compact('guest', 'data', 'date'));
  302. }
  303. public function fast_track_details($date, $page = 1, $perPage = 15)
  304. {
  305. $firstLoad = false;
  306. if ($page == 0)
  307. {
  308. // little hack
  309. $page = 1;
  310. $firstLoad = true;
  311. }
  312. $count = $this->Result->getFastTrackCount($date);
  313. $data = $this->Result->getFastTrackSubset($date, $page, $perPage);
  314. $paging = generatePagination(site_url('main/fast_track_details/' . $date), $count, $page, $perPage, true);
  315. $hasPages = $count > $perPage;
  316. $fastTrack = $this->load->view('results/partial/fast_track_details', compact ('data', 'method', 'paging', 'hasPages'), true);
  317. if (!$firstLoad)
  318. echo $fastTrack;
  319. else $this->load->view('results/fast_track_details', compact ('fastTrack'));
  320. }
  321. public function invest_log($cyclerId = 1)
  322. {
  323. $roundData = $this->Investment->getCyclerData($cyclerId);
  324. if (!$roundData || is_null($roundData->start_date))
  325. {
  326. $this->session->set_flashdata('error', 'Sorry this round has not been found');
  327. redirect('investment/log.html');
  328. }
  329. $guest = !$this->ion_auth->logged_in();
  330. if (!$guest)
  331. $this->__memberPageSetup('Invest Log');
  332. $lastRound = $this->Investment->lastOpenRound();
  333. $active = $this->Investment->getActiveCycler();
  334. $paid110 = $this->Investment->getCycledAmount($cyclerId);
  335. $paid125 = $this->Investment->getDailyPaidAmount($cyclerId);
  336. $participants = $this->Investment->getParticipants($cyclerId);
  337. $invested = $this->Investment->getTotalInvested($cyclerId);
  338. $longest = $this->Investment->getLongest($cyclerId);
  339. $log110 = $this->log110($cyclerId, 1, 20, true);
  340. $log125 = $this->log125($cyclerId, 1, 20, true);
  341. $this->addStyleSheet(asset('styles/investments.css'));
  342. $this->addJavascript(asset('scripts/invest.js'));
  343. $this->addJavascript(asset('scripts/paging.js'));
  344. $this->loadView('investment/log', 'My Traffic Value: Invest Log', compact('guest', 'roundData', 'active', 'lastRound', 'paid110', 'paid125', 'participants', 'invested', 'longest', 'log110', 'log125'));
  345. }
  346. public function log110($cyclerId, $page = 1, $perPage = 20, $return = false)
  347. {
  348. $count = $this->Investment->getCycledUnitsCount($cyclerId);
  349. $data = $this->Investment->getCycledUnitsSubset($cyclerId, $page, $perPage);
  350. $paging = generatePagination(site_url('main/log110/' . $cyclerId), $count, $page, $perPage, true);
  351. $hasPages = $count > $perPage;
  352. $investments = $this->load->view('investment/partial/log110', compact ('data', 'method', 'paging', 'hasPages'), true);
  353. if ($return)
  354. return $investments;
  355. echo $investments;
  356. }
  357. public function log125($cyclerId, $page = 1, $perPage = 20, $return = false)
  358. {
  359. $count = $this->Investment->getDailyPayCount($cyclerId);
  360. $data = $this->Investment->getDailyPaySubset($cyclerId, $page, $perPage);
  361. $paging = generatePagination(site_url('main/log125/' . $cyclerId), $count, $page, $perPage, true);
  362. $hasPages = $count > $perPage;
  363. $dailypay = $this->load->view('investment/partial/log125', compact ('data', 'method', 'paging', 'hasPages'), true);
  364. if ($return)
  365. return $dailypay;
  366. echo $dailypay;
  367. }
  368. //Traffic Value
  369. public function trafficvalue()
  370. {
  371. $this->addStyleSheet(asset('styles/trafficvalue.css'));
  372. $guest = !$this->ion_auth->logged_in();
  373. if (!$guest)
  374. $this->__memberPageSetup('Results');
  375. $this->load->model('user_model', 'User');
  376. $levelsValueData = $this->User->getLevelsValueData();
  377. $this->layoutData['member_page'] = 'Traffic Value';
  378. $this->loadView('common/trafficvalue', 'My Traffic Value: Traffic Value', compact('guest', 'levelsValueData'));
  379. }
  380. //COI Future Business Group Ltd
  381. public function coi()
  382. {
  383. echo $this->loadPartialView('common/coi');
  384. }
  385. /**
  386. * Loading Pop-up view of arranging a meeting Main > Arrange a meeting
  387. */
  388. public function meeting()
  389. {
  390. echo $this->loadPartialView('common/meeting');
  391. }
  392. //Graph for Money Flow
  393. public function moneyflow()
  394. {
  395. echo $this->loadPartialView('common/moneyflow');
  396. }
  397. //FAQ
  398. public function faq()
  399. {
  400. $this->addJavascript(asset('scripts/faq.js'));
  401. $this->load->model('faq_model','Faq');
  402. $faqs = $this->Faq->getFaqs();
  403. $this->load->library('text_format');
  404. $guest = !$this->ion_auth->logged_in();
  405. if (!$guest)
  406. $this->__memberPageSetup('FAQ');
  407. $isAdmin = false;
  408. $this->loadView('common/faq', 'My Traffic Value: FAQ', compact('guest','faqs','isAdmin'));
  409. }
  410. // This will be called to set up a page viewed from a member's eye
  411. private function __memberPageSetup($title)
  412. {
  413. $this->layoutData['member_page'] = $title;
  414. $this->profile = $this->ion_auth->user()->row();
  415. $this->setLayout('layout/member');
  416. $this->layoutData['name'] = $this->profile->username;
  417. // If admin, link to admin zone:
  418. if ($this->ion_auth->is_admin())
  419. $this->layoutData['name'] .= ' - ' . anchor('admin', 'Admin');
  420. }
  421. public function video()
  422. {
  423. echo $this->loadPartialView('partial/video');
  424. }
  425. }