Файл: DarkAge/test.php
Строк: 77
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
require_once('common.php');
require_once('config.php');
/**
* Вызываемая функция скрипта
*
*/
function vgrInt_Main()
{
define('TAG', 'test.php');
header("Content-type: text/plain;charset=utf-8");
$filePath = "test.xml";
$content = file_get_contents($filePath);
if($content === FALSE)
{
vgrInt_printMessage(TAG, VGR_INT_MESSAGE_ERROR, "Файл с тестовыми данными не найден: $filePath");
}
else
{
try
{
$vals = null;
$index = null;
$p = xml_parser_create();
xml_parse_into_struct($p, $content, $vals, $index);
xml_parser_free($p);
$votes = array();
$voteData = null;
foreach ($vals as $value)
{
$array = $value;
$tagName = $array['tag'];
$tagName = strtolower($tagName);
switch($tagName)
{
case "vote":
{
if($voteData != null)
{
array_push($votes, $voteData);
}
$voteData = array();
break;
}
case "char":
{
$xmlChar = null;
$x = 'value';
if(array_key_exists($x, $array))
{
$xmlChar = $array[$x];
$xmlChar = trim($xmlChar);
}
$voteData['char'] = $xmlChar;
break;
}
default:
{
break;
}
}
}
if(count($votes) == 0)
{
vgrInt_printMessage(TAG, VGR_INT_MESSAGE_ERROR, "Нет данных в Файле с тестовыми данными: $filePath");
return;
}
else
{
vgrInt_openVotesSQLConnection();
vgrInt_createSQLTables();
global $vgrInt_SQLLink;
$query = "select min(id) as id from vigre_votes";
$res = mysql_query($query, $vgrInt_SQLLink) or vgrInt_throwMySQLError();
$row = mysql_fetch_array($res);
$id = $row['id'];
$id = intval($id);
if($id > 0)
{
$id = 0;
}
foreach ($votes as $value)
{
$id--;
$date = time();
$dateString = date("d.m.y H:i:s", $date);
$character = $value['char'];
$ip = '127.0.0.1';
$info = "Добавлен голос: [$id $dateString $ip $character]";
vgrInt_printMessage(TAG, VGR_INT_MESSAGE_INFO, $info);
$characterSQL = mysql_real_escape_string($character, $vgrInt_SQLLink);
$ipSQL = mysql_real_escape_string($ip, $vgrInt_SQLLink);
$query = "insert into vigre_votes (id, date, charname, ip)
values($id, FROM_UNIXTIME($date), '$characterSQL', '$ipSQL')";
mysql_query($query, $vgrInt_SQLLink) or vgrInt_throwMySQLError();
}
}
}
catch (Exception $e)
{
vgrInt_printMessage(TAG, VGR_INT_MESSAGE_INFO, $e->getMessage());
}
vgrInt_closeVotesSQLConnection();
}
}
/**
* Вызываем скрипт
*/
vgrInt_Main();
?>