<?php
//BindEvents Method @1-8A6C34E5
function BindEvents()
{
    global $grdVariation;
    global $CCSEvents;
    $grdVariation->CCSEvents["BeforeShowRow"] = "grdVariation_BeforeShowRow";
    $CCSEvents["BeforeShow"] = "Page_BeforeShow";
}
//End BindEvents Method

//grdVariation_BeforeShowRow @12-557ACAF8
function grdVariation_BeforeShowRow(& $sender)
{
    $grdVariation_BeforeShowRow = true;
    $Component = & $sender;
    $Container = & CCGetParentContainer($sender);
    global $grdVariation; //Compatibility
//End grdVariation_BeforeShowRow

//Custom Code @31-2A29BDB7
// -------------------------
    // Write your own code here.
	global $DBcnxRecensement;
	global $nb_prec;
	

	//$nb = CCDLookup("count(id)", "rec_mehari", "saisie <= (DATE_ADD(CURDATE(), INTERVAL( 6 + DAYOFWEEK( CURDATE()))  *  - 1 DAY)) and departement_id = ".$grdVariation->ds->f("departement_id"), $DBcnxRecensement);
	$nb = CCDLookup("count(id)", "rec_mehari", "saisie <= subdate( curdate( ) , INTERVAL( weekday( curdate( ) ) + 1 ) DAY ) and departement_id = ".$grdVariation->ds->f("departement_id"), $DBcnxRecensement);
 

	$diff = $grdVariation->ds->f("Nbmemedepartement") - $nb;
	if ($diff == 0)
		$diff = ""; 
	elseif ($diff >= 0)
		$diff = "+ ".$diff;

	$grdVariation->lblDiff->SetValue($diff);

	if ($nb_prec <> $grdVariation->ds->f("Nbmemedepartement"))
	{
		$nb_prec = $grdVariation->ds->f("Nbmemedepartement");
		$grdVariation->Nbmemedepartement->SetValue($nb_prec);
		$grdVariation->lblClassNew->SetValue("class='new'");
		if ($diff <> "")
			$grdVariation->lblClassNew->SetValue("class='newdiff'");
	}
	else
	{
		$grdVariation->Nbmemedepartement->SetValue("");
		$grdVariation->lblClassNew->SetValue("");
		if ($diff <> "")
			$grdVariation->lblClassNew->SetValue("class='diff'");
	}


// -------------------------
//End Custom Code

//Close grdVariation_BeforeShowRow @12-DF07B0CB
    return $grdVariation_BeforeShowRow;
}
//End Close grdVariation_BeforeShowRow

//DEL  // -------------------------
//DEL      // Write your own code here.
//DEL  	$grdForumUsers->username->SetValue(utf8_decode($grdForumUsers->username->GetValue()));
//DEL  // -------------------------

//DEL  // -------------------------
//DEL      // Write your own code here.
//DEL  	$str = "";
//DEL  	$i = 0;
//DEL  
//DEL  	$db = new clsDBcnxRecensement();
//DEL    	$SQL = "SELECT r.id, r.mehari_id, r.recensement_qui, r.recensement_adherent, r.mehari_pseudo_forum, r.mehari_pseudo_ok ";
//DEL  	$SQL .= "FROM rec_mehari r ";
//DEL  	$SQL .= "WHERE (r.recensement_qui like '%".utf8_decode($grdForumUsers->ds->f("username"))."%' ";
//DEL  	$SQL .= "OR r.recensement_adherent like '%".utf8_decode($grdForumUsers->ds->f("username"))."%' ";
//DEL  	$SQL .= "OR r.mehari_pseudo_forum like '%".utf8_decode($grdForumUsers->ds->f("username"))."%') ";
//DEL  	//$SQL .= "AND mehari_pseudo_ok <> 1"
//DEL  
//DEL  	//echo "SQL : ".$SQL."<br>";
//DEL   	
//DEL  	$result = mysql_query($SQL);
//DEL   	while ($row = mysql_fetch_assoc($result)) {
//DEL  		$i++;
//DEL  		if ($i>1)
//DEL  			$str .= "<br>";
//DEL  	   	$str .= "- ".$row['id']."";
//DEL      	$str .= " / mehari_id : ".$row['mehari_id']."";    
//DEL      	$str .= " / qui : <b>".$row['recensement_qui']."</b>";    
//DEL      	$str .= " / adherent : ".$row['recensement_adherent']."";    
//DEL      	$str .= " / pseudo : ".$row['mehari_pseudo_forum']."";
//DEL  		if ($row['mehari_pseudo_ok'] == 1)
//DEL  			$str .= "<font color=red><b>  OK</b></font>";
//DEL  		else
//DEL  			$str .= " : <a href=\"recensement_pseudo.php?lettre=".CCGETParam("lettre", "")."&id=".$row['id']."&pseudo=".utf8_decode($grdForumUsers->ds->f("username"))."\">--> OK</a>";
//DEL  		
//DEL  	}
//DEL  
//DEL  	$grdForumUsers->lblPseudo->SetValue($str);      
//DEL    	$db->close();
//DEL  	//	$str .= utf8_decode($grdForumUsers->ds->f("username"))."\n";
//DEL  
//DEL  	//foreach(mb_list_encodings() as $chr){ 
//DEL      //    $str .= mb_convert_encoding($grdForumUsers->ds->f("username"), 'UTF-8', $chr)." : ".$chr."\n";    
//DEL   	//}
//DEL  	//		$grdForumUsers->lblPseudo->SetValue($str);      
//DEL   
//DEL  // -------------------------

//Page_BeforeShow @1-A82138D9
function Page_BeforeShow(& $sender)
{
    $Page_BeforeShow = true;
    $Component = & $sender;
    $Container = & CCGetParentContainer($sender);
    global $recensement_variation; //Compatibility
//End Page_BeforeShow

//Custom Code @11-2A29BDB7
// -------------------------
    // Write your own code here.
	$db = new clsDBcnxRecensement();

	if (CCGETParam("pseudo", "") <> "" and CCGETParam("id", "") <> "")
	{
		$db = new clsDBcnxRecensement();

  		$SQL = "UPDATE rec_mehari SET mehari_pseudo_forum = '".CCGETParam("pseudo", "")."', mehari_pseudo_ok = 1 ";
		$SQL .= "WHERE id = ".CCGETParam("id", "");
		//echo "SQL : ".$SQL."<br>";

		$db->query($SQL);
		$db->close();
	}
// -------------------------
//End Custom Code

//Close Page_BeforeShow @1-4BC230CD
    return $Page_BeforeShow;
}
//End Close Page_BeforeShow
?>