Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- use Brick\Math\BigInteger;
- use Brick\Math\BigDecimal;
- use Brick\Math\RoundingMode;
- class Admin extends MY_Controller {
- public function __construct()
- {
- parent::__construct(true);
- if(!empty($this->session->user_arr)) {
- $user_arr = $this->session->user_arr;
- // fix admin from config
- $user_arr['super_admin'] = false;
- if(!empty($user_arr['email']) and ($user_arr['email'] == $this->config->item('super_admin_email'))) {
- $user_arr['super_admin'] = true;
- if ($user_arr['is_admin'] != 1) {
- $user_arr['is_admin'] = 1;
- $this->User_model->update_by_id(array('id' => $user_arr['id'], 'is_admin' => 1));
- // session sync
- $this->session->user_arr = $user_arr;
- $this->session->user_id = $user_arr['id'];
- }
- }
- // fix the game data
- if(empty($this->session->user_arr['gamecode1'])) {
- $user_arr['gamecode1'] = mt_rand(1, 3);
- $user_arr['gamecode2'] = mt_rand(0, 1);
- $user_arr['lastgame_at'] = time();
- $this->User_model->update_by_id(['id' => $user_arr['id'], 'lastgame_at' => time(), 'gamecode1' => $user_arr['gamecode1'], 'gamecode2' => $user_arr['gamecode2']]);
- // session sync
- $this->session->user_arr = $user_arr;
- $this->session->user_id = $user_arr['id'];
- }
- }
- //echo '<pre>';print_r($_SESSION);die;
- }
- public function index()
- {
- $this->_check_login();
- redirect('/'.$this->load->_get_this_controller_slug().'/profile/');
- }
- public function profile()
- {
- $this->_check_login();
- $this->data['notify_opt'] = 'asap';
- if(!empty($this->data['emailing_options'])) {
- $emailing_options = unserialize($this->data['emailing_options']);
- if(!empty($emailing_options['notify_opt'])) {
- $this->data['notify_opt'] = $emailing_options['notify_opt'];
- }
- }
- //get options
- $dgold_inc_arr = $this->Options_model->get_option('dgold_inc_arr');
- $this->load->model('Ticket_model');
- // del tickets if asked
- $invoice_id = (int)trim($this->input->get('del_invoice'));
- if($invoice_id > 0) {
- $invoice = $this->Ticket_model->get_one(array('id' => $invoice_id, 'user_id' => $this->data['id'], 'is_paid' => 0));
- if(!empty($invoice)) {
- $this->Ticket_model->delete(array('id' => $invoice_id));
- redirect('/'.$this->load->_get_this_controller_slug().'/my_invoices/');
- }
- }
- // load form helper and validation library
- $this->load->helper('form');
- $this->load->library('form_validation');
- $messages = array(
- 'required' => 'You have not provided %s.',
- 'is_unique' => 'This %s already exists. Please choose another one.',
- 'matches' => 'Passwords do not match.'
- );
- if($this->input->post('action') == 'settings') {
- // set validation rules
- $this->form_validation->set_rules('language', 'Language', 'trim|min_length[2]|max_length[2]', $messages);
- $this->form_validation->set_rules('name', 'Name', 'trim|min_length[2]', $messages);
- $this->form_validation->set_rules('surname', 'Surname', 'trim|min_length[2]', $messages);
- $this->form_validation->set_rules('password', 'Password', 'trim|min_length[6]', $messages);
- $this->form_validation->set_rules('password_confirm', 'Confirm Password', 'trim|min_length[6]|matches[password]', $messages);
- if ($this->form_validation->run() === false) {
- // validation not ok, send validation errors to the view
- $this->data['settings_error'] = validation_errors();
- } else {
- if(empty($_COOKIE['lang']) or ($_COOKIE['lang'] != trim($this->input->post('language')))) {
- setcookie('lang', trim($this->input->post('language')), time() + 3600 * 24 * 31 * 366, '/');
- redirect('/' . $this->load->_get_this_controller_slug() . '/profile/');
- }
- $user_data = array(
- 'name' => trim($this->input->post('name')),
- 'surname' => trim($this->input->post('surname')),
- 'password' => trim($this->input->post('password')),
- );
- foreach ($user_data as $idx => $rec) {
- if (empty($rec)) {
- unset($user_data[$idx]);
- }
- }
- if (!empty($user_data)) {
- $this->data['name'] = empty($user_data['name']) ? $this->data['name'] : $user_data['name'];
- $this->data['surname'] = empty($user_data['surname']) ? $this->data['surname'] : $user_data['surname'];
- if(!empty($user_data['password'])) {
- $user_data['password'] = $this->get_password_hash($user_data['password']);
- }
- $user_data['is_emailed'] = empty(trim($this->input->post('send_notifications'))) ? 0 : 1;
- $emailing_options = [];
- $allowed_opt = array_flip(explode(' ', 'asap hourly daily weekly'));
- $emailing_options['notify_opt'] = isset($allowed_opt[trim($this->input->post('notify_opt'))]) ? trim($this->input->post('notify_opt')) : 'asap';
- $user_data['emailing_options'] = serialize($emailing_options);
- foreach ($user_data as $idx => $rec) {
- $this->data[$idx] = $rec;
- }
- $this->data['notify_opt'] = $emailing_options['notify_opt'];
- $this->session->user_arr = $this->data;
- $this->session->user_id = $this->data['id'];
- $user_data['id'] = $this->data['id'];
- $this->User_model->update_by_id($user_data);
- }
- }
- } elseif($this->input->post('action') == 'buy_dgold') {
- $ask_price = trim($this->input->post('inputUSD'));
- $inputUSD = BigDecimal::of($ask_price);
- if(($inputUSD->compareTo(0) > 0) and ($inputUSD->compareTo($this->data['usd'] + $this->data['usd_cashout']) <= 0)) {
- $inputDGold = BigDecimal::of($inputUSD)->dividedBy($this->data['dgold_rate'], 0, RoundingMode::HALF_UP);
- $this->Ticket_model->start_transaction();
- $ticket_id = $this->Ticket_model->insert([
- 'user_id' => $this->data['id'],
- 'amount_usd' => (string)$inputUSD,
- 'amount_dgold' => (string)$inputDGold,
- ]);
- if($this->data['usd'] >= $ask_price) {
- $this->db->set('usd', "usd - {$ask_price}", FALSE);
- } else {
- $usd_price = $this->data['usd'];
- $usd_cashout_price = $ask_price - $this->data['usd'];
- $this->db->set('usd', "usd - {$usd_price}", FALSE);
- $this->db->set('usd_cashout', "usd_cashout - {$usd_cashout_price}", FALSE);
- }
- $this->User_model->update_by_id(['id' => $this->data['id']]);
- $ticket = $this->Ticket_model->get_one(['id' => $ticket_id]);
- $this->_add_dgold($ticket, 'Balance', null);
- $this->Ticket_model->commit_transaction();
- $data2 = $this->User_model->get_one(array('id' => $this->session->user_id));
- $this->data['usd'] = $data2['usd'];
- $this->data['usd_cashout'] = $data2['usd_cashout'];
- $this->data['coins'] = $data2['coins'];
- $this->data['show_modal_dgold_paid'] = (string)$inputDGold;
- }
- }
- /*elseif($this->input->post('action') == 'buy') {
- $inputUSD = BigDecimal::of(trim($this->input->post('inputUSD')));
- if($inputUSD->compareTo(0) >= 0) {
- $inputDGold = BigDecimal::of($inputUSD)->dividedBy($dgold_rate, 0, RoundingMode::HALF_UP);
- $invoice_arr = array(
- 'user_id' => $this->data['id'],
- 'amount_usd' => (string)$inputUSD,
- 'amount_dgold' => (string)$inputDGold,
- );
- $this->Ticket_model->insert($invoice_arr);
- $this->data['show_modal_new_invoice'] = true;
- }
- }*/
- elseif($this->input->post('action') == 'upload_docs') {
- //echo '<pre>';print_r($_FILES);die;
- $user_docs_dir = FCPATH.'docs'.DIRECTORY_SEPARATOR.$this->session->user_id;
- if(!is_dir($user_docs_dir)) {
- mkdir($user_docs_dir);
- chmod($user_docs_dir, 0777);
- }
- if(is_array($_FILES['picture']['tmp_name'])) {
- $docs_added = 0;
- foreach($_FILES['picture']['tmp_name'] as $idx => $tmp_name) {
- $fname = str_replace(['/', '\\'], '', $_FILES['picture']['name'][$idx]);
- $fext = (strrpos($fname, '.') !== false) ? substr($fname, strrpos($fname, '.')) : '';
- $rand_fname = substr(md5(password_hash(mt_rand(), PASSWORD_BCRYPT)), 0, 7);
- $target_fname = $user_docs_dir.DIRECTORY_SEPARATOR."{$rand_fname}{$fext}";
- move_uploaded_file($tmp_name, $target_fname);
- //add to database too
- if(file_exists($target_fname)) {
- $this->load->model('Docs_model');
- $this->Docs_model->insert([
- 'user_id' => $this->session->user_id,
- 'file_name' => "{$rand_fname}{$fext}",
- 'type' => 'verification',
- 'is_approved' => 0,
- ]);
- $docs_added++;
- }
- }
- if($docs_added) {
- $this->data['show_modal_add_docs'] = true;
- }
- }
- //redirect();
- } elseif($this->input->post('action') == 'my_payout_options') {
- $this->data['my_payout_options'] = [
- 'btc' => trim((string)$this->input->post('my_btc')),
- 'ethereum' => trim((string)$this->input->post('my_ethereum')),
- 'solidtrustpay' => trim((string)$this->input->post('my_solidtrustpay')),
- 'payeer' => trim((string)$this->input->post('my_payeer')),
- 'advcash' => trim((string)$this->input->post('my_advcash')),
- //'cryptonator' => trim((string)$this->input->post('my_cryptonator')),
- //'coinbase' => trim((string)$this->input->post('my_coinbase')),
- 'paypal' => trim((string)$this->input->post('my_paypal')),
- ];
- $this->User_model->update_by_id([
- 'id' => $this->data['id'],
- 'my_payout_options' => serialize($this->data['my_payout_options']),
- ]);
- }
- $this->data['invoices'] = $this->Ticket_model->get(['user_id' => $this->data['id'], 'is_paid' => 0], 'updated_at DESC');
- $this->data['merchants_data'] = $this->_get_merchants_data();
- $this->data['my_referrals'] = $this->User_model->get_my_referrals($this->data['id'], $dgold_inc_arr); // flat list of my referrals
- $this->data['refs_cnt'] = $this->User_model->get_my_referrals_cnt($this->data['id'], $dgold_inc_arr); // calculate number of my referrals
- $this->data['wallet'] = $this->load->view2_get_link_by($this->data['id'], 'wallet_id');
- $this->data['buy_usd_value'] = $this->config->item('buy_usd_amount');
- $this->data['dollars'] = $this->data['coins'] * $this->data['dgold_rate'];
- $this->data['ref_link'] = $this->load->view2_get_link_by($this->data['username'], 'referrer_link');
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->data['languages'] = $this->get_lang_arr();
- $this->data['cur_lang'] = empty($_COOKIE['lang']) ? 'en' : $_COOKIE['lang'];
- $this->load->model('Docs_model');
- $docs1 = $this->Docs_model->get(['user_id' => $this->session->user_id, 'type' => 'ID document', 'is_approved' => 1]);
- $docs2 = $this->Docs_model->get(['user_id' => $this->session->user_id, 'type' => 'Proof of address', 'is_approved' => 1]);
- $this->data['uploaded_docs'] = !empty($docs1) and !empty($docs2);
- // get merchants options
- $this->data['solidtrustpay_on'] = $this->Options_model->get_option('merchant_solidtrustpay_on');
- $this->data['payeer_on'] = $this->Options_model->get_option('merchant_payeer_on');
- $this->data['advcash_on'] = $this->Options_model->get_option('merchant_advcash_on');
- $this->data['cryptonator_on'] = $this->Options_model->get_option('merchant_cryptonator_on');
- $this->data['btc_on'] = $this->Options_model->get_option('merchant_btc_on');
- $this->data['coinbase_on'] = $this->Options_model->get_option('merchant_coinbase_on');
- $this->data['paypal_on'] = $this->Options_model->get_option('merchant_paypal_on');
- $this->data['paypal_payout_on'] = $this->Options_model->get_option('merchant_paypal_payout_on');
- $this->load->view2('profile', $this->data);
- }
- public function my_referrals($page = 0)
- {
- $this->_check_login();
- //get options
- $dgold_inc_arr = $this->Options_model->get_option('dgold_inc_arr');
- $page = ((int)$page - 1);
- $page = ($page > 0) ? $page : 0;
- $referrals = $this->User_model->get_my_referrals($this->data['id'], $dgold_inc_arr); // flat list of my referrals
- $cnt = count($referrals);
- if($cnt) {
- $ref_chunks = array_chunk($referrals, $this->data['rows_per_page']);
- $page = ($page < count($ref_chunks)) ? $page : count($ref_chunks);
- $this->data['my_referrals'] = $ref_chunks[$page];
- // pagination
- $base_url = base_url($this->load->_get_this_controller_slug().'/'.__FUNCTION__);
- $this->data['pagination'] = $this->_get_pagination_html($base_url, $cnt);
- // receive packages
- $this->load->model('Packages_model');
- $Uids = $this->User_model->gather_columns($this->data['my_referrals'], 'id');
- $this->data['ref_packages'] = $this->Packages_model->get(['user_id' => $Uids, 'packages.is_active' => 1]);
- //echo '<pre>';print_r($this->data['ref_packages']);die;
- } else {
- $this->data['pagination'] = '';
- }
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('my_referrals', $this->data);
- }
- public function my_balance()
- {
- $this->_check_login();
- // data for calculate DGold price dynamically
- $this->data['buy_usd_value'] = $this->config->item('buy_usd_amount');
- $this->load->model('Docs_model');
- $docs1 = $this->Docs_model->get(['user_id' => $this->session->user_id, 'type' => 'ID document', 'is_approved' => 1]);
- $docs2 = $this->Docs_model->get(['user_id' => $this->session->user_id, 'type' => 'Proof of address', 'is_approved' => 1]);
- $this->data['uploaded_docs'] = !empty($docs1) and !empty($docs2);
- $this->load->model('Packages_model');
- $this->db->select('SQL_CALC_FOUND_ROWS *', false);
- $this->data['packages'] = $this->Packages_model->get(['user_id' => $this->data['id'], 'packages.is_active' => 1], 'last_payout_date DESC');
- $this->data['packages_pagination'] = '';
- // USD Invoices
- $this->load->model('Money_model');
- $all_invoice_url = '/'.$this->load->_get_this_controller_slug().'/my_usd_invoices/';
- // del tickets if asked
- $invoice_id = (int)trim($this->input->get('del_usd_invoice'));
- if($invoice_id > 0) {
- $invoice = $this->Money_model->get_one(array('id' => $invoice_id, 'user_id' => $this->data['id'], 'is_paid' => 0));
- if(!empty($invoice)) {
- $this->Money_model->delete(array('id' => $invoice_id));
- redirect($all_invoice_url);
- }
- } elseif($this->input->post('action') == 'charge_usd') {
- $inputUSD = BigDecimal::of(trim($this->input->post('inputUSD2')));
- if($inputUSD->compareTo(0) >= 0) {
- $invoice_arr = array(
- 'user_id' => $this->data['id'],
- 'amount_usd' => (string)$inputUSD,
- );
- $this->Money_model->insert($invoice_arr);
- $this->data['show_modal_new_invoice'] = true;
- }
- }
- $this->db->select('SQL_CALC_FOUND_ROWS *', false);
- $this->data['usd_invoices'] = $this->Money_model->get(['user_id' => $this->data['id']], '`updated_at` DESC', null, 0, $this->data['rows_per_page']);
- $query = $this->db->query('SELECT FOUND_ROWS() AS records');
- $row = $query->row();
- $this->data['usd_pagination'] = ($row->records > $this->data['rows_per_page']) ? '<ul class="pagination pull-right"><li><a href="'.$all_invoice_url.'">Full History</a></ul>' : '';
- // DGold Invoices
- $this->load->model('Ticket_model');
- $all_invoice_url = '/'.$this->load->_get_this_controller_slug().'/my_invoices/';
- // del tickets if asked
- $invoice_id = (int)trim($this->input->get('del_dgold_invoice'));
- if($invoice_id > 0) {
- $invoice = $this->Ticket_model->get_one(array('id' => $invoice_id, 'user_id' => $this->data['id'], 'is_paid' => 0));
- if(!empty($invoice)) {
- $this->Ticket_model->delete(array('id' => $invoice_id));
- redirect($all_invoice_url);
- }
- } elseif($this->input->post('action') == 'buy_dgold') {
- $ask_price = trim($this->input->post('inputUSD'));
- $inputUSD = BigDecimal::of($ask_price);
- if(($inputUSD->compareTo(0) > 0) and ($inputUSD->compareTo($this->data['usd'] + $this->data['usd_cashout']) <= 0)) {
- $inputDGold = BigDecimal::of($inputUSD)->dividedBy($this->data['dgold_rate'], 0, RoundingMode::HALF_UP);
- $this->Ticket_model->start_transaction();
- $ticket_id = $this->Ticket_model->insert([
- 'user_id' => $this->data['id'],
- 'amount_usd' => (string)$inputUSD,
- 'amount_dgold' => (string)$inputDGold,
- ]);
- if($this->data['usd'] >= $ask_price) {
- $this->db->set('usd', "usd - {$ask_price}", FALSE);
- } else {
- $usd_price = $this->data['usd'];
- $usd_cashout_price = $ask_price - $this->data['usd'];
- $this->db->set('usd', "usd - {$usd_price}", FALSE);
- $this->db->set('usd_cashout', "usd_cashout - {$usd_cashout_price}", FALSE);
- }
- $this->User_model->update_by_id(['id' => $this->data['id']]);
- $ticket = $this->Ticket_model->get_one(['id' => $ticket_id]);
- $this->_add_dgold($ticket, 'Balance', null);
- $this->Ticket_model->commit_transaction();
- $data2 = $this->User_model->get_one(array('id' => $this->session->user_id));
- $this->data['usd'] = $data2['usd'];
- $this->data['usd_cashout'] = $data2['usd_cashout'];
- $this->data['coins'] = $data2['coins'];
- $this->data['show_modal_dgold_paid'] = (string)$inputDGold;
- }
- }
- // pay ticket if asked (old tickets support)
- $ticket_id = (int)trim($this->input->get('pay_dgold_id'));
- if($ticket_id > 0) {
- $ticket = $this->Ticket_model->get_one(array('id' => $ticket_id, 'user_id' => $this->data['id'], 'is_paid' => 0));
- if(!empty($ticket) and ($this->data['usd'] >= $ticket['amount_usd'])) {
- $this->Ticket_model->start_transaction();
- $this->db->set('usd', "usd - {$ticket['amount_usd']}", FALSE);
- $this->User_model->update_by_id(['id' => $this->session->user_id]);
- $this->_add_dgold($ticket, 'Balance', null);
- $this->Ticket_model->commit_transaction();
- $data2 = $this->User_model->get_one(array('id' => $this->session->user_id));
- $this->data['usd'] = $data2['usd'];
- $this->data['show_modal_dgold_paid'] = true;
- }
- }
- $this->db->select('SQL_CALC_FOUND_ROWS *', false);
- $this->data['dgold_invoices'] = $this->Ticket_model->get(['user_id' => $this->data['id']], '`updated_at` DESC', null, 0, $this->data['rows_per_page']);
- $query = $this->db->query('SELECT FOUND_ROWS() AS records');
- $row = $query->row();
- $this->data['dgold_pagination'] = ($row->records > $this->data['rows_per_page']) ? '<ul class="pagination pull-right"><li><a href="'.$all_invoice_url.'">Full History</a></ul>' : '';
- $this->data['merchants_data'] = $this->_get_merchants_data();
- // Packages to buy
- if($this->input->post('action') == 'buy_package') {
- $package_id = (int)trim($this->input->post('id'));
- if($package_id > 0) {
- if($this->_buy_package($package_id, $this->data)) {
- $data2 = $this->User_model->get_one(array('id' => $this->data['id']));
- $this->data['usd'] = $data2['usd'];
- $this->data['show_modal_package_bought'] = true;
- $this->db->select('SQL_CALC_FOUND_ROWS *', false);
- $this->data['packages'] = $this->Packages_model->get(['user_id' => $this->data['id'], 'packages.is_active' => 1], 'last_payout_date DESC');
- $this->data['packages_pagination'] = '';
- $this->data['show_modal_package_bought'] = true;
- //redirect('/admin/dgold_mining/');
- } else {
- $this->data['show_modal_insufficient_money'] = true;
- }
- }
- }
- // create payout ticket
- $payout_usd_amount = (int)trim($this->input->get('payout_usd_amount'));
- $microtimnow = time();
- $datatwo = $this->User_model->get_one(array('id' => $this->data['id']));
- $difference = $microtimnow - $datatwo['microtime'];
- $finaltime = round($difference / (60 * 60 * 24));
- $payout_usd_via = (string)trim($this->input->get('payout_usd_via'));
- if(($payout_usd_amount > 0) and ($payout_usd_amount <= $this->data['usd_cashout']) and !empty($this->data['my_payout_options'][$payout_usd_via])) {
- $dates = empty($this->data['packages']) ? [] : $this->Packages_model->gather_columns($this->data['packages'], 'start_date');
- $dates[] = time();
- $p_buy_package_date = min($dates);
- if ($this->data['uploaded_docs'] and ($p_buy_package_date + 86400 * 30 <= time())) {
- $this->load->model('Payout_model');
- if(empty($datatwo['microtime'])){
- $data = array (
- 'microtime' => $microtimnow,
- );
- $this->db->where('id', $this->data['id']);
- $this->db->update('user', $data);
- }
- if($finaltime >= 7){
- $data = array (
- 'microtime' => $microtimnow,
- 'total_amount' => '100',
- );
- $this->db->where('id', $this->data['id']);
- $this->db->update('user', $data);
- }
- if($datatwo['total_amount'] != 0){
- $ukupnooduzeti = $datatwo['total_amount'] - $payout_usd_amount;
- if($payout_usd_amount <= $datatwo['total_amount']){
- if ($this->Payout_model->add_payout($this->data['id'], $payout_usd_amount, ucfirst($payout_usd_via))) {
- // success
- $this->data['show_modal_new_payout'] = true;
- $data = array (
- 'microtime' => $microtimnow,
- 'total_amount' => $ukupnooduzeti,
- );
- $this->db->where('id', $this->data['id']);
- $this->db->update('user', $data);
- $data2 = $this->User_model->get_one(['id' => $this->data['id']]);
- $this->data['usd_cashout'] = $data2['usd_cashout'];
- }else {
- // fail
- }
- }else{
- $this->data['modal_limited'] = true;
- }
- }else{
- $this->data['timelimitnow'] = true;
- }
- /* }else{
- if ($this->Payout_model->add_payout($this->data['id'], $payout_usd_amount, ucfirst($payout_usd_via))) {
- // success
- $this->data['show_modal_new_payout'] = true;
- $data = array (
- 'microtime' => $microtimnow,
- 'total_amount' => $payout_usd_amount,
- );
- $this->db->where('id', $this->data['id']);
- $this->db->update('user', $data);
- $data2 = $this->User_model->get_one(['id' => $this->data['id']]);
- $this->data['usd_cashout'] = $data2['usd_cashout'];
- } else {
- // fail
- }
- }*/
- }
- }
- if($this->input->post('action') == 'upload_docs') {
- //echo '<pre>';print_r($_FILES);die;
- $user_docs_dir = FCPATH.'docs'.DIRECTORY_SEPARATOR.$this->session->user_id;
- if(!is_dir($user_docs_dir)) {
- mkdir($user_docs_dir);
- chmod($user_docs_dir, 0777);
- }
- $add_docs_list = [];
- if(is_array($_FILES['picture2']['tmp_name'])) {
- $add_docs_list['Proof of address'] = 'picture2';
- }
- if(is_array($_FILES['picture1']['tmp_name'])) {
- $add_docs_list['ID document'] = 'picture1';
- }
- if(!empty($add_docs_list)) {
- $docs_added = 0;
- foreach($add_docs_list as $pic_type => $pic_name) {
- foreach($_FILES[$pic_name]['tmp_name'] as $idx => $tmp_name) {
- $fname = str_replace(['/', '\\'], '', $_FILES[$pic_name]['name'][$idx]);
- $fext = (strrpos($fname, '.') !== false) ? substr($fname, strrpos($fname, '.')) : '';
- $rand_fname = substr(md5(password_hash(mt_rand(), PASSWORD_BCRYPT)), 0, 7);
- $target_fname = $user_docs_dir . DIRECTORY_SEPARATOR . "{$rand_fname}{$fext}";
- move_uploaded_file($tmp_name, $target_fname);
- //add to database too
- if (file_exists($target_fname)) {
- $this->load->model('Docs_model');
- $this->Docs_model->insert([
- 'user_id' => $this->session->user_id,
- 'file_name' => "{$rand_fname}{$fext}",
- 'type' => $pic_type,
- 'is_approved' => 0,
- ]);
- $docs_added++;
- }
- }
- }
- if($docs_added) {
- $this->data['show_modal_add_docs'] = true;
- }
- }
- //redirect();
- }
- // get merchants options
- $this->data['solidtrustpay_on'] = $this->Options_model->get_option('merchant_solidtrustpay_on');
- $this->data['payeer_on'] = $this->Options_model->get_option('merchant_payeer_on');
- $this->data['advcash_on'] = $this->Options_model->get_option('merchant_advcash_on');
- $this->data['cryptonator_on'] = $this->Options_model->get_option('merchant_cryptonator_on');
- $this->data['btc_on'] = $this->Options_model->get_option('merchant_btc_on');
- $this->data['coinbase_on'] = $this->Options_model->get_option('merchant_coinbase_on');
- $this->data['paypal_on'] = $this->Options_model->get_option('merchant_paypal_on');
- $this->data['paypal_payout_on'] = $this->Options_model->get_option('merchant_paypal_payout_on');
- $this->data['coin_counpayments_on'] = $this->Options_model->get_option('merchant_coin_paymentns_on');
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('my_balance', $this->data);
- }
- public function admin_ddk_sp_invoices(){
- $this->_check_login();
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('admin_ddk_sp_invoices', $this->data);
- }
- public function ddk_buy(){
- $this->_check_login();
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('ddkbuy', $this->data);
- }
- public function ddk_ref(){
- $this->_check_login();
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('ddkref', $this->data);
- }
- public function ddk_invoice(){
- $this->_check_login();
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('invoice_ddk', $this->data);
- }
- public function ddk_ip(){
- $this->_check_login();
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('ddkip', $this->data);
- }
- public function ddk_sp(){
- $this->_check_login();
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('ddksp', $this->data);
- }
- public function my_invoices($page = 0)
- {
- $this->_check_login();
- $this->load->model('Ticket_model');
- // del ticket if asked
- $invoice_id = (int)trim($this->input->get('del_invoice'));
- if($invoice_id > 0) {
- $invoice = $this->Ticket_model->get_one(array('id' => $invoice_id, 'user_id' => $this->data['id'], 'is_paid' => 0));
- if(!empty($invoice)) {
- $this->Ticket_model->delete(array('id' => $invoice_id));
- redirect('/'.$this->load->_get_this_controller_slug().'/my_invoices/');
- }
- }
- // pay ticket if asked
- $ticket_id = (int)trim($this->input->get('pay_dgold_id'));
- if($ticket_id > 0) {
- $ticket = $this->Ticket_model->get_one(array('id' => $ticket_id, 'user_id' => $this->data['id'], 'is_paid' => 0));
- if(!empty($ticket) and (($this->data['usd'] + $this->data['usd_cashout']) >= $ticket['amount_usd'])) {
- $this->Ticket_model->start_transaction();
- if($this->data['usd'] >= $ticket['amount_usd']) {
- $this->db->set('usd', "usd - {$ticket['amount_usd']}", FALSE);
- } else {
- $usd_price = $this->data['usd'];
- $usd_cashout_price = $ticket['amount_usd'] - $this->data['usd'];
- $this->db->set('usd', "usd - {$usd_price}", FALSE);
- $this->db->set('usd_cashout', "usd_cashout - {$usd_cashout_price}", FALSE);
- }
- $this->User_model->update_by_id(['id' => $this->session->user_id]);
- $this->_add_dgold($ticket, 'Balance', null);
- $this->Ticket_model->commit_transaction();
- $data2 = $this->User_model->get_one(array('id' => $this->session->user_id));
- $this->data['usd'] = $data2['usd'];
- //$this->data['show_modal_dgold_paid'] = true;
- redirect('/'.$this->load->_get_this_controller_slug().'/my_invoices/');
- }
- }
- $page = ((int)$page - 1);
- $page = ($page > 0) ? $page : 0;
- $this->db->select('SQL_CALC_FOUND_ROWS *', false);
- $this->data['invoices'] = $this->Ticket_model->get(['user_id' => $this->data['id']], '`updated_at` DESC', null, $page * $this->data['rows_per_page'], $this->data['rows_per_page']);
- // pagination
- $query = $this->db->query('SELECT FOUND_ROWS() AS records');
- $row = $query->row();
- $base_url = base_url($this->load->_get_this_controller_slug().'/'.__FUNCTION__);
- $this->data['pagination'] = $this->_get_pagination_html($base_url, $row->records);
- //get options
- $this->data['merchants_data'] = $this->_get_merchants_data();
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('my_invoices', $this->data);
- }
- public function my_usd_invoices($page = 0)
- {
- $this->_check_login();
- $this->load->model('Money_model');
- // del tickets if asked
- $invoice_id = (int)trim($this->input->get('del_invoice'));
- if($invoice_id > 0) {
- $invoice = $this->Money_model->get_one(array('id' => $invoice_id, 'user_id' => $this->data['id'], 'is_paid' => 0));
- if(!empty($invoice)) {
- $this->Money_model->delete(array('id' => $invoice_id));
- redirect('/'.$this->load->_get_this_controller_slug().'/my_usd_invoices/');
- }
- }
- $page = ((int)$page - 1);
- $page = ($page > 0) ? $page : 0;
- $this->db->select('SQL_CALC_FOUND_ROWS *', false);
- $this->data['invoices'] = $this->Money_model->get(['user_id' => $this->data['id']], '`updated_at` DESC', null, $page * $this->data['rows_per_page'], $this->data['rows_per_page']);
- // pagination
- $query = $this->db->query('SELECT FOUND_ROWS() AS records');
- $row = $query->row();
- $base_url = base_url($this->load->_get_this_controller_slug().'/'.__FUNCTION__);
- $this->data['pagination'] = $this->_get_pagination_html($base_url, $row->records);
- //get options
- $this->data['merchants_data'] = $this->_get_merchants_data();
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('my_usd_invoices', $this->data);
- }
- public function my_messages($page = 0)
- {
- $this->_check_login();
- $page = ((int)$page - 1);
- $page = ($page > 0) ? $page : 0;
- $this->load->model('Messages_model');
- $user_ids = $this->Messages_model->get_users_who_wrote($this->data['id']);
- $this->data['pagination'] = '';
- // "Support" rec
- $this->data['support_rec'] = [
- 'created_at' => 0,
- 'seen' => 'yes',
- ];
- $this->data['support_user_id'] = $this->Options_model->get_option('support_user_id');
- if(isset($user_ids['seen'][$this->data['support_user_id']])) {
- $this->data['support_rec'] = [
- 'created_at' => $user_ids['created_at'][$this->data['support_user_id']],
- 'seen' => $user_ids['seen'][$this->data['support_user_id']],
- ];
- unset($user_ids['created_at'][$this->data['support_user_id']]);
- unset($user_ids['seen'][$this->data['support_user_id']]);
- }
- if(!empty($user_ids)) {
- arsort($user_ids['created_at'], SORT_NATURAL);
- $user_dates_chunked = array_chunk($user_ids['created_at'], $this->data['rows_per_page'],true);
- $page = isset($user_dates_chunked[$page]) ? $page : count($user_dates_chunked) - 1;
- $retU = $this->User_model->get(['id' => array_keys($user_dates_chunked[$page])], null, 'id, username, email, name, surname');
- $retUassoc = [];
- foreach($retU as $objU) {
- $retUassoc[$objU['id']] = $objU;
- }
- $this->data['message_users'] = [];
- foreach($user_dates_chunked[$page] as $user_id => $created_at) {
- if(!empty($retUassoc[$user_id])) {
- $objU = $retUassoc[$user_id];
- $objU['seen'] = $user_ids['seen'][$user_id];
- $objU['last_msg'] = $created_at;
- $this->data['message_users'][$user_id] = $objU;
- }
- }
- // pagination
- $base_url = base_url($this->load->_get_this_controller_slug().'/'.__FUNCTION__);
- $this->data['pagination'] = $this->_get_pagination_html($base_url, count($user_ids['created_at']));
- }
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('my_messages', $this->data);
- }
- public function ajax_messages($with_user_id = null, $output = 'full')
- {
- $this->load->model('Options_model');
- $is_support = false;
- if($with_user_id == 'support') {
- $with_user_id = $this->Options_model->get_option('support_user_id');
- $is_support = true;
- }
- $with_user_id = (int)$with_user_id;
- if($with_user_id <= 0)
- die;
- $this->_check_login(false);
- $this->load->model('Messages_model');
- // check if user can text with this user
- $i_can_text = ($this->data['is_admin'] == 1) or $is_support;
- if(!$i_can_text) {
- $wrote_to_me = $this->Messages_model->get_one(['to_user' => $this->data['id']]);
- $i_can_text = !empty($wrote_to_me);
- if(!$i_can_text) {
- $dgold_inc_arr = $this->Options_model->get_option('dgold_inc_arr');
- $referrals = $this->User_model->get_my_referrals($this->data['id'], $dgold_inc_arr);
- $ref_ids = $this->User_model->gather_columns($referrals, 'id name', true);
- $i_can_text = isset($ref_ids[$this->data['id']]);
- }
- }
- if(!$i_can_text)
- return;
- // check if message sent
- $message = trim($this->input->post('message'));
- if(!empty($message)) {
- $ret = $this->_add_message($this->data['id'], $with_user_id, $message);
- }
- $this->data['users'][$this->session->user_id] = $this->data;
- if($is_support) {
- $this->data['users'][$with_user_id] = [
- 'id' => $with_user_id,
- 'name' => '<span class="text-red">Support</span>',
- 'surname' => '',
- 'username' => '',
- ];
- } else {
- $this->data['users'][$with_user_id] = $this->User_model->get_one(['id' => $with_user_id]);
- }
- $this->data['owner_id'] = $this->session->user_id;
- $this->data['with_user_id'] = $with_user_id;
- $this->data['output'] = $output;
- $this->data['messages'] = $this->Messages_model->get_user_chat($this->data['id'], $with_user_id);
- $this->load->view('user_chat', $this->data);
- }
- public function cron()
- {
- $t = time();
- $this->load->model('Options_model');
- $cron_running = $this->Options_model->get_option('cron_running', 0);
- if($cron_running) {
- $msg = "Cron is already running!";
- log_message('error', $msg);
- echo "{$msg}\n";
- die;
- }
- $this->Options_model->set_option('cron_running', 1);
- $cron_last_run = $this->Options_model->get_option('cron_last_run', 0);
- // send notification emails
- $this->load->model('Messages_model');
- // hourly update
- if(date('dmYH', $t) != date('dmYH', $cron_last_run)) {
- $this->db->distinct();
- $user_ids = $this->Messages_model->get(['notified' => 'hourly'], null, 'to_user');
- $email_res = $this->_send_notification_emails($user_ids, 'to_user');
- if($email_res) {
- $this->Messages_model->update(['notified' => 'hourly'], ['notified' => 'yes']);
- echo count($user_ids)." - hourly\n";
- }
- }
- // daily update
- if(date('dmY', $t) != date('dmY', $cron_last_run)) {
- $this->db->distinct();
- $user_ids = $this->Messages_model->get(['notified' => 'daily'], null, 'to_user');
- $email_res = $this->_send_notification_emails($user_ids, 'to_user');
- if($email_res) {
- $this->Messages_model->update(['notified' => 'daily'], ['notified' => 'yes']);
- echo count($user_ids)." - daily\n";
- }
- }
- // weekly update
- if(date('WY', $t) != date('WY', $cron_last_run)) {
- $this->db->distinct();
- $user_ids = $this->Messages_model->get(['notified' => 'weekly'], null, 'to_user');
- $email_res = $this->_send_notification_emails($user_ids, 'to_user');
- if($email_res) {
- $this->Messages_model->update(['notified' => 'weekly'], ['notified' => 'yes']);
- echo count($user_ids)." - weekly\n";
- }
- }
- /*
- if(!$is_ok) {
- $this->Options_model->set_option('cron_running', 0);
- $msg = "Check Voluum Email and Password!";
- log_message('error', $msg);
- echo "{$msg}\n";
- die;
- }
- */
- $this->Options_model->set_option('cron_running', 0);
- $this->Options_model->set_option('cron_last_run', $t);
- $msg = "Cron job from {$t} have updated in ".(time() - $t)." secs.";
- log_message('error', $msg);
- echo "{$msg}\n";
- }
- private function _send_notification_emails($user_ids = [], $column = 'to_user', $template = 'chat')
- {
- if(!empty($user_ids)) {
- $this->load->model('Options_model');
- if($template == 'inbox') {
- $notification_subject = $this->Options_model->get_option('email_notification_subject_inbox');
- $notification_message = $this->Options_model->get_option('email_notification_message_inbox');
- } else {
- $notification_subject = $this->Options_model->get_option('email_notification_subject_chat');
- $notification_message = $this->Options_model->get_option('email_notification_message_chat');
- }
- $Uids = $this->User_model->gather_columns($user_ids, $column);
- $ids = implode(',', $Uids);
- $query = $this->db->query("SELECT id, email, `name`, surname, username FROM `user` WHERE `id` IN({$ids})");
- $retU = $query->result_array();
- $to_email = [];
- foreach($retU as $objU) {
- $to_email[$objU['email']] = $this->User_model->get_user_name($objU);
- }
- $this->_send_email('', '', $to_email, '', '', '', $notification_subject, $notification_message, 'sendgrid');
- return true;
- }
- return false;
- }
- private function _add_message($from_user_id, $to_user_id, $message)
- {
- $message = trim(strip_tags($message, '<h1><h2><h3><h4><h5><h6><b><i><u><div><span><blockquote><ul><ol><li><br><p><a><img>'));
- if(empty($message))
- return false;
- $toObjU = $this->User_model->get_one(['id' => $to_user_id]);
- $notified = 'asap';
- if(!empty($toObjU['emailing_options'])) {
- $emailing_options = unserialize($toObjU['emailing_options']);
- $notified = empty($emailing_options['notify_opt']) ? $notified : $emailing_options['notify_opt'];
- }
- if($toObjU['is_emailed'] == 0) {
- $notified = 'yes';
- }
- $this->load->model('Messages_model');
- $new_msg_id = $this->Messages_model->insert([
- 'from_user' => $from_user_id,
- 'to_user' => $to_user_id,
- 'seen' => 'no',
- 'notified' => $notified,
- 'message' => $message,
- ]);
- //send email notification
- if($notified == 'asap') {
- $to_email = $toObjU['email'];
- $to_name = $this->User_model->get_user_name($toObjU);
- $this->load->model('Options_model');
- $notification_subject = $this->Options_model->get_option('email_notification_subject_chat');
- $notification_message = $this->Options_model->get_option('email_notification_message_chat');
- $this->_send_email('', '', $to_email, $to_name, '', '', $notification_subject, $notification_message, 'standard');
- $this->Messages_model->update_by_id([
- 'id' => $new_msg_id,
- 'notified' => 'yes',
- ]);
- }
- return true;
- }
- public function message_settings()
- {
- $this->_check_admin();
- // change chat configuration
- if($this->input->post('action') == 'chat_config') {
- $support_user_id = trim($this->input->post('support_user_id'));
- $support_user_id_int = (int)$support_user_id;
- $email_notification_subject = (string)trim($this->input->post('email_notification_subject'));
- $email_notification_message = (string)trim($this->input->post('email_notification_message'));
- if($support_user_id != $support_user_id_int) {
- $objU = $this->User_model->get_one(['username' => $support_user_id]);
- if(!empty($objU)) {
- $support_user_id = $objU['id'];
- }
- }
- $this->Options_model->set_option('support_user_id', $support_user_id);
- $this->Options_model->set_option('email_notification_subject_chat', $email_notification_subject);
- $this->Options_model->set_option('email_notification_message_chat', $email_notification_message);
- }
- // change messages configuration
- if($this->input->post('action') == 'message_config') {
- $email_notification_subject2 = (string)trim($this->input->post('email_notification_subject2'));
- $email_notification_message2 = (string)trim($this->input->post('email_notification_message2'));
- $this->Options_model->set_option('email_notification_subject_inbox', $email_notification_subject2);
- $this->Options_model->set_option('email_notification_message_inbox', $email_notification_message2);
- }
- // set options
- $this->data['support_user_id'] = $this->Options_model->get_option('support_user_id');
- $this->data['email_notification_subject'] = $this->Options_model->get_option('email_notification_subject_chat');
- $this->data['email_notification_message'] = $this->Options_model->get_option('email_notification_message_chat');
- $this->data['email_notification_subject2'] = $this->Options_model->get_option('email_notification_subject_inbox');
- $this->data['email_notification_message2'] = $this->Options_model->get_option('email_notification_message_inbox');
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('admin_message_settings', $this->data);
- }
- public function dgold_spinner_open()
- {
- $this->_check_login();
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('dgold_spinner_open', $this->data);
- }
- public function dgold_spinner()
- {
- $this->_check_login();
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('dgold_spinner', $this->data);
- }
- public function user_ddk_invoice(){
- $this->_check_login();
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('user_ddk_invoice', $this->data);
- }
- public function trka_za_coine()
- {
- $this->_check_login();
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('trka_za_coine', $this->data);
- }
- public function withdraw()
- {
- $this->_check_login();
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('withdraw', $this->data);
- }
- public function topone()
- {
- $this->_check_login();
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('topone', $this->data);
- }
- public function invoices_users_words()
- {
- $this->_check_login();
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('invoices_users_words', $this->data);
- }
- public function invoices_users_trial()
- {
- $this->_check_login();
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('invoices_users_trial', $this->data);
- }
- public function promo_coins()
- {
- $this->_check_login();
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $user_array = $this->session->user_arr;
- $this->session->user_arr = $user_array;
- $this->session->user_id = $user_array['id'];
- $this->data['user_ides'] = $user_array['id'];
- $this->load->view2('promo_coins', $this->data);
- }
- public function ddkprofile() {
- $this->_check_login();
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('ddkprofile', $this->data);
- }
- public function buyddk() {
- $this->_check_login();
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('buyddk', $this->data);
- }
- public function ddkreferals() {
- $this->_check_login();
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('ddkreferals', $this->data);
- }
- public function invoicesddk() {
- $this->_check_login();
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('invoicesddk', $this->data);
- }
- public function my_promo()
- {
- $this->_check_login();
- $this->load->helper('url');
- $bad_dirs = array_flip(explode(' ', '. ..'));
- $promo_lands = scandir(FCPATH."promo");
- $this->data['promo_lands'] = [];
- foreach($promo_lands as $land) {
- if(!isset($bad_dirs[$land]) and is_dir(FCPATH."promo") and @file_exists(FCPATH."promo/{$land}/preview.jpg")) {
- $landing_name = str_replace(['-', '_'], ' ', $land);
- $land_arr = explode(' ', $landing_name);
- foreach($land_arr as $idx => $rec) {
- $land_arr[$idx] = ucfirst($rec);
- }
- $landing_name = implode(' ', $land_arr);
- $this->data['promo_lands'][] = [
- 'landing' => $land,
- 'landing_name' => $landing_name,
- 'preview' => site_url("/promo/{$land}/preview.jpg"),
- 'ref_link' => site_url("/promo/{$land}/index.php?ref={$this->data['username']}"),
- ];
- }
- }
- $promo_banners = scandir(FCPATH."promo/banners");
- $banners_tmp_arr = [];
- foreach($promo_banners as $banner) {
- if(!isset($bad_dirs[$banner]) and is_dir(FCPATH."promo/banners") and @file_exists(FCPATH."promo/banners/{$banner}/preview.jpg")) {
- list($sizes) = array_reverse(explode('_', $banner));
- $sizes = explode('x', strtolower($sizes));
- if((count($sizes) != 2) or ((int)$sizes[0] <= 0) or ((int)$sizes[1] <= 0))
- continue;
- $banner_name = str_replace(['-', '_'], ' ', $banner);
- $banner_arr = explode(' ', $banner_name);
- foreach($banner_arr as $idx => $rec) {
- $banner_arr[$idx] = ucfirst($rec);
- }
- $banner_name = implode(' ', $banner_arr);
- $banners_tmp_arr[(int)$sizes[1]][] = [
- 'banner' => $banner,
- 'banner_name' => $banner_name,
- 'width' => (int)$sizes[0],
- 'height' => (int)$sizes[1],
- 'preview' => site_url("/promo/banners/{$banner}/preview.jpg"),
- 'ref_link' => site_url("/promo/banners/{$banner}/index.php?ref={$this->data['username']}"),
- ];
- }
- }
- // sorting
- ksort($banners_tmp_arr, SORT_NATURAL);
- $this->data['promo_banners'] = [];
- foreach($banners_tmp_arr as $tmp_arr) {
- foreach($tmp_arr as $banner_tmp) {
- $this->data['promo_banners'][] = $banner_tmp;
- }
- }
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('my_promo', $this->data);
- }
- public function the_game()
- {
- //log_message('error', 'the_game-status-'.$_SERVER['REMOTE_ADDR'].'-'.serialize($_POST).'-'.serialize($_GET));
- $this->_check_login();
- $this->data['game_chest_reward'] = $this->Options_model->get_option('game_chest_reward', 1);
- $this->data['game_flip_reward'] = $this->Options_model->get_option('game_flip_reward', 2);
- $this->data['dollars'] = $this->data['coins'] * $this->data['dgold_rate'];
- // let the game begin!
- if(($this->data['lastgame_at'] < time() - 3600 * $this->data['game_countdown']) and !empty($_GET['open_chest'])) {
- $open_chest = (int)$_GET['open_chest'];
- $add_reward = false;
- $reset_timer = false;
- if(isset($_GET['take_reward'])) {
- if($this->data['gamecode1'] == $open_chest) {
- $add_reward = $this->data['game_chest_reward'];
- }
- $reset_timer = true;
- } elseif(isset($_GET['heads'])) {
- if(($this->data['gamecode1'] == $open_chest) and ($this->data['gamecode2'] == (int)$_GET['heads'])) {
- $add_reward = $this->data['game_flip_reward'];
- echo 1;
- } else {
- echo 0;
- }
- $reset_timer = true;
- } else {
- if($this->data['gamecode1'] == $open_chest) {
- echo 1;
- } else {
- $reset_timer = true;
- echo 0;
- }
- }
- // add reward
- if(!empty($add_reward)) {
- // add 1 coin to user and allow to flip coin
- $this->db->set('coins', "coins + {$add_reward}", FALSE);
- $this->User_model->update_by_id(['id' => $this->data['id']]);
- $this->Options_model->inc_option('dgold_total_rewarded', $add_reward);
- }
- // reset timer and game codes
- if($reset_timer) {
- $this->data['gamecode1'] = mt_rand(1, 3);
- $this->data['gamecode2'] = mt_rand(0, 1);
- $this->User_model->update_by_id(['id' => $this->data['id'], 'lastgame_at' => time(), 'gamecode1' => $this->data['gamecode1'], 'gamecode2' => $this->data['gamecode2']]);
- }
- die;
- }
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('the_game', $this->data);
- }
- public function the_game_settings()
- {
- //log_message('error', 'the_game_settings-status-'.$_SERVER['REMOTE_ADDR'].'-'.serialize($_POST).'-'.serialize($_GET));
- $this->_check_admin();
- $this->data['game_chest_reward'] = $this->Options_model->get_option('game_chest_reward', 1);
- $this->data['game_flip_reward'] = $this->Options_model->get_option('game_flip_reward', 2);
- $this->data['dollars'] = $this->data['coins'] * $this->data['dgold_rate'];
- // change game elapsed time
- if(!empty($_GET['time_elapsed'])) {
- $time_elapsed = (int)$_GET['time_elapsed'];
- if($time_elapsed > 0) {
- $this->User_model->update_by_id(['id' => $this->data['id'], 'lastgame_at' => time() - 3600 * $this->data['game_countdown'] + $time_elapsed]);
- redirect('/'.$this->load->_get_this_controller_slug().'/'.__FUNCTION__);
- }
- }
- // change game configuration
- if($this->input->post('action') == 'config') {
- $countdown = (int)trim($this->input->post('inputCountdown'));
- $chestReward = (int)trim($this->input->post('inputChestReward'));
- $flipReward = (int)trim($this->input->post('inputFlipReward'));
- if(($countdown > 0) and ($chestReward > 0) and ($flipReward > 0)) {
- $this->Options_model->set_option('game_countdown', $countdown);
- $this->Options_model->set_option('game_chest_reward', $chestReward);
- $this->Options_model->set_option('game_flip_reward', $flipReward);
- $this->data['game_countdown'] = $countdown;
- $this->data['game_chest_reward'] = $chestReward;
- $this->data['game_flip_reward'] = $flipReward;
- }
- }
- // let the game begin!
- if(($this->data['lastgame_at'] < time() - 3600 * $this->data['game_countdown']) and !empty($_GET['open_chest'])) {
- $open_chest = (int)$_GET['open_chest'];
- $add_reward = false;
- $reset_timer = false;
- if(isset($_GET['take_reward'])) {
- if($this->data['gamecode1'] == $open_chest) {
- $add_reward = $this->data['game_chest_reward'];
- }
- $reset_timer = true;
- } elseif(isset($_GET['heads'])) {
- if(($this->data['gamecode1'] == $open_chest) and ($this->data['gamecode2'] == (int)$_GET['heads'])) {
- $add_reward = $this->data['game_flip_reward'];
- echo 1;
- } else {
- echo 0;
- }
- $reset_timer = true;
- } else {
- if($this->data['gamecode1'] == $open_chest) {
- echo 1;
- } else {
- $reset_timer = true;
- echo 0;
- }
- }
- // add reward
- if(!empty($add_reward)) {
- // add 1 coin to user and allow to flip coin
- $this->db->set('coins', "coins + {$add_reward}", FALSE);
- $this->User_model->update_by_id(['id' => $this->data['id']]);
- $this->Options_model->inc_option('dgold_total_rewarded', $add_reward);
- }
- // reset timer and game codes
- if($reset_timer) {
- $this->data['gamecode1'] = mt_rand(1, 3);
- $this->data['gamecode2'] = mt_rand(0, 1);
- $this->User_model->update_by_id(['id' => $this->data['id'], 'lastgame_at' => time(), 'gamecode1' => $this->data['gamecode1'], 'gamecode2' => $this->data['gamecode2']]);
- }
- die;
- }
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('admin_the_game', $this->data);
- }
- public function users($page = 0)
- {
- $this->_check_admin();
- $page = ((int)$page - 1);
- $page = ($page > 0) ? $page : 0;
- // change some user data if asked
- try {
- $user_id = (int)trim($this->input->get('id'));
- $is_confirmed = (int)trim($this->input->get('is_confirmed'));
- $is_banned = (int)trim($this->input->get('is_banned'));
- $is_admin = (int)trim($this->input->get('is_admin'));
- $coins = BigDecimal::of(trim($this->input->get('coins')));
- $ddk = BigDecimal::of(trim($this->input->get('ddk')));
- $dollars = BigDecimal::of(trim($this->input->get('dollars')));
- $dollars_cashout = BigDecimal::of(trim($this->input->get('dollars_cashout')));
- $buy_package = (int)trim($this->input->get('buy_package'));
- //echo $buy_package;die;
- if(($user_id > 0) and ($is_confirmed >= 0) and ($is_banned >= 0) and ($is_admin >= 0) and ($coins->compareTo(0) >= 0)) {
- $objU = $this->User_model->get_one(array('id' => $user_id));
- if(!empty($objU)) {
- $this->User_model->update_by_id(array(
- 'id' => $user_id,
- 'is_confirmed' => $is_confirmed ? 1 : 0,
- 'is_banned' => $is_banned ? 1 : 0,
- 'is_admin' => $is_admin ? 1 : 0,
- 'coins' => (string)$coins,
- 'doomsdaycoin' => (string)$ddk,
- 'usd' => (string)$dollars,
- 'usd_cashout' => (string)$dollars_cashout,
- ));
- if($buy_package > 0) {
- $objPS = $this->Packages_setup_model->get_one(['id' => $buy_package, 'is_active' => 1]);
- if(!empty($objPS)) {
- $this->load->model('Packages_model');
- $t = time();
- $this->Packages_model->insert([
- 'user_id' => $objU['id'],
- 'package_id' => $objPS['id'],
- 'daily_dgolds' => $objPS['daily_dgolds'],
- 'start_date' => $t,//$t - 31 * 86400,
- 'last_payout_date' => $t,//$t - 31 * 86400,
- 'stop_date' => $t + 12 * 30 * 86400,
- 'title' => $objPS['title'],
- 'hash_rate' => $objPS['hash_rate'],
- 'hash_rate_sign' => $objPS['hash_rate_sign'],
- 'last_share' => $t,
- 'next_share' => $t,
- 'is_active' => 1,
- ]);
- }
- }
- redirect('/'.$this->load->_get_this_controller_slug().'/users/');
- }
- }
- } catch(Exception $e) {
- // do nothing
- }
- // del user if asked
- $user_id = (int)trim($this->input->get('del_user'));
- if($user_id > 0) {
- $objU = $this->User_model->get_one(array('id' => $user_id));
- if(!empty($objU)) {
- $this->User_model->delete(array('id' => $user_id));
- redirect('/'.$this->load->_get_this_controller_slug().'/users/');
- }
- }
- // set db query condition if search string sent
- $condition = null;
- $this->data['search'] = null;
- $search = trim($this->input->get('search'));
- if(!empty($search)) {
- $search_int = (int)$search;
- if(($search_int > 0) or ($search === '0')) {
- $condition = "`id`={$search_int} OR `doomsdaycoin`={$search_int} OR `coins`={$search_int} OR `ref`={$search_int} OR `username`={$search_int} OR `name`={$search_int} OR `surname`={$search_int}";
- $this->data['search'] = $search_int;
- } elseif(!empty($search)) {
- $search_str = $this->db->escape($search);
- $search_str = substr($search_str, 0, 1).'%'.substr($search_str, 1, -1).'%'.substr($search_str, -1);
- $condition = "`username` LIKE {$search_str} OR `email` LIKE {$search_str} OR `name` LIKE {$search_str} OR `surname` LIKE {$search_str}";
- $this->data['search'] = $search;
- }
- }
- $this->db->select('SQL_CALC_FOUND_ROWS *', false);
- $this->data['users'] = $this->User_model->get($condition, '`id` DESC', null, $page * $this->data['rows_per_page'], $this->data['rows_per_page']);
- // pagination
- $query = $this->db->query('SELECT FOUND_ROWS() AS records');
- $row = $query->row();
- $base_url = base_url($this->load->_get_this_controller_slug().'/'.__FUNCTION__);
- $this->data['pagination'] = $this->_get_pagination_html($base_url, $row->records);
- $this->load->model('Packages_model');
- $Uids = $this->User_model->gather_columns($this->data['users'], 'id');
- $this->data['users_packages'] = $this->Packages_model->get(['user_id' => $Uids, 'packages.is_active' => 1]);
- //get options
- $this->data['dgold_inc_arr'] = $this->Options_model->get_option('dgold_inc_arr');
- $this->data['dgold_price_arr'] = $this->Options_model->get_option('dgold_price_arr');
- $this->data['dgold_total_rewarded'] = $this->Options_model->get_option('dgold_total_rewarded');
- $this->data['dgold_total_sold_value'] = $this->Options_model->get_option('dgold_total_sold_value');
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('admin_users', $this->data);
- }
- public function mass_message($page = 0)
- {
- $this->_check_admin();
- $page = ((int)$page - 1);
- $page = ($page > 0) ? $page : 0;
- $this->load->model('Blog_posts_model');
- // save as draft if asked
- if($this->input->post('action') == 'save_as_draft') {
- $edit_message = (int)trim($this->input->get('edit_message'));
- $mass_subject = (string)trim($this->input->post('mass_subject'));
- $mass_message = (string)trim($this->input->post('mass_message'));
- if($edit_message > 0) {
- $objME = $this->Blog_posts_model->get_one(['id' => $edit_message, 'is_draft' => 1]);
- if(!empty($objME) and ($objME['subject'] == $mass_subject) and ($objME['message'] == $mass_message)) {
- redirect('/'.$this->load->_get_this_controller_slug()."/mass_message/?edit_message={$edit_message}#new_edit");
- }
- }
- $edit_message = $this->Blog_posts_model->insert([
- 'subject' => $mass_subject,
- 'message' => $mass_message,
- 'is_draft' => 1,
- ]);
- redirect('/'.$this->load->_get_this_controller_slug()."/mass_message/?edit_message={$edit_message}#new_edit");
- }
- // edit message if asked
- $message_id = (int)trim($this->input->get('edit_message'));
- if($message_id > 0) {
- $objME = $this->Blog_posts_model->get_one(['id' => $message_id]);
- if(empty($objME)) {
- redirect('/'.$this->load->_get_this_controller_slug().'/mass_message/');
- }
- $this->data['edit_me'] = $objME;
- }
- // del message if asked
- $message_id = (int)trim($this->input->get('del_message'));
- if($message_id > 0) {
- $this->Blog_posts_model->delete(['id' => $message_id]);
- redirect('/'.$this->load->_get_this_controller_slug().'/mass_message/');
- }
- // del all drafts if asked
- $ask_delete = (int)trim($this->input->get('del_all_drafts'));
- if($ask_delete > 0) {
- $this->Blog_posts_model->delete(['is_draft' => 1]);
- redirect('/'.$this->load->_get_this_controller_slug().'/mass_message/');
- }
- $email_from_email = $this->Options_model->get_option('email_from_email');
- $email_from_name = $this->Options_model->get_option('email_from_name');
- $this->data['email_from_email'] = empty($email_from_email) ? "support@{$_SERVER['HTTP_HOST']}" : $email_from_email;
- $this->data['email_from_name'] = empty($email_from_name) ? 'Admin' : $email_from_name;
- // set db query condition if search string sent
- $condition = null;
- $this->data['search'] = null;
- $search = trim($this->input->get('search'));
- if(!empty($search)) {
- $search_int = (int)$search;
- if(($search_int > 0) or ($search === '0')) {
- $condition = "`id`={$search_int}";
- $this->data['search'] = $search_int;
- } elseif(!empty($search)) {
- $search_str = $this->db->escape($search);
- $search_str = substr($search_str, 0, 1).'%'.substr($search_str, 1, -1).'%'.substr($search_str, -1);
- $condition = "`subject` LIKE {$search_str} OR `message` LIKE {$search_str}";
- $this->data['search'] = $search;
- }
- }
- // send mass email if asked
- if($this->input->post('action') == 'mass_message') {
- $edit_message = (int)trim($this->input->get('edit_message'));
- $mass_subject = (string)trim($this->input->post('mass_subject'));
- $mass_message = (string)trim($this->input->post('mass_message'));
- $err_msg = '';
- if(empty($mass_subject)) {
- $err_msg .= "<br>You should set the Subject!";
- }
- if(empty($mass_message)) {
- $err_msg .= "<br>You should set the Message!";
- }
- if(empty($err_msg)) {
- // send mass message
- $should_insert = true;
- if($edit_message > 0) {
- $objME = $this->Blog_posts_model->get_one(['id' => $edit_message, 'is_draft' => 1]);
- if(!empty($objME) and ($objME['subject'] == $mass_subject) and ($objME['message'] == $mass_message)) {
- $should_insert = false;
- }
- }
- if($should_insert) {
- $edit_message = $this->Blog_posts_model->insert([
- 'subject' => $mass_subject,
- 'message' => $mass_message,
- 'is_draft' => 0,
- ]);
- } else {
- $this->Blog_posts_model->update_by_id([
- 'id' => $edit_message,
- 'is_draft' => 0,
- ]);
- }
- // send notification email to all registered users
- $user_ids = $this->User_model->get(['is_confirmed' => 1, 'is_banned' => 0], null, 'id');
- $this->_send_notification_emails($user_ids, 'id', 'inbox');
- /*
- $from_user_id = $this->Options_model->get_option('support_user_id');
- $message = "<h1>{$mass_subject}</h1>{$mass_message}";
- foreach($retU as $objU) {
- $this->_add_message($from_user_id, $objU['id'], $message);
- }
- */
- } else {
- $this->data['err_msg'] = $err_msg;
- }
- }
- $this->db->select('SQL_CALC_FOUND_ROWS *', false);
- $this->data['messages'] = $this->Blog_posts_model->get($condition, '`updated_at` DESC', 'id, created_at, updated_at, subject, message, is_draft', $page * $this->data['rows_per_page'], $this->data['rows_per_page']);
- // pagination
- $query = $this->db->query('SELECT FOUND_ROWS() AS records');
- $row = $query->row();
- $base_url = base_url($this->load->_get_this_controller_slug().'/'.__FUNCTION__);
- $this->data['pagination'] = $this->_get_pagination_html($base_url, $row->records, ['reuse_query_string' => false]);
- //get options
- $this->data['dgold_inc_arr'] = $this->Options_model->get_option('dgold_inc_arr');
- $this->data['dgold_price_arr'] = $this->Options_model->get_option('dgold_price_arr');
- $this->data['dgold_total_rewarded'] = $this->Options_model->get_option('dgold_total_rewarded');
- $this->data['dgold_total_sold_value'] = $this->Options_model->get_option('dgold_total_sold_value');
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('admin_mass_message', $this->data);
- }
- public function mass_email($page = 0)
- {
- $this->_check_admin();
- $page = ((int)$page - 1);
- $page = ($page > 0) ? $page : 0;
- $allowed_groups = [
- 'test_mail' => '',
- 'verified_users' => ['is_confirmed' => 1],
- 'unverified_users' => ['is_confirmed' => 0],
- 'have_active_mining_package' => ['is_confirmed' => 1],
- 'registered_last_7_days' => 'is_confirmed=1 AND created_at>"' . date('Y-m-d H:i:s', time() - 7 * 86400) . '"',
- ];
- $this->load->model('Mass_email_model');
- // save as draft if asked
- if($this->input->post('action') == 'save_as_draft') {
- $edit_email = (int)trim($this->input->get('edit_email'));
- $user_group = (string)trim($this->input->post('user_group'));
- $mass_subject = (string)trim($this->input->post('mass_subject'));
- $mass_message = (string)trim($this->input->post('mass_message'));
- if(!isset($allowed_groups[$user_group])) {
- redirect('/' . $this->load->_get_this_controller_slug() . '/mass_email/');
- }
- if($edit_email > 0) {
- $objME = $this->Mass_email_model->get_one(['id' => $edit_email, 'is_draft' => 1]);
- if(!empty($objME) and ($objME['user_group'] == $user_group) and ($objME['subject'] == $mass_subject) and ($objME['message'] == $mass_message)) {
- redirect('/'.$this->load->_get_this_controller_slug()."/mass_email/?edit_email={$edit_email}#new_edit");
- }
- }
- $edit_email = $this->Mass_email_model->insert([
- 'user_group' => $user_group,
- 'subject' => $mass_subject,
- 'message' => $mass_message,
- 'is_draft' => 1,
- ]);
- redirect('/'.$this->load->_get_this_controller_slug()."/mass_email/?edit_email={$edit_email}#new_edit");
- }
- // edit email if asked
- $email_id = (int)trim($this->input->get('edit_email'));
- if($email_id > 0) {
- $objME = $this->Mass_email_model->get_one(['id' => $email_id]);
- if(empty($objME)) {
- redirect('/'.$this->load->_get_this_controller_slug().'/mass_email/');
- }
- $this->data['edit_me'] = $objME;
- }
- // del email if asked
- $email_id = (int)trim($this->input->get('del_email'));
- if($email_id > 0) {
- $this->Mass_email_model->delete(['id' => $email_id]);
- redirect('/'.$this->load->_get_this_controller_slug().'/mass_email/');
- }
- // del all drafts if asked
- $ask_delete = (int)trim($this->input->get('del_all_drafts'));
- if($ask_delete > 0) {
- $this->Mass_email_model->delete(['is_draft' => 1]);
- redirect('/'.$this->load->_get_this_controller_slug().'/mass_email/');
- }
- $email_from_email = $this->Options_model->get_option('email_from_email');
- $email_from_name = $this->Options_model->get_option('email_from_name');
- $this->data['email_from_email'] = empty($email_from_email) ? "support@{$_SERVER['HTTP_HOST']}" : $email_from_email;
- $this->data['email_from_name'] = empty($email_from_name) ? 'Admin' : $email_from_name;
- // set db query condition if search string sent
- $condition = null;
- $this->data['search'] = null;
- $search = trim($this->input->get('search'));
- if(!empty($search)) {
- $search_int = (int)$search;
- if(($search_int > 0) or ($search === '0')) {
- $condition = "`id`={$search_int}";
- $this->data['search'] = $search_int;
- } elseif(!empty($search)) {
- $search_str = $this->db->escape($search);
- $search_str = substr($search_str, 0, 1).'%'.substr($search_str, 1, -1).'%'.substr($search_str, -1);
- $condition = "`user_group` LIKE {$search_str} OR `subject` LIKE {$search_str} OR `message` LIKE {$search_str}";
- $this->data['search'] = $search;
- }
- }
- // send mass email if asked
- if($this->input->post('action') == 'mass_email') {
- $edit_email = (int)trim($this->input->get('edit_email'));
- $user_group = (string)trim($this->input->post('user_group'));
- $mass_subject = (string)trim($this->input->post('mass_subject'));
- $mass_message = (string)trim($this->input->post('mass_message'));
- $err_msg = '';
- if(!isset($allowed_groups[$user_group])) {
- $err_msg .= "<br>Selected Group of Users is not allowed!";
- } else {
- if($user_group == 'test_mail') {
- $emails = explode("\r\n", $this->Options_model->get_option('massmail_test_email'));
- $retU = [];
- foreach($emails as $email) {
- $email = trim($email);
- if(empty($email))
- continue;
- $retU[] = [
- 'username' => 'Tester',
- 'name' => '',
- 'surname' => '',
- 'email' => $email,
- ];
- }
- } else {
- if ($user_group == 'have_active_mining_package') {
- $this->db->distinct();
- $this->db->join('packages', 'user.id = packages.user_id');
- }
- $retU = $this->User_model->get($allowed_groups[$user_group], null, 'user.id, user.username, user.email, user.name, user.surname');
- }
- }
- if(empty($mass_subject)) {
- $err_msg .= "<br>You should set the Subject!";
- }
- if(empty($mass_message)) {
- $err_msg .= "<br>You should set the Message!";
- }
- if(empty($retU)) {
- $err_msg .= "<br>No any users in this criteria found!";
- }
- if(empty($err_msg)) {
- // Save this email copy to Inbox if asked
- if(!empty($this->input->post('save_to_inbox'))) {
- $this->load->model('Blog_posts_model');
- $this->Blog_posts_model->insert([
- 'subject' => $mass_subject,
- 'message' => $mass_message,
- 'is_draft' => 0,
- 'is_company_email' => 1,
- ]);
- }
- // send mass email
- $sendgrid_api_key = $this->Options_model->get_option('sendgrid_api_key');
- $tos = [];
- foreach($retU as $objU) {
- $tos[$objU['email']] = $this->User_model->get_user_name($objU);
- }
- $tos_chunked = array_chunk($tos, 99, true);
- $should_insert = true;
- if($edit_email > 0) {
- $objME = $this->Mass_email_model->get_one(['id' => $edit_email, 'is_draft' => 1]);
- if(!empty($objME) and ($objME['user_group'] == $user_group) and ($objME['subject'] == $mass_subject) and ($objME['message'] == $mass_message)) {
- $should_insert = false;
- }
- }
- if($should_insert) {
- $edit_email = $this->Mass_email_model->insert([
- 'user_group' => $user_group,
- 'subject' => $mass_subject,
- 'message' => $mass_message,
- 'should_emails' => serialize($tos),
- 'sent_emails' => serialize([]),
- 'is_draft' => 0,
- ]);
- } else {
- $this->Mass_email_model->update_by_id([
- 'id' => $edit_email,
- 'should_emails' => serialize($tos),
- 'sent_emails' => serialize([]),
- 'is_draft' => 0,
- ]);
- }
- $sent_emails = [];
- foreach($tos_chunked as $tos_chunk) {
- $sendgrid_from = new \SendGrid\Mail\From($this->data['email_from_email'], $this->data['email_from_name']);
- $sendgrid_tos = [];
- foreach($tos_chunk as $tos_email => $tos_name) {
- $sendgrid_tos[] = new \SendGrid\Mail\To($tos_email, $tos_name);
- }
- $sendgrid_subject = new \SendGrid\Mail\Subject($mass_subject);
- $plainTextContent = new \SendGrid\Mail\PlainTextContent('');
- $htmlContent = new \SendGrid\Mail\HtmlContent($mass_message);
- $email = new \SendGrid\Mail\Mail(
- $sendgrid_from,
- $sendgrid_tos,
- $sendgrid_subject,
- $plainTextContent,
- $htmlContent
- );
- $sendgrid = new \SendGrid($sendgrid_api_key);
- try {
- $response = $sendgrid->send($email);
- $status = $response->statusCode();
- if(($status == 200) or ($status == 202)) {
- $sent_emails = array_merge($sent_emails, $tos_chunk);
- $this->Mass_email_model->update_by_id([
- 'id' => $edit_email,
- 'should_emails' => serialize(array_diff_assoc($tos, $sent_emails)),
- 'sent_emails' => serialize($sent_emails),
- ]);
- }
- log_message('error', 'Sendgrid-' . $user_group . '-ok_response-' . $status . '-' . serialize($response->headers()) . '-' . serialize($response->body()));
- } catch (Exception $e) {
- log_message('error', 'Sendgrid-' . $user_group . '-exception-' . $e->getMessage());
- }
- }
- /*
- foreach($tos_chunked as $tos_chunk) {
- $email = new \SendGrid\Mail\Mail();
- $email->setFrom($this->data['email_from_email'], $this->data['email_from_name']);
- $email->addTos($tos_chunk);
- $email->setSubject($mass_subject);
- //$email->addContent("text/plain", "and easy to do anywhere, even with PHP");
- $email->addContent("text/html", $mass_message);
- $sendgrid = new \SendGrid($sendgrid_api_key);
- try {
- $response = $sendgrid->send($email);
- $status = $response->statusCode();
- if(($status == 200) or ($status == 202)) {
- $sent_emails = array_merge($sent_emails, $tos_chunk);
- $this->Mass_email_model->update_by_id([
- 'id' => $edit_email,
- 'should_emails' => serialize(array_diff_assoc($tos, $sent_emails)),
- 'sent_emails' => serialize($sent_emails),
- ]);
- }
- log_message('error', 'Sendgrid-' . $user_group . '-ok_response-' . $status . '-' . serialize($response->headers()) . '-' . serialize($response->body()));
- } catch (Exception $e) {
- log_message('error', 'Sendgrid-' . $user_group . '-exception-' . $e->getMessage());
- }
- }
- */
- } else {
- $this->data['err_msg'] = $err_msg;
- }
- }
- $this->db->select('SQL_CALC_FOUND_ROWS *', false);
- $this->data['emails'] = $this->Mass_email_model->get($condition, '`updated_at` DESC', 'id, created_at, updated_at, user_group, subject, message, is_draft', $page * $this->data['rows_per_page'], $this->data['rows_per_page']);
- // pagination
- $query = $this->db->query('SELECT FOUND_ROWS() AS records');
- $row = $query->row();
- $base_url = base_url($this->load->_get_this_controller_slug().'/'.__FUNCTION__);
- $this->data['pagination'] = $this->_get_pagination_html($base_url, $row->records, ['reuse_query_string' => false]);
- //echo $base_url;print_r($this->data['pagination']);die;
- //get options
- $this->data['dgold_inc_arr'] = $this->Options_model->get_option('dgold_inc_arr');
- $this->data['dgold_price_arr'] = $this->Options_model->get_option('dgold_price_arr');
- $this->data['dgold_total_rewarded'] = $this->Options_model->get_option('dgold_total_rewarded');
- $this->data['dgold_total_sold_value'] = $this->Options_model->get_option('dgold_total_sold_value');
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('admin_mass_email', $this->data);
- }
- public function dgold_tables()
- {
- $this->_check_admin();
- // change referral reward table if asked
- if($this->input->post('action') == 'table_options') {
- $rows_per_page = (int)trim($this->input->post('rows_per_page'));
- $pagination_num_links = (int)trim($this->input->post('pagination_num_links'));
- if($rows_per_page > 0) {
- $this->Options_model->set_option('rows_per_page', $rows_per_page);
- }
- if($pagination_num_links >= 0) {
- $this->Options_model->set_option('pagination_num_links', $pagination_num_links);
- }
- }
- // change referral reward table if asked
- if($this->input->post('action') == 'dgold_prices') {
- //a:10:{i:1000000;s:5:"0.001";i:20000000;s:5:"0.002";i:100000000;s:5:"0.003";i:300000000;s:5:"0.004";i:500000000;s:5:"0.005";i:700000000;s:5:"0.006";i:900000000;s:5:"0.007";s:13:"1000000000000";s:5:"0.008";s:13:"3000000000000";s:5:"0.009";s:13:"5000000000000";s:4:"0.01";}
- $is_err = false;
- try {
- $dgold_price_arr = array();
- for($i = 1; $i <= 10; $i++) {
- $pp = (double)trim($this->input->post("pp{$i}"));
- $cs = BigInteger::of(trim($this->input->post("cs{$i}")));
- if(($pp > 0) and ($cs->compareTo(0) == 1)) {
- $dgold_price_arr[(string)$cs] = number_format($pp, 3, '.', '');
- } else {
- $is_err = true;
- }
- }
- } catch(Exception $e) {
- // do nothing
- }
- if(!$is_err and (count($dgold_price_arr) == 10)) {
- $this->Options_model->set_option('dgold_price_arr', $dgold_price_arr);
- }
- }
- // recalculate values button
- if($this->input->post('action') == 'recalculate') {
- $this->load->model('Ticket_model');
- $sum = $this->Ticket_model->get(array('is_paid' => 1), null, 'sum(`amount_usd`) a_usd, sum(`amount_dgold`) a_dgold');
- $this->Options_model->set_option('dgold_total_sold_value', $sum[0]['a_usd']);
- $this->Options_model->set_option('dgold_total_sold', 0);
- $this->Options_model->inc_option('dgold_total_sold', $sum[0]['a_dgold']);
- }
- // change referral reward table if asked
- if($this->input->post('action') == 'registration_reward') {
- $reg = (int)trim($this->input->post('reg'));
- $lvl1 = (int)trim($this->input->post('lvl1'));
- $lvl2 = (int)trim($this->input->post('lvl2'));
- $lvl3 = (int)trim($this->input->post('lvl3'));
- $lvl4 = (int)trim($this->input->post('lvl4'));
- $lvl5 = (int)trim($this->input->post('lvl5'));
- $purchase_reward = (int)trim($this->input->post('purchase_reward'));
- $mining_reward_lvl1 = (int)trim($this->input->post('mining_reward_lvl1'));
- $mining_reward_lvl2 = (int)trim($this->input->post('mining_reward_lvl2'));
- if (($reg >= 0) and ($lvl1 >= 0) and ($lvl2 >= 0) and ($lvl3 >= 0) and ($lvl4 >= 0) and ($lvl5 >= 0)) {
- $this->Options_model->set_option('dgold_inc_arr', [$reg, $lvl1, $lvl2, $lvl3, $lvl4, $lvl5]);
- }
- if($purchase_reward >= 0) {
- $this->Options_model->set_option('dgold_purchase_reward', $purchase_reward);
- }
- if(($mining_reward_lvl1 >= 0) and ($mining_reward_lvl2 >= 0)) {
- $this->Options_model->set_option('dgold_mining_reward_lvl1', $mining_reward_lvl1);
- $this->Options_model->set_option('dgold_mining_reward_lvl2', $mining_reward_lvl2);
- }
- }
- //get options
- $this->data['pagination_num_links'] = $this->Options_model->get_option('pagination_num_links');
- $this->data['dgold_inc_arr'] = $this->Options_model->get_option('dgold_inc_arr');
- $this->data['purchase_reward'] = $this->Options_model->get_option('dgold_purchase_reward');
- $this->data['mining_reward_lvl1'] = $this->Options_model->get_option('dgold_mining_reward_lvl1');
- $this->data['mining_reward_lvl2'] = $this->Options_model->get_option('dgold_mining_reward_lvl2');
- $this->data['dgold_price_arr'] = $this->Options_model->get_option('dgold_price_arr');
- $this->data['dgold_total_rewarded'] = $this->Options_model->get_option('dgold_total_rewarded');
- $this->data['dgold_total_sold_value'] = $this->Options_model->get_option('dgold_total_sold_value');
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('admin_dgold_tables', $this->data);
- }
- public function invoices_usd($page = 0)
- {
- $this->_check_admin();
- $page = ((int)$page - 1);
- $page = ($page > 0) ? $page : 0;
- $this->load->model('Money_model');
- // del package_setup if asked
- $invoice_id = (int)trim($this->input->get('del_invoice'));
- if($invoice_id > 0) {
- $this->Money_model->delete(['id' => $invoice_id]);
- redirect('/'.$this->load->_get_this_controller_slug().'/invoices_usd/');
- }
- // set db query condition if search string sent
- $condition = null;
- $this->data['search'] = null;
- if($this->input->post('action') == 'search') {
- $search = trim($this->input->post('search'));
- $search_int = (int)$search;
- if(($search_int > 0) or ($search === '0')) {
- $condition = "money.id={$search_int} OR `user_id`={$search_int} OR `amount_usd`={$search_int}";
- $this->data['search'] = $search_int;
- } elseif(!empty($search)) {
- $search_str = $this->db->escape($search);
- $search_str = substr($search_str, 0, 1).'%'.substr($search_str, 1, -1).'%'.substr($search_str, -1);
- $condition = "user.email LIKE {$search_str} OR merchant LIKE {$search_str}";
- $this->data['search'] = $search;
- }
- }
- //get options
- $this->data['dgold_inc_arr'] = $this->Options_model->get_option('dgold_inc_arr');
- $this->data['dgold_price_arr'] = $this->Options_model->get_option('dgold_price_arr');
- $this->data['dgold_total_rewarded'] = $this->Options_model->get_option('dgold_total_rewarded');
- $this->data['dgold_total_sold_value'] = $this->Options_model->get_option('dgold_total_sold_value');
- $this->db->join('user', 'user.id = money.user_id');
- $this->db->select('SQL_CALC_FOUND_ROWS *', false);
- $this->data['invoices'] = $this->Money_model->get($condition, '`money`.`updated_at` DESC', 'money.*, user.email', $page * $this->data['rows_per_page'], $this->data['rows_per_page']);
- // pagination
- $query = $this->db->query('SELECT FOUND_ROWS() AS records');
- $row = $query->row();
- $base_url = base_url($this->load->_get_this_controller_slug().'/'.__FUNCTION__);
- $this->data['pagination'] = $this->_get_pagination_html($base_url, $row->records);
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('admin_invoices_usd', $this->data);
- }
- public function videos()
- {
- $this->_check_login();
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('videos', $this->data);
- }
- public function invoices_dgold($page = 0)
- {
- $this->_check_admin();
- $page = ((int)$page - 1);
- $page = ($page > 0) ? $page : 0;
- $this->load->model('Ticket_model');
- // del package_setup if asked
- $invoice_id = (int)trim($this->input->get('del_invoice'));
- if($invoice_id > 0) {
- $this->Ticket_model->delete(['id' => $invoice_id]);
- redirect('/'.$this->load->_get_this_controller_slug().'/invoices_dgold/');
- }
- // set db query condition if search string sent
- $condition = null;
- $this->data['search'] = null;
- if($this->input->post('action') == 'search') {
- $search = trim($this->input->post('search'));
- $search_int = (int)$search;
- if(($search_int > 0) or ($search === '0')) {
- $condition = "ticket.id={$search_int} OR `user_id`={$search_int} OR `amount_usd`={$search_int} OR `amount_dgold`={$search_int}";
- $this->data['search'] = $search_int;
- } elseif(!empty($search)) {
- $search_str = $this->db->escape($search);
- $search_str = substr($search_str, 0, 1).'%'.substr($search_str, 1, -1).'%'.substr($search_str, -1);
- $condition = "user.email LIKE {$search_str} OR merchant LIKE {$search_str}";
- $this->data['search'] = $search;
- }
- }
- //get options
- $this->data['dgold_inc_arr'] = $this->Options_model->get_option('dgold_inc_arr');
- $this->data['dgold_price_arr'] = $this->Options_model->get_option('dgold_price_arr');
- $this->data['dgold_total_rewarded'] = $this->Options_model->get_option('dgold_total_rewarded');
- $this->data['dgold_total_sold_value'] = $this->Options_model->get_option('dgold_total_sold_value');
- $this->db->join('user', 'user.id = ticket.user_id');
- $this->db->select('SQL_CALC_FOUND_ROWS *', false);
- $this->data['invoices'] = $this->Ticket_model->get($condition, '`ticket`.`updated_at` DESC', 'ticket.*, user.email', $page * $this->data['rows_per_page'], $this->data['rows_per_page']);
- // pagination
- $query = $this->db->query('SELECT FOUND_ROWS() AS records');
- $row = $query->row();
- $base_url = base_url($this->load->_get_this_controller_slug().'/'.__FUNCTION__);
- $this->data['pagination'] = $this->_get_pagination_html($base_url, $row->records);
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('admin_invoices_dgold', $this->data);
- }
- public function docs($page = 0)
- {
- $this->_check_admin();
- $page = ((int)$page - 1);
- $page = ($page > 0) ? $page : 0;
- $this->load->model('Docs_model');
- // del doc if asked
- $doc_id = (int)trim($this->input->get('del_doc'));
- if($doc_id > 0) {
- $this->Docs_model->delete(['id' => $doc_id]);
- redirect('/'.$this->load->_get_this_controller_slug().'/docs/');
- }
- // change doc if asked
- $doc_id = (int)trim($this->input->get('change_id'));
- $is_approved = (int)trim($this->input->get('is_approved'));
- if(($doc_id > 0) and ($is_approved >= 0)) {
- $this->Docs_model->update_by_id([
- 'id' => $doc_id,
- 'is_approved' => $is_approved ? 1 : 0,
- ]);
- redirect('/'.$this->load->_get_this_controller_slug().'/docs/');
- }
- // set db query condition if search string sent
- $condition = null;
- $this->data['search'] = null;
- if($this->input->post('action') == 'search') {
- $search = trim($this->input->post('search'));
- $search_int = (int)$search;
- if(($search_int > 0) or ($search === '0')) {
- $condition = "docs.id={$search_int} OR `user_id`={$search_int}";
- $this->data['search'] = $search_int;
- } elseif(!empty($search)) {
- $search_str = $this->db->escape($search);
- $search_str = substr($search_str, 0, 1).'%'.substr($search_str, 1, -1).'%'.substr($search_str, -1);
- $condition = "user.email LIKE {$search_str} OR user.username LIKE {$search_str} OR user.name LIKE {$search_str} OR user.surname LIKE {$search_str}";
- $this->data['search'] = $search;
- }
- }
- $this->db->join('user', 'user.id = docs.user_id');
- $this->db->select('SQL_CALC_FOUND_ROWS *', false);
- $this->data['docs'] = $this->Docs_model->get($condition, 'docs.updated_at DESC', 'docs.*, user.email, user.username, user.name, user.surname', $page * $this->data['rows_per_page'], $this->data['rows_per_page']);
- // pagination
- $query = $this->db->query('SELECT FOUND_ROWS() AS records');
- $row = $query->row();
- $base_url = base_url($this->load->_get_this_controller_slug().'/'.__FUNCTION__);
- $this->data['pagination'] = $this->_get_pagination_html($base_url, $row->records);
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('admin_docs', $this->data);
- }
- public function packages($page = 0)
- {
- $this->_check_admin();
- $page = ((int)$page - 1);
- $page = ($page > 0) ? $page : 0;
- // add new package_setup if asked
- if($this->input->post('action') == 'add_new_package') {
- $all_packages = $this->Packages_setup_model->get();
- $cnt = empty($all_packages) ? 0 : count($all_packages);
- $this->Packages_setup_model->insert([
- 'is_active' => 0,
- 'title' => "New Package Title {$cnt}",
- 'price' => 0,
- 'hash_rate' => 0,
- 'daily_dgolds' => 0,
- 'show_order' => $cnt,
- ]);
- redirect('/'.$this->load->_get_this_controller_slug().'/packages/');
- }
- // del package_setup if asked
- $package_id = (int)trim($this->input->get('del_package_setup'));
- if($package_id > 0) {
- $this->Packages_setup_model->delete(['id' => $package_id]);
- redirect('/'.$this->load->_get_this_controller_slug().'/packages/');
- }
- // change package_setup if asked
- $package_id = (int)trim($this->input->get('change_id_setup'));
- $is_active = (int)trim($this->input->get('is_active'));
- $title = (string)trim($this->input->get('title'));
- $price = (string)trim($this->input->get('price'));
- $hash_rate = (string)trim($this->input->get('hash_rate'));
- $hash_rate_sign = (string)trim($this->input->get('hash_rate_sign'));
- $daily_dgolds = (int)trim($this->input->get('daily_dgolds'));
- $show_order = (int)trim($this->input->get('show_order'));
- if($package_id > 0) {
- $this->Packages_setup_model->update_by_id([
- 'id' => $package_id,
- 'is_active' => $is_active ? 1 : 0,
- 'title' => $title,
- 'price' => $price,
- 'hash_rate' => $hash_rate,
- 'hash_rate_sign' => $hash_rate_sign,
- 'daily_dgolds' => $daily_dgolds,
- 'show_order' => $show_order,
- ]);
- $this->load->model('Packages_model');
- $this->Packages_model->update(['package_id' => $package_id], [
- 'daily_dgolds' => $daily_dgolds,
- ]);
- redirect('/'.$this->load->_get_this_controller_slug().'/packages/');
- }
- $this->data['all_packages_setup'] = $this->Packages_setup_model->get();
- $this->load->model('Packages_model');
- // change package if asked
- $package_id = (int)trim($this->input->get('change_id'));
- $is_active = (int)trim($this->input->get('is_active'));
- if($package_id > 0) {
- $this->Packages_model->update_by_id([
- 'id' => $package_id,
- 'is_active' => $is_active ? 1 : 0,
- ]);
- redirect('/'.$this->load->_get_this_controller_slug().'/packages/');
- }
- // set db query condition if search string sent
- $condition = null;
- $this->data['search'] = null;
- if($this->input->post('action') == 'search') {
- $search = trim($this->input->post('search'));
- $search_int = (int)$search;
- if(($search_int > 0) or ($search === '0')) {
- $condition = "packages.id={$search_int} OR `user_id`={$search_int}";
- $this->data['search'] = $search_int;
- } elseif(!empty($search)) {
- $search_str = $this->db->escape($search);
- $search_str = substr($search_str, 0, 1).'%'.substr($search_str, 1, -1).'%'.substr($search_str, -1);
- $condition = "user.email LIKE {$search_str} OR packages.title LIKE {$search_str}";
- $this->data['search'] = $search;
- }
- }
- $this->db->join('user', 'user.id = packages.user_id');
- $this->db->select('SQL_CALC_FOUND_ROWS *', false);
- $this->data['packages'] = $this->Packages_model->get($condition, 'packages.created_at DESC', 'packages.*, user.email', $page * $this->data['rows_per_page'], $this->data['rows_per_page']);
- // pagination
- $query = $this->db->query('SELECT FOUND_ROWS() AS records');
- $row = $query->row();
- $base_url = base_url($this->load->_get_this_controller_slug().'/'.__FUNCTION__);
- $this->data['pagination'] = $this->_get_pagination_html($base_url, $row->records);
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('admin_packages', $this->data);
- }
- public function payouts_paypal()
- {
- $this->_check_admin();
- $this->load->model('Payout_model');
- $payout_id = (int)trim($this->input->get('cancel'));
- if($payout_id > 0) {
- $this->Payout_model->update_by_id([
- 'id' => $payout_id,
- 'is_paid' => 0,
- 'extra' => '',
- ]);
- }
- $payout_id = (int)trim($this->input->get('done'));
- if($payout_id > 0) {
- $this->Payout_model->update_by_id([
- 'id' => $payout_id,
- 'is_paid' => 1,
- 'extra' => '',
- ]);
- }
- redirect('/'.$this->load->_get_this_controller_slug().'/payouts/');
- }
- public function payouts($page = 0)
- {
- $this->_check_admin();
- $page = ((int)$page - 1);
- $page = ($page > 0) ? $page : 0;
- $this->load->model('Payout_model');
- // del payout if asked
- $payout_id = (int)trim($this->input->get('del_payout'));
- if($payout_id > 0) {
- $this->Payout_model->delete_payout($this->data['id'], $payout_id);
- redirect('/'.$this->load->_get_this_controller_slug().'/payouts/');
- }
- // approve payout if asked
- $payout_id = (int)trim($this->input->get('pay_now'));
- if($payout_id > 0) {
- $this->Payout_model->approve_payout($payout_id);
- $objP = $this->Payout_model->get_one(['id' => $payout_id, 'is_paid' => 1]);
- if(!empty($objP)) {
- $objU = $this->User_model->get_one(['id' => $objP['user_id']]);
- $this->_send_payout_email($objU, $objP);
- }
- redirect('/'.$this->load->_get_this_controller_slug().'/payouts/');
- }
- // set db query condition if search string sent
- $condition = null;
- $this->data['search'] = null;
- if($this->input->post('action') == 'search') {
- $search = trim($this->input->post('search'));
- $search_int = (int)$search;
- $search_double = "{$search}.00";
- if(($search_int > 0) or ($search === '0')) {
- $condition = "payout.id={$search_int} OR payout.amount_usd={$search_double} OR `user_id`={$search_int}";
- $this->data['search'] = $search_int;
- } elseif(!empty($search)) {
- $search_str = $this->db->escape($search);
- $search_str = substr($search_str, 0, 1).'%'.substr($search_str, 1, -1).'%'.substr($search_str, -1);
- $condition = "user.email LIKE {$search_str} OR payout.merchant LIKE {$search_str}";
- $this->data['search'] = $search;
- }
- }
- $this->db->join('user', 'user.id = payout.user_id');
- $this->db->select('SQL_CALC_FOUND_ROWS *', false);
- $this->data['payouts'] = $this->Payout_model->get($condition, 'payout.updated_at DESC', 'payout.*, user.email, user.my_payout_options', $page * $this->data['rows_per_page'], $this->data['rows_per_page']);
- // pagination
- $query = $this->db->query('SELECT FOUND_ROWS() AS records');
- $row = $query->row();
- $base_url = base_url($this->load->_get_this_controller_slug().'/'.__FUNCTION__);
- $this->data['pagination'] = $this->_get_pagination_html($base_url, $row->records);
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('admin_payouts', $this->data);
- }
- public function merchants()
- {
- $this->_check_admin();
- // change SolidTrustPay config if asked
- if($this->input->post('action') == 'solidtrustpay') {
- $solidtrustpay_merchantAccount = (string)trim($this->input->post('solidtrustpay_merchantAccount'));
- $solidtrustpay_sci_name = (string)trim($this->input->post('solidtrustpay_sci_name'));
- $solidtrustpay_sci_password = (string)trim($this->input->post('solidtrustpay_sci_password'));
- $solidtrustpay_on = (string)trim($this->input->post('solidtrustpay_on'));
- $this->Options_model->set_option('merchant_solidtrustpay_merchantAccount', $solidtrustpay_merchantAccount);
- $this->Options_model->set_option('merchant_solidtrustpay_sci_name', $solidtrustpay_sci_name);
- $this->Options_model->set_option('merchant_solidtrustpay_sci_password', $solidtrustpay_sci_password);
- $this->Options_model->set_option('merchant_solidtrustpay_on', empty($solidtrustpay_on) ? 0 : 1);
- }
- // change Payeer config if asked
- if($this->input->post('action') == 'payeer') {
- $payeer_id = (string)trim($this->input->post('payeer_id'));
- $payeer_key = (string)trim($this->input->post('payeer_key'));
- $payeer_on = (string)trim($this->input->post('payeer_on'));
- $this->Options_model->set_option('merchant_payeer_id', $payeer_id);
- $this->Options_model->set_option('merchant_payeer_key', $payeer_key);
- $this->Options_model->set_option('merchant_payeer_on', empty($payeer_on) ? 0 : 1);
- }
- // change AdvCash config if asked
- if($this->input->post('action') == 'advcash') {
- $advcash_email = (string)trim($this->input->post('advcash_email'));
- $advcash_sci_name = (string)trim($this->input->post('advcash_sci_name'));
- $advcash_secret = (string)trim($this->input->post('advcash_secret'));
- $advcash_on = (string)trim($this->input->post('advcash_on'));
- $this->Options_model->set_option('merchant_advcash_email', $advcash_email);
- $this->Options_model->set_option('merchant_advcash_sci_name', $advcash_sci_name);
- $this->Options_model->set_option('merchant_advcash_secret', $advcash_secret);
- $this->Options_model->set_option('merchant_advcash_on', empty($advcash_on) ? 0 : 1);
- }
- // change Cryptonator config if asked
- if($this->input->post('action') == 'cryptonator') {
- $cryptonator_merchant_id = (string)trim($this->input->post('cryptonator_merchant_id'));
- $cryptonator_secret = (string)trim($this->input->post('cryptonator_secret'));
- $cryptonator_currency = (array)$this->input->post('cryptonator_currency');
- $cryptonator_on = (string)trim($this->input->post('cryptonator_on'));
- $this->Options_model->set_option('merchant_cryptonator_merchant_id', $cryptonator_merchant_id);
- $this->Options_model->set_option('merchant_cryptonator_secret', $cryptonator_secret);
- $this->Options_model->set_option('merchant_cryptonator_currency', $cryptonator_currency);
- $this->Options_model->set_option('merchant_cryptonator_on', empty($cryptonator_on) ? 0 : 1);
- }
- // change BTC config if asked
- if($this->input->post('action') == 'btc') {
- $btc_xpub = (string)trim($this->input->post('btc_xpub'));
- $btc_api_key = (string)trim($this->input->post('btc_api_key'));
- $btc_secret = (string)trim($this->input->post('btc_secret'));
- $btc_on = (string)trim($this->input->post('btc_on'));
- $this->Options_model->set_option('merchant_btc_xpub', $btc_xpub);
- $this->Options_model->set_option('merchant_btc_api_key', $btc_api_key);
- $this->Options_model->set_option('merchant_btc_secret', $btc_secret);
- $this->Options_model->set_option('merchant_btc_on', empty($btc_on) ? 0 : 1);
- }
- // change CoinBase config if asked
- if($this->input->post('action') == 'coinbase') {
- $coinbase_api_key = (string)trim($this->input->post('coinbase_api_key'));
- $coinbase_webhook_secret = (string)trim($this->input->post('coinbase_webhook_secret'));
- $coinbase_on = (string)trim($this->input->post('coinbase_on'));
- $this->Options_model->set_option('merchant_coinbase_api_key', $coinbase_api_key);
- $this->Options_model->set_option('merchant_coinbase_webhook_secret', $coinbase_webhook_secret);
- $this->Options_model->set_option('merchant_coinbase_on', empty($coinbase_on) ? 0 : 1);
- }
- // change PayPal config if asked
- if($this->input->post('action') == 'paypal') {
- $paypal_email = (string)trim($this->input->post('paypal_email'));
- $paypal_sandbox_mode = (string)trim($this->input->post('paypal_sandbox_mode'));
- $paypal_on = (string)trim($this->input->post('paypal_on'));
- $this->Options_model->set_option('merchant_paypal_email', $paypal_email);
- $this->Options_model->set_option('merchant_paypal_sandbox_mode', empty($paypal_sandbox_mode) ? 0 : 1);
- $this->Options_model->set_option('merchant_paypal_on', empty($paypal_on) ? 0 : 1);
- }
- if($this->input->post('action') == 'paypal_payout') {
- $paypal_payout_username = (string)trim($this->input->post('paypal_payout_username'));
- $paypal_payout_password = (string)trim($this->input->post('paypal_payout_password'));
- $paypal_payout_signature = (string)trim($this->input->post('paypal_payout_signature'));
- $paypal_payout_appid = (string)trim($this->input->post('paypal_payout_appid'));
- $paypal_payout_sandbox_mode = (string)trim($this->input->post('paypal_payout_sandbox_mode'));
- $paypal_payout_on = (string)trim($this->input->post('paypal_payout_on'));
- $this->Options_model->set_option('merchant_paypal_payout_username', $paypal_payout_username);
- $this->Options_model->set_option('merchant_paypal_payout_password', $paypal_payout_password);
- $this->Options_model->set_option('merchant_paypal_payout_signature', $paypal_payout_signature);
- $this->Options_model->set_option('merchant_paypal_payout_appid', $paypal_payout_appid);
- $this->Options_model->set_option('merchant_paypal_payout_sandbox_mode', empty($paypal_payout_sandbox_mode) ? 0 : 1);
- $this->Options_model->set_option('merchant_paypal_payout_on', empty($paypal_payout_on) ? 0 : 1);
- }
- // get options
- $this->data['dgold_inc_arr'] = $this->Options_model->get_option('dgold_inc_arr');
- $this->data['dgold_price_arr'] = $this->Options_model->get_option('dgold_price_arr');
- $this->data['dgold_total_rewarded'] = $this->Options_model->get_option('dgold_total_rewarded');
- $this->data['dgold_total_sold_value'] = $this->Options_model->get_option('dgold_total_sold_value');
- // get merchants options
- $this->data['solidtrustpay_merchantAccount'] = $this->Options_model->get_option('merchant_solidtrustpay_merchantAccount');
- $this->data['solidtrustpay_sci_name'] = $this->Options_model->get_option('merchant_solidtrustpay_sci_name');
- $this->data['solidtrustpay_sci_password'] = $this->Options_model->get_option('merchant_solidtrustpay_sci_password');
- $this->data['solidtrustpay_on'] = $this->Options_model->get_option('merchant_solidtrustpay_on');
- $this->data['payeer_id'] = $this->Options_model->get_option('merchant_payeer_id');
- $this->data['payeer_key'] = $this->Options_model->get_option('merchant_payeer_key');
- $this->data['payeer_on'] = $this->Options_model->get_option('merchant_payeer_on');
- $this->data['advcash_email'] = $this->Options_model->get_option('merchant_advcash_email');
- $this->data['advcash_sci_name'] = $this->Options_model->get_option('merchant_advcash_sci_name');
- $this->data['advcash_secret'] = $this->Options_model->get_option('merchant_advcash_secret');
- $this->data['advcash_on'] = $this->Options_model->get_option('merchant_advcash_on');
- $this->data['cryptonator_merchant_id'] = $this->Options_model->get_option('merchant_cryptonator_merchant_id');
- $this->data['cryptonator_secret'] = $this->Options_model->get_option('merchant_cryptonator_secret');
- $this->data['cryptonator_currency'] = $this->Options_model->get_option('merchant_cryptonator_currency');
- $this->data['cryptonator_on'] = $this->Options_model->get_option('merchant_cryptonator_on');
- $this->data['btc_xpub'] = $this->Options_model->get_option('merchant_btc_xpub');
- $this->data['btc_api_key'] = $this->Options_model->get_option('merchant_btc_api_key');
- $this->data['btc_secret'] = $this->Options_model->get_option('merchant_btc_secret');
- $this->data['btc_on'] = $this->Options_model->get_option('merchant_btc_on');
- $this->data['coinbase_api_key'] = $this->Options_model->get_option('merchant_coinbase_api_key');
- $this->data['coinbase_webhook_secret'] = $this->Options_model->get_option('merchant_coinbase_webhook_secret');
- $this->data['coinbase_on'] = $this->Options_model->get_option('merchant_coinbase_on');
- $this->data['paypal_email'] = $this->Options_model->get_option('merchant_paypal_email');
- $this->data['paypal_sandbox_mode'] = $this->Options_model->get_option('merchant_paypal_sandbox_mode');
- $this->data['paypal_on'] = $this->Options_model->get_option('merchant_paypal_on');
- $this->data['paypal_payout_username'] = $this->Options_model->get_option('merchant_paypal_payout_username');
- $this->data['paypal_payout_password'] = $this->Options_model->get_option('merchant_paypal_payout_password');
- $this->data['paypal_payout_signature'] = $this->Options_model->get_option('merchant_paypal_payout_signature');
- $this->data['paypal_payout_appid'] = $this->Options_model->get_option('merchant_paypal_payout_appid');
- $this->data['paypal_payout_sandbox_mode'] = $this->Options_model->get_option('merchant_paypal_payout_sandbox_mode');
- $this->data['paypal_payout_on'] = $this->Options_model->get_option('merchant_paypal_payout_on');
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('admin_merchants', $this->data);
- }
- public function email_settings()
- {
- $this->_check_admin();
- // change email config if asked
- if($this->input->post('action') == 'email_config') {
- $from_email = (string)trim($this->input->post('from_email'));
- $from_name = (string)trim($this->input->post('from_name'));
- $this->Options_model->set_option('email_from_email', $from_email);
- $this->Options_model->set_option('email_from_name', $from_name);
- }
- // change SMTP config if asked
- if($this->input->post('action') == 'smtp_config') {
- $smtp_host = (string)trim($this->input->post('smtp_host'));
- $smtp_port = (string)trim($this->input->post('smtp_port'));
- $smtp_security = (string)trim($this->input->post('smtp_security'));
- $smtp_username = (string)trim($this->input->post('smtp_username'));
- $smtp_password = (string)trim($this->input->post('smtp_password'));
- $smtp_on = (string)trim($this->input->post('smtp_on'));
- $this->Options_model->set_option('email_smtp_host', $smtp_host);
- $this->Options_model->set_option('email_smtp_port', $smtp_port);
- $this->Options_model->set_option('email_smtp_security', $smtp_security);
- $this->Options_model->set_option('email_smtp_username', $smtp_username);
- $this->Options_model->set_option('email_smtp_password', $smtp_password);
- $this->Options_model->set_option('email_smtp_on', empty($smtp_on) ? 0 : 1);
- }
- // save sendgrid options if asked
- if($this->input->post('action') == 'sendgrid_config') {
- $sendgrid_api_key = (string)trim($this->input->post('sendgrid_api_key'));
- $massmail_test_email = (string)trim($this->input->post('massmail_test_email'));
- $email_arr = explode(' ', str_replace(["\r", "\n", "\t", ','], ' ', $massmail_test_email));
- $emails = [];
- if(!empty($email_arr)) {
- foreach($email_arr as $email) {
- $email = trim($email);
- if(empty($email))
- continue;
- $emails[] = $email;
- }
- $emails = implode("\r\n", $emails);
- } else {
- $emails = '';
- }
- $this->Options_model->set_option('sendgrid_api_key', $sendgrid_api_key);
- $this->Options_model->set_option('massmail_test_email', $emails);
- }
- // get options
- $this->data['dgold_inc_arr'] = $this->Options_model->get_option('dgold_inc_arr');
- $this->data['dgold_price_arr'] = $this->Options_model->get_option('dgold_price_arr');
- $this->data['dgold_total_rewarded'] = $this->Options_model->get_option('dgold_total_rewarded');
- $this->data['dgold_total_sold_value'] = $this->Options_model->get_option('dgold_total_sold_value');
- // get email options
- $this->data['from_email'] = $this->Options_model->get_option('email_from_email');
- $this->data['from_name'] = $this->Options_model->get_option('email_from_name');
- // get smtp options
- $this->data['smtp_host'] = $this->Options_model->get_option('email_smtp_host');
- $this->data['smtp_port'] = $this->Options_model->get_option('email_smtp_port');
- $this->data['smtp_security'] = $this->Options_model->get_option('email_smtp_security');
- $this->data['smtp_username'] = $this->Options_model->get_option('email_smtp_username');
- $this->data['smtp_password'] = $this->Options_model->get_option('email_smtp_password');
- $this->data['smtp_on'] = $this->Options_model->get_option('email_smtp_on');
- // get massmail options
- $this->data['sendgrid_api_key'] = $this->Options_model->get_option('sendgrid_api_key');
- $this->data['massmail_test_email'] = $this->Options_model->get_option('massmail_test_email');
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('admin_email_settings', $this->data);
- }
- public function send_email()
- {
- $from_id = (int)$this->session->user_id;
- $to_id = (int)trim($this->input->post('to_id'));
- if(($from_id <= 0) or ($to_id <= 0))
- die;
- $subject = (string)trim($this->input->post('subject'));
- $message = (string)trim($this->input->post('message'));
- if(empty($subject) or empty($message))
- die;
- $this->load->model('Options_model');
- $fromU = $this->User_model->get_one(['id' => $from_id]);
- $toU = $this->User_model->get_one(['id' => $to_id]);
- $allowed = ($fromU['is_admin'] == 1);
- if(!$allowed) {
- $dgold_inc_arr = $this->Options_model->get_option('dgold_inc_arr');
- $my_referrals = $this->User_model->get_my_referrals($from_id, $dgold_inc_arr);
- foreach($my_referrals as $my_ref_rec) {
- if($my_ref_rec['id'] == $to_id) {
- $allowed = true;
- break;
- }
- }
- }
- if(!$allowed)
- die;
- $to_email = $toU['email'];
- $to_name = $this->User_model->get_user_name($toU);
- $replyto_email = $fromU['email'];
- $replyto_name = $this->User_model->get_user_name($fromU);
- $signature = _v('This message is sent from contact form on <a href="https://www.dgoldcurrency.com/">www.dgoldcurrency.com</a> from one of registered users which referral you are (any of 5 levels).');
- $html = str_replace("\n", '<br>', $message);
- $html .= "<br><br>-----------<br><br>{$signature}";
- $this->_send_email('', '', $to_email, $to_name, $replyto_email, $replyto_name, $subject, $html, 'standard');
- $html = "<h1>{$subject}</h1>".str_replace("\n", '<br>', $message);
- $this->_add_message($from_id, $to_id, $html);
- }
- private function _send_email($from_email, $from_name, $to_email, $to_name, $replyto_email, $replyto_name, $subject, $message, $via = 'standard')
- {
- $this->load->model('Options_model');
- if(empty($from_email)) {
- $email_from_email = $this->Options_model->get_option('email_from_email');
- $email_from_name = $this->Options_model->get_option('email_from_name');
- $from_email = empty($email_from_email) ? "support@{$_SERVER['HTTP_HOST']}" : $email_from_email;
- $from_name = empty($email_from_name) ? 'Admin' : $email_from_name;
- }
- if($via == 'standard') {
- $email_smtp_on = $this->Options_model->get_option('email_smtp_on');
- if($email_smtp_on) {
- if(!empty($to_name)) {
- $to_email = [$to_email => $to_name];
- } else {
- $to_email = [$to_email];
- }
- $email_smtp_host = $this->Options_model->get_option('email_smtp_host');
- $email_smtp_port = $this->Options_model->get_option('email_smtp_port');
- $email_smtp_security = $this->Options_model->get_option('email_smtp_security');
- $email_smtp_username = $this->Options_model->get_option('email_smtp_username');
- $email_smtp_password = $this->Options_model->get_option('email_smtp_password');
- $transport = (new Swift_SmtpTransport($email_smtp_host, $email_smtp_port, $email_smtp_security))
- ->setUsername($email_smtp_username)
- ->setPassword($email_smtp_password);
- //->setStreamOptions(array('ssl' => array('allow_self_signed' => true, 'verify_peer' => false, 'verify_peer_name' => false)));
- // Create the Mailer using your created Transport
- $mailer = new Swift_Mailer($transport);
- // Create a message
- $msg = (new Swift_Message($subject))
- ->setFrom([$from_email => $from_name])
- ->setTo($to_email)
- ->setBody($message, 'text/html');
- if(!empty($replyto_email)) {
- if(!empty($replyto_name)) {
- $replyto = [$replyto_email => $replyto_name];
- } else {
- $replyto = [$replyto_email];
- }
- $msg->setReplyTo($replyto);
- }
- // Send the message
- $result = $mailer->send($msg);
- } else {
- if(!empty($replyto_email)) {
- if(!empty($replyto_name)) {
- $replyto = "{$replyto_email} {$replyto_name}";
- } else {
- $replyto = $replyto_email;
- }
- $message = _v('Do not reply to us!<br> You should reply to:')." {$replyto}<br><br>-----------<br><br>{$message}";
- }
- $this->load->library('email');
- $this->email->from($from_email, $from_name);
- $this->email->to($to_email);
- $this->email->subject($subject);
- $this->email->set_mailtype('html');
- $this->email->message($message);
- //send the email
- $this->email->send();
- }
- } elseif($via == 'sendgrid') {
- $sendgrid_api_key = $this->Options_model->get_option('sendgrid_api_key');
- $tos_chunked = array_chunk($to_email, 99, true);
- $sent_emails = [];
- foreach($tos_chunked as $tos_chunk) {
- $sendgrid_from = new \SendGrid\Mail\From($this->data['email_from_email'], $this->data['email_from_name']);
- $sendgrid_tos = [];
- foreach ($tos_chunk as $tos_email => $tos_name) {
- $sendgrid_tos[] = new \SendGrid\Mail\To($tos_email, $tos_name);
- }
- $sendgrid_subject = new \SendGrid\Mail\Subject($mass_subject);
- $plainTextContent = new \SendGrid\Mail\PlainTextContent('');
- $htmlContent = new \SendGrid\Mail\HtmlContent($mass_message);
- $email = new \SendGrid\Mail\Mail(
- $sendgrid_from,
- $sendgrid_tos,
- $sendgrid_subject,
- $plainTextContent,
- $htmlContent
- );
- $sendgrid = new \SendGrid($sendgrid_api_key);
- }
- foreach($tos_chunked as $tos_chunk) {
- $sendgrid_from = new \SendGrid\Mail\From($from_email, $from_name);
- $sendgrid_tos = [];
- foreach ($tos_chunk as $tos_email => $tos_name) {
- $sendgrid_tos[] = new \SendGrid\Mail\To($tos_email, $tos_name);
- }
- $sendgrid_subject = new \SendGrid\Mail\Subject($subject);
- $plainTextContent = new \SendGrid\Mail\PlainTextContent('');
- $htmlContent = new \SendGrid\Mail\HtmlContent($message);
- $email = new \SendGrid\Mail\Mail(
- $sendgrid_from,
- $sendgrid_tos,
- $sendgrid_subject,
- $plainTextContent,
- $htmlContent
- );
- $sendgrid = new \SendGrid($sendgrid_api_key);
- try {
- $response = $sendgrid->send($email);
- $status = $response->statusCode();
- if(($status == 200) or ($status == 202)) {
- $sent_emails = array_merge($sent_emails, $tos_chunk);
- }
- log_message('error', 'Sendgrid-notification-ok_response-' . $status . '-' . serialize($response->headers()) . '-' . serialize($response->body())) . '-'. serialize($tos_chunk);
- } catch (Exception $e) {
- log_message('error', 'Sendgrid-notification-exception-' . $e->getMessage());
- }
- }
- foreach($tos_chunked as $tos_chunk) {
- $email = new \SendGrid\Mail\Mail();
- $email->setFrom($from_email, $from_name);
- $email->addTos($tos_chunk);
- $email->setSubject($subject);
- //$email->addContent("text/plain", "and easy to do anywhere, even with PHP");
- $email->addContent("text/html", $message);
- $sendgrid = new \SendGrid($sendgrid_api_key);
- try {
- $response = $sendgrid->send($email);
- $status = $response->statusCode();
- if(($status == 200) or ($status == 202)) {
- $sent_emails = array_merge($sent_emails, $tos_chunk);
- }
- log_message('error', 'Sendgrid-notification-ok_response-' . $status . '-' . serialize($response->headers()) . '-' . serialize($response->body())) . '-'. serialize($tos_chunk);
- } catch (Exception $e) {
- log_message('error', 'Sendgrid-notification-exception-' . $e->getMessage());
- }
- }
- }
- }
- public function inbox($page = 0)
- {
- $this->_check_login();
- $page = ((int)$page - 1);
- $page = ($page > 0) ? $page : 0;
- $this->load->model('Blog_posts_model');
- $condition = ['is_draft' => 0];
- $this->db->select('SQL_CALC_FOUND_ROWS *', false);
- $this->data['posts'] = $this->Blog_posts_model->get($condition, '`updated_at` DESC', 'id, created_at, updated_at, subject, message', $page * $this->data['rows_per_page'], $this->data['rows_per_page']);
- // pagination
- $query = $this->db->query('SELECT FOUND_ROWS() AS records');
- $row = $query->row();
- $base_url = base_url($this->load->_get_this_controller_slug().'/'.__FUNCTION__);
- $this->data['pagination'] = $this->_get_pagination_html($base_url, $row->records);
- $this->load->model('Blog_posts_seen_model');
- $this->data['posts'] = $this->Blog_posts_seen_model->blog_posts_add_seen($this->data['posts']);
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('inbox', $this->data);
- }
- public function ajax_blog_messages($blog_post_id = null)
- {
- $blog_post_id = (int)$blog_post_id;
- if($blog_post_id <= 0)
- die;
- $this->_check_login(false);
- $this->load->model('Blog_posts_model');
- $post = $this->Blog_posts_model->get_one(['id' => $blog_post_id, 'is_draft' => 0]);
- if(empty($post))
- die;
- $this->load->model('Blog_posts_seen_model');
- $seenRec = $this->Blog_posts_seen_model->get_one(['user_id' => $this->data['id'], 'blog_post_id' => $blog_post_id]);
- if(empty($seenRec)) {
- $this->Blog_posts_seen_model->insert(['user_id' => $this->data['id'], 'blog_post_id' => $blog_post_id]);
- }
- $label = $post['is_company_email'] ? " <span class=\"label label-danger\">Company e-mail</span>" : '';
- echo "<div class=\"box\"><div class=\"box-header\"><h1 class=\"box-title\">{$post['subject']}{$label}</h1></div><div class=\"box-body\">{$post['message']}</div></div>";
- }
- public function contact_us()
- {
- //redirect('/admin/my_messages#contact_us');
- $this->_check_login();
- $subject = (string)trim($this->input->post('subject'));
- $message = (string)trim($this->input->post('message'));
- if(!empty($message)) {
- $email_from_email = $this->Options_model->get_option('email_from_email');
- $email_from_name = $this->Options_model->get_option('email_from_name');
- $email_from_email = empty($email_from_email) ? "support@{$_SERVER['HTTP_HOST']}" : $email_from_email;
- $email_from_name = empty($email_from_name) ? 'Admin' : $email_from_name;
- $reply_to = $this->data['email'];
- $to_email = 'support@dgoldcurrency.com';
- $html = $message;
- $email_smtp_on = $this->Options_model->get_option('email_smtp_on');
- if($email_smtp_on) {
- $to_email = array($to_email);
- if(!empty($this->data['name']) or !empty($this->data['surname'])) {
- $name = trim("{$this->data['name']} {$this->data['surname']}");
- $reply_to = array($reply_to => $name);
- } else {
- $reply_to = array($reply_to);
- }
- $email_smtp_host = $this->Options_model->get_option('email_smtp_host');
- $email_smtp_port = $this->Options_model->get_option('email_smtp_port');
- $email_smtp_security = $this->Options_model->get_option('email_smtp_security');
- $email_smtp_username = $this->Options_model->get_option('email_smtp_username');
- $email_smtp_password = $this->Options_model->get_option('email_smtp_password');
- $transport = (new Swift_SmtpTransport($email_smtp_host, $email_smtp_port, $email_smtp_security))
- ->setUsername($email_smtp_username)
- ->setPassword($email_smtp_password);
- //->setStreamOptions(array('ssl' => array('allow_self_signed' => true, 'verify_peer' => false, 'verify_peer_name' => false)));
- // Create the Mailer using your created Transport
- $mailer = new Swift_Mailer($transport);
- // Create a message
- $message = (new Swift_Message($subject))
- ->setFrom(array($email_from_email => $email_from_name))
- ->setTo($to_email)
- ->setReplyTo($reply_to)
- ->setBody($html, 'text/html')
- ;
- // Send the message
- $result = $mailer->send($message);
- } else {
- $this->load->library('email');
- $this->email->from($email_from_email, $email_from_name);
- $this->email->to($to_email);
- $this->email->subject($subject);
- $this->email->set_mailtype('html');
- $this->email->message($html);
- //send the email
- $this->email->send();
- }
- $this->data['info_message'] = '<div class="alert alert-success" role="alert">'._v('Message sent!').'</div>';
- }
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('contact_us', $this->data);
- }
- private function _send_payout_email($objU, $objP)
- {
- $subject = "Withdrawal is successfully made";
- $message = "{$objP['amount_usd']} USD was successfully paid to your {$objP['merchant']} wallet.<br>Contact support mail if any problems.";
- //get options
- $this->load->model('Options_model');
- $email_from_email = $this->Options_model->get_option('email_from_email');
- $email_from_name = $this->Options_model->get_option('email_from_name');
- $email_from_email = empty($email_from_email) ? "support@{$_SERVER['HTTP_HOST']}" : $email_from_email;
- $email_from_name = empty($email_from_name) ? 'Admin' : $email_from_name;
- $to_email = $objU['email'];
- $html = $message;
- $email_smtp_on = $this->Options_model->get_option('email_smtp_on');
- if($email_smtp_on) {
- if(!empty($objU['name']) or !empty($objU['surname'])) {
- $to_email = array($to_email => trim("{$objU['name']} {$objU['surname']}"));
- } else {
- $to_email = array($to_email);
- }
- $email_smtp_host = $this->Options_model->get_option('email_smtp_host');
- $email_smtp_port = $this->Options_model->get_option('email_smtp_port');
- $email_smtp_security = $this->Options_model->get_option('email_smtp_security');
- $email_smtp_username = $this->Options_model->get_option('email_smtp_username');
- $email_smtp_password = $this->Options_model->get_option('email_smtp_password');
- $transport = (new Swift_SmtpTransport($email_smtp_host, $email_smtp_port, $email_smtp_security))
- ->setUsername($email_smtp_username)
- ->setPassword($email_smtp_password);
- //->setStreamOptions(array('ssl' => array('allow_self_signed' => true, 'verify_peer' => false, 'verify_peer_name' => false)));
- // Create the Mailer using your created Transport
- $mailer = new Swift_Mailer($transport);
- // Create a message
- $message = (new Swift_Message($subject))
- ->setFrom(array($email_from_email => $email_from_name))
- ->setTo($to_email)
- ->setBody($html, 'text/html')
- ;
- // Send the message
- $result = $mailer->send($message);
- } else {
- $this->load->library('email');
- $this->email->from($email_from_email, $email_from_name);
- $this->email->to($to_email);
- $this->email->subject($subject);
- $this->email->set_mailtype('html');
- $this->email->message($html);
- //send the email
- $this->email->send();
- }
- }
- public function invoice_ddk(){
- $this->_check_login();
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('admin_invoices_ddk', $this->data);
- }
- public function dgold_mining()
- {
- $this->_check_login();
- // data for calculate DGold price dynamically
- $this->data['buy_usd_value'] = $this->config->item('buy_usd_amount');
- $this->load->model('Docs_model');
- $docs1 = $this->Docs_model->get(['user_id' => $this->session->user_id, 'type' => 'ID document', 'is_approved' => 1]);
- $docs2 = $this->Docs_model->get(['user_id' => $this->session->user_id, 'type' => 'Proof of address', 'is_approved' => 1]);
- $this->data['uploaded_docs'] = !empty($docs1) and !empty($docs2);
- $this->load->model('Packages_model');
- // Packages to buy
- if($this->input->post('action') == 'buy_package') {
- $package_id = (int)trim($this->input->post('id'));
- if($package_id > 0) {
- if($this->_buy_package($package_id, $this->data)) {
- $data2 = $this->User_model->get_one(array('id' => $this->data['id']));
- $this->data['usd'] = $data2['usd'];
- $this->data['show_modal_package_bought'] = true;
- $this->db->select('SQL_CALC_FOUND_ROWS *', false);
- $this->data['packages'] = $this->Packages_model->get(['user_id' => $this->data['id'], 'packages.is_active' => 1], 'last_payout_date DESC');
- $this->data['packages_pagination'] = '';
- } else {
- $this->data['show_modal_insufficient_money'] = true;
- }
- }
- }
- $this->load->helper('miner');
- // ask payout to dgold balance
- $package_id = (int)trim($this->input->get('payout_dgold_id'));
- if($package_id > 0) {
- $package = $this->Packages_model->get_one(['id' => $package_id, 'user_id' => $this->data['id'], 'is_active' => 1]);
- if(!empty($package)) {
- $delta = intdiv_1(time() - $package['last_payout_date'], 86400 * 30);
- if($delta > 0) {
- $next_payout_date = $package['last_payout_date'] + $delta * 86400 * 30;
- $val_dgold = $delta * $package['daily_dgolds'] * 30;
- $this->Packages_model->start_transaction();
- $this->db->set('coins', "coins + {$val_dgold}", FALSE);
- $this->User_model->update_by_id(['id' => $this->data['id']]);
- $this->Packages_model->update_by_id([
- 'id' => $package_id,
- 'last_payout_date' => $next_payout_date,
- ]);
- $this->Packages_model->commit_transaction();
- $data2 = $this->User_model->get_one(array('id' => $this->data['id']));
- $this->data['usd'] = $data2['usd'];
- $this->data['usd_cashout'] = $data2['usd_cashout'];
- $this->data['coins'] = $data2['coins'];
- $this->data['show_modal_payout_dgold'] = str_replace('xxx', $val_dgold, _v("xxx DGold have been transferred to your DGold balance."));
- }
- }
- }
- // ask payout to usd balance
- $package_id = (int)trim($this->input->get('payout_usd_id'));
- if($package_id > 0) {
- $package = $this->Packages_model->get_one(['id' => $package_id, 'user_id' => $this->data['id'], 'is_active' => 1]);
- if(!empty($package)) {
- $t = min($package['stop_date'], time());
- $delta = intdiv_1($t - $package['last_payout_date'], 86400 * 30);
- if($delta > 0) {
- $next_payout_date = $package['last_payout_date'] + $delta * 86400 * 30;
- $val_dgold = $delta * $package['daily_dgolds'] * 30 / 2;
- $val_usd = $val_dgold * $this->data['dgold_rate'];
- $this->Packages_model->start_transaction();
- $this->db->set('usd_cashout', "usd_cashout + {$val_usd}", FALSE);
- $this->db->set('coins', "coins + {$val_dgold}", FALSE);
- $this->User_model->update_by_id(['id' => $this->data['id']]);
- $this->Packages_model->update_by_id([
- 'id' => $package_id,
- 'last_payout_date' => $next_payout_date,
- ]);
- $this->Packages_model->commit_transaction();
- $data2 = $this->User_model->get_one(array('id' => $this->data['id']));
- $this->data['usd'] = $data2['usd'];
- $this->data['usd_cashout'] = $data2['usd_cashout'];
- $this->data['coins'] = $data2['coins'];
- $this->data['show_modal_payout_dgold'] = str_replace(['xxx', 'yyy'], [$val_dgold, $val_usd], _v("xxx DGold and yyy USD have been transferred to your DGold and USD balances."));
- }
- }
- }
- // ask percentage payout
- if($this->input->post('action') == 'request_payout') {
- $payout_percent = (int)trim($this->input->post('payout_percent'));
- $payout_percent = min(100, $payout_percent);
- $payout_percent = max(50, $payout_percent);
- $package_id = (int)trim($this->input->post('package_id'));
- if($package_id > 0) {
- $package = $this->Packages_model->get_one(['id' => $package_id, 'user_id' => $this->data['id'], 'is_active' => 1]);
- if (!empty($package)) {
- $delta = intdiv_1(time() - $package['last_payout_date'], 86400 * 30);
- if ($delta > 0) {
- $next_payout_date = $package['last_payout_date'] + $delta * 86400 * 30;
- $val_dgold_half = $delta * $package['daily_dgolds'] * 30 / 2;
- $val_usd_half = $val_dgold_half * $this->data['dgold_rate'];
- $val_dgold = floor($val_dgold_half / 50 * $payout_percent);
- $val_usd = floor($val_usd_half / 50 * (100 - $payout_percent) * 100) / 100;
- $this->Packages_model->start_transaction();
- $this->db->set('usd_cashout', "usd_cashout + {$val_usd}", FALSE);
- $this->db->set('coins', "coins + {$val_dgold}", FALSE);
- $this->User_model->update_by_id(['id' => $this->data['id']]);
- $this->Packages_model->update_by_id([
- 'id' => $package_id,
- 'last_payout_date' => $next_payout_date,
- ]);
- $this->Packages_model->commit_transaction();
- $data2 = $this->User_model->get_one(array('id' => $this->data['id']));
- $this->data['usd'] = $data2['usd'];
- $this->data['usd_cashout'] = $data2['usd_cashout'];
- $this->data['coins'] = $data2['coins'];
- if($val_usd == 0) {
- $this->data['show_modal_payout_dgold'] = str_replace('xxx', $val_dgold, _v("xxx DGold have been transferred to your DGold balance."));
- } else {
- $this->data['show_modal_payout_dgold'] = str_replace(['xxx', 'yyy'], [$val_dgold, $val_usd], _v("xxx DGold and yyy USD have been transferred to your DGold and USD balances."));
- }
- }
- }
- }
- }
- $this->db->select('SQL_CALC_FOUND_ROWS *', false);
- $this->data['packages'] = $this->Packages_model->get(['user_id' => $this->data['id'], 'packages.is_active' => 1], 'last_payout_date DESC');
- $this->data['packages_info'] = [];
- if(!empty($this->data['packages'])) {
- foreach($this->data['packages'] as $pid => $package) {
- $this->data['packages_info'][$package['id']] = $this->_get_package_info($package);
- }
- }
- $this->data['packages_pagination'] = '';
- $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
- $this->load->view2('dgold_mining', $this->data);
- }
- private function _buy_package($package_id, $objU)
- {
- $this->load->model('Packages_setup_model');
- $this->load->model('Packages_model');
- $ret = false;
- if($package_id > 0) {
- $this->Packages_model->start_transaction();
- $objPS = $this->Packages_setup_model->get_one(['id' => $package_id, 'is_active' => 1]);
- if(!empty($objPS)) {
- if(($objU['usd'] + $objU['usd_cashout']) >= $objPS['price']) {
- if($objU['usd'] >= $objPS['price']) {
- $this->db->set('usd', "usd - {$objPS['price']}", FALSE);
- } else {
- $usd_price = $objU['usd'];
- $usd_cashout_price = $objPS['price'] - $objU['usd'];
- $this->db->set('usd', "usd - {$usd_price}", FALSE);
- $this->db->set('usd_cashout', "usd_cashout - {$usd_cashout_price}", FALSE);
- }
- $this->User_model->update_by_id(['id' => $objU['id']]);
- $t = time();
- $this->Packages_model->insert([
- 'user_id' => $objU['id'],
- 'package_id' => $objPS['id'],
- 'daily_dgolds' => $objPS['daily_dgolds'],
- 'start_date' => $t,//$t - 31 * 86400,
- 'last_payout_date' => $t,//$t - 31 * 86400,
- 'stop_date' => $t + 12 * 30 * 86400,
- 'title' => $objPS['title'],
- 'hash_rate' => $objPS['hash_rate'],
- 'hash_rate_sign' => $objPS['hash_rate_sign'],
- 'last_share' => $t,
- 'next_share' => $t,
- 'is_active' => 1,
- ]);
- // add referral bonuses
- $mining_reward_lvl1 = $objPS['price'] / 100 * $this->Options_model->get_option('dgold_mining_reward_lvl1');
- $mining_reward_lvl2 = $objPS['price'] / 100 * $this->Options_model->get_option('dgold_mining_reward_lvl2');
- if($objU['ref'] > 0) {
- $objUref1 = $this->User_model->get_one(['id' => $objU['ref']]);
- if(!empty($objUref1)) {
- $this->db->set('usd', "usd + {$mining_reward_lvl1}", FALSE);
- $this->User_model->update_by_id(['id' => $objUref1['id']]);
- if($objUref1['ref'] > 0) {
- $objUref2 = $this->User_model->get_one(['id' => $objUref1['ref']]);
- if(!empty($objUref2)) {
- $this->db->set('usd', "usd + {$mining_reward_lvl2}", FALSE);
- $this->User_model->update_by_id(['id' => $objUref2['id']]);
- }
- }
- }
- }
- $ret = true;
- }
- }
- $this->Packages_model->commit_transaction();
- }
- return $ret;
- }
- public function json_get_package_info($package_id = 0)
- {
- $package_id = (int)$package_id;
- if($package_id < 0)
- return;
- $this->load->model('Packages_model');
- $this->load->model('Packages_setup_model');
- if($package_id == 0) {
- $packages_info = [];
- $packages = $this->Packages_model->get(['user_id' => $this->session->user_id, 'packages.is_active' => 1], 'last_payout_date DESC');
- if(!empty($packages)) {
- $hash_exps = ['EH/s' => 18, 'PH/s' => 15, 'TH/s' => 12, 'GH/s' => 9, 'MH/s' => 6, 'kH/s' => 3];
- $p_hashrate = 0.0;
- $p_mined_dgold = 0;
- $p_uptime = time();
- $p_last_share = 0;
- foreach($packages as $pid => $package_arr) {
- $p_hashrate += $package_arr['hash_rate'] * pow(10, $hash_exps[$package_arr['hash_rate_sign']]);
- $p_uptime = min($p_uptime, $package_arr['start_date']);
- $p_last_share = max($p_last_share, $package_arr['last_share']);
- $p_mined_dgold += (time() - $package_arr['last_payout_date']) / 86400 * $package_arr['daily_dgolds'];
- // fill numbered packages
- $info = $this->_get_package_info($package_arr);
- if(!empty($info)) {
- $packages_info[$package_arr['id']] = $info;
- }
- }
- $tmp_hashrate = number_format($p_hashrate, 0, '.', '');
- foreach($hash_exps as $sign => $exp) {
- if(strlen($tmp_hashrate) > $exp) {
- break;
- }
- }
- $pp_hashrate = number_format($p_hashrate / pow(10, $exp), 1, '.', ',');
- // fill zero package
- $packages_info[0] = $this->_get_package_info([
- 'id' => 0,
- 'hash_rate' => $pp_hashrate,
- 'hash_rate_sign' => $sign,
- 'start_date' => $p_uptime,
- 'last_payout_date' => '',
- 'last_share' => $p_last_share,
- 'daily_dgolds' => '',
- ]);
- $packages_info[0]['mined_dgold'] = $this->_mined_dgold_format($p_mined_dgold);
- }
- echo json_encode($packages_info);
- } else {
- $package_arr = $this->Packages_model->get_one(['user_id' => $this->session->user_id, 'packages.id' => $package_id]);
- if(!empty($package_arr)) {
- $info = $this->_get_package_info($package_arr);
- if(!empty($info)) {
- echo json_encode($info);
- }
- }
- }
- }
- private function _get_package_info($package)
- {
- $info = [];
- $this->load->helper('miner');
- $info['hashrate'] = "{$package['hash_rate']} {$package['hash_rate_sign']}";
- $info['cpu_load'] = number_format(99.2 + 0.7 * cos($package['id'] + deg2rad(18 + time() / 7)), 2, '.', ',')."%";
- $info['last_share'] = get_uptime($package['last_share']);//(time() - $package['last_share'])." secs";//(mt_rand(0, 1) + mt_rand(0, 2) * mt_rand(0, 2))." secs";
- $info['temperature'] = number_format(55 + 6 * sin($package['id'] + deg2rad(3 + time() / 21)), 2, '.', ',')."℃";
- $info['mined_dgold'] = $this->_mined_dgold_format((time() - $package['last_payout_date']) / 86400 * $package['daily_dgolds']);
- $info['uptime_str'] = get_uptime($package['start_date']);
- $info['uptime'] = "<span class=\"make_datatime2\">{$package['start_date']}</span>";
- return $info;
- }
- private function _mined_dgold_format($dgold = 0.0)
- {
- $ret = number_format($dgold, 8, '.', ',');
- $pos = strpos($ret, '.');
- if($pos !== false) {
- $ret = substr($ret, 0, $pos).'<span style="font-size:0.8em;">'.substr($ret, $pos).'</span>';
- }
- return $ret;
- }
- private function _check_login($load_default_options = true)
- {
- $userid = empty($this->session->user_id) ? 0 : $this->session->user_id;
- if($userid < 1) {
- $redir_url = urlencode(base_url($_SERVER['REQUEST_URI']));
- redirect("/user/login/?r={$redir_url}");
- }
- $this->data = $this->User_model->get_one(['id' => $this->session->user_id]);
- if(empty($this->data)) {
- redirect("/".$this->load->_get_this_controller_slug());
- }
- if($load_default_options) {
- $this->_load_default_options();
- }
- }
- private function _check_admin($load_default_options = true)
- {
- $userid = empty($this->session->user_id) ? 0 : $this->session->user_id;
- if($userid < 1) {
- $redir_url = urlencode(base_url($_SERVER['REQUEST_URI']));
- redirect("/user/login/?r={$redir_url}");
- }
- $this->data = $this->User_model->get_one(['id' => $this->session->user_id]);
- if(empty($this->data) or ($this->data['is_admin'] != 1)) {
- redirect("/".$this->load->_get_this_controller_slug());
- }
- if($load_default_options) {
- $this->_load_default_options();
- }
- }
- private function _load_default_options()
- {
- $this->load->model('Options_model');
- $this->data['my_payout_options'] = empty($this->data['my_payout_options']) ? [] : unserialize($this->data['my_payout_options']);
- $this->data['game_countdown'] = $this->Options_model->get_option('game_countdown', 24);
- $this->data['rows_per_page'] = $this->Options_model->get_option('rows_per_page');
- $this->data['dgold_rate'] = $this->Options_model->get_option('dgold_rate');
- $this->data['dgold_total_sold'] = $this->Options_model->get_option('dgold_total_sold');
- // update crypto ticker
- $cryptocurrency_last_update = $this->Options_model->get_option('cryptocurrency_last_update', 0);
- if($cryptocurrency_last_update + 10800 < time()) {
- $json = json_decode(file_get_contents('https://api.coinmarketcap.com/v2/ticker/'), true);
- $allowed_cryptocurrencies = array_flip(explode(' ', 'BTC ETH XRP BCH LTC EOS XLM'));
- $this->data['cryptocurrencies'] = [];
- foreach($json['data'] as $arr) {
- if(isset($allowed_cryptocurrencies[$arr['symbol']])) {
- $this->data['cryptocurrencies'][] = [
- 'name' => $arr['name'],
- 'symbol' => $arr['symbol'],
- 'price' => $arr['quotes']['USD']['price'],
- 'percent_change_1h' => $arr['quotes']['USD']['percent_change_1h'],
- 'percent_change_24h' => $arr['quotes']['USD']['percent_change_24h'],
- 'percent_change_7d' => $arr['quotes']['USD']['percent_change_7d'],
- ];
- }
- }
- if(!empty($this->data['cryptocurrencies'])) {
- $this->Options_model->set_option('cryptocurrencies', serialize($this->data['cryptocurrencies']));
- } else {
- $this->data['cryptocurrencies'] = $this->Options_model->get_option('cryptocurrencies');
- }
- $this->Options_model->set_option('cryptocurrency_last_update', time());
- } else {
- $this->data['cryptocurrencies'] = $this->Options_model->get_option('cryptocurrencies');
- }
- $this->load->model('Packages_setup_model');
- $this->data['packages_setup'] = $this->Packages_setup_model->get(['is_active' => 1], 'show_order');
- if($this->data['is_admin'] == 1) {
- $this->load->model('Payout_model');
- $ret = $this->Payout_model->get(['is_paid' => 0], null, 'id');
- $this->data['payout_not_paid_num'] = empty($ret) ? 0 : count($ret);
- $this->load->model('Docs_model');
- $ret = $this->Docs_model->get(['is_approved' => 0], null, 'id');
- $this->data['docs_not_approved_num'] = empty($ret) ? 0 : count($ret);
- }
- }
- private function _get_merchants_data()
- {
- $this->load->model('Options_model');
- $merchants_data = [
- 'paypal_on' => $this->Options_model->get_option('merchant_paypal_on'),
- 'coinbase_on' => $this->Options_model->get_option('merchant_coinbase_on'),
- 'solidtrustpay_on' => $this->Options_model->get_option('merchant_solidtrustpay_on'),
- 'payeer_on' => $this->Options_model->get_option('merchant_payeer_on'),
- 'advcash_on' => $this->Options_model->get_option('merchant_advcash_on'),
- 'cryptonator_on' => $this->Options_model->get_option('merchant_cryptonator_on'),
- 'btc_on' => $this->Options_model->get_option('merchant_btc_on'),
- ];
- return $merchants_data;
- }
- private function _get_pagination_html($base_url, $total_rows, $params = [])
- {
- $this->load->library('pagination');
- $this->pagination->initialize($this->_get_pagination_initialize_array($base_url, $total_rows, $params));
- return $this->pagination->create_links();
- }
- private function _get_pagination_initialize_array($base_url, $total_rows, $params = [])
- {
- $this->load->model('Options_model');
- $per_page = $this->Options_model->get_option('rows_per_page');
- $pagination_num_links = $this->Options_model->get_option('pagination_num_links');
- $params = is_array($params) ? $params : [];
- $pagination_initialize_arr = array_merge([
- 'base_url' => $base_url,
- 'reuse_query_string' => true,
- 'use_page_numbers' => true,
- 'total_rows' => $total_rows,
- 'per_page' => $per_page,
- 'num_links' => $pagination_num_links,
- 'full_tag_open' => '<ul class="pagination pull-right">',
- 'full_tag_close' => '</ul>',
- 'first_link' => '«',
- 'first_tag_open' => '<li>',
- 'first_tag_close' => '</li>',
- 'last_link' => '»',
- 'last_tag_open' => '<li>',
- 'last_tag_close' => '</li>',
- 'next_link' => '>',
- 'next_tag_open' => '<li>',
- 'next_tag_close' => '</li>',
- 'prev_link' => '<',
- 'prev_tag_open' => '<li>',
- 'prev_tag_close' => '</li>',
- 'num_tag_open' => '<li>',
- 'num_tag_close' => '</li>',
- 'cur_tag_open' => '<li class="active"><a href="#">',
- 'cur_tag_close' => '</a></li>',
- ], $params);
- return $pagination_initialize_arr;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement