Commit 296fcbe9 authored by Thranrion's avatar Thranrion 💬

Update/Blizz1 : Fixed Vote System and new SQL's

parent d977a4a5
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
|--------------------------------------------------------------------------
| Vote Time
|--------------------------------------------------------------------------
|
| Select the time of your Vote Store
|
| PTxH --> For Hours x is your time in Hours
| PxD --> For Days x is your Time in days (Recomended)
| Default == 3H; 3 hours once vote.
|
*/
$config['voteTime'] = 'PT3H';
......@@ -21,21 +21,46 @@ class Vote extends MX_Controller {
if (!$this->m_permissions->getMyPermissions('Permission_Vote'))
redirect(base_url(),'refresh');
$this->load->config('vote');
$this->load->model('vote_model');
$this->load->model('vote_model', 'fxvote');
}
public function index()
{
$data['fxtitle'] = $this->lang->line('nav_vote');
$data = array(
'fxtitle' => $this->lang->line('nav_vote'),
'voteList' => $this->fxvote->getVotes(),
);
$this->load->view('header', $data);
$this->load->view('index');
$this->load->view('footer');
}
/**
* function votenow
*/
public function voteNow($id)
{
echo $this->fxvote->voteNow($id);
}
/**
* function count votes
*/
public function voteNowCount()
{
$id = $this->input->post('value', TRUE);
$seconds = $this->fxvote->getVoteTime($id);
echo $this->fxvote->getCountDownHTML($id, $seconds);
}
public function votenow($id)
/**
* function calling url to vote
*/
public function voteCallURL()
{
$this->vote_model->getvoteNow($id);
$id = $this->input->post('value', TRUE);
echo $this->fxvote->getVoteUrl($id);
}
}
......@@ -8,87 +8,124 @@ class Vote_model extends CI_Model {
parent::__construct();
}
/**
* @return mixed
*/
public function getVotes()
{
return $this->db->select('*')
->get('fx_votes');
return $this->db->get('fx_votes')->result();
}
public function getFinallyTime($id, $time)
/**
* @param $id
* @return mixed
*/
public function getVotePoints($id)
{
$qq = $this->db->select('lasttime')
->where('idaccount', $this->session->userdata('fx_sess_id'))
->where('idvote', $id)
->get('fx_votes_logs');
if($qq->num_rows())
return strtotime('+'.$time.' hour', $qq->row_array()['lasttime']);
else
return '0,0,0';
return $this->db->where('id', $id)->get('fx_votes')->row('points');
}
public function getVoteSpecify($id)
/**
* @param $id
* @param $userid
* @return mixed
*/
public function getVoteLog($id, $userid)
{
return $this->db->select('*')
->where('id', $id)
->get('fx_votes');
return $this->db->where('idaccount', $userid)->where('idvote', $id)->limit('1')->order_by('id', 'DESC')->get('fx_votes_logs');
}
public function getvoteNow($id)
/**
* @param $id
* @param $userid
* @return mixed
*/
public function getTimeLogExpired($id, $userid)
{
if($id == '0')
redirect(base_url('vote'),'refresh');
if(!$this->getVoteSpecify($id)->num_rows())
redirect(base_url('vote'),'refresh');
return $this->db->where('idaccount', $userid)->where('idvote', $id)->limit('1')->order_by('id', 'DESC')->get('fx_votes_logs')->row('expired_at');
}
/**
* @param $id
* @param $userid
* @return mixed
*/
public function getCredits($userid)
{
return $this->db->where('accountid', $userid)->limit('1')->get('fx_credits')->row('vp');
}
/**
* @param $id
* @return mixed
*/
public function getVoteUrl($id)
{
return $this->db->where('id', $id)->get('fx_votes')->row('url');
}
/**
* @param &id
* @return bool|string
*/
public function voteNow($id)
{
$userid = $this->session->userdata('fx_sess_id');
$mytime = $this->m_data->getTimestamp();
$ppoints = $this->getVotePoints($id);
$url = $this->getVoteSpecify($id)->row_array()['url'];
$qqcheck = $this->getVoteLog($id, $userid);
$credits = $this->getCredits($userid);
$url = $this->getVoteUrl($id);
$fecha = new DateTime();
$expired = $fecha->add(new DateInterval($this->config->item('voteTime')));
$expired_at = $expired->getTimestamp();
if (!preg_match("~^(?:f|ht)tps?://~i", $url)) {
$url = "http://" . $url;
}
if($this->m_data->getTimestamp() < /* >= */ $this->getFinallyTime($id, $this->getVoteSpecify($id)->row('time')) ||
!$this->getVoteSpecifyLog($this->session->userdata('fx_sess_id'), $id)->num_rows())
{
echo '<script type="text/javascript">
$comprobetime = $qqcheck->row('expired_at');
if($this->m_data->getTimestamp() >= $comprobetime){
$datalog = array(
'idaccount' => $userid,
'idvote' => $id,
'lasttime' => $mytime,
'expired_at' => $expired_at,
'points' => $ppoints,
);
$qq = $this->db->where('accountid', $userid)->get('fx_credits');
if(!$qq->num_rows()){
$datas = array('accountid' => $userid, 'vp' => $ppoints, 'dp' => '0');
$this->db->insert('fx_credits', $datas);
} else {
$vp2 = $this->db->where('accountid', $userid)->get('fx_credits')->row('vp');
$vp = ($vp2+$ppoints);
$data = array( 'vp' => $vp );
$this->db->where('accountid', $userid)->update('fx_credits', $data);
$this->db->insert('fx_votes_logs', $datalog);
}
echo '<script type="text/javascript">
window.open( "'.$url.'" )
</script>';
$this->insertPoints($this->session->userdata('fx_sess_id'), $id);
redirect(base_url('vote'),'refresh');
}
else
redirect(base_url('vote'),'refresh');
}
public function getVoteSpecifyLog($account, $idvote)
{
return $this->db->select('*')
->where('idaccount', $account)
->where('idvote', $idvote)
->get('fx_votes_logs');
}
public function insertPoints($account, $idvote)
{
$qq = $this->getVoteSpecifyLog($account, $idvote);
if($qq->num_rows())
{
$this->db->set('lasttime', $this->m_data->getTimestamp())
->where('idaccount', $account)
->where('idvote', $idvote)
->update('fx_votes_logs');
}
else
{
$data = array(
'idaccount' => $account,
'idvote' => $idvote,
'lasttime' => $this->m_data->getTimestamp()
);
$this->db->insert('fx_votes_logs', $data);
}
redirect(base_url('vote'),'refresh');
} else {
echo '<script type="text/javascript">';
echo 'alert("According to our records you have already voted in this top. Contact with Support Ingame for Resolving this problem")';
echo '</script>';
redirect(base_url('vote'),'refresh');
}
}
}
......@@ -2,55 +2,21 @@
<div class="uk-container">
<h3 class="uk-h3 uk-text-bold uk-text-uppercase"><i class="fab fa-cc-paypal"></i> Vote</h3>
<div class="uk-child-width-1-1@s uk-child-width-1-2@m uk-child-width-1-4@l" uk-grid-parallax="translate:200">
<?php foreach($this->vote_model->getVotes()->result() as $voteList) { ?>
<?php foreach ($voteList as $key => $voteList): ?>
<div>
<div class="uk-card uk-card-secondary uk-card-body">
<img src="<?= $voteList->image ?>">
<span class="uk-badge"><?= $this->lang->line('panel_points'); ?> <?= $voteList->points ?></span>
<hr class="uk-divider-icon">
<?php echo $this->vote_model->getFinallyTime($voteList->id, $voteList->time) ?>
<!-- COUNTDOWN -->
<div class="uk-grid-medium uk-child-width-auto uk-margin" uk-grid id="countdowntovote">
<div>
<div class="uk-countdown-hours"></div>
</div>
<div>:</div>
<div>
<div class="uk-countdown-minutes"></div>
</div>
<div>:</div>
<div>
<div class="uk-countdown-seconds"></div>
</div>
</div>
<p> Next vote in : </p>
<h5><?= date('Y-m-d h:i:s A', $this->fxvote->getTimeLogExpired($this->session->userdata('fx_sess_id'), $voteList->id)) ?></h5>
<?= form_open(base_url('vote/votenow/'.$voteList->id)); ?>
<button class="uk-button uk-button-default uk-width-1-1"><?= $this->lang->line('nav_vote'); ?></button>
<?= form_close(); ?>
<!-- COUNTDOWN -->
</div>
</div>
<?php if($this->vote_model->getFinallyTime($voteList->id, $voteList->time) != '0,0,0') {
$hour = date('H', $this->vote_model->getFinallyTime($voteList->id, $voteList->time));
$minute = date('i', $this->vote_model->getFinallyTime($voteList->id, $voteList->time));
$second = date('s', $this->vote_model->getFinallyTime($voteList->id, $voteList->time));
}
else
{
$hour = '0';
$minute = '0';
$second = '0';
}
?>
<script>
jQuery(function(){
var d = new Date();
d.setHours(<?= $hour ?>,<?= $minute ?>,<?= $second ?>);
UIkit.countdown('#countdowntovote', {date: d});
})
</script>
<?php } ?>
<?php endforeach; ?>
</div>
</div>
</section>
......@@ -10,6 +10,7 @@ MySQL - 5.5.5-10.1.29-MariaDB : Database - blizzcms
/*!40101 SET SQL_MODE=''*/;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
/*Table structure for table `fx_api_char` */
......@@ -738,11 +739,11 @@ CREATE TABLE `fx_users_permission` (
CONSTRAINT `fx_users_permission_ibfk_1` FOREIGN KEY (`idrank`) REFERENCES `fx_ranks_default` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*Table structure for table `fx_votes` */
DROP TABLE IF EXISTS `fx_votes`;
CREATE TABLE `fx_votes` (
CREATE TABLE IF NOT EXISTS `fx_votes` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`url` text NOT NULL,
......@@ -750,18 +751,21 @@ CREATE TABLE `fx_votes` (
`points` int(10) NOT NULL DEFAULT '1',
`image` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
/*Table structure for table `fx_votes_logs` */
DROP TABLE IF EXISTS `fx_votes_logs`;
CREATE TABLE `fx_votes_logs` (
CREATE TABLE IF NOT EXISTS `fx_votes_logs` (
`id` int(14) NOT NULL AUTO_INCREMENT,
`idaccount` int(10) NOT NULL,
`idvote` int(10) NOT NULL,
`lasttime` int(10) NOT NULL
`points` int(10) NOT NULL,
`lasttime` int(10) NOT NULL,
`expired_at` int(10) NOT NULL,
KEY `Índice 1` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment