<?php 
include "config.php";
mysql_connect ($dbhost, $username, $password);
mysql_select_db ($maindb);
$field=$_GET['field'];
$value=$_GET['value'];
$id=$_GET['id'];
$value = iconv("UTF-8", "WINDOWS-1251", $value);
$photo=0;
if ($field=="name")
 {
 $rs = mysql_query("SELECT name FROM t1 WHERE id='$id'");
 $oldname = mysql_result($rs,0,0);
 $translitname = strtolower(translit(Trim($oldname)));
 $pfn = "photos/".$translitname.".jpg";
 if (file_exists($site_dir.$pfn))
  $photo = 1;
 }
mysql_query("UPDATE t1 SET $field='$value' WHERE id ='$id';");
if ($photo==1)
 {
 $newtranslitname = strtolower(translit(Trim($value)));
 @rename("photos/".$translitname.".jpg", "photos/".$newtranslitname.".jpg");
 }
mysql_close();

function translit($st)
    {
    // Сначала заменяем "односимвольные" фонемы.
    $st=strtr($st,"абвгдеёзийклмнопрстуфхъыэ. ",
    "abvgdeeziyklmnoprstufh'ie__");
    $st=strtr($st,"АБВГДЕЁЗИЙКЛМНОПРСТУФХЪЫЭ ",
    "ABVGDEEZIYKLMNOPRSTUFH'IE_");
    // Затем - "многосимвольные".
    $st=strtr($st,
                    array(
                        "ж"=>"zh", "ц"=>"ts", "ч"=>"ch", "ш"=>"sh",
                        "щ"=>"shch","ь"=>"", "ю"=>"yu", "я"=>"ya",
                        "Ж"=>"ZH", "Ц"=>"TS", "Ч"=>"CH", "Ш"=>"SH",
                        "Щ"=>"SHCH","Ь"=>"", "Ю"=>"YU", "Я"=>"YA",
                        "ї"=>"i", "Ї"=>"Yi", "є"=>"ie", "Є"=>"Ye",
                        "№"=>"N"
                        )
             );
    // Возвращаем результат.
    return $st;
    }
?>