<?php
ob_start();
include_once ("_dirinfo.php");
include_once (PATH_TO_ROOT."init.php");
include_once (PATH_TO_ROOT."config.php");
require_once(PATH_TO_ROOT.'CRM/class/FirePHP.class.php');
require_once(PATH_TO_ROOT.'CRM/class/fb.php');
$firephp = FirePHP::getInstance(true);
set_time_limit(0);
ini_set("display_errors",1);
ini_set('error_reporting', E_ALL ^ E_NOTICE);

$sql = "SELECT id_project, id_tel, firstname, surname FROM ".WARPIT_CRM."._visitStatistic GROUP BY id_project";
$res = $db->SQLexecute($sql);
while($row = $db->fetchAssoc($res)){
	$sql = "SELECT proj_name FROM ".DB_WARPIT_WEBCATI_BASE."._Projects WHERE id = ".$row['id_project'];		
	$rez = $db->SQLexecute($sql);
	$dat = $db->fetchAssoc($rez);
	$projectName = $dat['proj_name']."_structure";
	
	$sql = "DESCRIBE ".DB_WARPIT_WEBCATI_BASE.".".$projectName;
	$rez = $db->SQLexecute($sql);
	while($dat = $db->fetchAssoc($rez)){
		$fields[$dat['Field']] = $dat['Field'];
	}
	
	if(in_array("spol", $fields)){
		$sql = "SELECT spol, id_tel FROM ".DB_WARPIT_WEBCATI_BASE.".".$projectName." WHERE status = 1 AND status_rec = 1 AND spol IS NOT NULL";
		$rez = $db->SQLexecute($sql);
		while($dat = $db->fetchAssoc($rez)){
			$data[$dat['id_tel']] = $dat['spol'];
		}
	}
}
echo sizeof($data);
	foreach($data as $key => $value){
		$sql = "UPDATE ".WARPIT_CRM."._visitStatistic SET gender = ".$value. " WHERE id_tel = ".$key;
		$db->SQLexecute($sql);
	}
?>