· 7 years ago · Feb 05, 2019, 03:32 PM
1<?php
2defined('BASEPATH') OR exit('No direct script access allowed');
3
4
5use Brick\Math\BigInteger;
6use Brick\Math\BigDecimal;
7use Brick\Math\RoundingMode;
8
9
10class Admin extends MY_Controller {
11
12 public function __construct()
13 {
14 parent::__construct(true);
15
16 if(!empty($this->session->user_arr)) {
17 $user_arr = $this->session->user_arr;
18
19 // fix admin from config
20 $user_arr['super_admin'] = false;
21 if(!empty($user_arr['email']) and ($user_arr['email'] == $this->config->item('super_admin_email'))) {
22 $user_arr['super_admin'] = true;
23
24 if ($user_arr['is_admin'] != 1) {
25 $user_arr['is_admin'] = 1;
26 $this->User_model->update_by_id(array('id' => $user_arr['id'], 'is_admin' => 1));
27
28 // session sync
29 $this->session->user_arr = $user_arr;
30 $this->session->user_id = $user_arr['id'];
31 }
32 }
33
34 // fix the game data
35 if(empty($this->session->user_arr['gamecode1'])) {
36 $user_arr['gamecode1'] = mt_rand(1, 3);
37 $user_arr['gamecode2'] = mt_rand(0, 1);
38 $user_arr['lastgame_at'] = time();
39 $this->User_model->update_by_id(['id' => $user_arr['id'], 'lastgame_at' => time(), 'gamecode1' => $user_arr['gamecode1'], 'gamecode2' => $user_arr['gamecode2']]);
40
41 // session sync
42 $this->session->user_arr = $user_arr;
43 $this->session->user_id = $user_arr['id'];
44 }
45 }
46 //echo '<pre>';print_r($_SESSION);die;
47 }
48
49 public function index()
50 {
51 $this->_check_login();
52
53 redirect('/'.$this->load->_get_this_controller_slug().'/profile/');
54 }
55
56 public function profile()
57 {
58 $this->_check_login();
59
60 $this->data['notify_opt'] = 'asap';
61 if(!empty($this->data['emailing_options'])) {
62 $emailing_options = unserialize($this->data['emailing_options']);
63 if(!empty($emailing_options['notify_opt'])) {
64 $this->data['notify_opt'] = $emailing_options['notify_opt'];
65 }
66 }
67
68 //get options
69 $dgold_inc_arr = $this->Options_model->get_option('dgold_inc_arr');
70
71 $this->load->model('Ticket_model');
72
73 // del tickets if asked
74 $invoice_id = (int)trim($this->input->get('del_invoice'));
75 if($invoice_id > 0) {
76 $invoice = $this->Ticket_model->get_one(array('id' => $invoice_id, 'user_id' => $this->data['id'], 'is_paid' => 0));
77 if(!empty($invoice)) {
78 $this->Ticket_model->delete(array('id' => $invoice_id));
79 redirect('/'.$this->load->_get_this_controller_slug().'/my_invoices/');
80 }
81 }
82
83 // load form helper and validation library
84 $this->load->helper('form');
85 $this->load->library('form_validation');
86
87 $messages = array(
88 'required' => 'You have not provided %s.',
89 'is_unique' => 'This %s already exists. Please choose another one.',
90 'matches' => 'Passwords do not match.'
91 );
92
93 if($this->input->post('action') == 'settings') {
94 // set validation rules
95 $this->form_validation->set_rules('language', 'Language', 'trim|min_length[2]|max_length[2]', $messages);
96 $this->form_validation->set_rules('name', 'Name', 'trim|min_length[2]', $messages);
97 $this->form_validation->set_rules('surname', 'Surname', 'trim|min_length[2]', $messages);
98 $this->form_validation->set_rules('password', 'Password', 'trim|min_length[6]', $messages);
99 $this->form_validation->set_rules('password_confirm', 'Confirm Password', 'trim|min_length[6]|matches[password]', $messages);
100
101 if ($this->form_validation->run() === false) {
102 // validation not ok, send validation errors to the view
103 $this->data['settings_error'] = validation_errors();
104 } else {
105 if(empty($_COOKIE['lang']) or ($_COOKIE['lang'] != trim($this->input->post('language')))) {
106 setcookie('lang', trim($this->input->post('language')), time() + 3600 * 24 * 31 * 366, '/');
107 redirect('/' . $this->load->_get_this_controller_slug() . '/profile/');
108 }
109
110 $user_data = array(
111 'name' => trim($this->input->post('name')),
112 'surname' => trim($this->input->post('surname')),
113 'password' => trim($this->input->post('password')),
114 );
115
116 foreach ($user_data as $idx => $rec) {
117 if (empty($rec)) {
118 unset($user_data[$idx]);
119 }
120 }
121
122 if (!empty($user_data)) {
123 $this->data['name'] = empty($user_data['name']) ? $this->data['name'] : $user_data['name'];
124 $this->data['surname'] = empty($user_data['surname']) ? $this->data['surname'] : $user_data['surname'];
125
126 if(!empty($user_data['password'])) {
127 $user_data['password'] = $this->get_password_hash($user_data['password']);
128 }
129
130 $user_data['is_emailed'] = empty(trim($this->input->post('send_notifications'))) ? 0 : 1;
131
132
133 $emailing_options = [];
134
135 $allowed_opt = array_flip(explode(' ', 'asap hourly daily weekly'));
136 $emailing_options['notify_opt'] = isset($allowed_opt[trim($this->input->post('notify_opt'))]) ? trim($this->input->post('notify_opt')) : 'asap';
137
138 $user_data['emailing_options'] = serialize($emailing_options);
139
140
141 foreach ($user_data as $idx => $rec) {
142 $this->data[$idx] = $rec;
143 }
144 $this->data['notify_opt'] = $emailing_options['notify_opt'];
145
146 $this->session->user_arr = $this->data;
147 $this->session->user_id = $this->data['id'];
148
149 $user_data['id'] = $this->data['id'];
150 $this->User_model->update_by_id($user_data);
151 }
152 }
153 } elseif($this->input->post('action') == 'buy_dgold') {
154 $ask_price = trim($this->input->post('inputUSD'));
155 $inputUSD = BigDecimal::of($ask_price);
156 if(($inputUSD->compareTo(0) > 0) and ($inputUSD->compareTo($this->data['usd'] + $this->data['usd_cashout']) <= 0)) {
157 $inputDGold = BigDecimal::of($inputUSD)->dividedBy($this->data['dgold_rate'], 0, RoundingMode::HALF_UP);
158
159 $this->Ticket_model->start_transaction();
160
161 $ticket_id = $this->Ticket_model->insert([
162 'user_id' => $this->data['id'],
163 'amount_usd' => (string)$inputUSD,
164 'amount_dgold' => (string)$inputDGold,
165 ]);
166
167 if($this->data['usd'] >= $ask_price) {
168 $this->db->set('usd', "usd - {$ask_price}", FALSE);
169 } else {
170 $usd_price = $this->data['usd'];
171 $usd_cashout_price = $ask_price - $this->data['usd'];
172
173 $this->db->set('usd', "usd - {$usd_price}", FALSE);
174 $this->db->set('usd_cashout', "usd_cashout - {$usd_cashout_price}", FALSE);
175 }
176
177 $this->User_model->update_by_id(['id' => $this->data['id']]);
178
179
180 $ticket = $this->Ticket_model->get_one(['id' => $ticket_id]);
181 $this->_add_dgold($ticket, 'Balance', null);
182
183 $this->Ticket_model->commit_transaction();
184
185 $data2 = $this->User_model->get_one(array('id' => $this->session->user_id));
186 $this->data['usd'] = $data2['usd'];
187 $this->data['usd_cashout'] = $data2['usd_cashout'];
188 $this->data['coins'] = $data2['coins'];
189
190 $this->data['show_modal_dgold_paid'] = (string)$inputDGold;
191 }
192 }
193 /*elseif($this->input->post('action') == 'buy') {
194 $inputUSD = BigDecimal::of(trim($this->input->post('inputUSD')));
195 if($inputUSD->compareTo(0) >= 0) {
196 $inputDGold = BigDecimal::of($inputUSD)->dividedBy($dgold_rate, 0, RoundingMode::HALF_UP);
197
198 $invoice_arr = array(
199 'user_id' => $this->data['id'],
200 'amount_usd' => (string)$inputUSD,
201 'amount_dgold' => (string)$inputDGold,
202 );
203
204 $this->Ticket_model->insert($invoice_arr);
205
206 $this->data['show_modal_new_invoice'] = true;
207 }
208 }*/
209 elseif($this->input->post('action') == 'upload_docs') {
210 //echo '<pre>';print_r($_FILES);die;
211
212 $user_docs_dir = FCPATH.'docs'.DIRECTORY_SEPARATOR.$this->session->user_id;
213 if(!is_dir($user_docs_dir)) {
214 mkdir($user_docs_dir);
215 chmod($user_docs_dir, 0777);
216 }
217
218 if(is_array($_FILES['picture']['tmp_name'])) {
219 $docs_added = 0;
220
221 foreach($_FILES['picture']['tmp_name'] as $idx => $tmp_name) {
222 $fname = str_replace(['/', '\\'], '', $_FILES['picture']['name'][$idx]);
223 $fext = (strrpos($fname, '.') !== false) ? substr($fname, strrpos($fname, '.')) : '';
224 $rand_fname = substr(md5(password_hash(mt_rand(), PASSWORD_BCRYPT)), 0, 7);
225
226 $target_fname = $user_docs_dir.DIRECTORY_SEPARATOR."{$rand_fname}{$fext}";
227 move_uploaded_file($tmp_name, $target_fname);
228
229 //add to database too
230 if(file_exists($target_fname)) {
231 $this->load->model('Docs_model');
232
233 $this->Docs_model->insert([
234 'user_id' => $this->session->user_id,
235 'file_name' => "{$rand_fname}{$fext}",
236 'type' => 'verification',
237 'is_approved' => 0,
238 ]);
239
240 $docs_added++;
241 }
242 }
243
244 if($docs_added) {
245 $this->data['show_modal_add_docs'] = true;
246 }
247 }
248
249 //redirect();
250 } elseif($this->input->post('action') == 'my_payout_options') {
251 $this->data['my_payout_options'] = [
252 'btc' => trim((string)$this->input->post('my_btc')),
253 'ethereum' => trim((string)$this->input->post('my_ethereum')),
254 'solidtrustpay' => trim((string)$this->input->post('my_solidtrustpay')),
255 'payeer' => trim((string)$this->input->post('my_payeer')),
256 'advcash' => trim((string)$this->input->post('my_advcash')),
257 //'cryptonator' => trim((string)$this->input->post('my_cryptonator')),
258 //'coinbase' => trim((string)$this->input->post('my_coinbase')),
259 'paypal' => trim((string)$this->input->post('my_paypal')),
260 ];
261
262 $this->User_model->update_by_id([
263 'id' => $this->data['id'],
264 'my_payout_options' => serialize($this->data['my_payout_options']),
265 ]);
266 }
267
268 $this->data['invoices'] = $this->Ticket_model->get(['user_id' => $this->data['id'], 'is_paid' => 0], 'updated_at DESC');
269
270 $this->data['merchants_data'] = $this->_get_merchants_data();
271
272
273 $this->data['my_referrals'] = $this->User_model->get_my_referrals($this->data['id'], $dgold_inc_arr); // flat list of my referrals
274 $this->data['refs_cnt'] = $this->User_model->get_my_referrals_cnt($this->data['id'], $dgold_inc_arr); // calculate number of my referrals
275
276 $this->data['wallet'] = $this->load->view2_get_link_by($this->data['id'], 'wallet_id');
277
278 $this->data['buy_usd_value'] = $this->config->item('buy_usd_amount');
279 $this->data['dollars'] = $this->data['coins'] * $this->data['dgold_rate'];
280
281 $this->data['ref_link'] = $this->load->view2_get_link_by($this->data['username'], 'referrer_link');
282
283 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
284
285 $this->data['languages'] = $this->get_lang_arr();
286 $this->data['cur_lang'] = empty($_COOKIE['lang']) ? 'en' : $_COOKIE['lang'];
287
288
289 $this->load->model('Docs_model');
290 $docs1 = $this->Docs_model->get(['user_id' => $this->session->user_id, 'type' => 'ID document', 'is_approved' => 1]);
291 $docs2 = $this->Docs_model->get(['user_id' => $this->session->user_id, 'type' => 'Proof of address', 'is_approved' => 1]);
292 $this->data['uploaded_docs'] = !empty($docs1) and !empty($docs2);
293
294
295 // get merchants options
296 $this->data['solidtrustpay_on'] = $this->Options_model->get_option('merchant_solidtrustpay_on');
297 $this->data['payeer_on'] = $this->Options_model->get_option('merchant_payeer_on');
298 $this->data['advcash_on'] = $this->Options_model->get_option('merchant_advcash_on');
299 $this->data['cryptonator_on'] = $this->Options_model->get_option('merchant_cryptonator_on');
300 $this->data['btc_on'] = $this->Options_model->get_option('merchant_btc_on');
301 $this->data['coinbase_on'] = $this->Options_model->get_option('merchant_coinbase_on');
302 $this->data['paypal_on'] = $this->Options_model->get_option('merchant_paypal_on');
303 $this->data['paypal_payout_on'] = $this->Options_model->get_option('merchant_paypal_payout_on');
304
305
306 $this->load->view2('profile', $this->data);
307 }
308 public function my_referrals($page = 0)
309 {
310 $this->_check_login();
311
312 //get options
313 $dgold_inc_arr = $this->Options_model->get_option('dgold_inc_arr');
314
315 $page = ((int)$page - 1);
316 $page = ($page > 0) ? $page : 0;
317
318 $referrals = $this->User_model->get_my_referrals($this->data['id'], $dgold_inc_arr); // flat list of my referrals
319 $cnt = count($referrals);
320
321 if($cnt) {
322 $ref_chunks = array_chunk($referrals, $this->data['rows_per_page']);
323 $page = ($page < count($ref_chunks)) ? $page : count($ref_chunks);
324 $this->data['my_referrals'] = $ref_chunks[$page];
325
326 // pagination
327 $base_url = base_url($this->load->_get_this_controller_slug().'/'.__FUNCTION__);
328
329 $this->data['pagination'] = $this->_get_pagination_html($base_url, $cnt);
330
331 // receive packages
332 $this->load->model('Packages_model');
333 $Uids = $this->User_model->gather_columns($this->data['my_referrals'], 'id');
334 $this->data['ref_packages'] = $this->Packages_model->get(['user_id' => $Uids, 'packages.is_active' => 1]);
335 //echo '<pre>';print_r($this->data['ref_packages']);die;
336 } else {
337 $this->data['pagination'] = '';
338 }
339
340 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
341
342 $this->load->view2('my_referrals', $this->data);
343 }
344
345 public function my_balance()
346 {
347 $this->_check_login();
348
349 // data for calculate DGold price dynamically
350 $this->data['buy_usd_value'] = $this->config->item('buy_usd_amount');
351
352 $this->load->model('Docs_model');
353 $docs1 = $this->Docs_model->get(['user_id' => $this->session->user_id, 'type' => 'ID document', 'is_approved' => 1]);
354 $docs2 = $this->Docs_model->get(['user_id' => $this->session->user_id, 'type' => 'Proof of address', 'is_approved' => 1]);
355 $this->data['uploaded_docs'] = !empty($docs1) and !empty($docs2);
356
357
358 $this->load->model('Packages_model');
359 $this->db->select('SQL_CALC_FOUND_ROWS *', false);
360 $this->data['packages'] = $this->Packages_model->get(['user_id' => $this->data['id'], 'packages.is_active' => 1], 'last_payout_date DESC');
361
362 $this->data['packages_pagination'] = '';
363
364
365 // USD Invoices
366 $this->load->model('Money_model');
367 $all_invoice_url = '/'.$this->load->_get_this_controller_slug().'/my_usd_invoices/';
368
369 // del tickets if asked
370 $invoice_id = (int)trim($this->input->get('del_usd_invoice'));
371 if($invoice_id > 0) {
372 $invoice = $this->Money_model->get_one(array('id' => $invoice_id, 'user_id' => $this->data['id'], 'is_paid' => 0));
373 if(!empty($invoice)) {
374 $this->Money_model->delete(array('id' => $invoice_id));
375 redirect($all_invoice_url);
376 }
377 } elseif($this->input->post('action') == 'charge_usd') {
378 $inputUSD = BigDecimal::of(trim($this->input->post('inputUSD2')));
379 if($inputUSD->compareTo(0) >= 0) {
380
381 $invoice_arr = array(
382 'user_id' => $this->data['id'],
383 'amount_usd' => (string)$inputUSD,
384 );
385
386 $this->Money_model->insert($invoice_arr);
387 $this->data['show_modal_new_invoice'] = true;
388 }
389 }
390
391 $this->db->select('SQL_CALC_FOUND_ROWS *', false);
392 $this->data['usd_invoices'] = $this->Money_model->get(['user_id' => $this->data['id']], '`updated_at` DESC', null, 0, $this->data['rows_per_page']);
393
394 $query = $this->db->query('SELECT FOUND_ROWS() AS records');
395 $row = $query->row();
396 $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>' : '';
397
398
399 // DGold Invoices
400 $this->load->model('Ticket_model');
401 $all_invoice_url = '/'.$this->load->_get_this_controller_slug().'/my_invoices/';
402
403 // del tickets if asked
404 $invoice_id = (int)trim($this->input->get('del_dgold_invoice'));
405 if($invoice_id > 0) {
406 $invoice = $this->Ticket_model->get_one(array('id' => $invoice_id, 'user_id' => $this->data['id'], 'is_paid' => 0));
407 if(!empty($invoice)) {
408 $this->Ticket_model->delete(array('id' => $invoice_id));
409 redirect($all_invoice_url);
410 }
411 } elseif($this->input->post('action') == 'buy_dgold') {
412 $ask_price = trim($this->input->post('inputUSD'));
413 $inputUSD = BigDecimal::of($ask_price);
414 if(($inputUSD->compareTo(0) > 0) and ($inputUSD->compareTo($this->data['usd'] + $this->data['usd_cashout']) <= 0)) {
415 $inputDGold = BigDecimal::of($inputUSD)->dividedBy($this->data['dgold_rate'], 0, RoundingMode::HALF_UP);
416
417 $this->Ticket_model->start_transaction();
418
419 $ticket_id = $this->Ticket_model->insert([
420 'user_id' => $this->data['id'],
421 'amount_usd' => (string)$inputUSD,
422 'amount_dgold' => (string)$inputDGold,
423 ]);
424
425 if($this->data['usd'] >= $ask_price) {
426 $this->db->set('usd', "usd - {$ask_price}", FALSE);
427 } else {
428 $usd_price = $this->data['usd'];
429 $usd_cashout_price = $ask_price - $this->data['usd'];
430
431 $this->db->set('usd', "usd - {$usd_price}", FALSE);
432 $this->db->set('usd_cashout', "usd_cashout - {$usd_cashout_price}", FALSE);
433 }
434
435 $this->User_model->update_by_id(['id' => $this->data['id']]);
436
437
438 $ticket = $this->Ticket_model->get_one(['id' => $ticket_id]);
439 $this->_add_dgold($ticket, 'Balance', null);
440
441 $this->Ticket_model->commit_transaction();
442
443 $data2 = $this->User_model->get_one(array('id' => $this->session->user_id));
444 $this->data['usd'] = $data2['usd'];
445 $this->data['usd_cashout'] = $data2['usd_cashout'];
446 $this->data['coins'] = $data2['coins'];
447
448 $this->data['show_modal_dgold_paid'] = (string)$inputDGold;
449 }
450 }
451
452 // pay ticket if asked (old tickets support)
453 $ticket_id = (int)trim($this->input->get('pay_dgold_id'));
454 if($ticket_id > 0) {
455 $ticket = $this->Ticket_model->get_one(array('id' => $ticket_id, 'user_id' => $this->data['id'], 'is_paid' => 0));
456 if(!empty($ticket) and ($this->data['usd'] >= $ticket['amount_usd'])) {
457
458 $this->Ticket_model->start_transaction();
459
460 $this->db->set('usd', "usd - {$ticket['amount_usd']}", FALSE);
461 $this->User_model->update_by_id(['id' => $this->session->user_id]);
462
463 $this->_add_dgold($ticket, 'Balance', null);
464
465 $this->Ticket_model->commit_transaction();
466
467 $data2 = $this->User_model->get_one(array('id' => $this->session->user_id));
468 $this->data['usd'] = $data2['usd'];
469
470 $this->data['show_modal_dgold_paid'] = true;
471 }
472 }
473
474 $this->db->select('SQL_CALC_FOUND_ROWS *', false);
475 $this->data['dgold_invoices'] = $this->Ticket_model->get(['user_id' => $this->data['id']], '`updated_at` DESC', null, 0, $this->data['rows_per_page']);
476
477 $query = $this->db->query('SELECT FOUND_ROWS() AS records');
478 $row = $query->row();
479 $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>' : '';
480
481
482 $this->data['merchants_data'] = $this->_get_merchants_data();
483
484
485 // Packages to buy
486 if($this->input->post('action') == 'buy_package') {
487 $package_id = (int)trim($this->input->post('id'));
488 if($package_id > 0) {
489 if($this->_buy_package($package_id, $this->data)) {
490 $data2 = $this->User_model->get_one(array('id' => $this->data['id']));
491 $this->data['usd'] = $data2['usd'];
492
493 $this->data['show_modal_package_bought'] = true;
494
495 $this->db->select('SQL_CALC_FOUND_ROWS *', false);
496 $this->data['packages'] = $this->Packages_model->get(['user_id' => $this->data['id'], 'packages.is_active' => 1], 'last_payout_date DESC');
497
498 $this->data['packages_pagination'] = '';
499
500 $this->data['show_modal_package_bought'] = true;
501 //redirect('/admin/dgold_mining/');
502 } else {
503 $this->data['show_modal_insufficient_money'] = true;
504 }
505 }
506 }
507
508
509 // create payout ticket
510 $payout_usd_amount = (int)trim($this->input->get('payout_usd_amount'));
511 $microtimnow = time();
512
513 $datatwo = $this->User_model->get_one(array('id' => $this->data['id']));
514 $difference = $microtimnow - $datatwo['microtime'];
515
516 $finaltime = round($difference / (60 * 60 * 24));
517
518
519 $payout_usd_via = (string)trim($this->input->get('payout_usd_via'));
520 if(($payout_usd_amount > 0) and ($payout_usd_amount <= $this->data['usd_cashout']) and !empty($this->data['my_payout_options'][$payout_usd_via])) {
521 $dates = empty($this->data['packages']) ? [] : $this->Packages_model->gather_columns($this->data['packages'], 'start_date');
522 $dates[] = time();
523 $p_buy_package_date = min($dates);
524
525 if ($this->data['uploaded_docs'] and ($p_buy_package_date + 86400 * 30 <= time())) {
526 $this->load->model('Payout_model');
527 if(empty($datatwo['microtime'])){
528 $data = array (
529 'microtime' => $microtimnow,
530 );
531 $this->db->where('id', $this->data['id']);
532 $this->db->update('user', $data);
533 }
534 if($finaltime >= 7){
535 $data = array (
536 'microtime' => $microtimnow,
537 'total_amount' => '100',
538 );
539 $this->db->where('id', $this->data['id']);
540 $this->db->update('user', $data);
541 }
542
543
544 if($datatwo['total_amount'] != 0){
545 $ukupnooduzeti = $datatwo['total_amount'] - $payout_usd_amount;
546 if($payout_usd_amount <= $datatwo['total_amount']){
547 if ($this->Payout_model->add_payout($this->data['id'], $payout_usd_amount, ucfirst($payout_usd_via))) {
548 // success
549 $this->data['show_modal_new_payout'] = true;
550 $data = array (
551 'microtime' => $microtimnow,
552 'total_amount' => $ukupnooduzeti,
553 );
554 $this->db->where('id', $this->data['id']);
555 $this->db->update('user', $data);
556
557 $data2 = $this->User_model->get_one(['id' => $this->data['id']]);
558 $this->data['usd_cashout'] = $data2['usd_cashout'];
559 }else {
560 // fail
561 }
562
563 }else{
564 $this->data['modal_limited'] = true;
565 }
566 }else{
567 $this->data['timelimitnow'] = true;
568 }
569 /* }else{
570 if ($this->Payout_model->add_payout($this->data['id'], $payout_usd_amount, ucfirst($payout_usd_via))) {
571 // success
572 $this->data['show_modal_new_payout'] = true;
573 $data = array (
574 'microtime' => $microtimnow,
575 'total_amount' => $payout_usd_amount,
576 );
577 $this->db->where('id', $this->data['id']);
578 $this->db->update('user', $data);
579
580 $data2 = $this->User_model->get_one(['id' => $this->data['id']]);
581 $this->data['usd_cashout'] = $data2['usd_cashout'];
582 } else {
583 // fail
584 }
585 }*/
586 }
587 }
588
589
590 if($this->input->post('action') == 'upload_docs') {
591 //echo '<pre>';print_r($_FILES);die;
592
593 $user_docs_dir = FCPATH.'docs'.DIRECTORY_SEPARATOR.$this->session->user_id;
594 if(!is_dir($user_docs_dir)) {
595 mkdir($user_docs_dir);
596 chmod($user_docs_dir, 0777);
597 }
598
599 $add_docs_list = [];
600 if(is_array($_FILES['picture2']['tmp_name'])) {
601 $add_docs_list['Proof of address'] = 'picture2';
602 }
603 if(is_array($_FILES['picture1']['tmp_name'])) {
604 $add_docs_list['ID document'] = 'picture1';
605 }
606 if(!empty($add_docs_list)) {
607 $docs_added = 0;
608
609 foreach($add_docs_list as $pic_type => $pic_name) {
610 foreach($_FILES[$pic_name]['tmp_name'] as $idx => $tmp_name) {
611 $fname = str_replace(['/', '\\'], '', $_FILES[$pic_name]['name'][$idx]);
612 $fext = (strrpos($fname, '.') !== false) ? substr($fname, strrpos($fname, '.')) : '';
613 $rand_fname = substr(md5(password_hash(mt_rand(), PASSWORD_BCRYPT)), 0, 7);
614
615 $target_fname = $user_docs_dir . DIRECTORY_SEPARATOR . "{$rand_fname}{$fext}";
616 move_uploaded_file($tmp_name, $target_fname);
617
618 //add to database too
619 if (file_exists($target_fname)) {
620 $this->load->model('Docs_model');
621
622 $this->Docs_model->insert([
623 'user_id' => $this->session->user_id,
624 'file_name' => "{$rand_fname}{$fext}",
625 'type' => $pic_type,
626 'is_approved' => 0,
627 ]);
628
629 $docs_added++;
630 }
631 }
632 }
633
634 if($docs_added) {
635 $this->data['show_modal_add_docs'] = true;
636 }
637 }
638
639 //redirect();
640 }
641
642
643 // get merchants options
644 $this->data['solidtrustpay_on'] = $this->Options_model->get_option('merchant_solidtrustpay_on');
645 $this->data['payeer_on'] = $this->Options_model->get_option('merchant_payeer_on');
646 $this->data['advcash_on'] = $this->Options_model->get_option('merchant_advcash_on');
647 $this->data['cryptonator_on'] = $this->Options_model->get_option('merchant_cryptonator_on');
648 $this->data['btc_on'] = $this->Options_model->get_option('merchant_btc_on');
649 $this->data['coinbase_on'] = $this->Options_model->get_option('merchant_coinbase_on');
650 $this->data['paypal_on'] = $this->Options_model->get_option('merchant_paypal_on');
651 $this->data['paypal_payout_on'] = $this->Options_model->get_option('merchant_paypal_payout_on');
652 $this->data['coin_counpayments_on'] = $this->Options_model->get_option('merchant_coin_paymentns_on');
653
654
655 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
656
657 $this->load->view2('my_balance', $this->data);
658 }
659 public function admin_ddk_sp_invoices(){
660 $this->_check_login();
661 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
662
663 $this->load->view2('admin_ddk_sp_invoices', $this->data);
664 }
665 public function ddk_buy(){
666 $this->_check_login();
667 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
668
669 $this->load->view2('ddkbuy', $this->data);
670 }
671 public function ddk_ref(){
672 $this->_check_login();
673 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
674
675 $this->load->view2('ddkref', $this->data);
676 }
677 public function ddk_invoice(){
678 $this->_check_login();
679 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
680
681 $this->load->view2('invoice_ddk', $this->data);
682 }
683 public function ddk_ip(){
684 $this->_check_login();
685 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
686
687 $this->load->view2('ddkip', $this->data);
688 }
689 public function ddk_sp(){
690 $this->_check_login();
691 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
692
693 $this->load->view2('ddksp', $this->data);
694 }
695 public function my_invoices($page = 0)
696 {
697 $this->_check_login();
698
699 $this->load->model('Ticket_model');
700
701 // del ticket if asked
702 $invoice_id = (int)trim($this->input->get('del_invoice'));
703 if($invoice_id > 0) {
704 $invoice = $this->Ticket_model->get_one(array('id' => $invoice_id, 'user_id' => $this->data['id'], 'is_paid' => 0));
705 if(!empty($invoice)) {
706 $this->Ticket_model->delete(array('id' => $invoice_id));
707 redirect('/'.$this->load->_get_this_controller_slug().'/my_invoices/');
708 }
709 }
710
711 // pay ticket if asked
712 $ticket_id = (int)trim($this->input->get('pay_dgold_id'));
713 if($ticket_id > 0) {
714 $ticket = $this->Ticket_model->get_one(array('id' => $ticket_id, 'user_id' => $this->data['id'], 'is_paid' => 0));
715 if(!empty($ticket) and (($this->data['usd'] + $this->data['usd_cashout']) >= $ticket['amount_usd'])) {
716
717 $this->Ticket_model->start_transaction();
718
719
720 if($this->data['usd'] >= $ticket['amount_usd']) {
721 $this->db->set('usd', "usd - {$ticket['amount_usd']}", FALSE);
722 } else {
723 $usd_price = $this->data['usd'];
724 $usd_cashout_price = $ticket['amount_usd'] - $this->data['usd'];
725
726 $this->db->set('usd', "usd - {$usd_price}", FALSE);
727 $this->db->set('usd_cashout', "usd_cashout - {$usd_cashout_price}", FALSE);
728 }
729
730 $this->User_model->update_by_id(['id' => $this->session->user_id]);
731
732 $this->_add_dgold($ticket, 'Balance', null);
733
734 $this->Ticket_model->commit_transaction();
735
736 $data2 = $this->User_model->get_one(array('id' => $this->session->user_id));
737 $this->data['usd'] = $data2['usd'];
738
739 //$this->data['show_modal_dgold_paid'] = true;
740 redirect('/'.$this->load->_get_this_controller_slug().'/my_invoices/');
741 }
742 }
743
744
745 $page = ((int)$page - 1);
746 $page = ($page > 0) ? $page : 0;
747
748 $this->db->select('SQL_CALC_FOUND_ROWS *', false);
749 $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']);
750
751 // pagination
752 $query = $this->db->query('SELECT FOUND_ROWS() AS records');
753 $row = $query->row();
754
755 $base_url = base_url($this->load->_get_this_controller_slug().'/'.__FUNCTION__);
756
757 $this->data['pagination'] = $this->_get_pagination_html($base_url, $row->records);
758
759 //get options
760 $this->data['merchants_data'] = $this->_get_merchants_data();
761
762 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
763
764
765 $this->load->view2('my_invoices', $this->data);
766 }
767
768 public function my_usd_invoices($page = 0)
769{
770 $this->_check_login();
771
772 $this->load->model('Money_model');
773
774 // del tickets if asked
775 $invoice_id = (int)trim($this->input->get('del_invoice'));
776 if($invoice_id > 0) {
777 $invoice = $this->Money_model->get_one(array('id' => $invoice_id, 'user_id' => $this->data['id'], 'is_paid' => 0));
778 if(!empty($invoice)) {
779 $this->Money_model->delete(array('id' => $invoice_id));
780 redirect('/'.$this->load->_get_this_controller_slug().'/my_usd_invoices/');
781 }
782 }
783
784
785 $page = ((int)$page - 1);
786 $page = ($page > 0) ? $page : 0;
787
788 $this->db->select('SQL_CALC_FOUND_ROWS *', false);
789 $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']);
790
791 // pagination
792 $query = $this->db->query('SELECT FOUND_ROWS() AS records');
793 $row = $query->row();
794
795 $base_url = base_url($this->load->_get_this_controller_slug().'/'.__FUNCTION__);
796
797 $this->data['pagination'] = $this->_get_pagination_html($base_url, $row->records);
798
799 //get options
800 $this->data['merchants_data'] = $this->_get_merchants_data();
801
802 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
803
804
805 $this->load->view2('my_usd_invoices', $this->data);
806}
807
808 public function my_messages($page = 0)
809 {
810 $this->_check_login();
811
812 $page = ((int)$page - 1);
813 $page = ($page > 0) ? $page : 0;
814
815 $this->load->model('Messages_model');
816
817
818 $user_ids = $this->Messages_model->get_users_who_wrote($this->data['id']);
819 $this->data['pagination'] = '';
820
821 // "Support" rec
822 $this->data['support_rec'] = [
823 'created_at' => 0,
824 'seen' => 'yes',
825 ];
826 $this->data['support_user_id'] = $this->Options_model->get_option('support_user_id');
827 if(isset($user_ids['seen'][$this->data['support_user_id']])) {
828 $this->data['support_rec'] = [
829 'created_at' => $user_ids['created_at'][$this->data['support_user_id']],
830 'seen' => $user_ids['seen'][$this->data['support_user_id']],
831 ];
832 unset($user_ids['created_at'][$this->data['support_user_id']]);
833 unset($user_ids['seen'][$this->data['support_user_id']]);
834 }
835
836 if(!empty($user_ids)) {
837 arsort($user_ids['created_at'], SORT_NATURAL);
838 $user_dates_chunked = array_chunk($user_ids['created_at'], $this->data['rows_per_page'],true);
839
840 $page = isset($user_dates_chunked[$page]) ? $page : count($user_dates_chunked) - 1;
841
842 $retU = $this->User_model->get(['id' => array_keys($user_dates_chunked[$page])], null, 'id, username, email, name, surname');
843 $retUassoc = [];
844 foreach($retU as $objU) {
845 $retUassoc[$objU['id']] = $objU;
846 }
847
848 $this->data['message_users'] = [];
849 foreach($user_dates_chunked[$page] as $user_id => $created_at) {
850 if(!empty($retUassoc[$user_id])) {
851 $objU = $retUassoc[$user_id];
852 $objU['seen'] = $user_ids['seen'][$user_id];
853 $objU['last_msg'] = $created_at;
854
855 $this->data['message_users'][$user_id] = $objU;
856 }
857 }
858
859 // pagination
860 $base_url = base_url($this->load->_get_this_controller_slug().'/'.__FUNCTION__);
861 $this->data['pagination'] = $this->_get_pagination_html($base_url, count($user_ids['created_at']));
862 }
863
864 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
865
866 $this->load->view2('my_messages', $this->data);
867 }
868
869 public function ajax_messages($with_user_id = null, $output = 'full')
870 {
871 $this->load->model('Options_model');
872
873 $is_support = false;
874 if($with_user_id == 'support') {
875 $with_user_id = $this->Options_model->get_option('support_user_id');
876 $is_support = true;
877 }
878
879 $with_user_id = (int)$with_user_id;
880 if($with_user_id <= 0)
881 die;
882
883 $this->_check_login(false);
884
885 $this->load->model('Messages_model');
886
887 // check if user can text with this user
888 $i_can_text = ($this->data['is_admin'] == 1) or $is_support;
889 if(!$i_can_text) {
890 $wrote_to_me = $this->Messages_model->get_one(['to_user' => $this->data['id']]);
891 $i_can_text = !empty($wrote_to_me);
892
893 if(!$i_can_text) {
894 $dgold_inc_arr = $this->Options_model->get_option('dgold_inc_arr');
895 $referrals = $this->User_model->get_my_referrals($this->data['id'], $dgold_inc_arr);
896
897 $ref_ids = $this->User_model->gather_columns($referrals, 'id name', true);
898 $i_can_text = isset($ref_ids[$this->data['id']]);
899 }
900 }
901 if(!$i_can_text)
902 return;
903
904 // check if message sent
905 $message = trim($this->input->post('message'));
906 if(!empty($message)) {
907 $ret = $this->_add_message($this->data['id'], $with_user_id, $message);
908 }
909
910 $this->data['users'][$this->session->user_id] = $this->data;
911 if($is_support) {
912 $this->data['users'][$with_user_id] = [
913 'id' => $with_user_id,
914 'name' => '<span class="text-red">Support</span>',
915 'surname' => '',
916 'username' => '',
917 ];
918 } else {
919 $this->data['users'][$with_user_id] = $this->User_model->get_one(['id' => $with_user_id]);
920 }
921
922 $this->data['owner_id'] = $this->session->user_id;
923 $this->data['with_user_id'] = $with_user_id;
924 $this->data['output'] = $output;
925
926 $this->data['messages'] = $this->Messages_model->get_user_chat($this->data['id'], $with_user_id);
927
928 $this->load->view('user_chat', $this->data);
929 }
930
931 public function cron()
932 {
933 $t = time();
934
935 $this->load->model('Options_model');
936
937 $cron_running = $this->Options_model->get_option('cron_running', 0);
938 if($cron_running) {
939 $msg = "Cron is already running!";
940 log_message('error', $msg);
941 echo "{$msg}\n";
942 die;
943 }
944 $this->Options_model->set_option('cron_running', 1);
945
946 $cron_last_run = $this->Options_model->get_option('cron_last_run', 0);
947
948 // send notification emails
949 $this->load->model('Messages_model');
950
951 // hourly update
952 if(date('dmYH', $t) != date('dmYH', $cron_last_run)) {
953 $this->db->distinct();
954 $user_ids = $this->Messages_model->get(['notified' => 'hourly'], null, 'to_user');
955
956 $email_res = $this->_send_notification_emails($user_ids, 'to_user');
957 if($email_res) {
958 $this->Messages_model->update(['notified' => 'hourly'], ['notified' => 'yes']);
959 echo count($user_ids)." - hourly\n";
960 }
961 }
962
963 // daily update
964 if(date('dmY', $t) != date('dmY', $cron_last_run)) {
965 $this->db->distinct();
966 $user_ids = $this->Messages_model->get(['notified' => 'daily'], null, 'to_user');
967
968 $email_res = $this->_send_notification_emails($user_ids, 'to_user');
969 if($email_res) {
970 $this->Messages_model->update(['notified' => 'daily'], ['notified' => 'yes']);
971 echo count($user_ids)." - daily\n";
972 }
973 }
974
975 // weekly update
976 if(date('WY', $t) != date('WY', $cron_last_run)) {
977 $this->db->distinct();
978 $user_ids = $this->Messages_model->get(['notified' => 'weekly'], null, 'to_user');
979
980 $email_res = $this->_send_notification_emails($user_ids, 'to_user');
981 if($email_res) {
982 $this->Messages_model->update(['notified' => 'weekly'], ['notified' => 'yes']);
983 echo count($user_ids)." - weekly\n";
984 }
985 }
986
987/*
988 if(!$is_ok) {
989 $this->Options_model->set_option('cron_running', 0);
990 $msg = "Check Voluum Email and Password!";
991 log_message('error', $msg);
992 echo "{$msg}\n";
993 die;
994 }
995*/
996
997
998
999
1000 $this->Options_model->set_option('cron_running', 0);
1001 $this->Options_model->set_option('cron_last_run', $t);
1002
1003 $msg = "Cron job from {$t} have updated in ".(time() - $t)." secs.";
1004 log_message('error', $msg);
1005 echo "{$msg}\n";
1006 }
1007
1008 private function _send_notification_emails($user_ids = [], $column = 'to_user', $template = 'chat')
1009 {
1010 if(!empty($user_ids)) {
1011 $this->load->model('Options_model');
1012
1013 if($template == 'inbox') {
1014 $notification_subject = $this->Options_model->get_option('email_notification_subject_inbox');
1015 $notification_message = $this->Options_model->get_option('email_notification_message_inbox');
1016 } else {
1017 $notification_subject = $this->Options_model->get_option('email_notification_subject_chat');
1018 $notification_message = $this->Options_model->get_option('email_notification_message_chat');
1019 }
1020
1021 $Uids = $this->User_model->gather_columns($user_ids, $column);
1022
1023 $ids = implode(',', $Uids);
1024 $query = $this->db->query("SELECT id, email, `name`, surname, username FROM `user` WHERE `id` IN({$ids})");
1025 $retU = $query->result_array();
1026
1027 $to_email = [];
1028 foreach($retU as $objU) {
1029 $to_email[$objU['email']] = $this->User_model->get_user_name($objU);
1030 }
1031
1032 $this->_send_email('', '', $to_email, '', '', '', $notification_subject, $notification_message, 'sendgrid');
1033
1034 return true;
1035 }
1036
1037 return false;
1038 }
1039
1040 private function _add_message($from_user_id, $to_user_id, $message)
1041 {
1042 $message = trim(strip_tags($message, '<h1><h2><h3><h4><h5><h6><b><i><u><div><span><blockquote><ul><ol><li><br><p><a><img>'));
1043 if(empty($message))
1044 return false;
1045
1046 $toObjU = $this->User_model->get_one(['id' => $to_user_id]);
1047
1048 $notified = 'asap';
1049 if(!empty($toObjU['emailing_options'])) {
1050 $emailing_options = unserialize($toObjU['emailing_options']);
1051 $notified = empty($emailing_options['notify_opt']) ? $notified : $emailing_options['notify_opt'];
1052 }
1053 if($toObjU['is_emailed'] == 0) {
1054 $notified = 'yes';
1055 }
1056
1057
1058 $this->load->model('Messages_model');
1059
1060 $new_msg_id = $this->Messages_model->insert([
1061 'from_user' => $from_user_id,
1062 'to_user' => $to_user_id,
1063 'seen' => 'no',
1064 'notified' => $notified,
1065 'message' => $message,
1066 ]);
1067
1068 //send email notification
1069 if($notified == 'asap') {
1070 $to_email = $toObjU['email'];
1071 $to_name = $this->User_model->get_user_name($toObjU);
1072
1073 $this->load->model('Options_model');
1074 $notification_subject = $this->Options_model->get_option('email_notification_subject_chat');
1075 $notification_message = $this->Options_model->get_option('email_notification_message_chat');
1076
1077 $this->_send_email('', '', $to_email, $to_name, '', '', $notification_subject, $notification_message, 'standard');
1078 $this->Messages_model->update_by_id([
1079 'id' => $new_msg_id,
1080 'notified' => 'yes',
1081 ]);
1082 }
1083
1084 return true;
1085 }
1086
1087 public function message_settings()
1088 {
1089 $this->_check_admin();
1090
1091 // change chat configuration
1092 if($this->input->post('action') == 'chat_config') {
1093 $support_user_id = trim($this->input->post('support_user_id'));
1094 $support_user_id_int = (int)$support_user_id;
1095 $email_notification_subject = (string)trim($this->input->post('email_notification_subject'));
1096 $email_notification_message = (string)trim($this->input->post('email_notification_message'));
1097
1098 if($support_user_id != $support_user_id_int) {
1099 $objU = $this->User_model->get_one(['username' => $support_user_id]);
1100 if(!empty($objU)) {
1101 $support_user_id = $objU['id'];
1102 }
1103 }
1104
1105 $this->Options_model->set_option('support_user_id', $support_user_id);
1106 $this->Options_model->set_option('email_notification_subject_chat', $email_notification_subject);
1107 $this->Options_model->set_option('email_notification_message_chat', $email_notification_message);
1108 }
1109
1110 // change messages configuration
1111 if($this->input->post('action') == 'message_config') {
1112 $email_notification_subject2 = (string)trim($this->input->post('email_notification_subject2'));
1113 $email_notification_message2 = (string)trim($this->input->post('email_notification_message2'));
1114
1115 $this->Options_model->set_option('email_notification_subject_inbox', $email_notification_subject2);
1116 $this->Options_model->set_option('email_notification_message_inbox', $email_notification_message2);
1117 }
1118
1119 // set options
1120 $this->data['support_user_id'] = $this->Options_model->get_option('support_user_id');
1121 $this->data['email_notification_subject'] = $this->Options_model->get_option('email_notification_subject_chat');
1122 $this->data['email_notification_message'] = $this->Options_model->get_option('email_notification_message_chat');
1123
1124 $this->data['email_notification_subject2'] = $this->Options_model->get_option('email_notification_subject_inbox');
1125 $this->data['email_notification_message2'] = $this->Options_model->get_option('email_notification_message_inbox');
1126
1127 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
1128
1129 $this->load->view2('admin_message_settings', $this->data);
1130 }
1131 public function dgold_spinner_open()
1132 {
1133 $this->_check_login();
1134 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
1135 $this->load->view2('dgold_spinner_open', $this->data);
1136
1137 }
1138 public function dgold_spinner()
1139 {
1140 $this->_check_login();
1141 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
1142
1143 $this->load->view2('dgold_spinner', $this->data);
1144
1145 }
1146 public function user_ddk_invoice(){
1147 $this->_check_login();
1148 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
1149
1150 $this->load->view2('user_ddk_invoice', $this->data);
1151 }
1152 public function trka_za_coine()
1153 {
1154 $this->_check_login();
1155 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
1156
1157 $this->load->view2('trka_za_coine', $this->data);
1158
1159 }
1160 public function withdraw()
1161 {
1162 $this->_check_login();
1163
1164 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
1165
1166
1167 $this->load->view2('withdraw', $this->data);
1168 }
1169 public function topone()
1170 {
1171 $this->_check_login();
1172
1173 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
1174
1175
1176 $this->load->view2('topone', $this->data);
1177 }
1178 public function invoices_users_words()
1179 {
1180 $this->_check_login();
1181
1182 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
1183
1184
1185 $this->load->view2('invoices_users_words', $this->data);
1186 }
1187 public function invoices_users_trial()
1188 {
1189 $this->_check_login();
1190
1191 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
1192
1193
1194 $this->load->view2('invoices_users_trial', $this->data);
1195 }
1196
1197
1198 public function promo_coins()
1199 {
1200 $this->_check_login();
1201 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
1202 $user_array = $this->session->user_arr;
1203 $this->session->user_arr = $user_array;
1204 $this->session->user_id = $user_array['id'];
1205 $this->data['user_ides'] = $user_array['id'];
1206 $this->load->view2('promo_coins', $this->data);
1207
1208 }
1209 public function ddkprofile() {
1210 $this->_check_login();
1211 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
1212 $this->load->view2('ddkprofile', $this->data);
1213 }
1214 public function buyddk() {
1215 $this->_check_login();
1216 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
1217 $this->load->view2('buyddk', $this->data);
1218 }
1219 public function ddkreferals() {
1220 $this->_check_login();
1221 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
1222 $this->load->view2('ddkreferals', $this->data);
1223 }
1224 public function invoicesddk() {
1225 $this->_check_login();
1226 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
1227 $this->load->view2('invoicesddk', $this->data);
1228 }
1229 public function my_promo()
1230 {
1231 $this->_check_login();
1232
1233 $this->load->helper('url');
1234
1235 $bad_dirs = array_flip(explode(' ', '. ..'));
1236
1237 $promo_lands = scandir(FCPATH."promo");
1238 $this->data['promo_lands'] = [];
1239 foreach($promo_lands as $land) {
1240 if(!isset($bad_dirs[$land]) and is_dir(FCPATH."promo") and @file_exists(FCPATH."promo/{$land}/preview.jpg")) {
1241 $landing_name = str_replace(['-', '_'], ' ', $land);
1242 $land_arr = explode(' ', $landing_name);
1243 foreach($land_arr as $idx => $rec) {
1244 $land_arr[$idx] = ucfirst($rec);
1245 }
1246 $landing_name = implode(' ', $land_arr);
1247
1248 $this->data['promo_lands'][] = [
1249 'landing' => $land,
1250 'landing_name' => $landing_name,
1251 'preview' => site_url("/promo/{$land}/preview.jpg"),
1252 'ref_link' => site_url("/promo/{$land}/index.php?ref={$this->data['username']}"),
1253 ];
1254 }
1255 }
1256
1257 $promo_banners = scandir(FCPATH."promo/banners");
1258 $banners_tmp_arr = [];
1259 foreach($promo_banners as $banner) {
1260 if(!isset($bad_dirs[$banner]) and is_dir(FCPATH."promo/banners") and @file_exists(FCPATH."promo/banners/{$banner}/preview.jpg")) {
1261 list($sizes) = array_reverse(explode('_', $banner));
1262 $sizes = explode('x', strtolower($sizes));
1263
1264 if((count($sizes) != 2) or ((int)$sizes[0] <= 0) or ((int)$sizes[1] <= 0))
1265 continue;
1266
1267 $banner_name = str_replace(['-', '_'], ' ', $banner);
1268 $banner_arr = explode(' ', $banner_name);
1269 foreach($banner_arr as $idx => $rec) {
1270 $banner_arr[$idx] = ucfirst($rec);
1271 }
1272 $banner_name = implode(' ', $banner_arr);
1273
1274 $banners_tmp_arr[(int)$sizes[1]][] = [
1275 'banner' => $banner,
1276 'banner_name' => $banner_name,
1277 'width' => (int)$sizes[0],
1278 'height' => (int)$sizes[1],
1279 'preview' => site_url("/promo/banners/{$banner}/preview.jpg"),
1280 'ref_link' => site_url("/promo/banners/{$banner}/index.php?ref={$this->data['username']}"),
1281 ];
1282 }
1283 }
1284
1285 // sorting
1286 ksort($banners_tmp_arr, SORT_NATURAL);
1287 $this->data['promo_banners'] = [];
1288 foreach($banners_tmp_arr as $tmp_arr) {
1289 foreach($tmp_arr as $banner_tmp) {
1290 $this->data['promo_banners'][] = $banner_tmp;
1291 }
1292 }
1293
1294 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
1295
1296 $this->load->view2('my_promo', $this->data);
1297 }
1298
1299 public function the_game()
1300 {
1301 //log_message('error', 'the_game-status-'.$_SERVER['REMOTE_ADDR'].'-'.serialize($_POST).'-'.serialize($_GET));
1302
1303 $this->_check_login();
1304
1305 $this->data['game_chest_reward'] = $this->Options_model->get_option('game_chest_reward', 1);
1306 $this->data['game_flip_reward'] = $this->Options_model->get_option('game_flip_reward', 2);
1307
1308 $this->data['dollars'] = $this->data['coins'] * $this->data['dgold_rate'];
1309
1310 // let the game begin!
1311 if(($this->data['lastgame_at'] < time() - 3600 * $this->data['game_countdown']) and !empty($_GET['open_chest'])) {
1312 $open_chest = (int)$_GET['open_chest'];
1313 $add_reward = false;
1314 $reset_timer = false;
1315
1316 if(isset($_GET['take_reward'])) {
1317 if($this->data['gamecode1'] == $open_chest) {
1318 $add_reward = $this->data['game_chest_reward'];
1319 }
1320 $reset_timer = true;
1321 } elseif(isset($_GET['heads'])) {
1322 if(($this->data['gamecode1'] == $open_chest) and ($this->data['gamecode2'] == (int)$_GET['heads'])) {
1323 $add_reward = $this->data['game_flip_reward'];
1324 echo 1;
1325 } else {
1326 echo 0;
1327 }
1328 $reset_timer = true;
1329 } else {
1330 if($this->data['gamecode1'] == $open_chest) {
1331 echo 1;
1332 } else {
1333 $reset_timer = true;
1334 echo 0;
1335 }
1336 }
1337
1338 // add reward
1339 if(!empty($add_reward)) {
1340 // add 1 coin to user and allow to flip coin
1341 $this->db->set('coins', "coins + {$add_reward}", FALSE);
1342 $this->User_model->update_by_id(['id' => $this->data['id']]);
1343
1344 $this->Options_model->inc_option('dgold_total_rewarded', $add_reward);
1345 }
1346
1347 // reset timer and game codes
1348 if($reset_timer) {
1349 $this->data['gamecode1'] = mt_rand(1, 3);
1350 $this->data['gamecode2'] = mt_rand(0, 1);
1351 $this->User_model->update_by_id(['id' => $this->data['id'], 'lastgame_at' => time(), 'gamecode1' => $this->data['gamecode1'], 'gamecode2' => $this->data['gamecode2']]);
1352 }
1353
1354 die;
1355 }
1356
1357
1358 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
1359
1360 $this->load->view2('the_game', $this->data);
1361 }
1362
1363 public function the_game_settings()
1364 {
1365 //log_message('error', 'the_game_settings-status-'.$_SERVER['REMOTE_ADDR'].'-'.serialize($_POST).'-'.serialize($_GET));
1366
1367 $this->_check_admin();
1368
1369 $this->data['game_chest_reward'] = $this->Options_model->get_option('game_chest_reward', 1);
1370 $this->data['game_flip_reward'] = $this->Options_model->get_option('game_flip_reward', 2);
1371
1372 $this->data['dollars'] = $this->data['coins'] * $this->data['dgold_rate'];
1373
1374 // change game elapsed time
1375 if(!empty($_GET['time_elapsed'])) {
1376 $time_elapsed = (int)$_GET['time_elapsed'];
1377 if($time_elapsed > 0) {
1378 $this->User_model->update_by_id(['id' => $this->data['id'], 'lastgame_at' => time() - 3600 * $this->data['game_countdown'] + $time_elapsed]);
1379 redirect('/'.$this->load->_get_this_controller_slug().'/'.__FUNCTION__);
1380 }
1381 }
1382
1383 // change game configuration
1384 if($this->input->post('action') == 'config') {
1385 $countdown = (int)trim($this->input->post('inputCountdown'));
1386 $chestReward = (int)trim($this->input->post('inputChestReward'));
1387 $flipReward = (int)trim($this->input->post('inputFlipReward'));
1388
1389 if(($countdown > 0) and ($chestReward > 0) and ($flipReward > 0)) {
1390 $this->Options_model->set_option('game_countdown', $countdown);
1391 $this->Options_model->set_option('game_chest_reward', $chestReward);
1392 $this->Options_model->set_option('game_flip_reward', $flipReward);
1393
1394 $this->data['game_countdown'] = $countdown;
1395 $this->data['game_chest_reward'] = $chestReward;
1396 $this->data['game_flip_reward'] = $flipReward;
1397 }
1398 }
1399
1400 // let the game begin!
1401 if(($this->data['lastgame_at'] < time() - 3600 * $this->data['game_countdown']) and !empty($_GET['open_chest'])) {
1402 $open_chest = (int)$_GET['open_chest'];
1403 $add_reward = false;
1404 $reset_timer = false;
1405
1406 if(isset($_GET['take_reward'])) {
1407 if($this->data['gamecode1'] == $open_chest) {
1408 $add_reward = $this->data['game_chest_reward'];
1409 }
1410 $reset_timer = true;
1411 } elseif(isset($_GET['heads'])) {
1412 if(($this->data['gamecode1'] == $open_chest) and ($this->data['gamecode2'] == (int)$_GET['heads'])) {
1413 $add_reward = $this->data['game_flip_reward'];
1414 echo 1;
1415 } else {
1416 echo 0;
1417 }
1418 $reset_timer = true;
1419 } else {
1420 if($this->data['gamecode1'] == $open_chest) {
1421 echo 1;
1422 } else {
1423 $reset_timer = true;
1424 echo 0;
1425 }
1426 }
1427
1428 // add reward
1429 if(!empty($add_reward)) {
1430 // add 1 coin to user and allow to flip coin
1431 $this->db->set('coins', "coins + {$add_reward}", FALSE);
1432 $this->User_model->update_by_id(['id' => $this->data['id']]);
1433
1434 $this->Options_model->inc_option('dgold_total_rewarded', $add_reward);
1435 }
1436
1437 // reset timer and game codes
1438 if($reset_timer) {
1439 $this->data['gamecode1'] = mt_rand(1, 3);
1440 $this->data['gamecode2'] = mt_rand(0, 1);
1441 $this->User_model->update_by_id(['id' => $this->data['id'], 'lastgame_at' => time(), 'gamecode1' => $this->data['gamecode1'], 'gamecode2' => $this->data['gamecode2']]);
1442 }
1443
1444 die;
1445 }
1446
1447
1448 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
1449
1450 $this->load->view2('admin_the_game', $this->data);
1451 }
1452
1453 public function users($page = 0)
1454 {
1455 $this->_check_admin();
1456
1457 $page = ((int)$page - 1);
1458 $page = ($page > 0) ? $page : 0;
1459
1460 // change some user data if asked
1461 try {
1462 $user_id = (int)trim($this->input->get('id'));
1463 $is_confirmed = (int)trim($this->input->get('is_confirmed'));
1464 $is_banned = (int)trim($this->input->get('is_banned'));
1465 $is_admin = (int)trim($this->input->get('is_admin'));
1466 $coins = BigDecimal::of(trim($this->input->get('coins')));
1467 $ddk = BigDecimal::of(trim($this->input->get('ddk')));
1468 $dollars = BigDecimal::of(trim($this->input->get('dollars')));
1469 $dollars_cashout = BigDecimal::of(trim($this->input->get('dollars_cashout')));
1470 $buy_package = (int)trim($this->input->get('buy_package'));
1471 //echo $buy_package;die;
1472 if(($user_id > 0) and ($is_confirmed >= 0) and ($is_banned >= 0) and ($is_admin >= 0) and ($coins->compareTo(0) >= 0)) {
1473 $objU = $this->User_model->get_one(array('id' => $user_id));
1474 if(!empty($objU)) {
1475 $this->User_model->update_by_id(array(
1476 'id' => $user_id,
1477 'is_confirmed' => $is_confirmed ? 1 : 0,
1478 'is_banned' => $is_banned ? 1 : 0,
1479 'is_admin' => $is_admin ? 1 : 0,
1480 'coins' => (string)$coins,
1481 'doomsdaycoin' => (string)$ddk,
1482 'usd' => (string)$dollars,
1483 'usd_cashout' => (string)$dollars_cashout,
1484 ));
1485
1486 if($buy_package > 0) {
1487 $objPS = $this->Packages_setup_model->get_one(['id' => $buy_package, 'is_active' => 1]);
1488 if(!empty($objPS)) {
1489 $this->load->model('Packages_model');
1490 $t = time();
1491 $this->Packages_model->insert([
1492 'user_id' => $objU['id'],
1493 'package_id' => $objPS['id'],
1494 'daily_dgolds' => $objPS['daily_dgolds'],
1495 'start_date' => $t,//$t - 31 * 86400,
1496 'last_payout_date' => $t,//$t - 31 * 86400,
1497 'stop_date' => $t + 12 * 30 * 86400,
1498 'title' => $objPS['title'],
1499 'hash_rate' => $objPS['hash_rate'],
1500 'hash_rate_sign' => $objPS['hash_rate_sign'],
1501 'last_share' => $t,
1502 'next_share' => $t,
1503 'is_active' => 1,
1504 ]);
1505 }
1506 }
1507 redirect('/'.$this->load->_get_this_controller_slug().'/users/');
1508 }
1509 }
1510 } catch(Exception $e) {
1511 // do nothing
1512 }
1513
1514 // del user if asked
1515 $user_id = (int)trim($this->input->get('del_user'));
1516 if($user_id > 0) {
1517 $objU = $this->User_model->get_one(array('id' => $user_id));
1518 if(!empty($objU)) {
1519 $this->User_model->delete(array('id' => $user_id));
1520 redirect('/'.$this->load->_get_this_controller_slug().'/users/');
1521 }
1522 }
1523
1524 // set db query condition if search string sent
1525 $condition = null;
1526 $this->data['search'] = null;
1527 $search = trim($this->input->get('search'));
1528 if(!empty($search)) {
1529 $search_int = (int)$search;
1530
1531 if(($search_int > 0) or ($search === '0')) {
1532 $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}";
1533 $this->data['search'] = $search_int;
1534 } elseif(!empty($search)) {
1535 $search_str = $this->db->escape($search);
1536 $search_str = substr($search_str, 0, 1).'%'.substr($search_str, 1, -1).'%'.substr($search_str, -1);
1537 $condition = "`username` LIKE {$search_str} OR `email` LIKE {$search_str} OR `name` LIKE {$search_str} OR `surname` LIKE {$search_str}";
1538 $this->data['search'] = $search;
1539 }
1540 }
1541
1542
1543 $this->db->select('SQL_CALC_FOUND_ROWS *', false);
1544 $this->data['users'] = $this->User_model->get($condition, '`id` DESC', null, $page * $this->data['rows_per_page'], $this->data['rows_per_page']);
1545
1546 // pagination
1547 $query = $this->db->query('SELECT FOUND_ROWS() AS records');
1548 $row = $query->row();
1549
1550 $base_url = base_url($this->load->_get_this_controller_slug().'/'.__FUNCTION__);
1551
1552 $this->data['pagination'] = $this->_get_pagination_html($base_url, $row->records);
1553
1554
1555 $this->load->model('Packages_model');
1556 $Uids = $this->User_model->gather_columns($this->data['users'], 'id');
1557 $this->data['users_packages'] = $this->Packages_model->get(['user_id' => $Uids, 'packages.is_active' => 1]);
1558
1559 //get options
1560 $this->data['dgold_inc_arr'] = $this->Options_model->get_option('dgold_inc_arr');
1561 $this->data['dgold_price_arr'] = $this->Options_model->get_option('dgold_price_arr');
1562 $this->data['dgold_total_rewarded'] = $this->Options_model->get_option('dgold_total_rewarded');
1563 $this->data['dgold_total_sold_value'] = $this->Options_model->get_option('dgold_total_sold_value');
1564
1565 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
1566
1567 $this->load->view2('admin_users', $this->data);
1568 }
1569
1570 public function mass_message($page = 0)
1571 {
1572 $this->_check_admin();
1573
1574 $page = ((int)$page - 1);
1575 $page = ($page > 0) ? $page : 0;
1576
1577 $this->load->model('Blog_posts_model');
1578
1579 // save as draft if asked
1580 if($this->input->post('action') == 'save_as_draft') {
1581 $edit_message = (int)trim($this->input->get('edit_message'));
1582
1583 $mass_subject = (string)trim($this->input->post('mass_subject'));
1584 $mass_message = (string)trim($this->input->post('mass_message'));
1585
1586 if($edit_message > 0) {
1587 $objME = $this->Blog_posts_model->get_one(['id' => $edit_message, 'is_draft' => 1]);
1588 if(!empty($objME) and ($objME['subject'] == $mass_subject) and ($objME['message'] == $mass_message)) {
1589 redirect('/'.$this->load->_get_this_controller_slug()."/mass_message/?edit_message={$edit_message}#new_edit");
1590 }
1591 }
1592
1593 $edit_message = $this->Blog_posts_model->insert([
1594 'subject' => $mass_subject,
1595 'message' => $mass_message,
1596 'is_draft' => 1,
1597 ]);
1598 redirect('/'.$this->load->_get_this_controller_slug()."/mass_message/?edit_message={$edit_message}#new_edit");
1599 }
1600
1601 // edit message if asked
1602 $message_id = (int)trim($this->input->get('edit_message'));
1603 if($message_id > 0) {
1604 $objME = $this->Blog_posts_model->get_one(['id' => $message_id]);
1605 if(empty($objME)) {
1606 redirect('/'.$this->load->_get_this_controller_slug().'/mass_message/');
1607 }
1608
1609 $this->data['edit_me'] = $objME;
1610 }
1611
1612 // del message if asked
1613 $message_id = (int)trim($this->input->get('del_message'));
1614 if($message_id > 0) {
1615 $this->Blog_posts_model->delete(['id' => $message_id]);
1616 redirect('/'.$this->load->_get_this_controller_slug().'/mass_message/');
1617 }
1618
1619 // del all drafts if asked
1620 $ask_delete = (int)trim($this->input->get('del_all_drafts'));
1621 if($ask_delete > 0) {
1622 $this->Blog_posts_model->delete(['is_draft' => 1]);
1623 redirect('/'.$this->load->_get_this_controller_slug().'/mass_message/');
1624 }
1625
1626 $email_from_email = $this->Options_model->get_option('email_from_email');
1627 $email_from_name = $this->Options_model->get_option('email_from_name');
1628 $this->data['email_from_email'] = empty($email_from_email) ? "support@{$_SERVER['HTTP_HOST']}" : $email_from_email;
1629 $this->data['email_from_name'] = empty($email_from_name) ? 'Admin' : $email_from_name;
1630
1631 // set db query condition if search string sent
1632 $condition = null;
1633 $this->data['search'] = null;
1634 $search = trim($this->input->get('search'));
1635 if(!empty($search)) {
1636 $search_int = (int)$search;
1637
1638 if(($search_int > 0) or ($search === '0')) {
1639 $condition = "`id`={$search_int}";
1640 $this->data['search'] = $search_int;
1641 } elseif(!empty($search)) {
1642 $search_str = $this->db->escape($search);
1643 $search_str = substr($search_str, 0, 1).'%'.substr($search_str, 1, -1).'%'.substr($search_str, -1);
1644 $condition = "`subject` LIKE {$search_str} OR `message` LIKE {$search_str}";
1645 $this->data['search'] = $search;
1646 }
1647 }
1648
1649
1650 // send mass email if asked
1651 if($this->input->post('action') == 'mass_message') {
1652 $edit_message = (int)trim($this->input->get('edit_message'));
1653
1654 $mass_subject = (string)trim($this->input->post('mass_subject'));
1655 $mass_message = (string)trim($this->input->post('mass_message'));
1656
1657 $err_msg = '';
1658
1659 if(empty($mass_subject)) {
1660 $err_msg .= "<br>You should set the Subject!";
1661 }
1662 if(empty($mass_message)) {
1663 $err_msg .= "<br>You should set the Message!";
1664 }
1665
1666 if(empty($err_msg)) {
1667 // send mass message
1668
1669 $should_insert = true;
1670 if($edit_message > 0) {
1671 $objME = $this->Blog_posts_model->get_one(['id' => $edit_message, 'is_draft' => 1]);
1672 if(!empty($objME) and ($objME['subject'] == $mass_subject) and ($objME['message'] == $mass_message)) {
1673 $should_insert = false;
1674 }
1675 }
1676 if($should_insert) {
1677 $edit_message = $this->Blog_posts_model->insert([
1678 'subject' => $mass_subject,
1679 'message' => $mass_message,
1680 'is_draft' => 0,
1681 ]);
1682 } else {
1683 $this->Blog_posts_model->update_by_id([
1684 'id' => $edit_message,
1685 'is_draft' => 0,
1686 ]);
1687 }
1688
1689 // send notification email to all registered users
1690 $user_ids = $this->User_model->get(['is_confirmed' => 1, 'is_banned' => 0], null, 'id');
1691 $this->_send_notification_emails($user_ids, 'id', 'inbox');
1692
1693 /*
1694 $from_user_id = $this->Options_model->get_option('support_user_id');
1695
1696 $message = "<h1>{$mass_subject}</h1>{$mass_message}";
1697
1698 foreach($retU as $objU) {
1699 $this->_add_message($from_user_id, $objU['id'], $message);
1700 }
1701 */
1702
1703 } else {
1704 $this->data['err_msg'] = $err_msg;
1705 }
1706 }
1707
1708
1709 $this->db->select('SQL_CALC_FOUND_ROWS *', false);
1710 $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']);
1711
1712 // pagination
1713 $query = $this->db->query('SELECT FOUND_ROWS() AS records');
1714 $row = $query->row();
1715
1716 $base_url = base_url($this->load->_get_this_controller_slug().'/'.__FUNCTION__);
1717
1718 $this->data['pagination'] = $this->_get_pagination_html($base_url, $row->records, ['reuse_query_string' => false]);
1719
1720
1721 //get options
1722 $this->data['dgold_inc_arr'] = $this->Options_model->get_option('dgold_inc_arr');
1723 $this->data['dgold_price_arr'] = $this->Options_model->get_option('dgold_price_arr');
1724 $this->data['dgold_total_rewarded'] = $this->Options_model->get_option('dgold_total_rewarded');
1725 $this->data['dgold_total_sold_value'] = $this->Options_model->get_option('dgold_total_sold_value');
1726
1727 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
1728
1729 $this->load->view2('admin_mass_message', $this->data);
1730 }
1731
1732 public function mass_email($page = 0)
1733 {
1734 $this->_check_admin();
1735
1736 $page = ((int)$page - 1);
1737 $page = ($page > 0) ? $page : 0;
1738
1739 $allowed_groups = [
1740 'test_mail' => '',
1741 'verified_users' => ['is_confirmed' => 1],
1742 'unverified_users' => ['is_confirmed' => 0],
1743 'have_active_mining_package' => ['is_confirmed' => 1],
1744 'registered_last_7_days' => 'is_confirmed=1 AND created_at>"' . date('Y-m-d H:i:s', time() - 7 * 86400) . '"',
1745 ];
1746
1747 $this->load->model('Mass_email_model');
1748
1749 // save as draft if asked
1750 if($this->input->post('action') == 'save_as_draft') {
1751 $edit_email = (int)trim($this->input->get('edit_email'));
1752
1753 $user_group = (string)trim($this->input->post('user_group'));
1754 $mass_subject = (string)trim($this->input->post('mass_subject'));
1755 $mass_message = (string)trim($this->input->post('mass_message'));
1756
1757 if(!isset($allowed_groups[$user_group])) {
1758 redirect('/' . $this->load->_get_this_controller_slug() . '/mass_email/');
1759 }
1760
1761 if($edit_email > 0) {
1762 $objME = $this->Mass_email_model->get_one(['id' => $edit_email, 'is_draft' => 1]);
1763 if(!empty($objME) and ($objME['user_group'] == $user_group) and ($objME['subject'] == $mass_subject) and ($objME['message'] == $mass_message)) {
1764 redirect('/'.$this->load->_get_this_controller_slug()."/mass_email/?edit_email={$edit_email}#new_edit");
1765 }
1766 }
1767
1768 $edit_email = $this->Mass_email_model->insert([
1769 'user_group' => $user_group,
1770 'subject' => $mass_subject,
1771 'message' => $mass_message,
1772 'is_draft' => 1,
1773 ]);
1774 redirect('/'.$this->load->_get_this_controller_slug()."/mass_email/?edit_email={$edit_email}#new_edit");
1775 }
1776
1777 // edit email if asked
1778 $email_id = (int)trim($this->input->get('edit_email'));
1779 if($email_id > 0) {
1780 $objME = $this->Mass_email_model->get_one(['id' => $email_id]);
1781 if(empty($objME)) {
1782 redirect('/'.$this->load->_get_this_controller_slug().'/mass_email/');
1783 }
1784
1785 $this->data['edit_me'] = $objME;
1786 }
1787
1788 // del email if asked
1789 $email_id = (int)trim($this->input->get('del_email'));
1790 if($email_id > 0) {
1791 $this->Mass_email_model->delete(['id' => $email_id]);
1792 redirect('/'.$this->load->_get_this_controller_slug().'/mass_email/');
1793 }
1794
1795 // del all drafts if asked
1796 $ask_delete = (int)trim($this->input->get('del_all_drafts'));
1797 if($ask_delete > 0) {
1798 $this->Mass_email_model->delete(['is_draft' => 1]);
1799 redirect('/'.$this->load->_get_this_controller_slug().'/mass_email/');
1800 }
1801
1802 $email_from_email = $this->Options_model->get_option('email_from_email');
1803 $email_from_name = $this->Options_model->get_option('email_from_name');
1804 $this->data['email_from_email'] = empty($email_from_email) ? "support@{$_SERVER['HTTP_HOST']}" : $email_from_email;
1805 $this->data['email_from_name'] = empty($email_from_name) ? 'Admin' : $email_from_name;
1806
1807 // set db query condition if search string sent
1808 $condition = null;
1809 $this->data['search'] = null;
1810 $search = trim($this->input->get('search'));
1811 if(!empty($search)) {
1812 $search_int = (int)$search;
1813
1814 if(($search_int > 0) or ($search === '0')) {
1815 $condition = "`id`={$search_int}";
1816 $this->data['search'] = $search_int;
1817 } elseif(!empty($search)) {
1818 $search_str = $this->db->escape($search);
1819 $search_str = substr($search_str, 0, 1).'%'.substr($search_str, 1, -1).'%'.substr($search_str, -1);
1820 $condition = "`user_group` LIKE {$search_str} OR `subject` LIKE {$search_str} OR `message` LIKE {$search_str}";
1821 $this->data['search'] = $search;
1822 }
1823 }
1824
1825
1826 // send mass email if asked
1827 if($this->input->post('action') == 'mass_email') {
1828 $edit_email = (int)trim($this->input->get('edit_email'));
1829
1830 $user_group = (string)trim($this->input->post('user_group'));
1831 $mass_subject = (string)trim($this->input->post('mass_subject'));
1832 $mass_message = (string)trim($this->input->post('mass_message'));
1833
1834 $err_msg = '';
1835
1836 if(!isset($allowed_groups[$user_group])) {
1837 $err_msg .= "<br>Selected Group of Users is not allowed!";
1838 } else {
1839 if($user_group == 'test_mail') {
1840 $emails = explode("\r\n", $this->Options_model->get_option('massmail_test_email'));
1841 $retU = [];
1842 foreach($emails as $email) {
1843 $email = trim($email);
1844 if(empty($email))
1845 continue;
1846
1847 $retU[] = [
1848 'username' => 'Tester',
1849 'name' => '',
1850 'surname' => '',
1851 'email' => $email,
1852 ];
1853 }
1854 } else {
1855 if ($user_group == 'have_active_mining_package') {
1856 $this->db->distinct();
1857 $this->db->join('packages', 'user.id = packages.user_id');
1858 }
1859 $retU = $this->User_model->get($allowed_groups[$user_group], null, 'user.id, user.username, user.email, user.name, user.surname');
1860 }
1861 }
1862
1863 if(empty($mass_subject)) {
1864 $err_msg .= "<br>You should set the Subject!";
1865 }
1866 if(empty($mass_message)) {
1867 $err_msg .= "<br>You should set the Message!";
1868 }
1869 if(empty($retU)) {
1870 $err_msg .= "<br>No any users in this criteria found!";
1871 }
1872
1873 if(empty($err_msg)) {
1874 // Save this email copy to Inbox if asked
1875 if(!empty($this->input->post('save_to_inbox'))) {
1876 $this->load->model('Blog_posts_model');
1877
1878 $this->Blog_posts_model->insert([
1879 'subject' => $mass_subject,
1880 'message' => $mass_message,
1881 'is_draft' => 0,
1882 'is_company_email' => 1,
1883 ]);
1884 }
1885
1886 // send mass email
1887 $sendgrid_api_key = $this->Options_model->get_option('sendgrid_api_key');
1888
1889 $tos = [];
1890 foreach($retU as $objU) {
1891 $tos[$objU['email']] = $this->User_model->get_user_name($objU);
1892 }
1893
1894 $tos_chunked = array_chunk($tos, 99, true);
1895
1896 $should_insert = true;
1897 if($edit_email > 0) {
1898 $objME = $this->Mass_email_model->get_one(['id' => $edit_email, 'is_draft' => 1]);
1899 if(!empty($objME) and ($objME['user_group'] == $user_group) and ($objME['subject'] == $mass_subject) and ($objME['message'] == $mass_message)) {
1900 $should_insert = false;
1901 }
1902 }
1903 if($should_insert) {
1904 $edit_email = $this->Mass_email_model->insert([
1905 'user_group' => $user_group,
1906 'subject' => $mass_subject,
1907 'message' => $mass_message,
1908 'should_emails' => serialize($tos),
1909 'sent_emails' => serialize([]),
1910 'is_draft' => 0,
1911 ]);
1912 } else {
1913 $this->Mass_email_model->update_by_id([
1914 'id' => $edit_email,
1915 'should_emails' => serialize($tos),
1916 'sent_emails' => serialize([]),
1917 'is_draft' => 0,
1918 ]);
1919 }
1920
1921 $sent_emails = [];
1922
1923 foreach($tos_chunked as $tos_chunk) {
1924 $sendgrid_from = new \SendGrid\Mail\From($this->data['email_from_email'], $this->data['email_from_name']);
1925
1926 $sendgrid_tos = [];
1927 foreach($tos_chunk as $tos_email => $tos_name) {
1928 $sendgrid_tos[] = new \SendGrid\Mail\To($tos_email, $tos_name);
1929 }
1930
1931 $sendgrid_subject = new \SendGrid\Mail\Subject($mass_subject);
1932
1933 $plainTextContent = new \SendGrid\Mail\PlainTextContent('');
1934 $htmlContent = new \SendGrid\Mail\HtmlContent($mass_message);
1935
1936 $email = new \SendGrid\Mail\Mail(
1937 $sendgrid_from,
1938 $sendgrid_tos,
1939 $sendgrid_subject,
1940 $plainTextContent,
1941 $htmlContent
1942 );
1943
1944 $sendgrid = new \SendGrid($sendgrid_api_key);
1945 try {
1946 $response = $sendgrid->send($email);
1947
1948 $status = $response->statusCode();
1949 if(($status == 200) or ($status == 202)) {
1950 $sent_emails = array_merge($sent_emails, $tos_chunk);
1951 $this->Mass_email_model->update_by_id([
1952 'id' => $edit_email,
1953 'should_emails' => serialize(array_diff_assoc($tos, $sent_emails)),
1954 'sent_emails' => serialize($sent_emails),
1955 ]);
1956 }
1957
1958 log_message('error', 'Sendgrid-' . $user_group . '-ok_response-' . $status . '-' . serialize($response->headers()) . '-' . serialize($response->body()));
1959 } catch (Exception $e) {
1960 log_message('error', 'Sendgrid-' . $user_group . '-exception-' . $e->getMessage());
1961 }
1962 }
1963
1964
1965 /*
1966 foreach($tos_chunked as $tos_chunk) {
1967 $email = new \SendGrid\Mail\Mail();
1968
1969 $email->setFrom($this->data['email_from_email'], $this->data['email_from_name']);
1970
1971 $email->addTos($tos_chunk);
1972
1973 $email->setSubject($mass_subject);
1974
1975 //$email->addContent("text/plain", "and easy to do anywhere, even with PHP");
1976 $email->addContent("text/html", $mass_message);
1977
1978 $sendgrid = new \SendGrid($sendgrid_api_key);
1979 try {
1980 $response = $sendgrid->send($email);
1981
1982 $status = $response->statusCode();
1983 if(($status == 200) or ($status == 202)) {
1984 $sent_emails = array_merge($sent_emails, $tos_chunk);
1985 $this->Mass_email_model->update_by_id([
1986 'id' => $edit_email,
1987 'should_emails' => serialize(array_diff_assoc($tos, $sent_emails)),
1988 'sent_emails' => serialize($sent_emails),
1989 ]);
1990 }
1991
1992 log_message('error', 'Sendgrid-' . $user_group . '-ok_response-' . $status . '-' . serialize($response->headers()) . '-' . serialize($response->body()));
1993 } catch (Exception $e) {
1994 log_message('error', 'Sendgrid-' . $user_group . '-exception-' . $e->getMessage());
1995 }
1996 }
1997 */
1998
1999 } else {
2000 $this->data['err_msg'] = $err_msg;
2001 }
2002 }
2003
2004
2005 $this->db->select('SQL_CALC_FOUND_ROWS *', false);
2006 $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']);
2007
2008 // pagination
2009 $query = $this->db->query('SELECT FOUND_ROWS() AS records');
2010 $row = $query->row();
2011
2012 $base_url = base_url($this->load->_get_this_controller_slug().'/'.__FUNCTION__);
2013
2014 $this->data['pagination'] = $this->_get_pagination_html($base_url, $row->records, ['reuse_query_string' => false]);
2015 //echo $base_url;print_r($this->data['pagination']);die;
2016
2017
2018 //get options
2019 $this->data['dgold_inc_arr'] = $this->Options_model->get_option('dgold_inc_arr');
2020 $this->data['dgold_price_arr'] = $this->Options_model->get_option('dgold_price_arr');
2021 $this->data['dgold_total_rewarded'] = $this->Options_model->get_option('dgold_total_rewarded');
2022 $this->data['dgold_total_sold_value'] = $this->Options_model->get_option('dgold_total_sold_value');
2023
2024 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
2025
2026 $this->load->view2('admin_mass_email', $this->data);
2027 }
2028
2029 public function dgold_tables()
2030 {
2031 $this->_check_admin();
2032
2033 // change referral reward table if asked
2034 if($this->input->post('action') == 'table_options') {
2035 $rows_per_page = (int)trim($this->input->post('rows_per_page'));
2036 $pagination_num_links = (int)trim($this->input->post('pagination_num_links'));
2037
2038 if($rows_per_page > 0) {
2039 $this->Options_model->set_option('rows_per_page', $rows_per_page);
2040 }
2041 if($pagination_num_links >= 0) {
2042 $this->Options_model->set_option('pagination_num_links', $pagination_num_links);
2043 }
2044 }
2045
2046 // change referral reward table if asked
2047 if($this->input->post('action') == 'dgold_prices') {
2048 //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";}
2049 $is_err = false;
2050 try {
2051 $dgold_price_arr = array();
2052 for($i = 1; $i <= 10; $i++) {
2053 $pp = (double)trim($this->input->post("pp{$i}"));
2054 $cs = BigInteger::of(trim($this->input->post("cs{$i}")));
2055
2056 if(($pp > 0) and ($cs->compareTo(0) == 1)) {
2057 $dgold_price_arr[(string)$cs] = number_format($pp, 3, '.', '');
2058 } else {
2059 $is_err = true;
2060 }
2061 }
2062 } catch(Exception $e) {
2063 // do nothing
2064 }
2065
2066 if(!$is_err and (count($dgold_price_arr) == 10)) {
2067 $this->Options_model->set_option('dgold_price_arr', $dgold_price_arr);
2068 }
2069 }
2070
2071 // recalculate values button
2072 if($this->input->post('action') == 'recalculate') {
2073 $this->load->model('Ticket_model');
2074
2075 $sum = $this->Ticket_model->get(array('is_paid' => 1), null, 'sum(`amount_usd`) a_usd, sum(`amount_dgold`) a_dgold');
2076
2077 $this->Options_model->set_option('dgold_total_sold_value', $sum[0]['a_usd']);
2078 $this->Options_model->set_option('dgold_total_sold', 0);
2079 $this->Options_model->inc_option('dgold_total_sold', $sum[0]['a_dgold']);
2080 }
2081
2082 // change referral reward table if asked
2083 if($this->input->post('action') == 'registration_reward') {
2084 $reg = (int)trim($this->input->post('reg'));
2085 $lvl1 = (int)trim($this->input->post('lvl1'));
2086 $lvl2 = (int)trim($this->input->post('lvl2'));
2087 $lvl3 = (int)trim($this->input->post('lvl3'));
2088 $lvl4 = (int)trim($this->input->post('lvl4'));
2089 $lvl5 = (int)trim($this->input->post('lvl5'));
2090 $purchase_reward = (int)trim($this->input->post('purchase_reward'));
2091 $mining_reward_lvl1 = (int)trim($this->input->post('mining_reward_lvl1'));
2092 $mining_reward_lvl2 = (int)trim($this->input->post('mining_reward_lvl2'));
2093
2094 if (($reg >= 0) and ($lvl1 >= 0) and ($lvl2 >= 0) and ($lvl3 >= 0) and ($lvl4 >= 0) and ($lvl5 >= 0)) {
2095 $this->Options_model->set_option('dgold_inc_arr', [$reg, $lvl1, $lvl2, $lvl3, $lvl4, $lvl5]);
2096 }
2097 if($purchase_reward >= 0) {
2098 $this->Options_model->set_option('dgold_purchase_reward', $purchase_reward);
2099 }
2100 if(($mining_reward_lvl1 >= 0) and ($mining_reward_lvl2 >= 0)) {
2101 $this->Options_model->set_option('dgold_mining_reward_lvl1', $mining_reward_lvl1);
2102 $this->Options_model->set_option('dgold_mining_reward_lvl2', $mining_reward_lvl2);
2103 }
2104 }
2105
2106 //get options
2107 $this->data['pagination_num_links'] = $this->Options_model->get_option('pagination_num_links');
2108
2109 $this->data['dgold_inc_arr'] = $this->Options_model->get_option('dgold_inc_arr');
2110 $this->data['purchase_reward'] = $this->Options_model->get_option('dgold_purchase_reward');
2111 $this->data['mining_reward_lvl1'] = $this->Options_model->get_option('dgold_mining_reward_lvl1');
2112 $this->data['mining_reward_lvl2'] = $this->Options_model->get_option('dgold_mining_reward_lvl2');
2113
2114 $this->data['dgold_price_arr'] = $this->Options_model->get_option('dgold_price_arr');
2115 $this->data['dgold_total_rewarded'] = $this->Options_model->get_option('dgold_total_rewarded');
2116 $this->data['dgold_total_sold_value'] = $this->Options_model->get_option('dgold_total_sold_value');
2117
2118 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
2119
2120 $this->load->view2('admin_dgold_tables', $this->data);
2121 }
2122
2123 public function invoices_usd($page = 0)
2124 {
2125 $this->_check_admin();
2126
2127 $page = ((int)$page - 1);
2128 $page = ($page > 0) ? $page : 0;
2129
2130 $this->load->model('Money_model');
2131
2132 // del package_setup if asked
2133 $invoice_id = (int)trim($this->input->get('del_invoice'));
2134 if($invoice_id > 0) {
2135 $this->Money_model->delete(['id' => $invoice_id]);
2136 redirect('/'.$this->load->_get_this_controller_slug().'/invoices_usd/');
2137 }
2138
2139 // set db query condition if search string sent
2140 $condition = null;
2141 $this->data['search'] = null;
2142 if($this->input->post('action') == 'search') {
2143 $search = trim($this->input->post('search'));
2144 $search_int = (int)$search;
2145
2146 if(($search_int > 0) or ($search === '0')) {
2147 $condition = "money.id={$search_int} OR `user_id`={$search_int} OR `amount_usd`={$search_int}";
2148 $this->data['search'] = $search_int;
2149 } elseif(!empty($search)) {
2150 $search_str = $this->db->escape($search);
2151 $search_str = substr($search_str, 0, 1).'%'.substr($search_str, 1, -1).'%'.substr($search_str, -1);
2152 $condition = "user.email LIKE {$search_str} OR merchant LIKE {$search_str}";
2153 $this->data['search'] = $search;
2154 }
2155 }
2156
2157 //get options
2158 $this->data['dgold_inc_arr'] = $this->Options_model->get_option('dgold_inc_arr');
2159 $this->data['dgold_price_arr'] = $this->Options_model->get_option('dgold_price_arr');
2160 $this->data['dgold_total_rewarded'] = $this->Options_model->get_option('dgold_total_rewarded');
2161 $this->data['dgold_total_sold_value'] = $this->Options_model->get_option('dgold_total_sold_value');
2162
2163
2164 $this->db->join('user', 'user.id = money.user_id');
2165 $this->db->select('SQL_CALC_FOUND_ROWS *', false);
2166 $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']);
2167
2168 // pagination
2169 $query = $this->db->query('SELECT FOUND_ROWS() AS records');
2170 $row = $query->row();
2171
2172 $base_url = base_url($this->load->_get_this_controller_slug().'/'.__FUNCTION__);
2173
2174 $this->data['pagination'] = $this->_get_pagination_html($base_url, $row->records);
2175
2176
2177 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
2178
2179 $this->load->view2('admin_invoices_usd', $this->data);
2180 }
2181public function videos()
2182 {
2183 $this->_check_login();
2184
2185 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
2186
2187
2188 $this->load->view2('videos', $this->data);
2189 }
2190 public function invoices_dgold($page = 0)
2191 {
2192 $this->_check_admin();
2193
2194 $page = ((int)$page - 1);
2195 $page = ($page > 0) ? $page : 0;
2196
2197 $this->load->model('Ticket_model');
2198
2199 // del package_setup if asked
2200 $invoice_id = (int)trim($this->input->get('del_invoice'));
2201 if($invoice_id > 0) {
2202 $this->Ticket_model->delete(['id' => $invoice_id]);
2203 redirect('/'.$this->load->_get_this_controller_slug().'/invoices_dgold/');
2204 }
2205
2206 // set db query condition if search string sent
2207 $condition = null;
2208 $this->data['search'] = null;
2209 if($this->input->post('action') == 'search') {
2210 $search = trim($this->input->post('search'));
2211 $search_int = (int)$search;
2212
2213 if(($search_int > 0) or ($search === '0')) {
2214 $condition = "ticket.id={$search_int} OR `user_id`={$search_int} OR `amount_usd`={$search_int} OR `amount_dgold`={$search_int}";
2215 $this->data['search'] = $search_int;
2216 } elseif(!empty($search)) {
2217 $search_str = $this->db->escape($search);
2218 $search_str = substr($search_str, 0, 1).'%'.substr($search_str, 1, -1).'%'.substr($search_str, -1);
2219 $condition = "user.email LIKE {$search_str} OR merchant LIKE {$search_str}";
2220 $this->data['search'] = $search;
2221 }
2222 }
2223
2224 //get options
2225 $this->data['dgold_inc_arr'] = $this->Options_model->get_option('dgold_inc_arr');
2226 $this->data['dgold_price_arr'] = $this->Options_model->get_option('dgold_price_arr');
2227 $this->data['dgold_total_rewarded'] = $this->Options_model->get_option('dgold_total_rewarded');
2228 $this->data['dgold_total_sold_value'] = $this->Options_model->get_option('dgold_total_sold_value');
2229
2230
2231 $this->db->join('user', 'user.id = ticket.user_id');
2232 $this->db->select('SQL_CALC_FOUND_ROWS *', false);
2233 $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']);
2234
2235 // pagination
2236 $query = $this->db->query('SELECT FOUND_ROWS() AS records');
2237 $row = $query->row();
2238
2239 $base_url = base_url($this->load->_get_this_controller_slug().'/'.__FUNCTION__);
2240
2241 $this->data['pagination'] = $this->_get_pagination_html($base_url, $row->records);
2242
2243
2244 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
2245
2246 $this->load->view2('admin_invoices_dgold', $this->data);
2247 }
2248
2249 public function docs($page = 0)
2250 {
2251 $this->_check_admin();
2252
2253 $page = ((int)$page - 1);
2254 $page = ($page > 0) ? $page : 0;
2255
2256 $this->load->model('Docs_model');
2257
2258 // del doc if asked
2259 $doc_id = (int)trim($this->input->get('del_doc'));
2260 if($doc_id > 0) {
2261 $this->Docs_model->delete(['id' => $doc_id]);
2262 redirect('/'.$this->load->_get_this_controller_slug().'/docs/');
2263 }
2264
2265 // change doc if asked
2266 $doc_id = (int)trim($this->input->get('change_id'));
2267 $is_approved = (int)trim($this->input->get('is_approved'));
2268 if(($doc_id > 0) and ($is_approved >= 0)) {
2269 $this->Docs_model->update_by_id([
2270 'id' => $doc_id,
2271 'is_approved' => $is_approved ? 1 : 0,
2272 ]);
2273 redirect('/'.$this->load->_get_this_controller_slug().'/docs/');
2274 }
2275
2276
2277
2278 // set db query condition if search string sent
2279 $condition = null;
2280 $this->data['search'] = null;
2281 if($this->input->post('action') == 'search') {
2282 $search = trim($this->input->post('search'));
2283 $search_int = (int)$search;
2284
2285 if(($search_int > 0) or ($search === '0')) {
2286 $condition = "docs.id={$search_int} OR `user_id`={$search_int}";
2287 $this->data['search'] = $search_int;
2288 } elseif(!empty($search)) {
2289 $search_str = $this->db->escape($search);
2290 $search_str = substr($search_str, 0, 1).'%'.substr($search_str, 1, -1).'%'.substr($search_str, -1);
2291 $condition = "user.email LIKE {$search_str} OR user.username LIKE {$search_str} OR user.name LIKE {$search_str} OR user.surname LIKE {$search_str}";
2292 $this->data['search'] = $search;
2293 }
2294 }
2295
2296 $this->db->join('user', 'user.id = docs.user_id');
2297 $this->db->select('SQL_CALC_FOUND_ROWS *', false);
2298 $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']);
2299
2300 // pagination
2301 $query = $this->db->query('SELECT FOUND_ROWS() AS records');
2302 $row = $query->row();
2303
2304 $base_url = base_url($this->load->_get_this_controller_slug().'/'.__FUNCTION__);
2305
2306 $this->data['pagination'] = $this->_get_pagination_html($base_url, $row->records);
2307
2308
2309 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
2310
2311 $this->load->view2('admin_docs', $this->data);
2312 }
2313
2314 public function packages($page = 0)
2315 {
2316 $this->_check_admin();
2317
2318 $page = ((int)$page - 1);
2319 $page = ($page > 0) ? $page : 0;
2320
2321 // add new package_setup if asked
2322 if($this->input->post('action') == 'add_new_package') {
2323 $all_packages = $this->Packages_setup_model->get();
2324 $cnt = empty($all_packages) ? 0 : count($all_packages);
2325
2326 $this->Packages_setup_model->insert([
2327 'is_active' => 0,
2328 'title' => "New Package Title {$cnt}",
2329 'price' => 0,
2330 'hash_rate' => 0,
2331 'daily_dgolds' => 0,
2332 'show_order' => $cnt,
2333 ]);
2334 redirect('/'.$this->load->_get_this_controller_slug().'/packages/');
2335 }
2336
2337 // del package_setup if asked
2338 $package_id = (int)trim($this->input->get('del_package_setup'));
2339 if($package_id > 0) {
2340 $this->Packages_setup_model->delete(['id' => $package_id]);
2341 redirect('/'.$this->load->_get_this_controller_slug().'/packages/');
2342 }
2343
2344 // change package_setup if asked
2345 $package_id = (int)trim($this->input->get('change_id_setup'));
2346 $is_active = (int)trim($this->input->get('is_active'));
2347 $title = (string)trim($this->input->get('title'));
2348 $price = (string)trim($this->input->get('price'));
2349 $hash_rate = (string)trim($this->input->get('hash_rate'));
2350 $hash_rate_sign = (string)trim($this->input->get('hash_rate_sign'));
2351 $daily_dgolds = (int)trim($this->input->get('daily_dgolds'));
2352 $show_order = (int)trim($this->input->get('show_order'));
2353 if($package_id > 0) {
2354 $this->Packages_setup_model->update_by_id([
2355 'id' => $package_id,
2356 'is_active' => $is_active ? 1 : 0,
2357 'title' => $title,
2358 'price' => $price,
2359 'hash_rate' => $hash_rate,
2360 'hash_rate_sign' => $hash_rate_sign,
2361 'daily_dgolds' => $daily_dgolds,
2362 'show_order' => $show_order,
2363 ]);
2364
2365 $this->load->model('Packages_model');
2366 $this->Packages_model->update(['package_id' => $package_id], [
2367 'daily_dgolds' => $daily_dgolds,
2368 ]);
2369
2370 redirect('/'.$this->load->_get_this_controller_slug().'/packages/');
2371 }
2372
2373 $this->data['all_packages_setup'] = $this->Packages_setup_model->get();
2374
2375
2376 $this->load->model('Packages_model');
2377
2378
2379 // change package if asked
2380 $package_id = (int)trim($this->input->get('change_id'));
2381 $is_active = (int)trim($this->input->get('is_active'));
2382 if($package_id > 0) {
2383 $this->Packages_model->update_by_id([
2384 'id' => $package_id,
2385 'is_active' => $is_active ? 1 : 0,
2386 ]);
2387 redirect('/'.$this->load->_get_this_controller_slug().'/packages/');
2388 }
2389
2390 // set db query condition if search string sent
2391 $condition = null;
2392 $this->data['search'] = null;
2393 if($this->input->post('action') == 'search') {
2394 $search = trim($this->input->post('search'));
2395 $search_int = (int)$search;
2396
2397 if(($search_int > 0) or ($search === '0')) {
2398 $condition = "packages.id={$search_int} OR `user_id`={$search_int}";
2399 $this->data['search'] = $search_int;
2400 } elseif(!empty($search)) {
2401 $search_str = $this->db->escape($search);
2402 $search_str = substr($search_str, 0, 1).'%'.substr($search_str, 1, -1).'%'.substr($search_str, -1);
2403 $condition = "user.email LIKE {$search_str} OR packages.title LIKE {$search_str}";
2404 $this->data['search'] = $search;
2405 }
2406 }
2407
2408 $this->db->join('user', 'user.id = packages.user_id');
2409 $this->db->select('SQL_CALC_FOUND_ROWS *', false);
2410 $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']);
2411
2412 // pagination
2413 $query = $this->db->query('SELECT FOUND_ROWS() AS records');
2414 $row = $query->row();
2415
2416 $base_url = base_url($this->load->_get_this_controller_slug().'/'.__FUNCTION__);
2417
2418 $this->data['pagination'] = $this->_get_pagination_html($base_url, $row->records);
2419
2420
2421 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
2422
2423 $this->load->view2('admin_packages', $this->data);
2424 }
2425
2426 public function payouts_paypal()
2427 {
2428 $this->_check_admin();
2429
2430 $this->load->model('Payout_model');
2431
2432 $payout_id = (int)trim($this->input->get('cancel'));
2433 if($payout_id > 0) {
2434 $this->Payout_model->update_by_id([
2435 'id' => $payout_id,
2436 'is_paid' => 0,
2437 'extra' => '',
2438 ]);
2439 }
2440
2441 $payout_id = (int)trim($this->input->get('done'));
2442 if($payout_id > 0) {
2443 $this->Payout_model->update_by_id([
2444 'id' => $payout_id,
2445 'is_paid' => 1,
2446 'extra' => '',
2447 ]);
2448 }
2449
2450 redirect('/'.$this->load->_get_this_controller_slug().'/payouts/');
2451 }
2452
2453 public function payouts($page = 0)
2454 {
2455 $this->_check_admin();
2456
2457 $page = ((int)$page - 1);
2458 $page = ($page > 0) ? $page : 0;
2459
2460 $this->load->model('Payout_model');
2461
2462 // del payout if asked
2463 $payout_id = (int)trim($this->input->get('del_payout'));
2464 if($payout_id > 0) {
2465 $this->Payout_model->delete_payout($this->data['id'], $payout_id);
2466
2467 redirect('/'.$this->load->_get_this_controller_slug().'/payouts/');
2468 }
2469
2470 // approve payout if asked
2471 $payout_id = (int)trim($this->input->get('pay_now'));
2472 if($payout_id > 0) {
2473 $this->Payout_model->approve_payout($payout_id);
2474
2475 $objP = $this->Payout_model->get_one(['id' => $payout_id, 'is_paid' => 1]);
2476 if(!empty($objP)) {
2477 $objU = $this->User_model->get_one(['id' => $objP['user_id']]);
2478 $this->_send_payout_email($objU, $objP);
2479 }
2480
2481 redirect('/'.$this->load->_get_this_controller_slug().'/payouts/');
2482 }
2483
2484
2485 // set db query condition if search string sent
2486 $condition = null;
2487 $this->data['search'] = null;
2488 if($this->input->post('action') == 'search') {
2489 $search = trim($this->input->post('search'));
2490 $search_int = (int)$search;
2491 $search_double = "{$search}.00";
2492
2493 if(($search_int > 0) or ($search === '0')) {
2494 $condition = "payout.id={$search_int} OR payout.amount_usd={$search_double} OR `user_id`={$search_int}";
2495 $this->data['search'] = $search_int;
2496 } elseif(!empty($search)) {
2497 $search_str = $this->db->escape($search);
2498 $search_str = substr($search_str, 0, 1).'%'.substr($search_str, 1, -1).'%'.substr($search_str, -1);
2499 $condition = "user.email LIKE {$search_str} OR payout.merchant LIKE {$search_str}";
2500 $this->data['search'] = $search;
2501 }
2502 }
2503
2504 $this->db->join('user', 'user.id = payout.user_id');
2505 $this->db->select('SQL_CALC_FOUND_ROWS *', false);
2506 $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']);
2507
2508 // pagination
2509 $query = $this->db->query('SELECT FOUND_ROWS() AS records');
2510 $row = $query->row();
2511
2512 $base_url = base_url($this->load->_get_this_controller_slug().'/'.__FUNCTION__);
2513 $this->data['pagination'] = $this->_get_pagination_html($base_url, $row->records);
2514
2515
2516 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
2517
2518 $this->load->view2('admin_payouts', $this->data);
2519 }
2520
2521 public function merchants()
2522 {
2523 $this->_check_admin();
2524
2525 // change SolidTrustPay config if asked
2526 if($this->input->post('action') == 'solidtrustpay') {
2527 $solidtrustpay_merchantAccount = (string)trim($this->input->post('solidtrustpay_merchantAccount'));
2528 $solidtrustpay_sci_name = (string)trim($this->input->post('solidtrustpay_sci_name'));
2529 $solidtrustpay_sci_password = (string)trim($this->input->post('solidtrustpay_sci_password'));
2530 $solidtrustpay_on = (string)trim($this->input->post('solidtrustpay_on'));
2531
2532 $this->Options_model->set_option('merchant_solidtrustpay_merchantAccount', $solidtrustpay_merchantAccount);
2533 $this->Options_model->set_option('merchant_solidtrustpay_sci_name', $solidtrustpay_sci_name);
2534 $this->Options_model->set_option('merchant_solidtrustpay_sci_password', $solidtrustpay_sci_password);
2535 $this->Options_model->set_option('merchant_solidtrustpay_on', empty($solidtrustpay_on) ? 0 : 1);
2536 }
2537
2538 // change Payeer config if asked
2539 if($this->input->post('action') == 'payeer') {
2540 $payeer_id = (string)trim($this->input->post('payeer_id'));
2541 $payeer_key = (string)trim($this->input->post('payeer_key'));
2542 $payeer_on = (string)trim($this->input->post('payeer_on'));
2543
2544 $this->Options_model->set_option('merchant_payeer_id', $payeer_id);
2545 $this->Options_model->set_option('merchant_payeer_key', $payeer_key);
2546 $this->Options_model->set_option('merchant_payeer_on', empty($payeer_on) ? 0 : 1);
2547 }
2548
2549 // change AdvCash config if asked
2550 if($this->input->post('action') == 'advcash') {
2551 $advcash_email = (string)trim($this->input->post('advcash_email'));
2552 $advcash_sci_name = (string)trim($this->input->post('advcash_sci_name'));
2553 $advcash_secret = (string)trim($this->input->post('advcash_secret'));
2554 $advcash_on = (string)trim($this->input->post('advcash_on'));
2555
2556 $this->Options_model->set_option('merchant_advcash_email', $advcash_email);
2557 $this->Options_model->set_option('merchant_advcash_sci_name', $advcash_sci_name);
2558 $this->Options_model->set_option('merchant_advcash_secret', $advcash_secret);
2559 $this->Options_model->set_option('merchant_advcash_on', empty($advcash_on) ? 0 : 1);
2560 }
2561
2562 // change Cryptonator config if asked
2563 if($this->input->post('action') == 'cryptonator') {
2564 $cryptonator_merchant_id = (string)trim($this->input->post('cryptonator_merchant_id'));
2565 $cryptonator_secret = (string)trim($this->input->post('cryptonator_secret'));
2566 $cryptonator_currency = (array)$this->input->post('cryptonator_currency');
2567 $cryptonator_on = (string)trim($this->input->post('cryptonator_on'));
2568
2569 $this->Options_model->set_option('merchant_cryptonator_merchant_id', $cryptonator_merchant_id);
2570 $this->Options_model->set_option('merchant_cryptonator_secret', $cryptonator_secret);
2571 $this->Options_model->set_option('merchant_cryptonator_currency', $cryptonator_currency);
2572 $this->Options_model->set_option('merchant_cryptonator_on', empty($cryptonator_on) ? 0 : 1);
2573 }
2574
2575 // change BTC config if asked
2576 if($this->input->post('action') == 'btc') {
2577 $btc_xpub = (string)trim($this->input->post('btc_xpub'));
2578 $btc_api_key = (string)trim($this->input->post('btc_api_key'));
2579 $btc_secret = (string)trim($this->input->post('btc_secret'));
2580 $btc_on = (string)trim($this->input->post('btc_on'));
2581
2582 $this->Options_model->set_option('merchant_btc_xpub', $btc_xpub);
2583 $this->Options_model->set_option('merchant_btc_api_key', $btc_api_key);
2584 $this->Options_model->set_option('merchant_btc_secret', $btc_secret);
2585 $this->Options_model->set_option('merchant_btc_on', empty($btc_on) ? 0 : 1);
2586 }
2587
2588 // change CoinBase config if asked
2589 if($this->input->post('action') == 'coinbase') {
2590 $coinbase_api_key = (string)trim($this->input->post('coinbase_api_key'));
2591 $coinbase_webhook_secret = (string)trim($this->input->post('coinbase_webhook_secret'));
2592 $coinbase_on = (string)trim($this->input->post('coinbase_on'));
2593
2594 $this->Options_model->set_option('merchant_coinbase_api_key', $coinbase_api_key);
2595 $this->Options_model->set_option('merchant_coinbase_webhook_secret', $coinbase_webhook_secret);
2596 $this->Options_model->set_option('merchant_coinbase_on', empty($coinbase_on) ? 0 : 1);
2597 }
2598
2599 // change PayPal config if asked
2600 if($this->input->post('action') == 'paypal') {
2601 $paypal_email = (string)trim($this->input->post('paypal_email'));
2602 $paypal_sandbox_mode = (string)trim($this->input->post('paypal_sandbox_mode'));
2603 $paypal_on = (string)trim($this->input->post('paypal_on'));
2604
2605 $this->Options_model->set_option('merchant_paypal_email', $paypal_email);
2606 $this->Options_model->set_option('merchant_paypal_sandbox_mode', empty($paypal_sandbox_mode) ? 0 : 1);
2607 $this->Options_model->set_option('merchant_paypal_on', empty($paypal_on) ? 0 : 1);
2608 }
2609 if($this->input->post('action') == 'paypal_payout') {
2610 $paypal_payout_username = (string)trim($this->input->post('paypal_payout_username'));
2611 $paypal_payout_password = (string)trim($this->input->post('paypal_payout_password'));
2612 $paypal_payout_signature = (string)trim($this->input->post('paypal_payout_signature'));
2613 $paypal_payout_appid = (string)trim($this->input->post('paypal_payout_appid'));
2614 $paypal_payout_sandbox_mode = (string)trim($this->input->post('paypal_payout_sandbox_mode'));
2615 $paypal_payout_on = (string)trim($this->input->post('paypal_payout_on'));
2616
2617 $this->Options_model->set_option('merchant_paypal_payout_username', $paypal_payout_username);
2618 $this->Options_model->set_option('merchant_paypal_payout_password', $paypal_payout_password);
2619 $this->Options_model->set_option('merchant_paypal_payout_signature', $paypal_payout_signature);
2620 $this->Options_model->set_option('merchant_paypal_payout_appid', $paypal_payout_appid);
2621 $this->Options_model->set_option('merchant_paypal_payout_sandbox_mode', empty($paypal_payout_sandbox_mode) ? 0 : 1);
2622 $this->Options_model->set_option('merchant_paypal_payout_on', empty($paypal_payout_on) ? 0 : 1);
2623 }
2624
2625 // get options
2626 $this->data['dgold_inc_arr'] = $this->Options_model->get_option('dgold_inc_arr');
2627 $this->data['dgold_price_arr'] = $this->Options_model->get_option('dgold_price_arr');
2628 $this->data['dgold_total_rewarded'] = $this->Options_model->get_option('dgold_total_rewarded');
2629 $this->data['dgold_total_sold_value'] = $this->Options_model->get_option('dgold_total_sold_value');
2630
2631 // get merchants options
2632 $this->data['solidtrustpay_merchantAccount'] = $this->Options_model->get_option('merchant_solidtrustpay_merchantAccount');
2633 $this->data['solidtrustpay_sci_name'] = $this->Options_model->get_option('merchant_solidtrustpay_sci_name');
2634 $this->data['solidtrustpay_sci_password'] = $this->Options_model->get_option('merchant_solidtrustpay_sci_password');
2635 $this->data['solidtrustpay_on'] = $this->Options_model->get_option('merchant_solidtrustpay_on');
2636
2637 $this->data['payeer_id'] = $this->Options_model->get_option('merchant_payeer_id');
2638 $this->data['payeer_key'] = $this->Options_model->get_option('merchant_payeer_key');
2639 $this->data['payeer_on'] = $this->Options_model->get_option('merchant_payeer_on');
2640
2641 $this->data['advcash_email'] = $this->Options_model->get_option('merchant_advcash_email');
2642 $this->data['advcash_sci_name'] = $this->Options_model->get_option('merchant_advcash_sci_name');
2643 $this->data['advcash_secret'] = $this->Options_model->get_option('merchant_advcash_secret');
2644 $this->data['advcash_on'] = $this->Options_model->get_option('merchant_advcash_on');
2645
2646 $this->data['cryptonator_merchant_id'] = $this->Options_model->get_option('merchant_cryptonator_merchant_id');
2647 $this->data['cryptonator_secret'] = $this->Options_model->get_option('merchant_cryptonator_secret');
2648 $this->data['cryptonator_currency'] = $this->Options_model->get_option('merchant_cryptonator_currency');
2649 $this->data['cryptonator_on'] = $this->Options_model->get_option('merchant_cryptonator_on');
2650
2651 $this->data['btc_xpub'] = $this->Options_model->get_option('merchant_btc_xpub');
2652 $this->data['btc_api_key'] = $this->Options_model->get_option('merchant_btc_api_key');
2653 $this->data['btc_secret'] = $this->Options_model->get_option('merchant_btc_secret');
2654 $this->data['btc_on'] = $this->Options_model->get_option('merchant_btc_on');
2655
2656 $this->data['coinbase_api_key'] = $this->Options_model->get_option('merchant_coinbase_api_key');
2657 $this->data['coinbase_webhook_secret'] = $this->Options_model->get_option('merchant_coinbase_webhook_secret');
2658 $this->data['coinbase_on'] = $this->Options_model->get_option('merchant_coinbase_on');
2659
2660 $this->data['paypal_email'] = $this->Options_model->get_option('merchant_paypal_email');
2661 $this->data['paypal_sandbox_mode'] = $this->Options_model->get_option('merchant_paypal_sandbox_mode');
2662 $this->data['paypal_on'] = $this->Options_model->get_option('merchant_paypal_on');
2663
2664 $this->data['paypal_payout_username'] = $this->Options_model->get_option('merchant_paypal_payout_username');
2665 $this->data['paypal_payout_password'] = $this->Options_model->get_option('merchant_paypal_payout_password');
2666 $this->data['paypal_payout_signature'] = $this->Options_model->get_option('merchant_paypal_payout_signature');
2667 $this->data['paypal_payout_appid'] = $this->Options_model->get_option('merchant_paypal_payout_appid');
2668 $this->data['paypal_payout_sandbox_mode'] = $this->Options_model->get_option('merchant_paypal_payout_sandbox_mode');
2669 $this->data['paypal_payout_on'] = $this->Options_model->get_option('merchant_paypal_payout_on');
2670
2671
2672 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
2673
2674 $this->load->view2('admin_merchants', $this->data);
2675 }
2676
2677 public function email_settings()
2678 {
2679 $this->_check_admin();
2680
2681 // change email config if asked
2682 if($this->input->post('action') == 'email_config') {
2683 $from_email = (string)trim($this->input->post('from_email'));
2684 $from_name = (string)trim($this->input->post('from_name'));
2685
2686 $this->Options_model->set_option('email_from_email', $from_email);
2687 $this->Options_model->set_option('email_from_name', $from_name);
2688 }
2689
2690 // change SMTP config if asked
2691 if($this->input->post('action') == 'smtp_config') {
2692 $smtp_host = (string)trim($this->input->post('smtp_host'));
2693 $smtp_port = (string)trim($this->input->post('smtp_port'));
2694 $smtp_security = (string)trim($this->input->post('smtp_security'));
2695 $smtp_username = (string)trim($this->input->post('smtp_username'));
2696 $smtp_password = (string)trim($this->input->post('smtp_password'));
2697 $smtp_on = (string)trim($this->input->post('smtp_on'));
2698
2699 $this->Options_model->set_option('email_smtp_host', $smtp_host);
2700 $this->Options_model->set_option('email_smtp_port', $smtp_port);
2701 $this->Options_model->set_option('email_smtp_security', $smtp_security);
2702 $this->Options_model->set_option('email_smtp_username', $smtp_username);
2703 $this->Options_model->set_option('email_smtp_password', $smtp_password);
2704 $this->Options_model->set_option('email_smtp_on', empty($smtp_on) ? 0 : 1);
2705 }
2706
2707 // save sendgrid options if asked
2708 if($this->input->post('action') == 'sendgrid_config') {
2709 $sendgrid_api_key = (string)trim($this->input->post('sendgrid_api_key'));
2710 $massmail_test_email = (string)trim($this->input->post('massmail_test_email'));
2711
2712 $email_arr = explode(' ', str_replace(["\r", "\n", "\t", ','], ' ', $massmail_test_email));
2713 $emails = [];
2714 if(!empty($email_arr)) {
2715 foreach($email_arr as $email) {
2716 $email = trim($email);
2717 if(empty($email))
2718 continue;
2719
2720 $emails[] = $email;
2721 }
2722 $emails = implode("\r\n", $emails);
2723 } else {
2724 $emails = '';
2725 }
2726
2727 $this->Options_model->set_option('sendgrid_api_key', $sendgrid_api_key);
2728 $this->Options_model->set_option('massmail_test_email', $emails);
2729 }
2730
2731 // get options
2732 $this->data['dgold_inc_arr'] = $this->Options_model->get_option('dgold_inc_arr');
2733 $this->data['dgold_price_arr'] = $this->Options_model->get_option('dgold_price_arr');
2734 $this->data['dgold_total_rewarded'] = $this->Options_model->get_option('dgold_total_rewarded');
2735 $this->data['dgold_total_sold_value'] = $this->Options_model->get_option('dgold_total_sold_value');
2736
2737 // get email options
2738 $this->data['from_email'] = $this->Options_model->get_option('email_from_email');
2739 $this->data['from_name'] = $this->Options_model->get_option('email_from_name');
2740
2741 // get smtp options
2742 $this->data['smtp_host'] = $this->Options_model->get_option('email_smtp_host');
2743 $this->data['smtp_port'] = $this->Options_model->get_option('email_smtp_port');
2744 $this->data['smtp_security'] = $this->Options_model->get_option('email_smtp_security');
2745 $this->data['smtp_username'] = $this->Options_model->get_option('email_smtp_username');
2746 $this->data['smtp_password'] = $this->Options_model->get_option('email_smtp_password');
2747 $this->data['smtp_on'] = $this->Options_model->get_option('email_smtp_on');
2748
2749 // get massmail options
2750 $this->data['sendgrid_api_key'] = $this->Options_model->get_option('sendgrid_api_key');
2751 $this->data['massmail_test_email'] = $this->Options_model->get_option('massmail_test_email');
2752
2753 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
2754
2755 $this->load->view2('admin_email_settings', $this->data);
2756 }
2757
2758 public function send_email()
2759 {
2760 $from_id = (int)$this->session->user_id;
2761 $to_id = (int)trim($this->input->post('to_id'));
2762
2763 if(($from_id <= 0) or ($to_id <= 0))
2764 die;
2765
2766 $subject = (string)trim($this->input->post('subject'));
2767 $message = (string)trim($this->input->post('message'));
2768
2769 if(empty($subject) or empty($message))
2770 die;
2771
2772
2773 $this->load->model('Options_model');
2774
2775 $fromU = $this->User_model->get_one(['id' => $from_id]);
2776 $toU = $this->User_model->get_one(['id' => $to_id]);
2777
2778 $allowed = ($fromU['is_admin'] == 1);
2779 if(!$allowed) {
2780 $dgold_inc_arr = $this->Options_model->get_option('dgold_inc_arr');
2781 $my_referrals = $this->User_model->get_my_referrals($from_id, $dgold_inc_arr);
2782
2783 foreach($my_referrals as $my_ref_rec) {
2784 if($my_ref_rec['id'] == $to_id) {
2785 $allowed = true;
2786 break;
2787 }
2788 }
2789 }
2790
2791 if(!$allowed)
2792 die;
2793
2794
2795 $to_email = $toU['email'];
2796 $to_name = $this->User_model->get_user_name($toU);
2797 $replyto_email = $fromU['email'];
2798 $replyto_name = $this->User_model->get_user_name($fromU);
2799
2800 $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).');
2801 $html = str_replace("\n", '<br>', $message);
2802 $html .= "<br><br>-----------<br><br>{$signature}";
2803
2804 $this->_send_email('', '', $to_email, $to_name, $replyto_email, $replyto_name, $subject, $html, 'standard');
2805
2806
2807 $html = "<h1>{$subject}</h1>".str_replace("\n", '<br>', $message);
2808
2809 $this->_add_message($from_id, $to_id, $html);
2810 }
2811
2812 private function _send_email($from_email, $from_name, $to_email, $to_name, $replyto_email, $replyto_name, $subject, $message, $via = 'standard')
2813 {
2814 $this->load->model('Options_model');
2815
2816 if(empty($from_email)) {
2817 $email_from_email = $this->Options_model->get_option('email_from_email');
2818 $email_from_name = $this->Options_model->get_option('email_from_name');
2819
2820 $from_email = empty($email_from_email) ? "support@{$_SERVER['HTTP_HOST']}" : $email_from_email;
2821 $from_name = empty($email_from_name) ? 'Admin' : $email_from_name;
2822 }
2823
2824 if($via == 'standard') {
2825 $email_smtp_on = $this->Options_model->get_option('email_smtp_on');
2826
2827 if($email_smtp_on) {
2828 if(!empty($to_name)) {
2829 $to_email = [$to_email => $to_name];
2830 } else {
2831 $to_email = [$to_email];
2832 }
2833
2834 $email_smtp_host = $this->Options_model->get_option('email_smtp_host');
2835 $email_smtp_port = $this->Options_model->get_option('email_smtp_port');
2836 $email_smtp_security = $this->Options_model->get_option('email_smtp_security');
2837 $email_smtp_username = $this->Options_model->get_option('email_smtp_username');
2838 $email_smtp_password = $this->Options_model->get_option('email_smtp_password');
2839
2840 $transport = (new Swift_SmtpTransport($email_smtp_host, $email_smtp_port, $email_smtp_security))
2841 ->setUsername($email_smtp_username)
2842 ->setPassword($email_smtp_password);
2843 //->setStreamOptions(array('ssl' => array('allow_self_signed' => true, 'verify_peer' => false, 'verify_peer_name' => false)));
2844
2845 // Create the Mailer using your created Transport
2846 $mailer = new Swift_Mailer($transport);
2847
2848 // Create a message
2849 $msg = (new Swift_Message($subject))
2850 ->setFrom([$from_email => $from_name])
2851 ->setTo($to_email)
2852 ->setBody($message, 'text/html');
2853
2854 if(!empty($replyto_email)) {
2855 if(!empty($replyto_name)) {
2856 $replyto = [$replyto_email => $replyto_name];
2857 } else {
2858 $replyto = [$replyto_email];
2859 }
2860 $msg->setReplyTo($replyto);
2861 }
2862
2863 // Send the message
2864 $result = $mailer->send($msg);
2865 } else {
2866 if(!empty($replyto_email)) {
2867 if(!empty($replyto_name)) {
2868 $replyto = "{$replyto_email} {$replyto_name}";
2869 } else {
2870 $replyto = $replyto_email;
2871 }
2872 $message = _v('Do not reply to us!<br> You should reply to:')." {$replyto}<br><br>-----------<br><br>{$message}";
2873 }
2874
2875 $this->load->library('email');
2876
2877 $this->email->from($from_email, $from_name);
2878 $this->email->to($to_email);
2879 $this->email->subject($subject);
2880 $this->email->set_mailtype('html');
2881
2882 $this->email->message($message);
2883
2884 //send the email
2885 $this->email->send();
2886 }
2887 } elseif($via == 'sendgrid') {
2888 $sendgrid_api_key = $this->Options_model->get_option('sendgrid_api_key');
2889
2890 $tos_chunked = array_chunk($to_email, 99, true);
2891
2892 $sent_emails = [];
2893
2894
2895
2896 foreach($tos_chunked as $tos_chunk) {
2897 $sendgrid_from = new \SendGrid\Mail\From($this->data['email_from_email'], $this->data['email_from_name']);
2898
2899 $sendgrid_tos = [];
2900 foreach ($tos_chunk as $tos_email => $tos_name) {
2901 $sendgrid_tos[] = new \SendGrid\Mail\To($tos_email, $tos_name);
2902 }
2903
2904 $sendgrid_subject = new \SendGrid\Mail\Subject($mass_subject);
2905
2906 $plainTextContent = new \SendGrid\Mail\PlainTextContent('');
2907 $htmlContent = new \SendGrid\Mail\HtmlContent($mass_message);
2908
2909 $email = new \SendGrid\Mail\Mail(
2910 $sendgrid_from,
2911 $sendgrid_tos,
2912 $sendgrid_subject,
2913 $plainTextContent,
2914 $htmlContent
2915 );
2916
2917 $sendgrid = new \SendGrid($sendgrid_api_key);
2918 }
2919
2920 foreach($tos_chunked as $tos_chunk) {
2921 $sendgrid_from = new \SendGrid\Mail\From($from_email, $from_name);
2922
2923 $sendgrid_tos = [];
2924 foreach ($tos_chunk as $tos_email => $tos_name) {
2925 $sendgrid_tos[] = new \SendGrid\Mail\To($tos_email, $tos_name);
2926 }
2927
2928 $sendgrid_subject = new \SendGrid\Mail\Subject($subject);
2929
2930 $plainTextContent = new \SendGrid\Mail\PlainTextContent('');
2931 $htmlContent = new \SendGrid\Mail\HtmlContent($message);
2932
2933 $email = new \SendGrid\Mail\Mail(
2934 $sendgrid_from,
2935 $sendgrid_tos,
2936 $sendgrid_subject,
2937 $plainTextContent,
2938 $htmlContent
2939 );
2940
2941 $sendgrid = new \SendGrid($sendgrid_api_key);
2942 try {
2943 $response = $sendgrid->send($email);
2944
2945 $status = $response->statusCode();
2946 if(($status == 200) or ($status == 202)) {
2947 $sent_emails = array_merge($sent_emails, $tos_chunk);
2948 }
2949
2950 log_message('error', 'Sendgrid-notification-ok_response-' . $status . '-' . serialize($response->headers()) . '-' . serialize($response->body())) . '-'. serialize($tos_chunk);
2951 } catch (Exception $e) {
2952 log_message('error', 'Sendgrid-notification-exception-' . $e->getMessage());
2953 }
2954 }
2955
2956
2957 foreach($tos_chunked as $tos_chunk) {
2958 $email = new \SendGrid\Mail\Mail();
2959
2960 $email->setFrom($from_email, $from_name);
2961
2962 $email->addTos($tos_chunk);
2963
2964 $email->setSubject($subject);
2965
2966 //$email->addContent("text/plain", "and easy to do anywhere, even with PHP");
2967 $email->addContent("text/html", $message);
2968
2969 $sendgrid = new \SendGrid($sendgrid_api_key);
2970 try {
2971 $response = $sendgrid->send($email);
2972
2973 $status = $response->statusCode();
2974 if(($status == 200) or ($status == 202)) {
2975 $sent_emails = array_merge($sent_emails, $tos_chunk);
2976 }
2977
2978 log_message('error', 'Sendgrid-notification-ok_response-' . $status . '-' . serialize($response->headers()) . '-' . serialize($response->body())) . '-'. serialize($tos_chunk);
2979 } catch (Exception $e) {
2980 log_message('error', 'Sendgrid-notification-exception-' . $e->getMessage());
2981 }
2982 }
2983
2984 }
2985 }
2986
2987 public function inbox($page = 0)
2988 {
2989 $this->_check_login();
2990
2991 $page = ((int)$page - 1);
2992 $page = ($page > 0) ? $page : 0;
2993
2994 $this->load->model('Blog_posts_model');
2995
2996 $condition = ['is_draft' => 0];
2997
2998 $this->db->select('SQL_CALC_FOUND_ROWS *', false);
2999 $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']);
3000
3001 // pagination
3002 $query = $this->db->query('SELECT FOUND_ROWS() AS records');
3003 $row = $query->row();
3004
3005 $base_url = base_url($this->load->_get_this_controller_slug().'/'.__FUNCTION__);
3006 $this->data['pagination'] = $this->_get_pagination_html($base_url, $row->records);
3007
3008
3009 $this->load->model('Blog_posts_seen_model');
3010 $this->data['posts'] = $this->Blog_posts_seen_model->blog_posts_add_seen($this->data['posts']);
3011
3012
3013 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
3014
3015 $this->load->view2('inbox', $this->data);
3016 }
3017
3018 public function ajax_blog_messages($blog_post_id = null)
3019 {
3020 $blog_post_id = (int)$blog_post_id;
3021 if($blog_post_id <= 0)
3022 die;
3023
3024 $this->_check_login(false);
3025
3026 $this->load->model('Blog_posts_model');
3027
3028 $post = $this->Blog_posts_model->get_one(['id' => $blog_post_id, 'is_draft' => 0]);
3029 if(empty($post))
3030 die;
3031
3032 $this->load->model('Blog_posts_seen_model');
3033
3034 $seenRec = $this->Blog_posts_seen_model->get_one(['user_id' => $this->data['id'], 'blog_post_id' => $blog_post_id]);
3035 if(empty($seenRec)) {
3036 $this->Blog_posts_seen_model->insert(['user_id' => $this->data['id'], 'blog_post_id' => $blog_post_id]);
3037 }
3038
3039 $label = $post['is_company_email'] ? " <span class=\"label label-danger\">Company e-mail</span>" : '';
3040
3041 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>";
3042 }
3043
3044 public function contact_us()
3045 {
3046 //redirect('/admin/my_messages#contact_us');
3047 $this->_check_login();
3048
3049 $subject = (string)trim($this->input->post('subject'));
3050 $message = (string)trim($this->input->post('message'));
3051
3052 if(!empty($message)) {
3053 $email_from_email = $this->Options_model->get_option('email_from_email');
3054 $email_from_name = $this->Options_model->get_option('email_from_name');
3055
3056 $email_from_email = empty($email_from_email) ? "support@{$_SERVER['HTTP_HOST']}" : $email_from_email;
3057 $email_from_name = empty($email_from_name) ? 'Admin' : $email_from_name;
3058
3059 $reply_to = $this->data['email'];
3060 $to_email = 'support@dgoldcurrency.com';
3061 $html = $message;
3062
3063 $email_smtp_on = $this->Options_model->get_option('email_smtp_on');
3064
3065 if($email_smtp_on) {
3066 $to_email = array($to_email);
3067
3068 if(!empty($this->data['name']) or !empty($this->data['surname'])) {
3069 $name = trim("{$this->data['name']} {$this->data['surname']}");
3070 $reply_to = array($reply_to => $name);
3071 } else {
3072 $reply_to = array($reply_to);
3073 }
3074
3075 $email_smtp_host = $this->Options_model->get_option('email_smtp_host');
3076 $email_smtp_port = $this->Options_model->get_option('email_smtp_port');
3077 $email_smtp_security = $this->Options_model->get_option('email_smtp_security');
3078 $email_smtp_username = $this->Options_model->get_option('email_smtp_username');
3079 $email_smtp_password = $this->Options_model->get_option('email_smtp_password');
3080
3081 $transport = (new Swift_SmtpTransport($email_smtp_host, $email_smtp_port, $email_smtp_security))
3082 ->setUsername($email_smtp_username)
3083 ->setPassword($email_smtp_password);
3084 //->setStreamOptions(array('ssl' => array('allow_self_signed' => true, 'verify_peer' => false, 'verify_peer_name' => false)));
3085
3086 // Create the Mailer using your created Transport
3087 $mailer = new Swift_Mailer($transport);
3088
3089 // Create a message
3090 $message = (new Swift_Message($subject))
3091 ->setFrom(array($email_from_email => $email_from_name))
3092 ->setTo($to_email)
3093 ->setReplyTo($reply_to)
3094 ->setBody($html, 'text/html')
3095 ;
3096
3097 // Send the message
3098 $result = $mailer->send($message);
3099 } else {
3100 $this->load->library('email');
3101
3102 $this->email->from($email_from_email, $email_from_name);
3103 $this->email->to($to_email);
3104 $this->email->subject($subject);
3105 $this->email->set_mailtype('html');
3106
3107 $this->email->message($html);
3108
3109 //send the email
3110 $this->email->send();
3111 }
3112
3113 $this->data['info_message'] = '<div class="alert alert-success" role="alert">'._v('Message sent!').'</div>';
3114 }
3115
3116
3117 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
3118
3119 $this->load->view2('contact_us', $this->data);
3120 }
3121
3122 private function _send_payout_email($objU, $objP)
3123 {
3124 $subject = "Withdrawal is successfully made";
3125 $message = "{$objP['amount_usd']} USD was successfully paid to your {$objP['merchant']} wallet.<br>Contact support mail if any problems.";
3126
3127 //get options
3128 $this->load->model('Options_model');
3129
3130 $email_from_email = $this->Options_model->get_option('email_from_email');
3131 $email_from_name = $this->Options_model->get_option('email_from_name');
3132
3133 $email_from_email = empty($email_from_email) ? "support@{$_SERVER['HTTP_HOST']}" : $email_from_email;
3134 $email_from_name = empty($email_from_name) ? 'Admin' : $email_from_name;
3135
3136 $to_email = $objU['email'];
3137 $html = $message;
3138
3139 $email_smtp_on = $this->Options_model->get_option('email_smtp_on');
3140
3141 if($email_smtp_on) {
3142 if(!empty($objU['name']) or !empty($objU['surname'])) {
3143 $to_email = array($to_email => trim("{$objU['name']} {$objU['surname']}"));
3144 } else {
3145 $to_email = array($to_email);
3146 }
3147
3148 $email_smtp_host = $this->Options_model->get_option('email_smtp_host');
3149 $email_smtp_port = $this->Options_model->get_option('email_smtp_port');
3150 $email_smtp_security = $this->Options_model->get_option('email_smtp_security');
3151 $email_smtp_username = $this->Options_model->get_option('email_smtp_username');
3152 $email_smtp_password = $this->Options_model->get_option('email_smtp_password');
3153
3154 $transport = (new Swift_SmtpTransport($email_smtp_host, $email_smtp_port, $email_smtp_security))
3155 ->setUsername($email_smtp_username)
3156 ->setPassword($email_smtp_password);
3157 //->setStreamOptions(array('ssl' => array('allow_self_signed' => true, 'verify_peer' => false, 'verify_peer_name' => false)));
3158
3159 // Create the Mailer using your created Transport
3160 $mailer = new Swift_Mailer($transport);
3161
3162 // Create a message
3163 $message = (new Swift_Message($subject))
3164 ->setFrom(array($email_from_email => $email_from_name))
3165 ->setTo($to_email)
3166 ->setBody($html, 'text/html')
3167 ;
3168
3169 // Send the message
3170 $result = $mailer->send($message);
3171 } else {
3172 $this->load->library('email');
3173
3174 $this->email->from($email_from_email, $email_from_name);
3175 $this->email->to($to_email);
3176 $this->email->subject($subject);
3177 $this->email->set_mailtype('html');
3178
3179 $this->email->message($html);
3180
3181 //send the email
3182 $this->email->send();
3183 }
3184 }
3185 public function invoice_ddk(){
3186 $this->_check_login();
3187
3188 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
3189
3190
3191 $this->load->view2('admin_invoices_ddk', $this->data);
3192 }
3193 public function dgold_mining()
3194 {
3195 $this->_check_login();
3196
3197 // data for calculate DGold price dynamically
3198 $this->data['buy_usd_value'] = $this->config->item('buy_usd_amount');
3199
3200
3201 $this->load->model('Docs_model');
3202 $docs1 = $this->Docs_model->get(['user_id' => $this->session->user_id, 'type' => 'ID document', 'is_approved' => 1]);
3203 $docs2 = $this->Docs_model->get(['user_id' => $this->session->user_id, 'type' => 'Proof of address', 'is_approved' => 1]);
3204 $this->data['uploaded_docs'] = !empty($docs1) and !empty($docs2);
3205
3206 $this->load->model('Packages_model');
3207
3208
3209 // Packages to buy
3210 if($this->input->post('action') == 'buy_package') {
3211 $package_id = (int)trim($this->input->post('id'));
3212 if($package_id > 0) {
3213 if($this->_buy_package($package_id, $this->data)) {
3214 $data2 = $this->User_model->get_one(array('id' => $this->data['id']));
3215 $this->data['usd'] = $data2['usd'];
3216
3217 $this->data['show_modal_package_bought'] = true;
3218
3219 $this->db->select('SQL_CALC_FOUND_ROWS *', false);
3220 $this->data['packages'] = $this->Packages_model->get(['user_id' => $this->data['id'], 'packages.is_active' => 1], 'last_payout_date DESC');
3221
3222 $this->data['packages_pagination'] = '';
3223 } else {
3224 $this->data['show_modal_insufficient_money'] = true;
3225 }
3226 }
3227 }
3228
3229
3230 $this->load->helper('miner');
3231
3232 // ask payout to dgold balance
3233 $package_id = (int)trim($this->input->get('payout_dgold_id'));
3234 if($package_id > 0) {
3235 $package = $this->Packages_model->get_one(['id' => $package_id, 'user_id' => $this->data['id'], 'is_active' => 1]);
3236 if(!empty($package)) {
3237 $delta = intdiv_1(time() - $package['last_payout_date'], 86400 * 30);
3238 if($delta > 0) {
3239 $next_payout_date = $package['last_payout_date'] + $delta * 86400 * 30;
3240
3241 $val_dgold = $delta * $package['daily_dgolds'] * 30;
3242
3243 $this->Packages_model->start_transaction();
3244
3245 $this->db->set('coins', "coins + {$val_dgold}", FALSE);
3246 $this->User_model->update_by_id(['id' => $this->data['id']]);
3247
3248 $this->Packages_model->update_by_id([
3249 'id' => $package_id,
3250 'last_payout_date' => $next_payout_date,
3251 ]);
3252
3253 $this->Packages_model->commit_transaction();
3254
3255 $data2 = $this->User_model->get_one(array('id' => $this->data['id']));
3256 $this->data['usd'] = $data2['usd'];
3257 $this->data['usd_cashout'] = $data2['usd_cashout'];
3258 $this->data['coins'] = $data2['coins'];
3259
3260 $this->data['show_modal_payout_dgold'] = str_replace('xxx', $val_dgold, _v("xxx DGold have been transferred to your DGold balance."));
3261 }
3262 }
3263 }
3264
3265 // ask payout to usd balance
3266 $package_id = (int)trim($this->input->get('payout_usd_id'));
3267 if($package_id > 0) {
3268 $package = $this->Packages_model->get_one(['id' => $package_id, 'user_id' => $this->data['id'], 'is_active' => 1]);
3269 if(!empty($package)) {
3270 $t = min($package['stop_date'], time());
3271 $delta = intdiv_1($t - $package['last_payout_date'], 86400 * 30);
3272 if($delta > 0) {
3273 $next_payout_date = $package['last_payout_date'] + $delta * 86400 * 30;
3274
3275 $val_dgold = $delta * $package['daily_dgolds'] * 30 / 2;
3276 $val_usd = $val_dgold * $this->data['dgold_rate'];
3277
3278 $this->Packages_model->start_transaction();
3279
3280 $this->db->set('usd_cashout', "usd_cashout + {$val_usd}", FALSE);
3281 $this->db->set('coins', "coins + {$val_dgold}", FALSE);
3282 $this->User_model->update_by_id(['id' => $this->data['id']]);
3283
3284 $this->Packages_model->update_by_id([
3285 'id' => $package_id,
3286 'last_payout_date' => $next_payout_date,
3287 ]);
3288
3289 $this->Packages_model->commit_transaction();
3290
3291 $data2 = $this->User_model->get_one(array('id' => $this->data['id']));
3292 $this->data['usd'] = $data2['usd'];
3293 $this->data['usd_cashout'] = $data2['usd_cashout'];
3294 $this->data['coins'] = $data2['coins'];
3295
3296 $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."));
3297 }
3298 }
3299 }
3300
3301 // ask percentage payout
3302 if($this->input->post('action') == 'request_payout') {
3303 $payout_percent = (int)trim($this->input->post('payout_percent'));
3304 $payout_percent = min(100, $payout_percent);
3305 $payout_percent = max(50, $payout_percent);
3306
3307 $package_id = (int)trim($this->input->post('package_id'));
3308 if($package_id > 0) {
3309 $package = $this->Packages_model->get_one(['id' => $package_id, 'user_id' => $this->data['id'], 'is_active' => 1]);
3310 if (!empty($package)) {
3311 $delta = intdiv_1(time() - $package['last_payout_date'], 86400 * 30);
3312 if ($delta > 0) {
3313 $next_payout_date = $package['last_payout_date'] + $delta * 86400 * 30;
3314
3315 $val_dgold_half = $delta * $package['daily_dgolds'] * 30 / 2;
3316 $val_usd_half = $val_dgold_half * $this->data['dgold_rate'];
3317
3318 $val_dgold = floor($val_dgold_half / 50 * $payout_percent);
3319 $val_usd = floor($val_usd_half / 50 * (100 - $payout_percent) * 100) / 100;
3320
3321 $this->Packages_model->start_transaction();
3322
3323 $this->db->set('usd_cashout', "usd_cashout + {$val_usd}", FALSE);
3324 $this->db->set('coins', "coins + {$val_dgold}", FALSE);
3325 $this->User_model->update_by_id(['id' => $this->data['id']]);
3326
3327 $this->Packages_model->update_by_id([
3328 'id' => $package_id,
3329 'last_payout_date' => $next_payout_date,
3330 ]);
3331
3332 $this->Packages_model->commit_transaction();
3333
3334 $data2 = $this->User_model->get_one(array('id' => $this->data['id']));
3335 $this->data['usd'] = $data2['usd'];
3336 $this->data['usd_cashout'] = $data2['usd_cashout'];
3337 $this->data['coins'] = $data2['coins'];
3338
3339 if($val_usd == 0) {
3340 $this->data['show_modal_payout_dgold'] = str_replace('xxx', $val_dgold, _v("xxx DGold have been transferred to your DGold balance."));
3341 } else {
3342 $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."));
3343 }
3344 }
3345 }
3346 }
3347 }
3348
3349
3350 $this->db->select('SQL_CALC_FOUND_ROWS *', false);
3351
3352 $this->data['packages'] = $this->Packages_model->get(['user_id' => $this->data['id'], 'packages.is_active' => 1], 'last_payout_date DESC');
3353 $this->data['packages_info'] = [];
3354 if(!empty($this->data['packages'])) {
3355 foreach($this->data['packages'] as $pid => $package) {
3356 $this->data['packages_info'][$package['id']] = $this->_get_package_info($package);
3357 }
3358 }
3359
3360 $this->data['packages_pagination'] = '';
3361
3362
3363 $this->data['side_navigation'] = $this->_get_side_navigation(__FUNCTION__, $this->data['is_admin']);
3364 $this->load->view2('dgold_mining', $this->data);
3365 }
3366
3367 private function _buy_package($package_id, $objU)
3368 {
3369 $this->load->model('Packages_setup_model');
3370 $this->load->model('Packages_model');
3371
3372 $ret = false;
3373
3374 if($package_id > 0) {
3375 $this->Packages_model->start_transaction();
3376
3377 $objPS = $this->Packages_setup_model->get_one(['id' => $package_id, 'is_active' => 1]);
3378 if(!empty($objPS)) {
3379 if(($objU['usd'] + $objU['usd_cashout']) >= $objPS['price']) {
3380 if($objU['usd'] >= $objPS['price']) {
3381 $this->db->set('usd', "usd - {$objPS['price']}", FALSE);
3382 } else {
3383 $usd_price = $objU['usd'];
3384 $usd_cashout_price = $objPS['price'] - $objU['usd'];
3385
3386 $this->db->set('usd', "usd - {$usd_price}", FALSE);
3387 $this->db->set('usd_cashout', "usd_cashout - {$usd_cashout_price}", FALSE);
3388 }
3389
3390 $this->User_model->update_by_id(['id' => $objU['id']]);
3391
3392 $t = time();
3393 $this->Packages_model->insert([
3394 'user_id' => $objU['id'],
3395 'package_id' => $objPS['id'],
3396 'daily_dgolds' => $objPS['daily_dgolds'],
3397 'start_date' => $t,//$t - 31 * 86400,
3398 'last_payout_date' => $t,//$t - 31 * 86400,
3399 'stop_date' => $t + 12 * 30 * 86400,
3400 'title' => $objPS['title'],
3401 'hash_rate' => $objPS['hash_rate'],
3402 'hash_rate_sign' => $objPS['hash_rate_sign'],
3403 'last_share' => $t,
3404 'next_share' => $t,
3405 'is_active' => 1,
3406 ]);
3407
3408 // add referral bonuses
3409 $mining_reward_lvl1 = $objPS['price'] / 100 * $this->Options_model->get_option('dgold_mining_reward_lvl1');
3410 $mining_reward_lvl2 = $objPS['price'] / 100 * $this->Options_model->get_option('dgold_mining_reward_lvl2');
3411
3412 if($objU['ref'] > 0) {
3413 $objUref1 = $this->User_model->get_one(['id' => $objU['ref']]);
3414
3415 if(!empty($objUref1)) {
3416 $this->db->set('usd', "usd + {$mining_reward_lvl1}", FALSE);
3417 $this->User_model->update_by_id(['id' => $objUref1['id']]);
3418
3419 if($objUref1['ref'] > 0) {
3420 $objUref2 = $this->User_model->get_one(['id' => $objUref1['ref']]);
3421
3422 if(!empty($objUref2)) {
3423 $this->db->set('usd', "usd + {$mining_reward_lvl2}", FALSE);
3424 $this->User_model->update_by_id(['id' => $objUref2['id']]);
3425 }
3426 }
3427 }
3428 }
3429
3430 $ret = true;
3431 }
3432 }
3433
3434 $this->Packages_model->commit_transaction();
3435 }
3436
3437 return $ret;
3438 }
3439
3440 public function json_get_package_info($package_id = 0)
3441 {
3442 $package_id = (int)$package_id;
3443 if($package_id < 0)
3444 return;
3445
3446 $this->load->model('Packages_model');
3447 $this->load->model('Packages_setup_model');
3448
3449 if($package_id == 0) {
3450 $packages_info = [];
3451
3452 $packages = $this->Packages_model->get(['user_id' => $this->session->user_id, 'packages.is_active' => 1], 'last_payout_date DESC');
3453
3454 if(!empty($packages)) {
3455 $hash_exps = ['EH/s' => 18, 'PH/s' => 15, 'TH/s' => 12, 'GH/s' => 9, 'MH/s' => 6, 'kH/s' => 3];
3456 $p_hashrate = 0.0;
3457
3458 $p_mined_dgold = 0;
3459 $p_uptime = time();
3460 $p_last_share = 0;
3461
3462 foreach($packages as $pid => $package_arr) {
3463 $p_hashrate += $package_arr['hash_rate'] * pow(10, $hash_exps[$package_arr['hash_rate_sign']]);
3464 $p_uptime = min($p_uptime, $package_arr['start_date']);
3465 $p_last_share = max($p_last_share, $package_arr['last_share']);
3466 $p_mined_dgold += (time() - $package_arr['last_payout_date']) / 86400 * $package_arr['daily_dgolds'];
3467
3468 // fill numbered packages
3469 $info = $this->_get_package_info($package_arr);
3470 if(!empty($info)) {
3471 $packages_info[$package_arr['id']] = $info;
3472 }
3473 }
3474
3475 $tmp_hashrate = number_format($p_hashrate, 0, '.', '');
3476 foreach($hash_exps as $sign => $exp) {
3477 if(strlen($tmp_hashrate) > $exp) {
3478 break;
3479 }
3480 }
3481 $pp_hashrate = number_format($p_hashrate / pow(10, $exp), 1, '.', ',');
3482
3483 // fill zero package
3484 $packages_info[0] = $this->_get_package_info([
3485 'id' => 0,
3486 'hash_rate' => $pp_hashrate,
3487 'hash_rate_sign' => $sign,
3488 'start_date' => $p_uptime,
3489 'last_payout_date' => '',
3490 'last_share' => $p_last_share,
3491 'daily_dgolds' => '',
3492 ]);
3493 $packages_info[0]['mined_dgold'] = $this->_mined_dgold_format($p_mined_dgold);
3494 }
3495 echo json_encode($packages_info);
3496 } else {
3497 $package_arr = $this->Packages_model->get_one(['user_id' => $this->session->user_id, 'packages.id' => $package_id]);
3498
3499 if(!empty($package_arr)) {
3500 $info = $this->_get_package_info($package_arr);
3501 if(!empty($info)) {
3502 echo json_encode($info);
3503 }
3504 }
3505 }
3506 }
3507
3508 private function _get_package_info($package)
3509 {
3510 $info = [];
3511
3512 $this->load->helper('miner');
3513
3514 $info['hashrate'] = "{$package['hash_rate']} {$package['hash_rate_sign']}";
3515 $info['cpu_load'] = number_format(99.2 + 0.7 * cos($package['id'] + deg2rad(18 + time() / 7)), 2, '.', ',')."%";
3516 $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";
3517 $info['temperature'] = number_format(55 + 6 * sin($package['id'] + deg2rad(3 + time() / 21)), 2, '.', ',')."℃";
3518 $info['mined_dgold'] = $this->_mined_dgold_format((time() - $package['last_payout_date']) / 86400 * $package['daily_dgolds']);
3519 $info['uptime_str'] = get_uptime($package['start_date']);
3520 $info['uptime'] = "<span class=\"make_datatime2\">{$package['start_date']}</span>";
3521
3522 return $info;
3523 }
3524
3525 private function _mined_dgold_format($dgold = 0.0)
3526 {
3527 $ret = number_format($dgold, 8, '.', ',');
3528 $pos = strpos($ret, '.');
3529 if($pos !== false) {
3530 $ret = substr($ret, 0, $pos).'<span style="font-size:0.8em;">'.substr($ret, $pos).'</span>';
3531 }
3532 return $ret;
3533 }
3534
3535 private function _check_login($load_default_options = true)
3536 {
3537 $userid = empty($this->session->user_id) ? 0 : $this->session->user_id;
3538 if($userid < 1) {
3539 $redir_url = urlencode(base_url($_SERVER['REQUEST_URI']));
3540
3541 redirect("/user/login/?r={$redir_url}");
3542 }
3543
3544 $this->data = $this->User_model->get_one(['id' => $this->session->user_id]);
3545
3546 if(empty($this->data)) {
3547 redirect("/".$this->load->_get_this_controller_slug());
3548 }
3549
3550 if($load_default_options) {
3551 $this->_load_default_options();
3552 }
3553 }
3554
3555 private function _check_admin($load_default_options = true)
3556 {
3557 $userid = empty($this->session->user_id) ? 0 : $this->session->user_id;
3558 if($userid < 1) {
3559 $redir_url = urlencode(base_url($_SERVER['REQUEST_URI']));
3560
3561 redirect("/user/login/?r={$redir_url}");
3562 }
3563
3564 $this->data = $this->User_model->get_one(['id' => $this->session->user_id]);
3565
3566 if(empty($this->data) or ($this->data['is_admin'] != 1)) {
3567 redirect("/".$this->load->_get_this_controller_slug());
3568 }
3569
3570 if($load_default_options) {
3571 $this->_load_default_options();
3572 }
3573 }
3574
3575 private function _load_default_options()
3576 {
3577 $this->load->model('Options_model');
3578 $this->data['my_payout_options'] = empty($this->data['my_payout_options']) ? [] : unserialize($this->data['my_payout_options']);
3579
3580 $this->data['game_countdown'] = $this->Options_model->get_option('game_countdown', 24);
3581
3582 $this->data['rows_per_page'] = $this->Options_model->get_option('rows_per_page');
3583
3584 $this->data['dgold_rate'] = $this->Options_model->get_option('dgold_rate');
3585 $this->data['dgold_total_sold'] = $this->Options_model->get_option('dgold_total_sold');
3586
3587 // update crypto ticker
3588 $cryptocurrency_last_update = $this->Options_model->get_option('cryptocurrency_last_update', 0);
3589 if($cryptocurrency_last_update + 10800 < time()) {
3590 $json = json_decode(file_get_contents('https://api.coinmarketcap.com/v2/ticker/'), true);
3591
3592 $allowed_cryptocurrencies = array_flip(explode(' ', 'BTC ETH XRP BCH LTC EOS XLM'));
3593 $this->data['cryptocurrencies'] = [];
3594 foreach($json['data'] as $arr) {
3595 if(isset($allowed_cryptocurrencies[$arr['symbol']])) {
3596 $this->data['cryptocurrencies'][] = [
3597 'name' => $arr['name'],
3598 'symbol' => $arr['symbol'],
3599 'price' => $arr['quotes']['USD']['price'],
3600 'percent_change_1h' => $arr['quotes']['USD']['percent_change_1h'],
3601 'percent_change_24h' => $arr['quotes']['USD']['percent_change_24h'],
3602 'percent_change_7d' => $arr['quotes']['USD']['percent_change_7d'],
3603 ];
3604 }
3605 }
3606
3607 if(!empty($this->data['cryptocurrencies'])) {
3608 $this->Options_model->set_option('cryptocurrencies', serialize($this->data['cryptocurrencies']));
3609 } else {
3610 $this->data['cryptocurrencies'] = $this->Options_model->get_option('cryptocurrencies');
3611 }
3612 $this->Options_model->set_option('cryptocurrency_last_update', time());
3613 } else {
3614 $this->data['cryptocurrencies'] = $this->Options_model->get_option('cryptocurrencies');
3615 }
3616
3617 $this->load->model('Packages_setup_model');
3618
3619 $this->data['packages_setup'] = $this->Packages_setup_model->get(['is_active' => 1], 'show_order');
3620
3621 if($this->data['is_admin'] == 1) {
3622 $this->load->model('Payout_model');
3623 $ret = $this->Payout_model->get(['is_paid' => 0], null, 'id');
3624 $this->data['payout_not_paid_num'] = empty($ret) ? 0 : count($ret);
3625
3626 $this->load->model('Docs_model');
3627 $ret = $this->Docs_model->get(['is_approved' => 0], null, 'id');
3628 $this->data['docs_not_approved_num'] = empty($ret) ? 0 : count($ret);
3629 }
3630 }
3631
3632 private function _get_merchants_data()
3633 {
3634 $this->load->model('Options_model');
3635
3636 $merchants_data = [
3637 'paypal_on' => $this->Options_model->get_option('merchant_paypal_on'),
3638 'coinbase_on' => $this->Options_model->get_option('merchant_coinbase_on'),
3639 'solidtrustpay_on' => $this->Options_model->get_option('merchant_solidtrustpay_on'),
3640 'payeer_on' => $this->Options_model->get_option('merchant_payeer_on'),
3641 'advcash_on' => $this->Options_model->get_option('merchant_advcash_on'),
3642 'cryptonator_on' => $this->Options_model->get_option('merchant_cryptonator_on'),
3643 'btc_on' => $this->Options_model->get_option('merchant_btc_on'),
3644 ];
3645
3646 return $merchants_data;
3647 }
3648
3649 private function _get_pagination_html($base_url, $total_rows, $params = [])
3650 {
3651 $this->load->library('pagination');
3652
3653 $this->pagination->initialize($this->_get_pagination_initialize_array($base_url, $total_rows, $params));
3654
3655 return $this->pagination->create_links();
3656 }
3657
3658 private function _get_pagination_initialize_array($base_url, $total_rows, $params = [])
3659 {
3660 $this->load->model('Options_model');
3661
3662 $per_page = $this->Options_model->get_option('rows_per_page');
3663 $pagination_num_links = $this->Options_model->get_option('pagination_num_links');
3664
3665 $params = is_array($params) ? $params : [];
3666
3667 $pagination_initialize_arr = array_merge([
3668 'base_url' => $base_url,
3669 'reuse_query_string' => true,
3670 'use_page_numbers' => true,
3671 'total_rows' => $total_rows,
3672 'per_page' => $per_page,
3673 'num_links' => $pagination_num_links,
3674 'full_tag_open' => '<ul class="pagination pull-right">',
3675 'full_tag_close' => '</ul>',
3676 'first_link' => '«',
3677 'first_tag_open' => '<li>',
3678 'first_tag_close' => '</li>',
3679 'last_link' => '»',
3680 'last_tag_open' => '<li>',
3681 'last_tag_close' => '</li>',
3682 'next_link' => '>',
3683 'next_tag_open' => '<li>',
3684 'next_tag_close' => '</li>',
3685 'prev_link' => '<',
3686 'prev_tag_open' => '<li>',
3687 'prev_tag_close' => '</li>',
3688 'num_tag_open' => '<li>',
3689 'num_tag_close' => '</li>',
3690 'cur_tag_open' => '<li class="active"><a href="#">',
3691 'cur_tag_close' => '</a></li>',
3692 ], $params);
3693
3694 return $pagination_initialize_arr;
3695 }
3696
3697
3698}