• [MOD] Rating by using AJAX functions-rating without reload (used by V@no) 5 0 5 1
Currently:  

Author Topic: [MOD] Rating by using AJAX functions-rating without reload (used by V@no)  (Read 57162 times)

0 Members and 1 Guest are viewing this topic.

Offline koikonut

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
    • http://www.konradin.net
Hello!

The problem is, that in that case there is no point in update the Rating-Display because it didn't change. So, there are no attributes for the second element-ID. Know I made a solution for this javascript-error, but it is not very elegant, but works (updating the same lement two times..):

Code: [Select]
  $votes = $old_votes + 1;
  echo "kbdisplay||".rating_pic($new_rating)." ".$new_rating." (".$votes." ".$lang['votes'].")||";
        }
        else
        {
          $msg = $lang['voting_error'];
        }
      }
      else {
        $msg = $lang['already_voted'];
      }
    }
    else {
      $msg = $lang['voting_error'];
    }
  }
  else
  {
    $msg = $lang['no_permission'];
  }
}
else
{
  $msg = "Security violation";
}
die("kbrating||".$msg);

replace with:

Code: [Select]
  $votes = $old_votes + 1;
  $msg1 = "kbdisplay||".rating_pic($new_rating)." ".$new_rating." (".$votes." ".$lang['votes'].")||";
        }
        else
        {
  $msg1 = "kbrating||-||";
          $msg = $lang['voting_error'];
        }
      }
      else {
        $msg1 = "kbrating||-||";
        $msg = $lang['already_voted'];
      }
    }
    else {
      $msg1 = "kbrating||-||";
      $msg = $lang['voting_error'];
    }
  }
  else
  {
    $msg1 = "kbrating||-||";
    $msg = $lang['no_permission'];
  }
}
else
{
  $msg1 = "kbrating||-||";
  $msg = "Security violation";
}
echo $msg1;
die("kbrating||".$msg);

bye Konradin

Offline live@ct

  • Sr. Member
  • ****
  • Posts: 348
    • View Profile
mm no, its not working, nothing happend in the record of votes...
Existen 10 tipos de personas, los que entienden el codigo binario y los que no.

Offline koikonut

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
    • http://www.konradin.net
mm no, its not working, nothing happend in the record of votes...

Todavía el mismo error? En mi pagina también me dió cuenta el error que describiste y con esa modificación solvé el problema  :roll: Por favor escribe cual es el error.

Gracias y saludos, Konradin

Offline live@ct

  • Sr. Member
  • ****
  • Posts: 348
    • View Profile
pues has de cuenta q, ya modifique lo que pusite, y al momento de calificar no me dice nada de q ya se ah calificado, me dice q ya se ah puntuado la imagen y no graba el voto, al parecer eso funciona con las ya votadas y creia q funcionaba, pero al momento de q quiero votar las otras imagenes q no eh votado pasa lo mismo, dice gracias por puntuar pero el voto no se guarda y muestra algo totalmente diferente, digamos habia 32 votos, le doy calificar y aparecen 26 votos  :? luego le dor refresh y todo queda como al inicio 32

Regrese como estaba originalmente y ya funciona de nuevo, pero me di cuenta q hay veces q otras imagenes q ya has votado te dice gracias por puntuar pero no califica la imagen pero las q no has calificado si funciona bien
Existen 10 tipos de personas, los que entienden el codigo binario y los que no.

Offline koikonut

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
    • http://www.konradin.net
pues has de cuenta q, ya modifique lo que pusite, y al momento de calificar no me dice nada de q ya se ah calificado, me dice q ya se ah puntuado la imagen y no graba el voto, al parecer eso funciona con las ya votadas y creia q funcionaba, pero al momento de q quiero votar las otras imagenes q no eh votado pasa lo mismo, dice gracias por puntuar pero el voto no se guarda y muestra algo totalmente diferente, digamos habia 32 votos, le doy calificar y aparecen 26 votos  :? luego le dor refresh y todo queda como al inicio 32

Regrese como estaba originalmente y ya funciona de nuevo, pero me di cuenta q hay veces q otras imagenes q ya has votado te dice gracias por puntuar pero no califica la imagen pero las q no has calificado si funciona bien

Cuando yo estoy probando el script en tu pagina con la calificación todo funciona muy bien. También la calculación de los votos después. No sé cual es el problema...
Porque pusiste void('0')? Es necesario para el javascript?

Quizás tienes que eliminar tus cookies para que funcione bien. Para que no se vea el rating si ya has calificado necesitas el script "Votes saved in Db" creo.

Chao

Offline live@ct

  • Sr. Member
  • ****
  • Posts: 348
    • View Profile
Si funciona muy bien todo pero con el codigo original
pero cuando una ya esta votada sale el error de java script q comente al inicio, tu has probado q funciona porq regrese al codigo inicial q funcionaba, ya que no puedo dejar algo q no funcione bien,
ahorita volvi a intentar cambiar el codigo q pusiste y al parecer al inicio funciona, pero cuando le doy a otra q ya habia calificado que queda en: Loading... y el mismo error javascript
Existen 10 tipos de personas, los que entienden el codigo binario y los que no.

Offline koikonut

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
    • http://www.konradin.net
hmm, no tengo idea porque podría ser...

Aca te voy a escribir otra vez el codigo completo del documento rating.php. Mi header.html no va a servir mucho porque ya lo modifiqué para funciones similares con "mi caja".

Code: [Select]
<?php
/**************************************************************************
 *                                                                        *
 *    4images - A Web Based Image Gallery Management System               *
 *    ----------------------------------------------------------------    *
 *                                                                        *
 *             File: rateimage.php                                        *
 *        Copyright: (C) 2002 Jan Sorgalla                                *
 *            Email: jan@4homepages.de                                    *
 *              Web: http://www.4homepages.de                             *
 *    Scriptversion: 1.7.2                                                *
 *                                                                        *
 *    Never released without support from: Nicky (http://www.nicky.net)   *
 *                                                                        *
 **************************************************************************
 *                                                                        *
 *    Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz-       *
 *    bedingungen (Lizenz.txt) f&#1100;r weitere Informationen.                 *
 *    ---------------------------------------------------------------     *
 *    This script is NOT freeware! Please read the Copyright Notice       *
 *    (Licence.txt) for further information.                              *
 *                                                                        *
 *************************************************************************/

$rating $_REQUEST['rating'];
$id $_REQUEST['id'];

$main_template '';
$nozip 1;
define('GET_CACHES'1);
define('ROOT_PATH''./');
include(
ROOT_PATH.'global.php');
require(
ROOT_PATH.'includes/sessions.php');
$user_access get_permission();
function 
update_image_rating_new($image_id$rating$image_row, &$new_rating, &$old_votes) {
  global 
$site_db;
  
$old_votes $image_row['image_votes'];
  
$old_rating $image_row['image_rating'];
  
$new_rating = (($old_rating $old_votes) + $rating) / ($old_votes 1);
  
$new_rating sprintf("%.2f"$new_rating);
  
$sql "UPDATE ".IMAGES_TABLE."
          SET image_votes = (
$old_votes + 1), image_rating = '$new_rating'
          WHERE image_id = 
$image_id";
  return 
$site_db->query($sql);
}
//-----------------------------------------------------
//--- Save Rating -------------------------------------
//-----------------------------------------------------
if ($id) {
  
$rating intval($rating);
  
$cookie_name = (defined("COOKIE_NAME")) ? COOKIE_NAME "4images_";
  
$cookie_rated = isset($HTTP_COOKIE_VARS[$cookie_name.'rated']) ? unserialize(stripslashes($HTTP_COOKIE_VARS[$cookie_name.'rated'])) : array();
  
$sql "SELECT cat_id, image_votes, image_rating
          FROM "
.IMAGES_TABLE."
          WHERE image_id = 
$id";
  
$image_row $site_db->query_firstrow($sql);
  if (
check_permission("auth_vote"$image_row['cat_id']))
  {

    if (
$rating && $rating <= MAX_RATING && $id) {
      if (!isset(
$session_info['rated_imgs'])) {
        
$session_info['rated_imgs'] = $site_sess->get_session_var("rated_imgs");
      }
      
$split_list = array();
      if (!empty(
$session_info['rated_imgs'])) {
        
$split_list explode(" "$session_info['rated_imgs']);
      }
      if (!
in_array($id$split_list) && !in_array($id$cookie_rated)) {
        if (
update_image_rating_new($id$rating$image_row$new_rating$old_votes))
        {
          
$session_info['rated_imgs'] .= " ".$id;
          
$session_info['rated_imgs'] = trim($session_info['rated_imgs']);
          
$site_sess->set_session_var("rated_imgs"$session_info['rated_imgs']);
          
$cookie_rated[] = $id;
          
$cookie_expire time() + 60 60 24 4;
          
setcookie($cookie_name.'rated'serialize($cookie_rated), $cookie_expireCOOKIE_PATHCOOKIE_DOMAINCOOKIE_SECURE);
          
$msg $lang['voting_success'];
  $votes $old_votes 1;
  $msg1 "kbdisplay||".rating_pic($new_rating)." ".$new_rating." (".$votes." ".$lang['votes'].")||";
        }
        else
        {
  $msg1 "kbrating||-||";
          
$msg $lang['voting_error'];
        }
      }
      else {
        
$msg1 "kbrating||-||";
        
$msg $lang['already_voted'];
      }
    }
    else {
      
$msg1 "kbrating||-||";
      
$msg $lang['voting_error'];
    }
  }
  else
  {
    
$msg1 "kbrating||-||";
    
$msg $lang['no_permission'];
  }
}
else
{
  
$msg1 "kbrating||-||";
  
$msg "Security violation";
}
echo 
$msg1;
die(
"kbrating||".$msg);
?>

Ojala que puedes solver el problema :-) Considera que deben estar elementos con id="kbdisplay" y id="kbrating".

Buenas Noches, Ko

Offline lotus69

  • Newbie
  • *
  • Posts: 11
    • View Profile
for those who like me, have issue with special characters,
simply insert after $user_access = get_permission();
Code: [Select]
header("Content-type: text/css; charset=".$lang['charset']."");

$lang['charset'] must be set with "iso-8859-1" in your language main.php file

Offline BartAfterDark

  • Hero Member
  • *****
  • Posts: 520
    • View Profile
Could you please post the complete script (need the thing with the stars) :/

Offline Ch*yeuk

  • Newbie
  • *
  • Posts: 27
    • View Profile
Excellent! I've installed it and it's working. Though it did take me two tries .. =P

Offline fabio

  • Newbie
  • *
  • Posts: 36
    • View Profile
i don`t know what i`m doing wrong but i have the problem discussed earlier
after voting i ge the loading message and no thank you although i`ve applied the changes konradin suggested in the rating.php




Offline BartAfterDark

  • Hero Member
  • *****
  • Posts: 520
    • View Profile
i don`t know what i`m doing wrong but i have the problem discussed earlier
after voting i ge the loading message and no thank you although i`ve applied the changes konradin suggested in the rating.php





Did you remember to add this
Code: [Select]
$site_template->register_vars("rating_url", ROOT_PATH."rating.php?id=".$image_id); to page_header.php or details.php?

Offline BartAfterDark

  • Hero Member
  • *****
  • Posts: 520
    • View Profile
Is there anyway to make the star rating update with the the new rating (when this mod is being used http://www.4homepages.de/forum/index.php?topic=923.0 )

Offline fabio

  • Newbie
  • *
  • Posts: 36
    • View Profile
yes i have :(
i added   {rating_url} the the path seeme to be registered correctly
also when i`ve already voted i get the corresponding message
so i think it has something to do with rating .php (??)


somene posted this link http://komodomedia.com/blog/index.php/2005/08/24/creating-a-star-rater-using-css/
i`ve tried it and works

in rate_form.html
inside the span tags replace the code with this
<ul class='star-rating'>
  <li><a href="javascript:rate('1');" title='Rate this 1 star out of 5' class='one-star'>1</a></li>
  <li><a href='"javascript:rate('2');" title='Rate this 2 stars out of 5' class='two-stars'>2</a></li>
  <li><a href="javascript:rate('3');" title='Rate this 3 stars out of 5' class='three-stars'>3</a></li>
  <li><a href="javascript:rate('4');" title='Rate this 4 stars out of 5' class='four-stars'>4</a></li>
  <li><a href="javascript:rate('5');" title='Rate this 5 stars out of 5' class='five-stars'>5</a></li>
</ul>
      

and add in style.css

/*             styles for the star rater                */
.star-rating{
   list-style:none;
   margin: 0px;
   padding:0px;
   width: 100px;
   height: 20px;
   position: relative;
   background: url(star_rating.gif) top left repeat-x;      
}
.star-rating li{
   padding:0px;
   margin:0px;
   /*\*/
   float: left;
   /* */
}
.star-rating li a{
   display:block;
   width:20px;
   height: 20px;
   text-decoration: none;
   text-indent: -9000px;
   z-index: 20;
   position: absolute;
   padding: 0px;
}
.star-rating li a:hover{
   background: url(star_rating.gif) left bottom;
   z-index: 1;
   left: 0px;
}
.star-rating a.one-star{
   left: 0px;
}
.star-rating a.one-star:hover{
   width:20px;
}
.star-rating a.two-stars{
   left:20px;
}
.star-rating a.two-stars:hover{
   width: 40px;
}
.star-rating a.three-stars:hover{
   width: 60px;
}
.star-rating a.three-stars{
   left: 40px;
}
.star-rating a.four-stars{
   left: 60px;
}   
.star-rating a.four-stars:hover{
   width: 80px;
}
.star-rating a.five-stars{
   left: 80px;
}
.star-rating a.five-stars:hover{
   width: 100px;
}
   
don`t foregt to change the paths of the images    
ps it`s for a 20X20p star image

Offline leh00

  • Newbie
  • *
  • Posts: 22
    • View Profile
Hi fabio,

how does your javascript looks like? You did not post it...

You should have something like this in : (sample not working...)

Code: [Select]
function rate() {
  id=document.all.fieldname.value;
  var text = 'loading...';
  document.getElementById('objectname').innerHTML = text;

  req.open('GET', '{rating_url}&rating=' + id, true);
   req.onreadystatechange = handleResponse;
  req.send(null);
}


Regards

Leh00