11548 sujets

JavaScript, DOM et API Web HTML5

bonjour a tous, je viens vers vous car je suis incapable de récupérer l'id de session en cours pour l'enregistrer dans la bdd:
voici ma page qui affiche les votes:
<?php include('config.php'); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!--HEAD-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Business Template, Download Free CSS Template</title>
<meta name="keywords" content="..." />
<meta name="description" content="..." />
<link href="webroot/css/style.css" rel="stylesheet" type="text/css" />
<!--vote-->
<script type="text/javascript" language="javascript" src="js/behavior.js"></script>
<script type="text/javascript" language="javascript" src="js/rating.js"></script>
<link rel="stylesheet" type="text/css" href="webroot/css/rating.css" />
<!--fin vote-->

<link rel="stylesheet" href="jquery/jRating.jquery.css" type="text/css" />

<style type="text/css">
		body {margin:15px;font-family:Arial;font-size:13px}
		a img{border:0}
		.datasSent, .serverResponse{margin-top:20px;width:470px;height:73px;border:1px solid #F0F0F0;background-color:#F8F8F8;padding:10px;float:left;margin-right:10px}
		.datasSent{width:200px;position:fixed;left:680px;top:0}
		.serverResponse{position:fixed;left:680px;top:100px}
		.datasSent p, .serverResponse p {font-style:italic;font-size:12px}
		.exemple{margin-top:15px;}
		.clr{clear:both}
		pre {margin:0;padding:0}
		.notice {background-color:#F4F4F4;color:#666;border:1px solid #CECECE;padding:10px;font-weight:bold;width:600px;font-size:12px;margin-top:10px}
</style>

<script type="text/javascript" src="tuto/mootools-1.2.1-core-yc.js"></script>
<script type="text/javascript" src="tuto/fonctions.js"></script>
<style type="text/css">

.zone_vote img {
	cursor:pointer;
}
</style>


</head>
<!--BODY-->
<body>
    <?php require('_drawrating.php'); ?>

                        
<?php if(isset($_SESSION['username'])) { ?>
    <!--ZONE VOTES-->                        
    <table width="100%">	
        <colgroup>
            <col span="1" width="50%"/>
            <col span="1" width="50%"/>			
        </colgroup>			
        <tr>
            <td>Question 1 <?php echo rating_bar($donnees['id_chien'].'-1',$donnees['id_chien'],'1','10'); ?></td>					
            <td>Question 6 <?php echo rating_bar($donnees['id_chien'].'-6',$donnees['id_chien'],'6','10'); ?></td>					
        </tr>
        <tr >
             <td colspan="2"><hr /></td>
        </tr>
        <tr>
             <td>Question 2 <?php echo rating_bar($donnees['id_chien'].'-2',$donnees['id_chien'],'2','10'); ?></td>					
                <td>Question 7 <?php echo rating_bar($donnees['id_chien'].'-7',$donnees['id_chien'],'7','10'); ?></td>					
        </tr>
        <tr >
             <td colspan="2"><hr /></td>
        </tr>				
        <tr>
             <td>Question 3 <?php echo rating_bar($donnees['id_chien'].'-3',$donnees['id_chien'],'3','10'); ?></td>					
            <td>Question 8 <?php echo rating_bar($donnees['id_chien'].'-8',$donnees['id_chien'],'8','10'); ?></td>					
        </tr>
        <tr >
            <td colspan="2"><hr /></td>
        </tr>				
        <tr>
            <td>Question 4 <?php echo rating_bar($donnees['id_chien'].'-4',$donnees['id_chien'],'4','10'); ?></td>					
            <td>Question 9 <?php echo rating_bar($donnees['id_chien'].'-9',$donnees['id_chien'],'9','10'); ?></td>					
        </tr>
        <tr>
            <td colspan="2"><hr /></td>
        </tr>				
        <tr>
            <td>Question 5 <?php echo rating_bar($donnees['id_chien'].'-5',$donnees['id_chien'],'5','10'); ?></td>					
            <td>Question 10 <?php echo rating_bar($donnees['id_chien'].'-10',$donnees['id_chien'],'10','10'); ?></td>					
        </tr>				
    </table>

</body>
</html>


voici le fichier _drawrating.php:
<?php

function rating_bar($id, $chien='', $question='', $units='', $static='') { 

require('_config-rating.php');
	
$ip = $_SERVER['REMOTE_ADDR'];
if (!$units) {$units = 10;}
if (!$static) {$static = FALSE;}

// recherche d'informations sur les votes
$query=mysql_query("SELECT 
						  total_votes, 
						  total_value, 
						  used_ips FROM $rating_dbname.$rating_tableName 
						  WHERE id='$id' ")or die(" Error: ".mysql_error());


// insert si les champs n'existe pas
if (mysql_num_rows($query) == 0) {
$req1 = "INSERT INTO $rating_dbname.$rating_tableName (`id`,`id_chien`,`id_question`,`total_votes`, `total_value`, `used_ips`) VALUES ('$id','$chien','$question', '0', '0', '')";

$result = mysql_query($req1);
}

$numbers=mysql_fetch_assoc($query);


if ($numbers['total_votes'] < 1) {
	$count = 0;
} else {
	$count=$numbers['total_votes']; //combien de vote total
}
$current_rating=$numbers['total_value']; //le nombre total d'&#65533;valuer ajout&#65533; ensemble et conserv&#65533;
$tense=($count==1) ? "vote" : "votes"; //votes/vote au pluriel

// d&#65533;terminez si l'utilisateur a vot&#65533;, donc nous savons comment tirer l'ul/li
$voted=mysql_num_rows(mysql_query("SELECT used_ips FROM $rating_dbname.$rating_tableName WHERE used_ips LIKE '%".$ip."%' AND id='".$id."' ")); 

// now draw the rating bar
$rating_width = @number_format($current_rating/$count,2)*$rating_unitwidth;
$rating1 = @number_format($current_rating/$count,1);
$rating2 = @number_format($current_rating/$count,2);


if ($static == 'static') {

		$static_rater = array();
		$static_rater[] .= "\n".'<div class="ratingblock">';
		$static_rater[] .= '<div id="unit_long'.$id.'">';
		$static_rater[] .= '<ul id="unit_ul'.$id.'" class="unit-rating" style="width:'.$rating_unitwidth*$units.'px;">';
		$static_rater[] .= '<li class="current-rating" style="width:'.$rating_width.'px;">Currently '.$rating2.'/'.$units.'</li>';
		$static_rater[] .= '</ul>';
		$static_rater[] .= '<p class="static">'.$id.'. Vote: <strong> '.$rating1.'</strong>/'.$units.' ('.$count.' '.$tense.' cast) <em>This is \'static\'.</em></p>';
		$static_rater[] .= '</div>';
		$static_rater[] .= '</div>'."\n\n";

		return join("\n", $static_rater);


} else {

      $rater ='';
      $rater.='<div class="ratingblock">';

      $rater.='<div id="unit_long'.$id.'">';
      $rater.='  <ul id="unit_ul'.$id.'" class="unit-rating" style="width:'.$rating_unitwidth*$units.'px;">';
      $rater.='     <li class="current-rating" style="width:'.$rating_width.'px;">Currently '.$rating2.' /'.$units.'</li>';

      for ($ncount = 1; $ncount <= $units; $ncount++) { // loop from 1 to the number of units
           if(!$voted) { // if the user hasn't yet voted, draw the voting stars
              $rater.='<li><a href="db.php?j='.$ncount.'&amp;q='.$id.'&amp;t='.$ip.'&amp;c='.$units.'" title="'.$ncount.' out of '.$units.'" class="r'.$ncount.'-unit rater" rel="nofollow">'.$ncount.'</a></li>';
           }
      }
      $ncount=0; // resets the count

      $rater.='  </ul>';
      $rater.='  <p';
      if($voted){ $rater.=' class="voted"'; }
      $rater.='>Moyenne: <strong><font color="#26c41a"></strong>'.$rating1.'</font>/'.$units.' ('.$count.' '.$tense.')';
      $rater.='  </p>';
      $rater.='</div>';
      $rater.='</div>';
      return $rater;
 }
}
?>



et le js, et il me semble comprendre que c'est ici que je doit faire les modif mais j'en suis incapable:
var xmlhttp
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	  try {
	  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
	 } catch (e) {
	  try {
	    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	  } catch (E) {
	   xmlhttp=false
	  }
	 }
	@else
	 xmlhttp=false
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	 try {
	  xmlhttp = new XMLHttpRequest();
	 } catch (e) {
	  xmlhttp=false
	 }
	}
	function myXMLHttpRequest() {
	  var xmlhttplocal;
	  try {
	    xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
	 } catch (e) {
	  try {
	    xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
	  } catch (E) {
	    xmlhttplocal=false;
	  }
	 }

	if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') {
	 try {
	  var xmlhttplocal = new XMLHttpRequest();
	 } catch (e) {
	  var xmlhttplocal=false;
	  alert('couldn\'t create xmlhttp object');
	 }
	}
	return(xmlhttplocal);
}

function sndReq(vote,id_num,ip_num,units) {
	var theUL = document.getElementById('unit_ul'+id_num); // the UL
	
	// switch UL with a loading div
	theUL.innerHTML = '<div class="loading"></div>';
	
    xmlhttp.open('get', 'rpc.php?j='+vote+'&q='+id_num+'&t='+ip_num+'&c='+units);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);	
}

function handleResponse() {
  if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
       	
        var response = xmlhttp.responseText;
        var update = new Array();

        if(response.indexOf('|') != -1) {
            update = response.split('|');
            changeText(update[0], update[1]);
        }
		}
    }
}

function changeText( div2show, text ) {
    // Detect Browser
    var IE = (document.all) ? 1 : 0;
    var DOM = 0; 
    if (parseInt(navigator.appVersion) >=5) {DOM=1};

    // Grab the content from the requested "div" and show it in the "container"
    if (DOM) {
        var viewer = document.getElementById(div2show);
        viewer.innerHTML = text;
    }  else if(IE) {
        document.all[div2show].innerHTML = text;
    }
}

/* =============================================================== */
var ratingAction = {
		'a.rater' : function(element){
			element.onclick = function(){

			var parameterString = this.href.replace(/.*\?(.*)/, "$1"); // onclick="sndReq('j=1&q=2&t=127.0.0.1&c=5');
			var parameterTokens = parameterString.split("&"); // onclick="sndReq('j=1,q=2,t=127.0.0.1,c=5');
			var parameterList = new Array();

			for (j = 0; j < parameterTokens.length; j++) {
				var parameterName = parameterTokens[j].replace(/(.*)=.*/, "$1"); // j
				var parameterValue = parameterTokens[j].replace(/.*=(.*)/, "$1"); // 1
				parameterList[parameterName] = parameterValue;
			}
			var theratingID = parameterList['q'];
			var theVote = parameterList['j'];
			var theuserIP = parameterList['t'];
			var theunits = parameterList['c'];
			
			//for testing	alert('sndReq('+theVote+','+theratingID+','+theuserIP+','+theunits+')'); return false;
			sndReq(theVote,theratingID,theuserIP,theunits); return false;		
			}
		}
		
	};
Behaviour.register(ratingAction);


pourriez vous m'aider svp ?
Modifié par juliet (04 Nov 2011 - 11:27)