Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

WebBackend.php

Go to the documentation of this file.
00001 <?php
00002 
00003 /***************************************************************************
00004  *   Copyright (C) 2005 by Ferenc Veres   *
00005  *   lion@netngine.hu   *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 include('TranslationBackend.php');
00023 include_once('export/TranslationExport.php');
00024 
00033 class WebBackend extends TranslationBackend
00034 {
00035         public $xStringStack;   
00036         public $xBrowserHelper; 
00042         function __construct()
00043         {
00044                 parent::__construct();
00045         }
00046 
00051         public function EventHandler()
00052         {
00053                 global $_POST;
00054                 
00055                 // Handle Events
00056                 $this->Event = (empty($_POST["__Event"]) ? "" : $_POST["__Event"] );
00057 
00058                 if($this->Event != "")
00059                 {
00060                         
00061                         // Move web variables into local controls
00062 
00063                         $this->xBrowserHelper = (empty($_POST["xBrowserHelper"]) ? "" : $_POST["xBrowserHelper"]);
00064                         $this->txtEditString = (empty($_POST["txtEditString_".$this->xBrowserHelper]) ? "" : $_POST["txtEditString_".$this->xBrowserHelper] );
00065                         $this->txtEditString  = trim($this->txtEditString);
00066 
00067                         $this->txtFindText = (empty($_POST["txtFindText"]) ? "" : $_POST["txtFindText"] );
00068                         $this->ddlFindPercent = (empty($_POST["ddlFindPercent"]) ? 60 : $_POST["ddlFindPercent"]);
00069                         $this->xStringID = (empty($_POST["xStringID"]) ? "" : $_POST["xStringID"]);
00070                         $this->xProjectID = (empty($_POST["xProjectID"]) ? "" : $_POST["xProjectID"]);
00071                         $this->ddlLocaleID = (empty($_POST["xOldLocaleID"]) ? "" : $_POST["xOldLocaleID"]);
00072                         $this->xOldLocaleID = (empty($_POST["xOldLocaleID"]) ? "" : $_POST["xOldLocaleID"]);
00073                         $this->ddlSearchType = (empty($_POST["ddlSearchType"]) ? 0 : $_POST["ddlSearchType"]);
00074                         $this->xStringStack = (empty($_POST["xStringStack"]) ? "" : $_POST["xStringStack"]);
00075                         $this->xDelStringID = (empty($_POST["xDelStringID"]) ? "" : $_POST["xDelStringID"]);
00076 
00077                         // If no valid root yet, try with posted ddlLocaleID too.
00078                         if($this->xProjectID == 0)
00079                         {
00080                                 $this->InitLanguage();
00081                         }
00082 
00083                         //echo "EVENT:".$this->Event;
00084                         
00085                         switch($this->Event)
00086                         {
00087                                 case "find":
00088                                         $this->Event_FindCustomString();
00089                                         break;
00090                                         
00091                                 case "editstring":
00092                                         $this->Event_EditString();
00093                                         break;
00094                                         
00095                                 case "deletestring":
00096                                         $this->Event_DeleteString();
00097                                         break;
00098                                 
00099                                 case "savenextmissing":
00100                                 case "savepopstack":
00101                                 case "savenext":
00102                                 case "nextmissing":
00103                                 case "next":
00104                                 case "save":
00105                                         $this->Event_SaveNavigate();
00106                                         break;
00107                                         
00108                                 case "setproject":
00109                                         $this->Event_SetProject();
00110                                         break;
00111 
00112                                 case "setlocale":
00113                                         $this->Event_SetLocale();
00114                                         break;
00115                                         
00116                                 case "exportpack":
00117                                         $this->Event_ExportPack();
00118                                         break;
00119 
00120                         }
00121                         
00122 
00123                         // If anything to edit, set browser input field suffix (for browser form cache)
00124                         if(!empty($this->LocatedString))
00125                         {
00126                                 $this->xBrowserHelper = md5($this->LocatedString->GetOriginal());
00127                         }
00128 
00129 
00130                 }
00131         }
00132 
00137         private function Event_FindCustomString()
00138         {
00139                 // Search the string
00140                 $this->FindStrings();
00141 
00142                 $this->SyncToString();
00143         }
00144 
00145 
00150         private function Event_EditString()
00151         {
00152                 // Load the selected string and related project paths
00153                 $this->SyncToString();
00154                 
00155                 // Find similar strings
00156                 if(!empty($this->LocatedString))
00157                 {
00158                         $this->ddlSearchType = 0;
00159                         $this->txtFindText = $this->LocatedString->GetOriginal();
00160                         $this->FindStrings();
00161                 }
00162         }
00163 
00168         private function Event_DeleteString()
00169         {
00170                 $this->DeleteString();
00171                 
00172                 if($this->xDelStringID == $this->xStringID)
00173                 {
00174                         // If it was the current string, go back to the first in this project.
00175                         $this->xStringID = 0;
00176                         $this->SyncToProject();
00177                 }
00178                 else
00179                 {
00180                         // Not current string, so sync back to that string
00181                         $this->SyncToString();
00182                 }
00183 
00184                 // Search unchanged
00185                 $this->FindStrings();
00186         }
00187         
00192         private function Event_SaveNavigate()
00193         {
00194                 // Save the string??
00195                 if($this->Event == "savenext" ||
00196                         $this->Event == "savenextmissing" ||
00197                         $this->Event == "savepopstack" ||
00198                         $this->Event == "save")
00199                 {
00200                         $this->SaveString();
00201                 }
00202 
00203                 // How to find the next string?
00204                 $locType = LOCATE_CURR;
00205                 
00206                 if($this->Event == "savenext" || $this->Event == "next")
00207                 {
00208                         $locType = LOCATE_NEXT;
00209                 }
00210                 else if($this->Event == "savenextmissing" || $this->Event == "nextmissing")
00211                 {
00212                         $locType = LOCATE_NEXTMISSING;
00213                 }
00214                 else if($this->Event == "savepopstack")
00215                 {
00216                         // Also locate curr, but we take the last string from stack!
00217                         $locType = LOCATE_CURR;
00218                         
00219                         $stack = split(",", $this->xStringStack);
00220                         $this->xStringID = array_pop($stack);
00221                         $this->xStringStack = join($stack, ",");
00222                 }
00223                 
00224                 // Locate it on the selected way
00225                 $this->LocateString($locType);
00226 
00227                 $this->SyncToString();
00228                 
00229                 // Find similar strings
00230                 if(!empty($this->LocatedString))
00231                 {
00232                         $this->ddlSearchType = 0;
00233                         $this->txtFindText = $this->LocatedString->GetOriginal();
00234                         $this->FindStrings();
00235                 }
00236         }
00237 
00242         private function Event_SetProject()
00243         {
00244                 $this->SyncToProject(); 
00245                 
00246                 // Find similar strings
00247                 if(!empty($this->LocatedString))
00248                 {
00249                         $this->ddlSearchType = 0;
00250                         $this->txtFindText = $this->LocatedString->GetOriginal();
00251                         $this->FindStrings();
00252                 }
00253 
00254         }
00255 
00260         private function Event_SetLocale()
00261         {
00262                 $this->xOldLocaleID = (empty($_POST["ddlLocaleID"]) ? "" : $_POST["ddlLocaleID"]);
00263                 $this->ddlLocaleID = $this->xOldLocaleID;
00264                 $this->InitLanguage();
00265 
00266                 $this->SyncToProject();
00267         }
00268 
00273         private function Event_ExportPack()
00274         {
00275                 global $CONFIG;
00276 
00277                 // Check if exporting is enabled, quit if not
00278                 if(!$CONFIG['enable_web_export'])
00279                 {
00280                         throw new Exception("Web GUI export function is disabled in configuration.");
00281                 }
00282                 
00283                 // Find selected locale's name
00284                 $localeName = "";
00285                 foreach(TranslationProject::$LocaleIDCache as $name => $id)
00286                 {
00287                         if($id == $this->ddlLocaleID)
00288                         {
00289                                 $localeName = $name;
00290                                 break;
00291                         }
00292                 }
00293 
00294                 if($localeName == "")
00295                 {
00296                         throw new Exception("Cannot find locale name for current locale id: " + $this->ddlLocaleID);
00297                 }
00298 
00299                 // Create a Xaraya exporter
00300                 // TODO: (Hardcoded project type for now!)
00301                 $factory = new CreateExporter();
00302                 $proc = $factory->NewExporter("Xaraya");
00303 
00304                 // Export to the configured output location
00305                 $proc->Export($localeName, true);
00306                 
00307                 // Compress the dir with TAR
00308                 $languagePack = $localeName."_".date('Y-m-d').".tar.gz";
00309                 system("tar -C ".$CONFIG['export_path']." --exclude $localeName/php -czf ".$CONFIG['language_pack_dir']."/$languagePack $localeName", $ret);
00310                 if($ret != 0)
00311                 {
00312                         echo("<p>Tar returned $ret, the package may be incomplete.</p>");
00313                 }
00314                 $link = $CONFIG['language_pack_url']."/$languagePack";
00315                 echo("<p>Language pack saved to: <a href=\"$link\">$link</a>.</p>");
00316         }
00317 
00322         private function SyncToProject()
00323         {
00324                 $this->xStringID = 0;
00325                 
00326                 if($this->xProjectID == 0)
00327                 {
00328                         return;
00329                 }
00330 
00331                 // Load the project's strings
00332                 $this->LoadProjectStrings();
00333                 
00334                 if($this->CurrentStrings->valid())
00335                 {
00336                         // If there are strings, take the first one and Load it
00337                         $this->xStringID = $this->CurrentStrings->current()->GetStringID();
00338                         $this->LocateString();
00339 
00340                         // Find similar strings
00341                         $this->txtFindText = $this->LocatedString->GetOriginal();
00342                         $this->FindStrings();
00343                 }
00344                 else
00345                 {
00346                         // Forget last string ID if no strings for this project.
00347                         $this->xStringID = 0;
00348                 }
00349 
00350                 // Load related project tree too
00351                 $this->FindProjectPath();
00352         }
00353 
00358         private function SyncToString()
00359         {
00360                 if($this->xStringID == 0)
00361                 {
00362                         return;
00363                 }
00364                 
00365                 $this->LocateString();
00366                 
00367                 if(!empty($this->LocatedString))
00368                 {
00369                         // If found the string, load related project info
00370                         $this->xProjectID = $this->LocatedString->GetProjectID();
00371                         $this->LoadProjectStrings();
00372                 }
00373 
00374                 // Load related project tree too
00375                 $this->FindProjectPath();
00376         }
00377 
00378 }

Generated on Sat Apr 22 16:49:54 2006 for XarayaTranslationMemory by  doxygen 1.4.4