Welcome Guest, Not a member yet? Register   Sign In
Ajax star rating bar
#19

[eluser]wiredesignz[/eluser]
And were the ratings updated after the redirect?

Try this updated, updated version of ratings_rpc:
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Ratings_rpc extends Controller
{
    function Ratings_rpc()
    {
        parent::Controller();
        $this->load->model('ratings_model');
        
        $this->output->set_header("Cache-Control: no-cache");
        $this->output->set_header("Pragma: nocache");
    }
    
    function index()
    {        
        //get the values
        $vote_sent = preg_replace("/[^0-9]/", "", $this->input->get('j'));
        $id_sent   = preg_replace("/[^0-9a-zA-Z]/", "", $this->input->get('q'));
        $ip_num    = preg_replace("/(^0-9\.)/", "", $this->input->get('t'));
        $units     = preg_replace("/(^0-9)/", "", $this->input->get('c'));
        $ip        = $this->input->ip_address();

        //added to detect if javascript is disabled `r=1`
        $nojs = (bool)preg_replace("/(^0-9)/", "", $this->input->get('r'));
        
        //default values
        $checkIP = NULL;
        $count = 0;
        $current_rating = 0;
        $sum = 0;
        $tense = "votes"; // 0 votes
        
        //get the current values!
        if ($numbers = $this->ratings_model->findBy_id($id_sent))
        {
            // kill the script if vote limit is exceeded.
            if ($vote_sent > $numbers['vote_limit']) die("Sorry, vote appears to be invalid.");
            
            $checkIP = unserialize($numbers['used_ips']);
            $count = $numbers['total_votes']; //how many votes total
            $current_rating = $numbers['total_value']; //total number of rating
            $sum = $vote_sent + $current_rating; // add together the current vote value and the total vote value
            $tense = ($count == 1) ? "vote" : "votes"; //plural form votes/vote
        }
        
        // checking to see if the first vote has been tallied or increment the current number of votes
        ($sum == 0 ? $added = 0 : $added = $count + 1);
        
        // if it is an array i.e. already has entries the push in another value
        (is_array($checkIP) ? array_push($checkIP, $ip_num) : $checkIP = array($ip_num));
        
        //if the user hasn't yet voted, then vote normally...
        if ($this->ratings_model->countBy_ip($ip, $id_sent) == 0)
        {            
            //make sure vote is valid and IP matches - no monkey business!
            if ($vote_sent > 0 && $ip == $ip_num)
            {
                $this->ratings_model->updateBy_id($id_sent, array(
                    'total_votes' => $added,
                    'total_value' => $sum,
                    'used_ips'    => serialize($checkIP),
                ));
            }
        }
        
        //get the new values!
        if ($numbers = $this->ratings_model->findBy_id($id_sent))
        {
            $checkIP = unserialize($numbers['used_ips']);
            $count = $numbers['total_votes']; //how many votes total
            $current_rating = $numbers['total_value']; //total number of rating
            $tense = ($count == 1) ? "vote" : "votes"; //plural form votes/vote
            $units = $numbers['vote_limit']; //get the vote limit
        }    
        
        if($nojs)  //javascript is disabled so redirect
        {
            //set nojspage in config/ratings.php
            redirect($this->config->item('nojspage'));
        }
        
        $data = array(
            'id_sent' => $id_sent,
            'current_rating' => $current_rating,
            'count' => $count,
            'sum'   => $sum,
            'added' => $added,
            'units' => $units,
            'tense' => $tense,
            'rating_unitwidth' => $this->config->item('rating_unitwidth'),
        );
        
        $this->load->view('newback_view', $data);
    }
}


Messages In This Thread
Ajax star rating bar - by El Forum - 02-14-2008, 12:12 AM
Ajax star rating bar - by El Forum - 02-14-2008, 12:14 AM
Ajax star rating bar - by El Forum - 02-14-2008, 12:16 AM
Ajax star rating bar - by El Forum - 02-14-2008, 12:20 AM
Ajax star rating bar - by El Forum - 02-14-2008, 12:32 AM
Ajax star rating bar - by El Forum - 02-14-2008, 12:51 AM
Ajax star rating bar - by El Forum - 02-15-2008, 12:13 AM
Ajax star rating bar - by El Forum - 02-16-2008, 07:20 AM
Ajax star rating bar - by El Forum - 02-16-2008, 07:36 AM
Ajax star rating bar - by El Forum - 02-16-2008, 11:49 AM
Ajax star rating bar - by El Forum - 02-16-2008, 03:34 PM
Ajax star rating bar - by El Forum - 02-16-2008, 06:06 PM
Ajax star rating bar - by El Forum - 02-16-2008, 07:26 PM
Ajax star rating bar - by El Forum - 02-18-2008, 12:11 AM
Ajax star rating bar - by El Forum - 02-18-2008, 03:25 AM
Ajax star rating bar - by El Forum - 02-18-2008, 02:43 PM
Ajax star rating bar - by El Forum - 02-18-2008, 03:14 PM
Ajax star rating bar - by El Forum - 02-18-2008, 08:40 PM
Ajax star rating bar - by El Forum - 02-18-2008, 08:43 PM
Ajax star rating bar - by El Forum - 02-18-2008, 08:47 PM
Ajax star rating bar - by El Forum - 02-18-2008, 08:52 PM
Ajax star rating bar - by El Forum - 02-18-2008, 08:56 PM
Ajax star rating bar - by El Forum - 02-18-2008, 09:51 PM
Ajax star rating bar - by El Forum - 02-18-2008, 10:20 PM
Ajax star rating bar - by El Forum - 02-18-2008, 10:32 PM
Ajax star rating bar - by El Forum - 02-19-2008, 12:45 AM
Ajax star rating bar - by El Forum - 02-19-2008, 02:00 AM
Ajax star rating bar - by El Forum - 02-19-2008, 06:23 PM
Ajax star rating bar - by El Forum - 02-19-2008, 09:13 PM
Ajax star rating bar - by El Forum - 03-14-2008, 06:18 PM
Ajax star rating bar - by El Forum - 03-17-2008, 01:17 PM
Ajax star rating bar - by El Forum - 03-18-2008, 07:54 PM
Ajax star rating bar - by El Forum - 03-19-2008, 07:53 PM
Ajax star rating bar - by El Forum - 03-19-2008, 08:06 PM
Ajax star rating bar - by El Forum - 06-02-2008, 04:05 PM
Ajax star rating bar - by El Forum - 06-05-2008, 10:01 PM
Ajax star rating bar - by El Forum - 06-05-2008, 10:25 PM
Ajax star rating bar - by El Forum - 06-06-2008, 06:39 AM
Ajax star rating bar - by El Forum - 06-06-2008, 12:28 PM
Ajax star rating bar - by El Forum - 06-11-2008, 06:53 PM
Ajax star rating bar - by El Forum - 06-12-2008, 01:00 PM
Ajax star rating bar - by El Forum - 06-17-2008, 07:42 AM
Ajax star rating bar - by El Forum - 06-17-2008, 11:04 AM
Ajax star rating bar - by El Forum - 06-17-2008, 10:50 PM
Ajax star rating bar - by El Forum - 06-23-2008, 11:43 AM
Ajax star rating bar - by El Forum - 08-24-2008, 07:10 AM
Ajax star rating bar - by El Forum - 10-15-2008, 12:30 AM
Ajax star rating bar - by El Forum - 02-24-2009, 04:11 AM
Ajax star rating bar - by El Forum - 06-03-2009, 10:47 PM
Ajax star rating bar - by El Forum - 06-03-2009, 10:56 PM
Ajax star rating bar - by El Forum - 06-04-2009, 04:34 AM
Ajax star rating bar - by El Forum - 06-04-2009, 05:27 AM
Ajax star rating bar - by El Forum - 08-09-2009, 01:26 PM
Ajax star rating bar - by El Forum - 10-28-2009, 03:18 AM
Ajax star rating bar - by El Forum - 07-01-2010, 03:39 PM
Ajax star rating bar - by El Forum - 07-02-2010, 01:18 AM
Ajax star rating bar - by El Forum - 07-02-2010, 02:04 AM
Ajax star rating bar - by El Forum - 07-02-2010, 05:41 AM
Ajax star rating bar - by El Forum - 07-04-2010, 12:14 AM
Ajax star rating bar - by El Forum - 03-10-2011, 01:56 PM
Ajax star rating bar - by El Forum - 06-26-2011, 08:53 PM
Ajax star rating bar - by El Forum - 08-16-2011, 09:43 AM
Ajax star rating bar - by El Forum - 02-01-2012, 10:03 AM



Theme © iAndrew 2016 - Forum software by © MyBB