00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 include('TranslationBackend.php');
00023 include_once('export/ExporterFactory.php');
00024
00033 class WebBackend extends TranslationBackend
00034 {
00035 public $xStringStack;
00036 public $xBrowserHelper;
00037 public $chkSearchSelects;
00043 function __construct()
00044 {
00045 parent::__construct();
00046 }
00047
00052 public function EventHandler()
00053 {
00054 global $_POST;
00055
00056
00057 $this->Event = (empty($_POST["__Event"]) ? "" : $_POST["__Event"] );
00058
00059 if($this->Event != "")
00060 {
00061
00062
00063
00064 $this->xBrowserHelper = (empty($_POST["xBrowserHelper"]) ? "" : $_POST["xBrowserHelper"]);
00065 $this->txtEditString = (empty($_POST["txtEditString_".$this->xBrowserHelper]) ? "" : $_POST["txtEditString_".$this->xBrowserHelper] );
00066 $this->txtEditString = trim($this->txtEditString);
00067
00068 $this->txtFindText = (empty($_POST["txtFindText"]) ? "" : $_POST["txtFindText"] );
00069 $this->ddlFindPercent = (empty($_POST["ddlFindPercent"]) ? 60 : $_POST["ddlFindPercent"]);
00070 $this->xStringID = (empty($_POST["xStringID"]) ? 0 : $_POST["xStringID"]);
00071 $this->xProjectID = (empty($_POST["xProjectID"]) ? 0 : $_POST["xProjectID"]);
00072 $this->ddlLocaleID = (empty($_POST["xOldLocaleID"]) ? "" : $_POST["xOldLocaleID"]);
00073 $this->xOldLocaleID = (empty($_POST["xOldLocaleID"]) ? "" : $_POST["xOldLocaleID"]);
00074 $this->ddlSearchType = (empty($_POST["ddlSearchType"]) ? 0 : $_POST["ddlSearchType"]);
00075 $this->xStringStack = (empty($_POST["xStringStack"]) ? "" : $_POST["xStringStack"]);
00076 $this->xDelStringID = (empty($_POST["xDelStringID"]) ? "" : $_POST["xDelStringID"]);
00077 $this->xDelProjectID = (empty($_POST["xDelProjectID"]) ? "" : $_POST["xDelProjectID"]);
00078
00079
00080 if(empty($_POST["chkSearchSelects"]))
00081 {
00082 unset($this->chkSearchSelects);
00083 }
00084 else
00085 {
00086 $this->chkSearchSelects = $_POST["chkSearchSelects"];
00087 }
00088
00089
00090 if($this->xProjectID == 0)
00091 {
00092 $this->InitLanguage();
00093 }
00094
00095
00096
00097 switch($this->Event)
00098 {
00099 case "find":
00100 $this->Event_FindCustomString();
00101 break;
00102
00103 case "editstring":
00104 $this->Event_EditString();
00105 break;
00106
00107 case "deletestring":
00108 $this->Event_DeleteString();
00109 break;
00110
00111 case "deleteproject":
00112 $this->Event_DeleteProject();
00113 break;
00114
00115 case "savenextmissing":
00116 case "savepopstack":
00117 case "savenext":
00118 case "nextmissing":
00119 case "next":
00120 case "save":
00121 case "savetoallchecked":
00122 $this->Event_SaveNavigate();
00123 break;
00124
00125 case "setproject":
00126 $this->Event_SetProject();
00127 break;
00128
00129 case "setlocale":
00130 $this->Event_SetLocale();
00131 break;
00132
00133 case "exportpack":
00134 $this->Event_ExportPack();
00135 break;
00136
00137 }
00138
00139
00140
00141 if(!empty($this->LocatedString))
00142 {
00143 $this->xBrowserHelper = md5($this->LocatedString->GetOriginal());
00144 }
00145
00146
00147 }
00148 }
00149
00154 private function Event_FindCustomString()
00155 {
00156
00157 $this->FindStrings();
00158
00159 if($this->xStringID != 0)
00160 {
00161 $this->SyncToString();
00162 }
00163 else
00164 {
00165 $this->SyncToProject();
00166 }
00167 }
00168
00169
00174 private function Event_EditString()
00175 {
00176
00177 $this->SyncToString();
00178
00179
00180 if(!empty($this->LocatedString))
00181 {
00182 $this->ddlSearchType = 0;
00183 $this->txtFindText = $this->LocatedString->GetOriginal();
00184 $this->FindStrings();
00185 }
00186 }
00187
00192 private function Event_DeleteString()
00193 {
00194 $this->DeleteString();
00195
00196 if($this->xDelStringID == $this->xStringID)
00197 {
00198
00199 $this->xStringID = 0;
00200 $this->SyncToProject();
00201 }
00202 else
00203 {
00204
00205 $this->SyncToString();
00206 }
00207
00208
00209 $this->FindStrings();
00210 }
00211
00216 private function Event_DeleteProject()
00217 {
00218
00219 $this->xProjectID = $this->DeleteProject($this->xDelProjectID);
00220 $this->xStringID = 0;
00221 $this->SyncToProject();
00222
00223
00224 $this->FindStrings();
00225 }
00226
00231 private function Event_SaveNavigate()
00232 {
00233
00234 if($this->Event == "savenext" ||
00235 $this->Event == "savenextmissing" ||
00236 $this->Event == "savepopstack" ||
00237 $this->Event == "save" ||
00238 $this->Event == "savetoallchecked")
00239 {
00240 $this->SaveString();
00241 }
00242
00243
00244 if($this->Event == "savetoallchecked")
00245 {
00246 if(count($this->chkSearchSelects) > 0)
00247 {
00248 foreach($this->chkSearchSelects as $stringID)
00249 {
00250
00251 $string = new TranslationString($stringID);
00252 $string->SetTranslation($this->txtEditString);
00253 $string->Save();
00254 }
00255 }
00256 }
00257
00258
00259 $locType = LOCATE_CURR;
00260
00261 if($this->Event == "savenext" || $this->Event == "next")
00262 {
00263 $locType = LOCATE_NEXT;
00264 }
00265 else if($this->Event == "savenextmissing" || $this->Event == "nextmissing")
00266 {
00267 $locType = LOCATE_NEXTMISSING;
00268 }
00269 else if($this->Event == "savepopstack")
00270 {
00271
00272 $locType = LOCATE_CURR;
00273
00274 $stack = split(",", $this->xStringStack);
00275 $this->xStringID = array_pop($stack);
00276 $this->xStringStack = join($stack, ",");
00277 }
00278
00279
00280 $this->LocateString($locType);
00281
00282 $this->SyncToString();
00283
00284
00285 if(!empty($this->LocatedString))
00286 {
00287 $this->ddlSearchType = 0;
00288 $this->txtFindText = $this->LocatedString->GetOriginal();
00289 $this->FindStrings();
00290 }
00291 }
00292
00297 private function Event_SetProject()
00298 {
00299 $this->SyncToProject();
00300
00301
00302 if(!empty($this->LocatedString))
00303 {
00304 $this->ddlSearchType = 0;
00305 $this->txtFindText = $this->LocatedString->GetOriginal();
00306 $this->FindStrings();
00307 }
00308
00309 }
00310
00315 private function Event_SetLocale()
00316 {
00317 $this->xOldLocaleID = (empty($_POST["ddlLocaleID"]) ? "" : $_POST["ddlLocaleID"]);
00318 $this->ddlLocaleID = $this->xOldLocaleID;
00319 $this->InitLanguage();
00320
00321 $this->SyncToProject();
00322 }
00323
00328 private function Event_ExportPack()
00329 {
00330 global $CONFIG;
00331
00332
00333 if(!$CONFIG['enable_web_export'])
00334 {
00335 throw new Exception("Web GUI export function is disabled in configuration.");
00336 }
00337
00338
00339 $localeName = "";
00340 foreach(TranslationProject::$LocaleIDCache as $name => $id)
00341 {
00342 if($id == $this->ddlLocaleID)
00343 {
00344 $localeName = $name;
00345 break;
00346 }
00347 }
00348
00349 if($localeName == "")
00350 {
00351 throw new Exception("Cannot find locale name for current locale id: " + $this->ddlLocaleID);
00352 }
00353
00354
00355
00356 $factory = new ExporterFactory();
00357 $proc = $factory->NewExporter("Xaraya");
00358
00359
00360 $proc->Export($localeName, true);
00361
00362
00363 $languagePack = $localeName."_".date('Y-m-d').".tar.gz";
00364 system("tar -C ".$CONFIG['export_path']." --exclude $localeName/php -czf ".$CONFIG['language_pack_dir']."/$languagePack $localeName", $ret);
00365 if($ret != 0)
00366 {
00367 echo("<p>Tar returned $ret, the package may be incomplete.</p>");
00368 }
00369 $link = $CONFIG['language_pack_url']."/$languagePack";
00370 echo("<p>Language pack saved to: <a href=\"$link\">$link</a>.</p>");
00371
00372
00373 if($this->xStringID != 0)
00374 {
00375 $this->SyncToString();
00376 }
00377 else
00378 {
00379 $this->SyncToProject();
00380 }
00381 }
00382
00387 private function SyncToProject()
00388 {
00389 $this->xStringID = 0;
00390
00391 if($this->xProjectID == 0)
00392 {
00393 return;
00394 }
00395
00396
00397 $this->LoadProjectStrings();
00398
00399 if($this->CurrentStrings->valid())
00400 {
00401
00402 $this->xStringID = $this->CurrentStrings->current()->GetStringID();
00403 $this->LocateString();
00404
00405
00406 $this->txtFindText = $this->LocatedString->GetOriginal();
00407 $this->FindStrings();
00408 }
00409 else
00410 {
00411
00412 $this->xStringID = 0;
00413 }
00414
00415
00416 $this->FindProjectPath();
00417 }
00418
00423 private function SyncToString()
00424 {
00425 if($this->xStringID == 0)
00426 {
00427 return;
00428 }
00429
00430 $this->LocateString();
00431
00432 if(!empty($this->LocatedString))
00433 {
00434
00435 $this->xProjectID = $this->LocatedString->GetProjectID();
00436 $this->LoadProjectStrings();
00437 }
00438
00439
00440 $this->FindProjectPath();
00441 }
00442
00443 }