\brief Page de vote pour un site. \warning Interdit aux bots ! */ require_once($_SERVER['DOCUMENT_ROOT'].'/core.class.php5'); // function parser() { global $tpl; $tpl->parse('global/header.tpl'); $tpl->parse('services/topsites/bar.tpl'); $tpl->parse('services/topsites/in.tpl'); $tpl->parse('global/footer.tpl'); } $tpl=new gagatemplate(pf_core::gaga_ini_dir()); $config=new config(); $config->service_id='TopSites'; $config->service_ident=4; $sql_c=new MySqreuil(); $pass_cookie=new cookie_choco(); pf_core::gaga_autoconfig($tpl); $rq_result=$sql_c->query('SELECT COUNT(*) AS n FROM topsites WHERE statut=0'); $n=$sql_c->fetch($rq_result); $n=(int)$n['n']; $tpl->assign(array( 'service_sel' => 6, 'page_title' => utils::service_name($config->service_ident), 'ts_no_votes' => false, 'err_msg' => '', 'err_type' => 2, 'fatal_err' => false, 'is_modo' => $pass_cookie->is_admin(4), 'num_ts_waiting' => $n )); // G�n�ration d'une cl� al�atoire $key=crc32(mt_rand()); $s=(int)$_GET['s']; $rq_result=$sql_c->query( 'SELECT '. 'id, '. 'statut, '. 'nom, '. 'timer_disabled, '. 'timer_kill_votes, '. 'timer_kill_visites, '. 'timer_autodelete '. 'FROM topsites '. 'WHERE id = '.$s, true ); if ($sql_c->num_rows($rq_result) <= 0) { $tpl->assign(array( 'err_msg' => 'Ce site n\'existe pas.', 'err_type' => 2, 'fatal_err' => true )); parser(); die(); } $site=$sql_c->fetch($rq_result); $site['id']=(int)$site['id']; if ($site['statut'] != 1) { if ($site['statut'] == 2) { if ($site['timer_disabled'] < time()) // P�nalit� p�rim�e { $sql_c->query( 'UPDATE topsites SET '. 'timer_disabled=NULL , '. 'statut='.$site['old_status'].' , '. 'old_status=NULL '. 'WHERE (id = '.$s.')', true ); $site['statut']=$site['old_status']; } else { $tpl->assign(array( 'ts_no_votes' => true, 'ts_dis_time' => date('j/n/Y @ G:i:s', (int)$site['timer_disabled']) )); parser(); die(); } } if ($site['statut'] != 1) { $tpl->assign(array( 'err_msg' => 'Ce site est désactivé.', 'fatal_err' => true )); parser(); die(); } } if (getenv('HTTP_X_FORWARDED_FOR')) { $ip=getenv('HTTP_X_FORWARD_FOR'); } else { $ip=getenv('REMOTE_ADDR'); } $host=@gethostbyaddr($ip); $my_ip=$ip.'@'.$host; class frm implements frm_combo { function __construct() { if ($_POST == array()) { $this->form_disp(); } else { $this->form_treat(); } } function form_disp($err='', $errtype=false, $redisp_form=true) { global $tpl, $config, $site, $key; $tpl->assign(array( 'err_msg' => $err, 'err_type' => (($errtype === false) ? 2 : $errtype), 'fatal_err' => !$redisp_form, 'ts_id' => (int)$site['id'], 'ts_name' => utils::strprotect($site['nom']), 'g_key' => utils::strprotect($key) )); parser(); die(); } function form_treat() { global $config, $sql_c, $pass_cookie, $site, $s, $my_ip; // [ZT] La cl� de r�f�rence est une cha�ne repr�sentant un d�cimal sign� (entre -2^31 et 2^31-1), // celle entr�e par l'utilisateur est une cha�ne d'un hexad�cimal sur 8 octets exactement (entre 0x00000000 et 0xFFFFFFFF). if (sprintf('%x', $_POST['ref']) != $_POST['vote_key']) { $this->form_disp('Le code que vous avez entré est erronné.', 2); } $rq_result=$sql_c->query( 'SELECT '. 't_ip.act , '. 't_ip.date_act , '. 't_ip.ip_host , '. 'tv.* '. 'FROM topsites_ip t_ip '. 'LEFT JOIN topsites_votes tv ON t_ip.id=tv.ip_host_link '. 'WHERE tv.site_voted='.$site['id'].' AND tv.time_vote > '.(time() - 86400).' AND t_ip.act=1 AND t_ip.ip_host=\''.$sql_c->escape($my_ip).'\'', true ); if ($sql_c->num_rows($rq_result) > 0) { $this->form_disp('Votre vote a déjà été pris en compte.
Vous ne pouvez voter qu\'une seule fois par jour pour un même site.', 1); } $rq_result=$sql_c->query( 'SELECT '. 'id '. 'FROM topsites_ip '. 'WHERE ((act=1) AND (ts_id='.$site['id'].') AND (ip_host=\''.$sql_c->escape($my_ip).'\'))', true ); if ($sql_c->num_rows($rq_result) <= 0) { $sql_c->query( 'INSERT INTO topsites_ip SET '. 'member_id='.(($pass_cookie->is_valid()) ? $pass_cookie->datas['user_id'] : 'NULL').' , '. 'ts_id='.$s.' , '. 'act=1 , '. 'ip_host=\''.$sql_c->escape($my_ip).'\' , '. 'date_act='.time(), true ); $ip_ident=$sql_c->last_index(); } else { $ip_ident=$sql_c->fetch($rq_result); $sql_c->query( 'UPDATE topsites_ip SET '. (($pass_cookie->is_valid()) ? 'member_id='.$pass_cookie->datas['user_id'].' , ' : ''). 'ip_host=\''.$sql_c->escape($my_ip).'\' , '. 'date_act='.time().' '. 'WHERE act=1 AND ts_id='.$site['id'].' AND ip_host=\''.$sql_c->escape($my_ip).'\'', true ); } $sql_c->query( 'INSERT INTO topsites_votes SET '. 'member_id='.(($pass_cookie->is_valid()) ? $pass_cookie->datas['user_id'] : 'NULL').' , '. 'site_voted='.$site['id'].' , '. 'is_valid=1 , '. 'ip_host_link='.$ip_ident['id'].' , time_vote='.time(), true ); $sql_c->query( 'UPDATE topsites SET '. 'timer_kill_votes='.(time() + $config->timer_disable_votes).' '. 'WHERE (id = '.$s.')', true ); $this->form_disp('Votre vote a bien été enregistré !', 0, false); } } new frm(); ?>