00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 include_once('config.inc.php');
00023 include_once('lib/Common.php');
00024
00025 $DB = NewADOConnection(GetConfigVar('db_software'));
00026 $DB->Connect(GetConfigVar('db_host'), GetConfigVar('db_username') , GetConfigVar('db_password'), GetConfigVar('db_database'));
00027 CacheIndexes();
00028
00029 define('LOCATE_CURR', 0);
00030 define('LOCATE_NEXT', 1);
00031 define('LOCATE_NEXTMISSING', 2);
00032 define('LOCATE_PREV', 3);
00033 define('LOCATE_PREVMISSING', 4);
00034
00043 class TranslationBackend
00044 {
00045 public $Event;
00047
00048
00049 public $txtFindText;
00050 public $ddlSearchType;
00051 public $ddlFindPercent;
00052 public $ddlLocaleID;
00053 public $xOldLocaleID;
00054 public $xStringID;
00055 public $xDelStringID;
00056 public $txtEditString;
00058
00059
00060 public $Translations;
00061 public $LocatedString;
00062 public $LocatedProjects;
00063 public $ChildProjects;
00064 public $CurrentStrings;
00065 public $RootLastSeen;
00067
00068
00069 private $String;
00078 function __construct()
00079 {
00080
00081 $this->String = new TranslationString();
00082 $this->DB = GetDbConn();
00083 $this->Tables = GetTables();
00084
00085 $this->txtFindText = "";
00086 $this->ddlSearchType = 0;
00087 $this->ddlFindPercent = 60;
00088 $this->ddlLocaleID = 1;
00089 $this->xOldLocaleID = 1;
00090 $this->xStringID = 0;
00091 $this->xProjectID = 0;
00092
00093 $this->InitLanguage();
00094 }
00095
00100 public function InitLanguage()
00101 {
00102
00103 $proj = new TranslationProject();
00104 if($proj->LoadRoot("Xaraya", $this->ddlLocaleID))
00105 {
00106 $this->xProjectID = $proj->GetID();
00107 $this->FindProjectPath();
00108 }
00109 }
00110
00126 function FindStrings()
00127 {
00128 switch($this->ddlSearchType)
00129 {
00130
00131 case 1:
00132
00133 $this->Translations = $this->String->FindText($this->txtFindText, $this->ddlLocaleID, true);
00134 break;
00135
00136 case 2:
00137
00138 $this->Translations = $this->String->FindText($this->txtFindText, $this->ddlLocaleID, false);
00139 break;
00140
00141 default:
00142
00143 $this->Translations = $this->String->FindSimilar($this->txtFindText, $this->ddlLocaleID, $this->ddlFindPercent);
00144 break;
00145 }
00146 }
00147
00160 function LocateString($locate = LOCATE_CURR)
00161 {
00162
00163 switch($locate)
00164 {
00165 case LOCATE_CURR:
00166 $this->LocatedString = new TranslationString($this->xStringID);
00167 break;
00168
00169 case LOCATE_NEXT:
00170 case LOCATE_NEXTMISSING:
00171 $this->LocateStringNext( ($locate == LOCATE_NEXTMISSING) );
00172 break;
00173 }
00174 }
00175
00180 private function LocateStringNext($missingOnly)
00181 {
00182 unset($this->LocatedString);
00183
00184
00185
00186
00187 if($this->xStringID != 0)
00188 {
00189
00190 $currentString = new TranslationString($this->xStringID);
00191 $stringIter = new StringIterator($currentString->GetProjectID());
00192
00193
00194
00195
00196 $takeString = false;
00197 foreach($stringIter as $str)
00198 {
00199 if($takeString)
00200 {
00201 $this->LocatedString = new TranslationString($str->GetStringID());
00202
00203
00204 if($missingOnly && $this->LocatedString->GetTranslation() != "")
00205 {
00206
00207 unset($this->LocatedString);
00208 }
00209 else
00210 {
00211
00212 $this->xStringID = $str->GetStringID();
00213 break;
00214 }
00215 }
00216
00217
00218 if($str->GetStringID() == $currentString->GetStringID())
00219 {
00220 $takeString = true;
00221 }
00222 }
00223 }
00224
00225
00226
00227
00228 $currentProject = new TranslationProject($this->xProjectID);
00229
00230
00231 $rootHit = false;
00232
00233
00234 while(empty($this->LocatedString) && !$rootHit)
00235 {
00236 $takeProject = false;
00237
00238
00239 $parentProjects = new RecursiveIteratorIterator(
00240 new ProjectIterator($currentProject->GetParentID(), $this->ddlLocaleID),
00241 RecursiveIteratorIterator::SELF_FIRST);
00242
00243
00244 foreach($parentProjects as $proj)
00245 {
00246
00247 if($takeProject)
00248 {
00249
00250 $stringIter = new StringIterator($proj->GetID());
00251
00252
00253 if(!$missingOnly)
00254 {
00255
00256 if($stringIter->valid())
00257 {
00258 $this->xStringID = $stringIter->current()->GetStringID();
00259 $this->LocatedString = new TranslationString($this->xStringID);
00260 break;
00261 }
00262 }
00263 else
00264 {
00265 $foundEmpty = false;
00266
00267
00268 foreach($stringIter as $str)
00269 {
00270 if($str->GetTranslation() == "")
00271 {
00272 $this->xStringID = $str->GetStringID();
00273 $this->LocatedString = new TranslationString($this->xStringID);
00274 $foundEmpty = true;
00275 break;
00276 }
00277 }
00278
00279
00280 if($foundEmpty)
00281 {
00282 break;
00283 }
00284 }
00285 }
00286
00287
00288 if($proj->GetID() == $this->xProjectID)
00289 {
00290 $takeProject = true;
00291 }
00292 }
00293
00294
00295 $rootHit = ($currentProject->GetParentID() == 0);
00296
00297
00298 if($currentProject->GetParentID() != 0 && empty($this->LocatedString))
00299 {
00300 $currentProject = new TranslationProject($currentProject->GetParentID());
00301 }
00302
00303 }
00304 }
00318 function FindProjectPath()
00319 {
00320 unset ($this->LocatedProjects);
00321 unset ($this->ChildProjects);
00322
00323 $pid = $this->xProjectID;
00324
00325
00326 while($pid != 0)
00327 {
00328 $proj = new TranslationProject($pid);
00329 $this->LocatedProjects[] = $proj;
00330 $pid = $proj->GetParentID();
00331
00332
00333 if($pid == 0)
00334 {
00335 $this->RootLastSeen = $proj->GetLastSeen();
00336 }
00337 }
00338
00339
00340 $this->ChildProjects = new ProjectIterator($this->xProjectID, $this->ddlLocaleID);
00341 }
00342
00351 function SaveString()
00352 {
00353
00354 $string = new TranslationString($this->xStringID);
00355 $string->SetTranslation($this->txtEditString);
00356 $string->Save();
00357 }
00358
00363 function DeleteString()
00364 {
00365
00366 $string = new TranslationString($this->xDelStringID);
00367 $string->DestroyData();
00368 }
00373 function LoadProjectStrings()
00374 {
00375 $this->CurrentStrings = new StringIterator($this->xProjectID);
00376 }
00377 }
00378
00379 ?>