Voting
{php} global $db; $id_gatto = $_REQUEST['id_gatto']; $voto = $_REQUEST['voto']; $ip_utente = $_SERVER['REMOTE_ADDR']; $messaggio = ""; $db = JFactory::getDBO(); $sql = "SELECT * FROM vota WHERE id_gatto = $id_gatto AND voto = $voto"; $db->setQuery($sql); $rows = $db->loadRow(); $cookie_gatto = "catbookvota_" . $id_gatto; if($rows != null){ //controllo ip if($rows[2] != $ip_utente){ //controllo valore cookie if(!isset($_COOKIE[$cookie_gatto])){ //incrementiamo totale del risultato trovato $tot = $rows[4]+1; $query2 = "UPDATE vota SET totale = $tot, ip_utente = '$ip_utente', data = CURDATE() WHERE id_gatto = $id_gatto AND voto = $voto"; $db->setQuery($query2); $db->query(); $messaggio = "Thank you for your vote!"; setCookie($cookie_gatto, $id_gatto, time()+3600*24*30); }else{ $messaggio = "
Your vote has been already registered!!!"; } }else{ //utente giĆ votato $messaggio = "
Your vote has been already registered!!!"; } }else{ if(!isset($_COOKIE[$cookie_gatto])){ //inserimento voto $sql2 = "INSERT INTO vota(id_gatto,ip_utente,voto,totale,data) VALUES ($id_gatto,'$ip_utente',$voto,1,CURDATE())"; $db->setQuery($sql2); $db->query(); $messaggio = "
Thank you for your vote!"; setCookie($cookie_gatto, $id_gatto, time()+3600*24*30); }else{ $messaggio = "
You can vote cats only once!!!"; } } echo "
" . $messaggio . "
back to profile
The top 4 voted profiles will be shown on the homepage of CatBook.it:
";
/*
if ($db->getErrorNum()){
echo $db->getErrorMsg();
}
*/
{/php}
- the most beautiful cat
- the nicest cat
- the most tender cat
- the most elegant cat